:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --ink: #102433;
  --ink-soft: #4a6172;
  --line: #d6dee5;
  --teal: #00a884;
  --teal-dark: #007a5e;
  --blueprint: #0b2a4a;
  --bp-line: #6fc8f5;
  --bp-line-soft: rgba(111, 200, 245, 0.28);
  --focus: #0a84ff;
  --max-w: 1080px;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.app {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 16px 14px 40px;
}

/* ---- Encabezado ---- */
.hdr { margin-bottom: 16px; display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.hdr__brand { display: flex; gap: 12px; align-items: flex-start; }
.hdr__logo {
  font-size: 30px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  width: 52px; height: 52px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.hdr__title { font-size: 22px; margin: 2px 0 2px; line-height: 1.1; }
.hdr__sub { margin: 0; font-size: 14px; color: var(--ink-soft); line-height: 1.4; max-width: 64ch; }

/* ---- Layout ---- */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

/* ---- Controles ---- */
.ctl-group {
  border: none;
  padding: 0;
  margin: 0 0 18px;
}
.ctl-group:last-child { margin-bottom: 0; }
.ctl-group legend {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  padding: 0;
  margin-bottom: 9px;
}

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.seg--col { grid-template-columns: 1fr; }
.seg__btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
  background: #f3f6f9;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  cursor: pointer;
  line-height: 1.25;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.seg__btn small {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-left: 4px;
}
.seg__btn:hover { border-color: var(--teal); }
.seg__btn.is-active {
  background: #e6f7f2;
  border-color: var(--teal);
  box-shadow: inset 0 0 0 1px var(--teal);
  color: var(--teal-dark);
}
.seg__btn.is-active small { color: var(--teal-dark); }
.seg .fam-btn { text-align: center; }

.ctl-note {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.4;
  margin: 10px 0 0;
}
.ctl-note strong { color: var(--ink); }

.pieza-btn[hidden] { display: none; }
.ctl-group[hidden] { display: none; }

/* ---- Marcar sobre la cara elegida en el visor 3D (Issue #46) ---- */
.marcar {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 12px 0;
  background: #f7fbfa;
}
.marcar[hidden] { display: none; }
.marcar__head {
  font-size: 13px;
  font-weight: 700;
  color: var(--teal-dark);
  margin: 0 0 10px;
}
.marcar .btn-add-hueco { width: 100%; margin-top: 4px; }
.marcar .btn-add-hueco[aria-pressed="true"] {
  color: #fff;
  background: var(--teal);
  border-style: solid;
}
.marcar .btn-add-hueco:disabled {
  opacity: .5;
  cursor: not-allowed;
}
.select--inline { width: auto; flex: 1; }

/* Aviso de "volvé a generar" cuando cambian las marcas después de generar */
.regen-note {
  font-size: 12.5px;
  line-height: 1.45;
  color: #6a4a12;
  background: #fff8e6;
  border: 1px solid #f1e0a8;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 10px;
}
.regen-note[hidden] { display: none; }

/* ---- Lista de huecos / agujeros ---- */
.hueco-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  align-items: end;
  gap: 8px;
  margin-bottom: 8px;
}
.hueco-row label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 2px;
}
.hueco-row .num { width: 100%; }
/* Fila de una marca hecha sobre la cara: no se edita por número, se describe. */
.hueco-row--face { grid-template-columns: 1fr auto; align-items: center; }
.hueco-row__text { font-size: 12.5px; line-height: 1.35; color: var(--ink); }
.hueco-row__text small { display: block; font-size: 11px; color: var(--ink-soft); }
.hueco-del {
  font: inherit;
  font-size: 16px;
  line-height: 1;
  color: #b23b3b;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
}
.hueco-del:hover { background: #fde8e8; border-color: #e7a3a3; }
.btn-add-hueco {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--teal);
  background: #fff;
  border: 1px dashed var(--teal);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
.btn-add-hueco:hover { background: rgba(0,168,132,.08); }

/* ---- Campos numéricos (medidas libres) ---- */
.num-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.num-row:last-child { margin-bottom: 0; }
.num-row[hidden] { display: none; }
.num-row label { font-size: 14px; font-weight: 600; flex: 1; }
.num {
  width: 90px;
  font: inherit;
  font-size: 14px;
  text-align: right;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  font-variant-numeric: tabular-nums;
}
.num:focus { border-color: var(--teal); outline: none; box-shadow: 0 0 0 2px rgba(0,168,132,.25); }
.num-row .u { font-size: 12px; color: var(--ink-soft); width: 24px; }

.select {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #f3f6f9;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

/* ---- Vistas (blueprint) ---- */
.results-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.view-card { display: flex; flex-direction: column; }
.view-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.view-head__tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--teal-dark);
  background: #e6f7f2;
  border-radius: 6px;
  padding: 3px 8px;
}
.view-head__tag--flat {
  color: #0b3a63;
  background: #dcefff;
}
.view-head__hint {
  font-size: 11px;
  color: var(--ink-soft);
}
.view-foot {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
}
.canvas {
  background: var(--blueprint);
  background-image:
    linear-gradient(var(--bp-line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--bp-line-soft) 1px, transparent 1px);
  background-size: 23px 23px;
  border-radius: 10px;
  padding: 6px;
  overflow: hidden;
}
.canvas svg { display: block; width: 100%; height: auto; }
.canvas { position: relative; }

/* ---- Visor 3D (Issue #40) ---- */
.viewer3d {
  position: relative;
  width: 100%;
  aspect-ratio: 340 / 240;
}
.viewer3d[hidden] { display: none; }
.viewer3d canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  touch-action: none;
  cursor: grab;
}
.viewer3d canvas:active { cursor: grabbing; }
.viewer3d__reset {
  position: absolute;
  right: 8px;
  bottom: 8px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}
.viewer3d__reset:hover { background: #fff; border-color: var(--teal); }
.view-foot--warning {
  color: #b06a00;
}
.view-foot--warning[hidden] { display: none; }
.view-foot--face {
  color: var(--teal-dark);
  font-weight: 600;
}
.view-foot--face[hidden] { display: none; }

/* Trazos del plano */
.bp-piece { fill: rgba(111,200,245,0.10); stroke: var(--bp-line); stroke-width: 2; }
.bp-metal {
  fill: none;
  stroke: var(--bp-line);
  stroke-linecap: round;
  stroke-linejoin: round;
}
.bp-blank { fill: rgba(111,200,245,0.10); stroke: var(--bp-line); stroke-width: 2; stroke-linejoin: round; }
.bp-relief { fill: var(--blueprint); stroke: #ffb3b3; stroke-width: 1.4; }
.bp-fold {
  stroke: #ffd166;
  stroke-width: 1.4;
  stroke-dasharray: 6 4;
  fill: none;
}
.bp-seam { stroke: #ff7a7a; stroke-width: 2.4; }
.bp-hole { fill: rgba(10,30,48,0.55); stroke: #9fd8f6; stroke-width: 1.4; }
.bp-cut { fill: rgba(10,30,48,0.55); stroke: #9fd8f6; stroke-width: 1.4; }
.bp-text--seam { fill: #ffb3b3; font-size: 10.5px; font-weight: 700; }
.bp-iso-face { fill: rgba(111,200,245,0.16); stroke: var(--bp-line); stroke-width: 1.6; stroke-linejoin: round; }
.bp-iso-base { fill: rgba(111,200,245,0.28); stroke: var(--bp-line); stroke-width: 1.6; stroke-linejoin: round; }
.bp-dim { stroke: #9fd8f6; stroke-width: 1; }
.bp-dim-tick { stroke: #9fd8f6; stroke-width: 1; }
.bp-text { fill: #d8eefc; font-size: 11px; font-family: "Segoe UI", Roboto, sans-serif; }
.bp-text--fold { fill: #ffd680; font-size: 10.5px; }
.bp-text--big { fill: #eaf6ff; font-size: 12.5px; font-weight: 700; }

/* ---- Hero: largo desarrollado ---- */
.hero {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: linear-gradient(135deg, #00a884, #007a5e);
  color: #eafff8;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.hero__label { font-size: 12px; color: #c8f5e8; text-transform: uppercase; letter-spacing: 0.05em; }
.hero__value { font-size: 30px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.hero__hint { font-size: 12px; color: #b6ecdb; margin-top: 2px; }

/* ---- Peso ---- */
.weight {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "label value" "hint hint";
  align-items: baseline;
  gap: 2px 10px;
  background: linear-gradient(135deg, #0b2a4a, #0e3a63);
  color: #eaf6ff;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 18px;
}
.weight__label { grid-area: label; font-size: 13px; color: #acd4f0; align-self: center; }
.weight__value {
  grid-area: value;
  text-align: right;
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.weight__hint { grid-area: hint; font-size: 12px; color: #8fb9d6; margin-top: 6px; }

/* ---- Acción: generar archivo real ---- */
.action { margin-bottom: 8px; }
.btn-generate {
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  width: 100%;
  color: #eafff8;
  background: linear-gradient(135deg, #00a884, #007a5e);
  border: none;
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 168, 132, 0.3);
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.12s;
}
.btn-generate:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(0,168,132,.4); }
.btn-generate:disabled { opacity: 0.6; cursor: progress; }
.results__hint { font-size: 12px; color: var(--ink-soft); margin: 10px 0 0; line-height: 1.4; }


/* ---- Estado de generación ---- */
.status {
  margin-top: 14px;
  font-size: 13.5px;
  line-height: 1.45;
  border-radius: 10px;
  padding: 11px 13px;
}
.status[hidden] { display: none; }
.status--info { background: #eef6ff; border: 1px solid #cfe4fb; color: #0b3a63; }
.status--error { background: #fdecea; border: 1px solid #f3c4bf; color: #8a2620; }

/* ---- Resultado / descargas ---- */
.result { margin: 14px 0 4px; }
.result[hidden] { display: none; }
.downloads { display: flex; flex-direction: column; gap: 8px; }
.btn-dl {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 14px; font-weight: 700; text-decoration: none;
  color: #07261a; background: var(--teal); border-radius: 10px; padding: 12px 14px;
  transition: background 0.15s;
}
.btn-dl:hover { background: var(--teal-dark); color: #fff; }
.btn-dl--alt { color: #0b2a4a; background: #cfe4fb; }
.btn-dl--alt:hover { background: #aacdf3; color: #0b2a4a; }
.results__meta { margin: 10px 0 0; font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.results__title { font-size: 14px; margin: 18px 0 8px; }

.table-wrap { overflow-x: auto; }
.bom {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.bom th, .bom td {
  text-align: left;
  padding: 8px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.bom .num { text-align: right; font-variant-numeric: tabular-nums; }
.bom tbody tr:last-child td { border-bottom: none; }

/* ---- Nota honesta ---- */
.nota {
  margin: 16px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
  background: #fff8e6;
  border: 1px solid #f1e0a8;
  border-left: 4px solid #e8b23a;
  border-radius: 10px;
  padding: 12px 14px;
}
.nota strong { color: var(--ink); }

/* ---- Arranque en frío del motor (Issue #57) ---- */
.wake-banner {
  display: flex; gap: 10px; align-items: center;
  margin: 0 0 12px;
  background: #eef6ff;
  border: 1px solid #cfe4fb;
  border-left: 4px solid var(--focus);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px; color: #0b3a63;
}
.wake-banner[hidden] { display: none; }
.wake-banner p { margin: 0; line-height: 1.4; }
.wake-banner__icon { font-size: 18px; }
.wake-banner--error { background: #fdecea; border-color: #f3c4bf; border-left-color: #c0392b; color: #8a2620; }

/* ---- Email opcional (Issue #57) ---- */
.leads { margin-top: 16px; }
.leads__title { font-size: 15px; margin: 0 0 10px; }
.leads__form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.leads__email {
  flex: 1 1 220px; min-width: 0;
  font-size: 14px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
.leads__consent { display: flex; gap: 8px; align-items: center; font-size: 13.5px; flex: 1 1 100%; }
.leads__consent input { width: 18px; height: 18px; flex: none; }
.leads__submit {
  font-size: 14px; font-weight: 700; color: #07261a; background: var(--teal);
  border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer;
}
.leads__submit:hover { background: var(--teal-dark); color: #fff; }
.leads__submit:disabled { opacity: 0.6; cursor: wait; }
.leads__purpose, .leads__optional { margin: 10px 0 0; font-size: 12.5px; line-height: 1.45; color: var(--ink-soft); }
.leads__purpose a { color: var(--teal-dark); }
.leads__status { margin: 10px 0 0; font-size: 13.5px; border-radius: 10px; padding: 9px 12px; }
.leads__status[hidden] { display: none; }
.leads__status--ok { background: #e7f7f1; border: 1px solid #b8e6d5; color: #06543f; }
.leads__status--error { background: #fdecea; border: 1px solid #f3c4bf; color: #8a2620; }

/* ---- Nota de privacidad (Issue #57) ---- */
.privacy {
  max-width: min(520px, calc(100vw - 32px));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; color: var(--ink); background: var(--panel);
  font-size: 14px; line-height: 1.5;
}
.privacy::backdrop { background: rgba(16, 36, 51, 0.45); }
.privacy h2 { font-size: 17px; margin: 0 0 10px; }
.privacy p { margin: 0 0 10px; }
.privacy a { color: var(--teal-dark); }
.privacy__close {
  font-size: 14px; font-weight: 700; border: 0; border-radius: 10px;
  padding: 9px 16px; background: #cfe4fb; color: #0b2a4a; cursor: pointer;
}

/* ---- Foco accesible ---- */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---- Desktop: dos columnas, datos | resultado (Issue #61) ---- */
@media (min-width: 860px) {
  .grid {
    grid-template-columns: 360px 1fr;
    align-items: start;
  }
  .hdr__title { font-size: 26px; }
}

/* ---- Radio interior y ángulos entre alas (Issue #59) ---- */
.bp-angle { fill: none; stroke: #ffd680; stroke-width: 1.2; }
.angulos { margin-top: 10px; }
.angulos[hidden] { display: none; }
.num-row label small { display: block; font-size: 11px; font-weight: 400; color: var(--ink-soft); }
.ctl-note--warn,
.results__warn {
  color: #6a4a12;
  background: #fff8e6;
  border: 1px solid #f1e0a8;
  border-radius: 8px;
  padding: 6px 9px;
}
.ctl-note--warn[hidden],
.results__warn[hidden] { display: none; }
.results__warn { margin: 10px 0 0; font-size: 12.5px; line-height: 1.4; }

/* ---- Selector de idioma ES | EN (Issue #59) ---- */
.lang-switch { display: inline-flex; flex: none; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.lang-switch__btn {
  font: inherit; font-size: 13px; font-weight: 700;
  padding: 7px 12px; border: 0; background: transparent; color: var(--ink-soft); cursor: pointer;
}
.lang-switch__btn + .lang-switch__btn { border-left: 1px solid var(--line); }
.lang-switch__btn[aria-pressed="true"] { background: var(--teal); color: #07261a; }

/* ---- Pantalla de taller (Issue #61) ---- */
.seg--piezas { margin-top: 8px; }
.select--inline { min-width: 0; }

/* Peso estimado en vivo, dentro de "Material y espesor" */
.weight--compact { margin: 12px 0 0; padding: 10px 14px; }
.weight--compact .weight__value { font-size: 22px; }

/* Medidas: ● Exteriores ○ Interiores */
.ref-switch { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 0 0 12px; font-size: 14px; }
.ref-switch[hidden] { display: none; }
.ref-switch__label { font-weight: 600; }
.ref-switch__opt { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.ref-switch__opt input { accent-color: var(--teal); width: 16px; height: 16px; margin: 0; }

/* Ajustes de taller: desplegable, cerrado por defecto */
.ajustes { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0 0 18px; background: #f7fbfa; }
.ajustes[hidden] { display: none; }
.ajustes__summary {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-soft); cursor: pointer;
}
.ajustes[open] .ajustes__summary { margin-bottom: 10px; }
.ajustes .num-row { margin-top: 10px; }
.btn-link {
  font: inherit; font-size: 12.5px; font-weight: 600; color: var(--teal-dark);
  background: none; border: 0; padding: 4px 0; cursor: pointer; text-decoration: underline;
}
.btn-link[hidden] { display: none; }
.matriz { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin: 12px 0 0; font-size: 13px; }
.matriz dt { color: var(--ink-soft); }
.matriz dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }

/* Nombre de la pieza */
.text {
  width: 100%; font: inherit; font-size: 14px; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.text:focus { border-color: var(--teal); outline: none; box-shadow: 0 0 0 2px rgba(0,168,132,.25); }

/* Visor con pestañas: 3D plegada | 2D desarrollo */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs__btn {
  font: inherit; font-size: 13.5px; font-weight: 700; color: var(--ink-soft);
  background: none; border: 0; border-bottom: 3px solid transparent;
  padding: 8px 12px; margin-bottom: -1px; cursor: pointer;
}
.tabs__btn:hover { color: var(--ink); }
.tabs__btn.is-active { color: var(--teal-dark); border-bottom-color: var(--teal); }
.tab-panel[hidden] { display: none; }

/* Avisos de fabricación (sólo si hay) */
.avisos {
  margin: 14px 0 0; color: #6a4a12; background: #fff8e6;
  border: 1px solid #f1e0a8; border-left: 4px solid #e8b23a; border-radius: 10px; padding: 10px 12px;
}
.avisos[hidden] { display: none; }
.avisos__title { font-size: 13px; margin: 0 0 6px; color: #5a3d0c; }
.avisos__list { margin: 0; padding-left: 18px; font-size: 12.5px; line-height: 1.45; }
.avisos__list li + li { margin-top: 4px; }

/* Descargas siempre a la vista: deshabilitadas hasta generar */
.results .downloads { margin-top: 14px; }
.btn-dl.is-disabled,
.btn-dl.is-disabled:hover { color: var(--ink-soft); background: #eef2f6; cursor: not-allowed; }
.downloads .results__meta { margin-top: 2px; }

/* Cortes pegados a un doblez: en rojo, con el motivo */
.hueco-warn { grid-column: 1 / -1; margin: 0; font-size: 12px; line-height: 1.4; color: #8a2620; }
.hueco-warn[hidden] { display: none; }
.hueco-row.is-near .num { border-color: #e7a3a3; background: #fdecea; }
.bp-mark--near { stroke: #ff7a7a; stroke-width: 2; }
