/* ── Root Variables ─────────────────────────────────────────────────────── */
:root {
    --sidebar-width: 240px;
    --sidebar-bg: #1e2a3a;
    --sidebar-text: #a8b5c8;
    --sidebar-active: #ffffff;
    --sidebar-active-bg: #2d6cdf;
    --sidebar-hover-bg: #27374d;
    --accent: #2d6cdf;
    --accent-light: #e8f0fd;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --bg: #f4f6fb;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --shadow: 0 1px 4px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
}

/* ── Reset & Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    font-size: 14px;
}
a { text-decoration: none; color: inherit; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
#sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform .25s ease;
    /* Prevent sidebar from stretching or causing layout shift */
    flex-shrink: 0;
}

.sidebar-brand {
    padding: 22px 20px 18px;
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.07);
    display: flex;
    align-items: center;
    letter-spacing: .3px;
    flex-shrink: 0;
}
.sidebar-brand i { font-size: 20px; color: var(--accent); }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
}
.sidebar-user-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #fff; line-height: 1.2; }
.sidebar-user-role { font-size: 11px; color: var(--sidebar-text); }

.sidebar-nav {
    list-style: none;
    padding: 10px 0;
    margin: 0;
    flex: 1;
}
.sidebar-nav-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    color: rgba(168,181,200,.5);
    padding: 16px 20px 6px;
    text-transform: uppercase;
}
.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--sidebar-text);
    font-size: 13.5px;
    font-weight: 500;
    transition: background .15s, color .15s;
}
.sidebar-nav li a i { font-size: 16px; width: 18px; flex-shrink: 0; }
.sidebar-nav li a:hover { background: var(--sidebar-hover-bg); color: #fff; }
.sidebar-nav li a.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active);
    font-weight: 600;
}

/* ── Main Content ───────────────────────────────────────────────────────── */
#main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* Prevent sidebar from ever overlapping content */
    position: relative;
    z-index: 1;
    width: calc(100% - var(--sidebar-width));
    max-width: 100%;
    overflow-x: hidden;
}

/* ── Topnav ─────────────────────────────────────────────────────────────── */
.topnav {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0 28px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 800;
    box-shadow: 0 1px 0 var(--border);
    width: 100%;
}
.topnav-title { font-size: 18px; font-weight: 700; color: var(--text); }
.topnav-right { display: flex; align-items: center; gap: 12px; }
.topnav-user  { font-size: 13px; font-weight: 600; color: var(--text-muted); gap: 5px; }

/* ── Page Content ───────────────────────────────────────────────────────── */
.page-content { padding: 28px; flex: 1; }

/* ── Stat Cards ─────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 18px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 22px 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
    border: 1px solid var(--border);
    transition: box-shadow .2s, transform .2s;
}
.stat-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,.1); transform: translateY(-1px); }
.stat-icon {
    width: 50px; height: 50px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}
.stat-icon.blue   { background: #e8f0fd; color: var(--accent); }
.stat-icon.green  { background: #dcfce7; color: var(--success); }
.stat-icon.amber  { background: #fef3c7; color: var(--warning); }
.stat-icon.red    { background: #fee2e2; color: var(--danger); }
.stat-icon.purple { background: #f3e8ff; color: #7c3aed; }

.stat-info .stat-label {
    font-size: 11.5px; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .5px;
}
.stat-info .stat-value {
    font-size: 23px; font-weight: 800; color: var(--text);
    margin-top: 2px; line-height: 1.1;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 16px 22px;
    font-weight: 700;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-body { padding: 22px; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table { font-size: 13.5px; margin-bottom: 0; }
.table th {
    background: #f8fafc;
    font-weight: 700;
    font-size: 11.5px;
    letter-spacing: .4px;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border) !important;
    padding: 12px 16px;
    white-space: nowrap;
}
.table td {
    padding: 13px 16px;
    vertical-align: middle;
    border-color: var(--border);
    color: var(--text);
}
.table tbody tr:hover { background: #f8fafc; }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge-paid {
    background: #dcfce7; color: #16a34a;
    padding: 4px 10px; border-radius: 20px;
    font-size: 12px; font-weight: 600;
    display: inline-flex; align-items: center; gap: 4px;
    white-space: nowrap;
}
.badge-pending {
    background: #fef3c7; color: #d97706;
    padding: 4px 10px; border-radius: 20px;
    font-size: 12px; font-weight: 600;
    display: inline-flex; align-items: center; gap: 4px;
    white-space: nowrap;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn-primary { background: var(--accent); border-color: var(--accent); font-weight: 600; border-radius: 8px; font-size: 13.5px; }
.btn-primary:hover { background: #1a57d0; border-color: #1a57d0; }
.btn-sm { padding: 6px 14px; font-size: 12.5px; border-radius: 7px; }
.btn-outline-secondary { border-radius: 8px; font-size: 13.5px; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-label { font-weight: 600; font-size: 13px; color: var(--text); margin-bottom: 5px; }
.form-control, .form-select {
    border-radius: 8px;
    border-color: var(--border);
    font-size: 13.5px;
    padding: 9px 12px;
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(45,108,223,.12);
}
.input-group .form-control:focus { z-index: 3; }

/* ── Auth Pages ─────────────────────────────────────────────────────────── */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e2a3a 0%, #2d6cdf 100%);
    padding: 24px;
}
.auth-card {
    background: #fff;
    border-radius: 16px;
    padding: 40px 36px;
    width: 100%;
    max-width: 430px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo-icon {
    width: 56px; height: 56px;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 14px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 28px;
    margin-bottom: 12px;
}
.auth-logo h1 { font-size: 22px; font-weight: 800; color: var(--text); margin: 0; }
.auth-logo p  { font-size: 13px; color: var(--text-muted); margin: 4px 0 0; }
.auth-divider { text-align: center; margin: 20px 0; position: relative; }
.auth-divider::before { content:''; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: var(--border); }
.auth-divider span { background: #fff; padding: 0 10px; position: relative; font-size: 12px; color: var(--text-muted); }

/* ── Page Header ────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}
.page-header h2 { font-size: 22px; font-weight: 800; margin: 0; color: var(--text); }
.page-header p  { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; }

/* ── Icon Buttons in Tables ─────────────────────────────────────────────── */
.table-actions { display: flex; gap: 6px; }
.btn-icon {
    width: 32px; height: 32px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-muted);
    font-size: 13px;
    transition: all .15s;
    cursor: pointer;
}
.btn-icon:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-icon.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ── Empty State ────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 56px 20px; color: var(--text-muted); }
.empty-state i { font-size: 48px; opacity: .25; margin-bottom: 12px; display: block; }
.empty-state p  { font-size: 15px; margin: 0; }

/* ── Chart ──────────────────────────────────────────────────────────────── */
.chart-wrap { position: relative; height: 240px; }

/* ── Filter Bar ─────────────────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
    background: #fafbfd;
}
.filter-bar .form-control,
.filter-bar .form-select { font-size: 13px; padding: 7px 10px; border-radius: 7px; }

/* ── Avatar circle ──────────────────────────────────────────────────────── */
.avatar-circle {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; flex-shrink: 0;
}

/* ── Sidebar overlay (mobile) ───────────────────────────────────────────── */
#sidebarOverlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.45);
    z-index: 999;
}

/* ── Mobile Toggle ──────────────────────────────────────────────────────── */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
}
.sidebar-toggle:hover { background: var(--bg); }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    #sidebar { transform: translateX(-100%); }
    #sidebar.open { transform: translateX(0); }
    #main-content {
        margin-left: 0;
        width: 100%;
    }
    .sidebar-toggle { display: block; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .page-content { padding: 16px; }
    .auth-card { padding: 28px 20px; }
    .topnav { padding: 0 16px; }
    .filter-bar { padding: 12px 16px; }
}
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
}

/* ── Utility ────────────────────────────────────────────────────────────── */
.text-money { font-weight: 700; font-size: 14.5px; }
.fw-800 { font-weight: 800; }
.text-accent { color: var(--accent); }

/* ── Print / PDF ─────────────────────────────────────────────────────────── */
@media print {
    /* Hide everything except main content */
    #sidebar,
    .topnav,
    .no-print,
    .sidebar-toggle,
    #sidebarOverlay {
        display: none !important;
    }

    /* Show print-only elements */
    .print-only {
        display: block !important;
    }

    /* Reset layout — no sidebar offset */
    #main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .page-content {
        padding: 0 !important;
    }

    body {
        font-size: 12px;
        color: #000;
        background: #fff;
    }

    /* Cards print flat */
    .card {
        border: 1px solid #ccc !important;
        box-shadow: none !important;
        page-break-inside: avoid;
        margin-bottom: 16px !important;
    }

    .card-header {
        background: #f5f5f5 !important;
        border-bottom: 1px solid #ccc !important;
    }

    /* Tables */
    .table {
        font-size: 11px;
    }

    .table th {
        background: #f5f5f5 !important;
        color: #000 !important;
        border-bottom: 1px solid #999 !important;
    }

    .table td, .table th {
        padding: 6px 8px !important;
    }

    /* Stat cards in a grid when printing */
    .stats-grid {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 8px !important;
        margin-bottom: 16px !important;
    }

    .stat-card {
        border: 1px solid #ccc !important;
        box-shadow: none !important;
        padding: 10px !important;
        page-break-inside: avoid;
    }

    .stat-value {
        font-size: 18px !important;
    }

    /* Badges stay readable */
    .badge-paid, .badge-pending {
        border: 1px solid #999;
        padding: 2px 6px;
        border-radius: 4px;
        font-size: 10px;
    }

    /* Don't print chart canvases (they don't render well) */
    .chart-wrap {
        display: none !important;
    }

    /* Remove Bootstrap row gutters for print */
    .row { margin: 0 !important; }
    .col-lg-6 { width: 50% !important; float: left; padding: 0 4px !important; }

    /* Page breaks */
    h2, h3 { page-break-after: avoid; }
    tr { page-break-inside: avoid; }

    a[href]:after { content: none !important; }
}
