:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1d1d1b;
  --muted: #65635c;
  --border: #e2dfd6;
  --accent: #0f6e56;
  --accent-ink: #ffffff;
  --accent-soft: rgba(15, 110, 86, 0.14);
  --history: #3b3a36;
  --compare: #a8a49a;
  --error: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151614;
    --surface: #1e1f1c;
    --surface-2: #272824;
    --text: #ecebe6;
    --muted: #a3a197;
    --border: #34352f;
    --accent: #3cbf96;
    --accent-ink: #0d1f19;
    --accent-soft: rgba(60, 191, 150, 0.18);
    --history: #d9d7cf;
    --compare: #77756c;
    --error: #ff8a80;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.55 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100dvh; display: flex; flex-direction: column;
}
button { font: inherit; cursor: pointer; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px max(16px, calc((100% - 860px) / 2));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 20px;
}
.brand h1 { font-size: 18px; margin: 0; letter-spacing: .04em; }
.tag { margin: 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 8px; }
.ghost {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 6px 14px; font-size: 14px;
}
.ghost:hover { background: var(--surface-2); }

main { flex: 1; width: 100%; max-width: 860px; margin: 0 auto; padding: 24px 16px 8px; }
.welcome h2 { font-size: clamp(22px, 4vw, 30px); line-height: 1.2; margin: 24px 0 8px; }
.welcome p { color: var(--muted); max-width: 640px; }
.suggestions { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin-top: 20px; }
.suggestions button {
  text-align: left; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; font-size: 14px; box-shadow: var(--shadow);
}
.suggestions button:hover { border-color: var(--accent); }

.msg { margin: 18px 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: var(--accent); color: var(--accent-ink); border-radius: var(--radius) var(--radius) 4px var(--radius);
  padding: 10px 14px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.assistant .content { overflow-wrap: anywhere; }
.msg.assistant .content p { margin: 0 0 .7em; }
.msg.assistant .content :is(ul, ol) { padding-left: 1.3em; margin: 0 0 .7em; }
.msg.assistant .content table { border-collapse: collapse; margin: .5em 0; font-size: 14px; }
.msg.assistant .content :is(th, td) { border: 1px solid var(--border); padding: 4px 8px; }
.status { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.status::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}
.status.done::before { animation: none; opacity: .4; }
@keyframes pulse { 50% { opacity: .25; } }
.error { color: var(--error); font-size: 14px; }

.displays { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin: 10px 0 14px; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px 10px; box-shadow: var(--shadow); min-width: 0;
}
.panel.wide { grid-column: 1 / -1; }
.panel h3 { font-size: 14px; margin: 0; }
.panel .unit { color: var(--muted); font-size: 12px; margin: 0 0 6px; }
.panel .note { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.panel canvas { width: 100% !important; height: 220px !important; }
.table-wrap { overflow-x: auto; }
.panel table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
.panel th { text-align: right; font-weight: 600; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); }
.panel td { text-align: right; padding: 5px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.panel :is(th, td):first-child { text-align: left; }
.panel tr:last-child td { border-bottom: none; }

.composer {
  position: sticky; bottom: 0; width: 100%; max-width: 860px; margin: 0 auto;
  display: flex; gap: 8px; padding: 10px 16px; background: var(--bg);
}
.composer textarea {
  flex: 1; resize: none; max-height: 180px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 11px 14px; box-shadow: var(--shadow);
}
.composer textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.composer button {
  width: 46px; border: none; border-radius: var(--radius); background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
}
.composer button:disabled { opacity: .45; cursor: default; }
.footnote { max-width: 860px; margin: 0 auto; padding: 0 16px 14px; color: var(--muted); font-size: 12px; }

.overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, .45);
}
.overlay[hidden] { display: none; }
.card {
  background: var(--surface); color: var(--text); border-radius: 18px; padding: 24px;
  width: min(420px, 100%); box-shadow: 0 10px 40px rgba(0, 0, 0, .2);
}
.card.about { width: min(620px, 100%); max-height: 85dvh; overflow: auto; }
.card h2 { margin: 0 0 8px; }
.card p { color: var(--muted); }
.card input {
  width: 100%; font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); margin: 6px 0 10px;
}
.card button {
  border: none; border-radius: 10px; background: var(--accent); color: var(--accent-ink);
  padding: 10px 18px; font-weight: 600;
}
