/* Look and feel carried over from v1 (SpendingAppUI.html), then v2 additions at the bottom. */
:root {
  color-scheme: dark;
  --bg: #000000;
  --card: #1c1c1e;
  --card-2: #2c2c2e;
  --line: #38383a;
  --ink: #ffffff;
  --muted: #8e8e93;
  --orange: #ff9500;
  --orange-dim: #7a4a00;
  --green: #30d158;
  --red: #ff453a;
  --key-dark: #333336;
  --key-dark-active: #4a4a4d;
  --key-light: #a5a5aa;
  --key-light-active: #c7c7ce;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  height: 100%;
}
.screen { display: none; min-height: 100vh; flex-direction: column; padding: 20px 16px 30px; }
.screen.active { display: flex; }

h1 { font-size: 22px; font-weight: 700; margin: 4px 0 14px; text-align: center; letter-spacing: 0.2px; }

.nav-bar { display: flex; background: var(--card-2); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.nav-bar button { flex: 1; padding: 9px 8px; border-radius: 8px; border: none; background: transparent; color: var(--muted); font-size: 14px; font-weight: 700; }
.nav-bar button.selected { background: var(--orange); color: #000; }

.card { background: var(--card); border-radius: 16px; overflow: hidden; }
.card + .card { margin-top: 12px; }
.field-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; border-bottom: 1px solid var(--line); gap: 12px; }
.field-row:last-child { border-bottom: none; }
.field-row .k { font-size: 15px; color: var(--ink); font-weight: 500; white-space: nowrap; }
.field-row.tappable { width: 100%; border: none; background: transparent; text-align: left; }

.field-value-btn {
  flex: 1; text-align: right; background: none; border: none; padding: 4px 0;
  font-size: 16px; font-weight: 600; color: var(--orange);
}

select {
  flex: 1; text-align: right; padding: 4px 0; font-size: 16px; border: none;
  background: transparent; color: var(--orange); font-weight: 600; -webkit-appearance: none; appearance: none;
}
select { direction: rtl; }
select option { direction: ltr; background: var(--card-2); color: var(--ink); }

.segmented { display: flex; background: var(--card-2); border-radius: 9px; padding: 2px; flex: 1; }
.segmented button {
  flex: 1; padding: 7px 8px; border-radius: 7px; border: none;
  background: transparent; font-size: 14px; font-weight: 600; color: var(--muted);
}
.segmented button.selected { background: #545458; color: var(--ink); }

.section-label { font-size: 13px; color: var(--muted); font-weight: 600; margin: 18px 4px 8px; text-transform: uppercase; letter-spacing: 0.4px; }
/* Tighter on the Enter screen specifically, so the whole thing clears the
   fold even on the smallest handsets with the House toggle showing. */
#entryScreen .section-label { margin: 12px 4px 6px; }

.direction-options { display: flex; flex-direction: column; gap: 8px; }
.direction-card {
  text-align: left; padding: 10px 14px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--card); display: flex; flex-direction: column; gap: 1px;
}
.direction-card .dc-title { font-size: 15px; font-weight: 700; color: var(--ink); }
.direction-card .dc-sub { font-size: 12px; color: var(--muted); line-height: 1.3; }
.direction-card.selected { border-color: var(--orange); background: rgba(255,149,0,0.12); }
.direction-card.selected .dc-title { color: var(--orange); }
.direction-card.refund-mode.selected { border-color: var(--red); background: rgba(255,69,58,0.12); }
.direction-card.refund-mode.selected .dc-title { color: var(--red); }

.amount-block { margin-top: 22px; display: flex; align-items: baseline; justify-content: space-between; padding: 0 6px; }
.amount-display { font-size: 52px; font-weight: 300; letter-spacing: 0.5px; font-variant-numeric: tabular-nums; color: var(--ink); }
.clear-link { background: none; border: none; color: var(--orange); font-size: 15px; font-weight: 600; padding: 8px; }

/* Tappable amount on the Enter screen opens the keypad modal, so the
   keypad no longer takes up half the screen and nothing needs scrolling. */
.amount-block.tappable {
  width: 100%; border: 1.5px solid var(--line); background: var(--card);
  border-radius: 16px; padding: 12px 16px; align-items: center; text-align: left;
  margin-top: 14px;
}
.amount-block.tappable .amount-display { font-size: 42px; }
.amount-hint { font-size: 14px; font-weight: 600; color: var(--orange); white-space: nowrap; }

/* Slightly shorter keys inside the modal so the whole thing fits on
   smaller handsets without the sheet itself needing to scroll. */
.modal-sheet .keypad { margin-top: 14px; }
/* Rounded rectangles rather than circles here: squashing a circle to fit
   four rows on screen just reads as a squashed circle. */
.modal-sheet .keypad button { aspect-ratio: 1.45 / 1; border-radius: 20px; font-size: 25px; }
.modal-sheet .amount-block { margin-top: 4px; }
.amount-modal-context { font-size: 13px; color: var(--muted); font-weight: 600; text-align: center; margin-bottom: 2px; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 10px; }
.keypad button {
  aspect-ratio: 1 / 1; border-radius: 50%; border: none; font-size: 26px; font-weight: 500;
  background: var(--key-dark); color: var(--ink);
}
.keypad button:active { background: var(--key-dark-active); }
.keypad button.func { background: var(--key-light); color: #000; font-size: 22px; font-weight: 600; }
.keypad button.func:active { background: var(--key-light-active); }

.spacer { flex: 1; }

.primary-btn {
  width: 100%; padding: 17px; border-radius: 14px; border: none;
  background: var(--orange); color: #000; font-size: 17px; font-weight: 700;
  margin-top: 22px;
}
.primary-btn:disabled { background: var(--orange-dim); color: rgba(0,0,0,0.5); }
.secondary-btn {
  width: 100%; padding: 15px; border-radius: 14px; border: 1.5px solid var(--line);
  background: transparent; color: var(--ink); font-size: 15px; font-weight: 600;
  margin-top: 10px;
}

.summary-card .row { display: flex; justify-content: space-between; padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 15px; }
.summary-card .row:last-child { border-bottom: none; }
.summary-card .row .k { color: var(--muted); }
.summary-card .row .v { font-weight: 600; text-align: right; color: var(--ink); }

.action-note { margin-top: 14px; padding: 14px 16px; border-radius: 14px; font-size: 14px; line-height: 1.45; font-weight: 500; }
.action-note.add { background: rgba(48,209,88,0.12); color: var(--green); }
.action-note.reverse { background: rgba(255,69,58,0.12); color: var(--red); }

.error-box { background: rgba(255,69,58,0.15); color: var(--red); border-radius: 12px; padding: 13px 16px; font-size: 14px; margin-top: 14px; font-weight: 500; }

.success-icon { text-align: center; font-size: 56px; margin: 22px 0 10px; }
.success-text { text-align: center; font-size: 19px; font-weight: 700; margin-bottom: 6px; }
.success-sub { text-align: center; font-size: 13px; color: var(--muted); margin-bottom: 6px; padding: 0 20px; }

.month-total-card {
  background: var(--card); border-radius: 16px; padding: 20px; margin-top: 18px; text-align: center;
  border: 1.5px solid var(--line);
}
.month-total-card .mt-label { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.month-total-card .mt-value { font-size: 40px; font-weight: 700; color: var(--orange); margin-top: 6px; font-variant-numeric: tabular-nums; }
.month-total-card .mt-value.negative { color: var(--red); }
.month-total-card .mt-value.positive { color: var(--green); }
.month-total-card .mt-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }

.net-caption { font-size: 12.5px; color: var(--muted); line-height: 1.4; margin: -6px 4px 14px; }

.preview-banner {
  background: rgba(255,149,0,0.15); color: var(--orange); font-size: 12px; font-weight: 600;
  text-align: center; padding: 8px; border-radius: 10px; margin-bottom: 14px;
}
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: #3a1210; color: var(--red); font-size: 13px; font-weight: 600;
  text-align: center; padding: 10px 16px;
}
.load-error-icon { text-align: center; font-size: 48px; margin: 40px 0 10px; }
.load-error-text { text-align: center; font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.load-error-sub { text-align: center; font-size: 14px; color: var(--muted); padding: 0 20px; margin-bottom: 6px; }

/* ---- date picker modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: flex-end;
  z-index: 50;
}
.modal-sheet {
  background: var(--card); width: 100%; border-radius: 20px 20px 0 0; padding: 16px 16px 26px;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; padding: 0 6px; }
.modal-header button { background: var(--card-2); border: none; color: var(--orange); font-size: 20px; font-weight: 700; width: 34px; height: 34px; border-radius: 50%; }
.modal-header span { font-size: 16px; font-weight: 700; }
.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-day { aspect-ratio: 1/1; border-radius: 50%; border: none; background: transparent; color: var(--ink); font-size: 14px; font-weight: 500; }
.cal-day.cal-muted { color: #48484a; }
.cal-day.cal-today { box-shadow: inset 0 0 0 1.5px var(--muted); }
.cal-day.cal-selected { background: var(--orange); color: #000; font-weight: 700; }
.modal-quick-row { display: flex; gap: 10px; margin-top: 14px; }
.modal-quick-row button { flex: 1; padding: 11px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card-2); color: var(--ink); font-size: 14px; font-weight: 600; }

/* ---- chart screen ---- */
.chart-card { background: var(--card); border-radius: 16px; padding: 14px 10px 6px; margin-top: 14px; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-point-label { text-align: center; font-size: 14px; font-weight: 600; margin-top: 6px; padding-bottom: 10px; color: var(--ink); min-height: 20px; }
.stat-row { display: flex; gap: 10px; margin-top: 12px; }
.stat-tile { flex: 1; background: var(--card); border-radius: 14px; padding: 12px 10px; text-align: center; }
.stat-tile .st-label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.stat-tile .st-value { font-size: 17px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.chart-loading { text-align: center; color: var(--muted); font-size: 14px; padding: 40px 0; }
.range-row { display: flex; gap: 10px; }
.range-row select { flex: 1; text-align: left; direction: ltr; background: var(--card-2); border-radius: 10px; padding: 10px; color: var(--ink); font-weight: 500; }

/* ---- owed / reimbursements screen ---- */
.switch { position: relative; width: 46px; height: 28px; border-radius: 14px; background: var(--card-2); flex-shrink: 0; transition: background 0.15s; }
.switch.on { background: var(--orange); }
.switch-knob { position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left 0.15s; }
.switch.on .switch-knob { left: 20px; }
.repay-input {
  width: 100%; background: var(--card-2); border: none; border-radius: 10px; padding: 12px;
  color: var(--ink); font-size: 16px; font-weight: 600; margin-bottom: 10px; font-family: inherit;
}
.repay-input::placeholder { color: var(--muted); font-weight: 500; }
.owed-empty { text-align: center; color: var(--muted); font-size: 14px; padding: 30px 0; }

/* ===================== v2 additions ===================== */

/* Standalone home-screen app: respect the notch, fill the screen without
   the page itself scrolling, status line sits above the active screen. */
body {
  display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh;
  padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
  box-sizing: border-box;
}
body.dry-run { padding-top: calc(env(safe-area-inset-top) + 18px); }
.screen { min-height: 0; flex: 1 0 auto; padding-top: 6px; }
#entryScreen h1, #chartScreen h1, #owedScreen h1 { margin: 2px 0 10px; }

.dry-run-bar {
  position: fixed; top: env(safe-area-inset-top); left: 0; right: 0; z-index: 120; height: 18px; line-height: 18px;
  background: var(--orange); color: #000; font-size: 11px; font-weight: 800; text-align: center; letter-spacing: 0.6px;
}
.update-banner {
  position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 12px); z-index: 130;
  background: var(--ink); color: #000; border: none; border-radius: 12px; padding: 13px; font-size: 15px; font-weight: 700;
}

.status-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 16px 0; font-size: 12px; color: var(--muted); font-weight: 600; min-height: 26px;
}
.status-right { display: flex; gap: 6px; align-items: center; }
.pill {
  border: none; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700;
  background: var(--card-2); color: var(--muted);
}
.pill.pill-pending { background: rgba(255,149,0,0.18); color: var(--orange); }
.pill.pill-ok { background: rgba(48,209,88,0.15); color: var(--green); }
.pill.pill-red { background: rgba(255,69,58,0.18); color: var(--red); }
.pill.pill-busy { opacity: 0.6; }

/* Budget chips: warnings only, never headroom */
.chip { border-radius: 999px; padding: 3px 9px; font-size: 11.5px; font-weight: 800; white-space: nowrap; }
.chip.chip-over { background: rgba(255,69,58,0.2); color: var(--red); }
.chip.chip-trending { background: rgba(255,149,0,0.2); color: var(--orange); }
.chip.chip-lg { display: inline-block; margin-top: 10px; font-size: 13px; padding: 5px 12px; }

.estimate-tag { color: var(--orange); }

.setup-intro { color: var(--muted); font-size: 15px; text-align: center; margin: 0 8px 12px; line-height: 1.4; }
.note-box { background: rgba(255,149,0,0.12); color: var(--orange); border-radius: 12px; padding: 12px 14px; font-size: 13.5px; line-height: 1.4; font-weight: 500; }
.code-input {
  width: 100%; background: var(--card); color: var(--ink); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 12px; font-size: 14px; font-family: ui-monospace, Menlo, monospace; resize: none;
}
.ok-box { background: rgba(48,209,88,0.12); color: var(--green); border-radius: 12px; padding: 13px 16px; font-size: 14px; font-weight: 500; }
.link-btn { background: none; border: none; color: var(--muted); font-size: 13px; padding: 14px; margin-top: 6px; text-decoration: underline; }
.secondary-btn.danger { color: var(--red); border-color: rgba(255,69,58,0.4); }

.report-sheet { max-height: 80vh; display: flex; flex-direction: column; }
.report-title { font-size: 17px; font-weight: 700; text-align: center; margin-bottom: 10px; }
.report-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.report-section { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; margin: 10px 4px 6px; }
.report-item { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--card-2); margin-bottom: 6px; font-size: 14px; }
.report-item .ri-main { flex: 1; }
.report-item .ri-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.report-item.failed { background: rgba(255,69,58,0.14); color: var(--red); }
.report-item.failed .ri-sub { color: var(--red); opacity: 0.85; }

.attention-item { background: var(--card); border-radius: 14px; padding: 14px 16px; margin-bottom: 10px; }
.attention-item .ai-title { font-size: 15px; font-weight: 700; }
.attention-item .ai-reason { font-size: 13px; color: var(--red); margin: 6px 0 10px; line-height: 1.35; }
.attention-item .ai-actions { display: flex; gap: 8px; }
.attention-item .ai-actions button { flex: 1; padding: 10px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--card-2); color: var(--ink); font-size: 14px; font-weight: 600; }
.attention-item .ai-actions button.discard { color: var(--red); }

.queued-tag { font-size: 11px; color: var(--orange); font-weight: 700; margin-left: 6px; }

/* Shorter phones (iPhone SE/8 size): tighten the Enter screen so it still
   fits without scrolling with the House toggle showing. */
@media (max-height: 700px) {
  .screen { padding-bottom: 14px; }
  #entryScreen h1 { font-size: 19px; margin: 0 0 8px; }
  #entryScreen .nav-bar { margin-bottom: 10px; }
  #entryScreen .field-row { padding: 9px 16px; }
  #entryScreen .section-label { margin: 8px 4px 5px; }
  #entryScreen .direction-options { gap: 6px; }
  #entryScreen .direction-card { padding: 7px 12px; }
  #entryScreen #personallyFundedCard { margin-top: 8px !important; }
  #entryScreen .amount-block.tappable { margin-top: 8px; padding: 6px 16px; }
  #entryScreen .amount-block.tappable .amount-display { font-size: 34px; }
  #entryScreen .primary-btn { margin-top: 10px; padding: 14px; }
  .status-row { padding-top: 4px; min-height: 22px; }
}
