/*
 * The Crucible's two lenses.
 *
 * Both read the same build. Blueprint is the plain-English one and the default; Workshop is the
 * machinery. Per the visual north star: command records rather than messenger bubbles, machined
 * frames with real mass, copper as metal, green reserved for energy and state.
 */

#cru { display: grid; gap: 16px; margin: 0 0 20px; }

/* ---------- head: the lens switch and the live cost ------------------------------------- */
.cru-head {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  flex-wrap: wrap;
}

.cru-switch {
  display: inline-flex; gap: 0; border: 0;
  background: none; box-shadow: none;
}
.cru-switch button {
  font: 800 17px inherit; letter-spacing: .06em; text-transform: capitalize;
  padding: 12px 18px; border: 0; border-bottom: 3px solid transparent; cursor: pointer;
  color: var(--muted, #7d8f9c); background: none;
  transition: color .18s ease, border-color .18s ease;
}
.cru-switch button:hover { color: var(--ink, #dff1fb); }
.cru-switch button.on {
  color: var(--ink, #e8f6ff); border-bottom-color: var(--copper-hot, #d4823c);
}

.cru-meter { display: inline-flex; align-items: baseline; gap: 9px; font-size: 12px; }
.cru-meter .lbl { color: var(--muted, #7d8f9c); letter-spacing: .12em; text-transform: uppercase; font-size: 10.5px; }
.cru-meter .val { color: var(--copper-hot, #d4823c); font-variant-numeric: tabular-nums; font-size: 13.5px; }

.cru-log-btn { font: inherit; font-size: 12.5px; cursor: pointer; padding: 9px 15px; border-radius: 3px;
  color: var(--ink-soft, #b9d3e4); border: 1px solid var(--glass-line, rgba(150,200,230,.22));
  background: linear-gradient(180deg, rgba(14,33,54,.85), rgba(4,11,20,.92));
  transition: all .18s ease; }
.cru-log-btn:hover { color: var(--ink, #e8f6ff); border-color: rgba(118, 255, 104, .35); }

/* ---------- blueprint ------------------------------------------------------------------- */
.cru-title { margin: 0; font-size: 15px; font-weight: 600; color: var(--ink, #e8f6ff); letter-spacing: .02em; }
.cru-blueprint { display: grid; gap: 11px; }

/* A command record, not a chat bubble: square shoulders, a recessed face, a state edge. */
.cru-card {
  display: grid; gap: 8px;
  padding: 15px 17px;
  border: 1px solid var(--glass-line, rgba(150, 200, 230, .18));
  border-left: 3px solid rgba(125, 143, 156, .5);
  border-radius: 3px;
  background: linear-gradient(180deg, rgba(11, 27, 44, .82), rgba(3, 10, 18, .93));
  box-shadow: inset 0 1px 0 rgba(210, 240, 255, .08), 0 8px 20px rgba(0, 0, 0, .42);
}
.cru-card[data-state="running"]   { border-left-color: var(--energy, #76ff68); }
.cru-card[data-state="done"]      { border-left-color: rgba(118, 255, 104, .55); }
.cru-card[data-state="repairing"] { border-left-color: var(--copper-hot, #d4823c); }
.cru-card[data-state="failed"],
.cru-card[data-state="blocked"]   { border-left-color: #e2544a; }

.c-top { display: flex; align-items: center; gap: 11px; }
.c-num {
  flex: 0 0 auto; width: 23px; height: 23px; border-radius: 3px;
  display: grid; place-items: center;
  font-size: 11.5px; font-variant-numeric: tabular-nums;
  color: var(--copper-hot, #d4823c);
  border: 1px solid rgba(185, 107, 50, .4);
  background: linear-gradient(180deg, rgba(48, 24, 10, .8), rgba(12, 6, 3, .9));
}
.c-title { flex: 1 1 auto; font-size: 14.5px; color: var(--ink, #e8f6ff); }
.c-state {
  flex: 0 0 auto; font-size: 10px; letter-spacing: .13em; text-transform: uppercase;
  color: var(--muted, #7d8f9c);
}
.cru-card[data-state="running"] .c-state { color: var(--energy-hot, #9dff92); }
.cru-card[data-state="failed"] .c-state,
.cru-card[data-state="blocked"] .c-state { color: #ff8b81; }

.c-why { margin: 0; font-size: 13.5px; line-height: 1.6; color: var(--ink-soft, #b9d3e4); }
.c-msg {
  margin: 0; padding: 9px 11px; border-radius: 3px;
  font-size: 12.5px; line-height: 1.55; color: #ffc9a8;
  border-left: 2px solid rgba(212, 130, 60, .55);
  background: rgba(48, 24, 10, .3);
}
.c-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.c-files, .c-model {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  color: var(--muted, #8ba0ae);
  border: 1px solid rgba(150, 200, 230, .16);
  background: rgba(6, 17, 28, .7);
}
.c-model { color: var(--ink-soft, #b9d3e4); }
.c-model.is-forge { color: var(--copper-hot, #d4823c); border-color: rgba(185, 107, 50, .35); }

.cru-note { margin: 0; font-size: 12.5px; line-height: 1.6; color: var(--muted, #7d8f9c); }
.cru-outcome { margin: 0; font-size: 13px; color: var(--ink-soft, #b9d3e4); }
.cru-outcome[data-outcome="done"] { color: var(--energy-hot, #9dff92); }
.cru-outcome[data-outcome="error"] { color: #ff8b81; }

.cru-empty { display: grid; gap: 9px; padding: 26px 4px; }
.cru-empty h3 { margin: 0; font-size: 15px; color: var(--ink, #e8f6ff); font-weight: 600; }
.cru-empty p { margin: 0; max-width: 46ch; font-size: 13.5px; line-height: 1.65; color: var(--muted, #8ba0ae); }

/* ---------- workshop -------------------------------------------------------------------- */
.cru-workshop { display: grid; gap: 18px; }
.w-section { display: grid; gap: 9px; }
.w-section h4 {
  margin: 0; font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--copper-hot, #d4823c);
}

.w-tree { list-style: none; margin: 0; padding: 0 0 0 13px; font-size: 12.5px; }
.w-tree .w-tree { border-left: 1px solid rgba(150, 200, 230, .13); }
.w-tree li { padding: 2.5px 0; color: var(--ink-soft, #b9d3e4); }
.w-tree li.is-dir { color: var(--muted, #8ba0ae); }
.w-tree li.is-dir::before { content: "/ "; color: rgba(185, 107, 50, .6); }
.w-tree li.is-file::before { content: "\00b7 "; color: rgba(150, 200, 230, .4); }
.w-bytes { margin-left: 8px; font-size: 11px; color: var(--muted, #6f8492); font-variant-numeric: tabular-nums; }

.w-diff, .w-run {
  border: 1px solid var(--glass-line, rgba(150, 200, 230, .16));
  border-radius: 3px;
  background: linear-gradient(180deg, rgba(6, 17, 28, .8), rgba(2, 8, 14, .92));
  overflow: hidden;
}
.w-diff-head, .w-run-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px; font-size: 12px; color: var(--ink-soft, #b9d3e4);
  border-bottom: 1px solid rgba(150, 200, 230, .12);
  background: rgba(11, 27, 44, .6);
}
.w-diff-stat { font-size: 11px; color: var(--muted, #8ba0ae); font-variant-numeric: tabular-nums; }
.w-run-badge { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.w-run[data-ok="yes"] .w-run-badge { color: var(--energy-hot, #9dff92); }
.w-run[data-ok="no"] .w-run-badge { color: #ff8b81; }
.w-run[data-ok="no"] { border-color: rgba(226, 84, 74, .35); }

.w-diff pre, .w-run pre {
  margin: 0; padding: 11px 12px; max-height: 320px; overflow: auto;
  font: 400 11.5px/1.55 "Cascadia Mono", "Consolas", ui-monospace, monospace;
  color: var(--ink-soft, #b9d3e4);
  white-space: pre-wrap; word-break: break-word;
}
.w-diff pre .add { color: #9dff92; }
.w-diff pre .del { color: #ff8b81; }
.w-diff pre .ctx { color: var(--muted, #8ba0ae); }

/* ---------- past-builds log panel -------------------------------------------------------- */
#cru-log {
  position: fixed; right: 0; top: 0; bottom: 0; width: min(320px, 86vw);
  background: linear-gradient(180deg, rgba(6, 17, 28, .95), rgba(2, 8, 14, .98));
  border-left: 1px solid var(--glass-line, rgba(150, 200, 230, .18));
  box-shadow: -8px 0 30px rgba(0, 0, 0, .6);
  display: flex; flex-direction: column; z-index: 342;
  overflow-y: auto;
}
.cru-log-close {
  font: inherit; font-size: 13px; cursor: pointer;
  padding: 12px 14px; border: 0; margin: 0; align-self: flex-end;
  color: var(--muted, #8ba0ae); background: none;
  transition: color .18s ease;
}
.cru-log-close:hover { color: var(--ink, #e8f6ff); }
.cru-log-loading, .cru-log-empty {
  margin: 20px 14px; font-size: 12.5px; color: var(--muted, #8ba0ae);
}
.cru-log-list {
  display: flex; flex-direction: column; gap: 0;
}
.cru-log-entry {
  font: inherit; font-size: 12px; cursor: pointer;
  padding: 12px 14px; border: 0; text-align: left;
  color: var(--ink-soft, #b9d3e4);
  background: none; border-top: 1px solid rgba(150, 200, 230, .08);
  transition: background .15s ease, color .15s ease;
  display: flex; flex-direction: column; gap: 3px; min-width: 0;
}
.cru-log-entry:hover { color: var(--ink, #e8f6ff); background: rgba(16, 34, 54, .4); }
.log-title {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12.5px; font-weight: 500; color: inherit;
}
.log-meta {
  font-size: 11px; color: var(--muted, #8ba0ae);
}

/* ---------- phone ------------------------------------------------------------------------
 * Blueprint has to be fully usable on a phone, because approving a build from anywhere is the
 * point of the whole background-persistence design. Workshop stays readable but is desktop-first. */
@media (max-width: 620px) {
  .cru-head { gap: 10px; }
  /* The lens switch stays the dominant header on a phone too: a hair smaller so it fits without
     overflowing, never small enough for the eye to skip. */
  .cru-switch button { padding: 10px 14px; font-size: 15px; letter-spacing: .04em; }
  .cru-card { padding: 13px 14px; }
  .c-title { font-size: 14px; }
  .w-diff pre, .w-run pre { font-size: 11px; max-height: 220px; }
}

/* ---------- the publish invitation as modal ------------------------------------------------------ */
.cru-publish-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .6); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 345;
}
.cru-publish-modal {
  display: grid; gap: 10px; max-width: 420px; width: 90vw;
  padding: 17px 19px; border-radius: 3px;
  border: 1px solid rgba(157, 255, 146, .4);
  border-left: 3px solid var(--energy, #76ff68);
  background: linear-gradient(180deg, rgba(9, 34, 18, .95), rgba(2, 11, 6, .98));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .8);
}
.cru-publish-modal .pub-done { margin: 0; font-size: 12.5px; color: var(--muted, #8ba0ae); }
.cru-publish-modal h3 { margin: 0; font-size: 15.5px; font-weight: 600; color: var(--energy-hot, #9dff92); }
.cru-publish-modal .pub-row { display: flex; gap: 9px; flex-wrap: wrap; }
.cru-publish-modal button { font: inherit; font-size: 12.5px; cursor: pointer; padding: 9px 15px; border-radius: 3px;
  color: var(--ink, #e8f6ff); border: 1px solid var(--glass-line, rgba(150,200,230,.22));
  background: linear-gradient(180deg, rgba(14,33,54,.92), rgba(4,11,20,.96)); }
.cru-publish-modal button:hover { border-color: rgba(118, 255, 104, .45); }
.cru-publish-modal .pub-later { color: var(--muted, #8ba0ae); }
.cru-publish-modal .pub-explain { margin: 0; font-size: 13px; line-height: 1.7; color: var(--ink-soft, #b9d3e4); max-width: 64ch; }

/* The lens column must never widen the stage either; long diff lines and cost strings shrink
   inside their own boxes instead of asserting content width. */
#cru { max-width: 100%; min-width: 0; grid-template-columns: minmax(0, 1fr); }
#cru .cru-head, #cru .cru-body { min-width: 0; max-width: 100%; }

/* ============================== ITERATION 2: modes in the lenses =========================== */
/* One container of compact rows, never fifteen boxes. */
.cru-plan { display: grid; gap: 0; border: 1px solid var(--glass-line, rgba(150,200,230,.18));
  border-radius: 4px; overflow: hidden; min-width: 0; }
.cru-row { min-width: 0; border-bottom: 1px solid rgba(150,200,230,.08); }
.cru-row:last-child { border-bottom: 0; }
/* A sub-agent row sits visibly under its task: indented, thinner, with a lineage rail. */
.cru-row.cru-sub .r-line { padding-left: 34px; }
.cru-row.cru-sub { border-left: 2px solid rgba(185, 107, 50, .35); background: rgba(10, 20, 32, .35); }
.cru-row.cru-sub .c-num { border-color: transparent; background: none; }
.cru-row.cru-sub .c-title { font-size: 13.5px; color: var(--ink-soft, #b9d3e4); }
.cru-row[data-state="skipped"] .c-title { color: var(--muted, #7d8f9c); }
.cru-row[data-state="skipped"] .c-state { color: #d9a04b; }
.cru-row .r-line { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  font: inherit; cursor: pointer; border: 0; padding: 10px 12px; min-width: 0;
  background: linear-gradient(180deg, rgba(10,24,40,.55), rgba(4,10,18,.55)); color: inherit; }
.cru-row .r-line:hover { background: rgba(16, 34, 54, .65); }
.cru-row .c-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: 13px; color: var(--ink, #e8f6ff); }
.cru-row[data-state="running"] .c-title { text-shadow: 0 0 14px rgba(118,255,104,.25); }
.cru-row .r-detail { padding: 4px 12px 12px 34px; display: grid; gap: 6px; min-width: 0;
  background: rgba(4, 10, 18, .5); }
.cru-plansum { font: inherit; font-size: 13px; cursor: pointer; text-align: left; padding: 12px 14px;
  border-radius: 4px; color: var(--ink-soft, #d9c9b8);
  border: 1px solid var(--glass-line, rgba(150,200,230,.18));
  background: linear-gradient(180deg, rgba(10,24,40,.55), rgba(4,10,18,.55)); }
.cru-plansum:hover { border-color: rgba(185, 107, 50, .5); }
.w-code-toggle { font: inherit; font-size: 12.5px; cursor: pointer; padding: 9px 16px;
  border-radius: 3px; justify-self: start; color: var(--ink-soft, #d9c9b8);
  border: 1px solid var(--glass-line, rgba(150,200,230,.2));
  background: linear-gradient(180deg, rgba(14,33,54,.9), rgba(4,11,20,.95)); }
.w-code-toggle:hover { border-color: rgba(118, 255, 104, .4); }

/* ---------- the live preview frame -------------------------------------------------------- */
.w-preview { min-width: 0; }
.w-preview-open, .w-preview-close { font: inherit; font-size: 12.5px; cursor: pointer;
  padding: 9px 16px; border-radius: 3px; justify-self: start; color: var(--ink, #e8f6ff);
  border: 1px solid rgba(118, 255, 104, .45);
  background: linear-gradient(180deg, rgba(14,33,54,.92), rgba(4,11,20,.96)); }
.w-preview-close { color: var(--muted, #8ba0ae); border-color: var(--glass-line, rgba(150,200,230,.2)); }
.w-preview-frame { width: 100%; height: 62vh; border: 1px solid rgba(185, 107, 50, .45);
  border-radius: 4px; background: #fff; display: block; margin-bottom: 8px; }
/* The engineer reads code beside the running thing when the screen affords it. */
@media (min-width: 900px) {
  .cru-workshop[data-mode="engineer"] { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr);
    gap: 14px; align-items: start; }
  .cru-workshop[data-mode="engineer"] .w-preview { grid-column: 2; grid-row: 1 / span 4; position: sticky; top: 8px; }
  .cru-workshop[data-mode="engineer"] .w-section:not(.w-preview) { grid-column: 1; }
}
