/* Mobile-first. Light + dark, each chosen (not flipped). Chart roles follow the reference data-viz palette. */
:root {
  color-scheme: light;
  --bg: #f4f5f7; --surface-1: #ffffff; --line: #e3e5e8;
  --text-primary: #191919; --text-secondary: #666666;
  --accent: #1757ac; --accent-ink: #ffffff;
  --series-1: #257de0; --series-2: #f47230;
  --grid: #ececec;
  --good: #0aac23; --warning: #fbb315; --serious: #f18a59; --critical: #dc3c3d;
  --good-ink: #006c10; --crit-ink: #b42727; --warn-ink: #8a5a00;
  --radius: 14px;
  --tabs-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111111; --surface-1: #191919; --line: #2c2c2c;
    --text-primary: #efefef; --text-secondary: #9c9c9c;
    --accent: #338ced; --accent-ink: #0b0b0b;
    --series-1: #338ced; --series-2: #e76624;
    --grid: #2a2a2a;
    --good-ink: #3fd25a; --crit-ink: #f07a7b; --warn-ink: #fbb315;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text-primary);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif;
  padding-bottom: calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 8px 0 12px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; display: flex; align-items: baseline; gap: 8px; }
h1 .right, h2 .right { margin-left: auto; font-weight: 600; }
.small { font-size: .85rem; } .muted { color: var(--text-secondary); }
.block { display: block; } .right { margin-left: auto; text-align: right; } .grow { flex: 1; min-width: 0; }
.err { color: var(--crit-ink); }
.up { color: var(--good-ink); } .down { color: var(--crit-ink); }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg); }
.brand { font-weight: 700; color: var(--text-primary); }
main { max-width: 760px; margin: 0 auto; padding: 0 14px; }

.card { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  margin: 0 0 12px; }
.card.flush { padding: 4px 14px; }
.card.note { border-color: var(--accent); }
.hero .big { font-size: 2.2rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.15; }
.mid { font-size: 1.25rem; font-weight: 700; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin-bottom: 8px; }
.row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.pill { font-size: .72rem; padding: 1px 7px; border-radius: 99px; border: 1px solid var(--line); color: var(--text-secondary); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list.tx > li { padding: 0; }
.txlink { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 0; color: inherit; }
.txlink b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.txlink .small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ico { font-size: 1.2rem; width: 28px; text-align: center; }
.amt { white-space: nowrap; font-weight: 600; font-variant-numeric: tabular-nums; }
.amt.in { color: var(--good-ink); }
.menu a { display: flex; width: 100%; color: inherit; padding: 4px 0; }

details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: 10px; }
details.item { border-top: 1px solid var(--line); padding: 10px 0; }
details.item:first-of-type { border-top: 0; }

/* budgets & progress (status colors always paired with an icon + label) */
.budget { margin: 8px 0 12px; }
.bar { height: 8px; background: var(--grid); border-radius: 99px; overflow: hidden; margin-top: 5px; }
.bar i { display: block; height: 100%; border-radius: 99px; background: var(--good); }
.bar i.warning { background: var(--warning); } .bar i.over { background: var(--critical); }
.status { font-size: .78rem; font-weight: 600; margin-left: 4px; white-space: nowrap; }
.status.good { color: var(--good-ink); } .status.warn { color: var(--warn-ink); } .status.crit { color: var(--crit-ink); }

/* charts */
.chart { position: relative; height: 210px; margin-top: 6px; }
.chart.sm { height: 120px; }

/* forms */
.form { display: grid; gap: 10px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label { display: grid; gap: 4px; font-size: .82rem; color: var(--text-secondary); }
input, select, button { font: inherit; color: var(--text-primary); }
input, select { width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-1); min-height: 44px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button { padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-1);
  min-height: 44px; cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; }
button.danger { color: var(--crit-ink); border-color: transparent; background: transparent; padding-left: 0; }
button.link { border: 0; background: none; color: var(--accent); padding: 0 4px; min-height: 0; }
button.small { font-size: .85rem; min-height: 36px; padding: 6px 10px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
form.inline { display: inline; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.filters select, .filters input { width: auto; flex: 1 1 140px; }
.seg { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.seg a { flex: 1; text-align: center; padding: 9px 10px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--surface-1); color: var(--text-primary); white-space: nowrap; }
.seg a.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; }

table { width: 100%; border-collapse: collapse; font-size: .88rem; margin-top: 8px; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
th { color: var(--text-secondary); font-weight: 600; } .num { text-align: right; font-variant-numeric: tabular-nums; }

.flash { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--surface-1);
  border: 1px solid var(--good); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; }
.flash.error { border-color: var(--critical); }

/* bottom tab bar + big add button */
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: var(--surface-1);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; display: grid; place-items: center; height: var(--tabs-h); font-size: .72rem; color: var(--text-secondary); }
.tabs a span { font-size: 1.25rem; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabs a.on { color: var(--accent); font-weight: 650; }
.tabs a.on span { filter: none; opacity: 1; }
.fab { position: fixed; right: 18px; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); z-index: 11;
  width: 58px; height: 58px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 2rem; font-weight: 400; box-shadow: 0 4px 14px rgba(0,0,0,.25); }

@media (min-width: 900px) {
  main { max-width: 860px; }
  .chart { height: 260px; }
}

/* login */
body.login { padding-bottom: 0; min-height: 100vh; display: grid; place-items: center; }
.login-card { max-width: 360px; margin: 40px auto; text-align: center; display: grid; gap: 8px; justify-items: center; }
.login-card .form { width: 100%; text-align: left; }
.login-card img { border-radius: 16px; }

/* Phase 5: subscriptions, goals, receipts, import */
label.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--text-primary); }
label.check input { width: auto; min-height: 0; margin: 0; }
fieldset.checks { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: grid; gap: 6px; margin: 0; }
details.card.muted summary { opacity: .65; }
a.button { display: inline-block; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  color: var(--text-primary); text-decoration: none; }
.grid-receipts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.receipt { display: flex; flex-direction: column; background: var(--surface-1); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; color: var(--text-primary); text-decoration: none; }
.receipt img, .receipt .pdf { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; background: var(--grid); }
.receipt .pdf { display: grid; place-items: center; font-size: 1.1rem; color: var(--text-secondary); }
.receipt .cap { padding: 8px 10px; font-size: .9rem; }
.list.import > li { display: grid; gap: 6px; }
.list.import > li.dup { opacity: .65; }
.list.import select { padding: 7px 9px; }
.nowrap { white-space: nowrap; }
.pos { color: var(--good-ink); }
