:root {
  --azul: #1f3a5f; --azul2: #2d5a8c; --azul-claro: #e9eef5; --fondo: #f4f6f9; --borde: #d8dee7; --texto: #1d2633; --gris: #6b7688;
  --verde: #1e7d4f; --verde-claro: #e3f4ea; --rojo: #b42318; --rojo-claro: #fdecea; --ambar: #a15c07; --ambar-claro: #fff4e0;
  --radio: 8px; --sombra: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--texto); background: var(--fondo); }
a { color: var(--azul2); }
.layout { display: flex; min-height: 100vh; }
.menu { width: 220px; background: var(--azul); color: #fff; padding: 16px 10px; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.menu .marca { font-weight: 700; font-size: 17px; padding: 4px 8px 18px; line-height: 1.2; display: flex; align-items: center; gap: 10px; }
.menu .marca img { width: 40px; height: 40px; border-radius: 9px; flex-shrink: 0; }
.menu .marca small { display: block; font-weight: 400; font-size: 11px; opacity: .75; margin-top: 3px; }
.menu a { display: flex; align-items: center; gap: 10px; color: #dbe5f1; text-decoration: none; padding: 9px 12px; border-radius: 6px; margin-bottom: 2px; }
.menu a:hover { background: rgba(255,255,255,.08); color: #fff; }
.menu a.activo { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.menu .ico { width: 18px; text-align: center; }
.menu .pie { margin-top: 24px; padding: 10px 12px; font-size: 12px; opacity: .8; border-top: 1px solid rgba(255,255,255,.15); }
.menu .pie button { background: none; border: 1px solid rgba(255,255,255,.35); color: #fff; padding: 4px 10px; border-radius: 5px; cursor: pointer; margin-top: 6px; }
.contenido { flex: 1; padding: 22px 28px 60px; min-width: 0; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--azul); }
.sub { color: var(--gris); margin: 0 0 18px; }
.tarjeta { background: #fff; border: 1px solid var(--borde); border-radius: var(--radio); box-shadow: var(--sombra); padding: 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 12px 14px; }
.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)); }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; } .span4 { grid-column: 1 / -1; }
label.campo { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; color: #3a4556; }
label.campo small { font-weight: 400; color: var(--gris); }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--borde); border-radius: 6px; background: #fff; width: 100%; color: var(--texto); }
input:focus, select:focus, textarea:focus { outline: 2px solid #b9cde6; border-color: var(--azul2); }
input[type=checkbox], input[type=radio] { width: auto; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13px; cursor: pointer; }
button { font: inherit; cursor: pointer; }
.btn { border: 1px solid var(--borde); background: #fff; color: var(--texto); padding: 8px 14px; border-radius: 6px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #f3f5f8; }
.btn.prim { background: var(--azul2); border-color: var(--azul2); color: #fff; } .btn.prim:hover { background: var(--azul); }
.btn.peligro { color: var(--rojo); border-color: #f0c2bd; } .btn.peligro:hover { background: var(--rojo-claro); }
.btn.peq { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.acciones { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.entre { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--gris); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--borde); background: #fafbfc; white-space: nowrap; }
table.t td { padding: 8px; border-bottom: 1px solid #edf0f4; vertical-align: middle; }
table.t tr.clic { cursor: pointer; } table.t tr.clic:hover td { background: #f6f9fc; }
table.t td.n, table.t th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t tfoot td { font-weight: 700; background: #fafbfc; }
.tabla-scroll { overflow-x: auto; }
.lineas input, .lineas select { padding: 6px 7px; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.chip.PROCESADO { background: var(--verde-claro); color: var(--verde); }
.chip.RECHAZADO { background: var(--rojo-claro); color: var(--rojo); }
.chip.PENDIENTE { background: var(--ambar-claro); color: var(--ambar); }
.chip.INVALIDADO, .chip.DESCARTADO { background: #eceef2; color: #555; }
.chip.demo { background: #fff1e6; color: #b5520b; }
.aviso { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: 13.5px; line-height: 1.45; }
.aviso.info { background: var(--azul-claro); color: var(--azul); }
.aviso.ok { background: var(--verde-claro); color: var(--verde); }
.aviso.error { background: var(--rojo-claro); color: var(--rojo); white-space: pre-line; }
.aviso.ambar { background: var(--ambar-claro); color: var(--ambar); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px 16px; box-shadow: var(--sombra); }
.kpi .l { font-size: 12px; color: var(--gris); font-weight: 600; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .d { font-size: 12px; color: var(--gris); margin-top: 2px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--borde); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: none; border: none; padding: 9px 14px; border-bottom: 2px solid transparent; color: var(--gris); font-weight: 600; }
.tabs button.act { color: var(--azul2); border-bottom-color: var(--azul2); }
.tipos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.tipos button { background: #fff; border: 1.5px solid var(--borde); border-radius: var(--radio); padding: 12px; text-align: left; }
.tipos button b { display: block; font-size: 14px; } .tipos button span { font-size: 12px; color: var(--gris); }
.tipos button.act { border-color: var(--azul2); background: var(--azul-claro); }
.totales { margin-left: auto; width: 100%; max-width: 340px; }
.totales div { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.totales .gran { border-top: 2px solid var(--azul); margin-top: 6px; padding-top: 8px; font-size: 18px; font-weight: 700; color: var(--azul); }
.modal-fondo { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 760px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.ancho { max-width: 980px; }
.modal .cab { padding: 16px 20px; border-bottom: 1px solid var(--borde); display: flex; justify-content: space-between; align-items: center; }
.modal .cab h2 { margin: 0; }
.modal .cue { padding: 18px 20px; }
.modal .pie { padding: 12px 20px; border-top: 1px solid var(--borde); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.x { background: none; border: none; font-size: 22px; color: var(--gris); line-height: 1; }
.toast { position: fixed; bottom: 20px; right: 20px; z-index: 99; max-width: 420px; padding: 12px 16px; border-radius: 8px; color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.2); white-space: pre-line; }
.toast.ok { background: var(--verde); } .toast.error { background: var(--rojo); } .toast.info { background: var(--azul2); }
.login { max-width: 380px; margin: 10vh auto; }
.login .marca { text-align: center; margin-bottom: 18px; color: var(--azul); }
.login .marca b { font-size: 26px; display: block; margin-bottom: 2px; }
.login .marca img { width: 104px; height: 104px; border-radius: 22px; display: block; margin: 0 auto 12px; box-shadow: 0 6px 18px rgba(16,24,40,.18); }
.vacio { text-align: center; color: var(--gris); padding: 30px 10px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; }
.muted { color: var(--gris); font-size: 12.5px; }
.barras { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 8px; }
.barras div { flex: 1; max-width: 36px; background: var(--azul2); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.barras div:hover { background: var(--azul); }
.buscador { position: relative; }
.sugerencias { position: absolute; z-index: 20; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--borde); border-radius: 6px; box-shadow: var(--sombra); max-height: 260px; overflow-y: auto; }
.sugerencias div { padding: 7px 10px; cursor: pointer; font-size: 13px; } .sugerencias div:hover { background: var(--azul-claro); }
.cargando { opacity: .6; pointer-events: none; }
.solo-imprimir { display: none; }
.barra-movil, .velo { display: none; }
@media (max-width: 900px) {
  .layout { display: block; }
  .barra-movil { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 40; background: var(--azul); color: #fff; padding: 8px 12px; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
  .barra-movil img { width: 30px; height: 30px; border-radius: 7px; }
  .barra-movil b { font-size: 16px; }
  .barra-movil .muted-claro { margin-left: auto; font-size: 13px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
  .hamburguesa { background: none; border: none; color: #fff; font-size: 24px; line-height: 1; padding: 4px 6px; }
  .menu { position: fixed; top: 0; left: 0; bottom: 0; width: 270px; max-width: 85vw; height: 100vh; z-index: 60; transform: translateX(-105%); transition: transform .2s ease; display: block; box-shadow: 4px 0 20px rgba(0,0,0,.25); }
  .menu.abierto { transform: none; }
  .menu a { padding: 11px 12px; }
  .velo { display: block; position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 55; }
  .contenido { padding: 16px 12px 70px; }
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .tipos { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  body { font-size: 15px; }
  input, select, textarea { font-size: 16px; }   /* evita el zoom automático del iPhone */
  h1 { font-size: 20px; }
  .tarjeta { padding: 14px 12px; }
  .grid.g2 { grid-template-columns: 1fr; }
  .grid.g3, .grid.g4, .contenido .grid[style*="grid-template-columns"] { grid-template-columns: repeat(2, minmax(0,1fr)) !important; }
  .span2, .span3, .span4 { grid-column: 1 / -1; }
  .grid > .acciones { grid-column: 1 / -1; }
  .entre { align-items: flex-start; }
  .acciones .btn { flex: 1 1 auto; justify-content: center; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; } .kpi { padding: 12px; } .kpi .v { font-size: 18px; }
  .totales { max-width: none; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; } .tabs button { white-space: nowrap; padding: 9px 10px; }
  /* Tablas como tarjetas */
  table.t.con-tarjeta thead { display: none; }
  table.t.con-tarjeta, table.t.con-tarjeta tbody, table.t.con-tarjeta tfoot { display: block; width: 100%; }
  table.t.con-tarjeta td:first-child:not(:only-child) { font-weight: 600; }
  table.t.con-tarjeta tr { display: block; border: 1px solid var(--borde); border-radius: 8px; padding: 6px 10px; margin-bottom: 10px; background: #fff; }
  table.t.con-tarjeta tfoot tr { background: #fafbfc; }
  table.t.con-tarjeta td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: none; padding: 5px 0; text-align: right; min-height: 0; }
  table.t.con-tarjeta td::before { content: attr(data-et); font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--gris); font-weight: 600; text-align: left; flex-shrink: 0; }
  table.t.con-tarjeta td[data-et=""]::before { display: none; }
  table.t.con-tarjeta td[data-et=""] { justify-content: flex-start; text-align: left; }
  table.t.con-tarjeta td:empty { display: none; }
  table.t.con-tarjeta td.n { justify-content: space-between; }
  table.t.con-tarjeta td.vacio { justify-content: center; }
  table.t.con-tarjeta.lineas td { flex-wrap: wrap; }
  table.t.con-tarjeta.lineas td > input, table.t.con-tarjeta.lineas td > select { width: 55%; }
  table.t.con-tarjeta.lineas td > .buscador { width: 100%; }
  table.t.con-tarjeta.lineas td:first-child { display: block; text-align: left; }
  table.t.con-tarjeta.lineas td:first-child::before { display: block; margin-bottom: 4px; }
  table.t.sin-tarjeta { min-width: 760px; }
  .tabla-scroll, .tarjeta { overflow-x: auto; }
  table.t.kv td { word-break: break-word; }
  /* Ventanas a pantalla completa */
  .modal-fondo { padding: 0; align-items: stretch; }
  .modal, .modal.ancho { max-width: none; min-height: 100vh; border-radius: 0; display: flex; flex-direction: column; }
  .modal .cue { flex: 1; padding: 14px 12px; }
  .modal .cab { position: sticky; top: 0; background: #fff; z-index: 2; padding: 12px; }
  .modal .pie { position: sticky; bottom: 0; background: #fff; padding: 10px 12px; }
  .modal .pie .btn { flex: 1 1 auto; justify-content: center; }
  .toast { left: 12px; right: 12px; bottom: 12px; max-width: none; }
  .login { margin: 6vh 12px; }
  .sugerencias { max-height: 50vh; }
  table.t td.mono, table.t td .mono { word-break: break-all; }
  .grid > * { min-width: 0; }
  table.t.kv { table-layout: fixed; }
  table.t.kv td:first-child { width: 42%; color: var(--gris); }
  table.t.kv td:first-child { white-space: normal; }
}
@media print {
  .menu, .no-imprimir, .acciones, .tabs { display: none !important; } .contenido { padding: 0; } .tarjeta { box-shadow: none; border: none; padding: 0; } .solo-imprimir { display: block; }
  body { background: #fff; }
}

.selector-act .sel-valor { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--borde); border-radius: 6px; background: #fff; cursor: pointer; min-height: 38px; font-weight: 400; color: var(--texto); }
.selector-act .sel-valor.vacio { color: var(--gris); }
.selector-act .sel-valor:focus { outline: 2px solid #b9cde6; }
.selector-act .sel-acc { display: flex; align-items: center; gap: 6px; color: var(--gris); flex-shrink: 0; }
.selector-act .sel-acc .x { font-size: 18px; padding: 0 2px; cursor: pointer; }
.selector-act .sugerencias { max-height: 320px; }
div.campo { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; color: #3a4556; }
div.campo small { font-weight: 400; color: var(--gris); }
