/**
 * app.css — Edition B (ECharts) shell chrome: header, sidebar, main panel,
 * chat bar, narration, why, action bar, follow-ups, welcome / loading states.
 * Structure + styling copied from docs/Implemtation_docs/v2_ui_mockup.html,
 * class names converted to snake_case (per 05_frontend_intern_plan.md).
 */

/* ── Header ─────────────────────────────────────────────────────── */
header {
  grid-area: header;
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, var(--panel) 0%, rgba(19, 26, 46, 0.96) 100%);
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 20px;
  z-index: 40;
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 12px; justify-self: start; }
.brand_mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 800; color: #fff;
  box-shadow: 0 2px 10px -2px var(--accent);
}
.brand_text { display: flex; flex-direction: column; line-height: 1.15; }
.brand_title { font-weight: 700; font-size: 15px; color: var(--text); }
.brand_subtitle { font-size: 11px; color: var(--text-mute); font-weight: 500; }

.persona_toggle {
  display: flex; justify-self: center; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 9px; padding: 4px; gap: 2px;
}
.persona_toggle button {
  background: transparent; color: var(--text-dim); border: none;
  padding: 7px 18px; font-size: 12px; font-weight: 600;
  border-radius: 6px; cursor: pointer; transition: all 0.15s;
}
.persona_toggle button:hover { color: var(--text); }
.persona_toggle button.active {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: white; box-shadow: 0 2px 8px -2px var(--accent);
}

.header_actions { display: flex; gap: 8px; justify-self: end; }
.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 7px 13px; font-size: 12px; border-radius: 7px; cursor: pointer; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px; transition: all 0.15s;
}
.btn:hover { background: var(--chip); border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%); border: none; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }

/* ── Chat panel (left column) ───────────────────────────────────── */
.chat_panel {
  grid-area: chat;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
  min-height: 0;
}
.chat_head {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  background: var(--panel-3);
}
.chat_head_title { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: var(--text); }
.chat_head_icon { color: var(--accent); font-size: 14px; }
.chat_head_meta { display: flex; align-items: center; gap: 8px; }

/* Deterministic engine chip */
.engine_chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10.5px; font-weight: 600; padding: 3px 9px;
  border-radius: 20px; background: rgba(52, 211, 153, 0.12);
  color: var(--good); border: 1px solid rgba(52, 211, 153, 0.25);
  white-space: nowrap;
}
.engine_chip.engine_pred { background: rgba(91,141,239,0.12); color: var(--accent); border-color: rgba(91,141,239,0.25); }
.engine_chip.engine_strat { background: rgba(251,191,36,0.12); color: var(--warn); border-color: rgba(251,191,36,0.25); }
.engine_dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; box-shadow: 0 0 6px currentColor; }

/* Audio waveform icon */
.waveform { display: inline-flex; align-items: center; gap: 2px; height: 16px; }
.waveform i {
  width: 2.5px; border-radius: 2px; background: var(--accent);
  animation: wf 1.1s ease-in-out infinite;
}
.waveform i:nth-child(1) { height: 6px;  animation-delay: 0s; }
.waveform i:nth-child(2) { height: 12px; animation-delay: 0.15s; }
.waveform i:nth-child(3) { height: 16px; animation-delay: 0.3s; }
.waveform i:nth-child(4) { height: 10px; animation-delay: 0.45s; }
.waveform i:nth-child(5) { height: 7px;  animation-delay: 0.6s; }
@keyframes wf { 0%, 100% { transform: scaleY(0.4); opacity: 0.5; } 50% { transform: scaleY(1); opacity: 1; } }

.chat_messages {
  flex: 1;
  overflow-y: auto;
  /* Minimal edge margin (≈7px) so bubbles use nearly the full panel width
     without touching the borders. */
  padding: 12px 7px;
  display: flex;
  flex-direction: column;
  /* Denser history now that the redundant "PHARMA AI" label row is gone. */
  gap: 7px;
  min-height: 0;
}
/* Left-panel scrollbar: nearly invisible so it never competes with content.
   2px thin, transparent thumb that only hints on hover. Scroll stays fully
   functional. Webkit + Firefox. */
.chat_messages { scrollbar-width: thin; scrollbar-color: transparent transparent; }
.chat_messages:hover { scrollbar-color: var(--scroll-thumb) transparent; }
.chat_messages::-webkit-scrollbar { width: 3px; }
.chat_messages::-webkit-scrollbar-track { background: transparent; }
.chat_messages::-webkit-scrollbar-thumb { background: transparent; border-radius: 3px; }
.chat_messages:hover::-webkit-scrollbar-thumb { background: var(--scroll-thumb); }
.chat_messages::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); }

.chat_welcome {
  font-size: 12px; color: var(--text-mute); line-height: 1.6;
  padding: 11px 12px; background: var(--panel-2);
  border-radius: 8px; border: 1px solid var(--border);
}
/* Sender label above each message */
.msg_row { display: flex; flex-direction: column; gap: 4px; max-width: 100%; }
.msg_row.user { align-items: flex-end; }
.msg_row.bot  { align-items: flex-start; }
.msg_meta {
  display: flex; align-items: center; gap: 6px;
  font-size: 10px; color: var(--text-mute); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0 4px;
}
.msg_avatar {
  width: 16px; height: 16px; border-radius: 5px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 9px; color: #fff;
}
.msg_row.user .msg_avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.msg_row.bot  .msg_avatar { background: var(--chip); color: var(--accent); }

.msg_user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff; padding: 9px 12px;
  border-radius: 14px 14px 2px 14px;
  max-width: 97%; font-size: 13px; line-height: 1.5;
  word-break: break-word;
  display: flex; align-items: flex-start; gap: 8px; position: relative;
  box-shadow: 0 4px 12px -4px rgba(91, 141, 239, 0.5);
}
.msg_text { flex: 1; }
.msg_edit_btn {
  flex-shrink: 0;
  background: rgba(255,255,255,0.15); border: none; color: #fff;
  width: 22px; height: 22px; border-radius: 5px;
  font-size: 12px; cursor: pointer; line-height: 1;
  opacity: 0.65; transition: opacity 0.15s, background 0.15s;
  display: flex; align-items: center; justify-content: center;
  padding: 0; margin-top: 1px;
}
.msg_edit_btn:hover { opacity: 1; background: rgba(255,255,255,0.3); }
.msg_thinking {
  align-self: flex-start;
  color: var(--text-mute); font-size: 12px; font-style: italic;
  padding: 6px 4px;
}
.msg_done {
  align-self: flex-start;
  color: var(--good); font-size: 11px;
  padding: 4px; display: flex; align-items: center; gap: 5px;
}
.msg_bot {
  align-self: flex-start;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text); padding: 9px 12px;
  border-radius: 4px 14px 14px 14px;
  /* Use the full available panel width (minus the minimal edge margin). */
  max-width: 100%; width: 100%; font-size: 13px; line-height: 1.5;
  word-break: break-word;
}

/* ── Active-conversation highlight ─────────────────────────────────
   The question/answer pair whose dashboard is currently shown gets an EMERALD
   GREEN accent bar + glow so it stands apart from the blue/violet theme (blue
   blended in too much). Warm ORANGE takes over on hover so pointing at any
   card previews it distinctly. Kept understated (no animation) to stay
   executive-grade. Applied to both the user bubble and the answer card. */
.msg_row.active_convo .msg_user {
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.5),
              0 6px 18px -6px rgba(52, 211, 153, 0.6);
}
.msg_row.active_convo .msg_bot {
  border-color: var(--accent-green);
  border-left-width: 3px;
  background: rgba(52, 211, 153, 0.08);
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.32),
              0 6px 18px -8px var(--accent-green);
}
/* Hover preview — warm orange, distinct from the green active state. Does not
   override the active pair's own hover (kept green-leaning via specificity). */
.msg_row.convo_pair:hover .msg_bot {
  border-color: var(--accent-orange);
  box-shadow: 0 0 0 1px rgba(245, 147, 74, 0.28),
              0 6px 18px -9px var(--accent-orange);
}
.msg_row.active_convo:hover .msg_bot {
  border-color: var(--accent-green);
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.4),
              0 6px 18px -8px var(--accent-green);
}
/* Gentle transition so switching the active pair feels smooth, not jumpy. */
.msg_row .msg_user, .msg_row .msg_bot {
  transition: box-shadow 0.25s, background 0.25s, border-color 0.25s;
}

/* ── AI answer card (inside the chat bubble) ───────────────────────
   Layout: answer text (+ View More) → action row
           [ ▶ Play/Pause ] ............ [ View Charts ]. */
.ai_answer_card {
  display: flex; flex-direction: column; gap: 8px;
  max-width: 100%;
  padding: 10px 12px;
}
/* Action row: Play/Pause toggle group anchored left, View Charts right,
   both on the same horizontal line with matching icon sizes. */
.ai_answer_actions {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: 2px;
}
/* Full answer text. Starts COLLAPSED to a compact height (~4.5 lines); a
   "View More" toggle (added in JS only when content overflows) expands it.
   No "…" truncation — nothing is hidden, just clamped by height. Expansion
   animates max-height for a smooth, subtle growth (no bounce). preserve-line
   keeps the headline/body spacing from build_chat_answer_text intact. */
/* Text block wraps the answer + the View More toggle, stacked vertically. */
.ai_answer_text { display: flex; flex-direction: column; }
.ai_answer_preview {
  font-size: 13px; color: var(--text); line-height: 1.55;
  white-space: pre-line;         /* honour the \n\n between headline & body */
  word-break: break-word;
  overflow: hidden;
  transition: max-height 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Collapsed state — applied ONLY to genuinely long answers (see
   wire_answer_expand). Caps the height (~11–12 lines) with a soft bottom fade
   so the cut reads as intentional rather than a hard slice. Short/medium
   answers never get this class, so they size to content with no cap or mask.
   NOTE: 232px must match COLLAPSED_MAX in app.js (wire_answer_expand). */
.ai_answer_preview.collapsed {
  max-height: 232px;
  -webkit-mask-image: linear-gradient(180deg, #000 80%, transparent 100%);
          mask-image: linear-gradient(180deg, #000 80%, transparent 100%);
}

/* View More / View Less — a LIGHTWEIGHT inline text action, not a button.
   No border, no pill, no background: just green text + a green chevron, in the
   same green accent family as the Play button / scrollbars / deterministic
   badge. Sits tight against the text so it reads as a continuation. */
.view_more_btn {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 5px;
  margin-top: 5px; padding: 1px 0;
  font-size: 11px; font-weight: 600; letter-spacing: 0.01em;
  font-family: inherit; line-height: 1.4;
  cursor: pointer;
  color: var(--accent-green);
  background: none; border: none; box-shadow: none;
  transition: color 0.15s;
}
/* A tiny chevron before the label (green via currentColor), rotated when
   expanded, so ▼ View More / ▲ View Less reads at a glance. */
.view_more_btn::before {
  content: '';
  width: 0; height: 0;
  border-left: 3.5px solid transparent;
  border-right: 3.5px solid transparent;
  border-top: 4px solid currentColor;
  transition: transform 0.2s ease;
}
.view_more_btn[aria-expanded="true"]::before { transform: rotate(180deg); }
.view_more_btn:hover { color: var(--accent-green-soft); text-decoration: underline; }
.view_more_btn:focus-visible { outline: 2px solid rgba(52, 211, 153, 0.6); outline-offset: 2px; border-radius: 3px; }

/* Compact media-player TTS controls — a single Play/Pause toggle, left-anchored. */
.tts_controls {
  display: flex; align-items: center; gap: 5px;
  padding-bottom: 0;
}
/* Play/Pause — subtle GREEN icon on a minimal background, consistent with the
   green accent family (scrollbars / deterministic badge / positive metrics). */
.tts_btn {
  background: rgba(52, 211, 153, 0.08); border: 1px solid rgba(52, 211, 153, 0.28);
  color: var(--accent-green); border-radius: 50%;
  width: 24px; height: 24px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; transition: color 0.15s, border-color 0.15s, background 0.15s;
}
/* Icons sized to match the View Charts icon (12px) for visual balance. */
.tts_btn svg { width: 12px; height: 12px; }
.tts_btn:hover { color: var(--accent-green-soft); border-color: var(--accent-green); background: rgba(52, 211, 153, 0.16); }
.tts_btn.active { color: #06251a; border-color: transparent; background: linear-gradient(135deg, var(--accent-green-soft), var(--accent-green)); }
.tts_wave { margin-left: 2px; opacity: 0.25; height: 12px; }
.tts_wave.on { opacity: 1; }
.tts_wave:not(.on) i { animation-play-state: paused; }

/* View Charts — borderless, near-transparent secondary action. GREEN text
   (green accent family) with an ORANGE chart icon (orange emphasis family)
   for a clean, premium look. */
.view_charts_btn {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 5px;
  background: transparent; border: 1px solid transparent;
  color: var(--accent-green); padding: 5px 8px; border-radius: 7px;
  font-size: 11px; font-weight: 600; cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
/* Chart icon is orange regardless of the (green) text color — the SVG uses
   stroke:currentColor, so we set the svg's own color to orange. */
.view_charts_btn svg { width: 12px; height: 12px; color: var(--accent-orange); }
.view_charts_btn:hover {
  color: var(--accent-green-soft);
  background: rgba(52, 211, 153, 0.10);
}
.view_charts_btn:hover svg { color: var(--accent-orange-soft); }

/* ── Chat bar (bottom of left panel) ─────────────────────────────
   Single pill wrapper holds the mic (left), the auto-growing textarea
   (centre) and the send button (right). Mic + send are anchored to the
   bottom so they stay aligned to the last line as the textarea grows. */
/* No top border/separator: conversation history flows directly into the
   input area for one continuous ChatGPT-style experience. */
.chat_bar {
  background: var(--panel);
  padding: 8px 12px 10px;
  display: flex;
  flex-shrink: 0;
}
.chat_input_wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 5px 6px 5px 5px;
  transition: border-color 0.15s;
}
.chat_input_wrap:focus-within { border-color: var(--accent); }
.chat_input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 7px 4px;
  font-size: 14px; font-family: inherit; line-height: 1.45;
  /* Auto-grow (JS sets height); start at one row, cap + scroll after max. */
  resize: none;
  min-height: 20px;
  max-height: 160px;
  overflow-y: auto;
}
.chat_input:focus { outline: none; }
.chat_input::placeholder { color: var(--text-mute); }

/* ── Answer workspace (center column) ──────────────────────────── */
main {
  grid-area: answer;
  overflow-y: auto;
  padding: 0;
  min-height: 0;
  background: var(--bg);
}

/* The answer card is now an unstyled flow container; each workspace
   section carries its own border/shadow (Step 4). */
.answer_card {
  display: flex; flex-direction: column;
  padding: 10px 12px 12px;
  gap: 9px;
}

/* Metadata chip row — sits above the sticky KPI block. The query title was
   removed (it's shown in the left chat panel), so this is now just a compact,
   left-aligned strip of persona / confidence / source chips; the KPI strip
   sits directly beneath it to reclaim the freed vertical space. */
.answer_header {
  display: flex; justify-content: flex-start; align-items: center;
  gap: 12px; padding: 2px 2px 0;
}
.answer_meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ── Workspace section wrapper (Step 4) ────────────────────────── */
.ws_section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.ws_head {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 12px 0; font-size: 12px; font-weight: 700; color: var(--text);
}
.ws_body { padding: 9px 12px 10px; }
/* Headless sections (charts, result table) drop the title but keep even
   top/bottom padding so content isn't flush to the border. */
.ws_section_headless .ws_body { padding: 10px 12px; }

/* ── Narration ──────────────────────────────────────────────────── */
.narration { padding: 0; background: transparent; }
.narration_headline { font-size: 13.5px; font-weight: 600; color: var(--text); margin-bottom: 7px; line-height: 1.4; }
.narration_body { font-size: 12.5px; color: var(--text-dim); line-height: 1.6; white-space: pre-line; }
.narration_body strong { color: var(--text); font-weight: 600; }
.actionables { margin-top: 10px; }
.actionables_title {
  font-size: 10px; color: var(--text-mute); text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 700; margin-bottom: 5px;
}
.actionables ul { margin: 0; padding-left: 16px; }
.actionables li { font-size: 12px; color: var(--text-dim); line-height: 1.5; }

/* ── TTS icon button ────────────────────────────────────────────── */
.tts_icon_btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 4px 10px; font-size: 15px; border-radius: 6px; cursor: pointer;
  margin-bottom: 10px; display: inline-block;
}
.tts_icon_btn:hover { background: var(--chip); border-color: var(--accent); }
.tts_icon_btn.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; }

/* ── Why section (its own card in the workspace) ─────────────────── */
.why_section {
  padding: 14px 18px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.why_toggle { font-size: 12px; color: var(--accent); cursor: pointer; font-weight: 600; }
.why_content { margin-top: 12px; display: none; }
.why_content.open { display: block; }
.why_block { margin-bottom: 12px; }
.why_block:last-child { margin-bottom: 0; }
.why_title {
  font-size: 11px; color: var(--text-mute); text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 700; margin-bottom: 6px;
}
.why_text {
  font-size: 13px; color: var(--text-dim); line-height: 1.65;
  font-family: 'JetBrains Mono', 'Consolas', monospace;
}
.why_text.business { font-family: inherit; }

/* ── Action bar ─────────────────────────────────────────────────── */
.action_bar {
  padding: 9px 12px; background: var(--panel); border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: space-between; align-items: center;
}
.audit_line { font-size: 10px; color: var(--text-mute); font-family: 'JetBrains Mono', monospace; }
.action_buttons { display: flex; gap: 8px; }

/* ── Follow-ups ─────────────────────────────────────────────────── */
.followups { padding: 9px 12px; background: var(--panel); border-top: 1px solid var(--border); }
.followups_title {
  font-size: 10px; color: var(--text-mute); text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 700; margin-bottom: 6px;
}
.followup_chips { display: flex; gap: 6px; flex-wrap: wrap; }
.followup_chip {
  background: var(--chip); padding: 5px 11px; border-radius: 14px;
  font-size: 11px; color: var(--text-dim); cursor: pointer; border: 1px solid var(--border);
}
.followup_chip:hover { background: var(--panel-2); color: var(--text); border-color: var(--accent); }

/* ── Welcome / loading states ───────────────────────────────────── */
.welcome {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; text-align: center; padding: 40px; color: var(--text-mute);
}
.welcome h2 { color: var(--text); font-size: 22px; margin-bottom: 8px; font-weight: 600; }
.welcome p { font-size: 14px; max-width: 500px; line-height: 1.6; }
.welcome_tip {
  margin-top: 20px; padding: 12px 18px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; color: var(--text-dim); max-width: 600px;
}
.loading { padding: 60px; text-align: center; color: var(--text-mute); }
.loading_dots::after { content: '.'; animation: dots 1.4s infinite; }
@keyframes dots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60% { content: '...'; }
}

/* ── Voice controls ───────────────────────────────────────────────
   Mic is the left-anchored control inside the input pill; send is the
   right-anchored control. Both sit flush to the bottom line. */
.voice_btn {
  flex-shrink: 0;
  background: none; border: none; outline: none; box-shadow: none;
  line-height: 0; padding: 6px; cursor: pointer;
  border-radius: 8px;
  color: var(--text-dim); transition: color 0.15s, background 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.voice_btn:hover { color: var(--accent); background: rgba(91,141,239,0.10); }
.voice_btn.listening { color: var(--accent); animation: pulse 1.4s infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* Send button — compact, right-anchored inside the input pill */
.send_btn {
  flex-shrink: 0;
  width: 34px; height: 34px; padding: 0;
  border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ── Edition footer banner ──────────────────────────────────────── */
.edition_banner {
  padding: 14px 24px; background: var(--panel);
  border-top: 2px dashed var(--border); margin-top: 24px;
  border-radius: var(--radius-sm);
}
.edition_banner_title {
  font-size: 11px; color: var(--text-mute); text-transform: uppercase;
  letter-spacing: 0.08em; font-weight: 700; margin-bottom: 4px;
}
.edition_banner_text { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.edition_banner code { background: var(--chip); padding: 1px 6px; border-radius: 3px; font-size: 11px; }

/* ── Error state ────────────────────────────────────────────────── */
.answer_error {
  margin: 24px; padding: 20px 24px; background: rgba(248, 113, 113, 0.08);
  border: 1px solid var(--bad); border-radius: var(--radius-sm);
  color: var(--bad); font-size: 13px; line-height: 1.6;
}
.loading { margin: 24px; }
.rail_error {
  margin: 16px; padding: 14px 16px; background: rgba(248, 113, 113, 0.08);
  border: 1px solid var(--bad); border-radius: var(--radius-sm);
  color: var(--bad); font-size: 12px; line-height: 1.5;
}
.msg_row.error .msg_bot {
  background: rgba(248, 113, 113, 0.08); border: 1px solid var(--bad); color: var(--bad);
}

/* ── Sticky KPI workspace (Step 4.1) ───────────────────────────────
   Stays pinned directly below the header while everything below scrolls. */
.kpi_workspace {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding-top: 2px;
  margin: 0 -2px;
}
.kpi_workspace.stuck { box-shadow: 0 14px 22px -14px rgba(0,0,0,0.7); }
.kpi_workspace .ws_section { border-color: var(--border); }

/* ── Insights rail (Step 6) ────────────────────────────────────── */
.insights_rail {
  grid-area: rail;
  display: flex; flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow: hidden;
  min-height: 0;
}
.rail_tabs {
  flex-shrink: 0;
  display: flex; gap: 2px; padding: 8px 8px 0; background: var(--panel-3);
  border-bottom: 1px solid var(--border);
}
.rail_tab {
  flex: 1; background: transparent; border: none; cursor: pointer;
  color: var(--text-mute); font-size: 11px; font-weight: 600;
  padding: 7px 0 8px; border-radius: 7px 7px 0 0;
  border-bottom: 2px solid transparent; transition: all 0.15s;
}
.rail_tab:hover { color: var(--text-dim); background: rgba(255,255,255,0.02); }
.rail_tab.active {
  background: var(--panel-2); color: var(--accent);
  border-bottom-color: var(--accent);
}
/* Disabled tab (e.g. Actions when a response produced no actions). */
.rail_tab.disabled {
  opacity: 0.35; cursor: default; pointer-events: none;
}
/* The rail body stacks all three cards. Cards size to their content; the
   body scrolls if the total exceeds the column height (no clipping/overlap).
   To avoid large empty gaps when content is short, the last card grows to
   absorb leftover space (see rule below). */
.rail_body {
  /* Minimal ≈7px edge margin so cards use nearly the full rail width,
     matching the left-panel density. */
  flex: 1; overflow-y: auto; padding: 8px 7px; min-height: 0;
  display: flex; flex-direction: column; gap: 8px;
}
/* Near-invisible rail scrollbar (2px), Webkit + Firefox. Scroll preserved. */
.rail_body { scrollbar-width: thin; scrollbar-color: transparent transparent; }
.rail_body:hover { scrollbar-color: var(--scroll-thumb) transparent; }
.rail_body::-webkit-scrollbar { width: 3px; }
.rail_body::-webkit-scrollbar-track { background: transparent; }
.rail_body::-webkit-scrollbar-thumb { background: transparent; border-radius: 3px; }
.rail_body:hover::-webkit-scrollbar-thumb { background: var(--scroll-thumb); }
.rail_body::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); }
.rail_placeholder { font-size: 11px; color: var(--text-mute); line-height: 1.55; padding: 6px; }

/* ── Insights-rail loading skeleton ──────────────────────────────────
   Shown from question submit until the backend responds. Status line +
   shimmering placeholder bars, styled to match the dark theme so the rail
   reads as "working" rather than showing stale content. */
.rail_status {
  font-size: 11px; font-weight: 600; color: var(--accent);
  margin-bottom: 8px; display: flex; align-items: center;
}
.skeleton_line {
  height: 9px; border-radius: 5px; margin: 6px 0;
  background: linear-gradient(90deg, var(--panel-3) 25%, var(--chip) 37%, var(--panel-3) 63%);
  background-size: 400% 100%;
  animation: skeleton_shimmer 1.4s ease infinite;
}
.skeleton_line.short { width: 60%; }
@keyframes skeleton_shimmer {
  0%   { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}
/* Loading groups keep full opacity (they aren't the "unfocused" state). */
[data-rail-group].rail_loading { opacity: 1; }

/* Each stacked section sizes to its content; it may grow but never shrinks
   below content size (flex-shrink:0) so cards can't overlap. */
[data-rail-group] { display: flex; flex-direction: column; flex: 0 0 auto; }
/* The last section absorbs remaining space so the rail feels dense. */
[data-rail-group]:last-child { flex: 1 0 auto; }

/* Context tab — key/value list */
.ctx_list { display: flex; flex-direction: column; gap: 0; }
.ctx_row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 6px 0; border-bottom: 1px dashed var(--border-soft);
}
.ctx_row:last-child { border-bottom: none; }
.ctx_row dt { font-size: 10px; color: var(--text-mute); font-weight: 600; flex-shrink: 0; }
.ctx_row dd { font-size: 11px; color: var(--text-dim); text-align: right; line-height: 1.4; }

.rail_group { display: flex; flex-direction: column; }
/* In the last (space-absorbing) section, let its card grow to fill. */
[data-rail-group]:last-child .rail_group { flex: 1; }
[data-rail-group]:last-child .rail_card { flex: 1; }
.rail_group_head {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; font-weight: 700; color: var(--text); margin-bottom: 7px;
}
.rail_group_icon {
  width: 19px; height: 19px; border-radius: 6px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 11px;
  background: var(--chip); color: var(--accent); flex-shrink: 0;
}
.rail_group.actionable .rail_group_icon { color: var(--good); }
.rail_group.recommended .rail_group_icon { color: var(--warn); }
.rail_card {
  background: var(--panel-2); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 9px 11px;
  transition: box-shadow var(--glow-timing), background-color var(--glow-timing),
              border-color var(--glow-timing);
}
/* Active (tab-focused) rail section uses the SHARED glow recipe, with a
   per-category color: Insights → blue, Actions → green, Context → cyan.
   (The recipe lives in theme.css `.is_active`; here we only pick the color
   per group and re-declare it for the .rail_card via the same values.) */
[data-rail-group="insights"] { --glow-rgb: var(--glow-insights); }
[data-rail-group="actions"]  { --glow-rgb: var(--glow-actions); }
[data-rail-group="context"]  { --glow-rgb: var(--glow-context); }
[data-rail-group].focused .rail_card {
  border-color: rgb(var(--glow-rgb, var(--glow-insights)));
  background: rgba(var(--glow-rgb, var(--glow-insights)), 0.07);
  box-shadow:
    0 0 0 1px rgba(var(--glow-rgb, var(--glow-insights)), 0.30),
    0 6px 18px -8px rgba(var(--glow-rgb, var(--glow-insights)), 0.85);
}
[data-rail-group].focused .rail_group_head { color: rgb(var(--glow-rgb, var(--glow-insights))); }
[data-rail-group] { transition: opacity 0.25s; }
[data-rail-group]:not(.focused) { opacity: 0.78; }
.rail_list { list-style: none; display: flex; flex-direction: column; gap: 7px; }
.rail_list li {
  font-size: 11.5px; color: var(--text-dim); line-height: 1.5;
  padding-left: 15px; position: relative;
}
.rail_list li::before {
  content: ''; position: absolute; left: 0; top: 6px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
}
.rail_group.actionable .rail_list li::before { background: var(--good); }
.rail_group.recommended .rail_list li::before { background: var(--warn); }
.rail_muted { font-size: 11px; color: var(--text-mute); font-style: italic; line-height: 1.5; }

/* Fold the rail below the 3-column breakpoint. Declared here (after the
   rail's own `display: flex`) so it wins the cascade — see theme.css note.
   Must match the grid breakpoint in theme.css (1400px). */
@media (max-width: 1400px) {
  .insights_rail { display: none; }
}

/* ── Methodology (inside answer workspace) ─────────────────────── */
.method_items {
  display: flex; align-items: center; gap: 8px 18px; flex-wrap: wrap;
}
.method_item {
  display: inline-flex; align-items: baseline; gap: 6px;
  font-family: 'JetBrains Mono', 'Consolas', monospace; font-size: 11px; color: var(--text-dim);
}
.method_key {
  font-family: 'Inter', sans-serif; font-weight: 600; color: var(--text-mute);
  text-transform: uppercase; letter-spacing: 0.03em; font-size: 10px;
}
