/* Household Money — phone-first, dark, thumb-reachable.
   One accent colour, big numbers, nothing that needs a stylus. */

:root {
  --bg: #0f1216;
  --panel: #171c22;
  --panel-2: #1e242c;
  --line: #2a323c;
  --text: #eef2f6;
  --muted: #93a1b1;
  --accent: #4ade80;
  --accent-dim: #16351f;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  overscroll-behavior-y: contain;
}

body { min-height: 100dvh; }
main { display: flex; flex-direction: column; min-height: 100dvh; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px calc(14px + env(safe-area-inset-top, 0px));
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; letter-spacing: -0.01em; }
.icon-btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; font-size: 18px;
}

/* ---------- views ---------- */
.view { display: none; flex: 1; padding: 16px 16px calc(24px + var(--safe-bottom)); }
.view.active { display: block; }

/* ---------- chat ---------- */
#view-talk.active { display: flex; flex-direction: column; padding: 0; }
.thread {
  flex: 1; overflow-y: auto; padding: 18px 16px 8px;
  display: flex; flex-direction: column; gap: 12px;
}
.starters { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 10px; }
.starter {
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 9px 14px; font-size: 13.5px; font-weight: 500;
}
.starter:active { background: var(--panel-2); color: var(--text); }
.bubble {
  max-width: 86%; padding: 12px 15px; border-radius: 18px;
  line-height: 1.42; font-size: 16px; white-space: pre-wrap; word-wrap: break-word;
  animation: pop .16s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }
.bubble.user { align-self: flex-end; background: var(--accent); color: #06210f;
  border-bottom-right-radius: 6px; font-weight: 500; }
.bubble.agent { align-self: flex-start; background: var(--panel); border: 1px solid var(--line);
  border-bottom-left-radius: 6px; }
.bubble.agent.thinking { color: var(--muted); font-style: italic; }
.toolchip {
  align-self: flex-start; font-size: 12px; color: var(--muted);
  padding: 3px 9px; border-radius: 999px; background: var(--panel-2);
  border: 1px solid var(--line);
}

.composer {
  position: sticky; bottom: 0; padding: 8px 12px calc(12px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.hint { font-size: 12.5px; color: var(--muted); text-align: center; min-height: 16px; }
.controls { display: flex; align-items: center; justify-content: center; }

.mic {
  display: flex; align-items: center; gap: 10px;
  background: var(--accent-dim); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 999px;
  padding: 15px 30px; font-size: 16.5px; font-weight: 600;
  min-width: 240px; justify-content: center;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
  touch-action: none; user-select: none;
}
.mic.recording { background: color-mix(in srgb, var(--accent) 20%, var(--panel));
  border-color: var(--accent); transform: scale(.97); }
.mic .mic-icon { color: var(--accent); flex: 0 0 auto; }
.mic.recording .mic-icon { color: var(--danger); animation: pulse 1s infinite; }
.mic.busy { opacity: .55; }
@keyframes pulse { 50% { opacity: .25; } }

.text-row { display: flex; gap: 8px; width: 100%; max-width: 560px; align-items: center; }
.text-row input {
  flex: 1; background: transparent; border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 11px 16px; font-size: 16px;
}
.text-row input::placeholder { color: color-mix(in srgb, var(--muted) 80%, transparent); }
.send {
  width: 40px; height: 40px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted); font-size: 17px; font-weight: 700;
  flex: 0 0 auto;
}
.send:not(:disabled):hover { color: var(--text); }
.text-row:focus-within .send { background: var(--accent); color: #06210f; border-color: var(--accent); }

/* ---------- dashboard ---------- */
.hero-card {
  background: linear-gradient(160deg, #17251c, var(--panel) 60%);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 20px;
}
.hero-label { font-size: 12.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); }
.hero-amount { font-size: 42px; font-weight: 700; letter-spacing: -0.03em; margin: 6px 0 2px; }
.hero-amount.negative { color: var(--danger); }
.hero-sub { font-size: 14px; color: var(--muted); }
.hero-bars { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 18px; }
.hero-bars .bar {
  display: flex; justify-content: space-between; font-size: 13.5px;
  background: rgba(255,255,255,.04); border-radius: 10px; padding: 9px 12px;
}
.hero-bars .bar span { color: var(--muted); }
.hero-bars .bar b { font-variant-numeric: tabular-nums; }
.hero-foot { margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.hero-foot span { font-variant-numeric: tabular-nums; }

.section-h { font-size: 13px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin: 26px 4px 10px; font-weight: 600; }

.stack { display: flex; flex-direction: column; gap: 10px; }
.stack.tight { gap: 7px; }

.row {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 13px 15px; display: flex; align-items: center; gap: 12px;
}
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 550; font-size: 15.5px; }
.row .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.row .amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.row.paid { opacity: .48; }
.row.paid .title { text-decoration: line-through; }
.row .tap { font-size: 12.5px; color: var(--accent); background: none; border: 0;
  padding: 6px 0 6px 10px; font-weight: 600; }
.row .tap.danger { color: var(--danger); }
.row .tap.quiet { color: var(--muted); font-weight: 500; font-size: 12px; }
.row .tap.quiet:hover, .row .tap.quiet:active { color: var(--danger); }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2);
  color: var(--muted); border: 1px solid var(--line); margin-left: 6px; }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.pill.bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.pill.good { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }

.advice { border-left: 3px solid var(--line); }
.advice.alert { border-left-color: var(--danger); }
.advice.warn { border-left-color: var(--warn); }
.advice.good { border-left-color: var(--accent); }
.advice .detail { font-size: 13.5px; color: var(--muted); margin-top: 4px; line-height: 1.4; }

.progress { height: 7px; border-radius: 999px; background: var(--panel-2);
  overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------- forms ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-top: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.form { display: flex; flex-direction: column; gap: 10px; }
.form input, .form select, .field input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 11px; padding: 12px 13px; font-size: 16px; width: 100%;
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 9px; font-size: 14px; color: var(--muted); }
.check input { width: 20px; height: 20px; }

button.primary {
  background: var(--accent); color: #06210f; border: 0; border-radius: 12px;
  padding: 13px; font-size: 15.5px; font-weight: 650;
}
button.primary:disabled { opacity: .5; }
button.ghost {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; font-size: 15px; width: 100%; margin-top: 10px;
}
button.ghost.danger { color: var(--danger); }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---------- tabs ---------- */
.seg { display: flex; gap: 6px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 5px; margin-bottom: 16px; }
.seg.tiny { margin-bottom: 4px; padding: 4px; border-radius: 10px; }
.seg-btn { flex: 1; background: none; border: 0; color: var(--muted); padding: 9px;
  border-radius: 9px; font-size: 14px; font-weight: 550; }
.seg.tiny .seg-btn { padding: 7px; font-size: 13px; }
.seg-btn.active { background: var(--panel-2); color: var(--text); }
.tab { display: none; }
.tab.active { display: block; }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; inset: 0; z-index: 40; background: rgba(8,10,13,.72);
  backdrop-filter: blur(3px); display: flex; flex-direction: column;
  justify-content: flex-end; padding: 18px 14px calc(18px + var(--safe-bottom));
  gap: 8px;
}
.drawer button {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  padding: 16px; border-radius: 14px; font-size: 16px; font-weight: 550; text-align: left;
}

/* ---------- gate ---------- */
.gate-page { display: grid; place-items: center; min-height: 100dvh; padding: 20px; }
.gate { display: grid; place-items: center; width: 100%; }
.gate-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px 22px; text-align: center; }
.gate-card h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.02em; }
.gate-card .muted { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.pin { width: 100%; text-align: center; font-size: 30px; letter-spacing: .35em;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.gate-card .primary { width: 100%; }
.error { color: var(--danger); font-size: 13.5px; min-height: 20px; margin: 12px 0 0; }
.audit { font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 6px;
  max-height: 240px; overflow-y: auto; }
.audit div { display: flex; justify-content: space-between; gap: 10px; }

@media (min-width: 720px) {
  .view { max-width: 720px; margin: 0 auto; width: 100%; }
  .thread { max-width: 720px; margin: 0 auto; width: 100%; }
}
