:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-2: #f3efe8;
  --ink: #23201c;
  --muted: #6f6961;
  --line: #e7e1d7;
  --accent: #c2693e;
  --accent-ink: #9a4f2a;
  --accent-soft: #f6e6db;
  --ok: #2f8a5b;
  --ok-soft: #e3f3ea;
  --bad: #b8433c;
  --bad-soft: #f8e4e1;
  --busy: #c08a1e;
  --busy-soft: #faf0d9;
  --shadow: 0 1px 2px rgba(35, 32, 28, .05), 0 6px 24px rgba(35, 32, 28, .06);
  --radius: 16px;
  --serif: "Source Serif 4", Georgia, serif;
  --sans: Inter, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a18; --surface: #242220; --surface-2: #2d2a27; --ink: #efe9e1; --muted: #a39b91; --line: #3a3632;
    --accent: #e0875a; --accent-ink: #f0a37b; --accent-soft: #3d2a20; --ok: #5cc28c; --ok-soft: #1f3529;
    --bad: #e2766e; --bad-soft: #3d2422; --busy: #e2b04a; --busy-soft: #3a311d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1a18; --surface: #242220; --surface-2: #2d2a27; --ink: #efe9e1; --muted: #a39b91; --line: #3a3632;
  --accent: #e0875a; --accent-ink: #f0a37b; --accent-soft: #3d2a20; --ok: #5cc28c; --ok-soft: #1f3529;
  --bad: #e2766e; --bad-soft: #3d2422; --busy: #e2b04a; --busy-soft: #3a311d; color-scheme: dark;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html, body, #app { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
.serif { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; }
.error { color: var(--bad); font-size: 14px; margin: 10px 0 0; }
.fineprint { color: var(--muted); font-size: 12px; text-align: center; margin: 10px 0 0; }
.credit { display: flex; align-items: center; justify-content: center; gap: 8px; }
.credit-logo { height: 20px; width: auto; filter: brightness(0); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .credit-logo { filter: brightness(0) invert(1); }
}
:root[data-theme="dark"] .credit-logo { filter: brightness(0) invert(1); }
.row-between { display: flex; justify-content: space-between; margin-top: 18px; }

/* buttons */
.btn { font: inherit; font-weight: 500; border: 1px solid transparent; border-radius: 10px; padding: 10px 16px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background .15s, border-color .15s, opacity .15s; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-ink); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; margin-top: 8px; min-height: 44px; }
.icon-btn { background: none; border: 0; color: var(--muted); padding: 6px; border-radius: 8px; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; vertical-align: -3px; }
.spinner.sm { width: 14px; height: 14px; }
.spinner.xs { width: 11px; height: 11px; border-width: 1.6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* login */
.login { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow); }
.login-card h1 { font-family: var(--serif); font-size: 26px; margin: 26px 0 6px; }
.login-card p { margin: 0 0 18px; }
.field { display: block; margin-bottom: 8px; }
.field span { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
input[type=email], input[inputmode=numeric] { font: inherit; width: 100%; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); outline: none; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.otp { position: relative; display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 4px 0 10px; cursor: text; }
.otp-input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; font-size: 16px; caret-color: transparent; }
.otp-box { height: 54px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.otp:focus-within .otp-box.active, .otp:focus-within .otp-box:last-child.filled { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* brand + shell */
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); font-size: 15px; }
.brand:hover { text-decoration: none; }
.brand b { font-weight: 700; }
.brand .star { color: var(--accent); display: inline-flex; }
.brand-lg { font-size: 17px; }
.shell { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5; }
.tabs { display: flex; gap: 4px; margin-left: 12px; flex: 1; }
.tabs a { color: var(--muted); padding: 7px 12px; border-radius: 9px; font-weight: 500; font-size: 14px; display: inline-flex; align-items: center; gap: 7px; }
.tabs a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.tabs a.active { background: var(--surface-2); color: var(--ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.user { position: relative; }
.avatar { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; font-size: 13px; cursor: pointer; }
.menu { position: absolute; right: 0; top: 42px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); min-width: 220px; padding: 6px; }
.menu-head { font-size: 13px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; }
.menu button { width: 100%; text-align: left; background: none; border: 0; font: inherit; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--ink); }
.menu button:hover { background: var(--surface-2); }

/* chat */
.chat { flex: 1; display: flex; min-height: 0; position: relative; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.history { width: 260px; flex: none; border-right: 1px solid var(--line); padding: 14px 10px; overflow-y: auto; background: var(--bg); }
.history .new-chat { margin: 0 0 14px; justify-content: flex-start; }
.history-empty { padding: 4px 8px; }
.history-group { margin-bottom: 14px; }
.history-label { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 4px 8px; }
.history-item { display: flex; align-items: center; border-radius: 9px; }
.history-item a { flex: 1; min-width: 0; padding: 7px 8px; color: var(--ink); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item a:hover { text-decoration: none; }
.history-item:hover, .history-item.active { background: var(--surface-2); }
.history-item .del { opacity: 0; padding: 5px; }
.history-item:hover .del { opacity: 1; }
.history-toggle { display: none; }
.history-scrim { display: none; }
.chat-scroll { flex: 1; overflow-y: auto; }
.chat-col { max-width: 760px; margin: 0 auto; padding: 28px 16px 24px; }
.empty { text-align: center; padding: 8vh 0 0; }
.woody-badge { width: 64px; height: 64px; margin: 0 auto 18px; }
.empty h1 { font-size: 30px; margin-bottom: 10px; }
.empty p { max-width: 520px; margin: 0 auto 28px; }
.suggestions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; text-align: left; }
.suggestion { font: inherit; font-size: 14px; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; color: var(--ink); transition: border-color .15s, transform .15s; }
.suggestion:hover { border-color: var(--accent); transform: translateY(-1px); }
.msg { margin: 0 0 26px; }
.msg.user { display: flex; justify-content: flex-end; }
.bubble { background: var(--surface-2); border-radius: 16px 16px 4px 16px; padding: 10px 15px; max-width: 85%; white-space: pre-wrap; }
.asst { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 14px; }
.assistant-avatar { width: 30px; height: 30px; flex: none; margin-top: 2px; }
.assistant-body { min-width: 0; }
.thinking { color: var(--muted); font-size: 14px; display: flex; gap: 8px; align-items: center; }
.steps { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); margin: 0 0 12px; font-size: 13.5px; }
.steps summary { cursor: pointer; list-style: none; padding: 9px 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.steps summary::-webkit-details-marker { display: none; }
.steps summary::after { content: "›"; margin-left: auto; transition: transform .15s; font-size: 16px; }
.steps[open] summary::after { transform: rotate(90deg); }
.steps ul { list-style: none; margin: 0; padding: 2px 13px 11px; }
.steps li { display: flex; align-items: center; gap: 9px; padding: 3px 0; color: var(--ink); }
.step-icon { width: 16px; display: inline-flex; justify-content: center; color: var(--muted); }
.steps li.ok .step-icon { color: var(--ok); }
.steps li.warn .step-icon { color: var(--busy); }
.chart-card { margin: 4px 0 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 10px; }
.chart-card figcaption { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.chart-box { position: relative; height: 280px; }
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md p { margin: 0 0 12px; }
.md ul, .md ol { padding-left: 22px; margin: 0 0 12px; }
.md h1, .md h2, .md h3 { font-family: var(--serif); margin: 18px 0 8px; font-size: 18px; }
.md table { border-collapse: collapse; max-width: 100%; margin: 6px 0 14px; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border-bottom: 1px solid var(--line); padding: 7px 10px; text-align: left; white-space: nowrap; }
.md th { font-weight: 600; color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; }
.md td:not(:first-child) { font-variant-numeric: tabular-nums; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.md strong { font-weight: 600; }
.msg-actions { margin-top: 2px; }

.composer-wrap { padding: 8px 16px 16px; max-width: 792px; width: 100%; margin: 0 auto; }
.composer { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 12px 12px 8px 16px; }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.composer textarea { width: 100%; border: 0; resize: none; font: inherit; font-size: 15.5px; background: transparent; color: var(--ink); outline: none; box-shadow: none; max-height: 220px; padding: 2px 0; }
.composer-bar { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.send { width: 36px; height: 36px; border-radius: 12px; border: 0; background: var(--accent); color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.send:disabled { background: var(--line); color: var(--muted); cursor: default; }
.send.stop { background: var(--ink); color: var(--bg); }

/* status */
.status { flex: 1; overflow-y: auto; }
.status-col { max-width: 880px; margin: 0 auto; padding: 32px 16px 40px; }
.status-col > h1 { font-size: 30px; margin-bottom: 6px; }
.status-col > p { margin: 0 0 22px; max-width: 620px; }
.status h3 { font-size: 15px; margin: 30px 0 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.hero { display: flex; gap: 18px; align-items: flex-start; }
.hero h2 { font-size: 19px; margin-bottom: 4px; }
.hero p { margin: 0; }
.hero-icon { width: 52px; height: 52px; flex: none; border-radius: 14px; display: flex; align-items: center; justify-content: center; }
.hero.ok .hero-icon { background: var(--ok-soft); color: var(--ok); }
.hero.bad .hero-icon { background: var(--bad-soft); color: var(--bad); }
.hero.bad { border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
.facts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-top: 14px; }
.facts > div { background: var(--surface); padding: 12px 16px; }
.facts span { display: block; font-size: 12px; color: var(--muted); }
.facts b { font-weight: 600; font-size: 14px; }
.areas { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.area { display: flex; flex-direction: column; gap: 4px; }
.area p { margin: 0; }
.area .btn { margin-top: auto; align-self: flex-start; }
.area-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 6px; }
.area h4 { font-size: 15px; }
.area-amount { font-family: var(--serif); font-size: 24px; font-weight: 600; margin: 2px 0; }
.area .small.muted:last-of-type { margin-bottom: 12px; }
.pill { font-size: 12px; font-weight: 500; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.busy { background: var(--busy-soft); color: var(--busy); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.tl-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--line); }
.tl-dot.ok { background: var(--ok); } .tl-dot.bad { background: var(--bad); } .tl-dot.busy { background: var(--busy); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); z-index: 20; }

@media (max-width: 900px) {
  .history { position: fixed; top: 0; bottom: 0; left: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); width: 280px; }
  .history.open { transform: none; }
  .history-scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .history-toggle { display: inline-flex; }
  .history-item .del { opacity: 1; }
}
@media (max-width: 760px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  .brand > :not(.star) { display: none; }
  .brand { font-size: 0; }
  .tabs { margin-left: 0; }
  .suggestions { grid-template-columns: 1fr; }
  .facts { grid-template-columns: repeat(2, 1fr); }
  .areas { grid-template-columns: 1fr; }
  .empty { padding-top: 4vh; }
  .hero { flex-direction: column; gap: 12px; }
}
