/**
 * WHAT: Layout and component styles for the command-and-control dashboard.
 * WHY: `theme.css` only defines the three locked brand colors; this file
 * is every visual decision built on top of them, kept in one place so the
 * whole surface "reads as one product" (AGENTS.md SS6 aesthetics rule).
 * HOW: Loaded after theme.css; references --brand-primary/--brand-ink/
 * --brand-accent exclusively — no literal hex codes below. State (pending/
 * running/done/error/skipped) is distinguished by border style, icon
 * glyph, and text label together, never by color alone (WCAG "use of
 * color" success criterion, frontend/README.md accessibility note).
 */

* {
  box-sizing: border-box;
}

/* WHAT: Standard "visually hidden but still announced" utility — used for
   the aria-live stage/run announcer (index.html #sr-announcer). WHY:
   `hidden`/`display:none` would also hide it from assistive tech, which
   defeats the point; this clips it visually while keeping it in the
   accessibility tree. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  margin: 0 0 0.4rem 0;
  letter-spacing: -0.01em;
}

button {
  font: inherit;
  cursor: pointer;
}

button:focus-visible,
textarea:focus-visible,
.run-history__button:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}

/* --- Top bar --- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, var(--surface-2), transparent);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.topbar__title h1 {
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(120deg, var(--brand-primary) 30%, var(--brand-accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  width: fit-content;
}

.topbar__subtitle {
  margin: 0;
  color: var(--brand-accent);
  font-size: 0.9rem;
  letter-spacing: 0.01em;
}

.topbar__status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.topbar__status .dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  border: 1px solid var(--brand-primary);
  background: transparent;
  transition: box-shadow 0.3s ease, background 0.3s ease;
}

.topbar__status[data-state="ok"] .dot {
  background: var(--brand-primary);
  box-shadow: 0 0 0.6rem var(--glow-primary);
}

.topbar__status[data-state="down"] .dot {
  background: var(--brand-accent);
  border-style: dashed;
}

.theme-toggle {
  background: var(--surface-1);
  color: var(--brand-primary);
  border: 1px solid var(--brand-accent);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 600;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.theme-toggle:hover {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0.9rem var(--glow-accent);
  transform: translateY(-1px);
}

/* --- Layout --- */

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  gap: 1.25rem;
  padding: 1.25rem 1.5rem 2.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.panel {
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 1.1rem 1.25rem;
  background: linear-gradient(160deg, var(--surface-2), var(--surface-1) 60%);
  box-shadow: 0 1.5rem 3rem -1.5rem var(--shadow-ambient), inset 0 1px 0 var(--surface-1);
}

/* --- Launch panel --- */

.launch-panel form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.launch-panel label {
  font-size: 0.85rem;
  color: var(--brand-accent);
}

.launch-panel textarea {
  resize: vertical;
  background: var(--surface-1);
  color: var(--brand-primary);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.launch-panel textarea:focus-visible {
  border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px var(--glow-accent);
}

.launch-panel button {
  background: linear-gradient(120deg, var(--brand-primary), var(--brand-accent));
  color: var(--brand-ink);
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  box-shadow: 0 0.5rem 1.2rem -0.4rem var(--glow-accent);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.launch-panel button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 0.7rem 1.6rem -0.4rem var(--glow-accent);
}

.launch-panel button:active:not(:disabled) {
  transform: translateY(0);
}

.launch-panel button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.error-text {
  color: var(--brand-accent);
  font-weight: 600;
  font-size: 0.85rem;
}

.notify-toggle {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--brand-primary);
  cursor: pointer;
}

.notify-toggle input {
  accent-color: var(--brand-accent);
}

.model-pricing-note {
  margin: 0.5rem 0 0;
  font-size: 0.72rem;
  color: var(--brand-accent);
  opacity: 0.8;
}

.model-pricing-note a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.history-heading {
  margin-top: 1.5rem;
}

.run-history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 40vh;
  overflow-y: auto;
}

.run-history__empty {
  color: var(--brand-accent);
  font-size: 0.85rem;
}

.run-history__button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface-1);
  color: var(--brand-primary);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.run-history__button:hover {
  border-color: var(--brand-accent);
  background: var(--surface-2);
  transform: translateX(2px);
}

.run-history__item.is-active .run-history__button {
  border-style: solid;
  border-width: 2px;
  border-color: var(--brand-accent);
  background: var(--surface-2);
  box-shadow: 0 0 0.9rem var(--glow-accent);
}

.run-history__brief {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
}

.run-history__badge {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  flex-shrink: 0;
}

/* --- Pipeline panel --- */

.pipeline-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.run-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
}

.run-meta__id {
  color: var(--brand-accent);
  font-family: ui-monospace, monospace;
}

.run-meta__badge {
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--brand-primary);
  font-weight: 600;
  box-shadow: 0 0 0.6rem var(--glow-primary);
}

.pipeline-empty {
  color: var(--brand-accent);
  padding: 3rem 0;
  text-align: center;
  border: 1px dashed var(--border-soft);
  border-radius: 10px;
  margin-top: 0.75rem;
}

.gate-banner {
  margin: 0.75rem 0;
  padding: 0.8rem 1rem;
  border: 2px solid var(--brand-primary);
  border-radius: 10px;
  font-weight: 600;
  background: linear-gradient(120deg, var(--surface-2), var(--surface-1));
  box-shadow: 0 0 1.5rem -0.3rem var(--glow-primary);
}

.gate-banner[data-state="error"] {
  border-style: dashed;
  border-color: var(--brand-accent);
  box-shadow: 0 0 1.5rem -0.3rem var(--glow-accent);
}

/* --- Stage grid --- */

.stage-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-top: 0.75rem;
  counter-reset: stage-counter;
}

@media (max-width: 700px) {
  .stage-grid {
    grid-template-columns: 1fr;
  }
}

.stage-card {
  grid-column: span 1;
  counter-increment: stage-counter;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 1rem 0.9rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-width: 0;
  background: linear-gradient(160deg, var(--surface-2), var(--surface-1) 70%);
  box-shadow: 0 0.75rem 1.5rem -1rem var(--shadow-ambient);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.stage-card:hover {
  border-color: var(--brand-accent);
  transform: translateY(-2px);
  box-shadow: 0 1rem 2rem -1rem var(--shadow-ambient), 0 0 1.2rem -0.4rem var(--glow-accent);
}

/* WHAT: A large low-opacity watermark digit per card, pure-CSS (::after +
   counter()) — no markup or JS needed, purely decorative/static so it
   isn't subject to the state-selector caveat below. WHY: a bit of
   dashboard personality without touching the locked palette. */
.stage-card::after {
  content: counter(stage-counter, decimal-leading-zero);
  position: absolute;
  right: 0.7rem;
  bottom: 0.4rem;
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 2.1rem;
  font-weight: 800;
  color: var(--brand-primary);
  opacity: 0.07;
  line-height: 1;
  pointer-events: none;
}

/* WHAT: Top accent bar — a real element (not ::before) with `data-state`
   set directly on it by app.js's setStageStatus(), mirroring the exact
   attribute-selector shape already proven reliable by
   .stage-card__status[data-state=...] below. WHY: pseudo-elements /
   ancestor-scoped attribute selectors (`.stage-card[data-x] .child`) do
   not reliably restyle after a dynamic dataset mutation in every browser
   engine — using a real element with the attribute set on itself avoids
   that class of invalidation bug entirely. */
.stage-card__accent {
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--border-soft);
  transition: background 0.3s ease;
}

.stage-card__accent[data-state="running"] {
  background: linear-gradient(90deg, var(--brand-accent), var(--brand-primary), var(--brand-accent));
  background-size: 200% 100%;
  animation: barber-pole 2.4s linear infinite;
}

.stage-card__accent[data-state="done"] {
  background: var(--brand-primary);
}

.stage-card__accent[data-state="error"] {
  background: var(--brand-accent);
}

.stage-card__accent[data-state="skipped"] {
  opacity: 0.4;
}

@keyframes barber-pole {
  from { background-position: 0 0; }
  to { background-position: 200% 0; }
}

/* WHAT: Sequential stages (research, business, validator, quality_gate)
   span the full grid width so the parallel specialists, and separately the
   parallel Reviewer/Challenge Division pair, each visually read as one
   concurrent row between the sequential stages surrounding them. */
.stage-card[data-lane="sequential"] {
  grid-column: 1 / -1;
}

.stage-card__header {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
}

.stage-card__icon-badge {
  flex-shrink: 0;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  border: 1.5px solid var(--border-soft);
  background: var(--surface-2);
  transition: border-color 0.3s ease, box-shadow 0.3s ease, background 0.3s ease, transform 0.3s ease;
}

.stage-card__heading {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  padding-top: 0.1rem;
}

.stage-card__title {
  font-size: 0.95rem;
}

.stage-card__role {
  font-size: 0.72rem;
  color: var(--brand-accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stage-card__model {
  display: block;
  font-size: 0.68rem;
  font-family: ui-monospace, "Cascadia Code", monospace;
  color: var(--brand-primary);
  opacity: 0.65;
}

.stage-card__model:empty {
  display: none;
}

.stage-card__icon-badge[data-state="running"] {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0.8rem var(--glow-primary);
  animation: badge-breathe 1.6s ease-in-out infinite;
}

.stage-card__icon-badge[data-state="done"] {
  border-color: var(--brand-primary);
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-accent));
  color: var(--brand-ink);
  box-shadow: 0 0 0.7rem var(--glow-primary);
}

.stage-card__icon-badge[data-state="error"] {
  border-color: var(--brand-accent);
  border-width: 2px;
  box-shadow: 0 0 0.8rem var(--glow-accent);
}

.stage-card__icon-badge[data-state="pending"] {
  opacity: 0.5;
}

.stage-card__icon-badge[data-state="skipped"] {
  opacity: 0.3;
}

@keyframes badge-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.stage-card__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.stage-card__status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--brand-accent);
  width: fit-content;
  transition: box-shadow 0.3s ease, opacity 0.3s ease;
}

.stage-card__status[data-state="pending"] {
  opacity: 0.5;
  border-style: dashed;
}

.stage-card__status[data-state="running"] {
  border-style: solid;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0.9rem var(--glow-primary);
  animation: pulse 1.4s ease-in-out infinite;
}

.stage-card__status[data-state="done"] {
  border-color: var(--brand-primary);
  border-style: solid;
  font-weight: 600;
  box-shadow: 0 0 0.6rem var(--glow-primary);
}

.stage-card__status[data-state="error"] {
  border-style: double;
  border-width: 4px;
  font-weight: 700;
  box-shadow: 0 0 0.8rem var(--glow-accent);
}

.stage-card__status[data-state="skipped"] {
  opacity: 0.35;
  border-style: dotted;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0.4rem var(--glow-primary); }
  50% { opacity: 0.65; box-shadow: 0 0 1.1rem var(--glow-primary); }
}

.stage-card__toggle {
  background: var(--surface-1);
  color: var(--brand-primary);
  border: 1px solid var(--brand-primary);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  transition: background 0.15s ease, transform 0.15s ease;
}

.stage-card__toggle:hover {
  background: var(--surface-2);
  transform: translateY(-1px);
}

.stage-card__output {
  margin: 0;
  max-height: 16rem;
  overflow-y: auto;
  overflow-x: auto;
  word-break: break-word;
  background: var(--surface-1);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 0.7rem;
  font-size: 0.85rem;
  line-height: 1.5;
}
