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

:root {
  --bg: #0b1120;
  --panel: #111c34;
  --bot: #1b2942;
  --user: #2563eb;
  --accent: #38bdf8;
  --text: #f1f5f9;
  --muted: #93a4bd;
  --border: #29384f;
  --radius: 18px;
  --font: 16px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--font);
  background:
    radial-gradient(1200px 600px at 20% -10%, #14233f 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  line-height: 1.55;
}

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

/* ---------- header ---------- */
header {
  padding: 16px 22px;
  background: rgba(17, 28, 52, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-avatar {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  font-size: 24px;
  border-radius: 14px;
  background: linear-gradient(145deg, #1d4ed8, #38bdf8);
  box-shadow: 0 6px 18px rgba(56,189,248,0.25);
}
.brand-text h1 { font-size: 19px; font-weight: 700; letter-spacing: .2px; }
.brand-text p { font-size: 13px; color: var(--muted); }
.brand-text code { color: var(--accent); font-size: 12.5px; }
.status {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--muted);
  font-family: ui-monospace, Menlo, monospace;
  background: #0e1830; border: 1px solid var(--border);
  padding: 6px 11px; border-radius: 999px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #34d399;
       box-shadow: 0 0 0 3px rgba(52,211,153,0.18); }

/* ---------- chat ---------- */
#chat {
  flex: 1;
  overflow-y: auto;
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.msg { display: flex; gap: 12px; align-items: flex-end; max-width: 100%; }
.msg.user { flex-direction: row-reverse; }

.avatar {
  flex: 0 0 38px;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-size: 19px;
  border-radius: 50%;
  background: var(--bot);
  border: 1px solid var(--border);
}
.msg.user .avatar { background: var(--user); border-color: transparent; }

.bubble {
  max-width: 78%;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: var(--font);
  word-wrap: break-word;
}
.msg.bot .bubble {
  background: var(--bot);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.msg.user .bubble {
  background: linear-gradient(160deg, #2563eb, #1d4ed8);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.bubble p { margin: 0; }
.bubble b { color: var(--accent); }
.msg.user .bubble b { color: #fff; }

/* example chips */
.examples { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 9px; }
.ex {
  background: #0e1830;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 13.5px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.ex:hover { background: rgba(56,189,248,0.14); transform: translateY(-1px); }

/* result blocks */
.explanation { color: var(--muted); font-style: italic; margin-bottom: 10px; font-size: 14.5px; }

pre.sql {
  background: #060c18;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
  overflow-x: auto;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13.5px;
  color: #7dd3fc;
  margin: 6px 0 14px;
  white-space: pre-wrap;
  line-height: 1.5;
}

.meta { color: var(--muted); font-size: 13px; margin-bottom: 8px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; max-height: 420px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 9px 13px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #060c18; color: var(--accent); position: sticky; top: 0; font-weight: 600; }
tbody tr:hover { background: rgba(56,189,248,0.07); }

.error { color: #fecaca; background: rgba(248,113,113,0.12); border: 1px solid #7f1d1d;
         padding: 12px 14px; border-radius: 12px; font-size: 14.5px; }

/* typing indicator */
.thinking { display: inline-flex; gap: 5px; align-items: center; }
.thinking span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.thinking span:nth-child(2) { animation-delay: .2s; }
.thinking span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- composer ---------- */
#composer {
  display: flex;
  gap: 12px;
  padding: 16px 22px 22px;
  background: linear-gradient(transparent, var(--bg) 30%);
}
#q {
  flex: 1;
  padding: 15px 20px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
}
#q::placeholder { color: var(--muted); }
#q:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56,189,248,0.15); }
#send {
  flex: 0 0 54px;
  width: 54px; height: 54px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(145deg, #38bdf8, #2563eb);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: grid; place-items: center;
  transition: transform .1s, opacity .15s;
}
#send:hover { transform: scale(1.05); }
#send:disabled { opacity: 0.45; cursor: default; transform: none; }

@media (max-width: 600px) {
  :root { --font: 15px; }
  .bubble { max-width: 84%; }
}
