/* Budget app styles.
 *
 * Dark mode is selected, not flipped: each value is chosen for its surface.
 * Colours follow the data-viz palette - status steps for budget state,
 * never a per-category hue (24 categories would need 24 colours, which is
 * the classic dashboard mistake).
 */

:root {
  color-scheme: light;

  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --surface-2:    #f2f1ed;
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --muted:        #898781;
  --hairline:     #e1e0d9;

  /* status: state of a budget, paired with text - never colour alone */
  --good:         #0ca30c;
  --warning:      #fab219;
  --serious:      #ec835a;
  --critical:     #d03b3b;
  --accent:       #2a78d6;

  --meter-track:  #e8e7e1;

  --radius:       10px;
  --pad:          16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:       #0d0d0d;
    --surface:     #1a1a19;
    --surface-2:   #232321;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --muted:       #898781;
    --hairline:    #2c2c2a;
    --meter-track: #2c2c2a;
    --accent:      #3987e5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:       #0d0d0d;
  --surface:     #1a1a19;
  --surface-2:   #232321;
  --ink:         #ffffff;
  --ink-2:       #c3c2b7;
  --muted:       #898781;
  --hairline:    #2c2c2a;
  --meter-track: #2c2c2a;
  --accent:      #3987e5;
}

* { box-sizing: border-box; }

html { overflow-x: hidden; }

body {
  margin: 0;
  max-width: 100%;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- header */

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  padding: 12px var(--pad) 0;
}

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

.bar h1 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.bar .who { color: var(--muted); font-size: 13px; }

/* Seven tabs do not fit on a phone. Let the strip scroll rather than let it
   push the whole page wider than the viewport - which it did, at 504px. */
nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
nav::-webkit-scrollbar { display: none; }

nav button {
  appearance: none;
  flex: 0 0 auto;
  white-space: nowrap;
  border: 0;
  background: none;
  color: var(--ink-2);
  font: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  min-height: 44px;            /* touch target */
}

nav button[aria-current="page"] {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

nav .count {
  display: inline-block;
  min-width: 20px;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}

nav .count[data-zero="true"] { background: var(--muted); }

main { padding: var(--pad); max-width: 860px; margin: 0 auto; }

/* ------------------------------------------------------------ stat tiles */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.kpi .label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi .value {
  font: 600 26px/1.2 var(--font);
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
  letter-spacing: -0.02em;
}

.kpi .sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.kpi .value.neg { color: var(--critical); }
.kpi .value.pos { color: var(--good); }

.month-nav {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 4px;
}

.month-nav button { min-width: 44px; padding: 0 12px; font-size: 17px; line-height: 1; }
.month-nav select { flex: 0 1 220px; font-weight: 600; }

/* ---------------------------------------------------------------- meters */

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 22px 0 8px;
}

.meters {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  overflow: hidden;
}

.meter-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--hairline);
}

.meter-row:last-child { border-bottom: 0; }

.meter-row .name { font-weight: 500; }

.meter-row .amounts {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--ink-2);
  text-align: right;
  white-space: nowrap;
}

/* the meter: one ratio against a limit */
.track {
  grid-column: 1 / -1;
  height: 6px;
  border-radius: 3px;
  background: var(--meter-track);
  margin-top: 7px;
  overflow: hidden;
  position: relative;
}

.fill {
  height: 100%;
  border-radius: 3px;
  background: var(--good);
  transition: width .2s ease;
}

.fill[data-state="warning"]  { background: var(--warning); }
.fill[data-state="serious"]  { background: var(--serious); }
.fill[data-state="critical"] { background: var(--critical); }

/* Status never travels by colour alone - every non-good row says so. */
.state {
  grid-column: 1 / -1;
  font-size: 12px;
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-variant-numeric: tabular-nums;
}

.state[data-state="critical"] { color: var(--critical); }
.state[data-state="serious"]  { color: var(--ink-2); }
.state[data-state="warning"]  { color: var(--ink-2); }
.state .rollover { color: var(--muted); }

.unbudgeted { color: var(--muted); font-size: 12px; }

/* ----------------------------------------------------------- review queue */

.txn {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}

.txn-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.txn .merchant { font-weight: 600; }
.txn .amount {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}
.txn .amount.inflow { color: var(--good); }

.txn .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.txn .reason {
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 8px;
  padding-left: 9px;
  border-left: 2px solid var(--hairline);
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 11px; }

button.chip, select.chip {
  appearance: none;
  font: inherit;
  font-size: 14px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--hairline);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
}

button.chip.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

button.chip:hover { border-color: var(--muted); }
button.chip.primary:hover { filter: brightness(1.07); }

select.chip { padding-right: 30px; }

.card.pad { padding: 14px; }

.field { display: block; margin-bottom: 12px; }
.field > span {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 5px;
}
.field select, .field input[type="file"] { width: 100%; max-width: 420px; }
.field input[type="file"] { font: inherit; color: var(--ink-2); }

.hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 10px; }
.fact .n { font: 600 20px/1.2 var(--font); font-variant-numeric: tabular-nums; }
.fact .l { font-size: 12px; color: var(--muted); }
.fact .n.flag { color: var(--serious); }

.notice {
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 13px;
  color: var(--ink-2);
}

.pair {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.pair .legs { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.pair .why { font-size: 12px; color: var(--muted); margin-top: 4px; }

.field input[type="text"], .field input[type="number"], .field input[type="date"] {
  width: 100%; max-width: 420px; padding: 0 12px;
}

input.chip { min-height: 44px; }

td input.amount-input {
  width: 120px; text-align: right; padding: 0 8px; min-height: 36px;
  font: inherit; font-variant-numeric: tabular-nums;
  border: 1px solid var(--hairline); border-radius: 6px;
  background: var(--surface-2); color: var(--ink);
}

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.switch input { width: 18px; height: 18px; }

.goal { background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 13px 15px; margin-bottom: 10px; }
.goal .top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.goal .name { font-weight: 600; }
.goal .amt { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--ink-2); }
.goal .say { font-size: 12px; margin-top: 6px; display: flex; gap: 5px; }
.goal .say[data-pace="behind"]  { color: var(--critical); }
.goal .say[data-pace="overdue"] { color: var(--critical); }
.goal .say[data-pace="done"]    { color: var(--good); }
.goal .say[data-pace="on track"], .goal .say[data-pace="no deadline"] { color: var(--ink-2); }

.mini { font-size: 12px; color: var(--muted); }
button.link { background: none; border: 0; color: var(--critical);
  font: inherit; font-size: 13px; cursor: pointer; padding: 6px; }

/* ---------------------------------------------------------------- tables */

/* A wide table scrolls inside its own card instead of widening the page. */
.card { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--hairline);
}

td { padding: 9px 10px; border-bottom: 1px solid var(--hairline); }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  overflow: hidden;
}

.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--muted);
}

.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }

.hidden { display: none !important; }

.err {
  background: var(--surface);
  border: 1px solid var(--critical);
  border-left-width: 3px;
  border-radius: var(--radius);
  padding: 11px 14px;
  margin-bottom: 14px;
  font-size: 14px;
}

@media (max-width: 520px) {
  main { padding: 12px; }
  .kpi .value { font-size: 22px; }
  nav button { padding: 9px 10px; font-size: 13px; }
}
