/* Omega Ledger — same design tokens and app-shell pattern as the sibling Recruitment
   Tracker app, per the official Omega_Softlogix_-_BRAND_GUIDE.pdf, so this reads as part
   of the same family of internal tools rather than a one-off. Colors #64DBE3 (bright
   cyan-teal) / #48AFB6 (deep teal) / #2B2A29 (near-black), font Montserrat. --navy is a
   further-darkened derivative of the brand teal (#48AFB6 alone is only 2.6:1 contrast
   against white — fails WCAG AA — so it's reserved for accents/borders, not text-on-teal
   backgrounds; --navy carries 7.44:1 contrast, used for the sidebar's active nav state,
   buttons, and headings). Left sidebar nav + mobile drawer, light & airy surfaces. */

:root {
    --navy: #175E64;
    --navy-deep: #0F3D40;
    --teal: #23838B;
    --teal-tint: #EAF6F7;
    --brand-cyan: #64DBE3;
    --brand-teal: #48AFB6;
    --amber: #F2A93B;
    --amber-deep: #D68F1F;
    --coral: #E8604C;
    --bg: #F7F9FA;
    --card: #FFFFFF;
    --ink: #2B2A29;
    --muted: #6B7685;
    --border: #E7EBEE;
    --green: #1A7F37;
    --green-bg: #DCF3E1;
    --hover-bg: #F4F6F7;
    --brand-text: var(--navy-deep);
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 1px 3px rgba(16, 24, 40, 0.06), 0 4px 12px rgba(16, 24, 40, 0.04);
    --sidebar-w: 240px;
}

/* Dark mode: applied explicitly via [data-theme="dark"] (the toggle button, persisted to
   localStorage) or automatically when the OS prefers dark and no explicit choice was made.
   --navy/--navy-deep are deliberately left alone - they're only ever used as button/gradient
   backgrounds paired with hardcoded white text, which stays correct regardless of page theme;
   --brand-text is the separate token for "brand-colored text on the page/card surface"
   (headings, active nav, form labels) that actually needs to lighten in the dark. */
:root[data-theme="dark"] {
    --bg: #12181B;
    --card: #1B2327;
    --ink: #E8EDEF;
    --muted: #93A0A8;
    --border: #2A343A;
    --teal-tint: #16262A;
    --hover-bg: #212B30;
    --brand-text: #7FE0E6;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]):not([data-theme="dark"]) {
        --bg: #12181B;
        --card: #1B2327;
        --ink: #E8EDEF;
        --muted: #93A0A8;
        --border: #2A343A;
        --teal-tint: #16262A;
        --hover-bg: #212B30;
        --brand-text: #7FE0E6;
    }
}

* { box-sizing: border-box; }

body {
    font-family: 'Montserrat', -apple-system, Segoe UI, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--ink);
}

h1, h2, h3 { font-family: 'Montserrat', sans-serif; font-weight: 600; color: var(--brand-text); letter-spacing: -0.01em; }

/* ==== App shell: sidebar + main content ==== */
.app-shell { display: flex; align-items: stretch; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar-brand { padding: 20px 20px 16px; }
.sidebar-brand img { height: 30px; }
.brand-fallback { font-family: 'Montserrat', sans-serif; font-weight: 700; font-size: 18px; color: var(--brand-text); }

.sidebar-nav { flex: 1; padding: 4px 12px; }
.nav-group-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin: 18px 12px 6px;
}
.nav-group-label:first-child { margin-top: 6px; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    margin-bottom: 2px;
    border-radius: 8px;
    color: var(--ink);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
}
.nav-link:hover { background: var(--hover-bg); }
.nav-link.is-active { background: var(--teal-tint); color: var(--brand-text); font-weight: 600; }
.nav-link.is-active .nav-icon { color: var(--brand-text); }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; color: var(--muted); }
.nav-link:hover .nav-icon, .nav-link.is-active .nav-icon { color: var(--brand-text); }

.sidebar-footer { padding: 14px 20px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar { background: var(--teal); color: #fff; border-radius: 50%; width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.user-chip-text { font-size: 13px; font-weight: 600; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.user-chip .role { display: block; color: var(--muted); font-size: 11px; font-weight: 500; }
.logout-link { color: var(--muted); flex-shrink: 0; display: inline-flex; }
.logout-link:hover { color: var(--coral); }
.logout-link svg { width: 17px; height: 17px; }

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-top: 10px;
    padding: 7px 8px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.theme-toggle:hover { color: var(--brand-text); border-color: var(--teal); }
.theme-toggle svg { width: 15px; height: 15px; flex-shrink: 0; }

.main-content { flex: 1; min-width: 0; }
.container { max-width: 1150px; margin: 28px auto; padding: 0 28px; }

/* ==== Mobile drawer ==== */
.mobile-topbar { display: none; }
.drawer-backdrop { display: none; }

@media (max-width: 960px) {
    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 14px;
        position: sticky;
        top: 0;
        z-index: 30;
        background: var(--card);
        border-bottom: 1px solid var(--border);
        padding: 10px 16px;
    }
    .drawer-toggle { background: none; border: none; padding: 4px; cursor: pointer; color: var(--brand-text); }
    .drawer-toggle svg { width: 22px; height: 22px; }

    .app-shell { position: relative; }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--shadow-md);
    }
    body.drawer-open .sidebar { transform: translateX(0); }
    body.drawer-open .drawer-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 26, 0.4);
        z-index: 35;
    }

    .container { padding: 0 14px; margin: 16px auto; }
    .card { padding: 16px; overflow-x: auto; }
    .table { min-width: 560px; }
    .kpi-row { flex-direction: column; }
    .filter-row { flex-wrap: wrap; }
}

/* ==== Cards ==== */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px 28px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}
.card h2:first-child, .card h3:first-child { margin-top: 0; }

/* ---- Tables ---- */
.table { width: 100%; border-collapse: collapse; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.table th, .table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.table thead th { background: var(--teal-tint); color: var(--brand-text); font-family: 'Montserrat', sans-serif; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); }
.table tbody tr:hover { background: var(--hover-bg); }
.table a { color: var(--teal); font-weight: 600; text-decoration: none; }
.table a:hover { text-decoration: underline; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--navy);
    color: #fff;
    border: none;
    padding: 9px 18px;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
}
.btn:hover { background: var(--navy-deep); }
.btn.secondary { background: var(--card); color: var(--brand-text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--teal-tint); border-color: var(--teal); }
.btn-link { background: none; border: none; color: var(--coral); cursor: pointer; padding: 0; font-size: 13px; text-decoration: underline; }

/* ---- Alerts ---- */
.alert { padding: 10px 16px; border-radius: 8px; margin-bottom: 14px; background: var(--teal-tint); border-left: 4px solid var(--teal); font-size: 14px; }
.alert.error { background: #FBE1DC; border-left-color: var(--coral); color: #9b2c2c; }
.alert.success { background: var(--green-bg); border-left-color: var(--green); color: #1e6b34; }
.alert code { background: rgba(0,0,0,.08); padding: 2px 6px; border-radius: 3px; font-size: 13px; }

.muted { color: var(--muted); }

/* ---- Forms ---- */
form label { display: block; margin: 12px 0 4px; font-size: 13px; font-weight: 600; color: var(--brand-text); }
form input[type=text], form input[type=email], form input[type=number], form input[type=password],
form input[type=date], form input[type=datetime-local], form input[type=search], form input[type=url],
form select, form textarea {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 14px;
    background: var(--card);
    color: var(--ink);
}
form input:focus, form select:focus, form textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-tint); }
form p { margin-top: 18px; margin-bottom: 0; }
form button[type=submit], form .btn { margin-top: 6px; }

/* Transactions filter row - not a <form p>-spaced form, a compact inline toolbar */
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0 4px; }
.filter-row input, .filter-row select { padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; width: auto; background: var(--card); color: var(--ink); }

.rt-inline-add { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
.rt-inline-add input[type=text] { width: auto; flex: 1; }

/* Receipts / attachments */
.attachment-current { margin-bottom: 8px; font-size: 13px; }
.attachment-current a { color: var(--brand-text); text-decoration: none; }
.attachment-current a:hover { text-decoration: underline; }
.receipt-icon { margin-left: 4px; text-decoration: none; }
form input[type=file] { width: 100%; padding: 8px 0; font-size: 13px; }

/* ---- Income/expense type badge ---- */
.txn-type { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.txn-type-income { background: var(--green-bg); color: var(--green); }
.txn-type-expense { background: #FBE1DC; color: var(--coral); }

/* ---- KPI tiles (dashboard + reports) ---- */
.kpi-row { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 16px; }
.kpi-tile {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px 22px;
    min-width: 150px;
    flex: 1;
    box-shadow: var(--shadow-sm);
    text-align: center;
}
.kpi-tile h2 { font-size: 28px; margin: 0 0 4px; color: var(--brand-text); }
.kpi-tile p { margin: 0; color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .03em; }
.kpi-income h2 { color: var(--green); }
.kpi-expense h2 { color: var(--coral); }

/* ---- Login page ---- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(160deg, var(--navy) 0%, var(--navy-deep) 100%); }
.login-box { width: 100%; max-width: 360px; padding: 0 16px; }
.login-box .card { text-align: center; padding: 40px 36px; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.3); border: none; }
.login-logo { max-height: 48px; margin-bottom: 14px; }
.login-box h2 { font-size: 22px; }

/* ---- Report tabs (pill style) ---- */
.report-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.report-tab {
    padding: 8px 16px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    background: var(--hover-bg);
}
.report-tab:hover { color: var(--brand-text); background: var(--teal-tint); }
.report-tab.is-active { background: var(--navy); color: #fff; }
.period-pills { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.period-pill {
    padding: 6px 14px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    color: var(--brand-text);
    background: var(--card);
    border: 1px solid var(--border);
}
.period-pill:hover { border-color: var(--teal); }
.period-pill.is-active { background: var(--teal-tint); border-color: var(--teal); color: var(--brand-text); }
