:root {
    /* Older names, kept as aliases of the semantic tokens in 00-tokens.css (use --c-* in new rules). */
    --primary: var(--c-text);         /* "ink": headings, strong text — not the action colour (that is --c-primary) */
    --primary-light: var(--c-surface-2);
    --secondary: var(--c-text-muted);
    --accent: var(--c-primary);
    --success: var(--c-success);
    --danger: var(--c-danger);
    --danger-light: var(--c-danger-soft);
    --bg-main: var(--c-bg);
    --bg-card: var(--c-surface);
    --bg-sidebar: var(--c-surface);
    --border: var(--c-border);
    /* Text colours — every value here is ≥ 4.5:1 (WCAG AA) on white AND on the tinted
       surfaces (#f8fafc, #f1f5f9, #eff6ff, #ecfdf5, #fef2f2, #fff7ed, #faf5ff).
       Coloured numbers (green/red/blue/orange) must use the *-text tokens, never the fills. */
    --text-main: var(--c-text);
    --text-strong: var(--tx-main);
    --text-muted: var(--c-text-muted);
    --text-faint: var(--tx-faint);   /* 4.76:1 on white — white/near-white surfaces only */
    --success-text: var(--c-success);
    --danger-text: var(--c-danger);
    --accent-text: var(--c-primary);
    --warning-text: var(--c-warning);
    --violet-text: var(--st-new);
    --indigo-fill: var(--c-primary);

    /* Touch */
    --tap: 44px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-ui);
    font-variant-numeric: tabular-nums;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    direction: rtl;
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background-color: var(--bg-sidebar);
    border-inline-end: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px;
    z-index: 10;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
}

.bottom-actions { margin-top: auto; }

.main-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 40px;
    position: relative;
}

/* Views */
.view { display: none; animation: fadeIn 0.3s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ===== AGGRESSIVE DESKTOP TYPOGRAPHY (overview + ledger) ===== */
@media (min-width: 769px) {
    #view-dashboard, #view-ledger {
        font-size: 16px !important;
    }
    /* Force table text to 16px */
    #view-dashboard table td,
    #view-dashboard table th,
    #view-ledger table td,
    #view-ledger table th,
    .perf-grid table td,
    .perf-grid table th {
        font-size: 16px !important;
    }
    /* Force balances and headers to 18px */
    .perf-grid h4,
    #view-dashboard .card h3,
    .perf-grid strong[style*="font-size"] {
        font-size: 18px !important;
    }
    /* Override inline micro-fonts on performance labels */
    .perf-grid span[style*="font-size"],
    .perf-grid div[style*="font-size"],
    .perf-grid small {
        font-size: 14px !important;
    }
    .perf-grid thead,
    .perf-grid thead th {
        font-size: 15px !important;
    }
    /* Cash accounts & debt lists: unified font sizes */
    .dash-badge {
        font-size: 0.8rem !important;
    }
    .dash-name {
        font-size: 1rem !important;
    }
    .dash-balance {
        font-size: 1rem !important;
    }
    /* Transactions log table */
    #view-transactions table td,
    #view-transactions table th {
        font-size: 16px !important;
    }
}

/* Ledger form labels and inputs */
.ledger-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--secondary);
    display: block;
    margin-bottom: 4px;
}
.ledger-input {
    width: 100%;
    padding: 8px 10px;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
}

/* Performance grid: 2 columns on desktop, 1 column on mobile */
.perf-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    align-items: start;
}

/* Components */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
}

.card {
    background: var(--c-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.full-width { grid-column: 1 / -1; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.card-header h3 { font-size: 1.2rem; color: var(--primary); margin:0;}

/* Buttons (.btn-*, .btn-close, .fab, .btn-add) live in 01-components.css. */
.mt-2 { margin-top: 8px; }

/* Lists & Tables */
.list-wrapper { display: flex; flex-direction: column; gap: 16px; }

.tracker-item {
    border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; transition: transform var(--mo-base) var(--ease-out), opacity var(--mo-base) var(--ease-out), background-color var(--mo-base) var(--ease-out), color var(--mo-base) var(--ease-out), border-color var(--mo-base) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
    .tracker-item:hover { border-color: var(--secondary); }
}
.tracker-header { display: flex; justify-content: space-between; margin-bottom: 12px; align-items: flex-end; }
.tracker-type { font-size: 0.75rem; background: var(--primary-light); padding: 2px 6px; border-radius: 4px; margin-inline-start: 8px; font-weight: normal; }
.tracker-progress { height: 6px; background: var(--border); border-radius: 3px; margin-bottom: 12px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); }
.progress-bar.goal { background: var(--success); }
.tracker-footer { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; color: var(--text-muted); }
.tracker-actions { display: flex; gap: 8px; }

.icon-btn { background: transparent; border: none; color: var(--secondary); cursor: pointer; padding: 4px; font-size: 1rem; border-radius: 4px; transition: transform var(--mo-base) var(--ease-out), opacity var(--mo-base) var(--ease-out), background-color var(--mo-base) var(--ease-out), color var(--mo-base) var(--ease-out), border-color var(--mo-base) var(--ease-out); }
@media (hover: hover) and (pointer: fine) {
    .icon-btn:hover { color: var(--primary); background: var(--primary-light); }
}

.event-item { background: var(--primary-light); padding: 12px 16px; border-radius: var(--radius-sm); display: flex; align-items: center; gap: 16px; min-width: 250px;}
.event-info h4 { margin:0; font-size:0.95rem;}
.event-info p { margin:0; font-size:0.8rem; color:var(--text-muted);}
.event-amount { font-weight: bold; margin-inline-start: auto; }

/* Ledger Layout */

.badge { padding: 4px 10px; border-radius: 20px; font-size: 0.8rem; font-weight: 600; }

.table-responsive { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; text-align: start; font-size: 0.82rem; }
.data-table th, .data-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); line-height: 1.4; }
.data-table tbody tr:nth-child(even) { background-color: var(--primary-light); }
@media (hover: hover) and (pointer: fine) {
    .data-table tbody tr:hover { background-color: var(--c-border); }
}
.data-table th { color: var(--text-muted); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; padding: 8px 10px; }
.data-table tr:last-child td { border-bottom: none; }
.td-actions { width: 60px; text-align: end; }

.chart-container { height: 400px; position: relative; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 8px; color: var(--secondary); }
.form-group input, .form-group select {
    width: 100%; padding: 10px 12px; font-size: 0.95rem; font-family: var(--font-ui);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    transition: transform var(--mo-base) var(--ease-out), opacity var(--mo-base) var(--ease-out), background-color var(--mo-base) var(--ease-out), color var(--mo-base) var(--ease-out), border-color var(--mo-base) var(--ease-out); outline: none; background: var(--c-surface); color:var(--text-main);
}
.form-group input:focus, .form-group select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); }
.form-group input:focus-visible, .form-group select:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; }

.radio-group { display: flex; gap: 12px; }
.radio-card { flex: 1; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; cursor: pointer; display: flex; flex-direction: column;gap:4px; transition: transform var(--mo-base) var(--ease-out), opacity var(--mo-base) var(--ease-out), background-color var(--mo-base) var(--ease-out), color var(--mo-base) var(--ease-out), border-color var(--mo-base) var(--ease-out);}
@media (hover: hover) and (pointer: fine) {
    .radio-card:hover { border-color: var(--accent); }
}
.radio-card span { font-weight: 600; display:flex; align-items:center; gap:8px;}
.radio-card small { font-size: 0.75rem; color: var(--text-muted); }

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0; inset-inline-end: 0; inset-inline-start: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    /* Anchor modals near the top with a small breathing margin instead of
       centering. Prevents the "lots of empty space above the form" problem
       with short modals while still letting tall ones scroll naturally. */
    align-items: flex-start;
    justify-content: center;
    /* Above the mobile bottom-nav (z:9000) so the save button isn't clipped. */
    z-index: 9900;
    overflow-y: auto;
    padding: 6vh 12px calc(80px + env(safe-area-inset-bottom, 0px));
}
/* Constrain modal cards so they never extend past the visible area on mobile. */
@media (max-width: 768px) {
    .modal-overlay .modal-card,
    .modal-overlay .modal-card-sm {
        max-height: none;
        margin: auto;
    }

    /* iOS Safari auto-zooms when focusing an editable field whose font is
       < 16px. Pin text-entry fields to 16px on mobile to stop the zoom jump.
       Selects are excluded — iOS opens a picker (no zoom) and the compact
       mobile wallet selects must stay small. No effect on Android layout. */
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="button"]):not([type="submit"]):not([type="reset"]),
    textarea {
        font-size: 16px !important;
    }
}

.modal-overlay.active { display: flex; }

.modal-card { background: white; width: 100%; max-width: 500px; border-radius: var(--radius-md); box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); overflow: hidden; animation: slideUp 0.3s ease; }
.modal-card-sm { background: white; width: 100%; max-width: 400px; border-radius: var(--radius-md); box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); animation: slideUp 0.3s ease; }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { margin: 0; font-size: 1.25rem; }
.modal-body { padding: 24px; }

/* Category Tags Cloud */

.cat-tag { padding: 6px 12px; font-size: 0.85rem; border: 1px solid var(--border); border-radius: 20px; background: white; cursor: pointer; transition: transform var(--mo-base) var(--ease-out), opacity var(--mo-base) var(--ease-out), background-color var(--mo-base) var(--ease-out), color var(--mo-base) var(--ease-out), border-color var(--mo-base) var(--ease-out); font-family: var(--font-ui); font-weight: 600;}
@media (hover: hover) and (pointer: fine) {
    .cat-tag:hover { border-color: var(--accent); background: var(--primary-light); color: var(--accent-text); }
}

/* Budget Specific */

.budget-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.budget-item:last-child { border-bottom: none; }
.matrix-mobile { display: none; }
.matrix-table th, .matrix-table td { font-size: 0.85rem; padding: 8px 12px; white-space: nowrap; border: 1px solid var(--border); text-align: start; }
.matrix-table th { background: var(--bg-sidebar); position: sticky; inset-inline-start: 0; z-index: 10; font-family: var(--font-ui);} 
.matrix-header { background: var(--primary-light) !important; color: var(--primary); font-weight:bold; }

span.text-muted { color: var(--text-muted); }

/* Allocator: css/19-cashflow.css (.alc-*) */
input[type=range] { width: 100%; direction: rtl; cursor: pointer; }

/* Phone widths: every control is at least 44×44 (WCAG 2.5.5 / Material 48dp). `min-*` wins over
   the explicit `width`/`height` the components set, so dense rows keep their look but gain a real
   tap box. Checkboxes/radios keep their native size: their <label> is the target. */
@media (max-width: 768px) {
    button:not(.mobile-nav-btn):not(.mobile-nav-fab),
    .btn, [role="button"], summary {
        min-height: var(--tap);
    }
    button:not(.mobile-nav-btn):not(.mobile-nav-fab) { min-width: var(--tap); }
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="hidden"]),
    select, textarea {
        min-height: var(--tap);
    }
}
