/* ────────────────────────────────────────────────────────────────
   Denah — styles
   Track C (Editor & UI).

   Precision instrument, not a consumer app. Dense but calm. Dark
   chrome around a CAD-dark canvas so build-state tints carry the
   signal. Restraint everywhere except one place: the DEMO RATES
   watermark, which is deliberately loud. PRD §7 R1.

   No web fonts, no CDN — this has to work on a meeting-room laptop
   with no network.
   ──────────────────────────────────────────────────────────────── */

/* ────────────────────────────────────────────────────────────────
   Tokens
   ──────────────────────────────────────────────────────────────── */

:root {
  --bg: #0b0e10;
  --panel: #101417;
  --panel-2: #14191d;
  --line: #232a30;
  --line-soft: #1b2126;
  --ink: #e6eaee;
  --ink-2: #9aa5af;
  --ink-3: #6b7681;
  --accent: #4c8dff;
  --accent-ink: #0b0e10;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #f0616d;
  --demo: #ffb020;
  --demo-ink: #1a1204;
  --trace: #c4a5f5;
  --trace-ink: #16091f;

  --r: 6px;
  --r-lg: 10px;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --pad: 14px;
}

/* ────────────────────────────────────────────────────────────────
   Reset
   ──────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
h1, h2, h3, p, dl, dd, ul, figure { margin: 0; }
ul { list-style: none; padding: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.4; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; clip: rect(0 0 0 0); overflow: hidden; }
.num, .money { font-variant-numeric: tabular-nums; }
.money { font-family: var(--mono); font-size: 0.95em; letter-spacing: -0.01em; }
.muted { color: var(--ink-3); }
.is-bad { color: var(--bad); }
.is-good { color: var(--good); }
.empty { color: var(--ink-3); font-size: 12px; padding: 8px 0; }
.empty.is-error { color: var(--bad); }
.empty.is-warn { color: var(--warn); }

/* ────────────────────────────────────────────────────────────────
   Cost caveats
   Two independent failures, two badges, two colours, two sentences:
   the rates are invented (amber), and the geometry is a guess (violet).
   Real rates on traced geometry are still wrong, so these must not
   collapse into one. Loud on purpose. Anything showing money shows
   whichever apply. PRD §7 R1/R2.
   ──────────────────────────────────────────────────────────────── */

.caveat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 700 9px/1.25 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 3px;
  padding: 4px 6px;
  cursor: help;
  text-align: center;
}
.caveat--demo { color: var(--demo-ink); background: var(--demo); }
.caveat--trace { color: var(--trace-ink); background: var(--trace); }

.caveat--block {
  display: flex;
  width: 100%;
  justify-content: center;
  margin-top: 6px;
  background-image: repeating-linear-gradient(
    -45deg, rgba(0, 0, 0, 0.14) 0 6px, transparent 6px 12px
  );
}
/* Only the last badge in a stack rounds off against the container edge. */
.caveat--block:last-child { border-radius: 0 0 var(--r) var(--r); }

.demo-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--demo);
  color: var(--demo-ink);
  font: 700 10px/1 var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 7px;
  background-image: repeating-linear-gradient(
    -45deg, rgba(0, 0, 0, 0.12) 0 8px, transparent 8px 16px
  );
}
.demo-bar span { font-weight: 500; letter-spacing: 0.04em; text-transform: none; opacity: 0.8; }
.trace-bar { background: var(--trace); color: var(--trace-ink); }

/* Frames the cards below it — the reader must hit this before comparing
   figures that turn out to be the same figure. */
.results__tied {
  color: var(--ink-2);
  font-size: 11.5px;
  line-height: 1.5;
  padding: 9px 10px;
  border-left: 2px solid var(--accent);
  background: rgba(76, 141, 255, 0.07);
  border-radius: 0 var(--r) var(--r) 0;
}

.results__short {
  color: var(--ink-3);
  font-size: 11.5px;
  line-height: 1.5;
  padding: 9px 10px;
  border: 1px dashed var(--line);
  border-radius: var(--r);
}
.results__short strong { color: var(--ink-2); }

/* ────────────────────────────────────────────────────────────────
   Shell
   ──────────────────────────────────────────────────────────────── */

.app {
  display: grid;
  height: 100vh;
  grid-template-columns: minmax(0, 1fr) 460px;
  grid-template-rows: auto auto minmax(0, 1fr) 216px;
  grid-template-areas:
    "demo   demo"
    "head   head"
    "canvas aside"
    "gantt  aside";
}
.app__demo { grid-area: demo; }
.app__head { grid-area: head; }
.app__canvas { grid-area: canvas; }
.app__aside { grid-area: aside; }
.app__gantt { grid-area: gantt; }

.app__head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  height: 46px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 9px; }
.brand__mark { font: 700 15px/1 var(--sans); letter-spacing: -0.02em; }
.brand__sub { color: var(--ink-3); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; }
.head__floor { color: var(--ink-2); font-size: 12px; }
.head__spacer { flex: 1; }
.head__hint { color: var(--ink-3); font-size: 11px; font-family: var(--mono); }

.app__canvas { position: relative; background: #101417; border-right: 1px solid var(--line); }
#plan { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
body[data-tool="select"] #plan { cursor: default; }
body[data-tool="move"] #plan { cursor: grab; }

.app__aside {
  overflow-y: auto;
  overflow-x: hidden; /* nothing in here may push the panel wider than its column */
  overscroll-behavior: contain;
  background: var(--panel);
  border-left: 1px solid var(--line);
}
.app__aside > section { border-bottom: 1px solid var(--line); padding: var(--pad); }
.app__aside > section[hidden] { display: none; }

.app__gantt {
  position: relative;
  background: var(--panel-2);
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0 12px 10px;
}
.gantt__head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 10px;
  font: 600 11px/1 var(--sans); letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-3);
  background: var(--panel-2);
  padding: 10px 0 8px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 8px;
}
.gantt__head .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
.gantt__head #gantt-toggle { margin-left: auto; }

/* schedule/gantt.js ships a light theme (--dn-ink: #1c2430) and frappe-gantt
   draws on white. That is Track B's call and a reasonable one — but its
   legend text is near-black, which is invisible on this panel. Rather than
   override their variables and own their theme forever, give the chart the
   light surface it was designed for. It reads as a document inside the tool. */
#gantt-body {
  background: #f4f5f7;
  border: 1px solid #d9dde3;
  border-radius: var(--r);
  padding: 2px 10px 8px;
  min-height: 60px;
}
#gantt-body .empty { color: var(--bad); }
.btn--xs { padding: 4px 8px; font-size: 11px; text-transform: none; letter-spacing: 0; font-weight: 500; }

/* The strip is a glance; the drawer is for reading. Grid rows, so the
   canvas gives up the space rather than the chart overlapping it. */
body[data-gantt="open"] .app { grid-template-rows: auto auto minmax(0, 1fr) 58vh; }

/* Solver re-run on building-type swap — a real 380 ms recompute,
   flagged so the room sees the answer change rather than blink. */
body[data-recomputing] .results,
body[data-recomputing] .totals { animation: recompute 380ms ease; }
@keyframes recompute {
  0% { opacity: 1; }
  35% { opacity: 0.15; transform: translateY(2px); }
  100% { opacity: 1; }
}

/* ────────────────────────────────────────────────────────────────
   Panel primitives
   ──────────────────────────────────────────────────────────────── */

.panel__head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.panel__head h2 {
  font: 600 11px/1 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2);
}
.panel__head p { flex-basis: 100%; color: var(--ink-3); font-size: 11.5px; }

.kv { display: grid; gap: 3px; margin-top: 10px; }
.kv__row { display: flex; justify-content: space-between; gap: 12px; font-size: 11.5px; }
.kv dt { color: var(--ink-3); }
.kv dd { color: var(--ink-2); font-variant-numeric: tabular-nums; text-align: right; }

.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 7px 11px;
  font-size: 12px;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover:not(:disabled) { background: #1a2026; border-color: #2d363e; }
.btn--ghost { background: transparent; }
.btn--primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.btn--primary:hover:not(:disabled) { background: #6ba0ff; border-color: #6ba0ff; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg__btn {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  background: transparent; border: 0; border-right: 1px solid var(--line);
  padding: 7px 6px; font-size: 12px; color: var(--ink-2);
}
.seg__btn:last-child { border-right: 0; }
.seg__btn:hover { background: var(--panel-2); color: var(--ink); }
.seg__btn.is-on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg--sm { margin-top: 6px; }
.seg--sm .seg__btn { font-size: 10.5px; text-transform: capitalize; }
.seg__btn--not_started.is-on { background: #64748b; color: #fff; }
.seg__btn--in_progress.is-on { background: var(--warn); color: #1a1204; }
.seg__btn--finished.is-on { background: var(--good); color: #04140a; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dot); }

/* ────────────────────────────────────────────────────────────────
   Toolbar
   ──────────────────────────────────────────────────────────────── */

.toolbar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.tool {
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r);
  padding: 6px 7px; font-size: 11.5px; color: var(--ink-2);
}
.tool:hover { border-color: #2d363e; color: var(--ink); }
.tool.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.tool kbd {
  font: 600 9px/1 var(--mono); color: var(--ink-3);
  border: 1px solid var(--line); border-radius: 3px; padding: 2px 3px;
}
.tool.is-on kbd { color: var(--accent-ink); border-color: rgba(0, 0, 0, 0.25); }
.toolbar__hint { color: var(--ink-3); font-size: 11px; margin-top: 8px; min-height: 16px; }
.toolbar__undo { display: flex; gap: 6px; margin-top: 6px; }
.toolbar__undo .btn { flex: 1; }

/* ────────────────────────────────────────────────────────────────
   Rooms + build-state chips
   ──────────────────────────────────────────────────────────────── */

.rooms { display: grid; gap: 4px; }
.room {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r);
  padding: 8px 10px; text-align: left;
}
.room:hover { border-color: #2d363e; }
.room.is-on { border-color: var(--accent); background: #131c2b; }
.room__name { font-weight: 600; font-size: 12.5px; }
.room__meta { grid-column: 1; color: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.room__zones { grid-row: 1 / 3; grid-column: 2; display: flex; gap: 3px; }

.chip { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.chip--not_started { background: #64748b; }
.chip--in_progress {
  background: var(--warn);
  background-image: repeating-linear-gradient(-45deg, rgba(0,0,0,0.3) 0 2px, transparent 2px 4px);
}
.chip--finished {
  background: var(--good);
  background-image: repeating-linear-gradient(-45deg, rgba(0,0,0,0.3) 0 1px, transparent 1px 3px);
}
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; color: var(--ink-3); font-size: 10.5px; }
.legend__item { display: flex; align-items: center; gap: 5px; }

/* ────────────────────────────────────────────────────────────────
   Totals
   ──────────────────────────────────────────────────────────────── */

.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.total {
  display: grid; gap: 3px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r); padding: 10px;
}
.total__k { color: var(--ink-3); font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase; }
.total__v { font-size: 16px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.total__v em { display: block; font: 400 10.5px/1.3 var(--sans); font-style: normal; color: var(--ink-3); margin-top: 2px; }

.commits { display: grid; gap: 2px; margin-top: 10px; }
.commits li {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: baseline;
  font-size: 11.5px; padding: 5px 0; border-top: 1px solid var(--line-soft);
}

/* ────────────────────────────────────────────────────────────────
   Validation
   ──────────────────────────────────────────────────────────────── */

.issues { display: grid; gap: 3px; }
.issue {
  font-size: 11px; padding: 5px 8px; border-radius: 4px; border-left: 2px solid;
  font-family: var(--mono); line-height: 1.4;
}
.issue--error { border-color: var(--bad); background: rgba(240, 97, 109, 0.08); color: #ffb4ba; }
.issue--warn { border-color: var(--warn); background: rgba(245, 158, 11, 0.07); color: #f3ce8e; }

/* ────────────────────────────────────────────────────────────────
   What-if — the money shot
   ──────────────────────────────────────────────────────────────── */

.whatif { background: var(--panel-2); }
.ask { display: flex; gap: 6px; }
.ask__input {
  flex: 1; min-width: 0;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r);
  padding: 8px 10px; font-size: 13px;
}
.ask__input::placeholder { color: var(--ink-3); }
.ask__input:focus { border-color: var(--accent); outline: none; }
.ask__picker {
  width: 100%; margin-top: 6px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r);
  padding: 6px 8px; font-size: 11.5px; color: var(--ink-2);
}
.ask__status { color: var(--ink-3); font-size: 11px; margin-top: 8px; min-height: 15px; }
.ask__status.is-busy { color: var(--accent); }
.ask__status.is-error { color: var(--bad); }
.ask__warn { color: var(--warn); font-weight: 600; }

.results { display: grid; gap: 10px; margin-top: 12px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 12px; transition: border-color 0.12s, transform 0.12s;
}
.card:hover { border-color: #35414c; transform: translateY(-1px); }
.card.is-best { border-color: #2c4a7c; }

.card__head { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.card__rank {
  display: grid; place-items: center; width: 22px; height: 22px; flex: none;
  border-radius: 5px; background: var(--line); color: var(--ink-2);
  font: 700 11px/1 var(--mono);
}
.card.is-best .card__rank { background: var(--accent); color: var(--accent-ink); }
.card__where { display: grid; gap: 1px; min-width: 0; }
.card__where strong,
.card__where span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card__where strong { font-size: 12.5px; }
.card__where span { color: var(--ink-3); font: 10.5px/1 var(--mono); }
/* Role tags — the two poles of the tradeoff are the headline, so they are
   filled; balanced is a recommendation, so it is outlined; alternative is
   context, so it recedes. A card can carry several at once. */
.card__roles { display: flex; flex-wrap: wrap; gap: 5px; margin: 0 0 10px; }
.card__roles:empty { display: none; }
.role {
  font: 700 9px/1 var(--sans); letter-spacing: 0.08em; text-transform: uppercase;
  border-radius: 3px; padding: 4px 6px; border: 1px solid transparent; white-space: nowrap;
}
.role--cheapest { background: var(--accent); color: var(--accent-ink); }
.role--fastest { background: var(--good); color: #04140a; }
.role--balanced { color: var(--accent); border-color: #2c4a7c; }
.role--alternative { color: var(--ink-3); border-color: var(--line); }

.card__figures {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 10px;
}
.fig--rel { grid-column: 1 / -1; border-top: 1px solid var(--line-soft); padding-top: 8px; }
.fig { display: grid; gap: 2px; min-width: 0; }
.fig__k { color: var(--ink-3); font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase; }
.fig__v { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.fig--rel .fig__v { font-size: 13px; }

.card__narration {
  color: var(--ink-2); font-size: 12px; line-height: 1.5; margin: 10px 0;
  padding-left: 9px; border-left: 2px solid var(--line);
}
.card__narration[data-source="llm"] { border-color: var(--accent); }

.card__notes { display: grid; gap: 3px; margin: 10px 0 0; }
.card__notes li {
  color: var(--warn); font-size: 11px; line-height: 1.4; padding-left: 12px; position: relative;
}
.card__notes li::before { content: "!"; position: absolute; left: 2px; font-weight: 700; }

.card__commit { width: 100%; margin-top: 12px; }

/* Breakdown — the traceability table. This is the product. */
.br { margin-top: 10px; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.br summary {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 7px 10px; background: var(--bg);
  font: 600 10px/1 var(--sans); letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-2);
}
.br summary::-webkit-details-marker { display: none; }
.br__count { margin-left: auto; color: var(--ink-3); font-weight: 400; letter-spacing: 0; text-transform: none; }
/* Fixed layout: cost/model.js writes genuinely long explanatory labels
   ("Off-module cutting waste — footprint edges average 163 mm off the
   600 mm module grid…"). Auto layout lets one of those blow the table —
   and therefore the whole panel — past its column, clipping the amounts.
   The amounts are the point; they get reserved width and the prose wraps. */
.br__table { width: 100%; border-collapse: collapse; font-size: 10.5px; table-layout: fixed; }
.br__table th, .br__table td {
  padding: 5px 7px; text-align: left; border-top: 1px solid var(--line-soft);
  overflow-wrap: anywhere;
}
.br__table th:nth-child(2), .br__table td:nth-child(2) { width: 54px; white-space: nowrap; }
.br__table th:nth-child(3), .br__table td:nth-child(3) { width: 66px; }
.br__table th:nth-child(4), .br__table td:nth-child(4) { width: 74px; }
/* The digits are the product — they never wrap, whatever the label does. */
.br__table .money { white-space: nowrap; font-size: 9.5px; letter-spacing: -0.02em; }
.br__item { display: flex; flex-direction: column; gap: 2px; }
.br__label { color: var(--ink-2); }
.br__id {
  font-family: var(--mono); font-size: 9px; color: var(--ink-3);
  background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line-soft);
  border-radius: 3px; padding: 1px 3px; align-self: flex-start; max-width: 100%;
}
.br__table thead th {
  color: var(--ink-3); font-weight: 500; font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase;
  background: var(--panel);
}
.br__table .num { text-align: right; }
.br__table tbody td { color: var(--ink-2); }
.br__id { font-family: var(--mono); font-size: 9.5px; color: var(--ink-3) !important; white-space: nowrap; }
.br__cat th {
  background: var(--panel); color: var(--ink); font-weight: 600; font-size: 10px;
  letter-spacing: 0.04em; text-transform: uppercase;
}
.br__cat td { background: var(--panel); font-weight: 600; text-align: right; }
.br__table tfoot th, .br__table tfoot td {
  background: var(--bg); font-weight: 700; font-size: 11.5px; border-top: 1px solid var(--line);
}
.br__table tfoot td { text-align: right; }

/* ────────────────────────────────────────────────────────────────
   Narrow / short screens — a meeting room projector is 1280×720
   ──────────────────────────────────────────────────────────────── */

@media (max-width: 1360px) {
  .app { grid-template-columns: minmax(0, 1fr) 400px; }
  .toolbar { grid-template-columns: repeat(3, 1fr); }
}
@media (max-height: 800px) {
  .app { grid-template-rows: auto auto minmax(0, 1fr) 176px; }
}
