:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --text: #17211d;
  --muted: #5f6f68;
  --line: #dde4e0;
  --accent: #0f7a5c;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3ed;
  --user: #0f7a5c;
  --user-ink: #ffffff;
  --bot: #ffffff;
  --err: #b3261e;
  --err-soft: #fbeae8;
  --shadow: 0 1px 2px rgba(20, 40, 30, .06), 0 6px 20px rgba(20, 40, 30, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1513;
    --panel: #171f1c;
    --text: #e6efeb;
    --muted: #93a49c;
    --line: #26332e;
    --accent: #36c493;
    --accent-ink: #04251a;
    --accent-soft: #15302a;
    --user: #1d8f6c;
    --user-ink: #ffffff;
    --bot: #1b2420;
    --err: #ff8a80;
    --err-soft: #3a1f1d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 880px;
  margin: 0 auto;
  background: var(--bg);
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent);
  flex: none;
}
h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.sub { margin: 0; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }

.ghost {
  font: inherit; font-size: 13.5px; color: var(--text);
  background: transparent; border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 13px; cursor: pointer; white-space: nowrap;
}
.ghost:hover { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- message log ---------- */
.log {
  flex: 1;
  overflow-y: auto;
  padding: 22px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.welcome { margin: auto; text-align: center; padding: 20px 0 40px; max-width: 560px; }
.welcome h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.015em; }
.welcome p { margin: 0 0 20px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  font: inherit; font-size: 13.5px; color: var(--text); text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }

.msg { display: flex; flex-direction: column; max-width: 86%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; }
.who { font-size: 11.5px; color: var(--muted); margin: 0 6px 3px; }

.bubble {
  padding: 10px 14px; border-radius: 16px;
  overflow-wrap: anywhere; word-break: break-word;
}
.user .bubble { background: var(--user); color: var(--user-ink); border-bottom-right-radius: 5px; white-space: pre-wrap; }
.bot .bubble { background: var(--bot); border: 1px solid var(--line); border-bottom-left-radius: 5px; box-shadow: var(--shadow); }
.bot.error .bubble { background: var(--err-soft); border-color: var(--err); color: var(--err); }

.bubble p { margin: 0 0 8px; }
.bubble p:last-child, .bubble ul:last-child, .bubble .tablewrap:last-child { margin-bottom: 0; }
.bubble ul { margin: 0 0 8px; padding-left: 20px; }
.bubble code {
  font: 13px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace;
  background: var(--accent-soft); padding: 1px 5px; border-radius: 5px;
}
.tablewrap { overflow-x: auto; margin: 0 0 8px; border: 1px solid var(--line); border-radius: 10px; }
.bubble table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.bubble th, .bubble td { padding: 7px 11px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.bubble th { background: var(--accent-soft); font-weight: 600; }
.bubble tr:last-child td { border-bottom: 0; }
.chartbox { position: relative; height: 300px; min-width: min(560px, 80vw); margin: 0 0 10px; padding: 8px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.bubble .status { color: var(--muted); font-style: italic; }

/* streaming cursor and status note */
.cursor { display: inline-block; width: 7px; height: 1em; margin-left: 2px; vertical-align: text-bottom; background: var(--accent); animation: caret 1s steps(2) infinite; }
@keyframes caret { 50% { opacity: 0; } }
.status { color: var(--muted); font-size: 13px; }

/* typing indicator */
.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---------- composer ---------- */
.composer { padding: 10px 20px calc(14px + env(safe-area-inset-bottom, 0px)); background: var(--bg); }
.box {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 8px 8px 8px 16px; box-shadow: var(--shadow);
}
.box:focus-within { border-color: var(--accent); }
textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; line-height: 1.5; max-height: 140px; padding: 6px 0;
}
textarea::placeholder { color: var(--muted); }
.send {
  flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--accent); color: var(--accent-ink);
}
.send:disabled { opacity: .4; cursor: not-allowed; }
.hint { margin: 6px 6px 0; font-size: 11.5px; color: var(--muted); }

@media (max-width: 560px) {
  .topbar, .log, .composer { padding-left: 14px; padding-right: 14px; }
  .msg { max-width: 94%; }
  .hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .log { scroll-behavior: auto; }
  .typing i { animation: none; opacity: .6; }
  .cursor { animation: none; }
}

.actions { display: flex; gap: 8px; align-items: center; }
a.ghost { text-decoration: none; display: inline-block; }

.understood { font-size: 12.5px; color: var(--muted); margin: 0 6px 5px; font-style: italic; max-width: 100%; overflow-wrap: anywhere; }
