/* Budget app — styles. Light + dark from the phone's own setting. */

:root {
  --page: #eceef0;
  --surface: #ffffff;
  --surface-2: #f5f6f7;
  --ink: #14171a;
  --muted: #6e7278;
  --line: #e2e4e8;
  --accent: #0e7c66;
  --accent-ink: #ffffff;
  --accent-soft: #e3f0ec;
  --warn: #b06d0c;
  --danger: #be3a2b;
  --ok: #2e7d57;
  --exp: #c9642a;
  --inc: #2f6fb8;
  --radius: 14px;
  --shadow: 0 -14px 34px rgba(0, 0, 0, .3);
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0b0c0e;
    --surface: #17191c;
    --surface-2: #1f2226;
    --ink: #f1f2f4;
    --muted: #9aa0a6;
    --line: #2a2e33;
    --accent: #43c29f;
    --accent-ink: #06322a;
    --accent-soft: #123029;
    --warn: #d9a03c;
    --danger: #e2685a;
    --ok: #5fc79b;
    --exp: #f08a4b;
    --inc: #6fb2f0;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--page);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { display: flex; flex-direction: column; }

/* ---------- chrome ---------- */

#topbar {
  flex: 0 0 auto;
  padding: calc(env(safe-area-inset-top) + 10px) 18px 10px;
  background: var(--page);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
#topbar h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
#topbar .link { font-size: 14px; font-weight: 600; color: var(--accent); background: none; border: 0; padding: 4px 0; }
#topbar .link.muted { color: var(--muted); }

#view {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 18px 24px;
}

#tabbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px calc(env(safe-area-inset-bottom) + 8px);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
#tabbar button {
  background: none; border: 0; padding: 6px 2px; min-width: 54px;
  font: inherit; font-size: 11.5px; font-weight: 600; color: var(--muted);
}
#tabbar button.on { color: var(--accent); }
#tabbar .plus {
  width: 46px; height: 46px; min-width: 46px; margin-top: -22px;
  border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  font-size: 26px; font-weight: 400; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .22);
}

/* ---------- type + primitives ---------- */

.num { font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 600; }
.amount { font-size: 40px; font-weight: 650; line-height: 1.05; margin: 6px 0 2px; }
.amount .cur { font-size: 22px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.muted { color: var(--muted); }
.neg { color: var(--danger); }
.inc { color: var(--inc); }
.exp { color: var(--exp); }
.ok { color: var(--ok); }

.card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-top: 12px;
}
.card.plain { background: var(--surface); }

.row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 5px 0; font-size: 15px; }
.row .k { color: var(--muted); }
.row b { font-weight: 600; white-space: nowrap; }
.row.sub { padding-top: 1px; }
.row.sub .k, .row.sub b { font-size: 13px; color: var(--muted); font-weight: 500; }

.cover {
  margin-top: 12px; padding: 12px 14px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  border-radius: var(--radius);
}
.cover .line { font-size: 15px; font-weight: 650; color: var(--accent); line-height: 1.35; }
.cover .sub { font-size: 12.5px; color: var(--muted); margin-top: 5px; line-height: 1.45; }

.sect {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 20px 0 4px; font-size: 12px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
}
.sect b { font-size: 15px; letter-spacing: 0; text-transform: none; color: var(--ink); }

.item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
  background: none; border-left: 0; border-right: 0; border-top: 0;
  width: 100%; text-align: left; font: inherit; color: inherit;
}
.item:last-child { border-bottom: 0; }
.item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--exp); flex: 0 0 8px; }
.item .dot.income { background: var(--inc); }
.item .what { flex: 1 1 auto; min-width: 0; font-size: 15.5px; }
.item .what small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.item .amt { font-size: 15.5px; font-weight: 600; white-space: nowrap; }

.empty { color: var(--muted); font-size: 14px; line-height: 1.5; padding: 10px 0; }

.tag {
  font-size: 10.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent);
}
.tag.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.tag.plain { background: transparent; color: var(--muted); border: 1px solid var(--line); }

button.btn {
  display: block; width: 100%; margin-top: 14px; padding: 15px;
  border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink);
  font: inherit; font-size: 16px; font-weight: 650;
}
button.btn.inc { background: var(--inc); color: #fff; }
button.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); font-weight: 550; }
button.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); font-weight: 550; }
button.btn[disabled] { opacity: .45; }

/* ---------- segments, chips, fields ---------- */

.seg { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button {
  flex: 1 1 0; padding: 9px 4px; border: 0; border-radius: 9px; background: none;
  font: inherit; font-size: 14px; font-weight: 600; color: var(--muted);
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.seg.three button { font-size: 13px; }

.chips { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 8px; }
.chip {
  padding: 8px 13px; border-radius: 10px; border: 1px solid var(--line);
  background: none; color: var(--ink); font: inherit; font-size: 14px; font-weight: 500;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.field {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-top: 10px; font-size: 15px; color: var(--muted);
}
.field input, .field select, .field textarea {
  border: 0; background: none; font: inherit; color: var(--ink); text-align: right;
  width: 60%; outline: none;
}
.field input::placeholder { color: var(--muted); }
.field.stack { display: block; }
.field.stack input, .field.stack textarea { width: 100%; text-align: left; margin-top: 6px; }

.input-amount {
  width: 100%; border: 0; background: none; outline: none;
  font: inherit; font-size: 40px; font-weight: 650; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; color: var(--ink); padding: 6px 0;
}
.input-amount::placeholder { color: var(--line); }

.note { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin-top: 10px; }

/* ---------- calendar ---------- */

.monthhead { display: flex; align-items: center; gap: 8px; margin: 12px 0 10px; }
.monthhead button { background: none; border: 0; color: var(--muted); font-size: 20px; padding: 0 10px; }
.monthhead .pill {
  flex: 1 1 auto; text-align: center; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 11px; padding: 9px 4px;
  font-size: 14.5px; font-weight: 650;
}
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal .dow { font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); text-align: center; padding-bottom: 5px; }
.cal .dow.sat { color: var(--inc); }
.cal .dow.sun { color: var(--danger); }
.cal button.day {
  height: 52px; border: 0; border-radius: 9px; background: none; padding: 4px 4px 5px;
  display: flex; flex-direction: column; justify-content: space-between; font: inherit;
  color: inherit;
}
.cal button.day .n { font-size: 12px; font-weight: 500; line-height: 1; }
.cal button.day .v { font-size: 9px; font-weight: 700; letter-spacing: -.02em; text-align: right; line-height: 1; }
.cal button.day.out { opacity: .4; }
.cal button.day.today { background: color-mix(in srgb, var(--accent) 15%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent); }
.cal button.day.picked { background: color-mix(in srgb, var(--accent) 26%, transparent); }

.sum { display: flex; border-top: 1px solid var(--line); margin-top: 16px; padding-top: 11px; }
.sum div { flex: 1 1 0; text-align: center; }
.sum .lbl { font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.sum .val { font-size: 14px; font-weight: 700; margin-top: 4px; }

/* ---------- budgets ---------- */

.bud { margin-bottom: 16px; }
.bud .line { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 15px; }
.bud .line b { font-weight: 650; white-space: nowrap; }
.bud .subs { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.bar { height: 7px; border-radius: 4px; background: var(--line); overflow: hidden; margin: 8px 0 0; }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.bar i.low { background: var(--warn); }
.bar i.out { background: var(--danger); }

/* ---------- sheets ---------- */

#sheet-root { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
.scrim { position: absolute; inset: 0; background: rgba(8, 10, 12, .45); opacity: 0; transition: opacity .18s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 12px 18px calc(env(safe-area-inset-bottom) + 16px);
  box-shadow: var(--shadow);
  transform: translateY(102%); transition: transform .22s ease;
  max-height: 88vh; overflow-y: auto;
}
#sheet-root.open { pointer-events: auto; }
#sheet-root.open .scrim { opacity: 1; }
#sheet-root.open .sheet { transform: translateY(0); }
.grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 12px; }
.sheet h2 { margin: 0 0 4px; font-size: 19px; font-weight: 650; }
.sheet .cap { font-size: 13px; color: var(--muted); }
.kbtn { display: flex; gap: 7px; margin-top: 10px; }
.kbtn button {
  flex: 1 1 0; padding: 10px 0; border-radius: 10px; border: 1px solid var(--line);
  background: none; color: var(--ink); font: inherit; font-size: 13.5px; font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  .sheet, .scrim { transition: none; }
}

/* ---------- toast + first run ---------- */

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 92px);
  transform: translate(-50%, 12px); opacity: 0;
  background: var(--ink); color: var(--page);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 550;
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 60;
  max-width: 88vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#firstrun {
  position: fixed; inset: 0; z-index: 70; background: var(--page);
  padding: calc(env(safe-area-inset-top) + 40px) 22px 30px;
  display: none; flex-direction: column;
}
#firstrun.show { display: flex; }
#firstrun h1 { font-size: 26px; margin: 0 0 8px; letter-spacing: -.02em; }
#firstrun p { color: var(--muted); font-size: 15px; line-height: 1.5; margin: 0 0 22px; }
