:root {
  /* Paper & ink — a lab-notebook / spec-sheet palette, not the usual dark console */
  --paper: #f3f1ea;        /* page background — warm, slightly grey-green off-white */
  --paper-2: #eae7dc;      /* recessed areas on the paper */
  --card: #fffdf9;         /* raised surfaces — bubbles, panels */
  --line: #ddd7c6;         /* hairline borders */
  --line-bright: #c9c0a8;
  --ink: #1f261f;          /* primary text — deep bottle-ink green-black */
  --muted: #6b6f5e;        /* secondary text */
  --accent: #0f6f62;       /* deep teal — "shortlist / confirmed" */
  --accent-2: #b9791f;     /* ochre/amber — "clarify / needs input" */
  --accent-3: #b23a4e;     /* brick rose — reserved for off-topic/errors */
  /* test_type readout colors — each SHL category gets its own "channel" */
  --tt-a: #2f7cb8;
  --tt-b: #8a5aa8;
  --tt-c: #0f6f62;
  --tt-d: #4c8a3f;
  --tt-e: #b9791f;
  --tt-k: #a68a1f;
  --tt-p: #b23a4e;
  --tt-s: #5b63a8;
  --radius: 16px;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --display: 'Fraunces', Georgia, serif;
  --body: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
}

/* subtle paper texture instead of dark grain */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle at 1px 1px, rgba(31,38,31,0.05) 1px, transparent 0);
  background-size: 22px 22px;
  z-index: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: relative;
  z-index: 2;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 0.2px;
  color: var(--ink);
}
.brand-sub {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.03em;
  color: var(--muted);
  text-transform: uppercase;
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px 6px 10px;
  background: var(--paper-2);
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 0 rgba(0,0,0,0);
  transition: background 0.2s;
}
.status-dot.ok { background: var(--accent); box-shadow: 0 0 8px 0 color-mix(in srgb, var(--accent) 60%, transparent); }
.status-dot.down { background: var(--accent-3); box-shadow: 0 0 8px 0 color-mix(in srgb, var(--accent-3) 60%, transparent); }

.config-panel {
  position: relative;
  z-index: 2;
  background: var(--paper-2);
  border-bottom: 1px solid var(--line);
  padding: 16px 32px;
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}
.config-panel label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex: 1;
  min-width: 260px;
}
.config-panel input {
  font-family: var(--body);
  font-size: 13.5px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 8px;
  text-transform: none;
  letter-spacing: normal;
}
.config-panel input:focus {
  outline: none;
  border-color: var(--accent);
}
.config-hint {
  width: 100%;
  margin: 0;
  font-size: 11.5px;
  color: var(--muted);
}
.config-hint-inline {
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  color: var(--muted);
  font-size: 10.5px;
}
.config-hint code {
  color: var(--accent-2);
  background: color-mix(in srgb, var(--accent-2) 12%, transparent);
  padding: 1px 5px;
  border-radius: 4px;
}

.primary-btn {
  background: var(--accent);
  color: #f4f1e6;
  border: none;
  font-weight: 600;
  font-size: 13px;
  padding: 11px 18px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s, transform 0.1s;
}
.primary-btn:hover { filter: brightness(1.12); }
.primary-btn:active { transform: scale(0.98); }

/* ============ Roomier chat shell ============ */
.chat-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  margin: 0;
  padding: 0;
  position: relative;
  z-index: 1;
  min-height: 0;
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 36px clamp(18px, 6vw, 96px) 28px;
  background: var(--paper);
  /* faint calibration ruler along the top edge — a nod to the fact that
     what's being recommended here are measurement instruments */
  background-image:
    repeating-linear-gradient(
      to right,
      var(--line) 0, var(--line) 1px,
      transparent 1px, transparent 28px
    );
  background-size: 100% 6px;
  background-position: top left;
  background-repeat: no-repeat;
}

.msg { display: flex; width: 100%; max-width: 760px; animation: rise 0.28s ease both; }
.msg-user { justify-content: flex-end; }
.msg-assistant, .msg-system { justify-content: flex-start; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-bubble {
  max-width: 92%;
  padding: 15px 18px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
}
.msg-user .msg-bubble {
  background: var(--accent);
  color: #f4f1e6;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 16px -8px color-mix(in srgb, var(--accent) 55%, transparent);
}
.msg-assistant .msg-bubble, .msg-system .msg-bubble {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-bright);
  border-bottom-left-radius: 4px;
  color: var(--ink);
}
.msg-system .msg-bubble {
  border-left-color: var(--accent-2);
  font-size: 14px;
  color: var(--muted);
  background: color-mix(in srgb, var(--accent-2) 6%, var(--paper-2));
}
.msg-bubble p { margin: 0; }
.msg-bubble p + p { margin-top: 8px; }

/* Rendered markdown from LLM replies (see script.js's renderReplyHtml) */
.markdown-body ul, .markdown-body ol {
  margin: 8px 0 0;
  padding-left: 20px;
}
.markdown-body li { margin: 4px 0; line-height: 1.55; }
.markdown-body li + li { margin-top: 6px; }
.markdown-body strong {
  color: var(--accent);
  font-weight: 600;
}
.msg-user .markdown-body strong { color: inherit; }
.markdown-body code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--paper-2);
  padding: 1px 5px;
  border-radius: 4px;
}
.markdown-body h1, .markdown-body h2, .markdown-body h3 {
  font-family: var(--display);
  font-size: 15px;
  margin: 10px 0 4px;
}
.markdown-body > *:first-child { margin-top: 0; }

.rec-list {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.rec-card {
  position: relative;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 13px 14px 13px 16px;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
/* the "readout channel" — a thin colored strip keyed to test_type,
   like a signal trace on an instrument panel */
.rec-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--rec-color, var(--muted));
}
.rec-card:hover {
  border-color: var(--line-bright);
  transform: translateX(2px);
  box-shadow: 0 4px 14px -10px rgba(31,38,31,0.25);
}
.rec-card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.rec-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.1px;
}
.rec-name a { color: var(--ink); text-decoration: none; border-bottom: 1px dotted var(--muted); }
.rec-name a:hover { border-bottom-color: var(--rec-color, var(--accent)); color: var(--rec-color, var(--accent)); }
.rec-type {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--rec-color, var(--muted));
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  flex-shrink: 0;
}
.rec-type::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--rec-color, var(--muted));
  box-shadow: 0 0 6px 0 var(--rec-color, transparent);
}
.rec-desc {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
}

.msg-error .msg-bubble {
  border-color: color-mix(in srgb, var(--accent-3) 45%, var(--line));
  background: color-mix(in srgb, var(--accent-3) 8%, var(--paper-2));
  color: var(--accent-3);
}

.typing-bubble .msg-bubble { display: flex; gap: 5px; align-items: center; padding: 16px 18px; }
.typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  animation: pulse 1.1s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 60%, 100% { opacity: 0.3; transform: scale(0.85); } 30% { opacity: 1; transform: scale(1); } }

.composer-dock {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 14px clamp(18px, 6vw, 96px) 18px;
}

.quick-row {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 0 12px;
}
.quick-chip {
  font-family: var(--body);
  font-size: 12.5px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.quick-chip:hover { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--card)); }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 10px 10px 20px;
  box-shadow: 0 1px 2px rgba(31,38,31,0.04), 0 8px 22px -16px rgba(31,38,31,0.18);
  transition: border-color 0.15s, background 0.15s;
}
.composer textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.55;
  max-height: 140px;
  padding: 10px 0;
}
.composer textarea::placeholder { color: var(--muted); }

.send-btn {
  flex-shrink: 0;
  width: 42px; height: 42px;
  border-radius: 11px;
  border: none;
  background: var(--accent);
  color: #f4f1e6;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.15s, transform 0.1s;
}
.send-btn:hover { filter: brightness(1.1); }
.send-btn:active { transform: scale(0.94); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.composer-hint {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  margin: 8px 0 0;
  font-family: var(--mono);
  letter-spacing: 0.02em;
}

/* Keyboard focus visibility — required floor, not optional polish */
a:focus-visible,
button:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.composer:focus-within {
  border-color: var(--accent);
  background: var(--card);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent), 0 8px 22px -16px rgba(31,38,31,0.18);
}

/* Scrollbar tuned to the paper palette */
.chat-log::-webkit-scrollbar { width: 10px; }
.chat-log::-webkit-scrollbar-track { background: transparent; }
.chat-log::-webkit-scrollbar-thumb {
  background: var(--line-bright);
  border-radius: 999px;
  border: 2px solid var(--card);
}

@media (prefers-reduced-motion: reduce) {
  .typing-dot { animation: none; }
  .msg { animation: none; }
}

@media (max-width: 560px) {
  .topbar { padding: 14px 18px; }
  .chat-log { padding: 20px 14px 20px; gap: 16px; }
  .composer-dock { padding: 12px 14px 14px; }
  .brand-sub { display: none; }
  .msg-bubble { max-width: 92%; }
}