/**
 * Madison Equity Data — "Talk to the Data" chat styles
 * ------------------------------------------------------------------
 * Wave 4 Track B (PIP-92). Surface-specific rules only, following
 * policy.css's own header comment convention — no raw color/font
 * values, everything consumes design/tokens.css custom properties.
 * Loaded AFTER policy.css (see index.html's <link> order) so it can
 * override .chat-stub's now-removed styles cleanly if any residue
 * exists (it doesn't — the stub markup was replaced wholesale, this
 * file only defines new .chat-* classes).
 * ------------------------------------------------------------------ */

/* ── Visually-hidden utility (screen-reader-only text) ──
   No shared .sr-only exists yet elsewhere in this repo; scoped here
   since only the chat component needs it today (see MedChat's speaker
   labels + the thread's status-region pattern). Promote to shell.css
   if a second surface needs the same pattern later. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* The aria-live status line is visually redundant with the thread's
   own content (it just announces "Thinking…"/"Response complete." for
   screen readers) — keep it in the accessibility tree (aria-live
   requires the element to exist, not be display:none) but visually
   hidden using the same clip-rect technique, not `hidden` (which some
   AT treats as removed from the live-region tree). */
.chat-status.sr-only-unless-active {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Chat widget shell ── */
.chat-widget {
  background: var(--paper-raised);
  border: 1px solid var(--rule-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  max-width: var(--max-reading);
}

/* ── Honesty banner — always visible, never collapsible, matches the
   existing .policy-disclaimer's "never buried" treatment ── */
.chat-honesty-banner {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  border-left: 3px solid var(--caution);
  background: var(--caution-tint);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: var(--sp-3) var(--sp-4);
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  color: var(--ink);
  line-height: var(--lh-data);
}
.chat-honesty-banner-icon { flex-shrink: 0; line-height: 1; }

/* ── Model-lane selector (radiogroup of 2 buttons) ── */
.chat-lane-group {
  display: flex;
  gap: var(--sp-2);
  border-bottom: 1px solid var(--rule-light);
  padding-bottom: var(--sp-4);
}
.chat-lane-btn {
  flex: 1;
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--ink-mid);
  background: var(--parchment);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
  text-align: center;
  transition: background var(--motion-quick), color var(--motion-quick), border-color var(--motion-quick);
}
.chat-lane-btn:hover { background: var(--paper-raised); }
.chat-lane-btn.is-active {
  background: var(--accent);
  color: var(--ink-inverse-text-2);
  border-color: var(--accent);
  font-weight: var(--fw-semibold);
}

/* ── Lane panels (OpenRouter model select / Ollama endpoint fields) ── */
.chat-lane-panel {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  background: var(--parchment);
  border-radius: var(--radius-sm);
  padding: var(--sp-4);
}
/* MUST come after the bare .chat-lane-panel rule above so it wins the
   cascade: chat.js toggles the `hidden` DOM attribute to show/hide
   the OpenRouter vs. Ollama panel, but `display: flex` on the class
   selector otherwise overrides the UA stylesheet's `[hidden] {
   display: none }` rule (same specificity class-vs-attribute, source
   order decides, and this file loads after nothing overrides it) —
   caught via browser verification: both lane panels rendered
   simultaneously despite `hidden` being correctly set in the DOM. */
.chat-lane-panel[hidden] { display: none; }
.chat-lane-panel label {
  font-family: var(--font-ui);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--ink-mid);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.chat-lane-panel select,
.chat-lane-panel input[type="text"] {
  width: 100%;
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
}
.chat-lane-panel select:focus-visible,
.chat-lane-panel input[type="text"]:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}
.chat-lane-note {
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  color: var(--ink-mid);
  line-height: var(--lh-base);
  margin-top: var(--sp-1);
}
.chat-lane-note-privacy {
  color: var(--tier-1);
  font-weight: var(--fw-medium);
}
.chat-lane-note-hint {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--slate);
}

/* ── Conversation thread ── */
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  max-height: 420px;
  overflow-y: auto;
  padding: var(--sp-2) var(--sp-1);
}
.chat-bubble {
  display: block;
  max-width: 85%;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  line-height: var(--lh-base);
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-bubble-user {
  align-self: flex-end;
  background: var(--accent-tint);
  color: var(--ink);
  border: 1px solid var(--accent-tint-2);
}
.chat-bubble-assistant {
  align-self: flex-start;
  background: var(--parchment);
  color: var(--ink);
  border: 1px solid var(--rule-light);
}
.chat-bubble-pending .chat-bubble-content::after {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  margin-left: var(--sp-1);
  border-radius: 50%;
  background: var(--slate);
  animation: chatPulse 1s ease-in-out infinite;
}
@keyframes chatPulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-bubble-pending .chat-bubble-content::after { animation: none; opacity: 0.6; }
}
.chat-bubble-error {
  background: var(--danger-tint);
  border: 1px solid var(--danger);
  color: var(--ink);
}

/* ── Input form ── */
.chat-form {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  border-top: 1px solid var(--rule-light);
  padding-top: var(--sp-4);
}
.chat-input-label {
  /* Visible label kept off-screen per the task's "labeled input"
     requirement being satisfied via a REAL <label>, not a placeholder
     stand-in — placeholders are not an accessible-name substitute. */
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
#chatInput {
  flex: 1;
  font-family: var(--font-body);
  font-size: var(--fs-base);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
}
#chatInput:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}
#chatInput:disabled { background: var(--parchment); color: var(--slate); }

.chat-form .btn {
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--ink-inverse-text-2);
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: var(--sp-3) var(--sp-6);
  cursor: pointer;
  white-space: nowrap;
}
.chat-form .btn:hover { background: var(--accent-hover); }
.chat-form .btn:disabled { background: var(--rule); color: var(--slate); cursor: not-allowed; }
.chat-form .btn[aria-busy="true"] { position: relative; }

/* ── Responsive: mobile 375 -> desktop, matches policy.css's own breakpoints ── */
@media (max-width: 900px) {
  .chat-lane-group { flex-direction: column; }
}
@media (max-width: 480px) {
  .chat-widget { padding: var(--sp-4); }
  .chat-form { flex-direction: column; align-items: stretch; }
  .chat-bubble { max-width: 100%; }
}
