:root {
  --bg: #faf6f2;
  --card: #ffffff;
  --ink: #1f1a17;
  --muted: #6f655e;
  --line: #e8e0d8;
  --accent: #c44a34;
  --accent-ink: #ffffff;
  --soft: #f3ebe4;
  --high: #b3261e;
  --ok: #2e7d4f;
  --warn: #a15c00;
  --radius: 14px;
  --tabs: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161311;
    --card: #211d1a;
    --ink: #f2ece7;
    --muted: #a99d94;
    --line: #362f2a;
    --accent: #e0694f;
    --accent-ink: #1a0f0b;
    --soft: #2a2420;
    --high: #ff8a80;
    --ok: #7fd1a0;
    --warn: #ffb74d;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 340px; display: grid; gap: 12px; text-align: center; }
.login-card h1 { margin: 0 0 8px; font-size: 24px; }
.logo {
  width: 72px; height: 72px; margin: 0 auto; border-radius: 20px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 40px; font-weight: 800;
}

/* ── Frame ─────────────────────────────────────────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font-size: 20px; }
main { padding: 12px 16px calc(var(--tabs) + 24px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs a {
  position: relative; display: grid; place-items: center; align-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 12px;
}
.tabs a .ti { font-size: 20px; line-height: 1; }
.tabs a.on { color: var(--accent); font-weight: 600; }
.badge {
  position: absolute; top: 6px; left: 55%; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--high); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* ── Pieces ────────────────────────────────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
a.card { display: block; color: inherit; text-decoration: none; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.title { font-weight: 600; }
.section { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--soft); color: var(--muted); }
.pill.high { background: var(--high); color: #fff; }
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }
.error { color: var(--high); min-height: 1em; margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.notes { background: var(--soft); border-radius: 10px; padding: 10px 12px; font-size: 14px; }

button {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 14px; cursor: pointer; min-height: 44px;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--high); }
button:disabled { opacity: .5; }
.icon-btn { min-height: 36px; padding: 4px 10px; font-size: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.actions button { flex: 1 1 auto; }

input, textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 12px;
}
textarea { min-height: 220px; resize: vertical; line-height: 1.5; }
label.field { display: grid; gap: 4px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }

/* ── Thread ────────────────────────────────────────────────────────────── */
.msg { border-left: 3px solid var(--line); padding: 4px 0 4px 10px; margin: 10px 0; }
.msg.out { border-left-color: var(--accent); }
.msg .body { max-height: 220px; overflow: auto; }

/* ── Chat ──────────────────────────────────────────────────────────────── */
.chat { display: flex; flex-direction: column; gap: 8px; padding-bottom: 76px; }
.bubble { max-width: 88%; padding: 10px 12px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.thinking { color: var(--muted); font-style: italic; }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabs) + env(safe-area-inset-bottom)); z-index: 4;
  display: flex; gap: 8px; padding: 8px 16px; background: var(--bg); border-top: 1px solid var(--line);
}
.composer textarea { min-height: 44px; height: 44px; max-height: 140px; }
.proposal { border: 2px solid var(--accent); }

/* ── Money ─────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
th, td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
.scroll-x { overflow-x: auto; }
.stat { display: grid; gap: 2px; }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.neg { color: var(--high); }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs) + 16px + env(safe-area-inset-bottom)); z-index: 10;
  background: var(--ink); color: var(--bg); padding: 12px 14px; border-radius: 12px; text-align: center;
}
