:root {
  --azul-900: #0A2A55;
  --azul-800: #0B3B75;
  --azul-700: #12509B;
  --azul-600: #1A63BD;
  --azul-500: #2B7BDB;
  --azul-100: #E3EEFB;
  --azul-50: #F2F7FD;
  --fondo: #EEF2F7;
  --panel: #FFFFFF;
  --borde: #D8E0EA;
  --borde-suave: #E7ECF2;
  --texto: #1B2838;
  --texto-2: #4E5D70;
  --texto-3: #7A8799;
  --ok: #157A4A;
  --ok-bg: #E4F4EC;
  --alerta: #9A6200;
  --alerta-bg: #FCF1DC;
  --error: #B42318;
  --error-bg: #FDECEA;
  --radio: 8px;
  --sombra: 0 1px 2px rgba(16, 38, 70, .06), 0 2px 8px rgba(16, 38, 70, .05);
  --fuente: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--fuente); font-size: 14px; color: var(--texto); background: var(--fondo); -webkit-font-smoothing: antialiased; }
a { color: var(--azul-600); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
small, .muted { color: var(--texto-3); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.hidden { display: none !important; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-brand { background: linear-gradient(160deg, var(--azul-900), var(--azul-700)); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.login-brand .marca { font-size: 22px; font-weight: 700; letter-spacing: .02em; }
.login-brand .marca span { color: #8EC1FF; font-weight: 500; }
.login-brand h2 { font-size: 30px; line-height: 1.25; max-width: 460px; font-weight: 600; }
.login-brand ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; color: #D4E5FA; }
.login-brand li { display: flex; gap: 10px; align-items: center; }
.login-brand li::before { content: ""; width: 6px; height: 6px; background: #8EC1FF; border-radius: 50%; }
.login-form { display: flex; align-items: center; justify-content: center; padding: 32px; background: var(--panel); }
.login-form form { width: 100%; max-width: 360px; display: grid; gap: 16px; }
.login-form h1 { margin-bottom: 4px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100%; }
.side { background: var(--azul-900); color: #C8D8EE; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side .logo { padding: 20px 20px 16px; font-weight: 700; color: #fff; font-size: 17px; border-bottom: 1px solid rgba(255,255,255,.08); }
.side .logo span { color: #8EC1FF; font-weight: 500; }
.side nav { padding: 12px 10px; display: grid; gap: 2px; overflow-y: auto; }
.side nav .grupo { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7E97B8; padding: 14px 12px 6px; }
.side nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 6px; color: #C8D8EE; font-weight: 500; }
.side nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.side nav a.activo { background: var(--azul-700); color: #fff; }
.side .pie { margin-top: auto; padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.side .pie b { color: #fff; display: block; font-size: 13px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { height: 60px; background: var(--panel); border-bottom: 1px solid var(--borde); display: flex; align-items: center; gap: 14px; padding: 0 24px; position: sticky; top: 0; z-index: 20; }
.top .empresa { font-weight: 600; }
.top .empresa small { display: block; font-weight: 400; }
.top .der { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.btn.menu-btn { display: none; }
.contenido { padding: 24px; max-width: 1280px; width: 100%; }
.cabecera { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.cabecera .acciones { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.banda { padding: 10px 24px; font-size: 13px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid; }
.banda.info { background: var(--azul-50); color: var(--azul-800); border-color: var(--azul-100); }
.banda.alerta { background: var(--alerta-bg); color: var(--alerta); border-color: #F2DDB0; }
.banda.error { background: var(--error-bg); color: var(--error); border-color: #F5C6C1; }
.banda button { margin-left: auto; }

/* ---------- componentes ---------- */
.card { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); box-shadow: var(--sombra); }
.card > .hd { padding: 14px 18px; border-bottom: 1px solid var(--borde-suave); display: flex; align-items: center; gap: 10px; }
.card > .hd .acciones { margin-left: auto; display: flex; gap: 8px; }
.card > .bd { padding: 18px; }
.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-fac { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }

.kpi { padding: 16px 18px; }
.kpi .et { color: var(--texto-2); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.kpi .val { font-size: 24px; font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--texto-3); margin-top: 4px; }
.kpi .sub .up { color: var(--ok); } .kpi .sub .down { color: var(--error); }
.kpi .ico { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; background: var(--azul-100); color: var(--azul-700); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--borde); background: var(--panel); color: var(--texto); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--azul-50); border-color: #C2D1E3; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.prim { background: var(--azul-700); color: #fff; border-color: var(--azul-700); }
.btn.prim:hover { background: var(--azul-800); }
.btn.peligro { color: var(--error); }
.btn.peligro:hover { background: var(--error-bg); border-color: #F0B9B3; }
.btn.chico { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icono { width: 32px; padding: 0; height: 32px; }
.btn.grande { height: 44px; font-size: 15px; padding: 0 20px; }
.btn.bloque { width: 100%; }
.btn-link { background: none; border: 0; padding: 0; color: var(--azul-600); font: inherit; cursor: pointer; }

label.campo { display: grid; gap: 5px; font-size: 13px; color: var(--texto-2); font-weight: 500; }
input, select, textarea { font: inherit; color: var(--texto); background: #fff; border: 1px solid var(--borde); border-radius: 6px; height: 36px; padding: 0 10px; width: 100%; min-width: 0; }
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--azul-500); box-shadow: 0 0 0 3px rgba(43, 123, 219, .15); }
input[readonly] { background: var(--azul-50); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { width: 16px; height: 16px; }
.fila { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.fila > * { flex: 1; min-width: 140px; }
.ayuda { font-size: 12px; color: var(--texto-3); font-weight: 400; }

.tabla-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--texto-2); text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; background: var(--azul-50); border-bottom: 1px solid var(--borde); white-space: nowrap; }
table.t td { padding: 10px 14px; border-bottom: 1px solid var(--borde-suave); vertical-align: middle; }
table.t tbody tr:hover { background: #FAFCFE; }
table.t tr.clic { cursor: pointer; }
table.t .vacio { text-align: center; color: var(--texto-3); padding: 36px; }

table.t.items td, table.t.items th { padding: 6px 4px; }
table.t.items th:first-child, table.t.items td:first-child { padding-left: 14px; }
table.t.items th:last-child, table.t.items td:last-child { padding-right: 12px; }
.items input, .items select { height: 32px; }
.items { table-layout: fixed; min-width: 640px; }
.items input, .items select { padding: 0 7px; width: 100%; }
.items .w-chk { width: 40px; }
.items .w-cod { width: 76px; }
.items .w-cant, .items .w-desc { width: 70px; }
.items .w-pre { width: 88px; }
.items .w-iva { width: 92px; }
.items .w-tot { width: 80px; }
.items .w-del { width: 52px; }

.estado { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.estado::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.e-AUTORIZADO { background: var(--ok-bg); color: var(--ok); }
.e-ENVIADO, .e-PENDIENTE { background: var(--azul-100); color: var(--azul-700); }
.e-DEVUELTA, .e-NO.AUTORIZADO, .e-ERROR, .e-NO_AUTORIZADO { background: var(--error-bg); color: var(--error); }
.e-ANULADO { background: #ECEFF3; color: var(--texto-2); }
.e-ACTIVA { background: var(--ok-bg); color: var(--ok); }
.e-SUSPENDIDA { background: var(--error-bg); color: var(--error); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; background: var(--azul-100); color: var(--azul-800); letter-spacing: .02em; }
.tag.gris { background: #ECEFF3; color: var(--texto-2); }
.tag.alerta { background: var(--alerta-bg); color: var(--alerta); }

.totales { display: grid; gap: 0; }
.totales div { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--borde-suave); font-variant-numeric: tabular-nums; }
.totales .gran { border: 0; margin-top: 8px; padding: 12px 14px; background: var(--azul-800); color: #fff; border-radius: 6px; font-size: 18px; font-weight: 650; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--borde); margin-bottom: 18px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 14px; font: inherit; color: var(--texto-2); cursor: pointer; font-weight: 550; white-space: nowrap; }
.tabs button.activo { color: var(--azul-700); border-color: var(--azul-700); }

.lista-sug { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; margin-top: 4px; background: #fff; border: 1px solid var(--borde); border-radius: 6px; box-shadow: 0 8px 24px rgba(16,38,70,.14); max-height: 280px; overflow-y: auto; }
.lista-sug div { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
.lista-sug div:hover, .lista-sug div.sel { background: var(--azul-50); }
.rel { position: relative; }

.modal-fondo { position: fixed; inset: 0; background: rgba(10, 26, 50, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.ancho { max-width: 860px; }
.modal .hd { padding: 16px 20px; border-bottom: 1px solid var(--borde-suave); display: flex; align-items: center; gap: 10px; }
.modal .hd .x { margin-left: auto; }
.modal .bd { padding: 20px; display: grid; gap: 14px; }
.modal .pie { padding: 14px 20px; border-top: 1px solid var(--borde-suave); display: flex; justify-content: flex-end; gap: 8px; background: #FAFCFE; border-radius: 0 0 10px 10px; }

.toast-zona { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 200; }
.toast { background: var(--azul-900); color: #fff; padding: 12px 16px; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.2); max-width: 380px; font-size: 13.5px; }
.toast.error { background: var(--error); }
.toast.ok { background: var(--ok); }

.barras { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: 10px; }
.barras .b { flex: 1; background: var(--azul-500); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; opacity: .85; }
.barras .b:hover { opacity: 1; background: var(--azul-700); }
.barras-et { display: flex; gap: 4px; font-size: 10.5px; color: var(--texto-3); margin-top: 6px; }
.barras-et span { flex: 1; text-align: center; overflow: hidden; }

.mensajes-sri { background: var(--error-bg); border: 1px solid #F5C6C1; color: var(--error); border-radius: 6px; padding: 10px 14px; font-size: 13px; }
.mensajes-sri.ok { background: var(--ok-bg); border-color: #BFE3CF; color: var(--ok); }
.dl { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; font-size: 13.5px; }
.dl dt { color: var(--texto-3); }
.dl dd { margin: 0; word-break: break-all; }

.oferta { background: linear-gradient(135deg, var(--azul-800), var(--azul-600)); color: #fff; border-radius: var(--radio); padding: 28px; display: grid; gap: 12px; }
.oferta .precio { font-size: 34px; font-weight: 700; }
.oferta .precio small { font-size: 15px; color: #CFE2FA; font-weight: 500; }
.oferta ul { margin: 0; padding-left: 18px; color: #DCEAFB; display: grid; gap: 4px; }

.paginacion { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 14px; }
.vacio-grande { text-align: center; padding: 48px 20px; color: var(--texto-2); }
.vacio-grande h3 { margin-bottom: 6px; color: var(--texto); }

@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-fac { grid-template-columns: minmax(0, 1fr); }
  .g-fac > [style*=sticky] { position: static !important; }
}
@media (max-width: 860px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .app.menu-abierto .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .btn.menu-btn { display: inline-flex; }
  .top { padding: 0 16px; }
  .top .empresa small { display: none; }
  .contenido { padding: 16px; }
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  .fila > * { min-width: 120px; }
  .dl { grid-template-columns: 1fr; }
  .dl dt { margin-top: 6px; }
  .ocultar-movil { display: none !important; }
}
@media print {
  .side, .top, .banda, .cabecera .acciones { display: none !important; }
  .app { display: block; }
}
