:root {
    /* Color Palette - Deep Business Blue Theme */
    --color-bg: #0f172a;
    --color-sidebar: #1e293b;
    --color-card: #1e293b;
    --color-border: #334155;
    --color-text-main: #f8fafc;
    --color-text-muted: #94a3b8;
    
    --color-primary: #6366f1; /* Indigo */
    --color-primary-hover: #4f46e5;
    --color-secondary: #0ea5e9; /* Sky */
    --color-secondary-hover: #0284c7;
    
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --color-info: #3b82f6;

    /* Subtle overlay tints (hover states, header/input backgrounds) — these
       need to flip from "lighten" to "darken" in light mode, so they're
       tokens rather than raw rgba(255,255,255,x) scattered through the file. */
    --overlay-weak: rgba(255, 255, 255, 0.05);
    --overlay-weaker: rgba(255, 255, 255, 0.02);
    --overlay-strong: rgba(0, 0, 0, 0.2);
    --gradient-bg: radial-gradient(circle at top right, #1e293b 0%, #0f172a 40%);

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;

    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Outfit', sans-serif;
}

[data-theme="light"] {
    --color-bg: #f1f5f9;
    --color-sidebar: #ffffff;
    --color-card: #ffffff;
    --color-border: #e2e8f0;
    --color-text-main: #0f172a;
    --color-text-muted: #64748b;

    --overlay-weak: rgba(0, 0, 0, 0.04);
    --overlay-weaker: rgba(0, 0, 0, 0.02);
    --overlay-strong: rgba(0, 0, 0, 0.05);
    --gradient-bg: radial-gradient(circle at top right, #ffffff 0%, #f1f5f9 40%);

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.06);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.08);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--color-bg);
    color: var(--color-text-main);
    font-family: var(--font-body);
    height: 100vh;
    overflow: hidden;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background-color: var(--color-sidebar);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    /* .sidebar itself doesn't scroll — .nav-links does — so the brand up top
       and the Save/Load buttons at the bottom always stay put. */
    overflow: hidden;
    height: 100vh;
}

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    background: var(--gradient-bg);
}

/* Brand */
.brand {
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--color-primary);
    margin-bottom: 3rem;
}

/* Navigation */
.nav-links {
    list-style: none;
    flex: 1;
    min-height: 0; /* required for a flex child to actually scroll instead of overflowing */
    overflow-y: auto;
    overflow-x: hidden;
    /* thin scrollbar so a 260px sidebar doesn't feel cramped */
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}

.nav-links::-webkit-scrollbar {
    width: 6px;
}

.nav-links::-webkit-scrollbar-thumb {
    background-color: var(--color-border);
    border-radius: 3px;
}

.nav-links li {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--color-text-muted);
    transition: all 0.2s;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-links li:hover {
    background-color: var(--overlay-weak);
    color: var(--color-text-main);
}

.nav-links li.active {
    background-color: var(--color-primary);
    color: white;
    box-shadow: var(--shadow-md);
}

.nav-links li.nav-header {
    cursor: default;
    pointer-events: none;
    padding: 0.75rem 1rem 0.25rem;
    margin-top: 0.5rem;
    margin-bottom: 0;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    font-weight: 700;
    background: transparent;
}

.nav-links li.nav-header:first-child {
    margin-top: 0;
}

.nav-links li.nav-divider {
    cursor: default;
    pointer-events: none;
    height: 1px;
    padding: 0;
    margin: 0.75rem 0.25rem 1rem;
    background-color: var(--color-border);
}

.nav-icon-row {
    display: flex;
    gap: 0.5rem;
    padding: 0 !important;
    margin-bottom: 0 !important;
    background: transparent !important;
}

.nav-icon-btn {
    flex: 1;
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    border-radius: var(--radius-md);
    padding: 0.6rem 0;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-icon-btn:hover {
    background-color: var(--overlay-weak);
    color: var(--color-text-main);
}

.nav-icon-btn.active {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
    box-shadow: var(--shadow-md);
}

/* Buttons */
/* Shared so button labels never wrap mid-word (which throws off flex-end-
   aligned rows like the currency-add toolbar — a 2-line "Fetch Latest Rates"
   next to a 1-line "Add Currency" renders with mismatched top edges). */
.btn-primary, .btn-secondary, .btn-ghost {
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-primary {
    background-color: var(--color-primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary:hover {
    background-color: var(--color-primary-hover);
}

.btn-secondary {
    background-color: var(--color-secondary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-secondary:hover {
    background-color: var(--color-secondary-hover);
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-ghost:hover {
    border-color: var(--color-text-main);
    color: var(--color-text-main);
}

.btn-danger {
    background-color: var(--color-danger);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.danger-zone {
    border-color: var(--color-danger) !important;
}

.danger-zone h2 {
    color: var(--color-danger);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* .btn-primary/.btn-secondary/.btn-ghost are inline-sized everywhere by
   default; only the stacked sidebar footer wants them full-width. */
.sidebar-footer {
    flex-shrink: 0;
    padding-top: 0.75rem;
}

.app-credit {
    text-align: center;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 0.75rem;
}

.app-credit a {
    color: var(--color-text-muted);
    text-decoration: underline;
}

.app-credit a:hover {
    color: var(--color-text-main);
}

.sidebar-footer > button,
.sidebar-footer > label {
    width: 100%;
    justify-content: center;
    margin-bottom: 0.5rem;
}

.footer-icon-row {
    display: flex;
    gap: 0.5rem;
}

.btn-icon-action {
    flex: 1 1 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-card);
    color: var(--color-text-main);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.btn-icon-action:hover {
    background: var(--overlay-weak);
    border-color: var(--color-text-muted);
}

/* Compact variant for tight spaces (banners, inline table-view toolbars) —
   same shape and colors as the standard buttons, just smaller. */
.btn-primary.btn-sm, .btn-secondary.btn-sm, .btn-ghost.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0.25rem;
}

.btn-icon:hover {
    color: var(--color-danger);
}

.badge-synced {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-info);
    background: rgba(59, 130, 246, 0.15);
    border-radius: var(--radius-sm);
    padding: 0.1rem 0.4rem;
    margin-left: 0.4rem;
    white-space: nowrap;
}

.badge-overdue {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-danger);
    background: rgba(239, 68, 68, 0.15);
    border-radius: var(--radius-sm);
    padding: 0.1rem 0.4rem;
    margin-left: 0.4rem;
    white-space: nowrap;
}

.backup-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid var(--color-warning);
    color: var(--color-text-main);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.backup-banner.info-banner {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--color-info);
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
    margin-bottom: 1rem;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
}

.filter-bar label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    display: block;
    margin-bottom: 0.2rem;
}

.filter-bar .btn-ghost, .filter-bar .btn-secondary {
    width: auto;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    margin-bottom: 0;
}

/* Views & Cards */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

h1 {
    font-size: 2rem;
    font-weight: 600;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background-color: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background-color: var(--accent);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    background-color: var(--overlay-weak); /* slightly lighter than card */
    border-radius: var(--radius-md);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.25rem;
    color: var(--accent);
}

.kpi-info h3 {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text-main);
}

.kpi-sub {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* One "hero" metric per dashboard (Net Profit / Current Liquidity / Net Worth)
   gets visual priority over the supporting KPIs around it — otherwise every
   card looks equally important and the eye has nowhere to land first. */
.kpi-card--hero {
    padding: 2rem;
    box-shadow: inset 0 0 0 1px var(--accent);
}

.kpi-card--hero::before {
    width: 6px;
}

.kpi-card--hero .kpi-icon {
    width: 58px;
    height: 58px;
    font-size: 1.4rem;
}

.kpi-card--hero .kpi-info h3 {
    font-size: 0.95rem;
}

.kpi-card--hero .kpi-value {
    font-size: 2.25rem;
}

@media (min-width: 720px) {
    .kpi-card--hero {
        grid-column: span 2;
    }
}

/* Tables */
.table-container {
    background-color: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow-x: auto;
}

.data-table {
    width: 100%;
    min-width: 640px; /* forces .table-container to scroll instead of squashing columns unreadably narrow */
    border-collapse: collapse;
}

.cf-summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.data-table th, .data-table td {
    padding: 1rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.data-table th {
    background-color: var(--overlay-strong);
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-table tbody tr:nth-child(even) {
    background-color: var(--overlay-weaker);
}

.data-table tr:hover {
    background-color: var(--overlay-weak);
}

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

/* Inputs within tables */
.table-input {
    background: transparent;
    border: 1px solid transparent; /* Invisible border initially */
    color: var(--color-text-main);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    width: 100%;
    transition: all 0.2s;
}

.table-input:hover, .table-input:focus {
    background-color: var(--overlay-strong);
    border-color: var(--color-border);
    outline: none;
}

/* Every "amount + currency" table cell pairs an <input> with a <select>,
   both carrying .table-input's width:100%. In a cramped column (mobile,
   or a narrow scrolled table) the two fought over space with no floor,
   so the amount input — the number that actually matters — could shrink
   to an unreadable ~30px while the currency code stayed fully visible.
   Give the input a real minimum and let the row overflow into the
   table's existing horizontal scroll instead of silently collapsing it. */
.amount-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.amount-cell input.table-input {
    flex: 1 1 70px;
    min-width: 70px;
    width: auto;
}

.amount-cell select.table-input {
    flex: 0 0 auto;
    width: auto;
    min-width: 70px;
}

/* Utility */
.hidden {
    display: none;
}

.section-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.section-header-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.settings-card {
    background-color: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 600px;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--color-text-muted);
}

.form-group input {
    background-color: var(--overlay-strong);
    border: 1px solid var(--color-border);
    color: var(--color-text-main);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    width: 100%;
}

.faq-item {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
}

.faq-item:first-of-type {
    margin-top: 1rem;
    padding-top: 0;
    border-top: none;
}

.faq-item h3 {
    margin-bottom: 0.5rem;
}

.faq-item p {
    color: var(--color-text-muted);
    line-height: 1.6;
}

code {
    background: var(--overlay-strong);
    padding: 0.1rem 0.4rem;
    border-radius: var(--radius-sm);
    font-size: 0.9em;
}

/* ============================================================
   Responsive
   Below ~880px (tablet portrait and phones), the sidebar becomes a
   hamburger-triggered overlay instead of stacking above the content —
   stacking a full nav list ahead of the page ate the entire first
   screen's worth of vertical space before you ever saw your data.
   ============================================================ */
.hamburger-btn {
    display: none;
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text-main);
    border-radius: var(--radius-sm);
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    flex-shrink: 0;
    margin-right: 1rem;
}

.sidebar-backdrop {
    display: none;
}

@media (max-width: 880px) {
    .hamburger-btn {
        display: inline-flex;
    }

    .top-bar {
        display: flex;
        align-items: flex-start;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 60;
        width: 280px;
        max-width: 85vw;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: var(--shadow-lg);
    }

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

    .sidebar-backdrop.open {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 50;
    }

    .main-content {
        padding: 1.25rem;
        width: 100%;
    }

    .cf-summary-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 520px) {
    .main-content {
        padding: 1rem;
    }

    .data-table th, .data-table td {
        padding: 0.75rem 1rem;
    }
}
