/* CortaFácil — estilos */
:root {
  --fondo: #f4f1ec;
  --panel: #ffffff;
  --panel-2: #faf7f2;
  --borde: #e4dbcd;
  --texto: #2b2520;
  --sub: #6b6257;
  --cafe: #7a5230;
  --cafe-osc: #5a3e1b;
  --cafe-claro: #efe6d6;
  --acento: #ffb703;
  --verde: #4f7a3a;
  --rojo: #c0392b;
  --aviso: #b5541c;
  --sombra: 0 1px 2px rgba(60, 40, 15, .06), 0 2px 10px rgba(60, 40, 15, .06);
  --radio: 12px;
  --nav-h: 0px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fondo: #1d1915;
    --panel: #27221d;
    --panel-2: #2e2822;
    --borde: #3d352d;
    --texto: #f0e9df;
    --sub: #b3a796;
    --cafe: #c08a55;
    --cafe-osc: #e3b27c;
    --cafe-claro: #3a2f24;
    --verde: #93c27a;
    --rojo: #e3685a;
    --aviso: #f0a060;
    --sombra: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fondo);
  color: var(--texto);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }
[hidden] { display: none !important; }
.sub { color: var(--sub); font-size: 13px; }
.ayuda { color: var(--sub); font-size: 13px; margin: 0 0 10px; }

/* ---------------------------------------------------------------- barra */
.barra {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--borde);
}
.marca { display: flex; align-items: center; gap: 10px; min-width: 0; }
.marca img { flex: none; border-radius: 8px; }
.marca strong { display: block; font-size: 17px; color: var(--cafe-osc); }
.marca .sub { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.acciones-barra { display: flex; align-items: center; gap: 6px; }
.estado { color: var(--verde); font-size: 13px; margin-right: 6px; white-space: nowrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--borde); border-radius: 10px;
  background: var(--panel); cursor: pointer; text-align: center;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--panel-2); border-color: var(--cafe); }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.btn svg circle { fill: currentColor; stroke: none; }
.btn.primario { background: var(--cafe); border-color: var(--cafe); color: #fff; font-weight: 600; }
.btn.primario:hover { background: var(--cafe-osc); }
.btn.suave { color: var(--sub); }
.btn:disabled { opacity: .55; cursor: default; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .lado:focus-visible {
  outline: 2px solid var(--cafe); outline-offset: 2px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn.primario { color: #1d1915; }
}

.menu-mas { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  min-width: 250px; padding: 6px;
  background: var(--panel); border: 1px solid var(--borde); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.15);
}
.menu button { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; background: none; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--cafe-claro); }
.menu hr { border: 0; border-top: 1px solid var(--borde); margin: 4px 0; }

/* ---------------------------------------------------------------- layout */
.app {
  display: grid; grid-template-columns: minmax(360px, 430px) 1fr; gap: 16px;
  padding: 16px; max-width: 1800px; margin: 0 auto;
  align-items: start;
}
.panel { min-width: 0; }
.panel.izq { position: sticky; top: 72px; display: flex; flex-direction: column; max-height: calc(100vh - 88px); }
.panel.izq > .seccion { overflow-y: auto; padding: 2px 2px 8px; flex: 1; min-height: 0; }
.panel.der { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px 16px 18px; box-shadow: var(--sombra); min-height: 70vh; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--borde); margin-bottom: 12px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; flex: none; }
.tabs button {
  border: 0; background: none; padding: 10px 12px; cursor: pointer; white-space: nowrap;
  color: var(--sub); border-bottom: 3px solid transparent; margin-bottom: -1px; font-weight: 500;
}
.tabs button[aria-selected="true"] { color: var(--cafe-osc); border-bottom-color: var(--cafe); }

/* secciones visibles según pestaña (escritorio) */
.panel.izq > .seccion { display: none; }
body[data-tab-izq="piezas"] .panel.izq > [data-seccion="piezas"],
body[data-tab-izq="materiales"] .panel.izq > [data-seccion="materiales"],
body[data-tab-izq="ajustes"] .panel.izq > [data-seccion="ajustes"] { display: block; }
.tab-der { display: none; }
body[data-tab-der="plano"] [data-tab-panel="plano"],
body[data-tab-der="orden"] [data-tab-panel="orden"],
body[data-tab-der="cotizacion"] [data-tab-panel="cotizacion"] { display: block; }

/* ---------------------------------------------------------------- formularios */
.tarjeta { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 12px; margin-bottom: 12px; box-shadow: var(--sombra); }
fieldset.tarjeta { margin: 0 0 12px; }
legend { font-weight: 600; color: var(--cafe-osc); padding: 0 4px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--sub); min-width: 0; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px;
  border: 1px solid var(--borde); border-radius: 8px; background: var(--panel-2); color: var(--texto); font-size: 15px;
}
input[aria-invalid="true"] { border-color: var(--rojo); background: color-mix(in srgb, var(--rojo) 8%, var(--panel)); }
textarea { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.fila { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 10px; }
.fila > label { flex: 1; }
.fila > .crece { flex: 3; }
.fila > .corto { flex: .7; }
.fila.botones { align-items: center; flex-wrap: wrap; margin-bottom: 0; }
.fila.envolver { margin-top: 10px; }
label.check, label.radio { flex-direction: row; align-items: center; gap: 8px; color: var(--texto); font-size: 14px; padding: 6px 0; }
label.check input, label.radio input { width: 18px; height: 18px; accent-color: var(--cafe); margin: 0; }
.fila > label.check { flex: none; padding-bottom: 10px; }
.campo-lineal { display: grid; grid-template-columns: 1fr 90px; align-items: center; column-gap: 10px; color: var(--texto); font-size: 14px; margin: 6px 0 10px; }
.campo-lineal small { grid-column: 1 / -1; color: var(--sub); font-size: 12px; }
.proyecto-campos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.proyecto-campos label:first-child { grid-column: 1 / -1; }
.proyecto-campos label:first-child input { font-weight: 600; }

.segmentado { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 8px 0; font-size: 14px; }
.segmentado > span { margin-right: 4px; }
.segmentado label { flex-direction: row; }
.segmentado input { position: absolute; opacity: 0; pointer-events: none; }
.segmentado label span { padding: 6px 12px; border: 1px solid var(--borde); border-radius: 20px; cursor: pointer; color: var(--texto); font-size: 13px; }
.segmentado input:checked + span { background: var(--cafe); border-color: var(--cafe); color: #fff; }
.segmentado input:focus-visible + span { outline: 2px solid var(--cafe); outline-offset: 2px; }

/* editor de canto: rectángulo con 4 lados que se tocan */
.canto-editor { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.canto-editor .lbl { font-size: 13px; color: var(--sub); width: 100%; margin-bottom: -6px; }
.canto-pieza { position: relative; width: 132px; height: 78px; flex: none; }
.canto-pieza .centro { position: absolute; inset: 14px; background: #e8d9c0; border: 1px solid #b9a582; border-radius: 3px; pointer-events: none; }
.lado { position: absolute; border: 0; padding: 0; cursor: pointer; background: transparent; font-size: 10px; color: var(--sub); }
.lado::after { content: ""; position: absolute; background: #cdbfa8; border-radius: 3px; transition: background .15s; }
.lado[aria-pressed="true"]::after { background: var(--rojo); }
.lado.l1 { left: 14px; right: 14px; top: 0; height: 14px; }
.lado.l2 { left: 14px; right: 14px; bottom: 0; height: 14px; }
.lado.a1 { top: 14px; bottom: 14px; left: 0; width: 14px; }
.lado.a2 { top: 14px; bottom: 14px; right: 0; width: 14px; }
.lado.l1::after { left: 0; right: 0; bottom: 2px; height: 6px; }
.lado.l2::after { left: 0; right: 0; top: 2px; height: 6px; }
.lado.a1::after { top: 0; bottom: 0; right: 2px; width: 6px; }
.lado.a2::after { top: 0; bottom: 0; left: 2px; width: 6px; }
.lado { font-size: 0; }
.canto-rapido { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 160px; }
.chip { border: 1px solid var(--borde); background: var(--panel-2); border-radius: 16px; padding: 5px 10px; font-size: 12px; cursor: pointer; }
.chip:hover { border-color: var(--cafe); }

/* lista de piezas */
.lista-cab { display: flex; justify-content: space-between; align-items: baseline; margin: 6px 2px 6px; }
.lista-piezas { display: flex; flex-direction: column; gap: 6px; }
.pieza {
  display: grid; grid-template-columns: 14px 1fr auto; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--borde); border-radius: 10px; padding: 8px 6px 8px 10px;
}
.pieza.editando { border-color: var(--cafe); box-shadow: 0 0 0 2px color-mix(in srgb, var(--cafe) 30%, transparent); }
.pieza .color { width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(0,0,0,.25); }
.pieza .nom { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pieza .det { font-size: 12.5px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pieza .med { font-variant-numeric: tabular-nums; color: var(--texto); font-weight: 500; }
.pieza .acc { display: flex; gap: 2px; }
.icono { width: 36px; height: 36px; border: 0; background: none; border-radius: 8px; cursor: pointer; display: grid; place-items: center; color: var(--sub); }
.icono:hover { background: var(--cafe-claro); color: var(--cafe-osc); }
.icono svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.vacio { text-align: center; color: var(--sub); padding: 20px 10px; border: 1px dashed var(--borde); border-radius: 10px; }

/* materiales */
.material { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center; }
.material .nom { font-weight: 600; }
.agregar-mat { display: flex; gap: 10px; align-items: flex-end; }

/* calcular */
.barra-calcular { padding-top: 10px; background: var(--fondo); }
.btn.calcular {
  width: 100%; min-height: 52px; position: relative; overflow: hidden;
  background: var(--cafe); border-color: var(--cafe); color: #fff; font-size: 17px; font-weight: 700; letter-spacing: .3px;
}
.btn.calcular:hover { background: var(--cafe-osc); }
.btn.calcular .progreso { position: absolute; left: 0; bottom: 0; height: 4px; width: 0; background: var(--acento); }
.btn.calcular.ocupado .progreso { animation: avance 1.2s linear infinite; width: 40%; }
@keyframes avance { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.calcular { color: #1d1915; } }
#msg-progreso { min-height: 18px; padding-top: 4px; }

/* ---------------------------------------------------------------- resultado */
.resumen { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.resumen div { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.resumen span { display: block; font-size: 12px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.resumen b { display: block; font-size: 22px; color: var(--cafe-osc); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nota { color: var(--sub); font-size: 13px; margin: 8px 2px 10px; min-height: 18px; }
.nota.aviso { color: var(--aviso); font-weight: 600; }
.barra-imprimir { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.barra-imprimir .sub { flex: 1; min-width: 180px; }

.grupo-mat { margin: 6px 0 22px; }
.grupo-mat > h2 { font-size: 16px; margin: 0 0 10px; padding: 8px 12px; background: var(--cafe-claro); border-radius: 8px; color: var(--cafe-osc); }
.grupo-mat > h2 .sub { font-weight: 400; }
.hoja { margin-bottom: 22px; }
.hoja h3 { font-size: 14px; margin: 0 0 6px; color: var(--cafe); }
.hoja h3 .sub { font-weight: 400; }
.hoja svg { width: 100%; height: auto; touch-action: manipulation; }
.hoja svg .pz { cursor: pointer; }
.hoja svg .pz.sel rect.r { stroke: #000; stroke-width: 6; }
.info-pieza { font-size: 13px; min-height: 20px; margin-top: 4px; color: var(--texto); }
.leyenda { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--sub); margin: 4px 0 12px; }
.leyenda i { display: inline-block; width: 12px; height: 12px; vertical-align: -2px; margin-right: 4px; border-radius: 2px; }
.retazos-txt { font-size: 13px; color: var(--verde); margin-top: 2px; }

.inicio { text-align: center; padding: 48px 16px; color: var(--sub); }
.inicio img { width: 84px; height: 84px; margin: 0 auto 12px; }
.inicio h2 { color: var(--cafe-osc); margin: 0 0 8px; font-size: 20px; }
.inicio p { max-width: 460px; margin: 0 auto 16px; }

/* orden de cortes */
.orden-hoja { margin-bottom: 18px; }
.orden-hoja h3 { font-size: 15px; color: var(--cafe-osc); margin: 0 0 8px; }
.paso {
  display: grid; grid-template-columns: 30px 64px 1fr; gap: 4px 10px; align-items: start;
  padding: 10px 8px; border-bottom: 1px solid var(--borde); cursor: pointer; border-radius: 8px;
}
.paso:hover { background: var(--panel-2); }
.paso .ck { width: 22px; height: 22px; border: 2px solid var(--borde); border-radius: 6px; display: grid; place-items: center; margin-top: 2px; }
.paso.hecho .ck { background: var(--verde); border-color: var(--verde); }
.paso.hecho .ck::after { content: "✓"; color: #fff; font-size: 14px; font-weight: 700; }
.paso .n { font-weight: 700; color: var(--sub); font-size: 13px; padding-top: 3px; }
.paso .accion { font-weight: 600; }
.paso .trozo { font-size: 12px; color: var(--sub); }
.paso .res { grid-column: 3; font-size: 13px; color: var(--sub); }
.paso.hecho .accion, .paso.hecho .res { text-decoration: line-through; opacity: .6; }

/* cotización */
.cotizacion { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 14px; align-items: start; }
.cotizacion .tarjeta label { margin-bottom: 10px; }
.titulo-tarjeta { display: block; color: var(--cafe-osc); margin-bottom: 8px; }
table.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tabla td, table.tabla th { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--borde); vertical-align: top; }
table.tabla th { font-size: 12px; color: var(--sub); font-weight: 600; }
table.tabla td.v, table.tabla th.v { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.tabla tr.sub td { font-weight: 700; }
table.tabla td .det { display: block; font-size: 12px; color: var(--sub); }
.total-cot { display: flex; justify-content: space-between; align-items: baseline; margin-top: 12px; font-size: 15px; }
.total-cot b { font-size: 28px; color: var(--cafe-osc); }
.aviso { color: var(--aviso); font-size: 13px; margin-top: 6px; }

/* ---------------------------------------------------------------- diálogos */
.dlg {
  border: 0; padding: 0; border-radius: 16px; background: var(--panel); color: var(--texto);
  width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.dlg.angosto { width: min(460px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(30, 20, 10, .45); }
.dlg .cab { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 10px; border-bottom: 1px solid var(--borde); }
.dlg .cab h2 { margin: 0; font-size: 17px; color: var(--cafe-osc); }
.dlg .cuerpo { padding: 14px 16px; overflow: auto; max-height: calc(100vh - 190px); }
.dlg .pie { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid var(--borde); flex-wrap: wrap; }
.dlg .pie .izq { margin-right: auto; }
.dlg .cuerpo label { margin-bottom: 10px; }
.dlg .nota-dlg { color: var(--sub); font-size: 13px; margin: 0 0 12px; white-space: pre-line; }
.dlg .mensaje { white-space: pre-line; margin: 0; }
.lista-dlg { display: flex; flex-direction: column; gap: 6px; }
.item-dlg { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--borde); border-radius: 10px; }
.item-dlg .nom { font-weight: 600; }
.item-dlg .det { font-size: 12.5px; color: var(--sub); }
.item-dlg.clic { cursor: pointer; }
.item-dlg.clic:hover { border-color: var(--cafe); }
.buscar { margin-bottom: 10px; }

.noscript { padding: 20px; text-align: center; }

/* ---------------------------------------------------------------- celular / tableta */
.nav-movil { display: none; }
@media (max-width: 1100px) {
  .resumen { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cotizacion { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  :root { --nav-h: 62px; }
  body { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
  .solo-ancho { display: none; }
  .barra { padding: 8px 12px; }
  .btn { padding: 8px 10px; }
  .app { display: block; padding: 12px; }
  .panel.izq { position: static; max-height: none; display: block; }
  .panel.izq > .tabs { display: none; }
  .panel.izq > .seccion { overflow: visible; padding: 0; }
  .panel.der { padding: 12px; border-radius: 12px; min-height: 0; }
  /* en celular manda la barra inferior */
  .panel.izq > .seccion, .panel.der { display: none !important; }
  body[data-vista="piezas"] .panel.izq > [data-seccion="piezas"],
  body[data-vista="materiales"] .panel.izq > [data-seccion="materiales"],
  body[data-vista="ajustes"] .panel.izq > [data-seccion="ajustes"] { display: block !important; }
  body[data-vista="resultado"] .panel.der { display: block !important; }
  body[data-vista="resultado"] .barra-calcular { display: none; }
  .barra-calcular {
    position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 10;
    margin: 0 -12px; padding: 8px 12px; background: color-mix(in srgb, var(--fondo) 92%, transparent);
    backdrop-filter: blur(6px); border-top: 1px solid var(--borde);
  }
  #msg-progreso:empty { display: none; }
  .nav-movil {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel); border-top: 1px solid var(--borde);
  }
  .nav-movil button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11.5px; color: var(--sub); cursor: pointer; }
  .nav-movil svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
  .nav-movil button[aria-current="true"] { color: var(--cafe-osc); font-weight: 600; }
  .nav-movil button[aria-current="true"] svg { stroke-width: 2.2; }
  .resumen b { font-size: 19px; }
  .menu { position: fixed; right: 10px; top: 56px; }
}
@media (max-width: 420px) {
  .fila { gap: 8px; }
  .resumen { gap: 6px; }
  .resumen div { padding: 6px 8px; }
  .resumen b { font-size: 16px; }
  .resumen span { font-size: 11px; }
  .tabs .largo { display: none; }
  .paso { grid-template-columns: 26px 1fr; }
  .paso .n { display: none; }
  .paso .res { grid-column: 2; }
}

@media print {
  .barra, .nav-movil, .panel.izq, .barra-imprimir { display: none !important; }
}
