/* AI Rig Builder — a board on the bench.
 *
 * The board is drawn bracket by bracket at a fixed height per bracket, so a
 * three-slot card is visibly three brackets tall and the slots under its
 * cooler are visibly covered. Everything else on the page is a reading of
 * that drawing, so the drawing gets the room and the colour.
 *
 * Colours carry one meaning each: green is a slot or fit that works, amber a
 * cost (shared lanes, a supply past the reader's margin, a tight fit), red
 * something that will not work as drawn. Card colour is the maker, so a
 * mixed-vendor rig reads as one at a glance.
 */

.product[data-product="rig-builder"] {
  --product-ink: #e3eaf1;
  --product-paper: #10171f;
  --product-signal: #5fbf86;
  --product-warn: #d9a53c;
  --product-alarm: #e06c62;
  --rb-pcb: #12372c;
  --rb-pcb-line: #1f5a47;
  --rb-slot: #20262d;
  --rb-nvidia: #4c9a2a;
  --rb-amd: #c2412d;
  --rb-intel: #2f6fc0;
  --rb-yours: #7a6bb8;
  --rb-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

.rb-h { margin: 0 0 .5rem; font-size: 1rem; letter-spacing: .01em; }
.rb-wait, .rb-empty { padding: 1rem; border: 1px dashed var(--border); border-radius: var(--radius, 6px); color: var(--muted); }
.rb-live { min-height: 1.4em; margin: .5rem 0; color: var(--text); font-size: .95rem; }

.rb-rigbar, .rb-boardbar { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: end; margin-bottom: .75rem; }
.rb-rigactions { display: flex; flex-wrap: wrap; gap: .35rem; }
.rb-rigpick { display: grid; gap: .2rem; font-size: .85rem; color: var(--muted); }
.rb-select { min-height: 2.5rem; padding: .35rem .5rem; border: 1px solid var(--border); border-radius: var(--radius, 6px);
  background: var(--surface); color: var(--text); font: inherit; max-width: 100%; }

.rb-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .5rem; margin-bottom: 1rem; }
.rb-tile { display: grid; gap: .1rem; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: var(--radius, 6px); background: var(--surface); }
.rb-tile-label { color: var(--muted); font-size: .8rem; }
.rb-tile-value { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.rb-tile-sub { color: var(--muted); font-size: .8rem; }
.rb-tile.tone-bad { border-color: var(--product-alarm); }
.rb-tile.tone-bad .rb-tile-value { color: var(--product-alarm); }
.rb-tile.tone-warn .rb-tile-value { color: var(--product-warn); }
.rb-tile.tone-good .rb-tile-value { color: var(--product-signal); }

.rb-stage { display: grid; grid-template-columns: minmax(14rem, 17rem) minmax(0, 1fr) minmax(14rem, 17rem); gap: 1rem; align-items: start; }
@media (max-width: 1100px) {
  .rb-stage { grid-template-columns: minmax(0, 1fr) minmax(14rem, 17rem); }
  .rb-library { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .rb-stage { grid-template-columns: minmax(0, 1fr); }
}

/* ── Parts bin ── */
.rb-library { display: grid; gap: .5rem; }
.rb-search { width: 100%; }
.rb-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.rb-chip { min-height: 2rem; padding: .2rem .65rem; border: 1px solid var(--border); border-radius: 999px; background: transparent; color: var(--text); font: inherit; font-size: .85rem; cursor: pointer; }
.rb-chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-contrast, #000); }
.rb-parts { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; max-height: 34rem; overflow-y: auto; overscroll-behavior: contain; }
@media (max-width: 1100px) { .rb-parts { grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); max-height: 20rem; } }
.rb-part { display: grid; grid-template-columns: 1.6rem 1fr auto; gap: .5rem; align-items: center; padding: .4rem .5rem;
  border: 1px solid var(--border); border-radius: var(--radius, 6px); background: var(--surface); cursor: grab; touch-action: none; user-select: none; }
.rb-part:hover { border-color: var(--accent); }
.rb-part-text { display: grid; min-width: 0; font-size: .85rem; }
.rb-part-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rb-part-text span { color: var(--muted); font-size: .78rem; }
.rb-add { min-height: 2rem; padding: .2rem .6rem; border: 1px solid var(--border); border-radius: var(--radius, 6px); background: transparent; color: var(--text); font: inherit; font-size: .8rem; cursor: pointer; }
.rb-add:hover, .rb-add:focus-visible { border-color: var(--accent); }
.rb-mini { display: block; width: 1.4rem; border-radius: 2px; background: var(--rb-yours); }
.rb-vendor-nvidia.rb-mini { background: var(--rb-nvidia); }
.rb-vendor-amd.rb-mini { background: var(--rb-amd); }
.rb-vendor-intel.rb-mini { background: var(--rb-intel); }
.rb-none { color: var(--muted); font-size: .85rem; padding: .5rem; }
.rb-custom { display: grid; gap: .5rem; padding-top: .5rem; }

.rb-shelves { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); }
.rb-shelf { min-height: 2.25rem; padding: .3rem .6rem; border: 0; border-bottom: 2px solid transparent; background: transparent;
  color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer; }
.rb-shelf[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 700; }
.rb-shelf:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.rb-mini-cpu { display: block; width: 1.3rem; height: 1.3rem; border-radius: 2px; background: #8d969f;
  box-shadow: inset 0 0 0 3px #5b636b; }
.rb-mini-cpu.rb-vendor-amd { background: #b9bfc6; box-shadow: inset 0 0 0 3px var(--rb-amd); }
.rb-mini-cpu.rb-vendor-intel { background: #b9bfc6; box-shadow: inset 0 0 0 3px var(--rb-intel); }
.rb-part.is-chosen { border-color: var(--product-signal); }
.rb-part.is-static { grid-template-columns: 1fr auto; cursor: default; }
.rb-part-src { color: var(--muted); font-size: .7rem; letter-spacing: .02em; text-transform: uppercase; }
.rb-more { margin: 0; }
.rb-shelves { flex-wrap: wrap; }
.rb-buildlist ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }
.rb-buildrow { display: grid; grid-template-columns: 5.5rem 1fr auto; gap: .4rem; align-items: center; font-size: .82rem; }
.rb-buildkind { color: var(--muted); }
.rb-buildname { display: grid; min-width: 0; }
.rb-buildname strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.rb-buildname small { color: var(--muted); }
.rb-pair { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.rb-psuadd { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .5rem 0; }
.rb-psuadd .input { max-width: 22rem; }

.rb-field { display: grid; gap: .2rem; font-size: .85rem; }
.rb-field > span { color: var(--muted); }
.rb-field small { color: var(--muted); font-size: .75rem; }
.rb-field .input { width: 100%; }
.rb-check { display: flex; gap: .5rem; align-items: center; margin: .5rem 0; font-size: .9rem; }

/* ── The board ── */
.rb-bench { display: grid; gap: .75rem; min-width: 0; }
.rb-boardmeta { margin: -.25rem 0 .25rem; color: var(--muted); font-size: .85rem; }
.rb-board-scroll { overflow-x: auto; }
.rb-board { position: relative; min-width: 19rem; background: repeating-linear-gradient(90deg, transparent 0 39px, rgba(255,255,255,.025) 39px 40px); }
.rb-pcb { position: absolute; left: 2rem; right: 0; top: 0; border-radius: 6px; background: var(--rb-pcb);
  box-shadow: inset 0 0 0 1px var(--rb-pcb-line); }
.rb-bracket { position: absolute; left: 0; right: 0; border-top: 1px dashed rgba(255,255,255,.08); pointer-events: none; }
.rb-bracket-n { position: absolute; left: .3rem; top: .4rem; color: var(--muted); font: .75rem var(--rb-mono); }
.rb-bracket.is-case { background: rgba(255,255,255,.03); }
.rb-bracket.is-missing { background: repeating-linear-gradient(135deg, rgba(224,108,98,.08) 0 8px, transparent 8px 16px); }
.rb-bracket-note { position: absolute; left: 2.6rem; top: .9rem; color: var(--muted); font-size: .75rem; }

/* The top of the board: socket and memory, above the first bracket. */
.rb-platform { display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; align-items: center; margin-left: 2rem; padding: .75rem .9rem;
  border-radius: 6px 6px 0 0; background: var(--rb-pcb); box-shadow: inset 0 0 0 1px var(--rb-pcb-line); min-width: 17rem; }
.rb-socket { display: grid; gap: .15rem; min-width: 11rem; min-height: 4.2rem; padding: .5rem .7rem; text-align: left;
  border: 2px dashed #5b6b66; border-radius: 4px; background: rgba(0,0,0,.25); color: #dfe7ee; font: inherit; cursor: pointer; }
.rb-socket.is-fitted { border-style: solid; border-color: #9aa5ae; background: linear-gradient(135deg, #59626b, #3c434a); }
.rb-socket.is-wrong { border-color: var(--product-alarm); }
.rb-socket.is-selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.rb-socket:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.rb-socket.is-drop-ok { border-color: var(--product-signal); box-shadow: 0 0 0 2px var(--product-signal); }
.rb-socket.is-drop-no { border-color: var(--product-alarm); box-shadow: 0 0 0 2px var(--product-alarm); }
.rb-socket-name { font-weight: 700; font-size: .9rem; }
.rb-socket-meta { font: .72rem var(--rb-mono); opacity: .85; }
.rb-memwrap { display: grid; gap: .3rem; }
.rb-dimms { display: flex; gap: 4px; }
.rb-dimm { display: block; width: 8px; height: 3.4rem; border-radius: 1px; background: #1b222a; box-shadow: inset 0 0 0 1px #3a434d; }
.rb-dimm.is-filled { background: linear-gradient(#2f6b52, #24543f); box-shadow: inset 0 0 0 1px #6fb894; }
.rb-dimm.is-over { background: var(--product-alarm); }
.rb-dimm-label { color: #c9d3dc; font: .72rem var(--rb-mono); }
.rb-platform + .rb-board .rb-pcb { border-radius: 0 0 6px 6px; }

.rb-slot { position: absolute; left: 2.8rem; right: .8rem; height: 32px; display: flex; align-items: center; padding: 0 .6rem;
  border: 1px solid #3a434d; border-radius: 3px; background: var(--rb-slot); color: #c9d3dc; font: .75rem var(--rb-mono);
  text-align: left; cursor: pointer; }
.rb-slot.is-x1 { right: 70%; }
.rb-slot.is-x4 { right: 45%; }
.rb-slot.is-x8 { right: 28%; }
.rb-slot.is-unplaced { border-style: dashed; }
.rb-slot.is-covered { opacity: .45; }
.rb-slot:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rb-slot.is-drop-ok { border-color: var(--product-signal); box-shadow: 0 0 0 2px var(--product-signal); }
.rb-slot.is-drop-no { border-color: var(--product-alarm); box-shadow: 0 0 0 2px var(--product-alarm); }
.rb-slot-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.rb-card { display: grid; align-content: start; gap: .1rem; padding: .45rem .6rem; border-radius: 4px; color: #fff;
  background: var(--rb-yours); border: 1px solid rgba(255,255,255,.25); cursor: grab; touch-action: none; user-select: none;
  box-shadow: 0 6px 16px rgba(0,0,0,.35); }
.rb-card { --rb-card-bg: #2c2840; }
.rb-card.rb-vendor-nvidia { --rb-card-bg: #24311f; border-left: 5px solid var(--rb-nvidia); }
.rb-card.rb-vendor-amd { --rb-card-bg: #36231f; border-left: 5px solid var(--rb-amd); }
.rb-card.rb-vendor-intel { --rb-card-bg: #1d2735; border-left: 5px solid var(--rb-intel); }
.rb-card { background: var(--rb-card-bg); }
/* On the board the card is seen edge-on from above: its cooler fins run
   the length of the card and fill every bracket it covers. */
.rb-card.is-onboard { position: absolute; left: 2.6rem; right: .4rem; overflow: hidden;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.06) 0 2px, transparent 2px 9px), var(--rb-card-bg); }
.rb-card.is-selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.rb-card.is-flagged { box-shadow: 0 0 0 2px var(--product-warn), 0 6px 16px rgba(0,0,0,.35); }
.rb-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.rb-card-name { font-weight: 700; font-size: .9rem; }
.rb-card-meta, .rb-card-link { font: .75rem var(--rb-mono); opacity: .85; }
.rb-card-covers { margin-top: .25rem; font: .75rem var(--rb-mono); color: var(--product-warn); }

.rb-risers, .rb-waiting { display: grid; gap: .4rem; padding: .7rem; border: 1px dashed var(--border); border-radius: var(--radius, 6px); }
.rb-risers.is-drop-ok { border-color: var(--product-signal); background: rgba(95,191,134,.06); }
.rb-risers.is-drop-no { border-color: var(--product-alarm); }
.rb-risers .rb-card, .rb-waiting .rb-card { position: relative; }

.rb-ghost { position: fixed; left: 0; top: 0; z-index: 1000; padding: .4rem .7rem; border-radius: 4px; pointer-events: none;
  background: var(--accent); color: var(--accent-contrast, #000); font-weight: 700; font-size: .85rem; box-shadow: 0 8px 20px rgba(0,0,0,.4); }
body.rb-dragging, body.rb-dragging * { cursor: grabbing !important; }

.rb-slottable { width: 100%; border-collapse: collapse; font-size: .85rem; }
.rb-slottable th, .rb-slottable td { padding: .25rem .35rem; border-bottom: 1px solid var(--border); text-align: left; }
.rb-slottable .input { min-height: 2rem; }

/* ── Inspector ── */
.rb-inspector { display: grid; gap: .55rem; padding: .8rem; border: 1px solid var(--border); border-radius: var(--radius, 6px); background: var(--surface); }
.rb-facts { display: grid; grid-template-columns: auto 1fr; gap: .2rem .7rem; margin: 0; font-size: .85rem; }
.rb-facts dt { color: var(--muted); }
.rb-facts dd { margin: 0; }
.rb-source { margin: 0; font-size: .85rem; }
.rb-unverified { color: var(--product-warn); }

/* ── Checks ── */
.rb-checks ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.rb-check-item { display: grid; grid-template-columns: 5.5rem 1fr; gap: .5rem; padding: .45rem .6rem; border-left: 4px solid var(--muted);
  background: var(--surface); border-radius: 3px; font-size: .9rem; }
.rb-check-level { font-weight: 700; font-size: .8rem; }
.rb-check-item.tone-error { border-left-color: var(--product-alarm); }
.rb-check-item.tone-error .rb-check-level { color: var(--product-alarm); }
.rb-check-item.tone-warn { border-left-color: var(--product-warn); }
.rb-check-item.tone-warn .rb-check-level { color: var(--product-warn); }

/* ── Power ── */
.rb-sysrow { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.rb-psus { display: grid; gap: .75rem; margin-bottom: .5rem; }
.rb-psu { display: grid; gap: .5rem; padding: .8rem; border: 1px solid var(--border); border-radius: var(--radius, 6px); background: var(--surface); }
.rb-psu-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; align-items: center; }
.rb-psu-head .input { max-width: 16rem; }
.rb-psu-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .5rem; }
.rb-bar { position: relative; height: 14px; border-radius: 7px; background: rgba(255,255,255,.08); overflow: hidden; }
.rb-bar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--product-signal); }
.rb-bar-fill.tone-warn { background: var(--product-warn); }
.rb-bar-fill.tone-bad { background: var(--product-alarm); }
.rb-bar-mark { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--product-warn); }
.rb-bar-mark.is-limit { background: var(--text); }
.rb-wall { display: grid; gap: .5rem; max-width: 40rem; }
.rb-wall-figure { margin: 0; font-size: 1.05rem; }
.rb-wall-figure.tone-bad strong { color: var(--product-alarm); }

.rb-tablewrap { overflow-x: auto; margin-bottom: 1rem; }
.rb-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.rb-table th, .rb-table td { padding: .4rem .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.rb-table thead th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.rb-table tr.is-selected { background: rgba(255,255,255,.04); }

/* ── Models ── */
.rb-modelbar { display: grid; grid-template-columns: minmax(14rem, 2fr) repeat(3, minmax(8rem, 1fr)); gap: .75rem; align-items: end; margin-bottom: .75rem; }
@media (max-width: 720px) { .rb-modelbar { grid-template-columns: 1fr 1fr; } .rb-modelpool { grid-column: 1 / -1; } }
.rb-modelpool { margin: 0; }
.rb-linkbtn { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; text-align: left; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.rb-verdict { display: inline-block; padding: .1rem .45rem; border-radius: 3px; font: .78rem var(--rb-mono); }
.rb-verdict.is-yes { background: rgba(95,191,134,.16); color: var(--product-signal); }
.rb-verdict.is-tight { background: rgba(217,165,60,.16); color: var(--product-warn); }
.rb-verdict.is-offload { background: rgba(120,150,220,.16); color: #9db4ea; }
.rb-verdict.is-no { background: rgba(224,108,98,.14); color: var(--product-alarm); }
.rb-minibar { position: relative; display: inline-block; width: 8rem; height: 8px; border-radius: 4px; background: rgba(255,255,255,.08); vertical-align: middle; overflow: hidden; }
.rb-minibar > span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); }
.rb-minibar > i { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); }
.rb-models tr.is-no .rb-minibar > span { background: var(--product-alarm); }
.rb-modeldetail { margin: .5rem 0 1rem; }
.rb-quants { display: grid; gap: .3rem; }
.rb-quant { display: grid; grid-template-columns: 5rem minmax(0, 1fr) 9rem; gap: .6rem; align-items: center; font: .8rem var(--rb-mono); }
.rb-stack { position: relative; display: flex; height: 12px; border-radius: 3px; background: rgba(255,255,255,.06); overflow: hidden; }
.rb-stack-w { background: var(--accent); }
.rb-stack-c { background: var(--product-warn); }
.rb-stack > i { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); }
.rb-quant.is-offload .rb-quant-name { color: #9db4ea; }
.rb-quant.is-no .rb-quant-name { color: var(--product-alarm); }
.rb-quant.is-tight .rb-quant-name { color: var(--product-warn); }
.rb-quant.is-yes .rb-quant-name { color: var(--product-signal); }
.rb-split { display: grid; gap: .3rem; }
.rb-split-card { display: grid; grid-template-columns: minmax(10rem, 1fr) 8rem auto; gap: .6rem; align-items: center; font-size: .85rem; }

.rb-export { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem 1rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.rb-export p { margin: .15rem 0 0; max-width: 60ch; }

@media (max-width: 520px) {
  .rb-quant { grid-template-columns: 4rem minmax(0, 1fr); }
  .rb-quant-fig { grid-column: 2; }
  .rb-split-card { grid-template-columns: 1fr; }
  .rb-check-item { grid-template-columns: 1fr; }
}

.rb-print { display: none; }
@media print {
  body[data-printing-scope] .rb-print[data-printing] { display: block; position: static; color: #000; font: 10pt/1.35 Helvetica, Arial, sans-serif; }
  .rb-print h2 { font-size: 15pt; margin: 0 0 .3rem; }
  .rb-print h3 { font-size: 12pt; margin: .8rem 0 .2rem; }
  .rb-print table { width: 100%; border-collapse: collapse; margin: .3rem 0 .8rem; }
  .rb-print th, .rb-print td { text-align: left; padding: 2pt 4pt; border-bottom: .5pt solid #aaa; font-size: 9pt; }
  .rb-print .rb-board { max-width: 6.5in; margin: .5rem 0; -webkit-print-color-adjust: exact; print-color-adjust: exact; break-inside: avoid; }
}

.rb-slot.is-held { border-color: var(--accent); color: var(--text); }
