/*
 * ════════════════════════════════════════════════════════════════════════
 *  Live chat — the floating widget, the "Bestil hjælp" thread, the inbox
 * ════════════════════════════════════════════════════════════════════════
 *
 * Kept out of notarium.css deliberately: chat is one workstream's surface,
 * and Propshaft's `stylesheet_link_tag :app` picks up every file under
 * app/assets/stylesheets anyway.
 *
 * ⚠ TOKEN NAMES ARE LOAD-BEARING — this file's first version invented five
 * that do not exist (--nt-hairline, --nt-paper, --nt-ink, --nt-ink-soft,
 * --nt-ink-faint). An unknown custom property is "invalid at computed-value
 * time", which does NOT fall back to the initial value: `border-color`
 * became currentColor (heavy black rules around every panel) and
 * `background` became transparent. The widget looked broken for exactly that
 * reason. Only tokens that appear in notarium.css sections 2a–2e may be used
 * here; when in doubt, grep for the name before typing it.
 *
 * The real names, for reference:
 *   surfaces  --nt-bg --nt-bg-accent --nt-surface-sunken --nt-surface
 *             --nt-surface-raised --nt-surface-overlay
 *   text      --nt-text --nt-text-secondary --nt-text-tertiary
 *   borders   --nt-border-subtle --nt-border --nt-border-strong
 *   identity  --nt-seal --nt-seal-hover --nt-seal-soft --nt-seal-tint
 *             --nt-seal-border --nt-seal-text --nt-on-seal
 */

/* ── Component-local theme tokens ────────────────────────────────────────
 *
 * The panel header is a bordeaux band — the wax seal is the identity and a
 * chat with a jurist should look like the product, not like a bolted-on box.
 * It needs its OWN pair rather than --nt-seal, because --nt-seal lightens in
 * dark mode (seal-400) and white-on-seal-400 is a 3.4:1 header. So: seal-600
 * in light, seal-800 in dark, both carrying near-white text.
 *
 * Three-state theming, same shape as notarium.css § 2b–2d.
 * ⚠ The two dark blocks are byte-identical on purpose. KEEP THEM IN SYNC.
 */

:root {
  --nt-chat-head-bg: var(--nt-c-seal-600);
  --nt-chat-head-fg: #fdf9f5;
  --nt-chat-head-soft: rgba(253, 249, 245, 0.74);
  --nt-chat-head-rule: rgba(253, 249, 245, 0.16);
  --nt-chat-head-hover: rgba(253, 249, 245, 0.14);
  --nt-chat-log-bg: var(--nt-bg-accent);
}

:root[data-theme="dark"] {
  --nt-chat-head-bg: var(--nt-c-seal-800);
  --nt-chat-head-fg: var(--nt-c-bone-100);
  --nt-chat-head-soft: rgba(236, 233, 226, 0.7);
  --nt-chat-head-rule: rgba(236, 233, 226, 0.14);
  --nt-chat-head-hover: rgba(236, 233, 226, 0.12);
  --nt-chat-log-bg: var(--nt-c-night-850);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --nt-chat-head-bg: var(--nt-c-seal-800);
    --nt-chat-head-fg: var(--nt-c-bone-100);
    --nt-chat-head-soft: rgba(236, 233, 226, 0.7);
    --nt-chat-head-rule: rgba(236, 233, 226, 0.14);
    --nt-chat-head-hover: rgba(236, 233, 226, 0.12);
    --nt-chat-log-bg: var(--nt-c-night-850);
  }
}

/* ══════════════════════════════════════════════════════════════════════
   1. THE FLOATING WIDGET
   ══════════════════════════════════════════════════════════════════════ */

.nt-chat {
  position: fixed;
  right: var(--nt-space-5);
  bottom: var(--nt-space-5);
  z-index: var(--nt-z-overlay);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--nt-space-3);
  /* The container is only a positioning frame — clicks must fall through the
     gap between launcher and panel to the page underneath. */
  pointer-events: none;
}

.nt-chat > * { pointer-events: auto; }

/* ── Launcher ─────────────────────────────────────────────── */

.nt-chat-launcher {
  position: relative;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: var(--nt-radius-full);
  border: none;
  background: var(--nt-chat-head-bg);
  color: var(--nt-chat-head-fg);
  box-shadow: var(--nt-shadow-3);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition:
    transform var(--nt-duration) var(--nt-ease-seal),
    box-shadow var(--nt-duration) var(--nt-ease),
    background-color var(--nt-duration-fast) var(--nt-ease);
}

.nt-chat-launcher:hover {
  transform: translateY(-2px);
  box-shadow: var(--nt-shadow-3), 0 0 0 6px var(--nt-seal-soft);
}

.nt-chat-launcher:focus-visible {
  outline: none;
  box-shadow: var(--nt-shadow-3), var(--nt-shadow-focus);
}

.nt-chat-launcher:active { transform: translateY(0); }

/* Both glyphs are stacked in the same grid cell and cross-faded, so the
   launcher never resizes and the swap reads as one object turning. */
.nt-chat-launcher-glyph {
  grid-area: 1 / 1;
  width: 1.5rem;
  height: 1.5rem;
  transition:
    opacity var(--nt-duration-fast) var(--nt-ease),
    transform var(--nt-duration) var(--nt-ease-seal);
}

.nt-chat-launcher-glyph-close { opacity: 0; transform: rotate(-90deg) scale(0.7); }

.nt-chat[data-open="true"] .nt-chat-launcher-glyph-open { opacity: 0; transform: rotate(90deg) scale(0.7); }
.nt-chat[data-open="true"] .nt-chat-launcher-glyph-close { opacity: 1; transform: none; }

/* Unread count on the closed launcher.
   Deliberately NOT red or amber: in this design system red is "overdue" and
   amber is "a frist is approaching". An unread reply is neither. Inverting
   the seal (paper disc, bordeaux numeral) reads as a count without borrowing
   a status colour that means something else. */
.nt-chat-unread {
  position: absolute;
  top: -0.15rem;
  right: -0.15rem;
  min-width: 1.3rem;
  height: 1.3rem;
  padding: 0 0.3rem;
  border-radius: var(--nt-radius-full);
  background: var(--nt-chat-head-fg);
  color: var(--nt-chat-head-bg);
  border: 2px solid var(--nt-chat-head-bg);
  font-family: var(--nt-font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  animation: nt-chat-pop var(--nt-duration-slow) var(--nt-ease-seal);
}

/* Empty span => no badge. The element always exists so Turbo has a target. */
.nt-chat-unread:empty { display: none; }

/* An open panel has already shown the message. */
.nt-chat[data-open="true"] .nt-chat-unread { display: none; }

@keyframes nt-chat-pop {
  from { transform: scale(0.2); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* ── Panel ────────────────────────────────────────────────── */

.nt-chat-panel {
  width: min(24rem, calc(100vw - 2.5rem));
  height: min(34rem, calc(100dvh - 8.5rem));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--nt-surface);
  border: 1px solid var(--nt-border-subtle);
  border-radius: var(--nt-radius-lg);
  box-shadow: var(--nt-shadow-3);
  transform-origin: bottom right;

  /* Closed-but-mounted state. `hidden` (display:none) is still applied by the
     Stimulus controller while the panel has never been opened — that is what
     keeps the lazy turbo-frame from intersecting the viewport, so a homepage
     nobody chats on pays nothing for the conversation. Once opened, the
     controller drops `hidden` and drives this attribute instead. */
  opacity: 0;
  transform: translateY(10px) scale(0.985);
  transition:
    opacity var(--nt-duration) var(--nt-ease),
    transform var(--nt-duration) var(--nt-ease-seal);
}

.nt-chat[data-open="true"] .nt-chat-panel {
  opacity: 1;
  transform: none;
}

.nt-chat-panel[hidden] { display: none; }

/* ── Header ───────────────────────────────────────────────── */

.nt-chat-head {
  display: flex;
  align-items: center;
  gap: var(--nt-space-3);
  padding: 0.8rem 0.9rem;
  background: var(--nt-chat-head-bg);
  color: var(--nt-chat-head-fg);
  border-bottom: 1px solid var(--nt-chat-head-rule);
  flex: none;
}

.nt-chat-head-seal {
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--nt-radius-full);
  display: grid;
  place-items: center;
  background: var(--nt-chat-head-hover);
  color: var(--nt-chat-head-fg);
}

.nt-chat-head-text { flex: 1 1 auto; min-width: 0; }

.nt-chat-title {
  font-family: var(--nt-font-display);
  font-weight: 600;
  font-size: var(--nt-text-md);
  line-height: 1.15;
  letter-spacing: -0.005em;
}

.nt-chat-close {
  flex: none;
  border: none;
  background: transparent;
  color: var(--nt-chat-head-soft);
  cursor: pointer;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: var(--nt-radius-sm);
  display: grid;
  place-items: center;
  transition:
    background-color var(--nt-duration-fast) var(--nt-ease),
    color var(--nt-duration-fast) var(--nt-ease);
}

.nt-chat-close:hover { background: var(--nt-chat-head-hover); color: var(--nt-chat-head-fg); }

.nt-chat-close:focus-visible {
  outline: 2px solid var(--nt-chat-head-fg);
  outline-offset: 1px;
}

/* ── Presence line ────────────────────────────────────────── */

.nt-chat-presence {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.15rem;
  font-size: var(--nt-text-xs);
  color: var(--nt-chat-head-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nt-chat-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: var(--nt-radius-full);
  background: currentColor;
  opacity: 0.55;
  flex: none;
}

.nt-chat-dot.is-online {
  background: var(--nt-c-green-300);
  opacity: 1;
  box-shadow: 0 0 0 0 rgba(143, 199, 176, 0.6);
  animation: nt-chat-pulse 2.4s var(--nt-ease-in-out) infinite;
}

@keyframes nt-chat-pulse {
  0%, 70%, 100% { box-shadow: 0 0 0 0 rgba(143, 199, 176, 0); }
  35%           { box-shadow: 0 0 0 4px rgba(143, 199, 176, 0.35); }
}

/* Panel body: a flex column so the log scrolls and the composer pins. */
.nt-chat-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--nt-chat-log-bg);
}

.nt-chat-loading {
  margin: auto;
  padding: var(--nt-space-8) var(--nt-space-4);
  text-align: center;
  color: var(--nt-text-tertiary);
  font-size: var(--nt-text-sm);
}

/* ══════════════════════════════════════════════════════════════════════
   2. THE MESSAGE LOG
   ══════════════════════════════════════════════════════════════════════ */

.nt-chat-log {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--nt-space-4);
  display: flex;
  flex-direction: column;
  gap: var(--nt-space-3);
  background: var(--nt-chat-log-bg);
  scroll-behavior: smooth;
}

.nt-chat-stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nt-chat-stack:empty { display: none; }

/* ── One message ──────────────────────────────────────────── */

.nt-chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: nt-chat-msg-in var(--nt-duration) var(--nt-ease);
}

.nt-chat-msg.is-mine   { align-self: flex-end;   align-items: flex-end; }
.nt-chat-msg.is-theirs { align-self: flex-start; align-items: flex-start; }

@keyframes nt-chat-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* Sender label. Shown once per run: two messages in a row from the same side
   are obviously from the same person, and repeating the name turns a
   conversation into a transcript. Done in CSS rather than in the partial
   because messages arrive as independent Turbo Stream appends — the partial
   never knows what came before it. */
.nt-chat-msg-who {
  font-size: var(--nt-text-xs);
  font-weight: 550;
  color: var(--nt-text-secondary);
  padding: 0 0.35rem;
  margin-bottom: 0.2rem;
}

.nt-chat-msg.is-mine + .nt-chat-msg.is-mine > .nt-chat-msg-who,
.nt-chat-msg.is-theirs + .nt-chat-msg.is-theirs > .nt-chat-msg-who { display: none; }

.nt-chat-msg-text {
  padding: 0.5rem 0.8rem;
  border-radius: var(--nt-radius);
  font-size: var(--nt-text-base);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.nt-chat-msg.is-theirs .nt-chat-msg-text {
  background: var(--nt-surface);
  color: var(--nt-text);
  border: 1px solid var(--nt-border-subtle);
  border-bottom-left-radius: var(--nt-radius-xs);
}

.nt-chat-msg.is-mine .nt-chat-msg-text {
  background: var(--nt-chat-head-bg);
  color: var(--nt-chat-head-fg);
  border: 1px solid transparent;
  border-bottom-right-radius: var(--nt-radius-xs);
}

/* Timestamps are for reference, not for reading — they never compete with
   the message itself, and they fade up on hover/focus of the row. */
.nt-chat-msg-time {
  font-family: var(--nt-font-mono);
  font-size: 0.66rem;
  font-variant-numeric: tabular-nums;
  color: var(--nt-text-tertiary);
  padding: 0 0.35rem;
  margin-top: 0.18rem;
  opacity: 0.55;
  transition: opacity var(--nt-duration-fast) var(--nt-ease);
}

.nt-chat-msg:hover .nt-chat-msg-time,
.nt-chat-msg:focus-within .nt-chat-msg-time { opacity: 1; }

/* Turbo needs a stable element to replace, but an EMPTY status wrapper would
   still eat one of the log's flex gaps. display:contents keeps the id in the
   DOM and takes the box out of layout. */
.nt-chat-status { display: contents; }

/* System line: "En jurist har overtaget samtalen". */
.nt-chat-note {
  align-self: center;
  text-align: center;
  max-width: 90%;
  font-size: var(--nt-text-xs);
  color: var(--nt-text-secondary);
  background: var(--nt-surface-raised);
  border: 1px solid var(--nt-border-subtle);
  border-radius: var(--nt-radius-full);
  padding: 0.25rem 0.75rem;
}

/* ── Empty state ──────────────────────────────────────────── */

.nt-chat-empty {
  margin: auto 0;
  padding: var(--nt-space-4) var(--nt-space-2) var(--nt-space-2);
  text-align: center;
}

/* The log holds one message => the invitation has been accepted.
   :has() rather than a sibling rule, because the appended messages land in
   #chat_messages while the empty state is a sibling of it. */
.nt-chat-log:has(.nt-chat-stack > .nt-chat-msg) .nt-chat-empty { display: none; }

.nt-chat-empty-seal { color: var(--nt-seal); margin-bottom: var(--nt-space-3); }

.nt-chat-empty-title {
  font-family: var(--nt-font-display);
  font-size: var(--nt-text-lg);
  font-weight: 600;
  line-height: 1.25;
  color: var(--nt-text);
}

.nt-chat-empty-body {
  margin-top: 0.35rem;
  font-size: var(--nt-text-sm);
  line-height: 1.5;
  color: var(--nt-text-secondary);
}

.nt-chat-prompts {
  margin-top: var(--nt-space-4);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* A concrete first question beats a blinking cursor. Clicking one drops the
   text into the composer — it is a suggestion, never a send. */
.nt-chat-prompt {
  width: 100%;
  text-align: left;
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  border-radius: var(--nt-radius);
  border: 1px solid var(--nt-border-subtle);
  background: var(--nt-surface);
  color: var(--nt-text-secondary);
  font-family: var(--nt-font-body);
  font-size: var(--nt-text-sm);
  line-height: 1.35;
  transition:
    border-color var(--nt-duration-fast) var(--nt-ease),
    color var(--nt-duration-fast) var(--nt-ease),
    background-color var(--nt-duration-fast) var(--nt-ease);
}

.nt-chat-prompt:hover {
  border-color: var(--nt-seal-border);
  background: var(--nt-seal-soft);
  color: var(--nt-seal-text);
}

.nt-chat-prompt:focus-visible {
  outline: none;
  box-shadow: var(--nt-shadow-focus);
  border-color: var(--nt-focus);
}

/* ── Escalation brief (customer side) ─────────────────────── */

/* The reassurance half of the escalation design: the customer must be able
   to see that the jurist is not starting from zero. Mirrors the sysadmin
   context pane, one line shorter. */
.nt-chat-brief {
  flex: none;
  display: flex;
  gap: var(--nt-space-3);
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--nt-seal-border);
  background: var(--nt-seal-soft);
  border-radius: var(--nt-radius);
}

.nt-chat-brief-icon { color: var(--nt-seal); flex: none; margin-top: 0.1rem; }
.nt-chat-brief-body { min-width: 0; }

.nt-chat-brief-title {
  font-size: var(--nt-text-sm);
  font-weight: 600;
  color: var(--nt-seal-text);
}

.nt-chat-brief-line {
  font-size: var(--nt-text-xs);
  line-height: 1.45;
  color: var(--nt-text-secondary);
  overflow-wrap: anywhere;
}

.nt-chat-brief-quote {
  margin-top: 0.3rem;
  font-size: var(--nt-text-xs);
  line-height: 1.45;
  color: var(--nt-text);
  border-left: 2px solid var(--nt-seal);
  padding-left: 0.5rem;
}

/* ── Scroll-to-latest ─────────────────────────────────────── */

/* Only offered when the reader has scrolled away from the bottom: yanking
   somebody back down while they are re-reading an answer is hostile. */
.nt-chat-jump {
  position: sticky;
  bottom: 0.4rem;
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.75rem;
  border-radius: var(--nt-radius-full);
  border: 1px solid var(--nt-border-subtle);
  background: var(--nt-surface-overlay);
  color: var(--nt-text-secondary);
  box-shadow: var(--nt-shadow-2);
  font-family: var(--nt-font-body);
  font-size: var(--nt-text-xs);
  cursor: pointer;
  z-index: 1;
  animation: nt-chat-pop var(--nt-duration) var(--nt-ease-seal);
}

.nt-chat-jump[hidden] { display: none; }
.nt-chat-jump:hover { color: var(--nt-text); border-color: var(--nt-border); }

/* ══════════════════════════════════════════════════════════════════════
   3. COMPOSER & EMAIL CAPTURE
   ══════════════════════════════════════════════════════════════════════ */

.nt-chat-composer {
  flex: none;
  padding: 0.6rem 0.7rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--nt-border-subtle);
  background: var(--nt-surface);
}

.nt-chat-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.nt-chat-textarea {
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  max-height: 8rem;
  min-height: 2.4rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--nt-radius);
  border: 1px solid var(--nt-border-subtle);
  background: var(--nt-bg-accent);
  color: var(--nt-text);
  font-family: var(--nt-font-body);
  font-size: var(--nt-text-base);
  line-height: 1.45;
  transition:
    border-color var(--nt-duration-fast) var(--nt-ease),
    box-shadow var(--nt-duration-fast) var(--nt-ease),
    background-color var(--nt-duration-fast) var(--nt-ease);
}

.nt-chat-textarea::placeholder { color: var(--nt-text-tertiary); }

.nt-chat-textarea:focus {
  outline: none;
  background: var(--nt-surface);
  border-color: var(--nt-focus);
  box-shadow: var(--nt-shadow-focus);
}

.nt-chat-send {
  flex: none;
  width: 2.4rem;
  height: 2.4rem;
  border: none;
  cursor: pointer;
  background: var(--nt-chat-head-bg);
  color: var(--nt-chat-head-fg);
  border-radius: var(--nt-radius);
  display: grid;
  place-items: center;
  transition:
    background-color var(--nt-duration-fast) var(--nt-ease),
    opacity var(--nt-duration-fast) var(--nt-ease),
    transform var(--nt-duration-fast) var(--nt-ease);
}

.nt-chat-send:hover:not(:disabled) { background: var(--nt-c-seal-700); transform: translateY(-1px); }

.nt-chat-send:focus-visible { outline: none; box-shadow: var(--nt-shadow-focus); }

.nt-chat-send:disabled {
  cursor: default;
  opacity: 0.4;
}

.nt-chat-hint {
  margin-top: 0.35rem;
  padding: 0 0.15rem;
  font-size: 0.68rem;
  color: var(--nt-text-tertiary);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.nt-chat-key {
  font-family: var(--nt-font-mono);
  font-size: 0.62rem;
  border: 1px solid var(--nt-border-subtle);
  border-bottom-width: 2px;
  border-radius: var(--nt-radius-xs);
  padding: 0.02rem 0.25rem;
  color: var(--nt-text-secondary);
  background: var(--nt-surface-raised);
}

/* ── "Hvor må vi svare dig?" ──────────────────────────────── */

.nt-chat-capture {
  flex: none;
  padding: 0.75rem 0.85rem;
  border-top: 1px solid var(--nt-info-border);
  background: var(--nt-info-soft);
  color: var(--nt-info-text);
  font-size: var(--nt-text-sm);
  line-height: 1.45;
}

.nt-chat-capture form {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.nt-chat-capture input[type="email"] {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.45rem 0.6rem;
  border-radius: var(--nt-radius-sm);
  border: 1px solid var(--nt-info-border);
  background: var(--nt-surface);
  color: var(--nt-text);
  font-family: var(--nt-font-body);
  font-size: var(--nt-text-sm);
}

.nt-chat-capture input[type="email"]:focus {
  outline: none;
  border-color: var(--nt-focus);
  box-shadow: var(--nt-shadow-focus);
}

.nt-chat-capture-submit {
  flex: none;
  border: none;
  cursor: pointer;
  background: var(--nt-chat-head-bg);
  color: var(--nt-chat-head-fg);
  border-radius: var(--nt-radius-sm);
  padding: 0.4rem 0.8rem;
  font-family: var(--nt-font-body);
  font-size: var(--nt-text-sm);
  font-weight: 550;
}

.nt-chat-capture-error {
  margin-top: 0.35rem;
  color: var(--nt-danger-text);
  font-size: var(--nt-text-xs);
}

/* ══════════════════════════════════════════════════════════════════════
   4. PHONE — a full-height sheet, not a 320px box in the corner
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 30rem) {
  .nt-chat {
    right: var(--nt-space-4);
    bottom: var(--nt-space-4);
  }

  .nt-chat-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
    transform-origin: bottom center;
    transform: translateY(2%);
  }

  .nt-chat-head { padding-top: calc(0.8rem + env(safe-area-inset-top, 0px)); }

  /* The sheet owns the screen; a launcher floating on top of it is noise. */
  .nt-chat[data-open="true"] .nt-chat-launcher { display: none; }

  .nt-chat-msg { max-width: 92%; }
}

/* ══════════════════════════════════════════════════════════════════════
   5. PAGE SURFACES — "Bestil hjælp" thread, sysadmin thread
   ══════════════════════════════════════════════════════════════════════ */

.nt-chat-page-log {
  height: min(30rem, 58vh);
  border: 1px solid var(--nt-border-subtle);
  border-radius: var(--nt-radius-lg) var(--nt-radius-lg) 0 0;
  padding: var(--nt-space-5);
}

.nt-chat-page-composer {
  border: 1px solid var(--nt-border-subtle);
  border-top: none;
  border-radius: 0 0 var(--nt-radius-lg) var(--nt-radius-lg);
  overflow: hidden;
}

.nt-chat-page-composer .nt-chat-composer { border-top: none; }

/* ══════════════════════════════════════════════════════════════════════
   6. SYSADMIN INBOX — two panes, one job
   ══════════════════════════════════════════════════════════════════════ */

.nt-inbox {
  display: grid;
  grid-template-columns: minmax(17rem, 22rem) minmax(0, 1fr);
  gap: var(--nt-space-4);
  align-items: stretch;
  /* One screenful, two independently scrolling columns — the jurist's eye
     never leaves the list while reading a thread. */
  height: calc(100dvh - 11rem);
  min-height: 30rem;
}

@media (max-width: 60rem) {
  .nt-inbox {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    min-height: 0;
  }

  .nt-inbox-list { max-height: 24rem; }
  .nt-inbox-thread { min-height: 32rem; }
}

.nt-inbox-list,
.nt-inbox-thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--nt-surface);
  border: 1px solid var(--nt-border-subtle);
  border-radius: var(--nt-radius-lg);
  box-shadow: var(--nt-shadow-1);
}

.nt-inbox-head {
  flex: none;
  padding: var(--nt-space-3) var(--nt-space-4);
  border-bottom: 1px solid var(--nt-border-subtle);
  background: var(--nt-surface-raised);
}

.nt-inbox-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.nt-chat-filters {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.nt-chat-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.22rem 0.65rem;
  border-radius: var(--nt-radius-full);
  border: 1px solid var(--nt-border-subtle);
  background: var(--nt-surface);
  font-size: var(--nt-text-xs);
  color: var(--nt-text-secondary);
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color var(--nt-duration-fast) var(--nt-ease),
    border-color var(--nt-duration-fast) var(--nt-ease),
    color var(--nt-duration-fast) var(--nt-ease);
}

.nt-chat-filter:hover { border-color: var(--nt-border-strong); color: var(--nt-text); }

.nt-chat-filter.is-active {
  background: var(--nt-chat-head-bg);
  border-color: var(--nt-chat-head-bg);
  color: var(--nt-chat-head-fg);
}

.nt-chat-filter-count {
  font-family: var(--nt-font-mono);
  font-size: 0.66rem;
  opacity: 0.75;
}

/* ── One row in the list ──────────────────────────────────── */

.nt-chat-row {
  display: block;
  position: relative;
  padding: 0.7rem 0.9rem 0.7rem 1rem;
  border-bottom: 1px solid var(--nt-border-subtle);
  border-left: 3px solid transparent;
  text-decoration: none;
  color: inherit;
  transition: background-color var(--nt-duration-fast) var(--nt-ease);
}

.nt-chat-row:hover { background: var(--nt-surface-raised); }

.nt-chat-row:focus-visible {
  outline: none;
  background: var(--nt-surface-raised);
  box-shadow: inset var(--nt-shadow-focus);
}

.nt-chat-row.is-unread { border-left-color: var(--nt-seal); }
.nt-chat-row.is-unread .nt-chat-row-title { font-weight: 650; }

.nt-chat-row.is-current {
  background: var(--nt-seal-soft);
  border-left-color: var(--nt-seal);
}

.nt-chat-row-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--nt-space-3);
}

.nt-chat-row-title {
  font-weight: 550;
  font-size: var(--nt-text-sm);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nt-chat-row-when {
  flex: none;
  font-family: var(--nt-font-mono);
  font-size: 0.66rem;
  color: var(--nt-text-tertiary);
}

.nt-chat-row-excerpt {
  color: var(--nt-text-secondary);
  font-size: var(--nt-text-xs);
  line-height: 1.4;
  margin-top: 0.2rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.nt-chat-row-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
  font-size: 0.68rem;
  color: var(--nt-text-tertiary);
}

.nt-chat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.32rem;
  border-radius: var(--nt-radius-full);
  background: var(--nt-seal);
  color: var(--nt-on-seal);
  font-family: var(--nt-font-mono);
  font-size: 0.66rem;
  font-weight: 600;
  line-height: 1;
}

.nt-inbox-empty {
  margin: auto;
  padding: var(--nt-space-10) var(--nt-space-6);
  text-align: center;
  color: var(--nt-text-tertiary);
  font-size: var(--nt-text-sm);
}

/* ── Thread pane ──────────────────────────────────────────── */

.nt-inbox-thread-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--nt-space-4);
  padding: var(--nt-space-3) var(--nt-space-4);
  border-bottom: 1px solid var(--nt-border-subtle);
  background: var(--nt-surface-raised);
}

.nt-inbox-thread-title {
  font-family: var(--nt-font-display);
  font-size: var(--nt-text-lg);
  font-weight: 600;
  line-height: 1.2;
}

.nt-inbox-thread-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* Thread body: transcript left, context right. The context pane is the whole
   point of escalation — it never collapses below the thread on desktop. */
.nt-inbox-thread-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(15rem, 19rem);
}

@media (max-width: 78rem) {
  .nt-inbox-thread-body { grid-template-columns: minmax(0, 1fr); }
  .nt-inbox-context { border-left: 0; border-top: 1px solid var(--nt-border-subtle); }
}

.nt-inbox-transcript {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.nt-inbox-transcript .nt-chat-log { background: var(--nt-chat-log-bg); }

.nt-inbox-context {
  border-left: 1px solid var(--nt-border-subtle);
  background: var(--nt-surface);
  overflow-y: auto;
  padding: var(--nt-space-4);
  min-height: 0;
}

/* ══════════════════════════════════════════════════════════════════════
   7. THE CONTEXT PANE — company card, wizard step, the tripwire verbatim
   ══════════════════════════════════════════════════════════════════════ */

.nt-chat-context-title {
  font-family: var(--nt-font-display);
  font-size: var(--nt-text-base);
  font-weight: 600;
  margin-bottom: var(--nt-space-3);
}

/* The company card. A jurist opening a thread must know whose file this is
   before reading a word, and be one click from it. */
.nt-chat-company {
  display: block;
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--nt-seal-border);
  background: var(--nt-seal-soft);
  border-radius: var(--nt-radius);
  padding: 0.7rem 0.8rem;
  margin-bottom: var(--nt-space-3);
  transition:
    border-color var(--nt-duration-fast) var(--nt-ease),
    background-color var(--nt-duration-fast) var(--nt-ease);
}

a.nt-chat-company:hover { background: var(--nt-seal-tint); border-color: var(--nt-seal); }

.nt-chat-company-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--nt-seal-text);
}

.nt-chat-company-name {
  font-family: var(--nt-font-display);
  font-size: var(--nt-text-md);
  font-weight: 600;
  line-height: 1.2;
  margin-top: 0.2rem;
  overflow-wrap: anywhere;
}

.nt-chat-company-meta {
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-family: var(--nt-font-mono);
  font-size: 0.68rem;
  color: var(--nt-text-secondary);
}

.nt-chat-company-open {
  margin-top: 0.45rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--nt-font-body);
  font-size: var(--nt-text-xs);
  font-weight: 550;
  color: var(--nt-seal-text);
}

/* The tripwire, quoted. This is the sentence the wizard refused to pass, and
   it is the single most useful line on the screen — it gets the loudest
   treatment the palette allows for "a rule stopped something". */
.nt-chat-tripwire {
  border: 1px solid var(--nt-warn-border);
  background: var(--nt-warn-soft);
  color: var(--nt-warn-text);
  border-radius: var(--nt-radius);
  padding: 0.6rem 0.75rem;
  margin-bottom: var(--nt-space-3);
}

.nt-chat-tripwire-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.nt-chat-tripwire-text {
  font-family: var(--nt-font-serif);
  font-size: var(--nt-text-base);
  line-height: 1.45;
  color: var(--nt-text);
  border-left: 2px solid var(--nt-warn);
  padding-left: 0.55rem;
  overflow-wrap: anywhere;
}

.nt-chat-context {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

.nt-chat-context dt {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--nt-text-tertiary);
  margin-top: 0.7rem;
}

.nt-chat-context dd {
  font-size: var(--nt-text-sm);
  line-height: 1.45;
  color: var(--nt-text);
  overflow-wrap: anywhere;
}

.nt-chat-context dd .nt-mono { font-size: 0.68rem; }

/* ══════════════════════════════════════════════════════════════════════
   8. REDUCED MOTION
   ══════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .nt-chat-panel,
  .nt-chat-launcher,
  .nt-chat-launcher-glyph,
  .nt-chat-msg,
  .nt-chat-unread,
  .nt-chat-jump,
  .nt-chat-send,
  .nt-chat-dot.is-online {
    transition-duration: 1ms !important;
    animation: none !important;
  }

  .nt-chat-panel { transform: none; }
  .nt-chat-log { scroll-behavior: auto; }
  .nt-chat-launcher:hover { transform: none; }
}
