:root {
  --paper: #f2f3f7;
  --card: #ffffff;
  --ink: #1b2141;
  --ink-soft: #5a607d;
  --line: #dfe2ec;
  --pen: #2b3bbf;
  --pen-deep: #202d93;
  --pen-tint: #eef0fe;
  --mark: #ffe066;
  --stamp: #b3372b;
  --stamp-bg: #fbefed;
  --note-bg: #fff7db;
  --note-text: #6b5300;
  --radius: 10px;
  --font-display: "Zilla Slab", Georgia, serif;
  --font-body: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 2rem; line-height: 1.15; margin: 0 0 0.75rem; }
h2 { font-size: 1.35rem; line-height: 1.25; margin: 0 0 0.75rem; }
h3 { font-size: 1.05rem; margin: 0 0 0.5rem; }
p { margin: 0 0 0.75rem; }

a { color: var(--pen); }
a:hover { color: var(--pen-deep); }

.mk {
  background: var(--mark);
  padding: 0 0.14em;
  border-radius: 3px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* Top bar */
.top {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.wordmark {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.2rem;
  color: var(--ink);
  text-decoration: none;
}
.wordmark:hover { color: var(--ink); }
.top nav { display: flex; gap: 1.25rem; align-items: center; }

main { max-width: 72rem; margin: 0 auto; padding: 1.5rem 1.5rem 5rem; }
main.narrow { max-width: 26rem; padding-top: 2.5rem; }

.sub { color: var(--ink-soft); max-width: 34rem; }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 1rem;
}

/* Hero */
.hero {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 3.5rem;
  align-items: center;
  padding: 2.5rem 0 3.5rem;
}
.hero h1 { font-size: clamp(2.1rem, 4.5vw, 3.1rem); }
.hero .actions { display: flex; gap: 1rem; align-items: center; margin-top: 1.75rem; }

/* Demo card */
.demo {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: 0 8px 24px rgba(27, 33, 65, 0.07);
}
.demo-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
}
.demo .thread { display: flex; flex-direction: column; gap: 0.7rem; }
.demo .slot { visibility: hidden; }

/* Bubbles (demo + chat) */
.bubble {
  max-width: 88%;
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.bubble::before {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.8rem;
  margin-right: 0.5rem;
}
.bubble.user {
  align-self: flex-end;
  background: var(--ink);
  color: #f5f6fb;
  border-bottom-right-radius: 4px;
}
.bubble.user::before { content: "Q."; color: var(--mark); }
.bubble.assistant {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  white-space: normal;
}
.bubble.assistant > *:first-child { display: inline; }
.bubble.assistant p { margin: 0 0 0.5rem; }
.bubble.assistant > *:last-child { margin-bottom: 0; }
.bubble.assistant ul, .bubble.assistant ol { margin: 0.25rem 0 0.5rem; padding-left: 1.25rem; }
.bubble.assistant li { margin: 0.15rem 0; }
.bubble.assistant code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--paper);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.bubble.assistant pre {
  background: var(--paper);
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.25rem 0 0.5rem;
}
.bubble.assistant pre code { background: none; padding: 0; }
.bubble.assistant h1, .bubble.assistant h2, .bubble.assistant h3 {
  font-size: 1rem;
  margin: 0.5rem 0 0.25rem;
}
.bubble.assistant table { border-collapse: collapse; margin: 0.25rem 0 0.5rem; font-size: 0.9em; }
.bubble.assistant th, .bubble.assistant td { border: 1px solid var(--line); padding: 0.3rem 0.6rem; text-align: left; }
.bubble.assistant::before { content: "A."; color: var(--pen); }
.demo .bubble.assistant { background: var(--paper); border: none; }
.bubble.error { background: var(--stamp-bg); color: var(--stamp); border: none; }
.bubble.error::before { content: none; }

.chip {
  align-self: flex-start;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: var(--pen-tint);
  color: var(--pen-deep);
}
.chip.escalated { background: var(--mark); color: var(--ink); }

.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing i {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--ink-soft);
  animation: blink 1s infinite both;
}
.typing i:nth-child(2) { animation-delay: 0.18s; }
.typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.rise { animation: rise 240ms ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .rise { animation: none; }
  .typing i { animation: none; opacity: 0.6; }
}

/* Sections */
.section { padding: 2.5rem 0; border-top: 1px solid var(--line); }
ol.steps {
  list-style: none;
  counter-reset: step;
  padding: 0;
  margin: 1.5rem 0 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2rem;
}
ol.steps li { counter-increment: step; }
ol.steps li::before {
  content: counter(step);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.6rem;
  color: var(--pen);
  display: block;
  margin-bottom: 0.25rem;
}
ol.steps b { display: block; margin-bottom: 0.25rem; font-weight: 600; }
ol.steps li p { color: var(--ink-soft); font-size: 0.95rem; margin: 0; }

.honesty {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 2rem;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2rem;
  align-items: center;
}
.honesty .big { font-family: var(--font-display); font-weight: 600; font-size: 2rem; white-space: nowrap; }
.honesty p { margin: 0; color: var(--ink-soft); max-width: 40rem; }

footer.site {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.5rem;
  color: var(--ink-soft);
  font-size: 0.8rem;
  border-top: 1px solid var(--line);
}

/* Forms */
form.stack, main.narrow form { display: flex; flex-direction: column; gap: 1rem; margin: 1.25rem 0 0; }
label { display: flex; flex-direction: column; gap: 0.375rem; font-weight: 500; font-size: 0.9rem; }
input, textarea {
  font: inherit;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
}
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--pen);
  outline-offset: 2px;
}
button, a.button {
  font: inherit;
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  background: var(--pen);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  align-self: flex-start;
  transition: background-color 150ms ease;
}
button:hover, a.button:hover { background: var(--pen-deep); color: #fff; }
button:disabled { background: var(--line); color: var(--ink-soft); cursor: default; }
button.link {
  background: none;
  color: var(--pen);
  padding: 0;
  font-weight: 500;
  text-decoration: underline;
}
button.link:hover { color: var(--pen-deep); background: none; }

/* Messages */
.notice { background: var(--note-bg); color: var(--note-text); padding: 0.75rem 1rem; border-radius: var(--radius); margin: 1rem 0; }
.error { background: var(--stamp-bg); color: var(--stamp); padding: 0.75rem 1rem; border-radius: var(--radius); margin: 1rem 0; }

/* Dashboard */
.bar { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.5rem;
  margin-top: 1.5rem;
}
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.mono { font-family: var(--font-mono); font-size: 0.85rem; }
.gauge { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 0.5rem 0 0.25rem; }
.gauge-fill { height: 100%; background: var(--pen); }
.meter { color: var(--ink-soft); font-family: var(--font-mono); font-size: 0.8rem; }
ul.docs { list-style: none; padding: 0; margin: 0.5rem 0 0; }
ul.docs li {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--line);
}
ul.docs li > :first-child { flex: 1; min-width: 0; }
ul.docs li > .docmeta { white-space: nowrap; }
ul.docs li:last-child { border-bottom: none; }
ul.docs .docmeta { font-family: var(--font-mono); font-size: 0.78rem; color: var(--ink-soft); }
ul.docs button.link { color: var(--ink-soft); }
ul.docs button.link:hover { color: var(--stamp); }

/* Chat page */
.chat-page {
  max-width: 44rem;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 4.2rem);
  height: calc(100dvh - 4.2rem);
  padding-bottom: 1.25rem;
}
.chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* The stream rewrites the last bubble on every chunk; native scroll anchoring
     latches onto the replaced node and makes the view jump. We pin manually. */
  overflow-anchor: none;
  scrollbar-gutter: stable;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.5rem 0;
}
.chat-empty { color: var(--ink-soft); }
.chat-input { display: flex; gap: 0.6rem; align-items: flex-end; }
.chat-input textarea {
  flex: 1;
  resize: none;
  max-height: 160px;
  line-height: 1.45;
}
.privacy { color: var(--ink-soft); font-size: 0.78rem; margin-top: 1rem; }

@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; gap: 2rem; padding: 1rem 0 2.5rem; }
  ol.steps { grid-template-columns: 1fr; gap: 1.5rem; }
  .honesty { grid-template-columns: 1fr; gap: 1rem; }
  .honesty .big { white-space: normal; }
  .panel-grid { grid-template-columns: 1fr; }
}

/* Admin */
table.data { border-collapse: collapse; width: 100%; margin-top: 0.75rem; }
table.data th, table.data td { border-bottom: 1px solid var(--line); padding: 0.45rem 0.75rem 0.45rem 0; text-align: left; font-size: 0.9rem; }
table.data th { color: var(--ink-soft); font-weight: 500; }
table.data .num { text-align: right; font-family: var(--font-mono); font-size: 0.82rem; }
table.data th.num { font-family: var(--font-body); font-size: 0.9rem; }
