:root {
  --bg: #faf7f1; --panel: #ffffff; --side: #f1ece2; --ink: #1d2733; --muted: #66707c; --line: #e2dbcd;
  --brand: #173a5e; --brand-ink: #ffffff; --accent: #d9822b; --soft: #f4efe6; --danger: #b3382c; --ok: #2d7a4f;
  --shadow: 0 1px 2px rgba(23, 58, 94, .08), 0 4px 14px rgba(23, 58, 94, .06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12171d; --panel: #1a2129; --side: #161c23; --ink: #e8ecf1; --muted: #98a3b0; --line: #2a333e;
    --brand: #7fb2e5; --brand-ink: #0f1620; --accent: #f4a340; --soft: #202832; --danger: #ef7a6d; --ok: #6cc497;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); }
}
* { box-sizing: border-box; }
html, body, #app { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 7px 13px; cursor: pointer; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
input[type=text], input[type=email], textarea { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 9px 11px; width: 100%; }
input:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* sign-in */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login h1 { font-size: 22px; margin-bottom: 4px; }
.login form { display: grid; gap: 12px; margin-top: 18px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; }

/* layout */
.shell { display: grid; grid-template-columns: 270px 1fr; height: 100%; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; font-weight: 700; font-size: 17px; }
.brand .mark { width: 28px; height: 28px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; }
.side nav { padding: 6px 10px; display: grid; gap: 4px; }
.side nav a, .chatlist a { display: block; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side nav a:hover, .chatlist a:hover { background: var(--soft); }
.side nav a.on, .chatlist a.on { background: var(--panel); box-shadow: var(--shadow); font-weight: 600; }
.side .label { padding: 12px 20px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.chatlist { flex: 1; overflow-y: auto; padding: 0 10px 10px; display: grid; gap: 2px; align-content: start; }
.chatlist a { font-size: 14px; }
.side footer { border-top: 1px solid var(--line); padding: 12px 16px; font-size: 13px; }
.side footer .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.menu-btn { display: none; }

/* chat */
.thread { flex: 1; overflow-y: auto; padding: 24px 20px 10px; }
.thread > .inner, .composer > .inner, .page > .inner { max-width: 860px; margin: 0 auto; }
.msg { margin: 0 0 18px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--brand); color: var(--brand-ink); border-radius: 16px 16px 4px 16px; padding: 10px 14px; max-width: 80%; white-space: pre-wrap; overflow-wrap: anywhere; }
.md { overflow-wrap: anywhere; }
.md p { margin: 0 0 10px; }
.md h1, .md h2, .md h3 { font-size: 16px; margin: 16px 0 8px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md code { background: var(--soft); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.md pre { background: var(--soft); padding: 10px 12px; border-radius: 10px; overflow-x: auto; }
.tablewrap { overflow-x: auto; margin: 0 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 7px 11px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--soft); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
details.step { margin: 0 0 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 14px; }
details.step summary { cursor: pointer; padding: 7px 12px; color: var(--muted); list-style: none; display: flex; gap: 8px; align-items: center; }
details.step summary::-webkit-details-marker { display: none; }
details.step summary::before { content: "▸"; }
details.step[open] summary::before { content: "▾"; }
details.step.bad summary { color: var(--danger); }
details.step .body { padding: 0 12px 10px; }
details.step pre { background: var(--soft); padding: 9px 11px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; margin: 0 0 8px; white-space: pre-wrap; }
details.step .tablewrap { max-height: 300px; overflow: auto; }
.spin { width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.thinking { color: var(--muted); display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.chartcard { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 14px; margin: 0 0 12px; }
.chartcard h3 { font-size: 15px; margin-bottom: 8px; }
.chartcard .canvas { position: relative; height: 300px; }
.reportcard { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 1px solid var(--line); border-left: 4px solid var(--accent); background: var(--panel); border-radius: 12px; padding: 12px 14px; margin: 0 0 12px; }
.composer { padding: 10px 20px 18px; }
.composer .box { display: flex; gap: 8px; align-items: flex-end; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px; box-shadow: var(--shadow); }
.composer textarea { border: 0; resize: none; max-height: 180px; padding: 6px 8px; background: transparent; }
.composer textarea:focus { outline: none; }
.empty { text-align: center; padding: 8vh 10px 20px; }
.empty h1 { font-size: 26px; margin-bottom: 6px; }
.ideas { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-top: 24px; text-align: left; }
.ideas button { text-align: left; padding: 12px 14px; border-radius: 12px; }

/* pages */
.page { flex: 1; overflow-y: auto; padding: 26px 20px 40px; }
.page .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page h1 { font-size: 24px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-bottom: 26px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 15px; text-decoration: none; color: var(--ink); display: block; box-shadow: var(--shadow); }
.card:hover { border-color: var(--brand); }
.card h3 { font-size: 16px; margin-bottom: 6px; }
.card p { margin: 0 0 10px; color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--soft); color: var(--muted); }
.block { margin-bottom: 26px; }
.block h2 { font-size: 17px; margin-bottom: 4px; }
.block .note { color: var(--muted); margin: 0 0 10px; font-size: 14px; }
.block .tablewrap { max-height: 480px; overflow: auto; }
.blockfoot { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--ink); padding: 22px; width: min(460px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 20, 30, .45); }
dialog h2 { font-size: 18px; margin-bottom: 12px; }
dialog .list { max-height: 50vh; overflow-y: auto; display: grid; gap: 4px; margin: 10px 0 16px; }
dialog label.pick { display: flex; gap: 10px; align-items: center; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
dialog label.pick:hover { background: var(--soft); }
dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
dialog .field { display: grid; gap: 5px; margin-bottom: 12px; }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 84vw; max-width: 310px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .shell.open .side { transform: none; box-shadow: 0 0 0 100vw rgba(10, 20, 30, .45); }
  .menu-btn { display: inline-block; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
  .thread, .page { padding-left: 14px; padding-right: 14px; }
  .composer { padding: 8px 12px 12px; }
  .msg.user .bubble { max-width: 92%; }
}
@media (min-width: 801px) { .topbar { display: none; } }
