:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #64717d;
  --line: #d8dee4;
  --surface: #ffffff;
  --surface-subtle: #f4f6f7;
  --teal: #087f75;
  --teal-soft: #e5f4f1;
  --blue: #215ca0;
  --blue-soft: #e9f0f8;
  --amber: #a26000;
  --amber-soft: #fff4d8;
  --red: #b42332;
  --red-soft: #fdecef;
  --shadow: 0 12px 30px rgba(23, 32, 42, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--surface-subtle);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.hidden {
  display: none !important;
}

.app-header {
  min-height: 66px;
  padding: 10px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: #fff;
  background: #17202a;
}

.brand-lockup,
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-lockup strong,
.brand-lockup span {
  display: block;
}

.brand-lockup span {
  margin-top: 2px;
  color: #b8c1c9;
  font-size: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
}

.session-user {
  color: #dbe1e6;
  font-size: 13px;
}

.sandbox-banner {
  padding: 8px 24px;
  text-align: center;
  color: #654300;
  background: var(--amber-soft);
  border-bottom: 1px solid #f0d695;
  font-size: 12px;
  font-weight: 650;
}

.app-main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 30px;
}

.start-view {
  max-width: 1000px;
  margin: 22px auto;
}

.start-copy {
  max-width: 760px;
}

.start-copy h1,
.run-heading h1 {
  margin: 5px 0 12px;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.08;
  letter-spacing: 0;
}

.start-copy p:not(.eyebrow) {
  color: var(--muted);
  font-size: 18px;
  line-height: 1.6;
}

.eyebrow {
  margin: 0;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.scenario-strip {
  margin: 30px 0 24px;
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  gap: 18px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.scenario-strip span,
.metric span,
.route-row span,
.diff-panel span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

.scenario-arrow {
  color: var(--teal);
  font-size: 24px;
}

.scenario-divider {
  width: 1px;
  height: 46px;
  background: var(--line);
}

.mode-form {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.mode-form fieldset {
  margin: 0 0 20px;
  padding: 0;
  border: 0;
}

.mode-form legend {
  margin-bottom: 12px;
  font-weight: 750;
}

.mode-option {
  min-height: 76px;
  margin-bottom: 10px;
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
}

.mode-option:has(input:checked) {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.mode-option input {
  margin-top: 4px;
}

.mode-option strong,
.mode-option small {
  display: block;
}

.mode-option small {
  margin-top: 5px;
  color: var(--muted);
  line-height: 1.4;
}

.primary-button,
.approve-button,
.reject-button,
.quiet-button {
  min-height: 40px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-weight: 750;
}

.primary-button,
.approve-button {
  color: #fff;
  background: var(--teal);
}

.primary-button:hover,
.approve-button:hover {
  background: #05695f;
}

.reject-button {
  color: var(--red);
  border-color: #e7aab2;
  background: #fff;
}

.quiet-button {
  min-height: 34px;
  padding: 6px 10px;
  color: inherit;
  border-color: var(--line);
  background: transparent;
}

.app-header .quiet-button {
  color: #fff;
  border-color: #4b5660;
}

.full-button {
  width: 100%;
}

.form-error {
  min-height: 20px;
  color: var(--red);
  font-size: 13px;
}

.run-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.run-heading h1 {
  font-size: 30px;
}

.run-id {
  margin: 0;
  color: var(--muted);
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
}

.status-badge {
  min-width: 120px;
  padding: 7px 10px;
  border-radius: 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  background: var(--blue-soft);
  color: var(--blue);
}

.status-badge.waiting {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-badge.complete {
  background: var(--teal-soft);
  color: var(--teal);
}

.status-badge.failed {
  background: var(--red-soft);
  color: var(--red);
}

.progress-track {
  width: 100%;
  height: 6px;
  margin: 22px 0;
  overflow: hidden;
  background: #dfe4e8;
}

.progress-track div {
  width: 0;
  height: 100%;
  background: var(--teal);
  transition: width 300ms ease;
}

.run-layout {
  min-height: 620px;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stage-nav {
  padding: 18px 0;
  border-right: 1px solid var(--line);
  background: #f8f9fa;
}

.stage-nav ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.stage-item {
  min-height: 43px;
  padding: 8px 18px;
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 9px;
  align-items: center;
  color: var(--muted);
  border-left: 3px solid transparent;
  font-size: 12px;
}

.stage-item .stage-index {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border: 1px solid #aab3bb;
  border-radius: 50%;
  font-size: 10px;
}

.stage-item.active {
  color: var(--ink);
  border-left-color: var(--blue);
  background: var(--blue-soft);
  font-weight: 750;
}

.stage-item.done {
  color: var(--teal);
}

.stage-item.done .stage-index {
  color: #fff;
  border-color: var(--teal);
  background: var(--teal);
}

.stage-workspace {
  min-width: 0;
  padding: 28px;
}

.stage-header {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.stage-header h2 {
  margin: 6px 0 8px;
  font-size: 24px;
  letter-spacing: 0;
}

.stage-header p:last-child {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.stage-visual {
  padding: 24px 0;
}

.route-grid,
.metric-grid,
.diff-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.route-row,
.metric,
.diff-panel,
.empty-visual {
  min-height: 112px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
}

.route-row.allowed {
  border-left: 4px solid var(--teal);
  background: var(--teal-soft);
}

.route-row.blocked {
  border-left: 4px solid var(--red);
  background: var(--red-soft);
}

.route-row p,
.metric p,
.diff-panel p {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 13px;
}

.metric strong {
  font-size: 24px;
}

.metric code,
.diff-panel code {
  word-break: break-word;
  font-size: 12px;
}

.gate-panel {
  margin: 0 0 24px;
  padding: 18px;
  border: 1px solid #e4c371;
  border-radius: 6px;
  background: var(--amber-soft);
}

.gate-panel h3 {
  margin: 0 0 8px;
}

.gate-panel p {
  line-height: 1.5;
}

.gate-panel label {
  display: block;
  margin: 14px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.gate-evidence {
  margin: 14px 0;
  padding: 10px 12px;
  border-left: 3px solid var(--amber);
  background: rgba(255, 255, 255, 0.7);
  font-size: 12px;
}

.gate-evidence ul {
  margin: 7px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.gate-panel textarea {
  width: 100%;
  min-height: 78px;
  margin-top: 6px;
  padding: 10px;
  resize: vertical;
  color: var(--ink);
  border: 1px solid #c5a14b;
  border-radius: 4px;
  background: #fff;
}

.gate-actions,
.result-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.result-actions {
  justify-content: flex-start;
  margin-top: 18px;
}

.result-actions a {
  padding: 9px 13px;
  color: var(--blue);
  border: 1px solid #9fb7d1;
  border-radius: 4px;
  text-decoration: none;
  font-weight: 700;
}

.report-inspector {
  margin-top: 18px;
  border: 1px solid var(--line);
}

.report-inspector summary {
  padding: 12px;
  cursor: pointer;
  font-weight: 750;
}

.report-inspector pre {
  max-height: 480px;
  margin: 0;
  padding: 14px;
  overflow: auto;
  color: #d7e0e7;
  background: #10171d;
  font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.terminal-state {
  padding: 18px;
  color: var(--red);
  border-left: 4px solid var(--red);
  background: var(--red-soft);
}

.terminal-state p {
  margin: 7px 0 0;
  color: var(--ink);
}

.technical-details {
  margin-top: 12px;
  border-top: 1px solid var(--line);
}

.technical-details summary {
  padding: 15px 0;
  cursor: pointer;
  font-weight: 750;
}

.log-toolbar {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #c7d0d8;
  background: #17202a;
  border-bottom: 1px solid #34404a;
  font-size: 11px;
}

.log-toolbar .quiet-button {
  color: #fff;
  border-color: #56616b;
}

#technical-log {
  min-height: 220px;
  max-height: 420px;
  margin: 0;
  padding: 14px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: #d7e0e7;
  background: #10171d;
  font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #17202a;
}

.login-shell {
  width: min(420px, 100%);
}

.login-panel {
  padding: 34px;
  border-radius: 6px;
  background: #fff;
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin: 8px 0;
  font-size: 34px;
}

.login-copy {
  margin: 0 0 24px;
  color: var(--muted);
  line-height: 1.5;
}

.login-form label {
  display: block;
  margin: 14px 0;
  font-size: 12px;
  font-weight: 750;
}

.login-form input {
  width: 100%;
  height: 42px;
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.login-form input:focus,
.gate-panel textarea:focus {
  outline: 2px solid #86b9b2;
  outline-offset: 1px;
}

.boundary-note {
  margin: 22px 0 0;
  padding-top: 16px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 11px;
  line-height: 1.5;
}

@media (max-width: 860px) {
  .app-main {
    padding: 18px;
  }

  .scenario-strip {
    grid-template-columns: 1fr;
  }

  .scenario-arrow,
  .scenario-divider {
    display: none;
  }

  .run-layout {
    grid-template-columns: 1fr;
  }

  .stage-nav {
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stage-nav ol {
    min-width: max-content;
    display: flex;
  }

  .stage-item {
    width: 145px;
    border-left: 0;
    border-bottom: 3px solid transparent;
  }

  .stage-item.active {
    border-bottom-color: var(--blue);
  }

  .route-grid,
  .metric-grid,
  .diff-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-header {
    padding: 10px 14px;
  }

  .brand-lockup span,
  .session-user {
    display: none;
  }

  .app-main {
    padding: 12px;
  }

  .run-heading {
    display: block;
  }

  .status-badge {
    width: max-content;
    margin-top: 12px;
  }

  .stage-workspace {
    padding: 18px;
  }

  .gate-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
