/* MiroFish console component system — P3.3-008.
 *
 * Cross-cutting UI components shared across the case pages: white cards,
 * status badges, the stat grid, Stage step-cards, the segmented view
 * switcher, the dark terminal trace-log panel, and the graph entity-legend
 * overlay. Linked once in base.html AFTER base.css so it reads the
 * tokens.css custom properties and may override base defaults.
 *
 * Class-based ONLY — the CSP forbids inline <script>; per-instance dynamic
 * values (forensic stage colours, progress-bar widths) still arrive as
 * inline `style=` (allowed by `style-src 'unsafe-inline'`), so the
 * STAGE_STYLE_WEB colour SSOT stays server-injected and is never hard-coded
 * here. No url(), no @import, no @font-face, no remote origin (INV-4).
 */

/* --- Card surface ---------------------------------------------------- */
.console-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
  margin: 0 0 var(--space-4);
}

.console-card > :first-child {
  margin-top: 0;
}

.console-card > :last-child {
  margin-bottom: 0;
}

/* A card whose own table/pre should sit flush to the card edges. */
.console-card--flush {
  padding: 0;
  overflow: hidden;
}

/* --- Panel header (card title bar with optional right-aligned tools) -- */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0 0 var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

.panel-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--heading);
}

.panel-subtitle {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--muted);
}

/* --- Status badge (traced / frontier / idle) ------------------------- */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.12rem var(--space-2);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.status-badge::before {
  content: "";
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: currentColor;
}

.status-badge--traced {
  color: var(--status-traced);
  background: var(--status-traced-bg);
}

.status-badge--frontier {
  color: var(--status-frontier);
  background: var(--status-frontier-bg);
}

.status-badge--idle {
  color: var(--status-idle);
  background: var(--status-idle-bg);
}

/* --- Stat grid / stat card (promoted from charts.css, refined) ------- */
/* SSOT for stat cards across pages. The dashboard keeps its #overview-cards
   grid rule in charts.css (htmx target id); these style the cards inside. */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
}

.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  padding: var(--space-3) var(--space-4);
}

.stat-card dt {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.stat-card dd {
  margin: var(--space-1) 0 0;
  font-family: var(--font-mono);
  font-size: 1.7rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--heading);
  font-variant-numeric: tabular-nums;
}

/* --- View switcher (segmented control) ------------------------------- */
.view-switcher {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

.view-switcher button {
  margin: 0;
  padding: var(--space-1) var(--space-3);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.view-switcher button:hover,
.view-switcher button:focus {
  color: var(--text);
  background: transparent;
}

.view-switcher button[aria-pressed="true"] {
  color: var(--heading);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

/* --- Stage step-rail (graph console right column) -------------------- */
.step-rail {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.step-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.step-num {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  min-width: 1.7rem;
  text-align: right;
}

.step-body {
  min-width: 0;
}

.step-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.step-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--heading);
}

.step-track {
  height: 0.4rem;
  margin-top: 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.step-fill {
  /* width + background + border-color arrive inline (dynamic stage colour
     from STAGE_STYLE_WEB); only the static box model lives here. display:block
     so the <span> honours width/height (an inline span would collapse). */
  display: block;
  height: 100%;
  min-width: 2px;
  border-radius: 999px;
}

.step-count {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--heading);
  font-variant-numeric: tabular-nums;
  min-width: 2.5rem;
  text-align: right;
}

/* --- Terminal trace-log panel (always dark — terminal aesthetic) ----- */
/* Intentionally hard-coded dark in BOTH themes: a terminal readout reads
   as a console regardless of the page theme. Values are byte-stable
   server-rendered trace facts, never a live stream. */
.terminal-log {
  background: #0f1419;
  color: #cbd5e1;
  border: 1px solid #1f2730;
  border-radius: var(--radius-card);
  padding: var(--space-3);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  line-height: 1.6;
  overflow-x: auto;
}

.terminal-log__head {
  color: #5a6675;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.68rem;
  margin-bottom: var(--space-2);
}

.terminal-line {
  white-space: pre-wrap;
  word-break: break-word;
}

.terminal-key {
  color: #5a6675;
}

.terminal-accent {
  color: #4ec77f;
}

.terminal-warn {
  color: #e0a24a;
}

/* --- Entity legend overlay (graph panel, anchored to #graph-stage) ---- */
.entity-legend {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-2) var(--space-3);
}

/* --- Mobile ---------------------------------------------------------- */
@media (max-width: 800px) {
  .stat-grid {
    grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
  }

  .view-switcher {
    width: 100%;
  }
}
