/* ── Tokens (LLMntal.ai design system) ───────────────────────────────────── */
:root {
  --bg:           #17141d;
  --bg-card:      #1e1b27;
  --bg-card-2:    #231f2e;
  --bg-user:      #2a2536;
  --border:       rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.14);
  --teal:         #4dd9c0;
  --purple:       #a855f7;
  --text:         #e8e6ed;
  --muted:        #6b6880;
  --muted-2:      #9896a4;
  --font:         'Inter', system-ui, -apple-system, sans-serif;
  --mono:         'JetBrains Mono', 'Fira Code', monospace;
  --radius:       12px;
  --radius-sm:    8px;
  --nav-h:        52px;
}

/* ── Reset + fixed-viewport layout ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ── Nav ─────────────────────────────────────────────────────────────────── */
nav {
  flex-shrink: 0;
  height: var(--nav-h);
  background: rgba(23, 20, 29, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}
.nav-inner {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.nav-logo {
  font-weight: 700;
  font-size: 0.95rem;
  background: linear-gradient(to right, var(--teal), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-decoration: none;
}
.nav-tag {
  font-size: 0.68rem;
  color: var(--muted-2);
  border: 1px solid var(--border);
  padding: 0.18rem 0.6rem;
  border-radius: 99px;
  background: var(--bg-card);
}

/* ── Main (fills remaining viewport) ─────────────────────────────────────── */
main {
  flex: 1;
  min-height: 0;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 0.9rem 1.5rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

/* ── Hero (compact) ──────────────────────────────────────────────────────── */
.hero { flex-shrink: 0; }
.hero-eyebrow {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 0.3rem;
}
.hero h1 {
  font-size: clamp(1.25rem, 2.3vw, 1.7rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}
.gradient-text {
  background: linear-gradient(to right, var(--teal), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero-sub {
  color: var(--muted-2);
  font-size: 0.8rem;
  line-height: 1.5;
  max-width: 620px;
}

.section-label {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

/* ── Schema strip (compact) ──────────────────────────────────────────────── */
.schema-section { flex-shrink: 0; }
.schema-tables {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.schema-table {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  flex: 1;
  min-width: 130px;
}
.table-name {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--teal);
  margin-bottom: 0.12rem;
}
.table-cols {
  font-family: var(--mono);
  font-size: 0.55rem;
  color: var(--muted);
  line-height: 1.4;
}
.schema-join {
  font-size: 0.56rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--purple);
}

/* ── Chat card (fills remaining space) ───────────────────────────────────── */
.chat-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.chat-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.75rem 0.85rem 0.4rem;
  display: flex;
  flex-direction: column;
}

/* ── Empty state (inside card) ───────────────────────────────────────────── */
#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  padding: 1rem 1rem;
  text-align: center;
  flex-shrink: 0;
}
/* Give it more presence / vertical centering only when it's alone in the card */
.chat-messages:has(#turns:empty) #empty-state {
  min-height: 320px;
  gap: 0.9rem;
  padding: 1.5rem 1rem;
}
.empty-prompt {
  color: var(--muted-2);
  font-size: 0.88rem;
}
.examples-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  max-width: 640px;
}
.example-btn {
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  color: var(--muted-2);
  font-family: var(--font);
  font-size: 0.74rem;
  padding: 0.35rem 0.8rem;
  border-radius: 99px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.example-btn:hover {
  border-color: var(--teal);
  color: var(--teal);
  background: rgba(77, 217, 192, 0.06);
}

/* Info pills — differentiated from example pills (purple accent) */
.info-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  margin-top: 0.5rem;
}
.info-btn {
  background: transparent;
  border: 1px dashed rgba(168, 85, 247, 0.35);
  color: var(--muted-2);
  font-family: var(--font);
  font-size: 0.74rem;
  padding: 0.35rem 0.8rem;
  border-radius: 99px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.info-btn:hover {
  border-style: solid;
  border-color: var(--purple);
  color: var(--purple);
  background: rgba(168, 85, 247, 0.06);
}

/* ── Turns ───────────────────────────────────────────────────────────────── */
#turns { display: flex; flex-direction: column; gap: 1rem; padding-bottom: 0.25rem; flex-shrink: 0; }

.turn {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  animation: fadeIn 0.25s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.user-bubble {
  align-self: flex-end;
  background: var(--bg-user);
  color: var(--text);
  padding: 0.45rem 0.75rem;
  border-radius: 12px 12px 3px 12px;
  font-size: 0.82rem;
  line-height: 1.45;
  max-width: 80%;
  border: 1px solid var(--border);
}

.assistant-card {
  align-self: flex-start;
  max-width: 90%;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* ── Steps ───────────────────────────────────────────────────────────────── */
.step.hidden { display: none; }
.step {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.step-header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.step.collapsible .step-header {
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(77, 217, 192, 0.15);
}

/* Layout row: toggle button (left) + body (right), aligned under the header */
.step-layout {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
}
.step-body { flex: 1; min-width: 0; }

/* Toggle button — visually small, but with a large invisible hit area */
.step-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card-2);
  color: var(--muted-2);
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 0.2rem;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  position: relative;               /* anchor for the hit-slop pseudo */
  /* mobile robustness */
  touch-action: manipulation;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
/* Invisible 44×44px hit target extending beyond the visible button */
.step-toggle::before {
  content: '';
  position: absolute;
  top:    -13px;
  right:  -13px;
  bottom: -13px;
  left:   -13px;
  /* no visual — just catches taps */
}
.step.collapsible .step-toggle { display: inline-flex; }
.step-toggle:hover { border-color: var(--teal); color: var(--teal); }
.step-toggle:focus { outline: none; }
.step-toggle:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }

.step.collapsed .step-body { display: none !important; }
.step-badge {
  font-size: 0.54rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--teal);
  background: rgba(77, 217, 192, 0.08);
  border: 1px solid rgba(77, 217, 192, 0.18);
  padding: 0.1rem 0.45rem;
  border-radius: 99px;
}
.step-status { font-size: 0.64rem; color: var(--muted); }
.step-status.thinking { color: var(--teal); display: flex; align-items: center; gap: 0.3rem; }
.step-status.thinking::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--teal);
  animation: pulse 1s ease-in-out infinite;
}
.step-status.done { color: var(--teal); display: inline-flex; align-items: center; gap: 0.25rem; }
.step-status.done::before {
  content: '✓';
  color: var(--teal);
  font-weight: 700;
  font-size: 0.68rem;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.3; transform: scale(0.6); }
}

.step-sql .sql-pre {
  background: var(--bg-card-2) !important;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 0 !important;
  padding: 0.45rem 0.65rem !important;
  font-size: 0.62rem !important;
  line-height: 1.55 !important;
  white-space: pre-wrap !important;
  word-break: break-word !important;
  overflow-x: hidden;
  opacity: 0.75;
}
.step-sql .sql-pre code {
  white-space: pre-wrap !important;
  word-break: break-word !important;
}

.step-table .table-wrap {
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  opacity: 0.8;
  display: inline-block;      /* shrink-wrap the container to the table width */
  max-width: 100%;
}
.step-table table {
  width: auto;                /* columns size to content, not full width */
  border-collapse: collapse;
  font-size: 0.62rem;
  font-family: var(--mono);
}
.step-table thead tr { border-bottom: 1px solid var(--border); }
.step-table th {
  text-align: left;
  padding: 0.2rem 0.5rem;
  color: var(--muted);
  font-size: 0.5rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.step-table td {
  padding: 0.2rem 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  color: var(--text);
  white-space: nowrap;
}
.step-table tr:last-child td { border-bottom: none; }
.step-table .more-rows {
  padding: 0.28rem 0.55rem;
  font-size: 0.6rem;
  color: var(--muted);
  text-align: center;
  background: rgba(255,255,255,0.02);
  border-top: 1px solid var(--border);
}

.step-chart .chart-wrap {
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem;
  height: 210px;
  position: relative;
}

.answer-box {
  background: rgba(77, 217, 192, 0.05);
  border: 1px solid rgba(77, 217, 192, 0.18);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.8rem;
}
.step-answer.out-of-scope .answer-box {
  background: rgba(255,255,255,0.03);
  border-color: var(--border);
}
.step-answer.out-of-scope .answer-icon { display: none; }
.oos-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
}
.answer-text {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text);
  font-weight: 500;
}
.answer-icon {
  color: var(--teal);
  margin-right: 0.3rem;
  font-size: 0.8rem;
}
.answer-cursor::after {
  content: '▋';
  color: var(--teal);
  animation: blink 0.8s step-end infinite;
  margin-left: 2px;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* Close card (turn-5 wrap-up) */
.close-card {
  background: linear-gradient(to bottom right, rgba(77, 217, 192, 0.08), rgba(168, 85, 247, 0.08));
  border: 1px solid rgba(77, 217, 192, 0.28);
  border-radius: var(--radius);
  padding: 0.95rem 1.05rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  animation: fadeIn 0.3s ease-out;
}
.close-message {
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--text);
  font-weight: 500;
  min-height: 1.2em;   /* reserve space so the card doesn't collapse while streaming */
}
.close-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s, transform 0.1s, border-color 0.15s, color 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary {
  background: linear-gradient(to right, var(--teal), var(--purple));
  color: var(--bg);
  border: none;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted-2);
  font-weight: 600;
}
.btn-secondary:hover { border-color: var(--teal); color: var(--teal); }
.btn-primary:focus,
.btn-secondary:focus { outline: none; }
.btn-primary:focus-visible,
.btn-secondary:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

.error-msg {
  color: #f87171;
  font-family: var(--mono);
  font-size: 0.76rem;
  padding: 0.65rem;
  background: rgba(248, 113, 113, 0.06);
  border: 1px solid rgba(248, 113, 113, 0.2);
  border-radius: var(--radius-sm);
}

/* ── Chat input (bottom of card) ─────────────────────────────────────────── */
.chat-input {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 0.65rem 0.9rem 0.75rem;
  background: var(--bg-card-2);
}
#question {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.88rem;
  line-height: 1.45;
  padding: 0.55rem 0.8rem;
  resize: none;
  outline: none;
  max-height: 120px;
  transition: border-color 0.15s;
}
#question:focus { border-color: var(--teal); }
.input-hint-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-top: 0.35rem;
}
.input-hint {
  font-size: 0.64rem;
  color: var(--muted);
  flex: 1;
  min-width: 0;
}
.reset-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted-2);
  font-family: var(--font);
  font-size: 0.64rem;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.reset-btn:hover { border-color: var(--teal); color: var(--teal); }
.reset-btn:focus { outline: none; }
.reset-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }
.input-hint kbd {
  font-family: var(--mono);
  font-size: 0.6rem;
  padding: 0.08rem 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--teal);
  margin: 0 0.08rem;
}

/* ── Responsive: ultra-short viewports ───────────────────────────────────── */
@media (max-height: 640px) {
  .hero-sub { display: none; }
  .schema-section { display: none; }
  main { gap: 0.6rem; padding: 0.6rem 1.5rem; }
}
@media (max-width: 600px) {
  main { padding: 0.6rem 1rem; }
  /* Mobile: hide the schema strip — the ⓘ Data info pill covers it conversationally */
  .schema-section { display: none; }
  .step-chart .chart-wrap { height: 185px; }
}
