/*
 * Savant panel.
 *
 * Deliberately hand-written CSS with no build step: the panel is a handful of screens, and a
 * bundler would be more machinery than the UI is worth at this stage.
 */

:root {
  --paper: #f4f6f5;
  --surface: #ffffff;
  --surface-sunk: #eaeeec;
  --ink: #14201f;
  --ink-soft: #4a5c5a;
  --ink-faint: #7b8b89;
  --rule: #d3dbd9;
  --rule-soft: #e3e9e7;
  --accent: #0d6d68;
  --accent-deep: #084b47;
  --accent-wash: #e2efed;
  --signal: #a2610a;
  --signal-wash: #f6ecdc;
  --stop: #a3352c;
  --stop-wash: #f8e9e7;

  --f-text: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --f-mono: ui-monospace, 'JetBrains Mono', 'SF Mono', 'Cascadia Mono', Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0d1413;
    --surface: #141d1c;
    --surface-sunk: #101817;
    --ink: #e4ebe9;
    --ink-soft: #a2b2af;
    --ink-faint: #6f807d;
    --rule: #26332f;
    --rule-soft: #1d2827;
    --accent: #4fbdb3;
    --accent-deep: #7fd4cb;
    --accent-wash: #122a28;
    --signal: #d99a3e;
    --signal-wash: #2a2116;
    --stop: #e0776c;
    --stop-wash: #2a1a18;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-text);
  font-size: 15.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.boot {
  padding: 4rem;
  color: var(--ink-faint);
  text-align: center;
}

/* --- chrome --------------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--ink) 40%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1.5rem;
}

.overlay .card {
  max-width: 24rem;
  width: 100%;
}

header.bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.4rem;
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 1.06rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.brand .sub {
  font-family: var(--f-mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 400;
}

.bar .spacer {
  flex: 1;
}

.bar nav {
  display: flex;
  gap: 0.35rem;
}

main {
  max-width: 62rem;
  margin: 0 auto;
  padding: 1.8rem 1.4rem 6rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

main.narrow {
  max-width: 30rem;
  padding-top: 4rem;
}

h1 {
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  margin: 0;
}
h2 {
  font-size: 1.1rem;
  margin: 0;
  letter-spacing: -0.01em;
}
p {
  margin: 0;
}

.muted {
  color: var(--ink-soft);
}
.faint {
  color: var(--ink-faint);
  font-size: 0.88rem;
}

/* --- controls ------------------------------------------------------------- */

button,
.btn {
  font: inherit;
  font-size: 0.92rem;
  padding: 0.42rem 0.85rem;
  border-radius: 5px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
button:hover,
.btn:hover {
  border-color: var(--ink-faint);
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
button.primary,
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}
button.danger {
  color: var(--stop);
  border-color: var(--rule);
}
button.ghost {
  border-color: transparent;
  background: transparent;
}
button.ghost:hover {
  background: var(--surface-sunk);
  border-color: transparent;
}
button.ghost.active {
  background: var(--accent-wash);
  color: var(--accent-deep);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

input,
textarea,
select {
  font: inherit;
  font-size: 0.95rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}
textarea {
  resize: vertical;
  min-height: 5.5rem;
  line-height: 1.55;
}
input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  outline: none;
}

/* --- panels --------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 7px;
  padding: 1.2rem 1.3rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.notice {
  border-left: 3px solid var(--accent);
  background: var(--accent-wash);
  padding: 0.85rem 1.1rem;
  border-radius: 0 5px 5px 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.notice.warn {
  border-left-color: var(--signal);
  background: var(--signal-wash);
}
.notice.error {
  border-left-color: var(--stop);
  background: var(--stop-wash);
}
.notice .label {
  font-family: var(--f-mono);
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-deep);
}
.notice.warn .label {
  color: var(--signal);
}
.notice.error .label {
  color: var(--stop);
}

.pill {
  font-family: var(--f-mono);
  font-size: 0.72rem;
  padding: 0.1rem 0.42rem;
  border-radius: 3px;
  background: var(--accent-wash);
  color: var(--accent-deep);
  white-space: nowrap;
}
.pill.none {
  background: var(--surface-sunk);
  color: var(--ink-faint);
}
.pill.warn {
  background: var(--signal-wash);
  color: var(--signal);
}
.pill.stop {
  background: var(--stop-wash);
  color: var(--stop);
}

.row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

/* --- ask ------------------------------------------------------------------ */

.thread {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.turn {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.turn .who {
  font-family: var(--f-mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.turn .body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  word-break: break-word;
}
/* Prose keeps the newlines the model wrote; a code block brings its own. */
.turn .body .prose {
  white-space: pre-wrap;
}

.code {
  margin: 0;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--surface-sunk);
  /* The border is the only thing separating a block from a `.you` bubble, which is the same
     colour underneath — so it must not be clipped away by the scrolling <pre> inside. */
  overflow: hidden;
}
.code figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.25rem 0.3rem 0.25rem 0.75rem;
  border-bottom: 1px solid var(--rule-soft);
  font-family: var(--f-mono);
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.code .copy {
  font-family: var(--f-mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  color: var(--ink-faint);
}
.code .copy:hover {
  color: var(--ink);
}
.code pre {
  margin: 0;
  padding: 0.75rem 0.85rem;
  overflow-x: auto;
}
.code pre code {
  /* A block is already sunk and bordered; the inline-span background would double it up. */
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 0.79rem;
  line-height: 1.55;
  /* No wrapping: a wrapped line of code reads as two lines of code. Scroll instead. */
  white-space: pre;
}
/* Still being written. The caption is the honest place for it — the code itself must not move. */
.code.open figcaption .lang::after {
  content: ' …';
}
.turn.you .body {
  background: var(--surface-sunk);
  border-radius: 6px;
  padding: 0.7rem 0.9rem;
}

.tools {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  align-items: center;
}
.tools .pill {
  background: var(--surface-sunk);
  color: var(--ink-soft);
}

.usage {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-family: var(--f-mono);
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
}

.working {
  color: var(--ink-faint);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.working::before {
  content: '';
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 0.25;
  }
  50% {
    opacity: 1;
  }
}
@media (prefers-reduced-motion: reduce) {
  .working::before {
    animation: none;
    opacity: 0.7;
  }
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  position: sticky;
  bottom: 0;
  background: var(--paper);
  padding-top: 0.6rem;
}

/* --- tables --------------------------------------------------------------- */

.scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 40rem;
}
th,
td {
  text-align: left;
  padding: 0.6rem 0.8rem 0.6rem 0;
  border-bottom: 1px solid var(--rule-soft);
  vertical-align: top;
}
thead th {
  font-family: var(--f-mono);
  font-size: 0.66rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
  border-bottom: 1px solid var(--rule);
}

.list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.list button {
  justify-content: flex-start;
  text-align: left;
  border-color: transparent;
  background: transparent;
  width: 100%;
}
.list button:hover {
  background: var(--surface-sunk);
}
.list button.active {
  background: var(--accent-wash);
  color: var(--accent-deep);
}

.split {
  display: grid;
  grid-template-columns: 15rem 1fr;
  gap: 1.6rem;
  align-items: start;
}
@media (max-width: 52rem) {
  .split {
    grid-template-columns: 1fr;
  }
  .split .aside {
    order: 2;
  }
}

code {
  font-family: var(--f-mono);
  font-size: 0.86em;
  background: var(--surface-sunk);
  padding: 0.08em 0.32em;
  border-radius: 3px;
}

/* --- conversation history ------------------------------------------------- */

.split {
  align-items: start;
  gap: 1.4rem;
  max-width: 74rem;
  margin: 0 auto;
  padding: 1.4rem;
}

.split .aside {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  position: sticky;
  top: 4.2rem;
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
}

.split main.pane {
  padding: 0;
  max-width: none;
  margin: 0;
}

/* Two lines per entry: the question, then when it was asked. */
.list .entry {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  width: 100%;
}

.entry-title {
  /* Titles are whole questions, so they must clip rather than wrap the sidebar wider. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}

.entry-when {
  font-family: var(--f-mono);
  font-size: 0.66rem;
  color: var(--ink-faint);
}

.snapshot-note {
  font-family: var(--f-mono);
  font-size: 0.68rem;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--rule-soft);
  padding-bottom: 0.6rem;
}

/* --- access tokens -------------------------------------------------------- */

.snippet {
  font-family: var(--f-mono);
  font-size: 0.78rem;
  background: var(--surface-sunk);
  border: 1px solid var(--rule-soft);
  border-radius: 5px;
  padding: 0.7rem 0.85rem;
  margin: 0;
  overflow-x: auto;
  color: var(--ink-soft);
}

code.token {
  font-family: var(--f-mono);
  font-size: 0.78rem;
  word-break: break-all;
  display: block;
  padding: 0.5rem 0.65rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
}

.token-row {
  justify-content: space-between;
  border-bottom: 1px solid var(--rule-soft);
  padding: 0.45rem 0;
}

/* --- audit ---------------------------------------------------------------- */

td.nowrap {
  white-space: nowrap;
}

td.detail {
  color: var(--ink-soft);
  font-size: 0.86rem;
  word-break: break-word;
  max-width: 34rem;
}

.bar nav + .row h1,
main > .row > h1 {
  font-size: 1.5rem;
  margin-right: 0.6rem;
}

/* --- question digest ------------------------------------------------------ */

/* The digest is rendered as the same fixed-width text the weekly email sends, so its histogram
   bars line up. Scrolls on its own rather than widening the page on a narrow screen. */
pre.digest {
  font-family: var(--f-mono);
  font-size: 0.82rem;
  line-height: 1.5;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  white-space: pre;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--ink);
}
