/* ============================================================
   ASK AI — dedicated chat page
   Reuses the design tokens from styles.css (:root palette, spacing, radii).
   ============================================================ */

.chat-body { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.brand { display: flex; align-items: center; gap: var(--sp-3); }
.brand-home {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none;
  border: 1px solid var(--border); border-radius: var(--r-md);
  color: var(--text-secondary); text-decoration: none; font-size: 20px; line-height: 1;
  transition: background .12s, color .12s;
}
.brand-home:hover { background: var(--surface-hover); color: var(--text); }

/* ---- shell: sidebar + main ---- */
.chat-shell { flex: 1; display: grid; grid-template-columns: 264px 1fr; min-height: 0; }

.chat-sidebar {
  border-right: 1px solid var(--border); background: var(--surface-alt);
  display: flex; flex-direction: column; min-height: 0; padding: var(--sp-4);
}
.chat-new {
  display: flex; align-items: center; gap: var(--sp-2); justify-content: center;
  font: inherit; font-size: var(--fs-body); font-weight: var(--fw-h2);
  color: var(--accent-on); background: var(--accent); border: none;
  border-radius: var(--r-md); padding: var(--sp-3); cursor: pointer;
  transition: filter .12s;
}
.chat-new:hover { filter: brightness(1.06); }
.chat-new .plus { font-size: 16px; line-height: 1; }

.chat-history-label {
  font-size: var(--fs-micro); font-weight: var(--fw-bold); letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-tertiary);
  margin: var(--sp-5) var(--sp-1) var(--sp-2);
}
.chat-history { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-history:empty::after {
  content: "No questions yet."; color: var(--text-tertiary);
  font-size: var(--fs-small); padding: var(--sp-1);
}
.hist-item {
  text-align: left; font: inherit; font-size: var(--fs-small); color: var(--text-secondary);
  background: transparent; border: none; border-radius: var(--r-sm);
  padding: var(--sp-2) var(--sp-3); cursor: pointer; width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .1s, color .1s;
}
.hist-item:hover { background: var(--surface-hover); color: var(--text); }
.hist-item.active { background: var(--accent-soft); color: var(--accent); font-weight: var(--fw-h2); }

/* ---- main conversation ---- */
.chat-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-scroll {
  flex: 1; overflow-y: auto; padding: var(--sp-6) var(--sp-6) var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-5);
  scroll-behavior: smooth;
}
.chat-thread { width: 100%; max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--sp-5); }

/* empty state */
.chat-empty { margin: auto; max-width: 560px; text-align: center; padding: var(--sp-6); }
.chat-empty h2 { font-size: 22px; font-weight: var(--fw-display); margin: 0 0 var(--sp-2); }
.chat-empty p { color: var(--text-secondary); font-size: var(--fs-body); margin: 0 0 var(--sp-6); }
.chat-examples { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.chat-example {
  text-align: left; font: inherit; font-size: var(--fs-body); color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--sp-3) var(--sp-4); cursor: pointer; transition: border-color .12s, background .12s;
}
.chat-example:hover { border-color: var(--accent); background: var(--surface-hover); }
.chat-example span { display: block; color: var(--text-tertiary); font-size: var(--fs-micro); margin-top: 2px; }

/* a Q/A turn */
.turn { display: flex; flex-direction: column; gap: var(--sp-3); }
.turn-q {
  align-self: flex-end; max-width: 80%;
  background: var(--accent); color: var(--accent-on);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-xl) var(--r-xl) var(--r-sm) var(--r-xl);
  font-size: var(--fs-body); line-height: var(--lh-body);
}
.turn-a {
  align-self: stretch; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-sm) var(--r-xl) var(--r-xl) var(--r-xl);
  padding: var(--sp-4);
}
.a-explain { font-size: var(--fs-body); color: var(--text); line-height: var(--lh-body); margin-bottom: var(--sp-3); }
.a-thinking { color: var(--text-tertiary); font-size: var(--fs-body); }
.a-thinking::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .a-thinking::after { animation: none; } .chat-scroll { scroll-behavior: auto; } }

.a-error {
  color: var(--danger); font-size: var(--fs-body);
  background: var(--danger-soft); border-radius: var(--r-md); padding: var(--sp-3);
}

/* result table */
.a-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-md); margin-top: var(--sp-1); }
.a-table { border-collapse: collapse; width: 100%; font-size: var(--fs-small); }
.a-table th, .a-table td {
  padding: var(--sp-2) var(--sp-3); text-align: left; border-bottom: 1px solid var(--border); vertical-align: top;
}
.a-table th {
  background: var(--surface-alt); position: sticky; top: 0;
  font-size: var(--fs-micro); text-transform: uppercase; letter-spacing: .03em;
  color: var(--text-tertiary); font-weight: var(--fw-bold); white-space: nowrap;
}
.a-table tbody tr:last-child td { border-bottom: none; }
.a-table td { font-variant-numeric: tabular-nums; }
.a-scalar { font-size: 28px; font-weight: var(--fw-display); color: var(--text); font-variant-numeric: tabular-nums; }

/* the SQL is available but understated — a subtle toggle, never in the sidebar */
.a-sql { margin-top: var(--sp-3); }
.a-sql summary {
  cursor: pointer; font-size: var(--fs-micro); font-weight: var(--fw-bold);
  letter-spacing: .04em; text-transform: uppercase; color: var(--text-tertiary);
  list-style: none;
}
.a-sql summary::before { content: "▸ "; }
.a-sql[open] summary::before { content: "▾ "; }
.a-sql pre {
  margin: var(--sp-2) 0 0; padding: var(--sp-3); overflow-x: auto;
  background: var(--surface-alt); border-radius: var(--r-sm);
  font-family: var(--font-mono); font-size: var(--fs-small); color: var(--text-secondary);
  white-space: pre-wrap;
}
.a-meta { font-size: var(--fs-micro); color: var(--text-tertiary); margin-top: var(--sp-2); }

/* ---- composer ---- */
.chat-composer {
  border-top: 1px solid var(--border); background: var(--surface);
  padding: var(--sp-4) var(--sp-6);
  display: flex; gap: var(--sp-2); align-items: flex-end;
}
.chat-composer { --composer-max: 780px; }
#chat-input {
  flex: 1; max-width: var(--composer-max); margin: 0 auto;
  resize: none; font: inherit; font-size: var(--fs-body); line-height: var(--lh-body);
  color: var(--text); background: var(--surface-alt);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--sp-3) var(--sp-4); max-height: 160px; overflow-y: auto;
}
#chat-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#chat-send {
  flex: none; width: 40px; height: 40px; border: none; border-radius: var(--r-md);
  background: var(--accent); color: var(--accent-on); font-size: 18px; cursor: pointer;
  transition: filter .12s;
}
#chat-send:hover:not(:disabled) { filter: brightness(1.06); }
#chat-send:disabled { opacity: .45; cursor: default; }

/* keep composer children centered as a group with the thread width */
.chat-composer { position: relative; }

/* ---- responsive ---- */
@media (max-width: 760px) {
  .chat-shell { grid-template-columns: 1fr; }
  .chat-sidebar { display: none; }
  .chat-examples { grid-template-columns: 1fr; }
}
