/* ============================================================
   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