/* benja-finance — CFO Dashboard  v2.2.0
 *
 * Mobile-first, RTL, zero dependencies.
 *
 * Colour is assigned by job, not by taste:
 *   - series-1 / series-2  categorical identity (income vs spend). Validated as a
 *                          pair against BOTH surfaces: CVD ΔE 26.8 dark / 24.7
 *                          light, normal-vision ΔE 31.8 / 33.6.
 *   - status-*             reserved for state (good / warning / critical) and
 *                          never reused as a series colour.
 * Status hues are mode-invariant and sub-3:1 on the light surface by design, so
 * every status mark ships with an icon AND a label, and all text wears text
 * tokens — colour never carries meaning on its own.
 */

/* ── Tokens ─────────────────────────────────────────────────────────────── */

:root {
  color-scheme: dark;

  --plane:        #0b0d14;
  --surface:      #161923;
  --surface-2:    #1d212d;
  --text-1:       #ffffff;
  --text-2:       #c2c6d4;
  --muted:        #8a8fa0;
  --grid:         #232734;
  --baseline:     #333a4d;
  --border:       rgba(255, 255, 255, 0.10);
  --shadow:       0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.28);

  --series-1:     #3987e5;  /* income  */
  --series-2:     #d95926;  /* spend   */

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-critical: #d03b3b;
  --status-info:     #3987e5;

  --radius:   14px;
  --radius-s: 8px;
  --gap:      12px;
  --pad:      16px;

  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans Hebrew", "Arial Hebrew", sans-serif;

  --tabbar-h: 62px;
}

:root[data-theme="light"] {
  color-scheme: light;

  --plane:     #f4f5f8;
  --surface:   #ffffff;
  --surface-2: #f7f8fa;
  --text-1:    #0b0b0b;
  --text-2:    #52514e;
  --muted:     #898781;
  --grid:      #e1e0d9;
  --baseline:  #c3c2b7;
  --border:    rgba(11, 11, 11, 0.10);
  --shadow:    0 1px 2px rgba(11, 11, 11, 0.06), 0 8px 24px rgba(11, 11, 11, 0.06);

  --series-1:  #2a78d6;
  --series-2:  #eb6834;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --plane:     #f4f5f8;
    --surface:   #ffffff;
    --surface-2: #f7f8fa;
    --text-1:    #0b0b0b;
    --text-2:    #52514e;
    --muted:     #898781;
    --grid:      #e1e0d9;
    --baseline:  #c3c2b7;
    --border:    rgba(11, 11, 11, 0.10);
    --shadow:    0 1px 2px rgba(11, 11, 11, 0.06), 0 8px 24px rgba(11, 11, 11, 0.06);
    --series-1:  #2a78d6;
    --series-2:  #eb6834;
  }
}

/* ── Base ───────────────────────────────────────────────────────────────── */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--plane);
}

body {
  font-family: var(--font);
  color: var(--text-1);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

/* Columns of figures align only when the digits are the same width. */
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* ── Lock screen ────────────────────────────────────────────────────────── */

.lock {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  background: var(--plane);
}

.lock[hidden] { display: none; }

.lock__card { width: 100%; max-width: 340px; text-align: center; }

.lock__brand {
  width: 62px;
  height: 62px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  font-size: 30px;
  font-weight: 700;
  color: var(--text-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.lock__title { font-size: 26px; }
.lock__subtitle { margin: 6px 0 0; color: var(--text-2); font-size: 14px; }

.lock__dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  min-height: 14px;
  margin: 22px 0 10px;
}

.lock__dots span {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--baseline);
  transition: transform 0.12s ease, background 0.12s ease;
}

.lock__dots span.is-filled { background: var(--text-1); transform: scale(1.12); }

.lock__message {
  min-height: 20px;
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-2);
}

.lock__message[data-tone="bad"] { color: var(--text-1); font-weight: 600; }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.key {
  height: 62px;
  font-size: 23px;
  font-weight: 500;
  color: var(--text-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: transform 0.08s ease, background 0.08s ease;
}

.key:active { transform: scale(0.95); background: var(--surface-2); }
.key--muted { color: var(--text-2); font-size: 18px; }
.key--accent { color: var(--series-1); font-size: 22px; }
.key:disabled { opacity: 0.4; }

/* On an enrolled device this is the primary way in, not a fallback, so it
   carries accent weight rather than sitting quietly under the keypad. */
.lock__bio {
  margin-top: 16px;
  padding: 13px 18px;
  width: 100%;
  color: var(--text-1);
  background: var(--surface-2);
  border: 1px solid var(--series-1);
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
}

.lock__bio:active { transform: scale(0.98); }
.lock__bio[hidden] { display: none; }

/* ── Biometric enrolment sheet ──────────────────────────────────────────── */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: end center;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.55);
}

.sheet[hidden] { display: none; }

.sheet__card {
  width: 100%;
  max-width: 380px;
  padding: var(--pad);
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sheet__icon { font-size: 34px; line-height: 1.2; }

.sheet__title { margin: 6px 0 8px; font-size: 19px; }

.sheet__body {
  margin: 0 0 12px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-2);
}

.sheet__message {
  min-height: 18px;
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
}

.sheet__primary {
  width: 100%;
  padding: 15px 18px;
  font-size: 16px;
  font-weight: 650;
  color: #ffffff;
  background: var(--series-1);
  border-radius: var(--radius);
}

.sheet__primary:active { transform: scale(0.98); }
.sheet__primary:disabled { opacity: 0.55; }

.sheet__ghost {
  width: 100%;
  margin-top: 8px;
  padding: 11px 18px;
  font-size: 14px;
  color: var(--text-2);
  border-radius: var(--radius);
}

.lock__meta {
  margin: 18px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.6;
}

/* ── App chrome ─────────────────────────────────────────────────────────── */

.app[hidden] { display: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) var(--pad) 10px;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar__eyebrow { display: block; font-size: 11.5px; color: var(--muted); }
.topbar__title { font-size: 19px; }

.topbar__actions { display: flex; gap: 8px; }

.iconbtn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  font-size: 17px;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
}

.iconbtn:active { background: var(--surface-2); }

.views {
  padding: var(--gap) var(--pad) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

.view[hidden] { display: none; }

.tabbar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--plane) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-top: 1px solid var(--border);
}

.tab {
  height: var(--tabbar-h);
  display: grid;
  place-items: center;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
}

.tab__icon { font-size: 19px; line-height: 1; }
.tab.is-active { color: var(--text-1); }
.tab.is-active .tab__icon { color: var(--series-1); }

/* ── Cards & layout ─────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: var(--gap);
  box-shadow: var(--shadow);
}

.card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card__title { font-size: 15px; }
.card__note { font-size: 11.5px; color: var(--muted); }

.section-title {
  margin: 20px 2px 10px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.empty {
  padding: 18px 4px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ── Stat tiles (KPI row) ───────────────────────────────────────────────── */

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.tile__label { font-size: 11.5px; color: var(--muted); }
.tile__value { margin-top: 5px; font-size: 21px; font-weight: 680; }
.tile__sub   { margin-top: 3px; font-size: 11.5px; color: var(--text-2); }

/* Ledger identity is a hairline, not a fill — §2's separation made visible
   without ever implying the two worlds belong on one scale. */
.tile[data-ledger="private"]  { border-inline-start: 3px solid var(--series-1); }
.tile[data-ledger="business"] { border-inline-start: 3px solid var(--series-2); }

/* ── Banker briefing ────────────────────────────────────────────────────── */

.banker {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: var(--gap);
  box-shadow: var(--shadow);
}

.banker__headline {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 16px;
  font-weight: 650;
  margin-bottom: 4px;
}

.banker__date { font-size: 11.5px; color: var(--muted); margin-bottom: 14px; }

.insight {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--grid);
}

.insight__icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text-2);
}

.insight[data-tone="good"] .insight__icon { color: var(--status-good); }
.insight[data-tone="warn"] .insight__icon { color: var(--status-warning); }
.insight[data-tone="bad"]  .insight__icon { color: var(--status-critical); }

.insight__title { font-size: 13.5px; font-weight: 620; }
.insight__detail { margin-top: 3px; font-size: 12.5px; color: var(--text-2); }
.insight__value { margin-top: 5px; font-size: 17px; font-weight: 680; }

/* ── Alerts ─────────────────────────────────────────────────────────────── */

.alert {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px 0;
  border-top: 1px solid var(--grid);
}

.alert:first-child { border-top: 0; padding-top: 0; }

.alert__dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--status-info);
}

.alert[data-severity="critical"] .alert__dot { background: var(--status-critical); }
.alert[data-severity="warning"]  .alert__dot { background: var(--status-warning); }

.alert__title { font-size: 13.5px; font-weight: 620; }
.alert__detail { margin-top: 3px; font-size: 12.5px; color: var(--text-2); }

/* ── Meters (credit utilisation) ────────────────────────────────────────── */

.meter {
  height: 8px;
  border-radius: 4px;
  background: var(--grid);
  overflow: hidden;
  margin: 8px 0 6px;
}

/* 4px rounded data-end, anchored to the baseline at the inline start. */
.meter__fill {
  height: 100%;
  border-radius: 4px;
  background: var(--status-good);
  transition: width 0.4s ease;
}

.meter__fill[data-band="warning"]  { background: var(--status-warning); }
.meter__fill[data-band="critical"] { background: var(--status-critical); }

.meter__legend {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-2);
}

/* ── Rows & tables ──────────────────────────────────────────────────────── */

.row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--grid);
}

.row:first-of-type { border-top: 0; }
.row__main { min-width: 0; }
.row__label { font-size: 13.5px; font-weight: 560; overflow-wrap: anywhere; }
.row__sub { margin-top: 2px; font-size: 11.5px; color: var(--muted); }
.row__value { font-size: 14px; font-weight: 640; white-space: nowrap; }
.row__value[data-tone="bad"]  { color: var(--text-1); }
.row__value[data-tone="good"] { color: var(--text-1); }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

table.data th {
  text-align: start;
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--baseline);
}

table.data td {
  padding: 7px 4px;
  border-bottom: 1px solid var(--grid);
  color: var(--text-2);
}

table.data td:first-child { color: var(--text-1); }
table.data .n { text-align: end; font-variant-numeric: tabular-nums; }

/* ── Monthly income/spend series ────────────────────────────────────────── */

.legend {
  display: flex;
  gap: 14px;
  margin-bottom: 12px;
  font-size: 11.5px;
  color: var(--text-2);
}

.legend__key { display: inline-flex; align-items: center; gap: 6px; }

.legend__swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--series-1);
}

.legend__swatch[data-series="2"] { background: var(--series-2); }

.bars { display: grid; gap: 10px; }

.bars__row { display: grid; grid-template-columns: 46px 1fr; gap: 10px; align-items: center; }

.bars__month {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  text-align: end;
}

/* Two thin bars sharing a baseline, separated by a 2px surface gap so the
   fills never touch. */
.bars__pair { display: grid; gap: 2px; }

.bars__bar {
  height: 9px;
  border-radius: 0 4px 4px 0;   /* rounded data-end; flat against the RTL baseline */
  background: var(--series-1);
  min-width: 2px;
}

.bars__bar[data-series="2"] { background: var(--series-2); }

.bars__track { position: relative; }

.bars__value {
  position: absolute;
  inset-inline-start: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%);
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

/* ── Chips ──────────────────────────────────────────────────────────────── */

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

.chip {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 10.5px;
  color: var(--text-2);
  white-space: nowrap;
}

.chip[data-confidence="data"]     { border-color: color-mix(in srgb, var(--status-good) 45%, transparent); }
.chip[data-confidence="derived"]  { border-color: color-mix(in srgb, var(--series-1) 45%, transparent); }
.chip[data-confidence="inferred"] { border-color: color-mix(in srgb, var(--status-warning) 55%, transparent); }

.chip[data-ledger="private"]  { border-color: color-mix(in srgb, var(--series-1) 45%, transparent); }
.chip[data-ledger="business"] { border-color: color-mix(in srgb, var(--series-2) 45%, transparent); }

/* ── Collapsible group ──────────────────────────────────────────────────── */

details.group { margin-bottom: var(--gap); }

details.group > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px var(--pad);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

details.group > summary::-webkit-details-marker { display: none; }
details.group[open] > summary { border-radius: var(--radius) var(--radius) 0 0; }

.group__title { font-size: 14px; font-weight: 620; }
.group__count { font-size: 11.5px; color: var(--muted); }

.group__body {
  padding: 4px var(--pad) var(--pad);
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ── Motion & forced colors ─────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

@media (forced-colors: active) {
  .meter__fill, .bars__bar, .alert__dot, .legend__swatch { forced-color-adjust: none; }
  .card, .tile, .key, .banker { border: 1px solid CanvasText; }
}

@media (min-width: 620px) {
  :root { --pad: 22px; }
  .views { max-width: 720px; margin: 0 auto; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
