/* Reset base (antes lo aportaba el artifact) */
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; font-family: var(--f-body); font-size: 14px; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* Layout: herramienta de tres columnas — programa | plano 2D | opciones, semáforo y materiales. Estética de lámina técnica: tinta, papel frío, acero y naranja de obra para lo que se agarra. */
:root {
  --paper: #edf1f0; --panel: #fafbfb; --ink: #17242a; --muted: #5a6a6f; --rule: #d2dadb; --soft: #e4e9e9;
  --accent: #1f5f8b; --accent-ink: #ffffff; --handle: #d9741c;
  --dorm: #dde8e0; --bano: #d4e2ee; --living: #efe8db; --hall: #e6e9eb; --counter: #c9c2b4;
  --wall: #17242a; --grid: #d9e0e0; --gridmod: #b9cbd8;
  --ok: #2c7a4b; --warn: #b2621a; --info: #4b6c86;
  --f-display: "Archivo Narrow", "Arial Narrow", "Roboto Condensed", sans-serif;
  --f-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --paper: #0f161a; --panel: #141c21; --ink: #e2e9eb; --muted: #94a4a9; --rule: #28343a; --soft: #1b252b;
  --accent: #6aaedb; --accent-ink: #0c1418; --handle: #f09a45;
  --dorm: #213129; --bano: #1c2d3b; --living: #322b20; --hall: #222b30; --counter: #4a4438;
  --wall: #dde6e9; --grid: #1a2328; --gridmod: #23384a;
  --ok: #5fbf86; --warn: #e79a4f; --info: #84a9c6; color-scheme: dark; } }
:root[data-theme="dark"] {
  --paper: #0f161a; --panel: #141c21; --ink: #e2e9eb; --muted: #94a4a9; --rule: #28343a; --soft: #1b252b;
  --accent: #6aaedb; --accent-ink: #0c1418; --handle: #f09a45;
  --dorm: #213129; --bano: #1c2d3b; --living: #322b20; --hall: #222b30; --counter: #4a4438;
  --wall: #dde6e9; --grid: #1a2328; --gridmod: #23384a;
  --ok: #5fbf86; --warn: #e79a4f; --info: #84a9c6; color-scheme: dark; }

html, body { height: 100%; }
body { background: var(--paper); color: var(--ink); font-family: var(--f-body); font-size: 14px; }
* { box-sizing: border-box; }
button, input, select { font: inherit; color: inherit; }
.app { height: 100%; display: grid; grid-template-columns: 290px minmax(0, 1fr) 330px; grid-template-rows: auto minmax(0, 1fr); }
header.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--panel); border-bottom: 1px solid var(--rule); }
.brand { display: flex; align-items: baseline; gap: 10px; margin-right: 6px; }
.brand b { font-family: var(--f-display); font-weight: 700; font-size: 22px; letter-spacing: .01em; }
.brand span { color: var(--muted); font-size: 12.5px; }
.group { display: flex; align-items: center; gap: 4px; }
.group .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-right: 4px; }
.btn { border: 1px solid var(--rule); background: var(--panel); border-radius: 6px; padding: 5px 10px; cursor: pointer; line-height: 1.2; }
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.on { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.btn:disabled { opacity: .55; cursor: progress; }
#theme, #rethink { display: inline-flex; align-items: center; gap: 6px; }
.variant { position: absolute; left: 12px; top: 12px; display: flex; align-items: center; gap: 8px; background: color-mix(in srgb, var(--panel) 94%, transparent); border: 1px solid var(--rule); border-radius: 6px; padding: 4px 6px 4px 10px; font-size: 12px; color: var(--muted); }
.variant b { color: var(--ink); font-weight: 600; }
.variant button { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 2px 4px; }
.variant button:focus-visible { outline: 2px solid var(--accent); }
#theme svg { display: block; }
.shape svg { display: block; }
.stats { margin-left: auto; display: flex; gap: 16px; font-family: var(--f-mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.stats div { display: flex; flex-direction: column; line-height: 1.15; }
.stats small { font-family: var(--f-body); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

aside { background: var(--panel); overflow-y: auto; min-width: 0; }
aside.left { border-right: 1px solid var(--rule); }
aside.right { border-left: 1px solid var(--rule); }
.sec { padding: 14px 16px; border-bottom: 1px solid var(--rule); display: flex; flex-direction: column; gap: 10px; }
.sec h2 { margin: 0; font-family: var(--f-display); font-size: 15px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; display: flex; align-items: center; gap: 8px; }
.sec h2 .count { margin-left: auto; font-family: var(--f-mono); font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: 0; text-transform: none; }
.help { color: var(--muted); font-size: 12.5px; line-height: 1.45; margin: 0; }
.row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row .name { font-size: 13px; min-width: 52px; color: var(--muted); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; margin-left: auto; }
.stepper button { border: 0; background: transparent; width: 28px; height: 26px; cursor: pointer; font-size: 16px; }
.stepper button:hover { background: var(--soft); }
.stepper output { min-width: 22px; text-align: center; font-family: var(--f-mono); font-size: 13px; }
.sub { display: flex; align-items: center; gap: 10px; }
.sub h3 { margin: 0; font-size: 13px; font-weight: 600; }
.item { display: grid; grid-template-columns: 54px minmax(0, 1fr); gap: 6px 8px; align-items: center; padding: 8px; border-radius: 6px; background: var(--soft); }
.item .tag { font-family: var(--f-mono); font-size: 11.5px; color: var(--muted); }
.dims { display: flex; align-items: center; gap: 4px; font-family: var(--f-mono); font-size: 12px; color: var(--muted); }
input.num { width: 58px; padding: 3px 5px; border: 1px solid var(--rule); border-radius: 5px; background: var(--panel); font-family: var(--f-mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }
select { padding: 3px 6px; border: 1px solid var(--rule); border-radius: 5px; background: var(--panel); font-size: 12.5px; min-width: 0; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--rule); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; border-right: 1px solid var(--rule); background: var(--panel); padding: 7px 0; cursor: pointer; font-family: var(--f-mono); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.toggles { display: flex; flex-direction: column; gap: 4px; padding-top: 4px; }
.toggles.off { opacity: .6; }
.toggles .help { margin: 0 0 6px 24px; }
.mhead { display: flex; align-items: center; gap: 10px; }
.fold { flex: 1; display: flex; align-items: center; gap: 8px; border: 0; background: none; padding: 4px 0; cursor: pointer; font-family: var(--f-display); font-size: 15px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; text-align: left; }
.fold svg { transition: transform .15s; transform: rotate(-90deg); flex: none; }
.fold[aria-expanded="true"] svg { transform: rotate(0deg); }
.fold .count { font-family: var(--f-mono); font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: 0; text-transform: none; }
.fold:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#matbody, .foldbody { display: flex; flex-direction: column; gap: 10px; }
#matbody[hidden], .foldbody[hidden] { display: none; }
.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; align-items: center; font-size: 13px; }
.kv label { color: var(--muted); }
.summary { font-family: var(--f-mono); font-size: 12px; color: var(--muted); line-height: 1.5; }
.summary b { color: var(--ink); font-weight: 500; }

.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.checks li { display: grid; grid-template-columns: 14px minmax(0, 1fr); gap: 2px 8px; padding: 6px 0; border-bottom: 1px dashed var(--rule); }
.checks li:last-child { border-bottom: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 4px; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.info { background: transparent; border: 2px solid var(--info); }
.checks .t { font-size: 13px; }
.checks .d { grid-column: 2; font-size: 12px; color: var(--muted); }
.pill { font-family: var(--f-mono); font-size: 11.5px; padding: 1px 7px; border-radius: 10px; }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }

.mat { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.mat td { padding: 5px 0; border-bottom: 1px solid var(--soft); vertical-align: top; }
.mat td.q { text-align: right; font-family: var(--f-mono); white-space: nowrap; padding-left: 10px; font-variant-numeric: tabular-nums; }
.mat td .n { display: block; color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.mat tr.g td { padding-top: 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); border-bottom: 1px solid var(--rule); }
details summary { cursor: pointer; font-size: 13px; color: var(--accent); }
.wallt { width: 100%; border-collapse: collapse; font-family: var(--f-mono); font-size: 11.5px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.wallt th { text-align: left; font-family: var(--f-body); font-weight: 500; color: var(--muted); font-size: 11px; border-bottom: 1px solid var(--rule); padding: 3px 4px 3px 0; }
.wallt td { padding: 3px 4px 3px 0; border-bottom: 1px solid var(--soft); }

main.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--paper); touch-action: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; user-select: none; -webkit-user-select: none; }
.hint { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 6px; flex-wrap: wrap; max-width: calc(100% - 24px); pointer-events: none; }
.hint span { background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--rule); border-radius: 5px; padding: 3px 8px; font-size: 12px; color: var(--muted); }
.hint kbd { font-family: var(--f-mono); font-size: 11px; color: var(--ink); }
.zoom { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.zoom .btn { width: 34px; height: 34px; padding: 0; font-size: 16px; }
.toast { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 6px 12px; border-radius: 6px; font-size: 12.5px; pointer-events: none; transition: opacity .25s; }
.legend { position: absolute; right: 12px; top: 12px; display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--rule); border-radius: 6px; padding: 5px 9px; font-size: 11.5px; color: var(--muted); max-width: calc(100% - 24px); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; border: 1px solid var(--rule); }

svg text { font-family: var(--f-body); }
svg .cota { font-family: var(--f-mono); fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
svg .rname { font-family: var(--f-display); font-weight: 600; fill: var(--ink); letter-spacing: .03em; text-transform: uppercase; }
svg .rdim { font-family: var(--f-mono); fill: var(--muted); }
svg .hv { fill: var(--handle); stroke: var(--panel); stroke-width: 2; cursor: grab; }
svg .hm { fill: var(--panel); stroke: var(--handle); stroke-width: 2; cursor: grab; }
svg .hit { stroke: transparent; stroke-width: 16; cursor: move; }
svg .hit:hover { stroke: color-mix(in srgb, var(--handle) 22%, transparent); }
svg .hv:hover, svg .hm:hover { stroke: var(--ink); }

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 62vh auto auto; height: auto; }
  html, body { height: auto; }
  main.stage { grid-row: 2; }
  aside.left { grid-row: 3; border-right: 0; border-top: 1px solid var(--rule); }
  aside.right { grid-row: 4; border-left: 0; border-top: 1px solid var(--rule); }
  aside { overflow: visible; }
  .stats { margin-left: 0; width: 100%; }
  .sec { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
}
@media (max-width: 600px) { .hint span:nth-child(3) { display: none; } .legend span:not(:last-child) { display: none; } }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* arrastre fluido: cursores, manija activa, guías y medida flotante (js/fluid.js) */
#cv { cursor: grab; touch-action: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
#cv[data-drag="pan"], #cv[data-drag="pinch"] { cursor: grabbing; }
#cv[data-drag="v"], #cv[data-drag="v"] * { cursor: grabbing !important; }
#cv[data-drag="eh"], #cv[data-drag="eh"] * { cursor: row-resize !important; }
#cv[data-drag="ev"], #cv[data-drag="ev"] * { cursor: col-resize !important; }
svg .hit.eh, svg .hm.eh { cursor: row-resize; }
svg .hit.ev, svg .hm.ev { cursor: col-resize; }
svg .hv { transition: r .12s ease-out; }
svg .fx-guide { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 4 3; fill: none; }
svg .fx-gdot { fill: var(--accent); }
svg .fx-halo { fill: color-mix(in srgb, var(--handle) 20%, transparent); stroke: none; }
svg .fx-active { fill: var(--handle); stroke: var(--ink); stroke-width: 2; }
svg .fx-edge { stroke: color-mix(in srgb, var(--handle) 55%, transparent); stroke-width: 6; stroke-linecap: round; }
svg .fx-tip rect { fill: var(--ink); opacity: .92; }
svg .fx-tip text { fill: var(--panel); font-family: var(--f-mono); font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
@media (pointer: coarse) { svg .hit { stroke-width: 34; } }
@media (prefers-reduced-motion: reduce) { svg .hv { transition: none; } }
