:root {
  --bg: #f6f2ea; --panel: #ffffff; --ink: #2b2620; --muted: #6f665a; --line: #e3dccf;
  --accent: #8a5a2b; --accent-ink: #ffffff; --accent-soft: #f1e6d8;
  --warn-bg: #fff4dc; --warn: #7a4f00; --err-bg: #fde8e6; --err: #a3241c;
  --visor: #ece6db;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1a16; --panel: #27231e; --ink: #f1ebe0; --muted: #a79d8c; --line: #3a342c;
    --accent: #d9a566; --accent-ink: #1d1a16; --accent-soft: #3a2f22;
    --warn-bg: #3a2f17; --warn: #f0c26b; --err-bg: #3d1f1c; --err: #f2938b;
    --visor: #2e2924;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.top { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.top span { font-size: 13px; color: var(--muted); }

/* Celular primero: visor arriba, opciones abajo. */
.layout { display: grid; gap: 12px; padding: 12px 16px; max-width: 1280px; margin: 0 auto; }
.layout > * { min-width: 0; }
.visor { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
#view { width: 100%; height: max(260px, 46vh); border-radius: 8px; overflow: hidden; background: var(--visor); touch-action: none; }
#view canvas { display: block; }
.medida { margin: 8px 4px 0; font-weight: 600; font-size: 15px; text-align: center; }
.ayuda { margin: 2px 4px 4px; font-size: 12px; color: var(--muted); text-align: center; }

.panel { display: grid; gap: 12px; align-content: start; }
.intro { margin: 0; color: var(--muted); font-size: 14px; }
.grupo { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 14px; }

.campo { display: grid; gap: 6px; }
.campo > label, .campo .titulo { font-size: 14px; font-weight: 600; }
.fila { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.fila output { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent); }
.rango { font-size: 12px; color: var(--muted); }

input[type="range"] { width: 100%; height: 32px; margin: 0; accent-color: var(--accent); }
input[type="number"], select {
  width: 100%; min-height: 44px; padding: 8px 10px; font: inherit; font-size: 16px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink);
}
.exacto { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.exacto span { color: var(--muted); font-size: 14px; }
body:not(.avanzado) .exacto { display: none; }

.segmentos { display: flex; gap: 6px; flex-wrap: wrap; }
.segmentos button {
  flex: 1 1 0; min-width: 72px; min-height: 44px; padding: 8px 10px; font: inherit; font-size: 15px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); cursor: pointer;
}
.segmentos button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }

.colores { display: flex; gap: 10px; flex-wrap: wrap; }
.colores button {
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 2px solid var(--line); box-shadow: inset 0 0 0 3px var(--panel);
}
.colores button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 3px var(--panel), 0 0 0 2px var(--accent); }
.color-nombre { font-size: 13px; color: var(--muted); font-weight: 400; }

.switch { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 15px; cursor: pointer; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; margin: 0; }

.avisos { display: grid; gap: 8px; }
.avisos p { margin: 0; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.avisos .aviso { background: var(--warn-bg); color: var(--warn); }
.avisos .error { background: var(--err-bg); color: var(--err); font-weight: 600; }
.cargando-txt { color: var(--muted); }

.barra-precio {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgb(0 0 0 / .08);
}
.precio-info { min-width: 0; }
.etq { font-size: 12px; color: var(--muted); }
.precio { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; transition: opacity .15s; }
.precio.cargando { opacity: .45; }
.anticipo { font-size: 13px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 10px 16px;
  border-radius: 10px; font: inherit; font-weight: 600; text-decoration: none; text-align: center; cursor: pointer;
  border: 1px solid var(--accent); color: var(--accent); background: transparent;
}
.btn.primario { background: var(--accent); color: var(--accent-ink); }
.btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }

/* ---------- Encabezado y catálogo ---------- */
.top .relleno { flex: 1; }
.enlace { background: none; border: 0; padding: 6px 0; font: inherit; font-size: 14px; color: var(--accent); cursor: pointer; font-weight: 600; }
.inicio { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }
.inicio h1 { font-size: 26px; }
.catalogo { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); margin-top: 16px; }
.tarjeta {
  display: grid; gap: 6px; text-align: left; padding: 18px 16px; min-height: 110px; cursor: pointer;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; font: inherit;
}
.tarjeta strong { font-size: 18px; }
.tarjeta span { font-size: 14px; color: var(--muted); }
.tarjeta em { font-size: 12px; color: var(--accent); font-style: normal; font-weight: 600; }
.tarjeta:hover, .tarjeta:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
body:not(.en-editor) { padding-bottom: 0; }

/* ---------- Espacios ---------- */
.nota { margin: 0; font-size: 13px; color: var(--muted); }
.esquema { background: var(--visor); border-radius: 8px; padding: 8px; }
.esquema-svg { display: block; width: 100%; max-height: 380px; }
.e-cuerpo { fill: var(--line); }
.e-hueco { fill: var(--panel); stroke: var(--muted); stroke-width: 2; }
.e-espacio { cursor: pointer; outline: none; }
.e-espacio:hover .e-hueco, .e-espacio:focus-visible .e-hueco { fill: var(--accent-soft); }
.e-tablero { fill: var(--muted); opacity: .55; }
.e-cajon { fill: none; stroke: var(--muted); stroke-width: 3; }
.e-manija, .e-tubo { stroke: var(--ink); stroke-width: 6; stroke-linecap: round; }
.e-gancho { fill: none; stroke: var(--muted); stroke-width: 2; }
.e-texto { fill: var(--muted); font-family: system-ui, sans-serif; pointer-events: none; }
.e-puerta { fill: none; stroke: var(--accent); stroke-width: 4; stroke-dasharray: 18 10; pointer-events: none; }
.e-puerta-linea { fill: none; stroke: var(--accent); stroke-width: 3; stroke-dasharray: 10 8; pointer-events: none; }
.e-seleccion { fill: none; stroke: #e08a2c; stroke-width: 10; pointer-events: none; }
.visor-lienzo { position: relative; }
.btn.flotante {
  position: absolute; top: 10px; right: 10px; min-height: 40px; padding: 6px 14px;
  background: var(--panel); box-shadow: 0 2px 8px rgb(0 0 0 / .15);
}
.btn.flotante[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.e-puerta-flecha { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; pointer-events: none; }
.herramientas { display: flex; gap: 8px; flex-wrap: wrap; }
.herramientas .btn { min-height: 44px; padding: 8px 14px; }
.btn:disabled { opacity: .4; cursor: default; }
.btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.e-linea { fill: var(--muted); }
.e-linea.activa { fill: var(--accent); }
.e-linea.tope { fill: var(--err); }
.e-linea-hit { fill: transparent; touch-action: none; }
.e-linea-hit.col { cursor: col-resize; }
.e-linea-hit.fil { cursor: row-resize; }
.e-linea-hit:hover { fill: var(--accent); fill-opacity: .18; }
.esquema-svg.trazando { cursor: crosshair; touch-action: none; }
.esquema-svg.marcando { cursor: crosshair; touch-action: none; }
.e-marco { fill: #2b7de9; fill-opacity: .08; stroke: #2b7de9; stroke-width: 3; stroke-dasharray: 10 8; pointer-events: none; }
.e-sombra { fill: #e08a2c; fill-opacity: .14; stroke: #e08a2c; stroke-width: 6; pointer-events: none; }
.e-multi { fill: #e08a2c; fill-opacity: .22; pointer-events: none; }
.esquema-svg.arrastrando .e-espacio, .esquema-svg.arrastrando .e-seleccion { opacity: .3; }
.e-prev { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 3; }
.e-guia { stroke: #2b7de9; stroke-width: 3; stroke-dasharray: 14 10; }
.e-trazo { stroke: var(--muted); stroke-width: 4; stroke-dasharray: 8 8; }
.e-corte { stroke: var(--accent); stroke-width: 12; }
.e-corte.mal { stroke: var(--err); }
.e-etiqueta { fill: var(--ink); font-family: system-ui, sans-serif; font-weight: 700; paint-order: stroke; stroke: var(--panel); stroke-width: 8px; pointer-events: none; }
.esquema-info { margin: 6px 2px 0; min-height: 1.4em; font-size: 14px; font-weight: 600; color: var(--ink); }
.esquema-info.tope { color: var(--err); }
.esquema-info.suave { color: var(--warn); }
.migas { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.miga { background: none; border: 0; padding: 6px 4px; font: inherit; font-size: 14px; color: var(--accent); cursor: pointer; }
.miga[aria-current="true"] { color: var(--ink); font-weight: 700; cursor: default; }
.miga-sep { color: var(--muted); }
.acciones { display: grid; gap: 14px; }
.medida-esp { margin: 0; font-weight: 600; }
.fila-campo { grid-template-columns: 1fr auto; align-items: center; }
.contador { display: flex; align-items: center; gap: 4px; }
.contador button { width: 44px; height: 44px; font-size: 22px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer; }
.contador button:disabled { opacity: .4; cursor: default; }
.contador output { min-width: 32px; text-align: center; font-weight: 700; font-size: 18px; }
.exacto-siempre { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.exacto-siempre span { color: var(--muted); }
input[type="text"], input[type="password"], input:not([type]) {
  width: 100%; min-height: 44px; padding: 8px 10px; font: inherit; font-size: 16px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink);
}
input:disabled { opacity: .55; }

/* ---------- Taller ---------- */
.taller-panel { display: grid; gap: 12px; }
/* Que tablas y formularios anchos no estiren la página en el celular. */
.panel > *, .taller-panel > *, .grupo > *, .acciones > * { min-width: 0; }
.taller-panel .grupo { border-color: var(--accent); }
body.taller .top { box-shadow: inset 0 -3px 0 var(--accent); }
.libre { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: grid; gap: 8px; }
.libre-cab { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; }
.icono { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); cursor: pointer; font-size: 16px; }
.rejilla { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.rejilla.cantos { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mini { display: grid; gap: 3px; font-size: 13px; }
.mini > span { color: var(--muted); }
.mini small { color: var(--muted); font-size: 11px; }
.mini select, .mini input { min-height: 40px; }
.botones { display: flex; flex-wrap: wrap; gap: 8px; }
.btn.peligro { border-color: var(--err); color: var(--err); }
.tabla { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabla th, .tabla td { padding: 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tabla .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tabla tfoot th, .tabla tfoot td { font-weight: 700; }
.desliza { overflow-x: auto; }
.laminas { display: grid; gap: 10px; }
.laminas figure { margin: 0; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px; color: #222; }
.laminas svg { display: block; width: 100%; height: auto; }
.laminas figcaption { font-size: 12px; color: #555; margin-top: 4px; }
h3 { font-size: 14px; margin: 14px 0 6px; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); width: min(380px, calc(100% - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { display: grid; gap: 12px; }
dialog h2 { text-transform: none; letter-spacing: 0; color: var(--ink); font-size: 18px; }
.error-txt { color: var(--err); margin: 0; font-size: 14px; min-height: 1em; }

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .rejilla { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .layout { grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; padding: 16px; }
  .visor { position: sticky; top: 16px; align-self: start; }
  #view { height: calc(100vh - 230px); min-height: 380px; }
  .panel { padding-bottom: 120px; }
  .barra-precio { left: auto; right: 16px; bottom: 16px; width: 400px; border: 1px solid var(--line); border-radius: 12px; }
}
