/* ──────────────────────────────────────────────────────────────────────
 * MultiMedAgent WebUI — base styles.
 *
 * Conventions:
 *  • Bilingual text is inserted by app.js via data-i18n keys; no Chinese
 *    or English strings live in this file.
 *  • All colors and spacings come from CSS variables so the frontend
 *    slice can introduce a dark theme later without rewriting selectors.
 *  • Widget-specific styles are kept minimal here; the frontend slice
 *    will extend them when implementing the chart helpers and detailed
 *    layouts.
 * ────────────────────────────────────────────────────────────────── */

/* Ensure the HTML [hidden] attribute always wins over component-level
 * display rules (e.g. .ai-plan-status { display: flex }, .dashboard-grid
 * { display: grid }). Without this rule, setting el.hidden = true in JS
 * has no visible effect on those elements because author CSS overrides
 * the user-agent [hidden] { display: none } rule at equal specificity. */
[hidden] { display: none !important; }

:root {
  --bg:           #f6f8fb;
  --surface:      #ffffff;
  --surface-alt:  #eef2f7;
  --border:       #d8dee9;
  --text:         #1f2933;
  --text-muted:   #5c6975;
  --accent:       #2f6feb;
  --accent-soft:  #e6efff;
  --success:      #2ea043;
  --warning:      #d97706;
  --danger:       #d73a49;
  --radius:       10px;
  --shadow:       0 1px 3px rgba(15, 23, 42, 0.06),
                  0 4px 12px rgba(15, 23, 42, 0.04);
  --font-sans:    -apple-system, BlinkMacSystemFont, "PingFang SC",
                  "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
                  "Noto Sans CJK SC", "Helvetica Neue", Arial, sans-serif;
  --font-mono:    "JetBrains Mono", "Cascadia Code", "Source Code Pro",
                  Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  height: 100%;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 28px; }
.brand-text h1 { font-size: 16px; margin: 0; }
.brand-text .tagline { margin: 0; color: var(--text-muted); font-size: 12px; }

.header-controls { display: flex; align-items: center; gap: 12px; }
.lang-toggle {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  font: inherit;
}
.lang-toggle:hover { background: var(--accent-soft); }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--surface-alt);
  color: var(--text-muted);
}
.pill-muted   { background: var(--surface-alt);  color: var(--text-muted); }
.pill-success { background: #e6f6ea; color: var(--success); }
.pill-warn    { background: #fef3c7; color: var(--warning); }
.pill-danger  { background: #ffeaee; color: var(--danger); }

/* Header pill that names the currently-selected session. Click to
   jump to the Sessions tab; hidden when no session is selected. */
.pill-session {
  background: var(--accent-soft, #e8f0fe);
  color: var(--accent, #1a56db);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pill-session:hover { border-color: var(--accent, #1a56db); }
.pill-session .pill-icon { font-size: 0.9em; line-height: 1; }
.pill-session #current-session-pill-label {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 230px;
}

/* Empty-state overlay shown on Intake / Dashboard / Report panels
   when no session is selected. Sessions tab is never gated. The
   overlay is hidden by default; the .is-empty class on the panel
   reveals it AND hides every other direct child of the panel. */
.panel-empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 64px 24px;
  gap: 16px;
  color: var(--text-muted);
}
.panel-empty-state h2 {
  margin: 0;
  color: var(--text);
  font-weight: 600;
}
.panel-empty-state p { margin: 0; max-width: 32em; }
.panel-empty-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}
.panel.is-empty > *:not(.panel-empty-state) { display: none !important; }
.panel.is-empty > .panel-empty-state { display: flex; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 24px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tab {
  appearance: none;
  border: none;
  padding: 10px 16px;
  background: transparent;
  font: inherit;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
}
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.layout {
  position: relative;
  height: calc(100vh - 110px);
  overflow: hidden;
}

.panel {
  display: none;
  height: 100%;
  overflow: auto;
  padding: 16px 24px;
}
.panel.is-active { display: block; }

/* ── Intake panel ──────────────────────────────────────────────── */

.panel-intake {
  display: none;
  /* Two-column intake: chat on the left, requirements + plan on the
   * right. Each column is a flex stack whose children manage their
   * own internal scroll, so the chat input form stays pinned at the
   * bottom-left and the requirements/plan boxes never overflow the
   * panel. ``minmax(0, 1fr)`` is critical — without it the grid
   * tracks would refuse to shrink below their content min size and
   * we'd get horizontal overflow on long markdown.
   */
  height: 100%;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: 1fr;
  gap: 16px;
}
.panel-intake.is-active { display: grid; }
.panel-intake > .panel-empty-state { grid-column: 1 / -1; }
/* The panel itself should NOT scroll — every column owns its own
 * overflow. Otherwise we end up with three nested scroll regions
 * competing for the wheel event. */
.panel.panel-intake.is-active { overflow: hidden; }

.intake-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  min-width: 0;
}

/* Left column: chat history grows, status pill + form are auto. */
.intake-col-left > #chat-history { flex: 1 1 0; min-height: 0; }
.intake-col-left > #ai-plan-status,
.intake-col-left > #chat-form { flex: 0 0 auto; }

/* Right column: requirements preview + (Loop-C) doctor summary share
 * the column. ``flex: 1 1 0`` on each means they evenly split the
 * available height; a hidden details element collapses (``display:
 * none``) so the visible one takes the whole column.
 *
 * Details panels normally lay out as a block, but we need their
 * markdown bodies to fill the flex cell — turn them into nested flex
 * columns and let the body grow. */
/* Right column: ONE tabbed box that swaps between the live
 * requirements draft (Loops A/B) and the AI-generated plan summary
 * (Loop C onwards). Both views share the same card chrome, so the
 * column never wastes space on a second outline. */
.intake-right-box {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.intake-right-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}
.intake-right-tab {
  appearance: none;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 12px;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.intake-right-tab:hover:not(:disabled) { color: var(--text); }
.intake-right-tab.is-active {
  color: var(--accent, #1a56db);
  border-bottom-color: var(--accent, #1a56db);
}
.intake-right-tab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.intake-right-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-right: 4px;
}
.intake-right-actions > .btn {
  padding: 6px 14px;
  font-size: 13px;
}
.intake-right-view {
  flex: 1 1 auto;
  min-height: 0;
  display: none;
  flex-direction: column;
}
.intake-right-view.is-active { display: flex; }
.intake-right-view > .preview-hint {
  margin: 12px 16px 0;
  font-size: 12px;
  color: var(--text-muted);
  flex: 0 0 auto;
}
.intake-right-view > .markdown-body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  padding: 8px 16px 16px;
  overflow: auto;
}

/* The legacy details elements (kept in DOM only for ID backward
 * compat) must not contribute to layout. */
.intake-col-right > details#requirements-preview,
.intake-col-right > details#doctor-summary {
  display: none !important;
}
/* Legacy slots panel hidden by ``hidden`` attribute; double-belt:
 * also exclude it from the flex column so its (empty) margin doesn't
 * push siblings. */
.intake-col-right > #slots-display { display: none; }

/* Responsive: collapse to a single column on tablets / phones so the
 * layout stays usable. Cap the markdown body height in this mode to
 * preserve the "form pinned at the bottom" invariant the single-
 * column layout used to need. */
@media (max-width: 900px) {
  .panel-intake.is-active {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 1fr;
  }
  .intake-right-box {
    flex: 0 0 auto;
    max-height: 50vh;
  }
  .intake-right-view > .markdown-body {
    max-height: 32vh;
  }
}

.chat-history {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* min-height: 0 lets the 1fr grid track shrink the chat box so it
   * scrolls internally instead of pushing the form below the fold.
   * The visual minimum is enforced by the grid template (minmax(120px, 1fr)). */
  min-height: 0;
}
.chat-message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  white-space: pre-wrap;
}
.chat-message.user      { align-self: flex-end; background: var(--accent-soft); }
.chat-message.assistant { align-self: flex-start; background: var(--surface-alt); }
.chat-message.system    { align-self: center; background: transparent;
                          color: var(--text-muted); font-size: 12px; }

.slots-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.slots-panel > summary {
  cursor: pointer;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  list-style: none;
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  gap: 8px;
}
.slots-panel > summary::-webkit-details-marker { display: none; }
.slots-panel > summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 0.15s;
}
.slots-panel[open] > summary::before { transform: rotate(90deg); }
.slots-panel dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  margin: 0;
  padding: 8px 16px 12px;
  max-height: 160px;
  overflow: auto;
}
.slots-panel dt { color: var(--text-muted); }
.slots-panel dd { margin: 0; }
.slots-panel .slot-empty { color: #b0b8c1; font-style: italic; }

/* Requirements preview — the live markdown draft the conversational
   agent (webui.requirements_agent) maintains. Replaces the legacy
   slots checklist in Loop A. */
.requirements-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.requirements-preview > summary {
  cursor: pointer;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 13px;
  list-style: none;
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}
.requirements-preview > summary::-webkit-details-marker { display: none; }
.requirements-preview > summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 0.15s;
  color: var(--text-muted);
}
.requirements-preview[open] > summary::before { transform: rotate(90deg); }
.requirements-status-pills {
  display: inline-flex;
  gap: 6px;
  margin-left: auto;
}
.requirements-status-pills .pill {
  font-size: 11px;
  padding: 2px 8px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
.requirements-preview .preview-hint {
  margin: 8px 16px 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.requirements-preview .markdown-body {
  padding: 8px 16px 16px;
  /* Cap at ~32% of viewport so it never crowds out the chat box
   * or pushes the chat-form off-screen. Internal scroll handles
   * longer drafts. */
  max-height: 32vh;
  min-height: 80px;
  overflow: auto;
}
.requirements-preview .preview-empty {
  margin: 0;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 16px;
}
.requirements-preview .markdown-body h1 { font-size: 1.1em; margin: 0 0 8px; }
.requirements-preview .markdown-body h2 { font-size: 1em; margin: 12px 0 6px; color: var(--accent, #1a56db); }
.requirements-preview .markdown-body h3 { font-size: 0.95em; margin: 8px 0 4px; }
.requirements-preview .markdown-body p,
.requirements-preview .markdown-body li { font-size: 0.9em; line-height: 1.5; margin: 4px 0; }
.requirements-preview .markdown-body ul,
.requirements-preview .markdown-body ol { padding-left: 1.5em; margin: 4px 0; }
.requirements-preview .markdown-body code { font-size: 0.85em; }

/* AI-plan generation status (spinner shown while approve-plan is in flight). */
.ai-plan-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
}
.ai-plan-status .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: ai-spinner-rotate 0.8s linear infinite;
  display: inline-block;
}
@keyframes ai-spinner-rotate { to { transform: rotate(360deg); } }

/* ── Plan / doctor-summary preview panels ─────────────────────── */

.preview-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
}
.preview-panel[open] { box-shadow: var(--shadow); }
.preview-panel > summary {
  cursor: pointer;
  padding: 12px 16px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  list-style: none;
  background: var(--surface-alt);
  border-bottom: 1px solid transparent;
}
.preview-panel > summary::-webkit-details-marker { display: none; }
.preview-panel[open] > summary { border-bottom-color: var(--border); }
.preview-panel > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.15s;
}
.preview-panel[open] > summary::before { transform: rotate(90deg); }
.preview-actions { display: inline-flex; gap: 6px; }
.preview-hint {
  margin: 12px 16px 0;
  color: var(--text-muted);
  font-size: 13px;
}
.summary-panel > summary { background: #e9f6ee; color: #186232; }
.summary-panel[open] > summary { border-bottom-color: #c6e6d0; }

.markdown-body {
  padding: 12px 20px 18px;
  max-height: 220px;
  overflow: auto;
  line-height: 1.55;
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3 { margin: 14px 0 6px; }
.markdown-body h1 { font-size: 18px; }
.markdown-body h2 { font-size: 16px; }
.markdown-body h3 { font-size: 14px; color: var(--text-muted); }
.markdown-body p  { margin: 6px 0; }
.markdown-body ul,
.markdown-body ol { margin: 6px 0 6px 20px; padding: 0; }
.markdown-body li { margin: 2px 0; }
.markdown-body code {
  background: var(--surface-alt);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.92em;
}
.markdown-body pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px;
  border-radius: 6px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  margin: 8px 0;
}
.markdown-body pre code { background: transparent; color: inherit; padding: 0; }
.markdown-body blockquote {
  margin: 6px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.btn-ghost:hover { background: var(--surface); }

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
}
.chat-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 56px;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font: inherit;
  background: var(--surface);
}
.chat-actions { display: flex; flex-direction: column; gap: 6px; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px 16px;
  font: inherit;
  cursor: pointer;
}
.btn:hover { background: var(--surface-alt); }
.btn-primary  { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover  { filter: brightness(1.05); }
.btn-success  { background: var(--success); color: white; border-color: var(--success); }
.btn-warning  { background: var(--warning); color: white; border-color: var(--warning); }
.btn-danger   { background: var(--danger);  color: white; border-color: var(--danger); }

/* ── Dashboard panel ───────────────────────────────────────────── */

.dashboard-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 32px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "headline   headline"
    "pipeline   pipeline"
    "tasks      primary"
    "tasks      activity"
    "compute    activity";
  gap: 12px;
  /* Fixed dashboard height: panel height MINUS the folded
   * console drawer (its card chrome + summary line + top-margin).
   * The grid never shrinks when the console expands because its
   * height is anchored to the FOLDED console size; opening the
   * drawer just pushes the panel's total content past the
   * viewport so the panel scrolls instead of squeezing the
   * widgets above. The 50 px allowance = ~38 px folded card
   * (8 px padding + ~20 px summary + 8 px padding + 1 px border × 2)
   * + 12 px margin. */
  height: calc(100% - var(--console-collapsed-h, 50px));
  min-height: 0;
  /* Three middle rows share leftover height with weighted shares
   * — primary metric card is the shortest (wide-aspect SVG looks
   * better in a low card), compute card is the tallest so the
   * GPU/CPU cards have room to breathe. */
  grid-template-rows: auto auto 0.7fr 1fr 1.3fr;
}
/* Panel is plain block flow with overflow:auto. The dashboard
 * grid above fills 100% - console-collapsed-h, the console
 * below is content-sized. Folded total = exactly viewport;
 * opened total > viewport → scroll. */
.panel-dashboard {
  overflow: auto;
}
@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "headline" "pipeline" "tasks" "primary" "activity" "compute";
    /* On narrow screens give up on the viewport-fit and let the
     * page scroll instead — there's no useful way to fit 6+
     * stacked widgets into one screen. */
    height: auto;
    min-height: 0;
  }
  .widget { overflow: visible; }
}

.widget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  /* Every widget is a vertical flex container so its inner body
   * can flex-fill the card and scroll internally. ``min-height: 0``
   * + ``overflow: hidden`` are required for the children's
   * ``overflow: auto`` rules to actually kick in inside a fixed-
   * height grid cell (see ``.dashboard-grid``). */
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.widget h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex: 0 0 auto;
}

.widget-headline {
  grid-area: headline;
  /* Override the column flex direction inherited from .widget so
   * the headline keeps its left-to-right layout. */
  flex-direction: row;
  align-items: center;
  gap: 16px;
  /* Headline never scrolls and has fixed height; let it visibly
   * overflow any tooltips. */
  overflow: visible;
}
.widget-headline h2 { margin: 0; font-size: 18px; flex: 1; }
.widget-pipeline {
  grid-area: pipeline;
  overflow: visible;  /* the stepper is short; no internal scroll */
}
.widget-tasks    { grid-area: tasks; }
.widget-primary  {
  grid-area: primary;
}
.widget-primary > svg {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: 100%;
}
.widget-activity {
  grid-area: activity;
}
.widget-activity > h3 { flex: 0 0 auto; }
.widget-activity > .activity-feed {
  flex: 1 1 auto;
  min-height: 0;
}
.widget-compute  { grid-area: compute; }
.widget-compute > .compute-grid {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}
/* Live console drawer — uses the standard ``.widget`` card chrome
 * (border, background, padding, shadow) for visual consistency
 * with the other dashboard widgets. Behaviour overrides:
 * - ``overflow: visible`` so the ``<details>`` can expand into a
 *   scrollable ``<pre>`` without being clipped.
 * - ``margin-top`` matches the ``--console-collapsed-h`` allowance
 *   reserved in ``.dashboard-grid`` so the folded card sits flush
 *   below the last widget row.
 * - Tighter padding than the default ``.widget`` since the drawer
 *   is a thin toggle, not a full content card.
 * - ``display: block`` so the ``<details>`` flows naturally
 *   (summary at top, <pre> below) rather than as a flex column. */
.widget-console {
  margin-top: 12px;
  padding: 8px 16px;
  overflow: visible;
  display: block;
  font-family: var(--font-mono);
}
.widget-console > summary {
  cursor: pointer;
  padding: 2px 0;
  /* Match the other widget card titles (see ``.widget h3``):
   * 13 px uppercase muted with letter-spacing. ``<h3>``'s
   * browser-default bold weight is inherited there; replicate it
   * here so the live-console title visually weighs the same. */
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.widget-console > summary::-webkit-details-marker { display: none; }
.widget-console > summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 120ms ease;
}
.widget-console[open] > summary::before { transform: rotate(90deg); }
.widget-console > pre,
.widget-console > #console-tail {
  margin-top: 6px;
  /* existing global rule (~line 1370) caps height at 260 px with
   * overflow:auto — keeps the drawer a fixed footprint. */
}
.widget-console > a {
  display: inline-block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.overall-progress {
  flex: 1.5;
  height: 8px;
  background: var(--surface-alt);
  border-radius: 999px;
  overflow: hidden;
}
.overall-progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width 200ms ease;
}
.headline-actions { display: flex; gap: 8px; }

.pipeline-stepper {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.pipeline-stepper li {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  font-size: 12px;
  color: var(--text-muted);
  padding: 0;
}
.pipeline-step-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  background: transparent;
  border: none;
  border-top: 4px solid var(--surface-alt);
  padding: 6px 4px 4px;
  font: inherit;
  color: inherit;
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 0.12s ease;
}
.pipeline-step-btn:hover { background: var(--surface-alt); }
.pipeline-step-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.pipeline-stepper li.s-running .pipeline-step-btn { border-top-color: var(--accent); color: var(--accent); }
.pipeline-stepper li.s-done    .pipeline-step-btn { border-top-color: var(--success); color: var(--success); }
.pipeline-stepper li.s-warning .pipeline-step-btn { border-top-color: var(--warning); color: var(--warning); }
.pipeline-stepper li.s-failed  .pipeline-step-btn { border-top-color: var(--danger); color: var(--danger); }
.pipeline-stepper li.is-selected .pipeline-step-btn {
  background: var(--accent-soft, #eef4ff);
  box-shadow: inset 0 -3px 0 var(--accent);
}

.task-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  /* Pack cards to the top of each row instead of stretching them to
   * match the tallest card in the row. Without this the cards in a
   * wide window grow to fill any extra row height, distributing the
   * slack as space between their inner rows. */
  align-items: start;
  /* And pack the rows of cards themselves to the top of the grid
   * container so an underfull grid (one short row of cards inside a
   * tall widget) doesn't get its inter-row gap blown up by the
   * default ``align-content: stretch`` distributing the slack. */
  align-content: start;
}
.task-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--surface-alt);
}
.task-card h4 { margin: 0; font-size: 14px; display: flex; justify-content: space-between; align-items: center; }

/* ``max-height`` cap removed in favour of the flex-fill rule on
 * ``.widget-activity`` so the feed claims the full card height and
 * scrolls internally — the prior 280-px cap left blank space inside
 * the (much taller) widget card. */
.activity-feed { list-style: none; margin: 0; padding: 0; overflow: auto; }
.activity-feed li {
  padding: 6px 4px;
  border-bottom: 1px dashed var(--surface-alt);
  font-size: 13px;
  cursor: pointer;
}
.activity-feed li:hover { background: var(--accent-soft); }

.compute-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.compute-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: var(--surface-alt);
  font-size: 13px;
}

.widget-console summary { cursor: pointer; font-family: var(--font-sans); font-size: 13px; color: var(--text-muted); text-transform: uppercase; }
.widget-console pre { max-height: 220px; overflow: auto; font-size: 12px; background: #0f172a; color: #cbd5f5; padding: 10px; border-radius: var(--radius); }

.audit-fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.audit-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 90vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 10;
  display: flex;
  flex-direction: column;
}
.audit-drawer header { display: flex; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.audit-drawer header h3 { margin: 0; font-size: 14px; }
.audit-drawer #audit-events { flex: 1; overflow: auto; padding: 8px 12px; font-size: 13px; }
#audit-close { appearance: none; background: none; border: none; font-size: 20px; cursor: pointer; }

/* ── Report panel ──────────────────────────────────────────────── */

.panel-report .report-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  justify-content: flex-end;
}
.panel-report iframe {
  width: 100%;
  height: calc(100vh - 200px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
}

/* ── Report split layout (chat + iframe side-by-side) ────────── */

/* The .panel base rule is ``display: none`` flipped to ``block``
 * by .is-active; only override when active so the panel stays
 * hidden on Sessions / Intake / Dashboard tabs. */
#panel-report.panel-report-split.is-active { display: block; }
.report-split-container {
  display: flex;
  gap: 14px;
  align-items: stretch;
  height: calc(100vh - 120px);
}
.report-chat {
  flex: 0 0 360px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 0;  /* allow inner flex item to scroll */
}
.report-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.report-chat-header h3 {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.report-chat-history {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
}
.report-chat-empty {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  margin: auto 0;
  padding: 16px;
}
.report-chat-bubble {
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 13px;
  max-width: 100%;
  word-wrap: break-word;
  line-height: 1.4;
}
.report-chat-bubble .bubble-meta {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.bubble-user {
  background: #e6f0ff;
  border: 1px solid #cfe0ff;
  align-self: flex-end;
  margin-left: 28px;
}
.bubble-agent {
  background: white;
  border: 1px solid var(--border);
  align-self: flex-start;
  margin-right: 28px;
}
.bubble-system {
  background: #fafafa;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-style: italic;
  align-self: stretch;
}
.bubble-stale,
.bubble-cancelled {
  opacity: 0.6;
}
.bubble-failed { border-color: #f0bdbd; background: #fdf1f1; }
.bubble-no_op  { background: #f3fbf3; border-color: #c7ebd2; color: var(--success); }
.report-agent-status {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 6px;
  min-height: 18px;
}
.report-agent-status.is-running { color: var(--accent); }
.report-agent-status.is-failed { color: var(--danger); }
.report-agent-status.is-ready { color: var(--success); }
.report-chat-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.report-chat-input {
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
  min-height: 64px;
}
.report-chat-form button {
  align-self: flex-end;
}
.report-render {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.report-render iframe {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
}
.report-version-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid #cfe0ff;
  font-variant-numeric: tabular-nums;
}

/* Stack vertically on narrow viewports. */
@media (max-width: 900px) {
  .report-split-container {
    flex-direction: column;
    height: auto;
  }
  .report-chat {
    flex: 1 1 auto;
    max-height: 50vh;
  }
}

/* ── Login page ────────────────────────────────────────────────── */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--accent-soft), #ffffff);
}
.login-card {
  background: var(--surface);
  padding: 32px 40px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.login-card h1 { margin: 0 0 16px; }
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font: inherit;
  margin-bottom: 12px;
}
.login-card button {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: white;
  font: inherit;
  cursor: pointer;
}
.login-card .hint { font-size: 12px; color: var(--text-muted); }
.login-card .error { color: var(--danger); margin-top: 8px; }

/* ── Frontend slice widgets ─────────────────────────────────────── */
.conn-connecting { background: var(--surface-alt); color: var(--text-muted); }
.conn-live { background: #e6f6ea; color: var(--success); }
.conn-reconnecting { background: #fef3c7; color: var(--warning); }
.conn-closed { background: #ffeaee; color: var(--danger); }
.conn-stale { background: #fff7ed; color: var(--warning); }
.conn-history { background: #e0e7ff; color: #3730a3; }

@media (min-width: 1280px) {
  .dashboard-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-areas:
      "headline headline headline headline"
      "pipeline pipeline pipeline pipeline"
      "tasks tasks primary activity"
      "tasks tasks compute activity";
    /* 4 area rows. Primary is in row 3, compute in row 4 — give
     * compute the larger share so its GPU cards have room. */
    grid-template-rows: auto auto 0.7fr 1.3fr;
  }
}
@media (min-width: 768px) and (max-width: 1279px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "headline headline"
      "pipeline pipeline"
      "tasks primary"
      "tasks activity"
      "compute activity";
    /* 5 area rows. Primary (row 3) gets the smallest share,
     * compute (row 5) the largest — matches the base rule. */
    grid-template-rows: auto auto 0.7fr 1fr 1.3fr;
  }
}
@media (max-width: 767px) {
  .app-header, .tabs { padding-left: 12px; padding-right: 12px; }
  .panel { padding: 12px; }
  .widget-headline { align-items: stretch; flex-direction: column; }
  .headline-actions { flex-wrap: wrap; }
  .dashboard-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "headline" "pipeline" "tasks" "primary" "activity" "compute";
    /* Stacked single column on mobile: let each widget size to
     * content and the page scroll. */
    grid-template-rows: none;
    height: auto;
    min-height: 0;
  }
  .pipeline-stepper { grid-template-columns: 1fr; }
}

.headline-info { color: var(--text); }
.headline-success { color: var(--success); }
.headline-warning, .headline-warn { color: var(--warning); }
.headline-error, .headline-failed { color: var(--danger); }

.pipeline-step { min-height: 82px; background: #fff; border-radius: 8px; padding: 8px 6px; }
.pipeline-step .step-icon { font-size: 18px; }
.pipeline-step .step-name { font-weight: 600; text-align: center; }
.step-duration, .step-eta { font-size: 11px; color: var(--text-muted); }
.step-empty { grid-column: 1 / -1; cursor: default; }

/* "Report regenerating" / "Report failed" / "v3" badge attached to
 * the Report stepper card so the dashboard shows live progress when
 * the user (re-)triggers report generation from the Report tab. */
.step-report-badge {
  display: inline-block;
  margin-top: 2px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.step-report-badge.step-report-running {
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid #cfe0ff;
  animation: stepReportPulse 1.4s ease-in-out infinite;
}
.step-report-badge.step-report-failed {
  color: var(--danger);
  background: #fdf1f1;
  border: 1px solid #f0bdbd;
}
.step-report-badge.step-report-ready {
  color: var(--success);
  background: #f0faf3;
  border: 1px solid #c7ebd2;
}
@keyframes stepReportPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.pipeline-step .step-count {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-alt);
  border-radius: 999px;
  padding: 1px 7px;
}
.pipeline-step .step-variants {
  display: inline-flex;
  gap: 4px;
  margin-top: 2px;
  align-items: center;
  justify-content: center;
}
.step-variant-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
}
.step-variant-dot.s-running { background: var(--accent); animation: variant-pulse 1.2s ease-in-out infinite; }
.step-variant-dot.s-done    { background: var(--success); }
.step-variant-dot.s-warning { background: var(--warning); }
.step-variant-dot.s-failed  { background: var(--danger); }
@keyframes variant-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* Sessions row — title + inline rename */
.session-row-title-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.session-row-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  max-width: 100%;
}
.session-row-started { font-size: 12px; color: var(--text-muted); }
.session-row-last { font-size: 12px; color: var(--text-muted); }
.session-rename-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 13px;
  opacity: 0.55;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}
.session-rename-btn:hover:not(:disabled) { opacity: 1; background: var(--surface-alt); }
.session-rename-btn:disabled { cursor: not-allowed; opacity: 0.25; }
.session-rename-input {
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  padding: 2px 6px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  min-width: 200px;
  max-width: 100%;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
}
.status-pending, .status-queued { background: var(--surface); color: var(--text-muted); }
.status-running, .status-training, .status-tuning { background: var(--accent-soft); color: var(--accent); }
.status-done, .status-succeeded { background: #e6f6ea; color: var(--success); }
.status-warning { background: #fef3c7; color: var(--warning); }
.status-failed, .status-stopped_by_user { background: #ffeaee; color: var(--danger); }
.status-border-running, .status-border-training, .status-border-tuning { border-color: var(--accent); }
.status-border-done { border-color: var(--success); }
.status-border-failed { border-color: var(--danger); }

/* Use flex column instead of grid so the rows always pack at the
 * top of the card. With ``display: grid`` the (default) row
 * distribution algorithm spread extra height between rows when
 * ``.task-grid``'s auto-stretch made the card taller than its
 * content — producing the "rows drift apart when the window is
 * wide" symptom. Flex column never stretches the gaps, only the
 * items if we explicitly opt in. */
.task-card { display: flex; flex-direction: column; gap: 6px; }
.task-metric, .task-target, .task-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  line-height: 1.35;
  flex: 0 0 auto;
}
.task-card > h4 { flex: 0 0 auto; }
/* The metric chart sits between ``task-target`` and ``task-foot``
 * and gets a small visual buffer above and below. It scales
 * proportionally with its viewBox (see ``.metric-chart``) so it
 * never distorts when the card resizes. */
.task-card > .metric-chart,
.task-card > .metric-chart-empty {
  margin: 4px auto;
  flex: 0 0 auto;
}
.metric-delta { font-weight: 600; }
.delta-good { color: var(--success); }
.delta-bad { color: var(--danger); }
.delta-none { color: var(--text-muted); }
/* Training-stage summary banner (above the task grid) */
.training-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 10px;
  align-items: center;
}
.training-summary .ts-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.training-summary .ts-done { color: var(--success); border-color: #c7ebd2; background: #f0faf3; }
.training-summary .ts-running { color: var(--accent); border-color: #cfe0ff; background: #eef4ff; }
.training-summary .ts-queued { color: var(--text-muted); }
.training-summary .ts-elapsed { color: var(--text-muted); }
/* "🎯 N/total targets met" pill — green when all met, amber when
 * only some met. Distinct from .ts-done (training-variant count)
 * because clinicians care about outcome, not training attempts. */
.training-summary .ts-targets-met { color: var(--success); border-color: #c7ebd2; background: #f0faf3; }
.training-summary .ts-targets-partial { color: #b78103; border-color: #f4e2a4; background: #fdf6e0; }
.training-summary-idle {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
}

/* ─── Report stage detail panel ──────────────────────────────── */

.report-stage-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.report-stage-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding: 6px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
}
.report-stage-header .rs-header-status {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  margin: 0 4px;
  font-size: 11px;
}
.report-stage-header.is-running .rs-header-status {
  color: var(--accent);
  background: var(--accent-soft);
}
.report-stage-header.is-ready .rs-header-status {
  color: var(--success);
  background: #f0faf3;
}
.report-stage-header.is-failed .rs-header-status {
  color: var(--danger);
  background: #fdf1f1;
}
.report-stage-header .rs-header-sub {
  display: block;
  font-weight: 400;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.report-stage-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.report-stage-grid .rs-task {
  display: grid;
  grid-template-columns: 16px 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.report-stage-grid .rs-task-status { font-size: 14px; }
.report-stage-grid .rs-task-name { font-weight: 600; }
.report-stage-grid .rs-task-metric { color: var(--text-muted); font-size: 12px; }
.report-stage-grid .rs-task-cohort { color: var(--text-muted); font-size: 12px; }
.report-stage-grid .rs-task.is-failed { border-left: 3px solid var(--danger); }
.report-stage-grid .rs-task.is-skipped { border-left: 3px solid #b78103; }
.report-stage-grid .rs-task.is-ok { border-left: 3px solid var(--success); }

.report-stage-timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.report-stage-timeline li {
  display: grid;
  grid-template-columns: 70px auto 1fr;
  gap: 6px;
  padding: 3px 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.report-stage-timeline .rs-ts { color: var(--text-muted); }
.report-stage-timeline .rs-phase { font-weight: 600; }
.report-stage-timeline .rs-detail { color: var(--text-muted); }
.report-stage-timeline li.is-failed { border-left: 3px solid var(--danger); }
.report-stage-timeline li.is-ready { border-left: 3px solid var(--success); }

.report-stage-chat-preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.report-stage-chat-preview .rs-chat-empty {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: 8px;
}
.report-stage-chat-preview .rs-chat-bubble {
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}
.report-stage-chat-preview .rs-chat-bubble strong {
  display: inline-block;
  margin-right: 6px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.04em;
}

.report-stage-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}
.evaluation-section-title {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.evaluation-rounds {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.evaluation-round {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}
.eval-round-icon { font-size: 14px; }
.eval-round-label { font-weight: 600; }
.eval-round-duration {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.evaluation-round-empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
  padding: 8px 2px;
}

/* ─── Stage detail panel sizing ──────────────────────────────────
 * The widget that hosts Stage detail (#w-tasks) is sized by the
 * dashboard grid to share vertical space with the primary-metric
 * chart + activity feed on the right. Without explicit flex rules
 * the inner sub-panel collapses to its content height — e.g. the
 * "no detail" placeholder used to leave a thin band of text with
 * a lot of empty card around it. Make the widget a column flex
 * container so the active sub-panel always fills it.
 */
.widget-tasks {
  /* min-height: 360px removed — the viewport-fit dashboard grid
   * now sizes this widget via ``grid-template-rows: 1fr`` so the
   * widget gets its share of the available height automatically.
   * The flex column setup is inherited from the generic ``.widget``
   * rule. */
}
.widget-tasks > h3,
.widget-tasks > .stage-detail-header { flex: 0 0 auto; }
.widget-tasks > .stage-subpanel:not([hidden]) {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-top: 4px;
}
/* The scrollable content of each sub-panel takes the rest of the
 * column; the placeholder uses centered layout instead of leaving
 * the empty band at the top. The Training & Evaluation panel
 * (#tasks-panel) is itself the scroll container because it has
 * multiple stacked sections (task-grid + optional rounds list).
 * Same goes for #report-stage-panel (header + tasks grid +
 * timeline + chat preview can easily overflow). */
#tasks-panel,
#report-stage-panel,
#codegen-panel > .codegen-body,
#preprocess-panel > .preprocess-list,
#plan-panel > .plan-summary {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}
.stage-placeholder.stage-subpanel:not([hidden]),
.stage-empty {
  align-items: center;
  justify-content: center;
  text-align: center;
}
.stage-subpanel > .stage-empty {
  flex: 1 1 auto;
  display: flex;
}

/* ─── Preprocess sub-panel ───────────────────────────────────── */
.preprocess-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.preprocess-item {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.preprocess-head {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}
.preprocess-icon { font-size: 16px; }
.preprocess-name { font-weight: 600; color: var(--text); }
.preprocess-duration { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.preprocess-description {
  margin: 4px 0 6px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}
.preprocess-script {
  display: flex;
  gap: 6px;
  align-items: baseline;
  font-size: 12px;
  color: var(--text-muted);
}
.preprocess-script code {
  font-family: var(--font-mono);
  background: var(--surface);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  word-break: break-all;
}
.preprocess-label { white-space: nowrap; }

/* ─── Metric chart (replaces .sparkline) ─────────────────────── */
/* The chart scales **proportionally** with width — its viewBox
 * controls the intrinsic aspect ratio and ``height: auto`` lets
 * the browser keep the line plot's shape no matter how wide the
 * card becomes. ``max-width`` keeps the chart from blowing up on
 * very wide cards (no point making the line plot 800 px wide when
 * the card might be that wide on a 4-K screen). */
.metric-chart {
  display: block;
  width: 100%;
  height: auto;
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
  background: transparent;  /* fixes the "white bar" — empty SVG no longer shows a card */
  border-radius: 6px;
  overflow: visible;
}
.metric-chart.is-large {
  max-width: none;
}
.metric-chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}
.metric-chart-point {
  fill: var(--accent);
  stroke: var(--surface);
  stroke-width: 2;
}
.metric-chart .chart-grid {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 2 3;
  opacity: 0.6;
}
.metric-chart .chart-target-line {
  stroke: var(--danger);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}
.metric-chart .chart-tick,
.metric-chart .chart-axis-label {
  fill: var(--text-muted);
  font-size: 11px;
  font-family: var(--font-sans);
}
.metric-chart-empty {
  height: 80px;
  width: 100%;
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  border: 1px dashed var(--border);
  border-radius: 6px;
}
.metric-chart-empty.is-large { height: 220px; max-width: none; }

/* Keep the old .sparkline class around for any code paths still
 * using it, but drop the white background so any straggler also
 * benefits from the white-bar fix. */
.sparkline { background: transparent; }

#primary-chart {
  width: 100%;
  height: 100%;
  min-height: 0;  /* the widget cell controls the height now */
  font-family: var(--font-sans);
}
.chart-axis { stroke: var(--border); stroke-width: 1; }
.chart-bar { fill: var(--accent); opacity: 0.85; }
.chart-target { stroke: var(--danger); stroke-width: 2; stroke-dasharray: 4 3; }
/* SVG text uses ``font-size`` in user (viewBox) units; the primary
 * chart's viewBox is ``0 0 600 200``, so 12 used to render very
 * small once the SVG was scaled into a card that's narrower than
 * 600 px. 14 is a comfortable readable size without dominating
 * the chart. */
.chart-label, .chart-value, .chart-empty {
  fill: var(--text-muted);
  font-size: 14px;
}
.chart-value { fill: var(--text); font-weight: 600; }

.activity-feed { font-family: var(--font-sans); }
.activity-item { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: start; }
.activity-icon { width: 22px; text-align: center; }
.activity-text { display: grid; gap: 2px; }
.activity-text strong { color: var(--text); font-weight: 600; }
.activity-text small { color: var(--text-muted); line-height: 1.35; }
.activity-item time, .audit-entry time { color: var(--text-muted); font-size: 11px; white-space: nowrap; }

.compute-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.compute-card h4 { margin: 0 0 8px; font-size: 13px; }
.compute-meta { margin-top: 6px; color: var(--text-muted); }
.meter { height: 7px; background: #fff; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin: 4px 0 8px; }
.meter span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--success)); }
.empty-state { color: var(--text-muted); font-size: 13px; padding: 8px 0; }
.compute-empty { display: flex; align-items: center; }

.widget-console pre, #console-tail {
  /* Roomier expanded drawer — was 260 px; bumped so the user can
   * see a meaningful chunk of the log without scrolling. ``50vh``
   * caps it at half the viewport on small screens so the drawer
   * never grows past sensible bounds. */
  max-height: min(50vh, 480px);
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.45;
  background: #0f172a;
  color: #dbeafe;
  padding: 12px;
  border-radius: var(--radius);
  white-space: pre-wrap;
}

.audit-entry { border-bottom: 1px solid var(--surface-alt); padding: 8px 0; }
.audit-entry summary { cursor: pointer; }
.audit-entry pre {
  overflow: auto;
  background: #0f172a;
  color: #dbeafe;
  border-radius: 8px;
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
}

/* ── Active runs badge + Sessions tab ─────────────────────────── */

#active-runs-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--success);
  color: var(--success);
  background: #e6f6ea;
  cursor: pointer;
  padding: 3px 12px;
  font-weight: 600;
  font-size: 12px;
  font: inherit;
  border-radius: 999px;
}
#active-runs-badge .badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: badge-pulse 1.4s ease-in-out infinite;
  display: inline-block;
}
@keyframes badge-pulse {
  0%,100% { opacity: 1; }
  50%     { opacity: 0.35; }
}
#active-runs-badge:hover { filter: brightness(0.97); }

.panel-sessions {
  padding: 16px 24px;
  overflow: auto;
}
.sessions-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.sessions-toolbar h2 { margin: 0; font-size: 18px; }
.sessions-toolbar-actions { display: flex; gap: 8px; align-items: center; }
.sessions-hint {
  margin: 8px 0 16px;
  color: var(--text-muted);
  font-size: 13px;
}
.btn-compact { padding: 4px 10px; font-size: 12px; }
.sessions-empty {
  margin: 0;
  padding: 12px 0;
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
}
.sessions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.session-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.session-row.is-current {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.session-row-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.session-row-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-row-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12px;
  color: var(--text-muted);
}
.session-row-sub .pill { font-weight: 600; }
.session-row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.session-row-actions .btn { padding: 4px 10px; font-size: 12px; }

.status-running   { background: #e6efff; color: var(--accent); }
.status-starting  { background: #fff7e6; color: var(--warning); }
.status-succeeded { background: #e6f6ea; color: var(--success); }
.status-failed    { background: #ffeaee; color: var(--danger); }
.status-stopped_by_user { background: var(--surface-alt); color: var(--text-muted); }

/* ── Stage detail (Per-task progress widget, driven by pipeline) ── */
.stage-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.stage-detail-header h3 { margin: 0; }
.stage-detail-sub {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
}
.stage-selected-name {
  font-weight: 600;
  color: var(--text);
}
.stage-selected-status {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.stage-follow-btn {
  font-size: 12px;
  padding: 2px 8px;
}
.stage-subpanel[hidden] { display: none; }
.stage-empty {
  font-size: 13px;
  color: var(--text-muted);
  padding: 8px 2px;
  font-style: italic;
  margin: 0;
}
.plan-summary {
  /* override .markdown-body's tight 220px cap — the AI plan summary needs room
     to breathe inside the Stage-detail widget. */
  max-height: 480px;
  padding: 4px 4px 12px;
}
.plan-summary h1 { font-size: 17px; margin-top: 0; }
.plan-summary h2 {
  font-size: 14px;
  margin-top: 16px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}
.plan-summary ul { margin-left: 18px; }
.plan-summary blockquote {
  background: var(--surface-alt);
  border-left: 3px solid var(--border);
  margin: 8px 0;
  padding: 8px 12px;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

/* ── Code-generation drilldown (inside the Stage-detail widget) ── */
.codegen-panel { /* container is shown/hidden by renderStageDetail */ }
.codegen-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.codegen-header h4 {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.codegen-status {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.codegen-status.is-running { color: var(--accent); font-weight: 600; }
.codegen-body {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}
.codegen-batch {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  padding: 8px 10px;
}
.codegen-batch.is-running {
  border-color: var(--accent);
  background: var(--accent-soft, #eef4ff);
}
.codegen-batch-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  margin-bottom: 6px;
}
.codegen-batch-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}
.codegen-batch-meta {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.codegen-files {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.codegen-files li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: baseline;
  padding: 3px 0;
  font-size: 13px;
  border-top: 1px dashed var(--border);
}
.codegen-files li:first-child { border-top: none; }
.codegen-files .codegen-path {
  font-family: var(--font-mono);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.codegen-files .codegen-size {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.codegen-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 2px;
  font-style: italic;
}
