/* ============================================================
   Nmible Cashflow Dashboard - CSS
   ============================================================ */
:root {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --accent: #0ea5a5;
    --danger: #dc2626;
    --warning: #d97706;
    --success: #15803d;
    --row-actual: #fff8e1;
    --row-closed: #f3f4f6;
    --row-forecast: #ffffff;
    --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 3px rgba(0,0,0,.05);
}

* { box-sizing: border-box; }
html, body { margin:0; padding:0; background: var(--bg); color: var(--text);
    font-family: Arial, "Segoe UI", sans-serif; font-size: 14px; }

button { font-family: inherit; font-size: inherit; cursor: pointer; }
button.link { background: none; border: 0; color: var(--primary); padding: 0; text-decoration: underline; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; padding: 6px 8px;
    border: 1px solid var(--border-strong); border-radius: 4px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

/* Top bar */
.topbar { display:flex; align-items:center; justify-content:space-between;
    padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10; }
.topbar-left { display:flex; align-items:center; gap: 18px; }
.brand { font-weight: 700; color: var(--primary-dark); }
.tabs { display:flex; gap: 4px; }
.tabs button { background: transparent; border: 0; padding: 6px 12px; border-radius: 4px;
    color: var(--muted); font-weight: 500; }
.tabs button:hover { background: var(--bg); color: var(--text); }
.tabs button.active { background: var(--primary); color: #fff; }
.topbar-right { display:flex; align-items:center; gap: 12px; color: var(--muted); }

/* Main view */
main#view { padding: 18px; max-width: 100%; }
.section { background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: var(--shadow); padding: 16px; margin-bottom: 18px; }
.section h2 { margin: 0 0 12px 0; font-size: 16px; }
.section h3 { margin: 12px 0 6px 0; font-size: 14px; color: var(--muted); }
.row { display:flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.kpi { padding: 12px; background: linear-gradient(180deg, #fafbfe, #f4f6fb); border: 1px solid var(--border); border-radius: 6px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

.btn { border: 1px solid var(--border-strong); background: #fff; color: var(--text);
    padding: 6px 12px; border-radius: 4px; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.small { padding: 3px 8px; font-size: 12px; }

.badge { display:inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge.open { background: #d1fae5; color: #065f46; }
.badge.closed { background: #fecaca; color: #7f1d1d; }
.badge.actual { background: #fef3c7; color: #78350f; }
.badge.forecast { background: #dbeafe; color: #1e3a8a; }

/* Grid (cashflow table) */
.grid-wrap { overflow: auto; max-height: calc(100vh - 220px); border: 1px solid var(--border); border-radius: 6px; }
table.grid { border-collapse: collapse; font-size: 12.5px; min-width: 100%; }
table.grid th, table.grid td { padding: 4px 8px; border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border); text-align: right; white-space: nowrap; }
table.grid th:first-child, table.grid td:first-child {
    position: sticky; left: 0; background: var(--panel);
    text-align: left; font-weight: 500; z-index: 1; }
table.grid thead th { position: sticky; top: 0; background: #f9fafb; z-index: 2; }
table.grid thead th.period-closed { background: #fee2e2; }
table.grid thead th.period-open   { background: #dcfce7; }
table.grid tr.row-total td { background: #f3f4f6; font-weight: 700; }
table.grid tr.row-opening td { background: #eef2ff; font-weight: 600; }
table.grid tr.row-closing td { background: #e0e7ff; font-weight: 700; }
table.grid tr.row-burn td { background: #fff4e0; font-weight: 600; }
table.grid td.col-closed input { background: #f3f4f6; }
table.grid td.col-actual      { background: var(--row-actual); }
table.grid td input { width: 90px; text-align: right; border: 0; background: transparent; padding: 2px 4px; }
table.grid td input:focus { outline: 2px solid var(--primary); background: #fff; }
table.grid td.neg { color: var(--danger); }
table.grid tr.category-header td { background: #111827; color: #fff; font-weight: 600; text-align: left; cursor: pointer; user-select: none; }
table.grid tr.category-header td:hover { background: #1f2937; }
table.grid tr.subcategory-header td { background: #374151; color: #fff; font-weight: 500; text-align: left; padding-left: 22px; cursor: pointer; user-select: none; }
table.grid tr.subcategory-header td:hover { background: #475569; }
table.grid tr.line-row.nested td:first-child { padding-left: 34px; }
table.grid .chev { display: inline-block; width: 12px; margin-right: 6px; font-size: 10px; color: #cbd5e1; transition: transform 0.1s ease; }
table.grid tr.category-header.collapsed .chev,
table.grid tr.subcategory-header.collapsed .chev { transform: rotate(-90deg); }
table.grid td .btn-chev { margin-right: 6px; border: 0; background: transparent;
    color: var(--primary); cursor: pointer; font-size: 14px; padding: 0 4px;
    line-height: 1; vertical-align: middle; font-weight: 700; }
table.grid td .btn-chev:hover { color: var(--primary-dark); }

/* Copy-forward modal */
.copy-forward-modal { position: fixed; inset: 0; background: rgba(17,24,39,0.5);
    display: grid; place-items: center; z-index: 50; }
.copy-forward-modal .card { background: #fff; border-radius: 10px; padding: 20px 22px;
    box-shadow: var(--shadow); width: 420px; max-width: 90vw; display: flex;
    flex-direction: column; gap: 12px; }
.copy-forward-modal h3 { margin: 0; font-size: 16px; }
.copy-forward-modal .preview { background: #f9fafb; border: 1px solid var(--border);
    border-radius: 6px; padding: 8px 10px; font-size: 12px; color: var(--muted);
    max-height: 140px; overflow-y: auto; }
.copy-forward-modal .actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Plain table */
table.table { border-collapse: collapse; width: 100%; }
table.table th, table.table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
table.table th { background: #f9fafb; font-weight: 600; color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: 0.02em; }
table.table tr:hover td { background: #fafbfe; }
table.table td.num, table.table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Login page */
body.login-page { display: grid; place-items: center; min-height: 100vh;
    background: linear-gradient(160deg, #eef2ff, #f4f6fb); }
.login-card { background: #fff; padding: 28px 30px; border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,.08); width: 340px; display: flex; flex-direction: column; gap: 10px; }
.l


/* Subcategory subtotal rows - visible in both expanded and collapsed states */
table.grid tr.row-subtotal td {
    background: #fef3c7;
    font-weight: 600;
    color: #78350f;
    border-top: 1px solid #fde68a;
}
table.grid tr.row-subtotal td:first-child {
    background: #fef3c7;
    padding-left: 22px;
    font-style: italic;
}
table.grid tr.row-subtotal.when-cat-collapsed td {
    background: #fde68a;
    color: #713f12;
    font-weight: 700;
}
table.grid tr.row-subtotal.when-cat-collapsed td:first-child {
    background: #fde68a;
    padding-left: 22px;
}

/* Scenario decision timeline */
table.table tr.timeline-row td {
    padding: 0;
    background: #f9fafb;
    border-bottom: 2px solid var(--border-strong);
}
.timeline-body {
    padding: 14px 18px;
    background: #f9fafb;
    max-height: 420px;
    overflow-y: auto;
}
.timeline-body .timeline-empty {
    color: var(--muted);
    font-style: italic;
    padding: 8px 0;
}
.timeline-month { margin-bottom: 14px; }
.timeline-month:last-child { margin-bottom: 0; }
.timeline-month h4 {
    margin: 0 0 6px 0;
    font-size: 12px;
    font-weight: 700;
    color: var(--primary-dark);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
}
.timeline-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.timeline-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    font-size: 13px;
    color: var(--text);
}
.timeline-list li + li { border-top: 1px dashed var(--border); }

/* Verb badges for scenario events */
.badge-cancelled, .badge-added, .badge-reduced, .badge-increased {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    flex-shrink: 0;
    min-width: 70px;
    text-align: center;
}
.badge-cancelled { background: #fecaca; color: #7f1d1d; }
.badge-added     { background: #d1fae5; color: #065f46; }
.badge-reduced   { background: #fed7aa; color: #9a3412; }
.badge-increased { background: #dbeafe; color: #1e3a8a; }

/* Expandable scenario row chevron */
table.table td .btn-chev-scenario {
    border: 0;
    background: transparent;
    color: var(--primary);
    cursor: pointer;
    font-size: 13px;
    padding: 0 6px 0 0;
    line-height: 1;
    vertical-align: middle;
    font-weight: 700;
}
table.table td .btn-chev-scenario:hover { color: var(--primary-dark); }

/* Runway KPI tones - applied to .kpi container */
.kpi.kpi-runway-ok {
    background: linear-gradient(180deg, #f0fdf4, #dcfce7);
    border-color: #86efac;
}
.kpi.kpi-runway-ok .value { color: #14532d; }
.kpi.kpi-runway-warning {
    background: linear-gradient(180deg, #fffbeb, #fef3c7);
    border-color: #fcd34d;
}
.kpi.kpi-runway-warning .value { color: #78350f; }
.kpi.kpi-runway-danger {
    background: linear-gradient(180deg, #fef2f2, #fee2e2);
    border-color: #fca5a5;
}
.kpi.kpi-runway-danger .value { color: #7f1d1d; font-weight: 800; }

/* Variance view (task #37) */
.variance-wrap {
    overflow-x: auto;
    margin-top: 14px;
    border: 1px solid var(--border, #e4e6eb);
    border-radius: 8px;
    background: #fff;
}
table.variance-grid {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
}
table.variance-grid th,
table.variance-grid td {
    padding: 6px 12px;
    border-bottom: 1px solid var(--border, #eef0f2);
    text-align: left;
    white-space: nowrap;
}
table.variance-grid th {
    background: #f7f8fa;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}
table.variance-grid td.num,
table.variance-grid th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
table.variance-grid tr.var-cat-row {
    background: #f3f4f6;
    font-weight: 600;
}
table.variance-grid tr.var-cat-row td { border-top: 2px solid #d1d5db; }
table.variance-grid tr.var-item-row td.var-label { color: #374151; }
table.variance-grid tr.var-item-row:hover { background: #fafbfc; }
table.variance-grid td.var-delta-good { color: #166534; font-weight: 600; }
table.variance-grid td.var-delta-bad  { color: #991b1b; font-weight: 600; }
.var-kpis { margin-top: 10px; }

/* ── Actuals entry mode (task #39) ───────────────────────────────── */
.actuals-toggle {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border: 1px solid #d1d5db; border-radius: 999px;
    background: #f9fafb; color: #374151; font-size: 13px;
    cursor: pointer; user-select: none;
    transition: background 120ms ease, border-color 120ms ease;
}
.actuals-toggle:hover { background: #f3f4f6; }
.actuals-toggle input[type="checkbox"] { margin: 0; accent-color: #16a34a; }
.actuals-toggle.on {
    background: #dcfce7; border-color: #16a34a; color: #166534; font-weight: 600;
}
.grid-wrap.actuals-mode table.grid tbody td input[type="text"] {
    background: #f0fdf4;
    border-color: #bbf7d0;
}
.grid-wrap.actuals-mode table.grid tbody td.col-closed input[type="text"] {
    background: #f3f4f6;  /* closed cells stay neutral */
    border-color: #e5e7eb;
}
.grid-wrap table.grid tbody td.col-closed input[type="text"] {
    background: #f3f4f6;
    color: #6b7280;
    cursor: not-allowed;
}

/* ── Cash balance chart (task #40) ──────────────────────────────── */
.chart-wrap {
    position: relative;
    height: 320px;
    margin-top: 6px;
}
.chart-wrap canvas { display: block; }

/* ── Variance subcategory + subtotal rows (task #42) ───────────── */
table.variance-grid tr.var-subcat-row {
    background: #e5e7eb;
    font-weight: 600;
    color: #111827;
}
table.variance-grid tr.var-subcat-row td { border-top: 1px solid #d1d5db; }
table.variance-grid tr.var-subtotal-row {
    background: #f3f4f6;
    font-weight: 600;
    color: #111827;
    border-top: 1px dashed #d1d5db;
}
table.variance-grid tr.var-subtotal-row td.var-label {
    color: #4b5563;
    font-style: italic;
}

/* ───────────── Budget feature (task #44–49) ───────────── */

.scenario-budget-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    background: #1e3a8a;       /* indigo-900 */
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-left: 4px;
    vertical-align: middle;
}

.budget-section {
    border-left: 4px solid #1e3a8a;
    padding-left: 14px;
    background: #f8fafc;
}

.budget-status-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

.variance-baseline-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f3f4f6;
    padding: 4px 6px;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
}

.variance-baseline-toggle .btn.small {
    padding: 4px 10px;
    font-size: 12px;
}

/* Budget-mode variance table: grouped column header */
table.variance-grid th.group-head {
    background: #eef2ff;
    color: #1e3a8a;
    font-weight: 600;
    text-align: center;
    border-bottom: 1px solid #c7d2fe;
}

/* Collapse All / Expand All button — consolidated table */
.section .row .btn[style] { vertical-align: middle; }

/* Per-month copy-forward chevron columns (Accounts grid) */
th.chev-col, td.chev-col {
    width: 18px;
    min-width: 18px;
    max-width: 18px;
    padding: 0 1px;
    border-left: none;
    border-right: none;
    background: transparent;
    text-align: center;
    vertical-align: middle;
}
.btn-cell-chev {
    display: none;
    background: none;
    border: none;
    color: #bbb;
    cursor: pointer;
    font-size: 13px;
    padding: 0 2px;
    line-height: 1;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}
tr:hover .btn-cell-chev {
    display: inline-block;
}
.btn-cell-chev:hover {
    color: #1a56db;
    background: #e8f0fe;
}
