/* API Theater v2 — polished layout, overflow-safe, guided + expert modes */

.at-v2 {
  overflow-x: clip;
}

.at-v2 * {
  box-sizing: border-box;
}

/* ─── Header ─── */
.at-v2-header .nav-shell {
  gap: 0.75rem;
}

.at-v2-header .site-nav {
  display: none;
}

@media (min-width: 900px) {
  .at-v2-header .site-nav {
    display: flex;
  }
}

.at-v2-header .nav-actions {
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.at-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
}

.at-mode-btn {
  appearance: none;
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.at-mode-btn:hover {
  color: var(--text);
}

.at-mode-btn.active {
  background: rgba(249, 115, 22, 0.2);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(249, 115, 22, 0.45);
}

body.at-mode-guided .at-expert-only { display: none !important; }
body.at-mode-expert .at-guided-only { display: none !important; }

/* ─── Top bar ─── */
.at-v2-topbar {
  padding: 1.75rem 0 1rem;
}

.at-v2-topbar-inner {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

@media (min-width: 960px) {
  .at-v2-topbar-inner {
    grid-template-columns: 1fr minmax(300px, 380px);
    gap: 2rem;
    align-items: start;
  }
}

.at-v2-title-block h1 {
  font-family: var(--display);
  font-size: clamp(1.45rem, 3.2vw, 2.1rem);
  line-height: 1.15;
  margin: 0.35rem 0 0.65rem;
  max-width: 24ch;
}

.at-v2-title-block .eyebrow {
  color: var(--accent);
  margin: 0;
  font-size: 0.72rem;
}

.at-v2-title-block .at-hero-lead {
  text-align: left;
  margin: 0;
  max-width: 56ch;
  font-size: 0.92rem;
  line-height: 1.6;
}

.at-v2-status-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.32);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.at-api-status-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--text2);
}

.at-api-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.3);
}

.at-api-dot.ok { background: #39d98a; box-shadow: 0 0 8px rgba(57, 217, 138, 0.45); }
.at-api-dot.warn { background: #ffb02e; }

.at-v2-status-card .at-api-banner {
  display: block;
  margin: 0;
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font-size: 0.72rem;
  line-height: 1.5;
  word-break: break-word;
  max-width: 100%;
}

.at-v2-status-card .at-api-banner code {
  font-size: 0.68rem;
  word-break: break-all;
}

.at-v2-status-card .at-demo-url {
  margin: 0;
  max-width: none;
}

.at-v2-status-card .at-demo-url label {
  font-size: 0.68rem;
  margin-bottom: 0.3rem;
}

.at-v2-status-card .at-demo-url input {
  min-width: 0;
  width: 100%;
  font-size: 0.68rem;
  padding: 0.5rem 0.6rem;
}

.at-v2-status-card .at-demo-url-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem;
}

/* ─── Workspace grid ─── */
.at-v2-workspace {
  padding-top: 0;
  padding-bottom: 3rem;
}

.at-v2-grid {
  display: grid;
  gap: 1rem;
  align-items: start;
}

body.at-mode-guided .at-v2-grid {
  grid-template-columns: 1fr;
  max-width: 920px;
  margin: 0 auto;
}

body.at-mode-expert .at-v2-grid {
  grid-template-columns: minmax(0, 220px) minmax(0, 1fr) minmax(0, 260px);
}

.at-v2-rail,
.at-v2-inspector,
.at-v2-center {
  min-width: 0;
}

.at-v2-rail,
.at-v2-inspector {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

body.at-mode-expert .at-v2-rail,
body.at-mode-expert .at-v2-inspector {
  position: sticky;
  top: 4.5rem;
  max-height: calc(100vh - 5.5rem);
  overflow-y: auto;
  overflow-x: hidden;
}

.at-rail-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  padding: 0.75rem;
  min-width: 0;
  overflow: hidden;
}

.at-rail-panel h3 {
  margin: 0 0 0.55rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text2);
  font-weight: 600;
}

/* Pipeline HUD */
.at-pipeline-hud {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.at-pipe-node {
  display: grid;
  grid-template-columns: 1.5rem 1fr;
  gap: 0 0.4rem;
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.7rem;
  color: var(--text2);
  cursor: pointer;
  text-align: left;
  width: 100%;
  background: transparent;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}

.at-pipe-node:hover {
  background: rgba(255, 255, 255, 0.04);
}

.at-pipe-node strong {
  grid-column: 2;
  font-size: 0.76rem;
  color: var(--text);
  font-weight: 600;
}

.at-pipe-node > span:last-child {
  grid-column: 2;
  font-size: 0.62rem;
  opacity: 0.85;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.at-pipe-idx {
  grid-row: 1 / span 2;
  align-self: center;
  font-family: var(--mono);
  font-size: 0.62rem;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.at-pipe-node.active {
  border-color: rgba(249, 115, 22, 0.45);
  background: rgba(249, 115, 22, 0.08);
}

.at-pipe-node.active .at-pipe-idx {
  background: rgba(249, 115, 22, 0.2);
  border-color: rgba(249, 115, 22, 0.5);
}

.at-manifest-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.55rem;
  margin: 0;
}

.at-manifest-dl dt {
  color: var(--text2);
  font-size: 0.62rem;
  text-transform: uppercase;
}

.at-manifest-dl dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.66rem;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.at-audit-log {
  max-height: 160px;
  overflow-y: auto;
  overflow-x: hidden;
  font-family: var(--mono);
  font-size: 0.62rem;
}

.at-audit-row {
  display: grid;
  grid-template-columns: 4.2rem minmax(0, 1fr);
  gap: 0.35rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text2);
  line-height: 1.4;
}

.at-audit-row span:last-child {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.at-audit-ts { opacity: 0.65; }
.at-audit-sys { color: #60a5fa; }
.at-audit-warn { color: #ffb02e; }
.at-audit-ok { color: #39d98a; }

/* ─── Wizard center ─── */
.at-v2-center .at-step-nav {
  display: flex;
  gap: 0.35rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  justify-content: flex-start;
  margin-bottom: 0.85rem;
  padding-bottom: 0.35rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.at-v2-center .at-step-tab {
  flex-shrink: 0;
  appearance: none;
  font-family: inherit;
  white-space: nowrap;
}

.at-wizard-card {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
  min-width: 0;
  overflow: hidden;
}

.at-wizard-card h2 {
  font-family: var(--display);
  font-size: 1.1rem;
  margin: 0 0 0.85rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.at-step-mount {
  min-width: 0;
}

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

.at-step-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.at-step-indicator {
  font-size: 0.75rem;
  color: var(--text2);
  font-family: var(--mono);
}

/* Guided flow strip */
.at-guided-flow {
  margin-top: 1.25rem;
}

.at-guided-flow .at-flow-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
}

.at-guided-flow .at-flow-step {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.02);
  min-width: 0;
}

.at-guided-flow .at-flow-step strong {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}

.at-guided-flow .at-flow-step p {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text2);
  line-height: 1.45;
}

.at-guided-flow .step-num {
  font-size: 0.62rem;
  color: var(--accent);
  margin: 0 0 0.2rem;
  font-family: var(--mono);
}

.at-guided-summary {
  font-size: 0.82rem;
  color: var(--text2);
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid rgba(57, 217, 138, 0.25);
  background: rgba(57, 217, 138, 0.06);
  margin-bottom: 1rem;
  line-height: 1.5;
}

.at-ingest-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}

@media (min-width: 640px) {
  .at-ingest-stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.at-ingest-stats > div {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  background: rgba(0, 0, 0, 0.2);
  min-width: 0;
}

.at-ingest-stats span {
  display: block;
  font-size: 0.6rem;
  text-transform: uppercase;
  color: var(--text2);
  letter-spacing: 0.05em;
}

.at-ingest-stats strong {
  font-family: var(--mono);
  font-size: 0.82rem;
  word-break: break-word;
}

/* Inspector tables */
.at-frame-table-wrap {
  overflow: auto;
  max-height: 150px;
  margin: 0 -0.25rem;
  padding: 0 0.25rem;
}

.at-frame-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.65rem;
  font-family: var(--mono);
  table-layout: fixed;
}

.at-frame-table th {
  text-align: left;
  font-size: 0.58rem;
  text-transform: uppercase;
  color: var(--text2);
  padding: 0.3rem 0.35rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(10, 12, 16, 0.95);
}

.at-frame-table td {
  padding: 0.28rem 0.35rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.at-frame-row { cursor: pointer; }
.at-frame-row:hover { background: rgba(255, 255, 255, 0.04); }
.at-frame-row.selected { background: rgba(249, 115, 22, 0.12); }

.tier-n { color: #39d98a; }
.tier-w { color: #ffb02e; }
.tier-c { color: #ff6b6b; }

.at-can-ok { color: #39d98a; }
.at-can-degraded { color: #ffb02e; }

.at-inspector-body { font-size: 0.72rem; min-width: 0; }

.at-inspector-section {
  margin-bottom: 0.75rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.at-inspector-section h4 {
  margin: 0 0 0.4rem;
  font-size: 0.7rem;
  color: var(--text);
  word-break: break-word;
}

.at-kv {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.2rem 0.45rem;
  margin: 0;
}

.at-kv dt { color: var(--text2); font-size: 0.62rem; }
.at-kv dd { margin: 0; font-family: var(--mono); font-size: 0.68rem; word-break: break-word; }

.at-mini-pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.62rem;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  color: var(--text2);
  max-height: 120px;
  overflow-y: auto;
}

.at-muted {
  color: var(--text2);
  font-size: 0.78rem;
  margin: 0;
}

/* ─── v2 overrides for step content (overflow-safe) ─── */
.at-v2 .at-action-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.at-v2 .at-action-row .btn {
  flex-shrink: 0;
}

.at-v2 .at-status {
  font-size: 0.75rem;
  flex: 1 1 140px;
  min-width: 0;
  word-break: break-word;
  line-height: 1.4;
}

.at-v2 .at-io-pair {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 720px) {
  body.at-mode-guided .at-v2 .at-io-pair {
    grid-template-columns: 1fr 1fr;
  }

  body.at-mode-expert .at-v2 .at-io-pair {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1280px) {
  body.at-mode-expert .at-v2 .at-io-pair {
    grid-template-columns: 1fr 1fr;
  }
}

.at-v2 .code-shell,
.at-v2 .at-code-shell {
  min-width: 0;
  max-width: 100%;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.at-v2 .code-shell header,
.at-v2 .at-code-shell header {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.at-v2 .code-shell pre,
.at-v2 .at-code-shell pre {
  margin: 0;
  padding: 0.75rem;
  max-height: 280px;
  overflow: auto;
  font-size: 0.68rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.at-v2 .at-tier-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

@media (min-width: 640px) {
  body.at-mode-guided .at-v2 .at-tier-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1100px) {
  body.at-mode-expert .at-v2 .at-tier-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.at-v2 .at-tier-card {
  min-width: 0;
  overflow: hidden;
}

.at-v2 .at-card-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
  margin: 0;
}

.at-v2 .at-card-metrics > div {
  min-width: 0;
}

.at-v2 .at-card-metrics dt {
  font-size: 0.58rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.at-v2 .at-card-metrics dd {
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.at-v2 .at-chart-panel {
  min-width: 0;
  overflow: hidden;
  margin-bottom: 1rem;
}

.at-v2 .at-mahal-chart {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
}

.at-v2 .at-stage-track {
  overflow-x: auto;
  flex-wrap: nowrap;
  padding: 0.65rem;
  margin-bottom: 1rem;
}

.at-v2 .at-stage {
  flex-shrink: 0;
}

.at-v2 .at-sse-log-wrap {
  min-width: 0;
  margin-bottom: 1rem;
}

.at-v2 .at-sse-log {
  max-height: 160px;
  word-break: break-word;
}

.at-v2 .at-result-card {
  min-width: 0;
  overflow: hidden;
}

.at-v2 .at-mono-line {
  word-break: break-all;
  font-size: 0.78rem;
}

.at-v2 .at-hash-dl {
  min-width: 0;
}

.at-v2 .at-hash-wrap {
  flex-wrap: wrap;
}

.at-v2 .at-hash,
.at-v2 .at-hash-muted {
  font-size: 0.68rem;
  word-break: break-all;
  overflow-wrap: anywhere;
}

.at-v2 .at-tab-row {
  flex-wrap: wrap;
}

.at-v2 .at-tab {
  appearance: none;
  font-family: inherit;
}

.at-v2 .at-copy,
.at-v2 .at-btn-ghost.at-btn-sm {
  appearance: none;
  font-family: inherit;
  cursor: pointer;
}

.at-v2 .at-step-lead {
  font-size: 0.88rem;
  line-height: 1.55;
  margin-bottom: 1rem;
}

.at-v2 .at-step-lead code {
  font-size: 0.82em;
  word-break: break-all;
}

/* Responsive expert layout */
@media (max-width: 1100px) {
  body.at-mode-expert .at-v2-grid {
    grid-template-columns: 1fr;
  }

  body.at-mode-expert .at-v2-rail,
  body.at-mode-expert .at-v2-inspector {
    position: static;
    max-height: none;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  body.at-mode-expert .at-rail-audit {
    grid-column: 1 / -1;
  }
}

@media (max-width: 768px) {
  .at-v2-header .nav-actions .btn-ghost,
  .at-v2-header .nav-actions .btn-primary {
    display: none;
  }

  .at-guided-flow .at-flow-strip {
    grid-template-columns: 1fr 1fr;
  }

  body.at-mode-expert .at-v2-rail,
  body.at-mode-expert .at-v2-inspector {
    grid-template-columns: 1fr;
  }

  .at-step-footer {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .at-guided-flow .at-flow-strip {
    grid-template-columns: 1fr;
  }
}
