:root {
  --fondo: #f3f5fa;
  --superficie: #ffffff;
  --texto: #1d2330;
  --tenue: #5f6b7a;
  --borde: #d9dee5;
  --primario: #012269;
  --primario-oscuro: #00154a;
  --exito: #1e7a46;
  --alerta: #9a6200;
  --error: #b3261e;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px; color: var(--texto); background: var(--fondo); line-height: 1.45; }
a { color: var(--primario); }
h1 { font-size: clamp(1.6rem, 3vw, 2rem); line-height: 1.2; letter-spacing: -.035em; margin: 0 0 .4rem; color: var(--primario-oscuro); }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
.tenue { color: var(--tenue); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Barra superior */
.barra { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.75rem; padding: .7rem max(20px, calc((100vw - 1280px) / 2)); background: var(--superficie); border-bottom: 1px solid var(--borde); box-shadow: 0 3px 18px #01226906; }
.marca { font-weight: 700; letter-spacing: .04em; text-decoration: none; color: var(--texto); }
.marca img { display: block; width: 128px; height: 72px; object-fit: contain; }
.menu { display: flex; flex-wrap: wrap; gap: .25rem .9rem; align-items: center; }
.menu a { text-decoration: none; }
.menu > a, .grupo summary { padding: .65rem .45rem; border-radius: 7px; font-weight: 550; }
.menu a[aria-current=page], .grupo-activo > summary { color: var(--primario); background: #eaf0fb; }
.grupo { position: relative; }
.grupo summary { cursor: pointer; color: var(--primario); list-style: none; }
.grupo summary::-webkit-details-marker { display: none; }
.grupo summary::after { content: ' ▾'; font-size: .8em; }
.submenu { position: absolute; top: 100%; left: -.6rem; z-index: 10; min-width: 240px; display: flex; flex-direction: column;
  background: var(--superficie); border: 1px solid var(--borde); border-radius: 8px; padding: .35rem 0; box-shadow: 0 6px 18px rgba(0,0,0,.08); }
.submenu a { padding: .4rem .9rem; }
.submenu a:hover { background: #eef1f5; }
.menu-toggle, .menu-boton { display: none; }
.salir { margin: 0; }
.enlace { background: none; border: 0; padding: 0; color: var(--tenue); font: inherit; cursor: pointer; }

.contenido { max-width: 1280px; margin: 0 auto; padding: 2rem 24px 3rem; min-height: calc(100vh - 180px); }

/* Encabezado de página */
.encabezado { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: .75rem; margin-bottom: 1rem; }
.acciones { display: flex; flex-wrap: wrap; gap: .5rem; }

/* Botones */
.boton, .boton-sec { display: inline-flex; justify-content: center; align-items: center; min-height: 42px; padding: .6rem 1rem; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; border: 1px solid var(--primario); }
.boton { background: var(--primario); color: #fff; }
.boton:hover { background: var(--primario-oscuro); }
.boton-sec { background: var(--superficie); color: var(--primario); }

/* Tarjetas */
.tarjeta { background: var(--superficie); border: 1px solid var(--borde); border-radius: 12px; padding: 1.25rem; box-shadow: 0 3px 12px #01226904; }
.login { max-width: 440px; margin: 3rem auto; padding: 2rem; border-top: 4px solid var(--primario); }
.logo-login { display: block; max-width: 100%; object-fit: contain; margin: 0 auto 1.75rem; }
.login h1 { font-size: 1.65rem; }
.login .campo { margin-bottom: 1rem; }
.login .boton { width: 100%; margin-top: .25rem; }
.login > .ayuda { font-size: .85rem; margin-bottom: 0; }
.indicadores { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; }
.indicador { text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s; }
.indicador:hover { border-color: #8ca6d4; box-shadow: 0 5px 18px #0122690d; }
.indicador .valor { font-size: 1.8rem; font-weight: 600; }
.indicador-alerta { border-color: #ecd6a6; background: #fdf6e7; }
.estado-borrador.estado, .estado-pendiente { background: #eceef1; color: var(--tenue); }
.estado-confirmada, .estado-recibida { background: #e5f4ea; color: var(--exito); }
.estado-anulada { background: #fbe9e8; color: var(--error); }

/* Filtros */
.filtros { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.filtros input[type=search] { flex: 1 1 220px; }

/* Formularios */
input[type=text], input[type=search], input[type=email], input[type=url], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; min-height: 42px; padding: .6rem .7rem; border: 1px solid #bec8d8; border-radius: 8px; font: inherit; background: #fff; color: var(--texto);
}
.filtros input, .filtros select { width: auto; max-width: 100%; }
.campos { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .9rem 1rem; margin-bottom: 1rem; }
.campo { display: flex; flex-direction: column; gap: .2rem; }
.campo label { font-weight: 500; }
.campo-check { justify-content: center; }
.campo-check label { font-weight: 400; display: flex; gap: .4rem; align-items: center; }
.campo-ancho { grid-column: 1 / -1; }
.ayuda { color: var(--tenue); font-size: .85rem; line-height: 1.5; }
.error { color: var(--error); }
.con-error input, .con-error select { border-color: var(--error); }

/* Tablas */
.tabla-envoltura { overflow-x: auto; background: var(--superficie); border: 1px solid var(--borde); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .75rem .85rem; border-bottom: 1px solid var(--borde); text-align: left; vertical-align: top; }
th { font-size: .82rem; font-weight: 650; color: #43516c; background: #edf1f8; white-space: nowrap; }
tbody tr:hover { background: #f8faff; }
tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 600; background: #f8f9fb; }
.vacio { text-align: center; color: var(--tenue); padding: 1.5rem; }

.etiqueta { display: inline-block; padding: .05rem .45rem; border-radius: 999px; font-size: .8rem; background: #e7eef8; color: var(--primario-oscuro); margin: 0 .2rem .2rem 0; }
.etiqueta-gris { background: #eceef1; color: var(--tenue); }
.estado { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 500; background: #eceef1; color: var(--tenue); vertical-align: middle; }
.estado-enviado, .estado-confirmado, .estado-parcial { background: #e7eef8; color: var(--primario); }
.estado-aceptado, .estado-entregado, .estado-cerrado { background: #e5f4ea; color: var(--exito); }
.estado-vencido { background: #fdf3df; color: var(--alerta); }
.estado-cancelado { background: #fbe9e8; color: var(--error); }
.acciones form { margin: 0; }
.boton-peligro { color: var(--error); border-color: #e3b2ae; }
.totales { max-width: 420px; margin: 1rem 0 0 auto; }
.totales .detalle { grid-template-columns: 1fr max-content; }
.tabla-lineas select { min-width: 220px; }
.tabla-lineas input { min-width: 90px; }
.descuento { color: var(--exito); }
.recargo { color: var(--alerta); }

/* Avisos */
.aviso { padding: .6rem .8rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid var(--borde); background: var(--superficie); }
.aviso-success { border-color: #b7dec6; background: #eef8f1; }
.aviso-error { border-color: #efc0bc; background: #fdf0ef; color: var(--error); }
.aviso-warning { border-color: #ecd6a6; background: #fdf6e7; color: #6b4500; }
.aviso-info { border-color: #cad8f1; background: #edf3ff; color: #193b75; }
.estado-rechazado { background: #fbe9e8; color: var(--error); }

/* Orientación y accesos para el trabajo diario */
:focus-visible { outline: 3px solid #4b7fd4; outline-offset: 3px; }
input:focus, select:focus, textarea:focus { border-color: #4b7fd4; }
.saltar { position: absolute; top: -80px; left: 16px; z-index: 100; background: white; padding: .8rem; }
.saltar:focus { top: 8px; }
.sobre-titulo { color: var(--primario); text-transform: uppercase; letter-spacing: .12em; font-size: .7rem; font-weight: 750; margin: 0 0 .5rem; }
.encabezado p { margin-bottom: 0; max-width: 800px; }
.inicio-rapido { display: grid; grid-template-columns: 1fr 2fr; gap: 2rem; padding: 1.75rem; margin: 1.5rem 0 2rem; border: 1px solid #ccd9ef; border-radius: 16px; background: linear-gradient(120deg, #e8effc, #f9fbff); }
.inicio-rapido h2 { font-size: 1.45rem; letter-spacing: -.025em; margin-top: 0; }
.inicio-rapido p { color: #4c5f7e; }
.inicio-rapido > div > a { font-size: .88rem; }
.accesos-rapidos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; }
.accesos-rapidos a { display: flex; flex-direction: column; gap: .65rem; padding: 1.1rem; border: 1px solid #d6dfed; border-radius: 12px; background: white; text-decoration: none; }
.accesos-rapidos a:hover { border-color: var(--primario); box-shadow: 0 4px 12px #0122690d; }
.accesos-rapidos a > span:last-child { color: var(--tenue); font-size: .85rem; }
.paso-icono { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: #eaf0fc; color: var(--primario); font-size: .75rem; font-weight: 750; }
.encabezado-seccion h2 { margin: 0; }
.nota-formulario { color: var(--tenue); font-size: .83rem; margin: 0 0 1rem; }
.guia { margin-bottom: 1.25rem; }
.guia h2 { margin-top: 0; }
.pasos { padding-left: 1.5rem; margin-bottom: 0; }
.pasos li { padding: .4rem 0 .8rem .5rem; max-width: 950px; }
.pasos li::marker { color: var(--primario); font-weight: 700; }
.guia-columnas { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.glosario dt { font-weight: 650; color: var(--primario); margin-top: 1rem; }
.glosario dd { margin: .25rem 0 0; color: var(--tenue); }
.guia details { border-top: 1px solid var(--borde); padding: 1rem 0; }
.guia summary { cursor: pointer; font-weight: 600; color: var(--primario); }
.pie-app { max-width: 1280px; margin: auto; padding: 1.25rem 24px; border-top: 1px solid var(--borde); display: flex; justify-content: space-between; gap: 1rem; color: var(--tenue); font-size: .82rem; }

.paginacion { display: flex; gap: 1rem; justify-content: center; margin-top: 1rem; }
.detalle { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.detalle dt { color: var(--tenue); }
.detalle dd { margin: 0; }

@media (max-width: 760px) {
  .indicadores { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .contenido { padding: 1.25rem 16px 2rem; }
  .barra { padding: .5rem 16px; }
  .marca img { width: 100px; height: 56px; }
  .inicio-rapido { grid-template-columns: 1fr; gap: 1.2rem; padding: 1.25rem; }
  .accesos-rapidos { grid-template-columns: 1fr; }
  .accesos-rapidos a { gap: .4rem; }
  .guia-columnas { grid-template-columns: 1fr; }
  .login { margin: 1rem auto; padding: 1.5rem; }
  .campos { grid-template-columns: minmax(0, 1fr); }
  input, select, textarea { font-size: 16px !important; }
  .menu-toggle { display: block; position: absolute; opacity: 0; width: 1px; height: 1px; }
  .menu-toggle:focus-visible + .menu-boton { outline: 3px solid #4b7fd4; outline-offset: 3px; }
  .menu-boton { display: inline-block; margin-left: auto; cursor: pointer; padding: .3rem .6rem; border: 1px solid var(--borde); border-radius: 6px; }
  .menu { display: none; width: 100%; flex-direction: column; align-items: flex-start; }
  .menu-toggle:checked ~ .menu { display: flex; }
  .submenu { position: static; box-shadow: none; border: 0; padding: .2rem 0 .2rem .8rem; min-width: 0; }
  .submenu a { padding: .25rem 0; }
  .detalle:not(.totales .detalle) { grid-template-columns: 1fr; }
  .detalle dd { margin-bottom: .4rem; }
}

@media print {
  .barra, .pie-app, .saltar, .inicio-rapido, .acciones { display: none; }
  body { background: white; }
  .contenido { padding: 0; max-width: none; }
  .tarjeta { box-shadow: none; }
}

/* Ventanita de alta rápida (presupuesto) */
.ventanita { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); border: 1px solid var(--borde); border-radius: 8px; padding: 1rem; background: var(--superficie); color: var(--texto); }
.ventanita::backdrop { background: rgba(0,0,0,.35); }
.ventanita h2 { margin-top: 0; }
.alta-enlace { display: block; margin-top: .25rem; font-size: .85rem; }

/* Cotización guiada: totales y margen internos siempre a mano. */
.cotizacion-viva { position: sticky; bottom: 12px; z-index: 5; display: grid; grid-template-columns: 1fr 1fr 1.25fr; gap: 1rem; padding: 1rem; margin-top: 1rem; background: #fff; border: 1px solid #c7d5ec; border-radius: 12px; box-shadow: 0 6px 28px #0122691c; }
.simulacion-pago { display: grid; gap: .3rem; font-size: .82rem; }
.totales-vivos { display: flex; flex-direction: column; justify-content: center; gap: .4rem; }
.totales-vivos span { display: flex; justify-content: space-between; gap: 1rem; }
.gran-total { padding-top: .5rem; border-top: 1px solid var(--borde); font-size: 1.2rem; }
.panel-margen { border: 1px solid var(--borde); border-radius: 9px; padding: 1rem; margin: 1rem 0; }
.cotizacion-viva .panel-margen { margin: 0; }
.panel-margen h2 { margin: 0 0 .5rem; }
.panel-margen p:last-child { margin-bottom: 0; }
#vivo-ganancia { font-size: 1.45rem; font-weight: 750; margin-top: .5rem; }
#vivo-aviso { font-size: .8rem; }
.margen-verde { color: #146039; background: #ecf8f0; border-color: #b0d9bd; }
.margen-amarillo { color: #775100; background: #fff7dc; border-color: #e7d59b; }
.margen-rojo { color: #9e2620; background: #fff0ee; border-color: #e5b6b2; }
.margen-sin-costo, .margen-sin-umbrales { background: #f2f5fa; color: #465571; }
.producto-celda { position: relative; min-width: 240px; }
.producto-celda .dato-producto { display: block; margin: .35rem 0; }
.sugerencias { position: relative; z-index: 15; width: 100%; max-height: 260px; overflow: auto; border: 1px solid #b9c8e1; border-radius: 8px; background: white; box-shadow: 0 5px 16px #01226924; }
.sugerencias button { display: block; width: 100%; padding: .8rem; text-align: left; border: 0; border-bottom: 1px solid var(--borde); background: white; color: var(--primario); font: inherit; cursor: pointer; }
.sugerencias button:hover, .sugerencias button:focus { background: #edf3ff; }
.tabla-presupuesto td { min-width: 105px; }
.tabla-presupuesto .margen-linea { white-space: normal; min-width: 145px; }
.modo-precio { display: block; margin: .2rem 0; }
.volver-lista { font-size: .78rem; text-decoration: underline; }
.seguimiento { display: flex; flex-wrap: wrap; gap: .3rem; margin: .5rem 0; }
.estado-facturado, .estado-cobrado { background: #e5f4ea; color: var(--exito); }
.resumen-movil { display: none; }
@media (max-width: 760px) {
  body:has(.resumen-movil) { padding-bottom: 140px; }
  .resumen-movil { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; flex-direction: column; gap: .3rem; padding: .8rem 1rem; border-top: 2px solid #b9c8e1; background: #f2f5fa; box-shadow: 0 -4px 18px #01226918; font-size: .85rem; }
  .resumen-movil span { display: flex; justify-content: space-between; gap: .5rem; }
  .cotizacion-viva { position: static; grid-template-columns: 1fr; padding: .8rem; }
  .tabla-presupuesto, .tabla-presupuesto tbody { display: block; }
  .tabla-presupuesto thead { display: none; }
  .tabla-presupuesto .fila-linea { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 0; border-bottom: 3px solid #d9e3f4; }
  .tabla-presupuesto td { display: block; min-width: 0; }
  .tabla-presupuesto td::before { content: attr(data-etiqueta); display: block; font-size: .75rem; color: var(--tenue); font-weight: 600; margin-bottom: .3rem; }
  .tabla-presupuesto .producto-celda, .tabla-presupuesto .margen-linea { grid-column: 1 / -1; }
  .tabla-presupuesto input, .tabla-presupuesto select { min-width: 0; }
  .tabla-presupuesto .num { text-align: left; white-space: normal; }
  .sugerencias { width: 100%; }
}
@media print { .cotizacion-viva, .panel-margen, .margen-linea, .resumen-movil { display: none !important; } }
/* Operación táctil: formularios sin desbordar la pantalla y tablas desplazables. */
@media (max-width: 760px) {
  .contenido, .tarjeta, .campos, .campo, .encabezado > div { min-width: 0; max-width: 100%; }
  input, select, textarea { max-width: 100%; font-size: 16px; }
  .boton, .boton-sec, button, summary { min-height: 44px; }
  .acciones { flex-wrap: wrap; }
  .filtros { display: flex; flex-direction: column; align-items: stretch; }
  .filtros input[type=search] { flex: none; }
  .filtros > *, .filtros label { width: 100%; }
  .tabla-envoltura { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
  .tabla-envoltura th a { display: inline-flex; min-height: 44px; align-items: center; }
  .detalle { overflow-wrap: anywhere; }
  canvas { display: block; }
}

/* Selector de productos fuera del ancho de la celda. */
.sugerencias:not([hidden]) { position: fixed; left: 2vw; right: 2vw; bottom: 3vh; width: auto; max-height: 45vh; z-index: 1000; }
.tabla-presupuesto td { padding-top: .45rem; padding-bottom: .45rem; }
.busqueda-global { display:flex; gap:.6rem; align-items:end; padding:.5rem max(1rem,5vw); background:#edf2fa; }
.busqueda-global label { flex:1; } .busqueda-global input { width:100%; }
.financiacion-presupuesto { margin:1.25rem 0; }
.planes-presupuesto { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:.75rem; }
.planes-presupuesto p { margin:0; padding:1rem; background:#eef3fb; border-radius:9px; color:var(--primario); }
.planes-presupuesto strong { display:block; font-size:1.2rem; }
@media(max-width:480px) { .planes-presupuesto { grid-template-columns:1fr; } }
.guardar-movil { display:none; }
.ventanita { width:min(650px,94vw); max-height:90vh; overflow:auto; border:1px solid var(--borde); border-radius:14px; padding:1.25rem; }
.ventanita::backdrop { background:#001c465e; }
@media(max-width:760px) {
  .tabla-tarjetas, .tabla-tarjetas tbody { display:block; width:100%; }
  .tabla-tarjetas thead { display:none; }
  .tabla-tarjetas tbody tr { display:block; margin:.7rem 0; border:1px solid var(--borde); border-radius:12px; background:white; padding:.5rem; }
  .tabla-tarjetas tbody td { display:grid; grid-template-columns:36% minmax(0,1fr); align-items:start; gap:.4rem; border:0; width:auto; padding:.4rem; white-space:normal; overflow-wrap:anywhere; text-align:right; }
  .tabla-tarjetas tbody td > * { grid-column:2; justify-self:end; }
  .tabla-tarjetas tbody td::before { content:attr(data-etiqueta); text-align:left; font-weight:600; color:var(--tenue); }
  .tabla-tarjetas td.num { font-size:1.15rem; font-weight:600; }
  .guardar-movil { display:flex; position:fixed; left:0; right:0; bottom:0; z-index:60; justify-content:space-between; align-items:center; gap:.5rem; background:white; border-top:1px solid var(--borde); padding:.55rem 1rem; }
  body:has(.guardar-movil) { padding-bottom:150px; }
  body:has(.guardar-movil) .resumen-movil { bottom:67px; }
  .busqueda-global { padding:.5rem; } .busqueda-global input { min-width:0; }
}
