/**
 * SaaS admin UI — Uplync
 * Force-loaded via layouts/app.blade.php → asset('css/app.css')
 */

/* ========== BASE ========== */
body {
    background: #f5f6fa;
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: #2d3436;
    -webkit-font-smoothing: antialiased;
}

/* ========== SIDEBAR ========== */
.sidebar {
    width: var(--saas-sidebar-w);
    height: 100vh;
    max-height: 100dvh;
    background: linear-gradient(180deg, #1e1b4b, #312e81);
    color: #c4c6e0;
    position: fixed;
    left: 0;
    top: 0;
    padding: 0;
    z-index: 1050;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    box-sizing: border-box;
    overflow: hidden;
}

.sidebar-header {
    flex-shrink: 0;
    padding: 1.25rem 1.25rem 1rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-header .logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: #c4b5fd;
    margin: 0;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

/* Scrollable menu — flex child must shrink for overflow */
.sidebar-menu {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.625rem 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}

.sidebar-menu::-webkit-scrollbar {
    width: 6px;
}

.sidebar-menu::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.22);
    border-radius: 10px;
}

.sidebar-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.32);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 0 0.75rem;
    gap: 0.125rem;
}

.sidebar a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.85rem;
    color: #c4c6e0;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.925rem;
    transition: background 0.18s ease, color 0.18s ease;
}

.sidebar a:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.sidebar a.active {
    background: linear-gradient(135deg, var(--saas-primary, #6c5ce7), #8e7cff);
    color: #fff;
    box-shadow: 0 4px 14px rgba(108, 92, 231, 0.35);
}

.sidebar a .icon {
    flex-shrink: 0;
    opacity: 0.92;
}

.sidebar-footer {
    flex-shrink: 0;
    padding: 0.85rem 1rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.12);
}

.sidebar-scroll-tools {
    display: flex;
    gap: 0.35rem;
    justify-content: center;
    margin-bottom: 0.65rem;
}

.sidebar-scroll-btn {
    flex: 1;
    max-width: 3.5rem;
    padding: 0.35rem 0.5rem;
    font-size: 0.95rem;
    line-height: 1;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.06);
    color: #e2e8f0;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.sidebar-scroll-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.25);
    color: #fff;
}

.sidebar-footer-link {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.4rem 0.25rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.65);
    text-decoration: none;
    border-radius: 6px;
    border: none;
    background: none;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.sidebar-footer-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.06);
}

.sidebar-footer-link.active {
    color: #c4b5fd;
}

.sidebar-footer-link--btn {
    font-family: inherit;
}

.sidebar-footer-account {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    margin-top: 0.35rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-footer-logout {
    margin: 0;
}

/* Mobile / tablet: off-canvas (aligns with Bootstrap lg breakpoint + hamburger) */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.4);
    }

    .sidebar.is-open,
    .sidebar.open {
        transform: translateX(0);
    }
}

@media (min-width: 992px) {
    .sidebar {
        transform: translateX(0) !important;
    }
}

@media (max-width: 767.98px) {
    .sidebar-scroll-tools {
        margin-bottom: 0.5rem;
    }
}

/* Backdrop (mobile) */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 22, 0.55);
    z-index: 1040;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.sidebar-backdrop.is-visible {
    display: block;
    opacity: 1;
}

@media (min-width: 992px) {
    .sidebar-backdrop {
        display: none !important;
    }
}

/* ========== MAIN COLUMN ========== */
.main-content {
    margin-left: var(--saas-sidebar-w);
    padding: 20px;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    box-sizing: border-box;
}

@media (max-width: 991.98px) {
    .main-content {
        margin-left: 0;
        padding: 16px;
    }
}

/* ========== TOPBAR (sticky) ========== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    background: #fff;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.topbar-title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: #2d3436;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-left: auto;
}

.topbar-user-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: #2d3436;
}

.topbar-role-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
    background: rgba(108, 92, 231, 0.12);
    color: #6c5ce7;
}

.btn-topbar-logout {
    font-size: 0.85rem;
    padding: 0.45rem 0.85rem;
    border-radius: 8px;
    border: 1px solid rgba(28, 28, 45, 0.12);
    background: #fff;
    color: #636e72;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.btn-topbar-logout:hover {
    border-color: #6c5ce7;
    color: #6c5ce7;
    background: rgba(108, 92, 231, 0.06);
}

.btn-sidebar-toggle {
    border: none;
    background: rgba(108, 92, 231, 0.1);
    color: #6c5ce7;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-sidebar-toggle:hover {
    background: rgba(108, 92, 231, 0.18);
}

@media (min-width: 992px) {
    .btn-sidebar-toggle {
        display: none !important;
    }
}

/* ========== PAGE CONTENT ========== */
.app-content {
    flex: 1;
}

/* ========== CARDS (Bootstrap + custom) ========== */
.card {
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    border: none;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.08);
}

.saas-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(28, 28, 45, 0.04);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.saas-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.08);
}

.saas-card-body {
    padding: 1.35rem 1.5rem;
}

/* ========== DESIGN TOKENS (legacy utilities) ========== */
:root {
    --saas-primary: #6c5ce7;
    --saas-gradient: linear-gradient(135deg, #6c5ce7, #8e7cff);
    --saas-text-muted: #636e72;
    --saas-radius: 12px;
    --saas-sidebar-w: 250px;
}

.saas-text-muted {
    color: var(--saas-text-muted);
    font-size: 0.9rem;
}

.btn-saas-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.15rem;
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    border-radius: 10px;
    color: #fff !important;
    background: var(--saas-gradient);
    box-shadow: 0 4px 14px rgba(108, 92, 231, 0.35);
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
    text-decoration: none;
}

.btn-saas-primary:hover {
    filter: brightness(1.05);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.45);
    transform: translateY(-1px);
    color: #fff !important;
}

.btn-saas-outline {
    border-radius: 10px;
    border: 1px solid rgba(28, 28, 45, 0.12);
    font-weight: 500;
    padding: 0.5rem 1rem;
    background: #fff;
    transition: border-color 0.15s, color 0.15s;
}

.btn-saas-outline:hover {
    border-color: #6c5ce7;
    color: #6c5ce7;
}

.table-saas {
    margin-bottom: 0;
}

.table-saas thead th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    color: var(--saas-text-muted);
}

.table-role-badge {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: capitalize;
    padding: 0.35rem 0.7rem;
    border-radius: 8px;
    background: rgba(108, 92, 231, 0.1);
    color: #6c5ce7;
}

.saas-breadcrumb .breadcrumb {
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.saas-breadcrumb .breadcrumb-item a {
    color: #6c5ce7;
    text-decoration: none;
}

.nav-tabs-saas .nav-link {
    border-radius: 10px;
    font-weight: 500;
    color: var(--saas-text-muted);
    border: none;
    padding: 0.5rem 1.1rem;
}

.nav-tabs-saas .nav-link:hover {
    color: #2d3436;
    background: rgba(108, 92, 231, 0.08);
}

.nav-tabs-saas .nav-link.active {
    color: #fff !important;
    background: var(--saas-gradient);
    box-shadow: 0 4px 14px rgba(108, 92, 231, 0.3);
}

.alert-saas-success {
    border-radius: 10px;
    border: none;
    background: rgba(46, 213, 115, 0.12);
    color: #00b894;
}

.rounded-saas {
    border-radius: var(--saas-radius) !important;
}

.form-control.rounded-saas,
.form-select.rounded-saas {
    border-color: rgba(28, 28, 45, 0.1);
}

.form-control.rounded-saas:focus,
.form-select.rounded-saas:focus {
    border-color: #6c5ce7;
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}

/* Auth (login) */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: #f5f6fa;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    padding: 2rem;
}

.auth-title {
    font-size: 1.65rem;
    font-weight: 700;
    color: #2d3436;
    margin-bottom: 0.35rem;
}

.auth-subtitle {
    font-size: 0.95rem;
    color: var(--saas-text-muted);
    margin-bottom: 1.75rem;
}

/* Shell flex wrapper */
.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Support tickets — chat thread */
.ticket-thread {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ticket-chat-row {
    display: flex;
    width: 100%;
}

.ticket-chat-row--client {
    justify-content: flex-start;
}

.ticket-chat-row--staff {
    justify-content: flex-end;
}

.ticket-chat-row--internal {
    justify-content: flex-end;
}

.badge-status-pending {
    background-color: #e67e22 !important;
    color: #fff !important;
}

.ticket-chat-bubble {
    max-width: min(100%, 34rem);
    padding: 0.75rem 1rem;
    border-radius: 12px;
    background: #fff;
    border: 1px solid rgba(28, 28, 45, 0.08);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.ticket-chat-row--staff .ticket-chat-bubble {
    background: linear-gradient(135deg, rgba(108, 92, 231, 0.12), rgba(142, 124, 255, 0.15));
    border-color: rgba(108, 92, 231, 0.25);
}

.ticket-chat-bubble--internal {
    background: linear-gradient(180deg, #fffbf0, #fff3cd) !important;
    border: 1px solid #ffc107 !important;
    color: #2d3436;
    box-shadow: 0 2px 10px rgba(255, 193, 7, 0.2);
}

.ticket-chat-bubble--internal .ticket-chat-meta {
    color: #636e72;
}

.ticket-chat-bubble--internal .ticket-chat-meta .fw-semibold {
    color: #2d3436;
}

.ticket-chat-bubble--internal .ticket-chat-body {
    color: #2d3436;
}

.ticket-chat-attachment a {
    color: #6c5ce7;
    text-decoration: none;
}

.ticket-chat-attachment a:hover {
    text-decoration: underline;
}

.helpdesk-meta-list > div {
    margin-bottom: 0.85rem;
}

.helpdesk-meta-list dt {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #636e72;
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.helpdesk-meta-list dd {
    margin-bottom: 0;
    font-size: 0.925rem;
}

.letter-spacing-tight {
    letter-spacing: 0.04em;
}

.helpdesk-ticket-num {
    color: #6c5ce7 !important;
}

.helpdesk-table-card .table thead th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #636e72;
    font-weight: 600;
    border-bottom-width: 1px;
}

.helpdesk-thread {
    min-height: 120px;
}

@media (min-width: 992px) {
    .helpdesk-sticky-side {
        position: sticky;
        top: 1rem;
        align-self: flex-start;
    }
}

.helpdesk-chat-header {
    background: rgba(108, 92, 231, 0.04);
}

.helpdesk-row-unread {
    background: rgba(108, 92, 231, 0.06) !important;
    box-shadow: inset 3px 0 0 #6c5ce7;
}

.ticket-chat-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.75rem;
    align-items: baseline;
    margin-bottom: 0.35rem;
    font-size: 0.8rem;
    color: #636e72;
}

.ticket-chat-meta .fw-semibold {
    color: #2d3436;
}

.ticket-chat-time {
    font-size: 0.75rem;
}

.ticket-chat-body {
    white-space: pre-wrap;
    font-size: 0.925rem;
    line-height: 1.5;
    color: #2d3436;
}

/* ========== INTERNAL CHAT (WhatsApp-style) ========== */
.saas-chat-shell {
    min-height: calc(100vh - 9.5rem);
    max-height: calc(100vh - 9.5rem);
}

.saas-chat-layout {
    display: flex;
    min-height: calc(100vh - 9.5rem);
    max-height: calc(100vh - 9.5rem);
}

.saas-chat-sidebar {
    width: 100%;
    max-width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: #f8f9fd;
}

.saas-chat-sidebar-head {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    background: #fff;
}

.saas-chat-sidebar-list {
    overflow-y: auto;
    flex: 1;
}

.saas-chat-thread {
    display: block;
    padding: 0.65rem 1rem;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    transition: background 0.12s ease;
}

.saas-chat-thread:hover {
    background: rgba(108, 92, 231, 0.06);
    color: inherit;
}

.saas-chat-thread.is-active {
    background: rgba(108, 92, 231, 0.12);
    box-shadow: inset 3px 0 0 var(--saas-primary, #6c5ce7);
}

.saas-chat-main {
    flex: 1;
    min-width: 0;
    background: #eceff4;
}

.saas-chat-main-head {
    background: #fff;
}

.saas-chat-messages {
    background: linear-gradient(180deg, #e8eaf0 0%, #eceff4 40%);
}

.saas-chat-composer {
    background: #fff;
}

.saas-chat-msg-row {
    display: flex;
    margin-bottom: 0.65rem;
}

.saas-chat-msg-row.is-mine {
    justify-content: flex-end;
}

.saas-chat-msg-row.is-theirs {
    justify-content: flex-start;
}

.saas-chat-msg-inner {
    max-width: min(78%, 420px);
}

.saas-chat-sender {
    color: #636e72;
    margin-bottom: 0.15rem;
    padding-left: 0.25rem;
}

.saas-chat-bubble {
    border-radius: 14px;
    padding: 0.5rem 0.75rem;
    font-size: 0.925rem;
    line-height: 1.45;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.is-mine .saas-chat-bubble {
    background: var(--saas-gradient, linear-gradient(135deg, #6c5ce7, #8e7cff));
    color: #fff;
    border-bottom-right-radius: 4px;
}

.is-mine .saas-chat-bubble a {
    color: #fff;
    text-decoration: underline;
}

.is-theirs .saas-chat-bubble {
    background: #fff;
    color: #2d3436;
    border-bottom-left-radius: 4px;
}

.is-theirs .saas-chat-time {
    text-align: left;
    padding-left: 0.35rem;
}

.is-mine .saas-chat-time {
    text-align: right;
    padding-right: 0.35rem;
    color: rgba(255, 255, 255, 0.85);
}

.is-theirs .saas-chat-time {
    color: #636e72;
}

@media (max-width: 991.98px) {
    .saas-chat-layout {
        flex-direction: column;
        max-height: none;
    }

    .saas-chat-shell {
        max-height: none;
    }

    .saas-chat-sidebar {
        max-width: none;
        max-height: 40vh;
        border-end: none !important;
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    }

    .saas-chat-main {
        min-height: 50vh;
    }
}

/* ========== ADMIN INVOICES (Perfex-style) ========== */
.saas-invoice-kpi {
    background: #fff;
}

.saas-invoices-table thead th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #636e72;
    font-weight: 600;
}

.saas-invoices-table tbody tr {
    transition: background-color 0.12s ease;
}

.saas-invoices-table tbody tr:hover {
    background-color: rgba(108, 92, 231, 0.04);
}

.saas-invoices-table td {
    vertical-align: middle;
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
}

/* Sidebar nested menu (admin) */
.sidebar-nav-group {
    border-radius: 8px;
}

.sidebar-nav-group summary.sidebar-nav-summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.85rem;
    color: #c4c6e0;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.925rem;
    transition: background 0.18s ease, color 0.18s ease;
}

.sidebar-nav-group summary.sidebar-nav-summary::-webkit-details-marker {
    display: none;
}

.sidebar-nav-group summary.sidebar-nav-summary::after {
    content: '';
    flex-shrink: 0;
    margin-left: 0.25rem;
    width: 0.45em;
    height: 0.45em;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    opacity: 0.65;
    transition: transform 0.2s ease;
}

.sidebar-nav-group[open] summary.sidebar-nav-summary::after {
    transform: rotate(-135deg);
    margin-top: 0.2em;
}

.sidebar-nav-group summary.sidebar-nav-summary:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.sidebar-nav-summary-active {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.sidebar-nav-summary-link {
    color: inherit;
    text-decoration: none;
    font-weight: inherit;
}

.sidebar-nav-summary-link:hover {
    color: #fff;
}

.sidebar-nav-sub {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    padding: 0.15rem 0 0.35rem 0.85rem;
    margin-left: 0.35rem;
    border-left: 2px solid rgba(255, 255, 255, 0.12);
}

.sidebar-nav-sub-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.85rem;
    color: #b8bacf;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.88rem;
    transition: background 0.18s ease, color 0.18s ease;
}

.sidebar-nav-sub-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.sidebar-nav-sub-link.active {
    background: linear-gradient(135deg, var(--saas-primary, #6c5ce7), #8e7cff);
    color: #fff;
    box-shadow: 0 3px 12px rgba(108, 92, 231, 0.28);
}

.admin-menu-nested-root ul.nested-sortable {
    min-height: 1.25rem;
}

/* Menu settings: full list scrollable (nested items e.g. Facebook) */
.saas-card-menu-settings .saas-card-body {
    overflow: visible !important;
}

.saas-card-menu-settings .menu-builder {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-right: 0.25rem;
    margin-right: -0.25rem;
}

@media (max-width: 991.98px) {
    .saas-card-menu-settings .menu-builder {
        max-height: calc(100vh - 240px);
    }
}
