/* style.css -- the look. Colours and sizes are variables at the top, so changing
   the theme is a handful of lines. Dark mode follows the phone's own setting. */

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("fonts/atkinson-hyperlegible-next-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("fonts/atkinson-hyperlegible-next-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("fonts/atkinson-hyperlegible-next-latin-800-normal.woff2") format("woff2");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --page: #f3f3f6;
  --raised: #ffffff;
  --frame: #e2e2e9;          /* around the app on a wide PC screen */
  --ink: #15151a;
  --ink-2: #4f4f59;
  --muted: #686873;
  --hairline: #dfdfe6;
  --accent: #6250d6;
  --accent-weak: #e4e0fa;    /* meter track: a lighter step of the accent */
  --on-accent: #ffffff;
  --money-in: #006300;       /* + amounts */
  --warning: #fab219;
  --warning-weak: #fbe8c2;
  --critical: #d03b3b;
  --critical-weak: #f5d9d9;
  --scrim: rgba(12, 12, 20, 0.45);
  --font: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --nav-height: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #17171c;
    --raised: #212128;
    --frame: #0f0f13;
    --ink: #f1f1f4;
    --ink-2: #c4c4cc;
    --muted: #9d9da8;
    --hairline: #31313b;
    --accent: #9085e9;
    --accent-weak: #302b58;
    --on-accent: #15151a;
    --money-in: #2fbf4f;
    --warning-weak: #4a3b14;
    --critical-weak: #4d2424;
    --scrim: rgba(0, 0, 0, 0.6);
  }
}

/* ------------------------------------------------------------------ basics */

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body.sheet-open { overflow: hidden; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.35; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

h1, h2, h3, p, dl, dd { margin: 0; }

.app {
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 0 20px calc(var(--nav-height) + 96px + env(safe-area-inset-bottom));
  background: var(--page);
}

/* On a wide PC screen, show the app as a phone-width column. */
@media (min-width: 600px) {
  body { background: var(--frame); }
  .app { border-left: 1px solid var(--hairline); border-right: 1px solid var(--hairline); }
}

.muted { color: var(--muted); }
.empty { padding: 18px 0; color: var(--ink-2); }
.hint { margin: 8px 0 12px; font-size: 14px; color: var(--ink-2); }

/* ------------------------------------------------------------------ buttons */

.primary-btn, .secondary-btn, .danger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 700;
  text-align: center;
}
.primary-btn { background: var(--accent); color: var(--on-accent); border: 1px solid var(--accent); }
.secondary-btn { background: var(--raised); color: var(--ink); border: 1px solid var(--hairline); }
.danger-btn { background: var(--raised); color: var(--critical); border: 1px solid var(--hairline); }
.btn-wide { width: 100%; }

.text-btn {
  min-height: 44px;
  padding: 8px 6px;
  background: none;
  border: 0;
  color: var(--accent);
  font-weight: 700;
}
.text-btn--danger { color: var(--critical); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: var(--raised);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn--small { width: 36px; height: 36px; border: 0; background: none; }
.icon-btn--small svg { width: 18px; height: 18px; }

/* ------------------------------------------------------------------ headers */

.page-head { padding: calc(20px + env(safe-area-inset-top)) 0 10px; }
.page-head h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.01em; }
.page-head--split { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.page-head--split h1 { font-size: 20px; }
.page-head--split span { font-size: 14px; color: var(--ink-2); }

.navbar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  padding: 6px 0 14px;
}
.navbar-title { text-align: center; font-size: 18px; font-weight: 700; line-height: 1.25; }
.navbar-title span { display: block; font-size: 14px; font-weight: 400; color: var(--ink-2); }

/* ------------------------------------------------------------------ hero number */

.hero { padding: 4px 0 20px; }
.hero-label { color: var(--ink-2); font-size: 15px; }
.hero-figure {
  margin: 2px 0 10px;
  font-size: clamp(44px, 15vw, 64px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.hero-figure.is-long { font-size: clamp(34px, 11.5vw, 52px); }
.hero--compact .hero-figure { font-size: clamp(36px, 12vw, 48px); }
.hero-sub { font-size: 17px; }
/* A money figure never splits across lines -- a minus sign on its own is a misread waiting to happen. */
.hero-sub strong, .day-balance strong, .limit-head span { white-space: nowrap; }
.hero-note { margin-top: 4px; font-size: 14px; color: var(--ink-2); }
.hero-note .state { margin-right: 4px; }

.state { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); font-weight: 700; }
.state svg { width: 18px; height: 18px; flex: none; }

/* ------------------------------------------------------------------ meter (spending limit) */

.meter { display: block; height: 12px; border-radius: 999px; background: var(--accent-weak); overflow: hidden; }
.meter-fill { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.meter--tight { background: var(--warning-weak); }
.meter--tight .meter-fill { background: var(--warning); }
.meter--over { background: var(--critical-weak); }
.meter--over .meter-fill { background: var(--critical); }
.meter-caption { margin-top: 8px; font-size: 14px; color: var(--ink-2); }

.limit {
  margin: 0 0 22px;
  padding: 16px;
  border-radius: 16px;
  background: var(--raised);
  border: 1px solid var(--hairline);
}
.limit-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.limit-head h2 { font-size: 16px; font-weight: 800; }
.limit-head span { font-size: 14px; color: var(--ink-2); white-space: nowrap; }
.limit .eq { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--hairline); }

/* today: allowance - spent = left */
.eq { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr); align-items: start; }
.eq-num { display: block; font-size: 19px; font-weight: 700; white-space: nowrap; }
.eq-cap { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink-2); }
.eq-cap svg { width: 15px; height: 15px; flex: none; }
.eq-op { padding: 0 6px; font-size: 24px; line-height: 1.05; color: var(--muted); }
.eq-result .eq-num { font-weight: 800; }
.eq-note { margin-top: 10px; font-size: 13px; color: var(--muted); }

/* ------------------------------------------------------------------ this week / this month */

.periods { display: grid; gap: 14px; margin: 0 0 24px; padding: 16px 0; border-top: 1px solid var(--hairline); border-bottom: 1px solid var(--hairline); }
.period h2 { margin-bottom: 6px; font-size: 16px; font-weight: 800; }
.period h2 span { margin-left: 6px; font-size: 14px; font-weight: 400; color: var(--ink-2); }

.trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.trio--two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.trio dt { font-size: 13px; color: var(--ink-2); }
.trio dd { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.trio dd.is-in { color: var(--money-in); }
.hero .trio { margin-top: 8px; }

/* ------------------------------------------------------------------ lists */

.block { margin-bottom: 22px; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.block-head h2 { font-size: 18px; font-weight: 800; }

.day { margin-bottom: 14px; }
.day-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--hairline);
  font-size: 15px;
  font-weight: 700;
}
.day-head .total { margin-left: auto; font-variant-numeric: tabular-nums; }

.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  width: 100%;
  min-height: 56px;
  padding: 9px 0;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  background: none;
  text-align: left;
}
.row.is-picked { background: var(--accent-weak); box-shadow: -20px 0 0 var(--accent-weak), 20px 0 0 var(--accent-weak); }
.row-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { grid-row: 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--ink-2); }
.row-amt {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  padding-left: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.row-amt.is-in { color: var(--money-in); }
.row-amt.is-expected { font-weight: 400; color: var(--ink-2); }
.row-amt.is-in.is-expected { color: var(--money-in); }

.nag {
  display: grid;
  gap: 10px;
  margin: 0 0 22px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--raised);
  border: 1px solid var(--hairline);
  font-size: 15px;
}
.nag .secondary-btn { justify-self: start; min-height: 40px; }

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

.cal-heads, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-heads { margin-bottom: 4px; font-size: 12px; color: var(--ink-2); text-align: center; }
.cal-day {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 3px;
  min-height: 52px;
  padding: 6px 0 4px;
  border: 0;
  border-radius: 12px;
  background: var(--raised);
}
.cal-num { font-size: 15px; font-weight: 700; line-height: 1.2; }
.cal-dots { display: flex; gap: 3px; min-height: 7px; }
.cal-day.is-other { background: none; color: var(--muted); }
.cal-day.is-today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-day.is-picked { background: var(--accent); color: var(--on-accent); }
.cal-day.is-negative::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 3px;
  height: 3px;
  border-radius: 2px;
  background: var(--critical);
}

.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; }
.dot--out { background: var(--ink-2); }
.dot--in { background: var(--money-in); }
.dot--expected { background: none; box-shadow: inset 0 0 0 1.5px var(--ink-2); }
.dot--in.dot--expected { box-shadow: inset 0 0 0 1.5px var(--money-in); }
.cal-day.is-picked .dot--out { background: var(--on-accent); }
.cal-day.is-picked .dot--expected { background: none; box-shadow: inset 0 0 0 1.5px var(--on-accent); }

.day-panel { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--hairline); }
.day-panel h2 { margin-bottom: 4px; font-size: 18px; font-weight: 800; }
.day-balance { margin: 12px 0 6px; font-size: 15px; color: var(--ink-2); }
.day-balance strong { color: var(--ink); }
.day-warn { margin-bottom: 10px; font-size: 14px; color: var(--ink-2); }
.day-panel .secondary-btn { margin-top: 8px; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 10px 0 4px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-bar { width: 18px; height: 8px; border-radius: 0 4px 4px 0; background: var(--accent); }
.legend-tick { width: 2px; height: 14px; border-radius: 1px; background: var(--ink); }

/* ------------------------------------------------------------------ reports: where it went */

.bars { list-style: none; margin: 0; padding: 0; }
.bar-row { padding: 12px 0; border-bottom: 1px solid var(--hairline); }
.bar-top { display: flex; justify-content: space-between; gap: 12px; font-weight: 700; }
.bar-top span:last-child { font-variant-numeric: tabular-nums; }
.bar-track { position: relative; height: 10px; margin: 8px 0 6px; border-radius: 0 5px 5px 0; background: var(--hairline); }
.bar-fill { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 0 4px 4px 0; background: var(--accent); }
.bar-usual { position: absolute; top: -4px; bottom: -4px; width: 2px; border-radius: 1px; background: var(--ink); box-shadow: 0 0 0 2px var(--page); }
.bar-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--ink-2); }

/* ------------------------------------------------------------------ segmented switch */

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 6px 0 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--page);
}
.seg--page { background: var(--hairline); margin: 0 0 10px; }
.seg-btn { min-height: 40px; border: 0; border-radius: 9px; background: none; font-weight: 700; color: var(--ink-2); }
.seg-btn[aria-pressed="true"] { background: var(--raised); color: var(--ink); box-shadow: 0 0 0 1px var(--hairline); }

/* ------------------------------------------------------------------ settings + setup forms */

.group { padding: 18px 0 8px; border-bottom: 1px solid var(--hairline); }
.group h2 { margin-bottom: 8px; font-size: 18px; font-weight: 800; }

.field { display: block; margin: 10px 0 16px; }
.field > span { display: block; font-weight: 700; }
.field > small { display: block; margin-bottom: 6px; font-size: 14px; color: var(--ink-2); }
.field > span + input, .field > span + select { margin-top: 6px; }
.field input, .field select, .inline-form input {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--hairline);
  background: var(--raised);
}

.cat-list { list-style: none; margin: 0 0 10px; padding: 0; }
.cat-list li { display: flex; align-items: center; justify-content: space-between; min-height: 44px; border-bottom: 1px solid var(--hairline); }
.inline-form { display: flex; gap: 8px; margin-bottom: 10px; }
.inline-form input { flex: 1; min-width: 0; }

.btn-stack { display: grid; gap: 10px; margin-bottom: 12px; }
.file-btn { position: relative; }
.file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.version { padding: 20px 0; font-size: 13px; color: var(--muted); text-align: center; }

.setup { padding: calc(28px + env(safe-area-inset-top)) 0 40px; }
.setup h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.01em; }
.lede { margin: 8px 0 18px; color: var(--ink-2); }
.setup-restore { margin-top: 22px; color: var(--ink-2); }
.link-btn { color: var(--accent); font-weight: 700; text-decoration: underline; cursor: pointer; }
.problem { margin: 0 0 18px; padding: 12px 14px; border-radius: 12px; background: var(--critical-weak); color: var(--ink); }

/* ------------------------------------------------------------------ bottom tabs + add button */

.tabs {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  width: min(480px, 100%);
  transform: translateX(-50%);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--raised);
  border-top: 1px solid var(--hairline);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--nav-height);
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: 12px;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent); font-weight: 700; }

.fab {
  position: fixed;
  z-index: 11;
  right: max(20px, calc(50% - 240px + 20px));
  bottom: calc(var(--nav-height) + 18px + env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 20px;
  border: 0;
  background: var(--accent);
  color: var(--on-accent);
}
.fab svg { width: 30px; height: 30px; }

/* ------------------------------------------------------------------ the add / edit sheet */

.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: var(--scrim); }
.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 21;
  display: flex;
  flex-direction: column;
  width: min(480px, 100%);
  max-height: 100vh;
  max-height: 100dvh;
  transform: translateX(-50%);
  border-radius: 22px 22px 0 0;
  background: var(--raised);
  padding-bottom: env(safe-area-inset-bottom);
  animation: sheet-up 0.22s ease-out;
}
@keyframes sheet-up {
  from { transform: translate(-50%, 100%); }
  to { transform: translate(-50%, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
}

.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 8px 14px 0; }
.sheet-head h2 { font-size: 17px; font-weight: 800; text-align: center; }
.sheet-head > :first-child { justify-self: start; }
.sheet-head > :last-child { justify-self: end; }
.sheet-head--seg { grid-template-columns: auto 1fr; gap: 10px; padding-right: 20px; }
.seg--head { margin: 0; }
.sheet-body { flex: 1 1 auto; overflow-y: auto; padding: 4px 20px 6px; }

.amount { padding: 8px 0 6px; }
.amount-expr { min-height: 22px; font-size: 16px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.amount-total { font-size: 44px; font-weight: 800; line-height: 1.05; letter-spacing: -0.02em; white-space: nowrap; }
.amount-total.is-empty { color: var(--muted); }
.amount-total.is-in { color: var(--money-in); }

.sheet-label { margin-top: 10px; font-size: 14px; font-weight: 700; color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 8px; }
.recent { display: flex; align-items: center; gap: 8px; margin: 10px -20px 6px 0; padding: 0 20px 4px 0; overflow-x: auto; scrollbar-width: none; }
/* A label at the start of a swipe row, so the row doesn't need a line of its own. */
/* It stays put while the chips slide under it. */
.row-label {
  position: sticky;
  left: 0;
  z-index: 1;
  flex: none;
  align-self: stretch;
  display: flex;
  align-items: center;
  padding-right: 4px;
  background: var(--raised);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-2);
}
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.recent::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--page);
  white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.chip-amt { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.chip--new { border-style: dashed; color: var(--accent); font-weight: 700; background: none; }
.date-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.sheet .field { margin: 8px 0 6px; }
.sheet .field > span { font-size: 14px; color: var(--ink-2); }
.sheet-hint { min-height: 0; margin: 2px 0 0; font-size: 14px; color: var(--ink-2); }
.sheet-hint:empty { display: none; }
.sheet-error { min-height: 20px; margin: 2px 0 0; font-size: 14px; font-weight: 700; color: var(--critical); }

/* The keypad: chunky till keys, Save as the big key where "=" would be. */
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--hairline);
  background: var(--page);
}
.key {
  display: grid;
  place-items: center;
  min-height: 54px;
  border: 0;
  border-radius: 14px;
  background: var(--raised);
  box-shadow: inset 0 -3px 0 var(--hairline);
  font-size: 24px;
  font-weight: 700;
}
.key:active { transform: translateY(1px); box-shadow: inset 0 -1px 0 var(--hairline); }
.key svg { width: 26px; height: 26px; }
.key--op { color: var(--accent); }
.key--save { grid-column: span 2; background: var(--accent); color: var(--on-accent); box-shadow: none; font-size: 20px; }

/* Most phones: a slightly smaller keypad so more of the form fits above it. */
@media (max-height: 880px) {
  .keypad { gap: 6px; padding: 8px 12px 10px; }
  .key { min-height: 46px; font-size: 21px; }
  .amount-total { font-size: 36px; }
  .amount { padding: 4px 0 2px; }
}

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 96px + env(safe-area-inset-bottom));
  z-index: 30;
  max-width: min(440px, calc(100% - 32px));
  padding: 10px 16px;
  transform: translateX(-50%);
  border-radius: 12px;
  background: var(--ink);
  color: var(--page);
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.is-on { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
