/* Estilos de SEFEL, copiados del prototipo v2 para que la aplicación se vea igual.
   La fuente Montserrat se sirve desde la misma aplicación (sin Google Fonts). */
@font-face { font-family: "Montserrat"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fuentes/montserrat-latin-400-normal.e7198b2dcb57.woff2") format("woff2"); }
@font-face { font-family: "Montserrat"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fuentes/montserrat-latin-500-normal.f96e8aab37e8.woff2") format("woff2"); }
@font-face { font-family: "Montserrat"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fuentes/montserrat-latin-600-normal.9e606da1cbeb.woff2") format("woff2"); }
@font-face { font-family: "Montserrat"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fuentes/montserrat-latin-700-normal.1c0792ac34ef.woff2") format("woff2"); }
@font-face { font-family: "Montserrat"; font-style: normal; font-weight: 800; font-display: swap; src: url("../fuentes/montserrat-latin-800-normal.9e624ca74fb3.woff2") format("woff2"); }
/* Paleta del dossier de SEFEL: rojo para acciones y énfasis, negro carbón
   para títulos y navegación, gris acero para lo secundario, fondo blanco. */
:root {
  --rojo: #C62828;
  --rojo-hover: #A82020;
  --rojo-suave: #FCEBEB;
  --carbon: #171717;
  --texto: #1F1F1F;
  --texto-2: #525252;        /* gris de texto secundario, contraste 7,8:1 sobre blanco */
  --acero: #8A8A8A;          /* solo bordes y decoración */
  --linea: #DCDCDC;
  --linea-suave: #ECECEC;
  --fondo: #FFFFFF;
  --fondo-2: #F6F6F5;
  --fondo-3: #EDEDEB;
  --verde: #1D6B35; --verde-fondo: #E3F3E7; --verde-borde: #7CC08F;
  --ambar: #7A4A00; --ambar-fondo: #FFF2CC; --ambar-borde: #E3A512;
  --gris: #474747; --gris-fondo: #EBEBEB;
  --foco: #1F1F1F;
  --sombra-panel: 0 18px 50px rgba(0, 0, 0, .22), 0 2px 8px rgba(0, 0, 0, .10);
  --radio: 8px;
  --f: "Montserrat", "Poppins", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --lateral: 264px;
  --lateral-chica: 76px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 400 17px/1.55 var(--f); color: var(--texto); background: var(--fondo); }
h1, h2, h3 { color: var(--carbon); line-height: 1.2; margin: 0; text-wrap: balance; }
h1 { font-size: 1.65rem; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1.06rem; font-weight: 700; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--carbon); font-weight: 600; text-decoration: underline; text-decoration-color: var(--rojo); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { color: var(--rojo-hover); }
.num, td.num, th.num, .cifra { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.num { text-align: right; white-space: nowrap; }
.suave { color: var(--texto-2); }
.chico { font-size: .88rem; }
.ico { width: 1.15em; height: 1.15em; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.2em; }
:focus-visible { outline: 3px solid var(--foco); outline-offset: 2px; box-shadow: 0 0 0 5px #fff; }
.solo-lector { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: no-preference) { html, .contenido, .capa-cuerpo { scroll-behavior: smooth; } }

/* ---------- estructura ---------- */
#app { display: grid; grid-template-columns: var(--lateral) minmax(0, 1fr); height: 100dvh; }
#app.colapsada { grid-template-columns: var(--lateral-chica) minmax(0, 1fr); }
.lateral { background: var(--carbon); color: #F2F2F2; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.lateral .marca { display: flex; align-items: center; gap: 12px; padding: 16px 16px 12px; }
.lateral .marca .placa { background: #fff; border-radius: 6px; padding: 4px 6px; display: grid; place-items: center; flex: none; }
.lateral .marca img { width: 64px; height: auto; display: block; }
.lateral .marca b { display: block; font-size: 1.05rem; letter-spacing: .02em; }
.lateral .marca span { display: block; font-size: .85rem; color: #C9C9C9; }
.nav { display: grid; gap: 2px; padding: 8px 10px; }
.nav a { display: flex; align-items: center; gap: 12px; color: #EDEDED; text-decoration: none; padding: 11px 12px; border-radius: 8px; font-weight: 600; font-size: 1rem; position: relative; min-height: 46px; }
.nav a .paso { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid #7A7A7A; font-size: .85rem; flex: none; }
.nav a:hover { background: #2A2A2A; }
.nav a[aria-current="page"] { background: #2E2E2E; color: #fff; }
.nav a[aria-current="page"]::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 3px 3px 0; background: var(--rojo); }
.nav a[aria-current="page"] .paso { background: var(--rojo); border-color: var(--rojo); color: #fff; }
.nav .separador { height: 1px; background: #333; margin: 8px 6px; }
.lateral .pie { margin-top: auto; padding: 12px 16px 16px; display: grid; gap: 8px; font-size: .88rem; color: #C9C9C9; }
.btn-lateral { display: flex; align-items: center; gap: 10px; background: transparent; border: 1px solid #444; color: #EDEDED; border-radius: 8px; padding: 9px 12px; cursor: pointer; min-height: 44px; font-weight: 600; font-size: .92rem; }
.btn-lateral:hover { background: #2A2A2A; }
#app.colapsada .lateral .marca { justify-content: center; padding-inline: 8px; }
#app.colapsada .lateral .marca img { width: 48px; }
#app.colapsada .txt-nav, #app.colapsada .lateral .marca .marca-txt, #app.colapsada .lateral .pie .txt-pie { display: none; }
#app.colapsada .nav a { justify-content: center; padding-inline: 0; }
#app.colapsada .btn-lateral { justify-content: center; }
#app.colapsada .btn-lateral .ico-colapsar { transform: rotate(180deg); }

.principal { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.barra-sup { display: flex; align-items: center; gap: 14px; padding: 10px 24px; border-bottom: 1px solid var(--linea); background: #fff; min-height: 62px; }
.migas { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: .95rem; min-width: 0; flex: 1; }
.migas .volver-ico { display: none; }
.migas a { color: var(--texto-2); text-decoration: none; font-weight: 600; padding: 4px 2px; }
.migas a:hover { color: var(--rojo); text-decoration: underline; }
.migas .sep { color: var(--acero); }
.migas [aria-current] { color: var(--carbon); font-weight: 700; }
.usuario { display: flex; align-items: center; gap: 10px; flex: none; }
.usuario .avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--carbon); color: #fff; display: grid; place-items: center; font-weight: 700; }
.usuario .quien { line-height: 1.2; }
.usuario .quien b { display: block; font-size: .95rem; }
.usuario .quien span { font-size: .85rem; color: var(--texto-2); }
.barra-sup .btn-menu { display: none; }
.contenido { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; overscroll-behavior: contain; position: relative; }
body:has(#app) { overflow: hidden; }
.lateral, .capa-caja { position: relative; }
#vista { padding: 22px 28px 0; display: flex; flex-direction: column; gap: 20px; min-height: 100%; }
#vista > :last-child:not(.barra-totales) { margin-bottom: 32px; }

/* ---------- componentes ---------- */
.cabecera { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.cabecera .titulos { display: grid; gap: 6px; min-width: 0; }
.cabecera .antetitulo { color: var(--texto-2); font-weight: 600; font-size: .95rem; }
.acciones { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; font-size: 1rem; line-height: 1.2; border-radius: var(--radio); border: 1.5px solid var(--rojo); background: var(--rojo); color: #fff; padding: 10px 18px; min-height: 46px; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--rojo-hover); border-color: var(--rojo-hover); }
.btn.sec { background: #fff; color: var(--carbon); border-color: #BDBDBD; }
.btn.sec:hover { border-color: var(--carbon); background: var(--fondo-2); }
.btn.oscuro { background: var(--carbon); border-color: var(--carbon); }
.btn.oscuro:hover { background: #333; }
.btn.fantasma { background: transparent; border-color: transparent; color: var(--carbon); padding-inline: 10px; }
.btn.fantasma:hover { background: var(--fondo-3); }
.btn.peligro { background: #fff; color: var(--rojo); border-color: var(--rojo); }
.btn.peligro:hover { background: var(--rojo-suave); }
.btn.mini { min-height: 38px; padding: 6px 12px; font-size: .92rem; }
.btn[aria-disabled="true"] { background: var(--fondo-3) !important; border-color: var(--linea) !important; color: #5E5E5E !important; cursor: not-allowed; }
.btn-icono { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 8px; border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--carbon); }
.btn-icono:hover { background: var(--fondo-3); border-color: var(--linea); }
.btn-icono[disabled] { opacity: .35; cursor: not-allowed; }
.btn-icono .ico { width: 20px; height: 20px; }
.tarjeta { background: #fff; border: 1px solid var(--linea); border-radius: 12px; padding: 18px 20px; display: grid; gap: 14px; align-content: start; min-width: 0; }
.tarjeta.gris { background: var(--fondo-2); }
.tarjeta h2 { font-size: 1.12rem; }
.rejilla { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.kpi { border: 1px solid var(--linea); border-radius: 12px; padding: 14px 16px; display: grid; gap: 4px; background: #fff; }
.kpi .eti { color: var(--texto-2); font-size: .92rem; font-weight: 600; }
.kpi .valor { font-size: clamp(1.15rem, 1.9vw, 1.55rem); font-weight: 700; color: var(--carbon); font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi.destacado { border-color: var(--carbon); border-width: 2px; }
.aviso { display: flex; gap: 12px; align-items: flex-start; border-radius: 10px; padding: 12px 16px; border: 1px solid var(--linea); background: var(--fondo-2); font-size: .98rem; }
.aviso .ico { width: 22px; height: 22px; margin-top: 1px; }
.aviso.info { border-left: 4px solid var(--carbon); }
.aviso.ok { background: var(--verde-fondo); border-color: var(--verde-borde); color: #123F20; }
.aviso.alerta { background: var(--ambar-fondo); border-color: var(--ambar-borde); color: #4A2E00; }
.aviso.error { background: var(--rojo-suave); border-color: #E7A3A3; color: #6B1111; }
.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 12px; font-size: .88rem; font-weight: 600; white-space: nowrap; border: 1px solid transparent; background: var(--fondo-3); color: var(--texto); }
.chip .ico { width: 16px; height: 16px; }
.chip.emitido { background: var(--carbon); color: #fff; }
.chip.elaboracion { background: #fff; border-color: var(--acero); color: var(--carbon); }
.chip.activo { background: var(--verde-fondo); color: var(--verde); }
.chip.inactivo { background: var(--gris-fondo); color: var(--gris); }
.chip.borde { background: #fff; border-color: var(--linea); }
.codigo { font-size: .85rem; color: var(--texto-2); font-weight: 600; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.vacio { border: 2px dashed var(--linea); border-radius: 12px; padding: 28px; display: grid; gap: 12px; justify-items: start; background: var(--fondo-2); }
.vacio h3 { font-size: 1.15rem; }

/* ---------- formularios ---------- */
.campo { display: grid; gap: 6px; align-content: start; }
.campo > label, .campo > .eti, fieldset legend { font-weight: 600; font-size: .98rem; color: var(--carbon); }
.campo .ayuda { font-size: .9rem; color: var(--texto-2); }
.campo .error { font-size: .92rem; color: #A01818; font-weight: 600; display: flex; gap: 6px; align-items: center; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="search"], select, textarea {
  width: 100%; border: 1.5px solid var(--acero); border-radius: var(--radio); padding: 10px 12px; min-height: 46px; background: #fff; font-size: 1rem; }
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
input:hover, select:hover, textarea:hover { border-color: #7A7A7A; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: #A01818; box-shadow: 0 0 0 2px #F3C4C4; background: #FFF8F8; }
input[readonly], input:disabled, select:disabled { background: var(--fondo-3); color: #4A4A4A; }
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; accent-color: var(--rojo); margin: 0; }
.formulario { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.formulario .ancho { grid-column: 1 / -1; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.opciones { display: flex; flex-wrap: wrap; gap: 8px; }
.opcion { display: inline-flex; align-items: center; gap: 10px; border: 1.5px solid var(--acero); border-radius: 8px; padding: 9px 14px; cursor: pointer; min-height: 46px; font-weight: 600; }
.opcion:has(input:checked) { border-color: var(--carbon); background: var(--fondo-2); box-shadow: inset 0 0 0 1px var(--carbon); }
.contador { font-size: .9rem; color: var(--texto-2); text-align: right; }
.entrada-cifra { text-align: right; font-variant-numeric: tabular-nums; }
.buscador { position: relative; }
.buscador .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--texto-2); }
.buscador input { padding-left: 42px; }
.filtros { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.filtros .buscador { flex: 1 1 320px; }
.filtros .campo { flex: 1 1 140px; }
.segmentos { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.segmentos button { border: 1.5px solid var(--acero); background: #fff; border-radius: 999px; padding: 8px 14px; font-weight: 600; cursor: pointer; min-height: 42px; font-size: .95rem; }
.segmentos button[aria-pressed="true"] { background: var(--carbon); border-color: var(--carbon); color: #fff; }

/* ---------- tablas ---------- */
.tabla-marco { border: 1px solid var(--linea); border-radius: 12px; background: #fff; }
.tabla-marco.desliza { overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 1rem; }
thead th { position: sticky; top: 0; z-index: 3; background: var(--fondo-2); color: var(--carbon); font-weight: 700; font-size: .95rem; text-align: left; padding: 12px 14px; border-bottom: 2px solid var(--carbon); white-space: nowrap; }
.tabla-marco thead th:first-child { border-top-left-radius: 12px; }
.tabla-marco thead th:last-child { border-top-right-radius: 12px; }
tbody td, tfoot td { padding: 11px 14px; border-bottom: 1px solid var(--linea-suave); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; background: var(--fondo-2); border-top: 2px solid var(--carbon); border-bottom: 0; }
tbody tr.clic { cursor: pointer; }
tbody tr.clic:hover td { background: #FAF6F6; }
tr.subtotal-cat td { background: var(--fondo-2); font-weight: 700; }
tr.encabezado-cat td { background: #fff; font-weight: 700; color: var(--carbon); padding-top: 16px; border-bottom: 1px solid var(--acero); }
td.acciones-fila { white-space: nowrap; text-align: right; }
td.acciones-fila .acciones { justify-content: flex-end; flex-wrap: nowrap; gap: 6px; }

/* ---------- presupuesto jerárquico ---------- */
.doc-cab { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 14px 22px; align-items: center; border: 1px solid var(--linea); border-radius: 12px; padding: 16px 20px; background: #fff; }
.doc-cab .logo { width: 84px; height: auto; display: block; }
.doc-cab h1 { font-size: 1.55rem; }
.doc-cab .datos { display: flex; flex-wrap: wrap; gap: 4px 22px; color: var(--texto-2); font-size: .98rem; margin-top: 6px; }
.doc-cab .datos b { color: var(--carbon); font-weight: 600; }
.doc-cab > .acciones { grid-column: 1 / -1; justify-content: flex-start; border-top: 1px solid var(--linea-suave); padding-top: 14px; }
.barra-arbol { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
table.arbol { table-layout: auto; }
table.arbol th.c-item, table.arbol td.c-item { width: 1%; white-space: nowrap; }
table.arbol td.c-item { font-weight: 700; color: var(--carbon); }
table.arbol .c-item .dentro { display: inline-flex; align-items: center; gap: 4px; }
table.arbol td.c-desc { padding-left: calc(14px + var(--n, 0) * 22px); min-width: 240px; width: 100%; }
table.arbol td.acciones-fila { padding-inline: 6px 10px; }
table.arbol td.acciones-fila .acciones { gap: 0; }
table.arbol .btn-icono { width: 36px; height: 36px; }
table.arbol th, table.arbol td { padding-inline: 12px; }
table.arbol td.num { white-space: nowrap; }
table.arbol td.c-cant { width: 130px; }
table.arbol .toggle { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; color: var(--carbon); }
table.arbol .toggle:hover { background: var(--fondo-3); }
table.arbol .toggle .ico { transition: transform .15s; }
table.arbol .toggle[aria-expanded="true"] .ico { transform: rotate(90deg); }
table.arbol .sin-toggle { display: inline-block; width: 32px; }
tr.fila-titulo td { font-weight: 700; color: var(--carbon); }
tr.fila-titulo.nivel-1 td { background: #EFEFED; border-bottom-color: #D5D5D3; font-size: 1.04rem; }
tr.fila-titulo.nivel-1 td:first-child { box-shadow: inset 4px 0 0 var(--rojo); }
tr.fila-titulo.nivel-2 td { background: #F6F6F5; }
tr.fila-titulo.nivel-3 td, tr.fila-titulo.nivel-4 td { background: #FBFBFA; }
tr.fila-titulo .conteo { font-weight: 500; color: var(--texto-2); font-size: .88rem; margin-left: 8px; }
tr.fila-partida:hover td { background: #FCFAFA; }
.link-apu { background: none; border: 0; padding: 2px 0; text-align: left; cursor: pointer; font-weight: 600; color: var(--carbon); text-decoration: underline; text-decoration-color: #BDBDBD; text-underline-offset: 4px; }
.link-apu:hover { color: var(--rojo); text-decoration-color: var(--rojo); }
.celda-cant { display: grid; gap: 4px; justify-items: end; }
.celda-cant input { width: 112px; min-height: 42px; padding: 7px 10px; }
.celda-cant .error { font-size: .88rem; color: #A01818; font-weight: 600; white-space: normal; text-align: right; max-width: 220px; }
.congelado { display: inline-flex; align-items: center; gap: 4px; }
.congelado .ico { width: 15px; height: 15px; color: var(--texto-2); }
.bajo-tabla { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.lista-indirectos { display: grid; gap: 0; }
.lista-indirectos .fila { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--linea); }
.recargo { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 4px 12px; align-items: center; padding: 6px 0; }
.recargo > label { grid-column: 1 / -1; font-weight: 600; }
.recargo.iva { grid-template-columns: minmax(0, 1fr) auto; }
.recargo.iva > label { grid-column: auto; display: flex; gap: 10px; align-items: center; min-height: 44px; cursor: pointer; }
.recargo input { min-height: 42px; }
.recargo .num { font-weight: 600; }
.lista-indirectos .fila .acciones { flex-wrap: nowrap; }
#consideraciones { min-height: 170px; }

/* barra de totales pegada abajo */
.barra-totales { position: sticky; bottom: 0; z-index: 5; margin: 0 -28px; padding: 10px 20px calc(12px + env(safe-area-inset-bottom, 0px)); background: #fff; border-top: 2px solid var(--carbon); box-shadow: 0 -8px 24px rgba(0, 0, 0, .08); display: flex; align-items: stretch; gap: 6px; overflow-x: auto; }
.barra-totales .t { display: grid; gap: 0; padding: 4px 8px; border-radius: 8px; min-width: max-content; flex: 1 0 auto; }
.barra-totales .t span { font-size: .84rem; color: var(--texto-2); font-weight: 600; white-space: nowrap; }
.barra-totales .t b { font-size: 1.04rem; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--carbon); }
.barra-totales .t + .t { border-left: 1px solid var(--linea); border-radius: 0; }
.barra-totales .t.base, .barra-totales .t.total { border-radius: 8px; }
.barra-totales .t.base + .t, .barra-totales .t.total { border-left: 0; }
.barra-totales .t.base { border: 2px solid var(--carbon); }
.barra-totales .t.total { background: var(--carbon); }
.barra-totales .t.total span { color: #E6E6E6; }
.barra-totales .t.total b { color: #fff; font-size: 1.22rem; }

/* ---------- capas superpuestas (paneles y modales) ---------- */
dialog.capa { border: 0; padding: 0; background: #fff; color: var(--texto); box-shadow: var(--sombra-panel); max-height: 100dvh; overflow: hidden; }
dialog.capa::backdrop { background: rgba(23, 23, 23, .45); }
dialog.capa-lateral { margin: 0 0 0 auto; height: 100dvh; width: min(980px, 94vw); max-width: 100vw; border-radius: 14px 0 0 14px; }
dialog.capa-lateral.angosta { width: min(640px, 94vw); }
dialog.capa-modal { width: min(720px, 94vw); max-height: min(88dvh, 900px); border-radius: 14px; }
dialog.capa-modal.chica { width: min(520px, 94vw); }
.capa-caja { display: flex; flex-direction: column; max-height: inherit; height: 100%; }
dialog.capa-modal .capa-caja { max-height: min(88dvh, 900px); }
.capa-cab { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 18px 22px 14px; border-bottom: 1px solid var(--linea); }
.capa-cab .antetitulo { color: var(--texto-2); font-weight: 600; font-size: .92rem; }
.capa-cab h2 { font-size: 1.35rem; }
.capa-cuerpo { padding: 18px 22px; overflow-y: auto; flex: 1; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-content: start; overscroll-behavior: contain; }
.capa-cuerpo > * { min-width: 0; }
.uni-movil { display: none; }
details.como summary { cursor: pointer; font-weight: 600; color: var(--carbon); min-height: 32px; }
details.como p { margin-top: 6px; color: var(--texto-2); }
.capa-pie { padding: 14px 22px; border-top: 1px solid var(--linea); display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; background: var(--fondo-2); }
.capa-cuerpo thead th { top: -18px; }
@media (prefers-reduced-motion: no-preference) {
  dialog.capa-lateral[open] { animation: deslizar .22s ease-out; }
  dialog.capa-modal[open] { animation: aparecer .16s ease-out; }
  dialog.capa[open]::backdrop { animation: oscurecer .2s ease-out; }
  @keyframes deslizar { from { transform: translateX(40px); opacity: .3; } }
  @keyframes aparecer { from { transform: translateY(10px) scale(.985); opacity: .2; } }
  @keyframes oscurecer { from { opacity: 0; } }
}
.lista-eleccion { display: grid; gap: 6px; }
.eleccion { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; text-align: left; width: 100%; border: 1.5px solid var(--linea); border-radius: 10px; background: #fff; padding: 10px 14px; cursor: pointer; min-height: 52px; }
.eleccion:hover { border-color: var(--carbon); }
.eleccion[aria-pressed="true"] { border-color: var(--rojo); box-shadow: inset 0 0 0 1px var(--rojo); background: #FFF9F9; }
.eleccion[aria-disabled="true"] { cursor: not-allowed; background: var(--fondo-2); color: #5E5E5E; }
.eleccion b { font-weight: 600; }
.eleccion .detalle { grid-column: 1 / -1; font-size: .9rem; color: var(--texto-2); }
.menu-acciones { display: grid; gap: 6px; }
.menu-acciones .btn { justify-content: flex-start; }

/* ---------- materiales a comprar ---------- */
.pestanas { display: flex; gap: 4px; border-bottom: 2px solid var(--linea); flex-wrap: wrap; }
.pestanas button { border: 0; background: none; padding: 10px 16px; font-weight: 700; color: var(--texto-2); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; min-height: 46px; font-size: 1rem; }
.pestanas button[aria-selected="true"] { color: var(--carbon); border-bottom-color: var(--rojo); }
.compra { font-weight: 700; color: var(--carbon); }
.compra small { display: block; font-weight: 500; color: var(--texto-2); font-size: .88rem; }
.cant-grande { font-size: 1.1rem; font-weight: 700; }
.tarjetas-mat { display: none; }

/* ---------- inicio ---------- */
.flujo { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); counter-reset: paso; }
.flujo li a { display: grid; gap: 6px; height: 100%; text-decoration: none; color: var(--texto); border: 1px solid var(--linea); border-radius: 12px; padding: 16px; background: #fff; position: relative; }
.flujo li a:hover { border-color: var(--carbon); }
.flujo li a .n { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--carbon); color: #fff; font-weight: 800; }
.flujo li.hecho a .n { background: var(--verde); }
.flujo li.siguiente a { border: 2px solid var(--rojo); }
.flujo li.siguiente a .n { background: var(--rojo); }
.flujo li a b { font-size: 1.05rem; color: var(--carbon); }
.flujo li a .estado-paso { font-size: .9rem; font-weight: 600; color: var(--texto-2); }

/* ---------- ingreso ---------- */
.ingreso { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: var(--fondo-2); }
.ingreso .caja { width: min(1000px, 100%); display: grid; grid-template-columns: 1fr 1.1fr; background: #fff; border-radius: 16px; overflow: hidden; border: 1px solid var(--linea); box-shadow: 0 10px 40px rgba(0, 0, 0, .08); }
.ingreso .lado-marca { background: var(--carbon); color: #EDEDED; padding: 32px; display: grid; gap: 18px; align-content: start; }
.ingreso .lado-marca .placa { background: #fff; border-radius: 10px; padding: 10px; width: 170px; }
.ingreso .lado-marca .placa img { width: 100%; display: block; }
.ingreso .lado-marca h1 { color: #fff; font-size: 1.8rem; }
.ingreso .lado-marca ol { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; color: #D6D6D6; }
.ingreso form { padding: 32px; display: grid; gap: 16px; align-content: start; }
.cuentas { display: grid; gap: 8px; }
.cuenta { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 12px; align-items: center; text-align: left; border: 1.5px solid var(--linea); border-radius: 10px; padding: 10px 14px; background: #fff; cursor: pointer; min-height: 56px; }
.cuenta:hover, .cuenta[aria-pressed="true"] { border-color: var(--carbon); background: var(--fondo-2); }
.cuenta .ico { grid-row: span 2; width: 26px; height: 26px; }
.cuenta small { color: var(--texto-2); font-size: .9rem; }

/* ---------- avisos flotantes ---------- */
.toast-zona { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 50; max-width: min(460px, calc(100vw - 32px)); pointer-events: none; }
dialog .toast-zona { position: fixed; }
.toast { display: flex; gap: 10px; align-items: flex-start; background: var(--carbon); color: #fff; padding: 12px 16px; border-radius: 10px; font-size: .98rem; box-shadow: 0 8px 26px rgba(0, 0, 0, .25); pointer-events: auto; }
.toast.error { background: #fff; color: #6B1111; border: 2px solid var(--rojo); }
.toast .ico { width: 22px; height: 22px; margin-top: 1px; }
@media (prefers-reduced-motion: no-preference) { .toast { animation: aparecer .2s ease-out; } }

/* ---------- documento para el cliente (reportes e impresión) ---------- */
.documento { background: #fff; border: 1px solid var(--linea); border-radius: 12px; padding: 28px 32px; display: grid; gap: 18px; }
.documento .doc-enc { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; border-bottom: 3px solid var(--rojo); padding-bottom: 14px; flex-wrap: wrap; }
.documento .doc-enc img { width: 120px; height: auto; }
.documento .doc-enc .empresa { text-align: right; font-size: .92rem; color: var(--texto-2); }
.documento .doc-enc .empresa b { color: var(--carbon); font-size: 1rem; }
.documento .doc-datos { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px 20px; font-size: .98rem; }
.documento .doc-datos span { color: var(--texto-2); }
.documento table { font-size: .95rem; }
.documento thead th { position: static; background: var(--carbon); color: #fff; border-bottom: 0; }
.documento tr.t1 td { font-weight: 700; background: #EFEFED; }
.documento tr.t2 td, .documento tr.t3 td, .documento tr.t4 td { font-weight: 700; background: #F8F8F7; }
.documento .resumen-doc { margin-left: auto; width: min(440px, 100%); display: grid; }
.documento .resumen-doc div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--linea-suave); }
.documento .resumen-doc div.fuerte { font-weight: 800; font-size: 1.08rem; border-bottom: 0; border-top: 2px solid var(--carbon); }
.documento .consideraciones { border: 1.5px solid var(--carbon); border-radius: 8px; padding: 12px 16px; white-space: pre-line; }
.documento .firmas { display: grid; grid-template-columns: 1fr 1fr; gap: 48px; margin-top: 30px; }
.documento .firmas div { border-top: 1.5px solid var(--carbon); padding-top: 6px; text-align: center; font-size: .92rem; }
.columna-libre { min-width: 120px; }
.reportes { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 20px; align-items: start; }
.lista-reportes { display: grid; gap: 4px; position: sticky; top: 0; }
.lista-reportes button { text-align: left; border: 1.5px solid transparent; background: none; padding: 11px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; min-height: 46px; display: flex; gap: 10px; align-items: center; }
.lista-reportes button:hover { background: var(--fondo-3); }
.lista-reportes button[aria-current="true"] { background: var(--fondo-2); border-color: var(--carbon); }
#impresion { display: none; }

/* ---------- tablet ---------- */
@media (max-width: 1100px) {
  #app { grid-template-columns: var(--lateral-chica) minmax(0, 1fr); }
  #app .txt-nav, #app .lateral .marca .marca-txt, #app .lateral .pie .txt-pie { display: none; }
  #app .nav a { justify-content: center; padding-inline: 0; }
  #app .lateral .marca { justify-content: center; padding-inline: 8px; }
  #app .lateral .marca img { width: 48px; }
  #app .btn-lateral { justify-content: center; }
  .btn-colapsar { display: none !important; }
  #app.menu-abierto .lateral { position: fixed; inset: 0 auto 0 0; width: var(--lateral); z-index: 40; box-shadow: var(--sombra-panel); }
  #app.menu-abierto .txt-nav, #app.menu-abierto .lateral .marca .marca-txt, #app.menu-abierto .lateral .pie .txt-pie { display: initial; }
  #app.menu-abierto .nav a { justify-content: flex-start; padding-inline: 12px; }
  .barra-sup .btn-menu { display: inline-grid; }
  #vista { padding: 18px 20px 0; }
  /* migas compactas: solo el paso anterior y el actual */
  .migas { flex-wrap: nowrap; }
  .migas > a:not(.ultimo), .migas > .sep:not(.ultimo) { display: none; }
  .migas > a.ultimo { display: inline-flex; align-items: center; gap: 2px; max-width: 45%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .migas .volver-ico { display: inline; }
  .migas > .sep.ultimo { display: none; }
  .migas [aria-current] { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .migas [aria-current]::before { content: "/"; color: var(--acero); margin: 0 6px; }
  /* el presupuesto: la unidad va junto a la cantidad para que quepa la tabla */
  table.arbol .c-uni { width: 0; max-width: 0; padding: 0 !important; font-size: 0; overflow: hidden; }
  .uni-movil { display: inline; margin-left: 4px; color: var(--texto-2); }
  table.arbol td.c-desc { min-width: 150px; }
  table.arbol th, table.arbol td { padding-inline: 8px; }
  table.arbol td.c-desc { padding-left: calc(8px + var(--n, 0) * 14px); }
  table.arbol .codigo { display: none; }
  table.arbol .solo-ancho, table.arbol .txt-acciones { display: none; }
  table.arbol thead th { white-space: normal; }
  table.arbol .toggle { width: 28px; }
  table.arbol .sin-toggle { width: 28px; }
  table.arbol td.c-desc { min-width: 130px; }
  .celda-cant input { width: 96px; }
  .barra-totales .t.secundario { display: none; }
  .tabla-marco { overflow-x: auto; }
  .barra-totales { margin: 0 -20px; padding-inline: 20px; }
  .reportes { grid-template-columns: minmax(0, 1fr); }
  .lista-reportes { position: static; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  .ingreso .caja { grid-template-columns: 1fr; }
}

/* ---------- teléfono ---------- */
@media (max-width: 640px) {
  body { font-size: 17px; }
  #app, #app.colapsada { grid-template-columns: minmax(0, 1fr); }
  .lateral { display: none; }
  #app.menu-abierto .lateral { display: flex; width: min(300px, 86vw); }
  .barra-sup { padding: 8px 12px; gap: 8px; min-height: 56px; }
  .usuario .quien { display: none; }
  .migas { font-size: .9rem; }
  #vista { padding: 14px 14px 0; gap: 16px; }
  h1 { font-size: 1.4rem; }
  .barra-totales { margin: 0 -14px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .barra-totales .t:not(.base):not(.total) { display: none; }
  .migas > a.ultimo { max-width: none; font-size: 1.3rem; padding: 4px 8px; }
  .migas > a.ultimo .txt-miga { display: none; }
  .migas [aria-current]::before { display: none; }
  .doc-cab h1 { font-size: 1.3rem; }
  .doc-cab .antetitulo { display: none; }
  /* tablas que pasan a tarjetas en el celular */
  table.tarjetas thead { display: none; }
  table.tarjetas, table.tarjetas tbody, table.tarjetas tfoot { display: block; }
  table.tarjetas tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 10px; padding: 10px 12px; border-bottom: 1px solid var(--linea); }
  table.tarjetas td { display: block; padding: 0; border: 0 !important; text-align: left !important; }
  table.tarjetas td.ancha, table.tarjetas tr.encabezado-cat td, table.tarjetas tr.subtotal-cat td:first-child, table.tarjetas tfoot td:first-child { grid-column: 1 / -1; }
  table.tarjetas td[data-eti]::before { content: attr(data-eti); display: block; font-size: .85rem; color: var(--texto-2); font-weight: 600; }
  table.tarjetas td:empty { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .valor { font-size: 1.3rem; }
  .barra-totales .t.base, .barra-totales .t.total { flex: 1; min-width: 0; }
  .doc-cab { grid-template-columns: minmax(0, 1fr); padding: 14px; }
  .doc-cab .logo { display: none; }
  .btn { padding-inline: 14px; }
  .acciones .btn { flex: 1 1 auto; }
  .btn-icono { width: 44px; height: 44px; }
  /* el presupuesto pasa a tarjetas legibles */
  table.arbol thead, table.arbol .c-uni { display: none; }
  table.arbol, table.arbol tbody { display: block; }
  table.arbol tr { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 2px 10px; padding: 12px 12px; border-bottom: 1px solid var(--linea); align-items: center; }
  table.arbol td { display: block; padding: 0; border: 0 !important; background: none !important; }
  table.arbol tr.fila-titulo { background: #EFEFED; padding-left: calc(8px + var(--n, 0) * 10px); }
  table.arbol tr.fila-titulo.nivel-1 { box-shadow: inset 4px 0 0 var(--rojo); }
  table.arbol tr.fila-titulo td.c-desc { padding-left: 0; min-width: 0; }
  table.arbol tr.fila-titulo .conteo { display: none; }
  table.arbol tr.fila-titulo td.c-sub { grid-column: 3; }
  table.arbol tr.fila-titulo td.acciones-fila { grid-column: 1 / -1; }
  table.arbol tr.fila-partida { grid-template-columns: repeat(2, minmax(0, 1fr)); padding-left: calc(12px + var(--n, 0) * 10px); }
  table.arbol tr.fila-partida td.c-item { grid-column: 1; }
  table.arbol tr.fila-partida td.c-desc { grid-column: 1 / -1; min-width: 0; padding: 0 0 6px; }
  table.arbol tr.fila-partida td[data-eti]::before { content: attr(data-eti); display: block; font-size: .85rem; color: var(--texto-2); font-weight: 600; }
  table.arbol tr.fila-partida td.num { text-align: left; }
  table.arbol tr.fila-partida td.c-sub { font-weight: 700; }
  table.arbol tr.fila-partida td.acciones-fila { grid-column: 1 / -1; }
  table.arbol td.acciones-fila .acciones { justify-content: flex-start; }
  .celda-cant { justify-items: start; }
  .tabla-mat { display: none; }
  .tarjetas-mat { display: grid; gap: 10px; }
  .tarjeta-mat { border: 1px solid var(--linea); border-radius: 12px; padding: 14px; display: grid; gap: 6px; background: #fff; }
  .tarjeta-mat .cant-grande { font-size: 1.35rem; }
  dialog.capa-lateral { width: 100vw; border-radius: 0; }
  dialog.capa-modal { width: 100vw; max-height: 92dvh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .capa-cab, .capa-cuerpo, .capa-pie { padding-inline: 16px; }
  .documento { padding: 16px; }
  .documento .firmas { grid-template-columns: 1fr; }
  .ingreso { padding: 0; }
  .ingreso .caja { border-radius: 0; }
  .ingreso .lado-marca, .ingreso form { padding: 22px 18px; }
  .ingreso .lado-marca ol { display: none; }
}

/* ---------- impresión ---------- */
@media print {
  @page { size: letter; margin: 14mm 12mm; }
  body { font-size: 11pt; background: #fff; }
  #app, .toast-zona, dialog, .ingreso { display: none !important; }
  #impresion { display: block !important; }
  #impresion .documento { border: 0; padding: 0; border-radius: 0; }
  #impresion table { font-size: 9.5pt; }
  #impresion tr, #impresion .consideraciones, #impresion .resumen-doc, #impresion .firmas { break-inside: avoid; }
  #impresion thead { display: table-header-group; }
  #impresion thead th { background: #171717 !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #impresion tr.t1 td, #impresion tr.t2 td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .no-imprimir { display: none !important; }
}

/* ---------- agregado para la versión Django ---------- */
/* sangría del árbol con clases en vez de style="--n:..." (así no se necesitan estilos en línea) */
.n-0 { --n: 0; } .n-1 { --n: 1; } .n-2 { --n: 2; } .n-3 { --n: 3; } .n-4 { --n: 4; }
tr.oculta { display: none; }
.lateral .nav a.paso-sin-numero .ico { width: 24px; height: 24px; }
.btn-lateral.salir { width: 100%; }
form.en-linea { display: inline; margin: 0; }
.dialogo-caja { display: contents; }
.mt-0 { margin: 0; }
.acciones .derecha { margin-left: auto; }
.lista-problemas { list-style: none; margin: 0; padding: 0; }
.lista-problemas li { cursor: default; }
.eleccion.sangria-1 { margin-left: 18px; width: calc(100% - 18px); }
.eleccion.sangria-2 { margin-left: 36px; width: calc(100% - 36px); }
.eleccion.sangria-3 { margin-left: 54px; width: calc(100% - 54px); }
.chip.pendiente { background: var(--ambar-fondo); color: var(--ambar); }
.version-suave { font-weight: 600; font-size: 1.1rem; color: var(--texto-2); }
.pre { white-space: pre-line; }
.ancho-total { flex: 1 1 420px; }
.htmx-request .btn, .btn.htmx-request { opacity: .7; }
.error-pagina { max-width: 640px; margin: 10vh auto; padding: 24px; display: grid; gap: 16px; }
.dialogo-caja > form, .capa-caja > form { display: contents; }
.columna-reporte { display: grid; gap: 16px; min-width: 0; }
.lista-reportes a.btn { justify-content: flex-start; white-space: normal; text-align: left; }
.lista-reportes a[aria-current="true"] { background: var(--fondo-2); border-color: var(--carbon); }

/* ficha del proyecto: una tarjeta por etapa, con sus acciones a la derecha del título */
.tarjeta-cab { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; margin-bottom: .6rem; }
.tarjeta-cab h2 { margin: 0; }
.acciones-cab { display: flex; flex-wrap: wrap; gap: .4rem; }
.tarjeta.etapa-comun { border-style: dashed; }

/* cabeceras que ordenan */
table.ordenable th a.orden { color: inherit; text-decoration: none; cursor: pointer; white-space: nowrap; }
table.ordenable th a.orden:hover { text-decoration: underline; }
table.ordenable th[aria-sort="none"] a.orden span { opacity: .4; }

/* configuración */
.pestanas-config { display: flex; flex-wrap: wrap; gap: .25rem; border-bottom: 2px solid #d8dde3; margin-bottom: 1rem; }
.pestanas-config a { padding: .55rem 1rem; border-radius: .5rem .5rem 0 0; text-decoration: none; color: inherit; font-weight: 600; }
.pestanas-config a[aria-current="page"] { background: #1f4e79; color: #fff; }
.fila-editable { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .35rem 0; }
.dos-col-config { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 1rem; }
.oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.rojo { color: #A31515; }

/* color por categoría: franja a la izquierda de la fila, cabecera de grupo teñida y etiqueta.
   Los mismos colores en Recursos, Materiales, Control y Configuración. */
.cat-azul     { --cat: #2E6DA4; --cat-suave: #E3EEF8; }
.cat-ambar    { --cat: #C98A0B; --cat-suave: #FDF1D8; }
.cat-verde    { --cat: #2F8A4C; --cat-suave: #E2F3E7; }
.cat-violeta  { --cat: #6C4BB4; --cat-suave: #ECE6F7; }
.cat-gris     { --cat: #6B7480; --cat-suave: #EEF0F3; }
.cat-turquesa { --cat: #168A8A; --cat-suave: #DFF3F3; }
.cat-naranjo  { --cat: #C4571A; --cat-suave: #FBE7DC; }
.cat-rosado   { --cat: #B23A6F; --cat-suave: #F8E3EC; }
tr.fila-cat > td:first-child { box-shadow: inset 5px 0 0 var(--cat); }
tr.encabezado-cat[class*="cat-"] td { background: var(--cat-suave); color: #1d232b; border-bottom: 2px solid var(--cat); }
.chip-cat { display: inline-block; padding: .1rem .55rem; border-radius: 999px; background: var(--cat-suave);
  color: #1d232b; border: 1px solid var(--cat); font-size: .85rem; white-space: nowrap; }
/* filas alternadas: en listas largas el ojo no se salta de línea */
.tabla-marco tbody tr:nth-child(even):not(.encabezado-cat):not(.subtotal-cat) td { background-color: #FAFBFC; }
tr.precio-viejo td { background-color: #FFF6E5 !important; }
.acciones-pie { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-top: 1rem; }
.acciones-pie .separa { flex: 1; }
