:root {
  --tinta: #16202a;
  --tinta-2: #4a5763;
  --tinta-3: #6f7b86;
  --fondo: #f3f5f7;
  --superficie: #ffffff;
  --lateral: #e9edf1;
  --borde: #dde3e8;
  --borde-fuerte: #c9d1d8;
  --acento: #12324f;
  --acento-hover: #0b2238;
  --acento-suave: #e6edf4;
  --exito: #1d7a4c;
  --exito-suave: #e3f3ea;
  --alerta: #9a5a00;
  --alerta-suave: #fbf0dd;
  --error: #b02a22;
  --error-suave: #fbe7e5;
  --info: #2c5d87;
  --info-suave: #e5eef7;
  --radio-s: 6px;
  --radio-m: 10px;
  --radio-l: 14px;
  --sombra: 0 1px 2px rgba(22, 32, 42, .06), 0 4px 14px rgba(22, 32, 42, .06);
  --sombra-panel: -12px 0 40px rgba(22, 32, 42, .14);
  --fuente: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--fuente); color: var(--tinta); background: var(--fondo); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
::selection { background: var(--acento); color: #fff; }
:focus-visible { outline: 2px solid var(--acento); outline-offset: 2px; }
h1, h2, h3 { margin: 0; letter-spacing: -.015em; text-wrap: balance; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--tinta-3); }
.oculto { display: none !important; }

/* Estructura */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100dvh; }
.app > * { min-width: 0; }
.lateral { background: var(--lateral); border-right: 1px solid var(--borde); padding: 20px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100dvh; }
.marca { font-weight: 800; font-size: 15px; letter-spacing: -.02em; padding: 4px 10px 18px; }
.marca small { display: block; font-weight: 500; font-size: 12px; color: var(--tinta-3); letter-spacing: 0; }
.nav-btn { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; color: var(--tinta-2); font: inherit; font-weight: 600; padding: 9px 10px; border-radius: var(--radio-s); cursor: pointer; text-align: left; min-height: 38px; }
.nav-btn svg { width: 18px; height: 18px; flex: none; }
.nav-btn:hover { background: rgba(18, 50, 79, .06); color: var(--tinta); }
.nav-btn[aria-current="page"] { background: var(--superficie); color: var(--acento); box-shadow: var(--sombra); }
.lateral .pie { margin-top: auto; font-size: 12px; color: var(--tinta-3); padding: 0 10px; }
.contenido { padding: 26px 32px 60px; max-width: 1360px; width: 100%; }
.cabecera { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.cabecera p { margin: 4px 0 0; color: var(--tinta-3); }

/* Botones */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600; border-radius: var(--radio-s); border: 1px solid var(--borde-fuerte); background: var(--superficie); color: var(--tinta); padding: 8px 14px; min-height: 38px; cursor: pointer; transition: background .15s ease-out, border-color .15s ease-out; white-space: nowrap; }
.btn:hover { border-color: var(--tinta-3); }
.btn svg { width: 16px; height: 16px; }
.btn-primario { background: var(--acento); border-color: var(--acento); color: #fff; }
.btn-primario:hover { background: var(--acento-hover); border-color: var(--acento-hover); }
.btn-peligro { color: var(--error); }
.btn-peligro:hover { border-color: var(--error); }
.btn-chico { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.cargando { pointer-events: none; opacity: .7; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 22px; }
.kpi { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio-m); padding: 14px 16px; }
.kpi .etq { color: var(--tinta-3); font-size: 12.5px; font-weight: 600; }
.kpi .valor { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .ctx { font-size: 12.5px; color: var(--tinta-3); margin-top: 2px; }
.kpi.alerta .valor { color: var(--alerta); }
.kpi.error .valor { color: var(--error); }

/* Tarjetas y tablas */
.tarjeta { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio-l); overflow: hidden; }
.tarjeta-cab { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--borde); flex-wrap: wrap; }
.tabla-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 700; color: var(--tinta-3); padding: 10px 16px; border-bottom: 1px solid var(--borde); background: #fafbfc; white-space: nowrap; position: sticky; top: 0; }
td { padding: 11px 16px; border-bottom: 1px solid #edf0f3; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.clic { cursor: pointer; }
tbody tr.clic:hover td { background: #f7f9fb; }
td.der, th.der { text-align: right; }
td .sub { display: block; font-size: 12px; color: var(--tinta-3); }
.vacio { padding: 36px 16px; text-align: center; color: var(--tinta-3); }
.vacio b { display: block; color: var(--tinta); margin-bottom: 4px; }

/* Insignias */
.ins { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.ins::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.ins-ok { background: var(--exito-suave); color: var(--exito); }
.ins-alerta { background: var(--alerta-suave); color: var(--alerta); }
.ins-error { background: var(--error-suave); color: var(--error); }
.ins-info { background: var(--info-suave); color: var(--info); }
.ins-neutro { background: #eef1f4; color: var(--tinta-2); }

/* Filtros */
.filtros { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip { white-space: nowrap; flex: none; font: inherit; font-size: 13px; font-weight: 600; border: 1px solid var(--borde); background: var(--superficie); color: var(--tinta-2); border-radius: 999px; padding: 5px 12px; cursor: pointer; min-height: 32px; }
.chip[aria-pressed="true"] { background: var(--acento); border-color: var(--acento); color: #fff; }
.buscar { font: inherit; border: 1px solid var(--borde-fuerte); border-radius: var(--radio-s); padding: 8px 12px; min-width: 240px; min-height: 38px; background: var(--superficie); }

/* Formularios */
label.campo { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 700; color: var(--tinta-2); }
label.campo input, label.campo select, label.campo textarea { min-width: 0; width: 100%; font: inherit; font-weight: 500; font-size: 14px; color: var(--tinta); border: 1px solid var(--borde-fuerte); border-radius: var(--radio-s); padding: 9px 11px; background: #fff; min-height: 40px; }
label.campo textarea { min-height: 70px; resize: vertical; }
label.campo .ayuda { font-weight: 500; color: var(--tinta-3); font-size: 12px; }
.rejilla { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.rejilla .ancho { grid-column: 1 / -1; }
.interruptor { display: flex; align-items: flex-start; gap: 12px; padding: 12px; border: 1px solid var(--borde); border-radius: var(--radio-m); cursor: pointer; }
.interruptor input { width: 38px; height: 22px; appearance: none; background: var(--borde-fuerte); border-radius: 999px; position: relative; flex: none; cursor: pointer; transition: background .15s ease-out; margin: 1px 0 0; }
.interruptor input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .18s ease-out; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.interruptor input:checked { background: var(--exito); }
.interruptor input:checked::after { transform: translateX(16px); }
.interruptor b { display: block; font-size: 14px; }
.interruptor span { font-size: 12.5px; color: var(--tinta-3); }

/* Panel lateral de detalle */
.velo { position: fixed; inset: 0; background: rgba(22, 32, 42, .32); z-index: 20; }
.cajon { position: fixed; top: 0; right: 0; height: 100dvh; width: min(620px, 100%); background: var(--fondo); z-index: 21; box-shadow: var(--sombra-panel); display: flex; flex-direction: column; animation: entrar .22s cubic-bezier(.16, 1, .3, 1); }
@keyframes entrar { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.cajon-cab { padding: 18px 22px; background: var(--superficie); border-bottom: 1px solid var(--borde); display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.cajon-cuerpo { padding: 18px 22px 40px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.bloque { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio-m); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.acciones { display: flex; gap: 8px; flex-wrap: wrap; }
.linea-evento { display: grid; grid-template-columns: 112px 1fr; gap: 10px; font-size: 13px; padding: 7px 0; border-bottom: 1px solid #edf0f3; }
.linea-evento:last-child { border-bottom: 0; }
.copiar { display: flex; gap: 8px; }
.copiar input { flex: 1; font: inherit; font-size: 13px; border: 1px solid var(--borde-fuerte); border-radius: var(--radio-s); padding: 8px 10px; background: #fafbfc; min-width: 0; }

/* Ajustes */
.checks { display: grid; gap: 8px; }
.check { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid #edf0f3; }
.check:last-child { border-bottom: 0; }
.dos-col { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; align-items: start; }
code { font-size: 12.5px; background: #eef1f4; padding: 2px 6px; border-radius: 4px; }
.skeleton { height: 14px; border-radius: 4px; background: linear-gradient(90deg, #eef1f4, #f6f8fa, #eef1f4); background-size: 200% 100%; animation: brillo 1.2s infinite; }
@keyframes brillo { to { background-position: -200% 0; } }

/* Aviso flotante */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--tinta); color: #fff; padding: 11px 16px; border-radius: var(--radio-m); font-weight: 600; z-index: 40; box-shadow: var(--sombra); max-width: calc(100% - 32px); }
.toast.error { background: var(--error); }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio-l); padding: 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 16px; box-shadow: var(--sombra); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .lateral { position: sticky; z-index: 10; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px; gap: 4px; }
  .tarjeta-cab .filtros { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 2px; }
  .cajon-cuerpo { padding: 14px 14px 40px; }
  .marca, .lateral .pie { display: none; }
  .nav-btn { width: auto; }
  .contenido { padding: 18px 16px 60px; }
  .dos-col, .rejilla { grid-template-columns: minmax(0, 1fr); }
  .buscar { min-width: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Servicios por cliente */
.linea-servicio { display: grid; grid-template-columns: minmax(0, 1fr) 150px auto; gap: 8px; align-items: center; }
.linea-servicio select, .linea-servicio input { font: inherit; font-size: 14px; border: 1px solid var(--borde-fuerte); border-radius: var(--radio-s); padding: 8px 10px; min-height: 40px; background: #fff; min-width: 0; width: 100%; }
.linea-servicio input { text-align: right; }
#ed-servicios, #ed-lineas { display: flex; flex-direction: column; gap: 8px; }
.linea-total { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding-top: 6px; border-top: 1px solid #edf0f3; }
.linea-total b { font-size: 16px; margin-left: 6px; }
.aviso-alerta { background: var(--alerta-suave); color: var(--alerta); padding: 9px 12px; border-radius: var(--radio-s); font-weight: 600; font-size: 13px; }
.cmp-factura { border: 1px solid var(--borde); border-radius: var(--radio-m); padding: 12px; display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.cmp-cab { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.cmp-cab a { margin-left: auto; color: var(--acento); font-weight: 600; }
.cmp-linea { display: flex; justify-content: space-between; gap: 10px; color: var(--tinta-2); }
.cmp-factura .btn { align-self: flex-start; margin-top: 4px; }
@media (max-width: 520px) { .linea-servicio { grid-template-columns: minmax(0, 1fr) 110px; } .linea-servicio .quitar { grid-column: 1 / -1; justify-self: end; } }
