/* =============================================================================
   chatMCD — DIFFRACTION
   -----------------------------------------------------------------------------
   Direction chosen from the five-variant review (artifact "chatMCD Design
   Directions", 2026-09-07): a crystallography console. A faint diffraction-spot
   lattice fades out behind the conversation, cyan reads as instrument readout
   rather than startup gradient, and amber is the counter-accent.

   Light is the default. Dark is the original artifact palette, verbatim, reached
   through the header switch. Theme is resolved by a `data-theme` attribute on
   <html>; there is no prefers-color-scheme fallback, because "default light" is
   a deliberate decision rather than a system question.

   Chivo 900 display / IBM Plex Sans body / IBM Plex Mono labels.
   ========================================================================== */

/* ---------------------------------------------------------------- 1. TOKENS */

:root,
:root[data-theme="light"] {
  --bg:        #F1F4FA;
  --surf:      #FFFFFF;
  --surf-2:    #E8EDF6;
  --ink:       #0B0E17;   /* the dark theme's ground, used as light theme's ink */
  --ink-2:     #4B5670;
  --ink-3:     #78829A;
  --line:      #D8DFEC;
  --line-2:    #C3CCDE;
  --acc:       #0E7C86;   /* instrument cyan, darkened to 4.9:1 on white */
  --acc-hi:    #0A5C64;
  --acc-soft:  #DFF1F2;
  --acc2:      #B4650F;   /* amber, text-safe */
  --acc2-soft: #FAEBD8;
  --on-acc:    #FFFFFF;
  --danger:    #B3261E;

  --spot:      rgba(24, 54, 92, .22);
  --glow-1:    rgba(14, 124, 134, .07);
  --glow-2:    rgba(224, 138, 60, .07);
  --shadow:    0 1px 2px rgba(11, 14, 23, .06), 0 8px 24px rgba(11, 14, 23, .07);
  --shadow-sm: 0 1px 2px rgba(11, 14, 23, .07);
}

:root[data-theme="dark"] {
  --bg:        #0B0E17;
  --surf:      #151A28;
  --surf-2:    #1C2233;
  --ink:       #E7EAF2;
  --ink-2:     #8891A8;
  --ink-3:     #6E7789;
  --line:      #242C40;
  --line-2:    #333D57;
  --acc:       #4FD1D9;
  --acc-hi:    #7FE3E9;
  --acc-soft:  #12303A;
  --acc2:      #F0A05A;
  --acc2-soft: #33241A;
  --on-acc:    #08131A;
  --danger:    #F2726A;

  --spot:      rgba(180, 205, 225, .16);
  --glow-1:    rgba(79, 209, 217, .09);
  --glow-2:    rgba(240, 160, 90, .07);
  --shadow:    0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
}

:root {
  --font-display: "Chivo", ui-sans-serif, system-ui, sans-serif;
  --font-body:    "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --r-panel: 12px;
  --r-bub:   4px 14px 14px 14px;
  --r-bub-u: 14px 4px 14px 14px;
  --r-chip:  6px;
  --r-input: 10px;

  --hdr-h:  auto;
  --maxw:   1010px;
}

/* ------------------------------------------------------------ 2. RESET/BASE */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img, svg, canvas { max-width: 100%; }

a { color: var(--acc); }

button { font: inherit; }

:where(a, button, input, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--acc);
  outline-offset: 2px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* --------------------------------------------------------------- 3. SHELL */

.shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: var(--maxw);
  margin: 0 auto;
  background: var(--bg);
}

/* Full app gets a framed console; the widget fills its iframe edge to edge. */
body.is-app .shell {
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

@media (min-width: 1000px) {
  body.is-app { padding: 22px 0; background: var(--surf-2); }
  body.is-app .shell {
    height: calc(100dvh - 44px);
    border: 1px solid var(--line);
    border-radius: var(--r-panel);
    overflow: hidden;
    box-shadow: var(--shadow);
  }
}

/* -------------------------------------------------------------- 4. HEADER */

.hdr {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 18px;
  background: var(--surf);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 3;
  flex-wrap: wrap;
  row-gap: 8px;
}

.hdr-avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  background: var(--surf-2);
  border: 1px solid var(--line);
  object-fit: cover;
}

.hdr-id { min-width: 0; flex: 1 1 250px; }

/* The amber logo dot is the one fixed authorship mark across Marc's apps. Here
   it doubles as the beam stop at the centre of the diffraction pattern. */
.hdr-name {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 16px;
  letter-spacing: -.01em;
  line-height: 1.2;
  margin: 0;
  display: flex; align-items: center; gap: 8px;
}
.hdr-name a { color: inherit; text-decoration: none; }
.hdr-name a:hover { color: var(--acc); }

.logo-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--acc2);
  flex: none;
  box-shadow: 0 0 0 3px var(--acc2-soft);
}

.hdr-role {
  margin: 2px 0 0;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .02em;
  color: var(--ink-2);
}

.hdr-links {
  display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end;
  flex: 0 1 auto;
}

.hdr-link {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .04em;
  text-decoration: none;
  color: var(--ink-2);
  border: 1px solid var(--line);
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.hdr-link:hover { color: var(--acc); border-color: var(--acc); }
.hdr-link.primary { color: var(--acc); border-color: var(--acc); }
.hdr-link.primary:hover { background: var(--acc-soft); }

/* theme switch ------------------------------------------------------------ */

.theme-switch {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0;
  background: var(--surf-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px;
}
.theme-switch button {
  display: grid; place-items: center;
  width: 26px; height: 22px;
  border: 0; border-radius: 999px;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.theme-switch button:hover { color: var(--ink); }
.theme-switch button[aria-pressed="true"] {
  background: var(--surf);
  color: var(--acc);
  box-shadow: var(--shadow-sm);
}
.theme-switch svg { width: 14px; height: 14px; display: block; }

/* --------------------------------------------------- 5. THE DIFFRACTION FIELD */

.transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 20px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  background:
    radial-gradient(circle at 22% 18%, var(--glow-1), transparent 42%),
    radial-gradient(circle at 78% 72%, var(--glow-2), transparent 45%),
    var(--bg);
}

/* The spot lattice: a dot grid masked to fade out from the centre, so it reads
   as a diffraction pattern rather than as graph paper. Fixed to the viewport so
   the pattern stays put while the conversation scrolls over it. */
.transcript::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .72;
  background-image: radial-gradient(var(--spot) 1px, transparent 1.4px);
  background-size: 26px 26px;
  background-position: 6px 6px;
  -webkit-mask-image: radial-gradient(ellipse at 50% 45%, #000 8%, transparent 72%);
  mask-image: radial-gradient(ellipse at 50% 45%, #000 8%, transparent 72%);
}

.transcript > * { position: relative; z-index: 1; }

/* ------------------------------------------------------------ 6. MESSAGES */

.msg {
  max-width: 82%;
  font-size: 14.5px;
  line-height: 1.55;
  animation: rise .22s ease-out both;
}

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

.msg .who {
  display: block;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .13em;
  text-transform: uppercase;
  opacity: .62;
  margin-bottom: 4px;
}

.msg.bot {
  align-self: flex-start;
  background: var(--surf);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r-bub);
  padding: 11px 15px;
  box-shadow: var(--shadow-sm);
}

.msg.user {
  align-self: flex-end;
  background: var(--acc);
  color: var(--on-acc);
  border: 1px solid transparent;
  border-radius: var(--r-bub-u);
  padding: 11px 15px;
}
.msg.user .who { opacity: .75; }

.msg.error {
  align-self: flex-start;
  border-color: var(--danger);
  color: var(--danger);
  background: var(--surf);
}

/* markdown inside an answer ---------------------------------------------- */

.msg .md > :first-child { margin-top: 0; }
.msg .md > :last-child  { margin-bottom: 0; }
.msg .md p { margin: 0 0 .65em; }
.msg .md ul, .msg .md ol { margin: 0 0 .65em; padding-left: 1.25em; }
.msg .md li { margin: .15em 0; }
.msg .md strong { font-weight: 600; }
.msg .md em { font-style: italic; }
.msg .md a { color: var(--acc); text-underline-offset: 2px; }
.msg.user .md a { color: var(--on-acc); }
.msg .md code {
  font-family: var(--font-mono);
  font-size: .88em;
  background: var(--surf-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 4px;
}
.msg.user .md code { background: rgba(255, 255, 255, .18); border-color: transparent; }
.msg .md pre {
  font-family: var(--font-mono);
  font-size: .85em;
  background: var(--surf-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 0 0 .65em;
}
.msg .md pre code { background: none; border: 0; padding: 0; }

/* typing indicator -------------------------------------------------------- */

.typing { display: inline-flex; gap: 4px; align-items: center; height: 1.2em; }
.typing i {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--acc);
  animation: pulse 1.1s ease-in-out infinite;
}
.typing i:nth-child(2) { animation-delay: .16s; }
.typing i:nth-child(3) { animation-delay: .32s; }
@keyframes pulse { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* status pill (cold start / queue) ---------------------------------------- */

.status {
  align-self: center;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--acc2);
  background: var(--acc2-soft);
  border: 1px solid color-mix(in srgb, var(--acc2) 35%, transparent);
  border-radius: 999px;
  padding: 5px 13px;
  display: flex; align-items: center; gap: 8px;
}
.status::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--acc2);
  animation: pulse 1.4s ease-in-out infinite;
}

/* answer actions (copy / vote) -------------------------------------------- */

.actions {
  display: flex; gap: 4px; align-items: center;
  margin-top: 8px; padding-top: 7px;
  border-top: 1px solid var(--line);
}
.actions button {
  border: 0; background: transparent; cursor: pointer;
  color: var(--ink-3);
  padding: 3px 6px; border-radius: 5px; line-height: 1;
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: 10.5px;
  transition: color .15s, background .15s;
}
.actions button:hover { color: var(--ink); background: var(--surf-2); }
.actions button[aria-pressed="true"] { color: var(--acc); background: var(--acc-soft); }
.actions svg { width: 13px; height: 13px; }

/* ------------------------------------------------------------- 7. COMPOSER */

.composer {
  flex: none;
  padding: 12px 18px 14px;
  background: var(--bg);
  border-top: 1px solid var(--line);
  position: relative; z-index: 2;
}

.chips { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 10px; }

.chip {
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.35;
  cursor: pointer;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: var(--r-chip);
  transition: color .14s, border-color .14s, background .14s;
}
.chip:hover { color: var(--acc); border-color: var(--acc); background: var(--acc-soft); }
.chip[disabled] { opacity: .35; cursor: default; }

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surf);
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  padding: 8px 8px 8px 14px;
  transition: border-color .15s, box-shadow .15s;
}
.input-row:focus-within {
  border-color: var(--acc);
  box-shadow: 0 0 0 3px var(--acc-soft);
}

.input-row textarea {
  flex: 1;
  border: 0; outline: 0; resize: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.5;
  max-height: 140px;
  padding: 4px 0;
}
.input-row textarea::placeholder { color: var(--ink-3); }

.send {
  flex: none;
  width: 32px; height: 32px;
  border: 0; border-radius: 50%;
  background: var(--acc); color: var(--on-acc);
  display: grid; place-items: center;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.send:hover:not(:disabled) { background: var(--acc-hi); }
.send:active:not(:disabled) { transform: scale(.94); }
.send:disabled { opacity: .38; cursor: default; }
.send svg { width: 15px; height: 15px; }
.send.stop { background: var(--danger); }

.foot-note {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .07em;
  color: var(--ink-3);
  text-align: center;
  margin: 9px 0 0;
}
.foot-note a { color: var(--ink-2); text-decoration: none; }
.foot-note a:hover { color: var(--acc); text-decoration: underline; }

/* first-run hint ---------------------------------------------------------- */

.hint {
  align-self: center;
  max-width: 62ch;
  text-align: center;
  font-size: 12.5px;
  color: var(--ink-2);
  border: 1px dashed var(--line-2);
  border-radius: 10px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--surf) 70%, transparent);
}
.hint b { color: var(--ink); font-weight: 600; }

/* ------------------------------------------------------------- 8. WIDGET */

body.is-embed { background: var(--bg); }
body.is-embed .shell { height: 100dvh; border: 0; }
/* The widget header must stay on one row down to 320 px: the overflow menu and
   the theme switch sit together on the right, and the credential strip is the
   only thing allowed to shorten. */
body.is-embed .hdr { padding: 10px 12px; gap: 9px; flex-wrap: nowrap; row-gap: 0; }
body.is-embed .hdr-id { flex: 1 1 auto; min-width: 0; }
body.is-embed .hdr-role {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
body.is-embed .theme-switch { padding: 1px; }
body.is-embed .theme-switch button { width: 24px; height: 20px; }
body.is-embed .hdr-avatar { width: 32px; height: 32px; }
body.is-embed .hdr-name { font-size: 14px; }
body.is-embed .hdr-role { font-size: 10px; }
body.is-embed .transcript { padding: 14px 13px 8px; gap: 11px; }
body.is-embed .msg { font-size: 13.5px; max-width: 90%; }
body.is-embed .composer { padding: 10px 13px 12px; }
body.is-embed .chips { gap: 6px; margin-bottom: 9px; max-height: 62px; overflow: hidden; }
body.is-embed .chip { font-size: 10.5px; padding: 5px 10px; }
body.is-embed .input-row textarea { font-size: 13.5px; }
body.is-embed .foot-note { display: none; }
body.is-embed .hint { font-size: 11.5px; padding: 8px 12px; }

/* An overflow menu replaces the link row in the widget. */
.hdr-menu { position: relative; flex: none; }
.hdr-menu > button {
  border: 1px solid var(--line); background: var(--surf-2); color: var(--ink-2);
  border-radius: 6px; padding: 3px 8px; cursor: pointer; line-height: 1.2;
  font-size: 14px; letter-spacing: 1px;
}
.hdr-menu > button:hover { color: var(--acc); border-color: var(--acc); }
.hdr-menu ul {
  position: absolute; right: 0; top: calc(100% + 6px);
  margin: 0; padding: 5px; list-style: none;
  background: var(--surf); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); min-width: 168px; z-index: 10;
}
.hdr-menu li a {
  display: block; padding: 6px 10px; border-radius: 5px;
  font-family: var(--font-mono); font-size: 11px;
  color: var(--ink-2); text-decoration: none;
}
.hdr-menu li a:hover { background: var(--acc-soft); color: var(--acc); }

/* ---------------------------------------------------------- 9. RESPONSIVE */

@media (max-width: 620px) {
  .hdr { flex-wrap: wrap; padding: 11px 14px; }
  .hdr-links { width: 100%; justify-content: flex-start; order: 3; }
  .hdr-role { white-space: normal; }
  .transcript { padding: 16px 14px 8px; }
  .msg { max-width: 92%; }
  .composer { padding: 10px 14px 12px; }
}

/* 320 px is the floor the widget must survive in an Elementor column. */
@media (max-width: 360px) {
  .hdr-avatar { width: 28px; height: 28px; }
  .hdr-name { font-size: 13px; }
  .chip { font-size: 10px; padding: 4px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .composer, .hdr-links, .theme-switch, .actions, .hint { display: none !important; }
  .transcript::before { display: none; }
  body, .shell { height: auto; background: #fff; color: #000; }
  .msg { max-width: 100%; break-inside: avoid; }
}

/* -----------------------------------------------------------------------------
   DIRECTION: Diffraction (chosen 2026-09-07 from the five-variant review).
   Why: chatMCD's first job is to make a recruiter in biotech or pharma read
   "serious structural biologist" before a word of the transcript is parsed. The
   spot lattice and instrument cyan do that; the amber counter-accent and the
   beer-named tool in the transcript carry the personality. Light is default
   because the widget is embedded in marcdeller.com's light WordPress pages,
   where a dark panel reads as a hole cut in the page.
   Registry note: PANTS also uses a direction called Diffraction, on a dark
   lattice with blue/violet (#8fb4ff / #c48cff). This one is indigo ground with
   cyan/amber and ships light-first, so the two do not collide.
   -------------------------------------------------------------------------- */

/* Inline text button inside the footer note (chat export). */
.link-btn {
  border: 0; background: none; padding: 0; cursor: pointer;
  font: inherit; letter-spacing: inherit;
  color: var(--ink-2); text-decoration: none;
}
.link-btn:hover { color: var(--acc); text-decoration: underline; }

/* The lattice opacity above is tuned for the light ground. Dark needs less,
   because a pale dot on a dark ground already carries more contrast. */
:root[data-theme="dark"] .transcript::before { opacity: .55; }

/* ------------------------------------------------- 10. WIDGET PREVIEW PAGE */
/* /embed/preview only. Chrome headless clamps its viewport to 500 px, so the
   widget cannot be screenshotted honestly at 320-420 px except in an iframe —
   which is also exactly how it ships. */

body.is-preview { height: auto; padding: 0 0 60px; }
.preview-wrap { max-width: 1240px; margin: 0 auto; padding: 30px 22px; }
.preview-head h1 {
  font-family: var(--font-display); font-weight: 900; font-size: 26px;
  letter-spacing: -.02em; margin: 0 0 8px;
}
.preview-head p { color: var(--ink-2); max-width: 68ch; margin: 0 0 16px; }
.preview-head code {
  font-family: var(--font-mono); font-size: .88em;
  background: var(--surf-2); border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 5px;
}
.preview-controls label {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-3);
  display: inline-flex; align-items: center; gap: 9px;
}
.preview-controls select {
  font: inherit; font-size: 12px; text-transform: none; letter-spacing: 0;
  color: var(--ink); background: var(--surf);
  border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px;
}

.preview-row { display: flex; gap: 26px; flex-wrap: wrap; margin: 26px 0 0; }
.preview-cell { margin: 0; flex: 0 0 auto; width: var(--w); }
.preview-cell figcaption {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-3); margin-bottom: 8px;
}
.preview-cell iframe {
  width: 100%; height: 560px; border: 1px solid var(--line);
  border-radius: 14px; background: var(--surf); box-shadow: var(--shadow);
  display: block;
}
.preview-h {
  font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-3);
  margin: 8px 0 0;
}

.preview-snippet { margin-top: 38px; }
.preview-snippet h2 {
  font-family: var(--font-display); font-weight: 700; font-size: 17px; margin: 0 0 10px;
}
.preview-snippet pre {
  font-family: var(--font-mono); font-size: 12px; line-height: 1.6;
  background: var(--surf); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; overflow-x: auto; margin: 0;
}
