/* ════════════════════════════════════════════════════════════
   WaveLedger — Modern UI  v3
   Palette: Midnight sidebar · Blue primary · Clean cards
   ════════════════════════════════════════════════════════════ */

/* ── CSS variables ───────────────────────────────────────── */
:root {
    --sidebar-width:   252px;
    --topbar-height:    58px;

    /* Brand (overridden by inline <style> from settings) */
    --brand:           #2563eb;
    --brand-dark:      #1d4ed8;
    --brand-light:     #eff6ff;
    --brand-muted:     rgba(37,99,235,.12);

    /* Surface */
    --bg:              #f0f4f8;
    --surface:         #ffffff;
    --surface-2:       #f8fafc;
    --border:          #e4eaf0;
    --border-light:    #f1f5f9;

    /* Sidebar */
    --sidebar-bg:      #0d1526;
    --sidebar-text:    #8ea3bf;
    --sidebar-active:  rgba(37,99,235,.20);
    --sidebar-hover:   rgba(255,255,255,.055);

    /* Text */
    --text:            #1a2332;
    --text-muted:      #637488;
    --text-light:      #94a3b8;

    /* Status colours */
    --green:   #10b981;
    --amber:   #f59e0b;
    --red:     #ef4444;
    --purple:  #8b5cf6;
    --cyan:    #06b6d4;

    /* Radius & shadow */
    --radius:  .75rem;
    --radius-sm: .5rem;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
    --shadow:    0 4px 16px rgba(0,0,0,.08), 0 1px 4px rgba(0,0,0,.04);
    --shadow-lg: 0 12px 32px rgba(0,0,0,.12);

    --transition: .18s ease;
}

/* ── Reset & base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
    background: var(--bg);
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: .875rem;
    margin: 0;
    color: var(--text);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ════════════════════════════════════════════════════════════
   TOP BAR
   ════════════════════════════════════════════════════════════ */
#topNavbar {
    height: var(--topbar-height);
    background: var(--sidebar-bg) !important;
    border-bottom: 1px solid rgba(255,255,255,.06);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 16px rgba(0,0,0,.25);
    padding: 0 1rem;
    z-index: 1050;
}
#topNavbar .navbar-brand {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -.02em;
    color: #fff !important;
    gap: .5rem;
}
#topNavbar .navbar-brand img { height: 28px; border-radius: .35rem; }
#topNavbar .nav-link,
#topNavbar .btn-link { color: rgba(255,255,255,.72) !important; }
#topNavbar .nav-link:hover { color: #fff !important; }

/* Search box in topbar */
#topNavbar .form-control.search-box {
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.12);
    color: #fff;
    border-radius: var(--radius-sm);
    font-size: .8rem;
    padding: .35rem .85rem;
    width: 220px;
    transition: var(--transition);
}
#topNavbar .form-control.search-box::placeholder { color: rgba(255,255,255,.38); }
#topNavbar .form-control.search-box:focus {
    background: rgba(255,255,255,.14);
    border-color: rgba(255,255,255,.28);
    box-shadow: none;
    width: 280px;
    color: #fff;
    outline: none;
}

/* Notification badge */
.notif-btn { position: relative; }
.notif-btn .badge-dot {
    position: absolute; top: 4px; right: 4px;
    width: 8px; height: 8px;
    background: var(--red); border-radius: 50%;
    border: 2px solid var(--sidebar-bg);
    display: none;
}
.notif-btn.has-unread .badge-dot { display: block; }

/* ════════════════════════════════════════════════════════════
   SIDEBAR
   ════════════════════════════════════════════════════════════ */
.sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--topbar-height));
    background: var(--sidebar-bg);
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform var(--transition);
    z-index: 1040;
    scrollbar-width: thin;
    scrollbar-color: #1e3a5f transparent;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255,255,255,.04);
}
.sidebar.collapsed { transform: translateX(-100%); }

.sidebar-nav { padding: .75rem 0 1.5rem; flex: 1; }

/* Section title */
.nav-section-title {
    color: rgba(255,255,255,.22);
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    padding: 1.1rem 1.1rem .4rem;
}

/* Nav items */
.nav-item {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .48rem 1.1rem .48rem 1.1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    border-left: 2.5px solid transparent;
    font-size: .82rem;
    cursor: pointer;
    border-radius: 0;
    margin: 1px 0;
    position: relative;
}
.nav-item:hover {
    background: var(--sidebar-hover);
    color: #dde8f8;
    border-left-color: rgba(255,255,255,.15);
}
.nav-item.active {
    background: var(--sidebar-active);
    color: #fff;
    border-left-color: var(--brand);
    font-weight: 600;
}
.nav-item.active i { color: var(--brand) !important; }
.nav-item i {
    width: 16px;
    text-align: center;
    font-size: .88rem;
    flex-shrink: 0;
    color: var(--sidebar-text);
    transition: color var(--transition);
}
.nav-item:hover i { color: #dde8f8; }
.nav-item .nav-arrow { transition: transform .2s; margin-left: auto; font-size: .7rem; opacity: .5; }
.nav-item[aria-expanded="true"] .nav-arrow { transform: rotate(180deg); }
.nav-item .nav-badge {
    margin-left: auto;
    background: var(--brand);
    color: #fff;
    font-size: .62rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 99px;
    line-height: 1.6;
}

.nav-group { background: rgba(0,0,0,.12); }
.nav-child { padding-left: 2.75rem !important; font-size: .79rem; }
.nav-child i { font-size: .78rem !important; }

/* Sidebar footer */
.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,.06);
    padding: .5rem 0;
}
.sidebar-footer .nav-item { font-size: .79rem; }

/* ════════════════════════════════════════════════════════════
   MAIN CONTENT AREA
   ════════════════════════════════════════════════════════════ */
.main-content {
    margin-left: var(--sidebar-width);
    padding-top: var(--topbar-height);
    min-height: 100vh;
    transition: margin-left var(--transition);
}
.main-content.expanded { margin-left: 0; }
.content-wrapper {
    padding: 1.6rem 1.75rem;
    max-width: 1600px;
}

/* ════════════════════════════════════════════════════════════
   PAGE HEADER
   ════════════════════════════════════════════════════════════ */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.4rem;
    flex-wrap: wrap;
    gap: .75rem;
}
.page-header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    letter-spacing: -.02em;
}
.page-header p {
    margin: .15rem 0 0;
    font-size: .8rem;
    color: var(--text-muted);
}

/* Module sub-nav */
.module-sub-nav {
    display: flex;
    gap: .2rem;
    margin-bottom: 1.2rem;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .35rem .4rem;
}
.module-sub-nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: .8rem;
    font-weight: 500;
    padding: .3rem .9rem;
    border-radius: .4rem;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
}
.module-sub-nav a:hover { background: var(--bg); color: var(--text); }
.module-sub-nav a.active {
    background: var(--brand);
    color: #fff;
    font-weight: 600;
}

/* ════════════════════════════════════════════════════════════
   CARDS
   ════════════════════════════════════════════════════════════ */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    background: var(--surface);
    transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow); }
.card-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: .9rem 1.25rem;
    font-weight: 600;
    font-size: .87rem;
    border-radius: var(--radius) var(--radius) 0 0 !important;
    color: var(--text);
}
.card-footer {
    background: var(--surface-2);
    border-top: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius) !important;
    padding: .75rem 1.25rem;
}
.card-body { padding: 1.25rem; }

/* ════════════════════════════════════════════════════════════
   STAT CARDS
   ════════════════════════════════════════════════════════════ */
.stat-card {
    border-radius: var(--radius);
    padding: 1.3rem 1.4rem;
    color: #fff;
    position: relative;
    overflow: hidden;
    min-height: 108px;
    border: none;
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,.12) 0%, transparent 60%);
    pointer-events: none;
}
.stat-card .stat-icon {
    position: absolute;
    right: 1.1rem;
    bottom: 1rem;
    font-size: 3rem;
    opacity: .15;
    pointer-events: none;
}
.stat-card .stat-label { font-size: .75rem; opacity: .85; text-transform: uppercase; letter-spacing: .06em; margin-bottom: .35rem; }
.stat-card .stat-value { font-size: 1.8rem; font-weight: 800; line-height: 1; letter-spacing: -.03em; }
.stat-card .stat-change { font-size: .73rem; margin-top: .45rem; opacity: .9; display: flex; align-items: center; gap: .3rem; }
.stat-card .stat-sub { font-size: .75rem; opacity: .78; margin-top: .3rem; }

/* ════════════════════════════════════════════════════════════
   TABLES
   ════════════════════════════════════════════════════════════ */
.table {
    color: var(--text);
    border-color: var(--border-light);
}
.table th {
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border) !important;
    padding: .65rem .9rem;
    white-space: nowrap;
    background: var(--surface-2);
}
.table td {
    padding: .65rem .9rem;
    font-size: .84rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
.table-hover > tbody > tr {
    transition: background var(--transition);
}
.table-hover > tbody > tr:hover > td {
    background: #f0f7ff;
}
.table-dark th { background: #1e293b !important; color: #e2e8f0 !important; }

/* ════════════════════════════════════════════════════════════
   BUTTONS
   ════════════════════════════════════════════════════════════ */
.btn {
    font-size: .83rem;
    font-weight: 500;
    border-radius: .55rem;
    padding: .45rem 1rem;
    transition: all var(--transition);
    letter-spacing: .01em;
}
.btn:active { transform: scale(.97); }
.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
    box-shadow: 0 2px 8px rgba(37,99,235,.25);
}
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); box-shadow: 0 4px 14px rgba(37,99,235,.35); }
.btn-outline-primary { border-color: var(--brand); color: var(--brand); }
.btn-outline-primary:hover { background: var(--brand); color: #fff; }
.btn-success { box-shadow: 0 2px 8px rgba(16,185,129,.22); }
.btn-danger  { box-shadow: 0 2px 8px rgba(239,68,68,.22); }

.btn-sm  { padding: .3rem .7rem; font-size: .78rem; border-radius: .45rem; }
.btn-xs  { padding: .2rem .55rem; font-size: .72rem; border-radius: .38rem; }

/* ════════════════════════════════════════════════════════════
   FORMS
   ════════════════════════════════════════════════════════════ */
.form-control, .form-select {
    border: 1px solid var(--border);
    border-radius: .55rem;
    font-size: .84rem;
    color: var(--text);
    background: var(--surface);
    padding: .45rem .85rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus, .form-select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
    background: #fff;
    outline: none;
}
.form-control::placeholder { color: #b0bec5; }
.form-label { font-size: .8rem; font-weight: 600; color: var(--text); margin-bottom: .35rem; }
.form-text  { font-size: .75rem; color: var(--text-light); }

.input-group .form-control { border-radius: 0; }
.input-group .form-control:first-child { border-radius: .55rem 0 0 .55rem; }
.input-group .form-control:last-child  { border-radius: 0 .55rem .55rem 0; }
.input-group-text {
    background: var(--surface-2);
    border-color: var(--border);
    font-size: .83rem;
    color: var(--text-muted);
}

/* ════════════════════════════════════════════════════════════
   BADGES
   ════════════════════════════════════════════════════════════ */
.badge {
    font-size: .7rem;
    font-weight: 600;
    padding: .25em .65em;
    border-radius: .4rem;
    letter-spacing: .02em;
}

/* Status badge helpers — matches getStatusBadge() output */
.badge.bg-success-subtle  { background: #d1fae5 !important; color: #065f46 !important; }
.badge.bg-warning-subtle  { background: #fef3c7 !important; color: #92400e !important; }
.badge.bg-danger-subtle   { background: #fee2e2 !important; color: #991b1b !important; }
.badge.bg-info-subtle     { background: #e0f2fe !important; color: #0369a1 !important; }
.badge.bg-secondary-subtle{ background: #f1f5f9 !important; color: #475569 !important; }
.badge.bg-primary-subtle  { background: #eff6ff !important; color: #1e40af !important; }

/* ════════════════════════════════════════════════════════════
   ALERTS
   ════════════════════════════════════════════════════════════ */
.alert {
    border-radius: var(--radius-sm);
    border: none;
    font-size: .84rem;
    padding: .8rem 1.1rem;
}
.alert-info    { background: #e0f2fe; color: #0369a1; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-danger  { background: #fee2e2; color: #991b1b; }

/* ════════════════════════════════════════════════════════════
   MODALS
   ════════════════════════════════════════════════════════════ */
.modal-content {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.modal-header {
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.4rem;
    border-radius: var(--radius) var(--radius) 0 0;
}
.modal-header .modal-title { font-size: .95rem; font-weight: 700; }
.modal-footer {
    border-top: 1px solid var(--border);
    padding: .85rem 1.4rem;
}
.modal-body { padding: 1.25rem 1.4rem; }

/* ════════════════════════════════════════════════════════════
   OFFLINE INDICATOR
   ════════════════════════════════════════════════════════════ */
#offlineBanner {
    position: fixed;
    bottom: 1.2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    background: #1e293b;
    color: #f8fafc;
    border-radius: var(--radius);
    padding: .65rem 1.4rem;
    display: flex;
    align-items: center;
    gap: .75rem;
    font-size: .84rem;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s, transform .3s;
    transform: translateX(-50%) translateY(20px);
    min-width: 260px;
    justify-content: center;
}
#offlineBanner.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}
#offlineBanner.offline { background: #991b1b; }
#offlineBanner.syncing { background: #1d4ed8; }
#offlineBanner.online  { background: #065f46; }
.offline-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: currentColor; opacity: .85;
    animation: pulse-dot 1.5s infinite;
}
@keyframes pulse-dot { 0%,100%{opacity:.3} 50%{opacity:1} }

/* Sync queue badge (top-right) */
#syncQueueBadge {
    position: fixed;
    bottom: 1.2rem;
    right: 1.2rem;
    z-index: 9998;
    background: var(--amber);
    color: #fff;
    border-radius: 99px;
    padding: .4rem .9rem;
    font-size: .75rem;
    font-weight: 700;
    display: none;
    box-shadow: var(--shadow);
    cursor: pointer;
}
#syncQueueBadge.show { display: block; }

/* ════════════════════════════════════════════════════════════
   MISC UTILITIES
   ════════════════════════════════════════════════════════════ */
.text-truncate-2 {
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Highlight on focus-within for form sections */
.form-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.form-section:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-muted); }

/* Progress bar */
.progress { height: 6px; border-radius: 99px; background: var(--border); }
.progress-bar { border-radius: 99px; background: var(--brand); }

/* Invoice / quote summary box */
.total-box {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem 1.25rem;
}

/* ── DataTables overrides ─────────────────────────────────── */
div.dataTables_wrapper div.dataTables_filter input {
    border: 1px solid var(--border);
    border-radius: .45rem;
    padding: .3rem .75rem;
    font-size: .8rem;
    margin-left: .5rem;
}
div.dataTables_wrapper div.dataTables_length select {
    border: 1px solid var(--border);
    border-radius: .45rem;
    padding: .3rem .5rem;
    font-size: .8rem;
}
.dataTables_paginate .page-item .page-link {
    border-radius: .4rem !important;
    font-size: .8rem;
}

/* ════════════════════════════════════════════════════════════
   PRINT STYLES
   ════════════════════════════════════════════════════════════ */
@media print {
    .sidebar, .module-sub-nav, nav, .no-print, #offlineBanner,
    #syncQueueBadge, .stat-icon, .page-header .d-flex,
    .chart-container, canvas { display: none !important; }
    .main-content { margin-left: 0 !important; padding-top: 0 !important; }
    .card { box-shadow: none !important; break-inside: avoid; border: 1px solid #dee2e6 !important; }
    .card-header { border-bottom: 1px solid #dee2e6 !important; }
    body { background: #fff; font-size: 11pt; color: #000; }
    .print-only { display: block !important; }
    h1 .fas, h1 .far, .card-header .fas { display: none !important; }
    .stat-card { color: #000 !important; }
    table { font-size: 9pt; }
    a { text-decoration: none; color: #000; }
    .badge {
        background: transparent !important;
        color: #000 !important;
        border: 1px solid #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    body::after { display: none !important; content: none !important; }
    .attendance-print-week { page-break-inside: avoid; }
    .invoice-footer, .inv-footer, .doc-footer,
    [class*="invoice-footer"], [class*="doc-footer"] {
        display: block !important; visibility: visible !important;
        opacity: 1 !important; position: relative !important;
        page-break-inside: avoid !important;
        border-top: 1px solid #ccc !important;
        padding-top: 8px !important; margin-top: 16px !important;
        font-size: 9pt; color: #444;
    }
    .invoice-totals, .inv-totals { page-break-inside: avoid !important; }
}
.print-only { display: none; }

/* ════════════════════════════════════════════════════════════
   RESPONSIVE — mobile
   ════════════════════════════════════════════════════════════ */
@media (max-width: 992px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.mobile-open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .main-content { margin-left: 0 !important; }
    .content-wrapper { padding: 1rem; }
    .stat-card .stat-value { font-size: 1.5rem; }
}

/* ════════════════════════════════════════════════════════════
   PWA INSTALL PROMPT
   ════════════════════════════════════════════════════════════ */
#pwaInstallPrompt {
    position: fixed;
    bottom: 4rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9990;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 320px;
    max-width: 480px;
    display: none;
}
#pwaInstallPrompt.show { display: flex; }
