/* Cash-flow calendar — departure board over a paper timetable. */

:root {
  --paper: #F6F4EF;
  --paper-dim: #EDEAE2;
  --ink: #1B1B1F;
  --rule: #D8D4C9;
  --muted: #8A8778;
  --faded: #B4B2A9;
  --board: #17181B;
  --board-text: #F2F0EA;
  --board-muted: #8B8B84;
  --board-rule: #33342F;
  --income-bg: #EAF3DE;
  --income-text: #3B6D11;
  --warn-bg: #F3E3BC;
  --warn-deep: #8A5B00;
  --danger: #A32D2D;
  --danger-text: #FCEBEB;
  --danger-soft: #F7C1C1;
  --signal: #E24B4A;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* --- Departure board --- */
.board {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--board);
  color: var(--board-text);
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 10px;
  font-family: var(--mono);
}
.board-label { font-size: 11px; letter-spacing: 0.14em; color: var(--board-muted); }
.board-main { display: flex; align-items: baseline; gap: 10px; margin-top: 2px; flex-wrap: wrap; }
.board-big { font-size: 34px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
.board-big.neg { color: var(--signal); }
.board-sub { font-size: 12px; color: var(--board-muted); }
.board-row {
  display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--board-rule);
}
.board-chip {
  font-family: var(--mono); font-size: 12px; color: var(--board-muted);
  font-variant-numeric: tabular-nums; padding: 2px 0; text-align: left;
}
.board-chip .warn { color: #F5B84A; }
.board-chip .danger { color: var(--signal); }
.board-chip .stale { color: #F5B84A; }

.whatif-strip {
  display: block; width: calc(100% + 32px); margin: 10px -16px -10px;
  padding: 9px 16px; background: #F5B84A; color: #1B1B1F;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em;
  text-align: center; font-weight: 600;
}

/* --- Layout --- */
#main { padding: 12px 0 calc(env(safe-area-inset-bottom, 0px) + 84px); }

/* --- Balance chart --- */
.chart { padding: 2px 16px 10px; }
.chart svg { display: block; width: 100%; height: 96px; }
.chart-label {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em;
  color: var(--muted); padding-bottom: 2px;
}

/* --- Minimap --- */
.minimap { padding: 0 16px 4px; }
.minimap-row { display: grid; grid-template-columns: 44px repeat(7, 1fr); gap: 3px; margin-bottom: 3px; align-items: center; }
.minimap-label { font-family: var(--mono); font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mm-cell {
  height: 16px; border: 1px solid var(--rule); background: var(--paper); position: relative;
  padding: 0; border-radius: 0;
}
.mm-cell.past { background: var(--paper-dim); border-color: var(--paper-dim); }
.mm-cell.warn { background: var(--warn-bg); border-color: var(--warn-bg); }
.mm-cell.danger { background: var(--danger); border-color: var(--danger); }
.mm-cell.income { background: var(--income-bg); }
.mm-cell.today { outline: 2px solid var(--ink); outline-offset: -1px; }
.mm-cell .dot {
  position: absolute; left: 50%; top: 50%; width: 4px; height: 4px;
  margin: -2px 0 0 -2px; background: var(--ink); border-radius: 50%;
}
.mm-cell.danger .dot { background: var(--danger-text); }
.mm-cell.past .dot { background: var(--faded); }
.minimap-key { font-size: 11px; color: var(--muted); padding: 4px 2px 8px; font-family: var(--mono); }

/* --- Timetable --- */
.timetable { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.tt-week {
  font-size: 11px; letter-spacing: 0.12em; color: var(--muted);
  padding: 14px 16px 4px; border-bottom: 2px solid var(--ink);
  display: flex; justify-content: space-between; align-items: baseline;
}
.tt-row {
  display: grid; grid-template-columns: 64px 1fr auto 64px; gap: 8px; align-items: baseline;
  width: 100%; text-align: left;
  padding: 9px 16px; border-bottom: 1px solid var(--rule);
  font-size: 14px;
}
.tt-date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.tt-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tt-name .flag { color: var(--muted); font-size: 11px; }
.tt-amt { text-align: right; white-space: nowrap; }
.tt-bal { text-align: right; color: var(--muted); font-size: 13px; }
.tt-row.income { background: var(--income-bg); }
.tt-row.income .tt-amt { color: var(--income-text); }
.tt-row.pretend { background: #F7ECCB; }
.tt-row.warn { background: var(--warn-bg); }
.tt-row.danger { background: var(--danger); color: var(--danger-text); }
.tt-row.danger .tt-date, .tt-row.danger .tt-bal, .tt-row.danger .tt-name .flag { color: var(--danger-soft); }
.tt-row.past { color: var(--faded); }
.tt-row.past .tt-amt, .tt-row.past .tt-bal { color: var(--faded); }
.tt-row.skipped .tt-name, .tt-row.skipped .tt-amt { text-decoration: line-through; color: var(--faded); }
.tt-paid { font-size: 11px; }
.tt-row.today-rule { border-top: 2px solid var(--ink); }
.tt-quiet { color: var(--faded); font-size: 12px; padding: 6px 16px; }
.tt-quiet .tt-bal { color: var(--faded); }
.tt-today-tag {
  display: block; width: max-content; background: var(--ink); color: var(--paper);
  font-size: 10px; letter-spacing: 0.1em; padding: 1px 4px; margin-top: 2px;
}

/* --- Empty state / nudge --- */
.empty { padding: 40px 24px; text-align: center; }
.empty h2 { font-size: 20px; font-weight: 600; margin-bottom: 10px; }
.empty p { font-size: 15px; color: var(--muted); line-height: 1.5; margin-bottom: 24px; }
.empty .btn { width: 100%; margin-bottom: 10px; }
.nudge {
  margin: 10px 16px 0; border: 1px solid var(--ink); padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  font-size: 14px;
}
.nudge button { text-decoration: underline; font-weight: 600; white-space: nowrap; }

/* --- Buttons / tab bar --- */
.btn {
  display: inline-block; min-height: 46px; padding: 12px 18px;
  border: 1.5px solid var(--ink); background: var(--paper); color: var(--ink);
  font-size: 16px; font-weight: 600; border-radius: 2px; text-align: center;
}
.btn:active { background: var(--paper-dim); }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:active { background: #3a3a40; }
.btn-icon { min-width: 46px; font-size: 20px; padding: 8px; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; gap: 10px; padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: var(--paper); border-top: 1px solid var(--rule);
}
.btn-add { flex: 1; }

/* --- Bottom sheet --- */
.scrim { position: fixed; inset: 0; background: rgba(23, 24, 27, 0.45); z-index: 40; border: none; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  background: var(--paper); border-top: 3px solid var(--ink);
  max-height: 75vh; overflow-y: auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
}
.sheet h2 { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.sheet .sheet-sub { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.sheet-item { border-bottom: 1px solid var(--rule); padding: 10px 0; }
.si-main {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; width: 100%; text-align: left;
  font-family: var(--mono); font-size: 15px; font-variant-numeric: tabular-nums;
}
.si-main .sub { grid-column: 1 / -1; font-size: 12px; color: var(--muted); margin-top: 2px; }
.si-main .amt.in { color: var(--income-text); }
.si-main.skipped > span:not(.sub) { text-decoration: line-through; color: var(--faded); }
.si-drift { font-family: var(--mono); font-size: 12px; color: var(--warn-deep); margin-top: 4px; }
.si-actions { display: flex; gap: 8px; margin-top: 8px; }
.si-actions .btn { min-height: 36px; padding: 6px 12px; font-size: 13px; font-weight: 600; border-width: 1px; flex: 1; }
.si-actions .btn.done { border-color: var(--income-text); color: var(--income-text); }
.si-payform { display: flex; gap: 8px; margin-top: 8px; }
.si-payform input {
  flex: 1; min-width: 0; min-height: 40px; padding: 6px 10px; font-size: 17px;
  border: 1.5px solid var(--ink); border-radius: 2px; font-family: var(--mono);
}
.si-payform .btn { min-height: 40px; padding: 6px 12px; font-size: 14px; border-width: 1px; }
.sheet-bal {
  display: flex; justify-content: space-between; padding: 12px 0;
  font-family: var(--mono); font-size: 14px; font-variant-numeric: tabular-nums;
}
.sheet-bal.danger { color: var(--danger); font-weight: 700; }
.sheet .btn { width: 100%; margin-top: 12px; }

/* --- Full screens (edit / settings) --- */
.screen {
  position: fixed; inset: 0; z-index: 50; background: var(--paper);
  overflow-y: auto; padding: calc(env(safe-area-inset-top, 0px) + 8px) 16px calc(env(safe-area-inset-bottom, 0px) + 24px);
}
.screen-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.screen-head h2 { font-size: 18px; font-weight: 700; }
.screen-head .btn { min-height: 38px; padding: 8px 14px; font-size: 15px; border-width: 1px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 11px; letter-spacing: 0.1em; color: var(--muted); font-family: var(--mono); margin-bottom: 5px; text-transform: uppercase; }
.field input[type="text"], .field input[type="date"], .field input[type="number"], .field select {
  width: 100%; min-height: 48px; padding: 10px 12px; font-size: 17px;
  border: 1.5px solid var(--ink); border-radius: 2px; background: #FFFFFF; color: var(--ink);
  font-family: var(--sans); appearance: none; -webkit-appearance: none;
}
.field input.money { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 22px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.seg { display: flex; border: 1.5px solid var(--ink); border-radius: 2px; overflow: hidden; }
.seg button {
  flex: 1; min-height: 46px; font-size: 15px; font-weight: 600; background: var(--paper);
  border-right: 1.5px solid var(--ink);
}
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--ink); color: var(--paper); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 15px; }
.check input { width: 22px; height: 22px; accent-color: var(--ink); }
.form-actions { margin-top: 20px; display: grid; gap: 10px; }
.form-actions .btn { width: 100%; }
.btn-quiet { border-color: var(--rule); color: var(--muted); font-weight: 400; }
details.more { margin: 8px 0 4px; }
details.more summary { font-size: 14px; color: var(--muted); padding: 8px 0; cursor: pointer; }
.error { border: 1.5px solid var(--danger); background: #F9E9E7; color: var(--danger); padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }

/* --- Settings extras --- */
.setting-block { border-top: 1px solid var(--rule); padding: 16px 0; }
.setting-block h3 { font-size: 12px; letter-spacing: 0.1em; font-family: var(--mono); color: var(--muted); text-transform: uppercase; margin-bottom: 10px; }
.setting-block p { font-size: 13px; color: var(--muted); line-height: 1.5; margin-top: 8px; }
.setting-block .btn { width: 100%; margin-top: 8px; }

/* --- What-if panel --- */
.wi-h {
  font-size: 11px; letter-spacing: 0.1em; font-family: var(--mono);
  color: var(--muted); text-transform: uppercase; margin: 16px 0 8px;
}
.wi-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--rule);
  font-family: var(--mono); font-size: 14px; font-variant-numeric: tabular-nums;
}
.wi-row .btn { min-height: 36px; padding: 6px 10px; font-size: 13px; border-width: 1px; }
.wi-check { border-bottom: 1px solid var(--rule); padding: 4px 0; }
.wi-check .wi-amt { margin-left: auto; font-family: var(--mono); color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
#btn-whatif { padding-left: 12px; padding-right: 12px; font-size: 14px; }

/* --- Pots & plans (settings) --- */
.pot-row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: baseline;
  font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 14px;
  padding: 10px 0; border-bottom: 1px solid var(--rule);
}
.pot-row .pot-sub { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.pot-take { display: flex; gap: 8px; grid-column: 1 / -1; margin-top: 6px; }
.pot-take input {
  flex: 1; min-width: 0; min-height: 40px; padding: 6px 10px; font-size: 17px;
  border: 1.5px solid var(--ink); border-radius: 2px; font-family: var(--mono);
}
.pot-take .btn { min-height: 40px; padding: 6px 12px; font-size: 13px; border-width: 1px; white-space: nowrap; }

/* --- Toast --- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom, 0px) + 84px);
  z-index: 60; background: var(--ink); color: var(--paper);
  padding: 12px 16px; font-size: 14px; text-align: center; border-radius: 2px;
}

@media (min-width: 560px) {
  #main, .board, .tabbar { max-width: 560px; margin-left: auto; margin-right: auto; }
  .board { left: 0; right: 0; }
}
