/* =========================================================
   ADLC deep dive — Phase 3: Build (sandboxes, tests, preview env)
   Builds on adlc-phase.css
   ========================================================= */

.role-agent { --role: var(--agent); }

/* Test-type colors, shared by tabs, pyramid and the table */
.t-unit     { --tc: #4f46e5; }
.t-prop     { --tc: #7c3aed; }
.t-int      { --tc: #0d9488; }
.t-contract { --tc: #0284c7; }
.t-e2e      { --tc: #d97706; }
.t-load     { --tc: #db2777; }

:root[data-theme="dark"] .t-unit     { --tc: #818cf8; }
:root[data-theme="dark"] .t-prop     { --tc: #a78bfa; }
:root[data-theme="dark"] .t-int      { --tc: #2dd4bf; }
:root[data-theme="dark"] .t-contract { --tc: #38bdf8; }
:root[data-theme="dark"] .t-e2e      { --tc: #fbbf24; }
:root[data-theme="dark"] .t-load     { --tc: #f472b6; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .t-unit     { --tc: #818cf8; }
  :root:not([data-theme="light"]) .t-prop     { --tc: #a78bfa; }
  :root:not([data-theme="light"]) .t-int      { --tc: #2dd4bf; }
  :root:not([data-theme="light"]) .t-contract { --tc: #38bdf8; }
  :root:not([data-theme="light"]) .t-e2e      { --tc: #fbbf24; }
  :root:not([data-theme="light"]) .t-load     { --tc: #f472b6; }
}

/* ---------- Environment ladder ---------- */

.env-rail {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 18px;
  padding: 0;
  counter-reset: env;
}

.env {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text-muted);
  transition: border-color 0.3s ease, box-shadow 0.3s ease, color 0.3s ease, opacity 0.3s ease;
  opacity: 0.7;
}

/* Arrow between environments */
.env:not(:last-child)::after {
  content: "→";
  position: absolute;
  right: -10px;
  top: 50%;
  transform: translate(50%, -50%);
  font-size: 13px;
  color: var(--text-muted);
  z-index: 1;
}

.env-icon {
  grid-row: span 2;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--code-bg);
  transition: background 0.3s ease, color 0.3s ease;
}

.env-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
  color: var(--text);
}

.env-meta {
  font-size: 12px;
}

.env.active {
  opacity: 1;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.env.active .env-icon {
  background: var(--accent);
  color: #fff;
  animation: env-pulse 1.6s ease-in-out infinite;
}

@keyframes env-pulse {
  50% { box-shadow: 0 0 0 6px var(--accent-soft); }
}

.env.done {
  opacity: 1;
}

.env.done .env-icon {
  background: color-mix(in srgb, var(--gate) 16%, transparent);
  color: var(--gate);
}

.env.next {
  opacity: 1;
  border-style: dashed;
  border-color: var(--accent);
}

/* ---------- Sandboxes ---------- */

.sandboxes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.sandbox {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  padding: 12px 12px 10px;
  overflow: hidden;
  transition: border-color 0.3s ease, box-shadow 0.3s ease, opacity 0.4s ease;
}

.sandbox.booted {
  border-style: solid;
  border-color: color-mix(in srgb, var(--agent) 45%, var(--border));
}

.sandbox.active {
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.sandbox.red {
  border-color: color-mix(in srgb, var(--fail) 60%, var(--border));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--fail) 10%, transparent);
}

.sbx-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.sbx-bot {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: var(--agent);
}

.sbx-who {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.sbx-who b {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
}

.sbx-task {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sbx-status {
  margin-left: auto;
  flex: none;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--text-muted);
  background: var(--code-bg);
  white-space: nowrap;
}

.sbx-status[data-tone="busy"] { color: var(--accent-strong); background: var(--accent-soft); }
.sbx-status[data-tone="bad"]  { color: var(--fail); background: color-mix(in srgb, var(--fail) 13%, transparent); }
.sbx-status[data-tone="good"] { color: var(--gate); background: color-mix(in srgb, var(--gate) 14%, transparent); }

.sbx-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.sbx-tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--text-muted);
  background: var(--code-bg);
}

.sbx-tag.guard {
  color: var(--gate);
  background: color-mix(in srgb, var(--gate) 11%, transparent);
}

/* Boot layers collapse once the sandbox is up */
.layer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 70px;
  gap: 8px;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  max-height: 22px;
  padding: 2px 0;
  transition: max-height 0.4s ease, opacity 0.3s ease, padding 0.4s ease;
}

.sandbox.collapsed .layer {
  max-height: 0;
  padding: 0;
  opacity: 0;
  overflow: hidden;
}

.layer-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer.done .layer-name::before {
  content: "✓ ";
  color: var(--gate);
}

.layer-bar {
  height: 5px;
  border-radius: 999px;
  background: var(--code-bg);
  overflow: hidden;
}

.layer-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--agent);
  border-radius: inherit;
}

.layer.done .layer-bar i {
  background: var(--gate);
}

/* Terminal */
.term {
  margin-top: 6px;
  min-height: 132px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #0b0d12;
  color: #cbd5e1;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.6;
}

:root[data-theme="dark"] .term {
  background: #05060a;
}

.tl {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tl:not(.shown) {
  display: none;
}

.tl.idle {
  color: #64748b;
}

.tl.k-cmd  { color: #e2e8f0; }
.tl.k-add  { color: #a5b4fc; }
.tl.k-fail { color: #f87171; }
.tl.k-pass { color: #4ade80; }
.tl.k-fix  { color: #fbbf24; }
.tl.k-info { color: #94a3b8; }

.sbx-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  min-height: 20px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
}

.sbx-refs {
  display: inline-flex;
  gap: 4px;
}

.tomb {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  flex-direction: column;
  gap: 4px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

.sandbox.destroyed {
  border-style: dashed;
  border-color: var(--border);
  box-shadow: none;
}

.sandbox.destroyed .tomb {
  opacity: 1;
}

.tomb b {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text);
}

.tomb span {
  font-weight: 500;
  color: var(--gate);
}

/* ---------- Tests: code viewer + pyramid ---------- */

.tests-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 12px;
}

@media (min-width: 1000px) {
  .tests-grid {
    grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
  }
}

.code-view {
  display: flex;
  flex-direction: column;
  min-height: 300px;
}

.code-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px 8px 0;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.code-tab {
  border: none;
  background: transparent;
  font: 600 12.5px var(--font-sans);
  color: var(--text-muted);
  padding: 7px 10px 8px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.code-tab:disabled {
  cursor: default;
}

.code-tab.avail {
  opacity: 1;
}

.code-tab.avail::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--tc);
}

.code-tab.on {
  color: var(--text);
  border-bottom-color: var(--tc);
}

.code {
  flex: 1;
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text);
}

.c-com { color: var(--text-muted); font-style: italic; }
.c-str { color: var(--gate); }
.c-key { color: var(--accent-strong); font-weight: 500; }
.c-num { color: var(--pm, #db2777); }

.cursor {
  display: inline-block;
  width: 7px;
  height: 1.1em;
  vertical-align: -0.2em;
  background: var(--accent);
  animation: caret 0.6s steps(2, start) infinite;
}

.code-view {
  position: relative;
}

.code-empty {
  position: absolute;
  inset: 40px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.code-view.empty .code-empty {
  opacity: 0.8;
}

/* Pyramid */
.pyramid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 16px 14px 8px;
}

.pyr {
  width: var(--w);
  min-width: 180px;
  max-width: 100%;
}

.pyr-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  background: var(--code-bg);
  border: 1px solid transparent;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.pyr-name {
  font-weight: 600;
  color: var(--text);
}

.pyr-name::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--tc);
}

.pyr-count {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.pyr[data-tone="busy"] .pyr-bar {
  border-color: color-mix(in srgb, var(--tc) 50%, transparent);
  background: color-mix(in srgb, var(--tc) 10%, var(--bg));
}

.pyr[data-tone="bad"] .pyr-bar {
  border-color: color-mix(in srgb, var(--fail) 45%, transparent);
  background: color-mix(in srgb, var(--fail) 8%, var(--bg));
}

.pyr[data-tone="bad"] .pyr-count { color: var(--fail); }

.pyr[data-tone="good"] .pyr-bar {
  background: color-mix(in srgb, var(--tc) 16%, var(--bg));
}

.pyr[data-tone="good"] .pyr-count { color: var(--gate); font-weight: 500; }

.pyramid-foot {
  padding: 4px 14px 14px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* ---------- Preview environment ---------- */

.preview {
  margin-top: 12px;
  opacity: 0.55;
  transition: opacity 0.4s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.preview.live,
.preview.done {
  opacity: 1;
}

.preview.live {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.mono-host {
  color: var(--text);
}

.preview-status {
  margin-left: auto;
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent-strong);
}

.preview-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 14px 16px 16px;
}

@media (min-width: 1000px) {
  .preview-grid {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1fr) minmax(0, 1.1fr);
    align-items: start;
  }
}

.services {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.svc {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12.5px;
  opacity: 0.45;
  transition: opacity 0.3s ease, border-color 0.3s ease;
}

.svc.up {
  opacity: 1;
}

.svc-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border);
}

.svc.up .svc-dot {
  background: var(--gate);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--gate) 20%, transparent);
}

.svc.torn .svc-dot {
  background: var(--text-muted);
  box-shadow: none;
}

.svc-text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.svc-text b {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 12px;
}

.svc-text span {
  color: var(--text-muted);
  font-size: 11.5px;
}

/* Board */
.board-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.client b {
  color: var(--gate);
  font-weight: 600;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.sq {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 2.4vw, 24px);
  line-height: 1;
  color: #1f2937;
  transition: background 0.3s ease;
}

.sq.light { background: #eceef4; }
.sq.dark  { background: #b4b9d0; }
.sq       { color: #111827; }
.sq.wp    { color: #ffffff; text-shadow: 0 0 1px #111827, 0 0 1px #111827, 0 1px 1px rgba(17, 24, 39, 0.8); }
.sq.from  { background: color-mix(in srgb, #fbbf24 45%, #eceef4); }
.sq.to    { background: color-mix(in srgb, #fbbf24 70%, #eceef4); animation: land 0.35s ease; }
.sq.mate  { background: color-mix(in srgb, #ef4444 60%, #eceef4); }

@keyframes land {
  40% { transform: scale(1.15); }
}

.board-foot {
  margin-top: 8px;
  min-height: 2.6em;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Latency histogram */
.latency-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.latency-head b {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text);
}

.hist {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 150px;
  padding-bottom: 1px;
  border-bottom: 1px solid var(--border);
}

.hb {
  flex: 1;
  height: var(--h);
  min-height: 1px;
  border-radius: 3px 3px 0 0;
  background: var(--t-load, #db2777);
  background: color-mix(in srgb, #db2777 70%, transparent);
  transform-origin: bottom;
  transform: scaleY(0);
  transition: transform 0.35s ease;
}

.hb.on {
  transform: scaleY(1);
}

.threshold {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 75%;
  width: 0;
  border-left: 2px dashed var(--fail);
}

.threshold i {
  position: absolute;
  top: -2px;
  left: 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-style: normal;
  color: var(--fail);
  white-space: nowrap;
}

.hist.done .threshold {
  border-left-color: var(--gate);
}

.hist.done .threshold i {
  color: var(--gate);
}

.hist-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-muted);
}

/* ---------- Test table ---------- */

.test-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
}

.test-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 640px;
}

.test-table th,
.test-table td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.test-table th {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.test-table tr:last-child td {
  border-bottom: none;
}

.test-table td:nth-child(2),
.test-table td:nth-child(3) {
  color: var(--text-muted);
}

.test-table td:last-child {
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.tt {
  --tc: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  white-space: nowrap;
}

.tt::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tc);
}

.test-table tr.muted td {
  opacity: 0.75;
}

.guard-head {
  margin-top: 40px;
}

/* ---------- Small screens ---------- */

@media (max-width: 1000px) {
  .sandboxes { grid-template-columns: 1fr; }
  .env-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .env:nth-child(2)::after { display: none; }
}

@media (max-width: 560px) {
  .env-rail { grid-template-columns: 1fr; }
  .env::after { display: none; }
  .env-meta { font-size: 11.5px; }
  .code { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .env.active .env-icon,
  .sq.to,
  .cursor {
    animation: none !important;
  }
}
