/* Competitive & Market Intelligence — interface styles.
 *
 * Shares its visual language with the case-study deck: cool grey-blue ground,
 * ink text, a single verdigris accent, hairline rules instead of filled panels.
 *
 * Two constraints shaped the restraint. The trace panel is read on a shared
 * screen at a distance, so its type stays monospaced and never relies on colour
 * alone to carry meaning — the tool name is always spelled out. And the palette
 * holds exactly three semantic colours: accent for recorded evidence, ochre for
 * a warning, brick for a refusal. Everything else is ink. A trace that lights
 * up in seven hues reads as decoration; this one reads as state.
 */

:root {
  --paper:       #EEF0F2;
  --raised:      #FAFBFC;
  --sunk:        #E7EAED;
  --ink:         #16202B;
  --ink-soft:    #4A5A6A;
  --ink-faint:   #5F6B75;
  --rule:        #CBD3DA;
  --rule-strong: #A9B5BF;

  --accent:      #2E6B5E;
  --accent-wash: #DEEAE6;
  --warn:        #7E5B13;
  --warn-wash:   #F1E8D6;
  --bad:         #9B3A2E;
  --bad-wash:    #F3E1DD;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;

  --r: 3px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:       #10161C;
    --raised:      #182029;
    --sunk:        #0B1116;
    --ink:         #E3EAF0;
    --ink-soft:    #9DACBA;
    --ink-faint:   #71808E;
    --rule:        #2A3742;
    --rule-strong: #3D4C59;

    --accent:      #6FBFA9;
    --accent-wash: #17302B;
    --warn:        #D2A24C;
    --warn-wash:   #322715;
    --bad:         #D9836F;
    --bad-wash:    #331D18;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ── Gate ─────────────────────────────────────────────────────────────── */
#gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--paper);
  z-index: 50;
  padding: 24px;
}
#gate .card {
  width: min(400px, 100%);
  padding: 40px 36px;
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  text-align: left;
}
#gate h1 {
  font-family: var(--serif);
  font-size: 25px;
  line-height: 1.15;
  letter-spacing: -0.015em;
  margin: 0 0 10px;
  font-weight: 600;
}
#gate p { color: var(--ink-soft); font-size: 14px; margin: 0 0 24px; }
#gate input {
  width: 100%;
  padding: 11px 13px;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.14em;
}
#gate input:focus { outline: none; border-color: var(--accent); }
#gate button {
  width: 100%;
  margin-top: 10px;
  padding: 11px;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--r);
  color: var(--raised);
  font-weight: 600;
  font-size: 15px;
}
#gate button:hover { filter: brightness(1.08); }
#gate .err { color: var(--bad); font-size: 13px; min-height: 19px; margin-top: 10px; }

/* ── Shell ────────────────────────────────────────────────────────────── */
/* Flex column rather than fixed grid rows: the replay bar appears and
   disappears, and a row template would reassign the flexible row to whichever
   child happened to land in it. */
#shell { display: none; flex-direction: column; height: 100%; }
#shell.on { display: flex; }
#shell > main { flex: 1; min-height: 0; }

header {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 13px 22px;
  border-bottom: 1px solid var(--rule);
  background: var(--raised);
}
header .brand {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.012em;
}
header .brand span { color: var(--accent); font-family: var(--sans); }
header .sub {
  font-family: var(--mono);
  color: var(--ink-faint);
  font-size: 11.5px;
  letter-spacing: 0.04em;
}
header .spacer { flex: 1; }

.modes { display: flex; gap: 2px; }
.modes button {
  padding: 5px 11px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  color: var(--ink-faint);
  font-size: 13px;
  transition: color 120ms ease, border-color 120ms ease;
}
.modes button:hover { color: var(--ink); }
.modes button.on {
  color: var(--accent);
  border-color: var(--rule-strong);
  background: var(--paper);
}

.linkbtn {
  background: none;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r);
  color: var(--ink-soft);
  padding: 5px 11px;
  font-size: 13px;
}
.linkbtn:hover { color: var(--ink); border-color: var(--ink-faint); }

/* ── Replay bar ───────────────────────────────────────────────────────── */
/* Only visible while reading a stored run, so it must not be mistakable for a
   live one: ochre, the same colour the trace uses for "attention required". */
#replay-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 9px 22px;
  background: var(--warn-wash);
  border-bottom: 1px solid var(--warn);
  color: var(--warn);
  font-family: var(--mono);
  font-size: 12px;
}
#replay-bar[hidden] { display: none; }
#replay-bar .linkbtn { border-color: var(--warn); color: var(--warn); margin-left: auto; }
#replay-bar .linkbtn:hover { background: var(--raised); }

/* ── History list ─────────────────────────────────────────────────────── */
.runrow {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  margin-bottom: 7px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--rule-strong);
  border-radius: var(--r);
  transition: border-color 120ms ease;
}
.runrow:hover { border-left-color: var(--accent); border-color: var(--rule-strong); }
.runrow .q { font-size: 14.5px; color: var(--ink); line-height: 1.4; }
.runrow .ex {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.runrow .sep { color: var(--rule-strong); }
.runrow .badrow { color: var(--bad); }
.runrow .warnrow { color: var(--warn); }

/* ── Columns ──────────────────────────────────────────────────────────── */
main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.8fr);
  min-height: 0;
}
#chat, #trace { overflow-y: auto; min-height: 0; }
#chat { padding: 30px 26px 40px; }
#trace {
  border-left: 1px solid var(--rule);
  background: var(--sunk);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.62;
  padding: 22px 20px 40px;
}

/* ── Chat ─────────────────────────────────────────────────────────────── */
.msg { margin-bottom: 30px; max-width: 66ch; }
.msg.user {
  margin-left: auto;
  background: var(--raised);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--accent);
  border-radius: var(--r);
  padding: 13px 17px;
  max-width: 54ch;
}
.msg.agent { max-width: 70ch; }
.msg .who {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--ink-faint);
  margin-bottom: 10px;
}

.answer h1, .answer h2 {
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.012em;
  margin: 28px 0 10px;
  text-wrap: balance;
}
.answer h1:first-child, .answer h2:first-child { margin-top: 0; }
.answer h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  color: var(--ink-faint);
  margin: 24px 0 8px;
}
.answer p { margin: 0 0 13px; }
.answer > p:last-child { margin-bottom: 0; }
.answer ul, .answer ol { margin: 0 0 13px; padding-left: 20px; }
.answer li { margin-bottom: 6px; }
.answer li::marker { color: var(--ink-faint); }
.answer strong { font-weight: 650; }
.answer a { color: var(--accent); text-underline-offset: 2px; }
.answer code {
  background: var(--sunk);
  border: 1px solid var(--rule);
  padding: 0.5px 5px;
  border-radius: var(--r);
  font-family: var(--mono);
  font-size: 0.87em;
}
.answer blockquote {
  margin: 0 0 13px;
  padding-left: 14px;
  border-left: 2px solid var(--rule-strong);
  color: var(--ink-soft);
}
.answer table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 16px;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
  font-variant-numeric: tabular-nums;
}
.answer th, .answer td {
  border-bottom: 1px solid var(--rule);
  padding: 8px 14px 8px 0;
  text-align: left;
  vertical-align: top;
}
.answer th {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-faint);
  border-bottom-color: var(--rule-strong);
}
.answer hr { border: 0; border-top: 1px solid var(--rule); margin: 22px 0; }
.answer .sub { color: var(--ink-faint); font-size: 14px; }

/* Source chips and confidence flags — the atom of the trust model. */
.chip {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  padding: 0.5px 6px;
  border-radius: var(--r);
  border: 1px solid var(--rule-strong);
  background: var(--raised);
  color: var(--ink-soft);
  white-space: nowrap;
  vertical-align: baseline;
}
.chip.t1 { border-color: var(--accent); color: var(--accent); }
.chip.t2 { border-color: var(--rule-strong); color: var(--ink-soft); }
.chip.t3 { border-color: var(--rule); color: var(--ink-faint); }

.flag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.5px 6px;
  border-radius: var(--r);
  vertical-align: baseline;
}
.flag.warn { background: var(--warn-wash); color: var(--warn); border: 1px solid var(--warn); }
.flag.bad  { background: var(--bad-wash);  color: var(--bad);  border: 1px solid var(--bad); }

.conf {
  margin-top: 22px;
  padding-top: 15px;
  border-top: 1px solid var(--rule);
  font-size: 14px;
  color: var(--ink-soft);
}
.conf .k {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--ink-faint);
}

.clarify {
  border: 1px solid var(--warn);
  background: var(--warn-wash);
  border-radius: var(--r);
  padding: 15px 17px;
}
.clarify .q { font-weight: 650; margin-bottom: 6px; }
.clarify .why { color: var(--ink-soft); font-size: 14px; margin-bottom: 12px; }
.clarify button {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 6px;
  padding: 9px 12px;
  background: var(--raised);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r);
  font-size: 14px;
}
.clarify button:hover { border-color: var(--accent); color: var(--accent); }

.errbox {
  border: 1px solid var(--bad);
  background: var(--bad-wash);
  color: var(--bad);
  border-radius: var(--r);
  padding: 12px 15px;
}

/* ── Trace ────────────────────────────────────────────────────────────── */
.trace-title {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
}
.step {
  margin-bottom: 2px;
  padding-left: 20px;
  text-indent: -20px;
  word-break: break-word;
  color: var(--ink-soft);
}
/* State, not category: the tool name already says which tool ran, so colour is
   reserved for whether the step produced evidence, a warning, or a refusal. */
.step .lead { color: var(--ink); font-weight: 600; }
.step.record .lead { color: var(--accent); }
.step.answer .lead { color: var(--accent); }
.step.cover  .lead { color: var(--warn); }
.step.fail   .lead { color: var(--bad); }
.step .meta { color: var(--ink-faint); }
.step .warnrow { color: var(--warn); }
.step .badrow  { color: var(--bad); }
.step.sub {
  padding-left: 20px;
  text-indent: 0;
  margin-left: 18px;
  border-left: 1px solid var(--rule);
  color: var(--ink-faint);
  font-size: 12.5px;
}

.thinking {
  color: var(--ink-faint);
  font-style: italic;
  font-size: 12.5px;
  margin: 8px 0 12px 20px;
  padding-left: 12px;
  border-left: 1px solid var(--rule);
  white-space: pre-wrap;
}
.spinner::after { content: ""; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* ── Footer ───────────────────────────────────────────────────────────── */
footer {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
  padding: 10px 22px;
  border-top: 1px solid var(--rule);
  background: var(--raised);
  font-family: var(--mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-faint);
}
footer .sep { color: var(--rule-strong); }
footer strong { color: var(--ink); font-weight: 600; }

/* ── Composer ─────────────────────────────────────────────────────────── */
#composer {
  padding: 16px 22px 18px;
  border-top: 1px solid var(--rule);
  background: var(--raised);
}
#composer .row { display: flex; gap: 9px; }
#composer textarea {
  flex: 1;
  resize: none;
  min-height: 46px;
  max-height: 160px;
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r);
  color: var(--ink);
  font: inherit;
  line-height: 1.5;
}
#composer textarea::placeholder { color: var(--ink-faint); }
#composer textarea:focus { outline: none; border-color: var(--accent); }
#composer button.send {
  padding: 0 22px;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--r);
  color: var(--raised);
  font-weight: 600;
}
#composer button.send:hover:not(:disabled) { filter: brightness(1.08); }
#composer button.send:disabled { opacity: 0.4; cursor: not-allowed; }

.examples { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 11px; }
.examples button {
  padding: 5px 11px;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  color: var(--ink-faint);
  font-size: 12.5px;
  text-align: left;
  transition: color 120ms ease, border-color 120ms ease;
}
.examples button:hover { color: var(--accent); border-color: var(--accent); }

/* ── Modal ────────────────────────────────────────────────────────────── */
#modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: color-mix(in srgb, var(--ink) 55%, transparent);
  z-index: 40;
  padding: 24px;
}
#modal.on { display: grid; }
#modal .card {
  width: min(760px, 100%);
  max-height: 84vh;
  overflow-y: auto;
  background: var(--raised);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r);
  padding: 28px 30px;
}
#modal h2 {
  font-family: var(--serif);
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.012em;
}
#modal h3 {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  margin: 26px 0 10px;
  font-weight: 500;
}
#modal ul { margin: 0; padding-left: 20px; font-size: 14.5px; color: var(--ink-soft); }
#modal li { margin-bottom: 6px; }
#modal li::marker { color: var(--ink-faint); }
#modal .close { float: right; }
#modal .tier {
  border: 1px solid var(--rule);
  border-left: 2px solid var(--accent);
  border-radius: var(--r);
  padding: 11px 14px;
  margin-bottom: 8px;
}
#modal .tier .name { font-weight: 650; margin-bottom: 3px; }
#modal .tier .ex {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-faint);
  word-break: break-word;
}

@media (max-width: 900px) {
  main { grid-template-columns: minmax(0, 1fr); grid-template-rows: 1fr 1fr; }
  #trace { border-left: 0; border-top: 1px solid var(--rule); }
  .msg.user, .msg.agent { max-width: 100%; }
  header { gap: 10px; padding: 11px 16px; }
  #chat { padding: 22px 16px 30px; }
  #composer { padding: 13px 16px 15px; }
  footer { padding: 9px 16px; }
}
