:root {
  --bg: #f6f7fb; --card: #ffffff; --ink: #161a2b; --muted: #636a80; --line: #e3e6ef; --soft: #eef1f8;
  --accent: #1d3a8a; --accent-2: #3557c7; --accent-soft: #e6ecfb;
  --good: #177245; --good-soft: #e3f4ea; --warn: #9a5b00; --warn-soft: #fff1d6; --bad: #b42318; --bad-soft: #fde7e5;
  --purple: #6a3bc0; --purple-soft: #efe8fb; --teal: #0f6e74; --teal-soft: #dff3f3;
  --radius: 14px; --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 14px rgba(20, 30, 60, .05);
  --nav-h: 64px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1220; --card: #181c2e; --ink: #e8eaf3; --muted: #9aa1b8; --line: #2a3048; --soft: #20253a;
    --accent: #8fa8ff; --accent-2: #a9bcff; --accent-soft: #232c4d;
    --good: #5fd39a; --good-soft: #163527; --warn: #f3b552; --warn-soft: #3a2c12; --bad: #ff8a7f; --bad-soft: #3d1c1a;
    --purple: #c3a6ff; --purple-soft: #2c2347; --teal: #6fd6dc; --teal-soft: #15343a;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-2); }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* ---------- Layout ---------- */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); padding: calc(env(safe-area-inset-top, 0px) + 12px) 18px 10px;
  display: flex; align-items: center; gap: 12px; }
.top h1 { font-size: 22px; margin: 0; flex: 1; letter-spacing: -.01em; }
.iconbtn { border: 0; background: var(--card); width: 40px; height: 40px; border-radius: 12px; box-shadow: var(--shadow);
  display: grid; place-items: center; font-size: 18px; }
main { max-width: 760px; margin: 0 auto; padding: 4px 16px calc(var(--nav-h) + var(--safe-b) + 90px); }
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; padding: 6px 4px calc(6px + var(--safe-b)); }
.nav a { flex: 1; text-decoration: none; color: var(--muted); display: flex; flex-direction: column; align-items: center;
  gap: 2px; font-size: 11.5px; padding: 4px 0; border-radius: 10px; }
.nav a .ico { font-size: 20px; line-height: 1; }
.nav a.on { color: var(--accent); font-weight: 600; }
.fab { position: fixed; right: 18px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 11; width: 58px; height: 58px;
  border-radius: 18px; border: 0; background: var(--accent); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 6px 20px rgba(29, 58, 138, .35); }
@media (prefers-color-scheme: dark) { .fab { color: #0f1220; } }
@media (min-width: 900px) {
  .nav { top: 0; bottom: 0; right: auto; width: 96px; flex-direction: column; justify-content: flex-start; gap: 6px;
    border-top: 0; border-right: 1px solid var(--line); padding-top: 24px; }
  .nav a { flex: 0; padding: 10px 0; }
  .top, main { margin-left: 96px; }
  main { padding-bottom: 100px; }
  .fab { bottom: 28px; right: 28px; }
}

/* ---------- Building blocks ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin: 0 0 12px; }
@media (prefers-color-scheme: dark) { .card { border: 1px solid var(--line); } }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  margin: 22px 2px 8px; display: flex; align-items: center; gap: 8px; }
.section-title .count { background: var(--soft); border-radius: 99px; padding: 0 8px; font-size: 12px; letter-spacing: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
@media (prefers-color-scheme: dark) { .tile { border: 1px solid var(--line); } }
.tile .label { font-size: 12px; color: var(--muted); }
.tile .value { font-size: 19px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--soft);
  color: var(--muted); white-space: nowrap; }
.pill.blue { background: var(--accent-soft); color: var(--accent); }
.pill.green { background: var(--good-soft); color: var(--good); }
.pill.amber { background: var(--warn-soft); color: var(--warn); }
.pill.red { background: var(--bad-soft); color: var(--bad); }
.pill.purple { background: var(--purple-soft); color: var(--purple); }
.pill.teal { background: var(--teal-soft); color: var(--teal); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 6px 13px; font-size: 13.5px; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .chip.on { color: #0f1220; } }
.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.empty { text-align: center; color: var(--muted); padding: 26px 12px; }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; }
.btn { border: 0; border-radius: 11px; padding: 10px 16px; font-weight: 600; background: var(--soft); }
.btn.primary { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0f1220; } }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.linkbtn { border: 0; background: none; color: var(--accent-2); padding: 0; font-weight: 600; }

/* ---------- Lists ---------- */
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
@media (prefers-color-scheme: dark) { .list { border: 1px solid var(--line); } }
.li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.li:first-child { border-top: 0; }
.li:active { background: var(--soft); }
.li .title { font-weight: 600; }
.li .sub { font-size: 13px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.li .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.li.done .title { text-decoration: line-through; color: var(--muted); }
.check { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); background: transparent;
  display: grid; place-items: center; font-size: 14px; color: transparent; padding: 0; }
.check.on { background: var(--good); border-color: var(--good); color: #fff; }
.month-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-weight: 600; margin: 18px 4px 6px; }
.bar { height: 8px; border-radius: 99px; background: var(--soft); overflow: hidden; position: relative; }
.bar > i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--accent-2); }
.bar.time > i { background: var(--muted); opacity: .55; }
.bar.good > i { background: var(--good); }
.bar.bad > i { background: var(--bad); }

/* ---------- Timeline ---------- */
.goal { cursor: pointer; }
.goal .head { display: flex; gap: 10px; align-items: flex-start; }
.goal h3 { margin: 0; font-size: 16.5px; flex: 1; }
.goal .meta { font-size: 13px; color: var(--muted); margin: 4px 0 10px; }
.goal .bars { display: grid; grid-template-columns: 64px 1fr 44px; gap: 6px 10px; align-items: center; font-size: 12.5px; color: var(--muted); }
.goal .bars span:nth-child(3n) { text-align: right; font-variant-numeric: tabular-nums; }
.goal .next { margin-top: 10px; font-size: 13.5px; padding-top: 10px; border-top: 1px dashed var(--line); }
.goal .next b { color: var(--ink); }
.tl { position: relative; padding-left: 30px; }
.tl::before { content: ""; position: absolute; left: 11px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.tl-month { position: relative; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 20px 0 8px -30px; padding-left: 30px; }
.tl-month:first-child { margin-top: 4px; }
.tl-item { position: relative; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 10px 12px; margin-bottom: 8px; cursor: pointer;
  display: flex; gap: 10px; align-items: center; }
@media (prefers-color-scheme: dark) { .tl-item { border: 1px solid var(--line); } }
.tl-item .dot { position: absolute; left: -26px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; border-radius: 50%;
  background: var(--card); border: 3px solid var(--accent-2); }
.tl-item.keydate .dot { border-radius: 3px; transform: translateY(-50%) rotate(45deg); width: 14px; height: 14px; left: -25px; border-color: var(--purple); }
.tl-item.goal-target .dot { border-color: var(--teal); background: var(--teal); }
.tl-item.overdue .dot { border-color: var(--bad); }
.tl-item.done { opacity: .6; }
.tl-item.done .t { text-decoration: line-through; }
.tl-item .when { flex: none; width: 50px; text-align: center; line-height: 1.1; }
.tl-item .when b { display: block; font-size: 19px; }
.tl-item .when span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; }
.tl-item .t { font-weight: 600; }
.tl-item .s { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.today { position: relative; margin: 10px 0 12px -30px; padding-left: 30px; display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; font-weight: 700; color: var(--bad); text-transform: uppercase; letter-spacing: .06em; }
.today::before { content: ""; position: absolute; left: 4px; width: 16px; height: 16px; border-radius: 50%; background: var(--bad);
  box-shadow: 0 0 0 4px var(--bad-soft); }
.today::after { content: ""; flex: 1; height: 2px; background: var(--bad); opacity: .5; }
.alert { border-left: 4px solid var(--bad); }
.alert.amber { border-left-color: var(--warn); }

/* ---------- Sheets / forms ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(10, 14, 30, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease; }
.sheet { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + var(--safe-b)); animation: up .2s ease; }
@media (min-width: 700px) { .backdrop { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }
.sheet h2 { margin: 0 0 14px; font-size: 19px; display: flex; align-items: center; gap: 8px; }
.sheet h2 .x { margin-left: auto; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input:not([type=checkbox]), .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; background: var(--bg); font-size: 16px; }
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; border-color: transparent; }
.field .inline { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--ink); font-weight: 500; }
.field .inline input { width: 22px; height: 22px; }
.money-input { position: relative; }
.money-input::before { content: "£"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money-input input { padding-left: 26px !important; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; gap: 10px; margin-top: 16px; }
.actions .btn.primary { flex: 1; }
.receipt-box { border: 1px dashed var(--line); border-radius: 11px; padding: 10px; display: flex; gap: 10px; align-items: center; }
.receipt-box img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.picker button { border: 1px solid var(--line); background: var(--bg); border-radius: 14px; padding: 14px 6px; display: flex; flex-direction: column;
  align-items: center; gap: 6px; font-weight: 600; font-size: 13.5px; }
.picker button .ico { font-size: 24px; }
.error { color: var(--bad); font-size: 14px; margin-top: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 90px); transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; animation: up .2s ease; }
.banner { background: var(--warn-soft); color: var(--warn); padding: 8px 14px; border-radius: 10px; font-size: 13.5px; margin-bottom: 12px; }
.menu { position: absolute; right: 16px; top: calc(env(safe-area-inset-top, 0px) + 58px); background: var(--card); border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .18); border: 1px solid var(--line); z-index: 40; min-width: 220px; overflow: hidden; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 13px 16px; border-top: 1px solid var(--line); }
.menu button:first-child { border-top: 0; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: 100%; max-width: 360px; }
.login .brand { text-align: center; margin-bottom: 22px; }
.login .brand img { width: 72px; height: 72px; border-radius: 18px; }
.login .brand h1 { margin: 10px 0 2px; font-size: 24px; }
