:root {
  --bg: #0b0f17;
  --bg-soft: #111725;
  --panel: #141b2a;
  --panel-2: #1a2334;
  --border: #24314a;
  --text: #e7ecf5;
  --muted: #92a0b8;
  --accent: #f0b429;
  --accent-2: #ff8a3d;
  --danger: #ff6b6b;
  --ok: #3ddc97;
  --radius: 14px;
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Consolas', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 600px at 80% -10%, #1a2440 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
}

.hidden { display: none !important; }

.boot {
  display: grid;
  place-items: center;
  height: 100vh;
  color: var(--muted);
}

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a1205;
  font-weight: 800;
  font-size: 20px;
  flex: none;
}

.brand h1 { font-size: 20px; margin: 0; letter-spacing: -0.02em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.brand.small h1 { font-size: 16px; }
.brand.small .brand-mark { width: 36px; height: 36px; font-size: 16px; border-radius: 10px; }

.stack { display: grid; gap: 14px; margin-top: 28px; }

label {
  display: grid;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

input, textarea {
  width: 100%;
  background: #0d1320;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.15);
}

button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 12px 16px;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
}

button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a1205;
  font-weight: 700;
}

.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.ghost:hover { border-color: #3a4c6e; background: rgba(255, 255, 255, 0.03); }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--muted);
  font-size: 12px;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.hint {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  margin: 14px 0 0;
  line-height: 1.5;
}

.shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  max-width: 980px;
  margin: 0 auto;
  padding: 0 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}

.topbar-actions { display: flex; gap: 10px; }
.topbar-actions button { padding: 8px 14px; font-size: 13px; }

.messages {
  overflow-y: auto;
  padding: 28px 4px 12px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: #263450; border-radius: 4px; }

.empty {
  max-width: 640px;
  margin: 6vh auto 0;
  text-align: center;
}

.empty h2 { font-size: 26px; margin: 0 0 8px; letter-spacing: -0.02em; }
.empty p { color: var(--muted); margin: 0 auto; max-width: 460px; line-height: 1.6; }

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 26px;
}

.suggestions button {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 999px;
}

.suggestions button:hover { border-color: var(--accent); }

.msg {
  display: flex;
  gap: 12px;
  margin-bottom: 22px;
  animation: rise 0.18s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg .avatar {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  flex: none;
  margin-top: 2px;
}

.msg.user .avatar { background: #24314a; color: var(--text); }
.msg.assistant .avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1a1205; }

.msg .body { min-width: 0; flex: 1; }

.bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user .bubble { background: #1b2740; border-color: #2a3c5e; }

.bubble.typing { color: var(--muted); }

.meta-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.chip {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-family: var(--mono);
}

details.tool {
  margin-top: 10px;
  background: #0d1320;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

details.tool summary {
  cursor: pointer;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
}

details.tool pre {
  margin: 0;
  padding: 12px;
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
  color: #b8c7e0;
  overflow-x: auto;
  white-space: pre;
}

.tool-actions {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.tool-actions button {
  padding: 6px 10px;
  font-size: 12px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.result-wrap {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  max-height: 380px;
}

table.result {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

table.result th, table.result td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.result th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  z-index: 1;
}

table.result tr:last-child td { border-bottom: none; }
table.result td.num { text-align: right; font-variant-numeric: tabular-nums; }

.chart {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  background: var(--panel);
}

.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-family: var(--font); font-size: 11px; }

.error-box {
  margin-top: 10px;
  border: 1px solid rgba(255, 107, 107, 0.4);
  background: rgba(255, 107, 107, 0.08);
  color: #ffb3b3;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  font-family: var(--mono);
  white-space: pre-wrap;
}

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.composer textarea {
  border: none;
  background: transparent;
  resize: none;
  max-height: 160px;
  padding: 8px 6px;
  font-size: 15px;
}

.composer textarea:focus { box-shadow: none; }
.composer .primary { padding: 11px 20px; flex: none; }

.footnote {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  margin: 10px 0 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #2a1520;
  border: 1px solid rgba(255, 107, 107, 0.45);
  color: #ffc7c7;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  max-width: min(560px, 90vw);
  z-index: 50;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

@media (max-width: 640px) {
  .shell { padding: 0 12px; }
  .topbar-actions button { padding: 7px 10px; }
  .empty h2 { font-size: 22px; }
  .bubble { padding: 12px 14px; }
}
