:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242736;
  --border: #2e3148;
  --accent: #e8354a;
  --accent2: #f5a623;
  --text: #e8eaf0;
  --text-muted: #7b8099;
  --user-bubble: #1e2d4a;
  --bot-bubble: #1a1d27;
  --radius: 12px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 820px;
  margin: 0 auto;
}

/* ── Header ── */
header {
  flex-shrink: 0;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo {
  font-size: 28px;
  color: var(--accent);
  line-height: 1;
}
h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ── Messages ── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#messages:empty::before {
  content: "Ask anything about the Pokémon Champions VGC meta — legal mons, team building, move synergies, usage stats, and more.";
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  margin: auto;
  max-width: 340px;
  line-height: 1.7;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot  { align-self: flex-start; align-items: flex-start; max-width: 95%; }

.bubble {
  padding: 11px 16px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

/* markdown inside bot bubbles */
.msg.bot .bubble { white-space: normal; }
.msg.bot .bubble p { margin: 0 0 0.5em; }
.msg.bot .bubble p:last-child { margin-bottom: 0; }
.msg.bot .bubble ul, .msg.bot .bubble ol { margin: 0.4em 0 0.5em 1.4em; padding: 0; }
.msg.bot .bubble li { margin-bottom: 0.25em; }
.msg.bot .bubble strong { color: #c8d4f0; font-weight: 600; }
.msg.bot .bubble code { background: var(--surface2); padding: 1px 5px; border-radius: 4px; font-family: 'Cascadia Code','Consolas',monospace; font-size: 12.5px; }
.msg.bot .bubble pre { background: var(--surface2); padding: 8px 12px; border-radius: 6px; overflow-x: auto; margin: 0.4em 0; }
.msg.bot .bubble pre code { background: none; padding: 0; }
.msg.bot .bubble h1,.msg.bot .bubble h2,.msg.bot .bubble h3 { font-size: 14.5px; font-weight: 700; margin: 0.6em 0 0.3em; }
.msg.bot .bubble table { margin: 0.6em 0; border-collapse: collapse; width: auto; min-width: 100%; }
.msg.bot .bubble th, .msg.bot .bubble td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; white-space: nowrap; }
.msg.bot .bubble th { background: var(--surface2); color: var(--text-muted); font-weight: 600; font-size: 12.5px; }
.msg.bot .bubble td { font-size: 13px; }
.msg.bot .bubble tr:nth-child(even) td { background: rgba(255,255,255,0.02); }
.msg.bot .bubble .table-wrap { overflow-x: auto; }
.msg.user .bubble {
  background: var(--user-bubble);
  border: 1px solid #2a3f6a;
  border-bottom-right-radius: 4px;
}
.msg.bot .bubble {
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* thinking */
.bubble.thinking {
  color: var(--text-muted);
  font-style: italic;
}
.bubble.thinking::after {
  content: '';
  display: inline-block;
  width: 3px;
  height: 3px;
  background: var(--text-muted);
  border-radius: 50%;
  margin-left: 6px;
  animation: blink 1s infinite;
  vertical-align: middle;
}
@keyframes blink { 0%,100%{opacity:0} 50%{opacity:1} }

/* error */
.bubble.error { color: #f87171; border-color: #4a1e1e; }

/* ── Collapsible SQL/rows ── */
.details-panel {
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 13px;
  max-width: 680px;
  width: 100%;
}
.details-panel summary {
  padding: 7px 12px;
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
  background: var(--surface2);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.details-panel summary::-webkit-details-marker { display: none; }
.details-panel summary::before {
  content: '▶';
  font-size: 10px;
  transition: transform 0.15s;
}
.details-panel[open] summary::before { transform: rotate(90deg); }

.details-body {
  padding: 12px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sql-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 12.5px;
  color: #a8c8ff;
  white-space: pre-wrap;
  overflow-x: auto;
}

.rows-label {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.rows-table-wrap { overflow-x: auto; }
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
}
th, td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
th {
  background: var(--surface2);
  color: var(--text-muted);
  font-weight: 600;
}
tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

/* ── Chips ── */
#chips {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px 4px;
}
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.chip:hover { border-color: var(--accent); color: var(--text); }

/* ── Input ── */
#chat-form {
  flex-shrink: 0;
  padding: 12px 20px 20px;
}
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 6px 6px 14px;
  transition: border-color 0.15s;
}
.input-row:focus-within { border-color: var(--accent); }

#question {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14.5px;
  font-family: var(--font);
  padding: 4px 0;
  resize: none;
  overflow: hidden;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
}
#question::placeholder { color: var(--text-muted); }

#send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
#send-btn:hover { background: #c42c3e; }
#send-btn:disabled { background: var(--surface2); color: var(--text-muted); cursor: not-allowed; }

/* ── Scrollbar ── */
#messages::-webkit-scrollbar { width: 5px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Mobile ── */
@media (max-width: 600px) {
  #app { max-width: 100%; }
  .msg { max-width: 95%; }
  #chips { padding: 10px 12px 4px; }
  #chat-form { padding: 10px 12px 16px; }
  #messages { padding: 14px 12px; }
}
