/* Configurador de edificio — page-scoped styles.
   Material-true palette: timber (CLT), concrete, earth; money in teal. */

.cfg {
  --clt: #C08552;
  --clt-soft: #F3E4D3;
  --horm: #9AA1A9;
  --horm-soft: #E9ECEF;
  --tierra: #7A6A58;
  --plano: #FBFAF6;
  --plano-line: #E4E0D5;
  --money: #0F766E;
  --money-soft: #E2F1EF;
  --tinta: #22303A;
}

.cfg-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.cfg-head h1 { margin: 0; }
.cfg-head .sub { color: var(--muted); font-size: 13px; }

.cfg-grid { display: grid; grid-template-columns: 320px minmax(0, 1fr) 300px; gap: 14px; align-items: start; }
@media (max-width: 1024px) { .cfg-grid { grid-template-columns: 300px minmax(0, 1fr) } .cfg-budget { grid-column: 1 / -1; position: static; } }
@media (max-width: 780px) { .cfg-grid { grid-template-columns: 1fr; } }

/* ---- left rail: the spec, in memoria order ---- */
.cfg-rail { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 18px 14px; }
.rail-intro { font-size: 11.5px; color: var(--muted); line-height: 1.4; padding: 10px 0 4px; }
.rail-intro a { color: var(--accent); }
.grp { border-top: 1px solid var(--line); padding: 14px 0 6px; }
.grp:first-child { border-top: 0; }
.grp-eyebrow { font-family: var(--mono); font-size: 10.5px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.grp-eyebrow b { color: var(--tinta); font-weight: 600; }

.fld { margin-bottom: 12px; }
.fld .fld-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--tinta); margin-bottom: 3px; }
.fld .fld-label .unit { font-weight: 400; color: var(--muted); }
.fld .help { font-size: 11.5px; line-height: 1.35; color: var(--muted); margin-top: 3px; }
.fld .capture-tag { display: inline-block; font-size: 10px; color: var(--muted);
  border: 1px dashed var(--line); border-radius: 8px; padding: 0 6px; margin-left: 6px; vertical-align: 1px; }
.fld input[type=number], .fld select { padding: 5px 8px; }
.fld-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rail-link { font-size: 12px; display: inline-block; margin: 2px 0 8px; color: var(--accent); text-decoration: none; }
.rail-link:hover { text-decoration: underline; }

/* structure choice: two material cards */
.mat-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mat-card { border: 1.5px solid var(--line); border-radius: 8px; padding: 9px 10px; cursor: pointer;
  background: #fff; text-align: left; font: inherit; }
.mat-card .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.mat-card.horm .sw { background: var(--horm); }
.mat-card.clt .sw { background: var(--clt); }
.mat-card b { font-size: 12.5px; }
.mat-card .mat-sub { font-size: 11px; color: var(--muted); margin-top: 3px; line-height: 1.3; }
.mat-card.selected { border-color: var(--tinta); box-shadow: inset 0 0 0 1px var(--tinta); }
.mat-card.selected.clt { border-color: var(--clt); box-shadow: inset 0 0 0 1px var(--clt); background: var(--clt-soft); }
.mat-card.selected.horm { border-color: var(--horm); box-shadow: inset 0 0 0 1px var(--horm); background: var(--horm-soft); }

/* ---- centre: the drawing sheet ---- */
.cfg-sheet { background: var(--plano); border: 1px solid var(--plano-line); border-radius: 10px;
  padding: 16px 18px 12px;
  background-image: radial-gradient(rgba(34, 48, 58, .05) 1px, transparent 1px);
  background-size: 18px 18px; }
.sheet-cap { font-family: var(--mono); font-size: 10.5px; letter-spacing: .16em; color: var(--tierra);
  text-transform: uppercase; margin: 6px 0 2px; }
.cfg-sheet svg { width: 100%; height: auto; display: block; }
.sheet-facts { display: flex; gap: 6px 14px; flex-wrap: wrap; border-top: 1px solid var(--plano-line);
  margin-top: 10px; padding-top: 8px; font-family: var(--mono); font-size: 11px; color: var(--tinta); }
.sheet-facts b { font-weight: 600; }
.sheet-legend { display: flex; gap: 12px; margin-top: 6px; font-size: 10.5px; color: var(--muted); }
.sheet-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* ---- right rail: the budget ---- */
.cfg-budget { position: sticky; top: 60px; }
.budget-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.budget-title { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.budget-title .grp-eyebrow { margin: 0; }
.calc-state { font-size: 11px; color: var(--muted); }
.calc-state.busy { color: var(--warn); }

.chain { border-left: 2px solid var(--money); padding-left: 12px; margin: 10px 0 4px; }
.chain-row { position: relative; padding: 5px 0; }
.chain-row::before { content: ""; position: absolute; left: -17px; top: 14px; width: 8px; height: 8px;
  border-radius: 50%; background: #fff; border: 2px solid var(--money); }
.chain-row .cl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.chain-row .cv { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--tinta); }
.chain-row .ck { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.chain-row .k-input { width: 62px; padding: 1px 4px; font-family: var(--mono); font-size: 10.5px;
  border: 1px solid var(--line); border-radius: 4px; color: var(--tinta); }
.chain-row.final .cv { font-size: 21px; color: var(--money); }
.chain-row .cv.pulse { animation: cfg-pulse .5s ease-out; }
@keyframes cfg-pulse { 0% { background: var(--money-soft); } 100% { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .chain-row .cv.pulse { animation: none; } }

/* CO2 de construccion: la viga de balance (almacenado <- 0 -> emitido).
   Polos = materiales de la pagina: madera (biogenico almacenado) vs gris
   hormigon (fosil/LULUC). El gris es eleccion semantica deliberada: la
   identidad la llevan la posicion respecto al cero, las etiquetas directas
   con valores y el veteado de la madera (validator: contraste >=3:1 OK). */
.co2-row { margin: 12px 0 10px; padding-top: 8px; border-top: 1px dashed #E4DED4; }
.co2-head { display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px; }
.co2-head .grp-eyebrow { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.co2-net { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: #22303A; white-space: nowrap; flex: none; }
.co2-beam { display: flex; align-items: center; height: 14px; margin: 7px 0 4px; }
.co2-seg { height: 10px; border-radius: 3px; min-width: 0;
  transition: width .3s ease; }
.co2-seg.bio { background: #A96B33;
  background-image: repeating-linear-gradient(90deg,
    rgba(255,244,230,.55) 0 1px, transparent 1px 5px); /* veta de la madera */
  margin-right: 2px; border-radius: 3px 2px 2px 3px; }
.co2-seg.fosil { background: #4E5A64; margin-left: 2px;
  border-radius: 2px 3px 3px 2px; }
.co2-seg.luluc { background: #37424B; margin-left: 2px; }
.co2-cero { width: 2px; height: 14px; background: #22303A; flex: none;
  border-radius: 1px; }
.co2-legs { display: flex; justify-content: space-between; gap: 10px;
  font-size: 10px; color: #7B7466;
  font-family: SF Mono, ui-monospace, Menlo, monospace; }
.co2-leg { display: inline-flex; align-items: center; gap: 4px; min-width: 0;
  white-space: nowrap; cursor: help; }
.co2-leg .sw { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.co2-leg .sw.bio { background: #A96B33; }
.co2-leg .sw.fosil { background: #4E5A64; }
.co2-leg .sw.luluc { background: #37424B; width: 6px; height: 6px; }
.co2-luluc-leg { display: inline-flex; align-items: center; gap: 4px; }
.co2-fin { display: flex; align-items: baseline; gap: 8px; margin-top: 7px;
  font-size: 11px; color: #7B7466; }
.co2-fin-lbl { white-space: nowrap; }
.co2-fin b { font-variant-numeric: tabular-nums; color: #22303A; font-size: 12px;
  white-space: nowrap; }
.co2-fin-sub { font-size: 10px; color: #8B8578; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
@media (prefers-reduced-motion: reduce) {
  .co2-seg { transition: none; }
}

.kpi-line { display: flex; gap: 6px 12px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted);
  border-top: 1px solid var(--line); padding-top: 8px; }
.kpi-line b { color: var(--tinta); font-variant-numeric: tabular-nums; }

.drivers { margin-top: 10px; }
.drivers table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.drivers td { padding: 3px 0; border-bottom: 1px dotted var(--line); vertical-align: top; }
.drivers td.amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--tinta); font-weight: 600; }
.drivers .drv-name { color: var(--muted); }

.budget-actions { margin-top: 12px; display: flex; gap: 8px; }
.budget-actions .primary { background: var(--money); border-color: var(--money); }
.budget-warn { margin-top: 8px; font-size: 11.5px; color: var(--warn); }

.cfg :is(input, select, button):focus-visible { outline: 2px solid var(--money); outline-offset: 1px; }

/* ---- collapsible rail groups ---- */
details.grp > summary { list-style: none; cursor: pointer; user-select: none; }
details.grp > summary::-webkit-details-marker { display: none; }
details.grp > summary::before { content: "▸"; display: inline-block; margin-right: 6px;
  transition: transform .15s; color: var(--muted); }
details.grp[open] > summary::before { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) { details.grp > summary::before { transition: none; } }

/* ---- floor chips (rail summary) ---- */
.floor-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.floor-chip { font-family: var(--mono); font-size: 11px; padding: 2px 8px; border-radius: 5px;
  border: 1px solid var(--line); background: #fff; cursor: pointer; }
.floor-chip.clt { background: var(--clt-soft); border-color: var(--clt); }
.floor-chip.h { background: var(--horm-soft); border-color: var(--horm); }
.floor-chip.s { background: #E3E6EA; border-color: #8D939B; }
.floor-chip.sel { box-shadow: 0 0 0 2px var(--money); }

/* ---- floor editor under the section drawing ---- */
#floor-editor { margin: 4px 0 12px; }
.floor-hint { font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.floor-add { display: flex; gap: 6px; margin-top: 6px; }
.floor-add button { font-size: 12px; padding: 4px 10px; background: #fff; }
.floor-strip { display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--horm);
  border-radius: 8px; padding: 8px 12px; font-size: 12px; }
.floor-strip.clt { border-left-color: var(--clt); }
.floor-strip.s { border-left-color: #8D939B; }
.floor-strip .floor-name { font-weight: 700; }
.floor-strip .floor-name .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  margin-right: 5px; background: var(--horm); }
.floor-strip.clt .floor-name .sw { background: var(--clt); }
.floor-strip.s .floor-name .sw { background: #8D939B; }
.floor-strip label { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.floor-strip input[type=number] { width: 64px; padding: 3px 6px; }
.floor-strip .floor-kind button { padding: 3px 9px; font-size: 11.5px; border-radius: 5px 0 0 5px; }
.floor-strip .floor-kind button + button { border-radius: 0 5px 5px 0; margin-left: -1px; }
.floor-strip .floor-kind button.on { background: var(--tinta); color: #fff; border-color: var(--tinta); }
.floor-strip .help { flex-basis: 100%; margin: 0; }
.warn-text { color: var(--warn); }
.floor-g { cursor: pointer; }
.floor-g:hover rect { filter: brightness(.96); }

/* ---- all fields (advanced) ---- */
.adv-panel { margin-top: 16px; }
.adv-outer { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 18px; }
.adv-outer > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline;
  justify-content: space-between; gap: 10px; }
.adv-outer > summary::-webkit-details-marker { display: none; }
.adv-outer > summary .grp-eyebrow { margin: 0; }
.adv-outer > .help { margin: 8px 0; }
#adv-search { max-width: 420px; margin-bottom: 10px; }
.adv-grp { border-top: 1px solid var(--line); }
.adv-grp > summary { list-style: none; cursor: pointer; padding: 7px 2px; font-size: 12.5px; font-weight: 600; }
.adv-grp > summary::-webkit-details-marker { display: none; }
.adv-count { font-weight: 400; color: var(--muted); font-size: 11px; margin-left: 8px;
  background: var(--bg); border-radius: 8px; padding: 0 7px; }
.adv-body, #adv-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 6px 16px; padding: 4px 0 12px; }
.adv-fld { display: grid; grid-template-columns: minmax(0, 1fr) 130px 22px; gap: 8px; align-items: center;
  font-size: 12px; padding: 2px 4px; border-radius: 5px; }
.adv-fld.changed { background: var(--money-soft); }
.adv-fld .adv-label { color: var(--tinta); min-width: 0; }
.adv-fld .adv-label-text { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adv-fld .adv-key { display: block; font-family: var(--mono); font-size: 10px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adv-fld input, .adv-fld select { padding: 3px 6px; font-size: 12px; }
.adv-reset { padding: 0 4px; border: none; background: none; color: var(--money); cursor: pointer;
  font-size: 13px; visibility: hidden; }
.adv-fld.changed .adv-reset { visibility: visible; }

/* ---- entidades (arrays del dominio) ---- */
.ent-list { margin: 6px 0 10px; }
.ent-items { display: flex; flex-direction: column; gap: 4px; }
.ent-item { border: 1px solid #DDD6CC; border-radius: 6px; background: #FDFCFA; }
.ent-item > summary { display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  cursor: pointer; font-size: 12.5px; list-style: none; }
.ent-item > summary::-webkit-details-marker { display: none; }
.ent-item > summary b { font-weight: 600; flex: 1; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.ent-item[open] { background: #FFF; }
.ent-body { padding: 4px 10px 10px; border-top: 1px dashed #E4DED4; }
.ent-del { border: none; background: none; color: #A33; font-size: 15px; cursor: pointer;
  padding: 0 4px; line-height: 1; }
.ent-add { margin-top: 6px; font-size: 12px; padding: 3px 10px; border: 1px dashed #B7AE9E;
  background: #FBFAF7; border-radius: 6px; cursor: pointer; }
.ent-add:hover { background: #F3EFE7; }

.mini-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.mini-row .mini { display: flex; flex-direction: column; width: 52px; font-size: 9.5px;
  color: #7B7466; }
.mini-row .mini input { width: 100%; font-size: 11.5px; padding: 2px 3px; }

.est-row { display: grid; grid-template-columns: 92px 1fr auto auto; gap: 6px;
  align-items: center; margin: 4px 0; font-size: 12px; }
.est-row .est-name { color: #5A5344; font-weight: 600; font-size: 11.5px; }
.est-row select { font-size: 11.5px; max-width: 100%; }
.est-row .est-bar { display: flex; align-items: center; gap: 4px; color: #7B7466;
  font-size: 10.5px; }

/* ---- forjado por planta ---- */
.forjado-detail { margin: 8px 0; padding: 8px 10px; border: 1px solid #E0D9CC;
  border-radius: 8px; background: #FBFAF6; }
.forjado-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.forjado-col { display: flex; flex-direction: column; gap: 5px; font-size: 12px; }
.forjado-col label { display: flex; flex-direction: column; gap: 2px; color: #6C6455; }
.forjado-col input, .forjado-col select { font-size: 12px; }
.forjado-cap { font-weight: 700; font-size: 11px; letter-spacing: .04em;
  text-transform: uppercase; color: #8B8578; }

/* ---- modo auditoría + tooltips ---- */
.audit-chip { display: inline-block; margin-left: 6px; padding: 0 5px; font-size: 9.5px;
  font-family: SF Mono, ui-monospace, Menlo, monospace; color: #7A6A58;
  background: #F3EEE4; border: 1px solid #E0D6C2; border-radius: 4px; vertical-align: 1px; }
.adv-tip { display: block; font-size: 10.5px; color: #8B8578; line-height: 1.35;
  margin-top: 2px; font-weight: 400; }
.audit-toggle { margin-left: auto; display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: #B8C4CE; cursor: pointer; white-space: nowrap; }
.topnav .nav-status { margin-left: 12px; }
.help-inline { font-weight: 400; font-size: 11px; color: #8B8578; }

/* ---- ¿por qué? (explicabilidad) ---- */
.drv-row { border-bottom: 1px dashed #EAE4D8; }
.drv-row > summary { display: flex; align-items: center; gap: 8px; padding: 4px 0;
  cursor: pointer; list-style: none; font-size: 12px; }
.drv-row > summary::-webkit-details-marker { display: none; }
.drv-row .drv-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.drv-row .why { font-size: 10px; color: #0F766E; opacity: 0; }
.drv-row > summary:hover .why { opacity: 1; }
.drv-more > summary { font-size: 11.5px; color: #7A6A58; cursor: pointer; padding: 6px 0; }
.explain { padding: 6px 8px 10px; font-size: 11.5px; background: #FBFAF6;
  border-radius: 6px; margin: 2px 0 8px; }
.explain code { display: block; white-space: pre-wrap; word-break: break-word;
  font-size: 10.5px; background: #F3EFE7; padding: 4px 6px; border-radius: 4px;
  margin: 2px 0 6px; }
.explain-cap { font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  color: #8B8578; margin-top: 4px; }
.explain-vars { width: 100%; font-size: 11px; border-collapse: collapse; }
.explain-vars td { padding: 2px 4px; border-top: 1px dotted #E4DED4; }
.explain-vars td.mono { text-align: right; font-family: SF Mono, ui-monospace, Menlo, monospace; }

/* ---- deshacer ---- */
.undo-btn { font-size: 11px; padding: 2px 8px; border: 1px solid #C9BFA9;
  background: #FFF8E6; border-radius: 6px; cursor: pointer; margin-top: 6px; }

/* ---- márgenes (modo K + duración de obra) ---- */
.markup-row { display: flex; gap: 12px; align-items: center; margin-top: 8px;
  padding-top: 8px; border-top: 1px dashed #E4DED4; font-size: 11px; color: #7B7466; }
.markup-row label { display: flex; align-items: center; gap: 5px; }
.markup-row select.k-mode { font-size: 11px; }
.markup-row input.k-input { width: 58px; }
