/* Books (14 Nov 2026): base look and the shared building blocks every view uses. Phone width first (360-430 px), then tablet and
   desktop. No horizontal page scroll: long words wrap, wide lists turn into stacked cards. Views add their own rules in
   views.css (Overview / Broker P&L / Bank / Reconcile) and upload.css (Upload / Setup), using these classes:
     .card .card-head .eyebrow   panels             .stats .stat          figure tiles (span label, b value, em note)
     .amount .positive .negative money              .btn .primary .ghost .danger .small .wide .armed   buttons
     .chips .chip .active        choice chips       .pill[data-kind]      a line type label
     .table td[data-label]       list table (cards on a phone)            .rows .row .row-main .row-amount   simple lists
     .field .compact .form-grid  form fields        .note .warn .bad .good  messages     .empty   nothing to show
     .toolbar                    a row of controls  .muted .nowrap .sr-only               helpers */

:root {
  --ink: #15213b;
  --muted: #66738c;
  --line: #dce4ef;
  --soft: #f4f7fb;
  --page: #eef2f8;
  --card: #ffffff;
  --navy: #10284e;
  --blue: #1d477e;
  --blue-soft: #e6ecf5;
  --green: #1f7a4f;
  --green-soft: #e8f6ee;
  --red: #b83232;
  --red-soft: #fff0f0;
  --amber: #8a4b00;
  --amber-soft: #fff6e6;
  --radius: 12px;
  --shadow: 0 1px 2px #10284e14, 0 6px 18px #10284e0d;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--page);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-wrap: anywhere;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
:focus-visible { outline: 3px solid #4f7fd1; outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
.sr-only, .hidden-user { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; white-space: nowrap; }

/* ---------- boot / login ---------- */
.boot { padding: 40px 16px; text-align: center; color: var(--muted); font-weight: 700; }
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, #10284e 0%, #1d477e 55%, #eef2f8 55.2%); }
.gate-card { width: min(100%, 380px); display: grid; gap: 14px; padding: 26px 22px; background: var(--card); border-radius: 16px; box-shadow: 0 18px 40px #10284e40; }
.gate-card h1 { font-size: 26px; }
.gate-note { color: var(--muted); font-size: 13px; }
.gate-error { padding: 9px 12px; color: var(--red); background: var(--red-soft); border: 1px solid #efc2c2; border-radius: 10px; font-size: 13px; font-weight: 700; }

/* ---------- frame ---------- */
.app { width: min(100%, 1180px); margin: 0 auto; padding: 0 12px 40px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 2px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { flex: none; display: grid; place-items: center; width: 34px; height: 34px; color: #fff; background: var(--navy); border-radius: 10px; font-weight: 900; }
.brand b { display: block; font-size: 17px; }
.brand small { display: block; color: var(--muted); font-size: 11.5px; font-weight: 600; }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: var(--blue-soft); border-radius: var(--radius); }
.tabs button { position: relative; padding: 9px 6px; color: #3b4d6b; background: transparent; border: 0; border-radius: 9px; font-size: 13px; font-weight: 800; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: #fff; background: var(--blue); box-shadow: 0 4px 12px #1d477e33; }
.tab-count { display: inline-block; min-width: 18px; margin-left: 5px; padding: 0 5px; color: #fff; background: var(--red); border-radius: 9px; font-size: 11px; line-height: 18px; }

.filters { display: grid; gap: 8px; margin: 10px 0 12px; padding: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.presets button { padding: 6px 10px; color: #34476a; background: var(--soft); border: 1px solid var(--line); border-radius: 999px; font-size: 12.5px; font-weight: 750; }
.presets button.active { color: #fff; background: var(--blue); border-color: var(--blue); }
.filter-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filter-fields .field:last-child { grid-column: 1 / -1; }

.problem { margin: 0 0 12px; padding: 11px 14px; color: var(--red); background: var(--red-soft); border: 1px solid #efc2c2; border-radius: var(--radius); font-weight: 700; }
.view { display: grid; gap: 12px; min-width: 0; outline: none; }

/* ---------- building blocks ---------- */
.card { display: grid; gap: 12px; min-width: 0; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.card-head h2 { font-size: 17px; }
.card-head small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; font-weight: 600; }
.eyebrow { margin: 0 0 2px; color: #5a78b0; font-size: 10.5px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stat { min-width: 0; padding: 10px 11px; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; }
.stat > span { display: block; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .03em; }
.stat > b { display: block; margin-top: 3px; font-size: 16px; font-variant-numeric: tabular-nums; }
.stat > em { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; font-style: normal; font-weight: 600; }
.stat.big b { font-size: 20px; }

.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.neutral { color: var(--ink); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 8px 14px; color: var(--blue); background: #fff; border: 1px solid #b9c8e0; border-radius: 10px; font-size: 13.5px; font-weight: 800; text-decoration: none; }
.btn.primary { color: #fff; background: var(--blue); border-color: var(--blue); }
.btn.danger { color: var(--red); border-color: #e3b1b1; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 12.5px; }
.btn.wide { width: 100%; }
.btn.armed { color: #fff; background: var(--red); border-color: var(--red); }
.btn.primary.armed { background: #0f6b3f; border-color: #0f6b3f; }
.btn.busy { pointer-events: none; opacity: .7; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 10px; color: #34476a; background: var(--soft); border: 1px solid var(--line); border-radius: 999px; font-size: 12.5px; font-weight: 750; }
.chip.active { color: #fff; background: var(--blue); border-color: var(--blue); }
.chip small { margin-left: 4px; opacity: .8; font-weight: 700; }

.pill { display: inline-block; padding: 2px 8px; color: #34476a; background: var(--soft); border: 1px solid var(--line); border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.pill[data-kind="PNL"], .pill[data-kind="INCOME"], .pill[data-kind="DIVIDEND"], .pill[data-kind="INTEREST"] { color: var(--green); background: var(--green-soft); border-color: #bfe3cf; }
.pill[data-kind="EXPENSE"], .pill[data-kind="CHARGES"], .pill[data-kind="TDS"] { color: var(--red); background: var(--red-soft); border-color: #efc2c2; }
.pill[data-kind="TRANSFER"], .pill[data-kind="BROKER"], .pill[data-kind="OWN_TRANSFER"] { color: var(--blue); background: var(--blue-soft); border-color: #c6d4ea; }
.pill[data-kind="SHARES"], .pill[data-kind="INVESTMENT"], .pill[data-kind="LOAN"] { color: #5b3f8f; background: #f1ecfa; border-color: #d9cdef; }
.pill[data-kind="UNKNOWN"] { color: var(--amber); background: var(--amber-soft); border-color: #f1d39b; }
.pill[data-kind="IGNORE"] { color: var(--muted); }
.pill.auto { color: var(--green); background: var(--green-soft); border-color: #bfe3cf; }
.pill.manual { color: var(--blue); background: var(--blue-soft); border-color: #c6d4ea; }

/* A list table: real columns from tablet width; on a phone every row is a small card and each cell shows its data-label. */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { padding: 7px 8px; color: var(--muted); font-size: 11px; font-weight: 800; text-align: left; letter-spacing: .03em; border-bottom: 1px solid var(--line); }
.table td { padding: 8px; vertical-align: top; border-bottom: 1px solid #edf1f7; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.total td { font-weight: 800; background: var(--soft); }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #f7f9fd; }
@media (max-width: 719px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 8px 10px; margin-bottom: 8px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
  .table td { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border: 0; text-align: right; }
  .table td::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 11.5px; font-weight: 750; text-align: left; }
  .table td[data-label=""]::before { content: none; }
  .table td.lead { display: block; text-align: left; font-weight: 750; }
  .table td.lead::before { content: none; }
  .table .num { text-align: right; }
}

.rows { display: grid; gap: 0; }
.row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 9px 2px; border-bottom: 1px solid #edf1f7; }
.row:last-child { border-bottom: 0; }
.row-main { min-width: 0; }
.row-main b { display: block; font-size: 13.5px; }
.row-main small { display: block; color: var(--muted); font-size: 12px; }
.row-amount { flex: none; text-align: right; font-variant-numeric: tabular-nums; font-weight: 800; }
.row-amount small { display: block; color: var(--muted); font-size: 11px; font-weight: 600; }

.field { display: grid; gap: 4px; min-width: 0; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.field input, .field select, .field textarea { width: 100%; min-width: 0; padding: 9px 10px; color: var(--ink); background: #fff; border: 1px solid #c9d6ea; border-radius: 9px; font-size: 14px; font-weight: 600; letter-spacing: 0; text-transform: none; }
.field.compact input, .field.compact select { padding: 7px 8px; font-size: 13px; }
.field small { color: var(--muted); font-size: 11.5px; font-weight: 600; letter-spacing: 0; text-transform: none; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.form-grid .span-all { grid-column: 1 / -1; }

.note, .warn, .bad, .good { padding: 10px 12px; border-radius: 10px; font-size: 13px; font-weight: 650; line-height: 1.45; }
.note { color: #2e4a78; background: #eef3fc; border: 1px solid #cddbf2; }
.warn { color: var(--amber); background: var(--amber-soft); border: 1px solid #f1d39b; }
.bad { color: var(--red); background: var(--red-soft); border: 1px solid #efc2c2; }
.good { color: var(--green); background: var(--green-soft); border: 1px solid #bfe3cf; }
.empty { padding: 22px 12px; color: var(--muted); text-align: center; font-weight: 650; }

.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; }
.toolbar .field { flex: 1 1 150px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

.toasts { position: fixed; left: 50%; bottom: 16px; z-index: 50; display: grid; gap: 8px; width: min(calc(100% - 24px), 460px); transform: translateX(-50%); }
.toast { padding: 11px 14px; color: #fff; background: var(--navy); border-radius: 10px; box-shadow: 0 10px 28px #10284e40; font-weight: 700; }
.toast.error { background: var(--red); }
.toast.ok { background: #136b42; }

/* ---------- wider screens ---------- */
@media (min-width: 560px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 720px) {
  .app { padding: 0 20px 48px; }
  .tabs { display: flex; width: fit-content; max-width: 100%; }
  .tabs button { padding: 9px 16px; }
  .filters { grid-template-columns: 1fr auto; align-items: end; }
  .filter-fields { grid-template-columns: repeat(3, minmax(130px, 170px)); }
  .filter-fields .field:last-child { grid-column: auto; }
  .card { padding: 16px 18px; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1000px) {
  .stats.six { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .chip, .tabs button { transition: background-color .12s, color .12s, border-color .12s; }
}
