/* ============================================================
   EXPENSE MANAGER — DESIGN SYSTEM
   Aesthetic: Refined financial / Luxury utility
   Fonts: DM Sans (body) + DM Mono (numbers)
   Color: Deep slate base, warm gold accent
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
    --sidebar-width: 256px;
    --topbar-height: 60px;

    /* Brand palette */
    --color-bg:           #f5f6f8;
    --color-surface:      #ffffff;
    --color-border:       #e2e6ec;
    --color-border-soft:  #edf0f4;

    /* Sidebar */
    --sidebar-bg:         #0f1923;
    --sidebar-bg-hover:   rgba(255,255,255,0.06);
    --sidebar-bg-active:  rgba(255,255,255,0.10);
    --sidebar-accent:     #c8a96e;   /* warm gold */
    --sidebar-text:       rgba(255,255,255,0.72);
    --sidebar-text-hover: #ffffff;
    --sidebar-divider:    rgba(255,255,255,0.06);

    /* Primary action */
    --color-primary:      #1a4b8c;
    --color-primary-h:    #163e74;
    --color-primary-l:    rgba(26,75,140,0.08);

    /* Semantic */
    --color-success:      #0d7a55;
    --color-success-bg:   #edf7f2;
    --color-danger:       #b52b27;
    --color-danger-bg:    #fdf1f0;
    --color-warning:      #b05c00;
    --color-warning-bg:   #fff7ed;
    --color-info:         #1557a0;
    --color-info-bg:      #eef4fd;

    /* Text scale */
    --text-primary:       #111827;
    --text-secondary:     #4b5563;
    --text-muted:         #9ca3af;

    /* Shadows */
    --shadow-card:        0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.05);
    --shadow-card-hover:  0 2px 8px rgba(0,0,0,0.08), 0 8px 24px rgba(0,0,0,0.08);
    --shadow-elevated:    0 4px 24px rgba(0,0,0,0.10);

    /* Radii */
    --radius-sm:          6px;
    --radius-md:          10px;
    --radius-lg:          14px;
    --radius-xl:          18px;

    /* Transitions */
    --transition-fast:    0.15s ease;
    --transition-base:    0.22s ease;
}

/* ── Reset / Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    background-color: var(--color-bg);
    color: var(--text-primary);
    font-family: 'DM Sans', 'Segoe UI', system-ui, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Numbers always in DM Mono for financial data */
.metric-value,
.mono,
td.numeric,
th.numeric {
    font-family: 'DM Mono', 'Fira Mono', monospace;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    z-index: 100;
}
.sidebar::-webkit-scrollbar { display: none; }

/* Brand */
.sidebar-brand {
    padding: 1.25rem 1.1rem 1rem;
    border-bottom: 1px solid var(--sidebar-divider);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.sidebar-brand-logo {
    width: 30px;
    height: 30px;
    background: linear-gradient(135deg, var(--sidebar-accent), #e8c98a);
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    color: #0f1923;
    flex-shrink: 0;
}

.sidebar-brand-name {
    color: #ffffff;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
    text-decoration: none;
}

.sidebar-brand-name:hover { color: #ffffff; text-decoration: none; }

/* Nav */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0.5rem 0.75rem;
    flex: 1;
}

.sidebar-group-title {
    color: rgba(255,255,255,0.32);
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 1rem 0.6rem 0.35rem;
}

.sidebar-link {
    color: var(--sidebar-text);
    text-decoration: none;
    padding: 0.575rem 0.75rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background var(--transition-fast), color var(--transition-fast);
    position: relative;
}

.sidebar-link i { opacity: 0.75; transition: opacity var(--transition-fast); }

.sidebar-link:hover {
    background-color: var(--sidebar-bg-hover);
    color: var(--sidebar-text-hover);
    text-decoration: none;
}

.sidebar-link:hover i { opacity: 1; }

/* Active indicator — gold left bar */
.sidebar-link.active-nav {
    background-color: var(--sidebar-bg-active);
    color: #ffffff;
}
.sidebar-link.active-nav i { opacity: 1; }
.sidebar-link.active-nav::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    height: 60%;
    width: 3px;
    background: var(--sidebar-accent);
    border-radius: 0 3px 3px 0;
}

.sidebar-toggle {
    display: flex;
    justify-content: space-between;
}

.sidebar-toggle .bi-chevron-down {
    font-size: 0.7rem;
    opacity: 0.5;
    transition: transform var(--transition-base);
}
.sidebar-toggle[aria-expanded="true"] .bi-chevron-down { transform: rotate(180deg); }

.sidebar-submenu {
    margin: 2px 0 4px;
    padding-left: 0.35rem;
}

.sidebar-sublink {
    color: rgba(255,255,255,0.58);
    text-decoration: none;
    padding: 0.48rem 0.75rem 0.48rem 1.6rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    font-size: 0.865rem;
    font-weight: 400;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar-sublink:hover {
    background-color: var(--sidebar-bg-hover);
    color: rgba(255,255,255,0.9);
    text-decoration: none;
}

.sidebar-sublink i { font-size: 0.78rem; opacity: 0.65; }

/* Footer */
.sidebar-footer {
    padding: 0.75rem 1rem 1rem;
    border-top: 1px solid var(--sidebar-divider);
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.sidebar-footer-avatar {
    width: 30px;
    height: 30px;
    background: linear-gradient(135deg, #2a4a6b, #1a4b8c);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-footer-name {
    color: rgba(255,255,255,0.6);
    font-size: 0.82rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Main content ──────────────────────────────────────────── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--color-bg);
}

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 1.5rem;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 90;
}

.topbar-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.topbar-user {
    border-right: 1px solid var(--color-border);
    line-height: 1.2;
    padding-right: 0.85rem;
    margin-right: 0.25rem;
}

.topbar-user .user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.topbar-user .user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ── Page content ──────────────────────────────────────────── */
.page-content {
    padding: 1.75rem 1.75rem 2.5rem;
    flex: 1;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    transition: box-shadow var(--transition-base);
}

.card:hover { box-shadow: var(--shadow-card-hover); }

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--color-border-soft);
    padding: 1rem 1.25rem;
}

.card-body { padding: 1.25rem; }

/* ============================================================
   METRIC CARDS  (KPI tiles)
   ============================================================ */
.metric-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    padding: 1.1rem 1.25rem;
    min-height: 110px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
    transition: box-shadow var(--transition-base), transform var(--transition-base);
}
.metric-card:hover {
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-1px);
}

.metric-card-icon {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 36px;
    height: 36px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
}

.metric-card-icon.income  { background: var(--color-success-bg); color: var(--color-success); }
.metric-card-icon.expense { background: var(--color-danger-bg);  color: var(--color-danger);  }
.metric-card-icon.flow    { background: var(--color-info-bg);    color: var(--color-info);    }
.metric-card-icon.debt    { background: var(--color-warning-bg); color: var(--color-warning); }

.metric-label {
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.metric-value {
    font-size: 1.6rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-top: 0.25rem;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.metric-value.income  { color: var(--color-success); }
.metric-value.expense { color: var(--color-danger); }

.metric-note {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

/* ============================================================
   PAGE HEADING
   ============================================================ */
.page-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.page-heading h2 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin: 0 0 0.15rem;
}

.page-heading .subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 0;
}

/* ============================================================
   SECTION TABS  (filter pills)
   ============================================================ */
.section-tabs {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    display: inline-flex;
    flex-wrap: wrap;
    gap: 3px;
    padding: 4px;
    margin-bottom: 1.25rem;
}

.section-tab {
    border-radius: 7px;
    color: var(--text-secondary);
    font-size: 0.855rem;
    font-weight: 500;
    padding: 0.42rem 0.85rem;
    text-decoration: none;
    transition: background var(--transition-fast), color var(--transition-fast);
    white-space: nowrap;
}

.section-tab:hover {
    background: var(--color-bg);
    color: var(--text-primary);
    text-decoration: none;
}

.section-tab.active {
    background: var(--color-primary);
    color: #fff;
    font-weight: 600;
}

/* ============================================================
   TABLES
   ============================================================ */
.table {
    color: var(--text-primary);
    font-size: 0.9rem;
    border-collapse: separate;
    border-spacing: 0;
}

.table thead th {
    background: #f9fafb;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0.7rem 0.85rem;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.table tbody td {
    padding: 0.75rem 0.85rem;
    border-bottom: 1px solid var(--color-border-soft);
    vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }

.table tbody tr {
    transition: background var(--transition-fast);
}

.table-hover tbody tr:hover td { background: #f8fafc; }

/* ============================================================
   FORMS
   ============================================================ */
.form-label {
    font-size: 0.84rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.form-control,
.form-select {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    padding: 0.48rem 0.75rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    background-color: var(--color-surface);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(26,75,140,0.10);
    outline: none;
}

.form-control::placeholder { color: var(--text-muted); }

.input-group-text {
    background: #f5f6f8;
    border: 1px solid var(--color-border);
    color: var(--text-muted);
    font-size: 0.88rem;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.44rem 1rem;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.btn-primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--color-primary-h);
    border-color: var(--color-primary-h);
    color: #fff;
    box-shadow: 0 2px 8px rgba(26,75,140,0.25);
}

.btn-outline-secondary {
    border-color: var(--color-border);
    color: var(--text-secondary);
    background: transparent;
}
.btn-outline-secondary:hover {
    background: var(--color-bg);
    border-color: #c5cdd8;
    color: var(--text-primary);
}

.btn-outline-danger {
    border-color: #f5c2c2;
    color: var(--color-danger);
    background: transparent;
}
.btn-outline-danger:hover {
    background: var(--color-danger-bg);
    border-color: var(--color-danger);
    color: var(--color-danger);
}

.btn-sm {
    font-size: 0.81rem;
    padding: 0.32rem 0.75rem;
}

.btn-icon {
    align-items: center;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    display: inline-flex;
    height: 32px;
    justify-content: center;
    padding: 0;
    width: 32px;
    transition: all var(--transition-fast);
}
.btn-icon:hover {
    background: var(--color-bg);
    border-color: #c5cdd8;
    color: var(--text-primary);
}

/* ============================================================
   BADGES / STATUS
   ============================================================ */
.badge {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    padding: 0.28em 0.6em;
    border-radius: 4px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3em;
    font-size: 0.76rem;
    font-weight: 600;
    padding: 0.2em 0.55em;
    border-radius: 20px;
}
.status-badge.active  { background: var(--color-success-bg); color: var(--color-success); }
.status-badge.closed  { background: #f3f4f6; color: #6b7280; }
.status-badge.warning { background: var(--color-warning-bg); color: var(--color-warning); }

/* ============================================================
   USER AVATAR
   ============================================================ */
.user-avatar {
    align-items: center;
    background: linear-gradient(135deg, #1a3a5c, var(--color-primary));
    border-radius: 50%;
    color: #fff;
    display: inline-flex;
    flex: 0 0 auto;
    font-size: 0.68rem;
    font-weight: 700;
    height: 32px;
    justify-content: center;
    width: 32px;
    letter-spacing: 0.05em;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    background: #f9fafb;
    border: 1.5px dashed var(--color-border);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    padding: 2.5rem 1.5rem;
    text-align: center;
    font-size: 0.9rem;
}

.empty-state i {
    font-size: 1.75rem;
    display: block;
    margin-bottom: 0.6rem;
    opacity: 0.4;
}

/* ============================================================
   ROLE CHECK GRID
   ============================================================ */
.role-check-grid { display: grid; gap: 0.4rem; }
.role-check-grid-inline { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.role-check {
    align-items: center;
    background: #f9fafb;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    display: flex;
    gap: 0.5rem;
    margin: 0;
    padding: 0.4rem 0.65rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background var(--transition-fast);
}
.role-check:hover { background: var(--color-primary-l); }

/* ============================================================
   CHART
   ============================================================ */
.chart-container {
    position: relative;
    width: 100%;
    height: 34vh;
    padding-top: 6px;
}
.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ============================================================
   AUTH / LOGIN PAGES
   ============================================================ */
.public-shell { min-height: 100vh; background-color: var(--color-bg); }
.public-content { min-height: 100vh; }

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(145deg, #0f1923 0%, #1a2e42 50%, #0f1923 100%);
}

.auth-card-wrapper { max-width: 360px; width: 100%; }

.auth-card-wrapper .card {
    border: 1px solid rgba(255,255,255,0.06);
    background: rgba(255,255,255,0.97);
    border-radius: var(--radius-xl);
    box-shadow: 0 24px 80px rgba(0,0,0,0.4);
}

.auth-card-wrapper .card-body { padding: 2rem !important; }

.auth-logo {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #c8a96e, #e8c98a);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.25rem;
    font-size: 1.4rem;
    color: #0f1923;
}

/* ============================================================
   DATATABLES  (override)
   ============================================================ */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.32rem 0.65rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    background: var(--color-surface);
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: var(--radius-sm) !important;
    padding: 0.25rem 0.6rem !important;
    font-size: 0.82rem !important;
    color: var(--text-secondary) !important;
    border: 1px solid transparent !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
    color: #fff !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: var(--color-bg) !important;
    border-color: var(--color-border) !important;
    color: var(--text-primary) !important;
}

.dataTables_info { font-size: 0.82rem; color: var(--text-muted); }

/* ============================================================
   SELECT2  (override)
   ============================================================ */
.select2-container--default .select2-selection--multiple {
    border-color: var(--color-border);
    border-radius: var(--radius-sm);
    min-height: 38px;
    background: var(--color-surface);
}
.select2-container--default.select2-container--focus .select2-selection--multiple {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(26,75,140,0.10);
}

/* ============================================================
   USER MANAGEMENT TABLE
   ============================================================ */
.user-management-table .clickable-row { cursor: pointer; }
.user-management-table .clickable-row:hover td { background: #f8fafc; }

/* ============================================================
   IMPERSONATION BANNER
   ============================================================ */
.alert-impersonation {
    background: #fef9ec;
    border: 1px solid #f5d77e;
    border-radius: var(--radius-md);
    color: #7a5200;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    margin-bottom: 1.25rem;
}

/* ============================================================
   REPORTS
   ============================================================ */
.report-page .table th,
.report-page .table td { vertical-align: middle; }

/* ============================================================
   SCROLLBAR (Webkit)
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d9e0; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #adb5bd; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 991.98px) {
    .app-shell { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        flex-direction: row;
        flex-wrap: wrap;
    }
    .topbar-user { display: none; }
    .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
    .page-content { padding: 1.25rem; }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
    body { background: #fff; }
    .sidebar, .topbar, .sidebar-footer,
    .report-toolbar, .alert, .d-print-none { display: none !important; }
    .page-content, .main-content { padding: 0 !important; margin: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #dee2e6 !important; }
}
