/* Paleta institucional azul y gris. Ajustar los tokens al manual de marca si es necesario. */
:root {
  --azul: #0b3a75;
  --azul-2: #1556a8;
  --azul-claro: #e6eef8;
  --gris-900: #1f2933;
  --gris-700: #3e4c59;
  --gris-500: #7b8794;
  --gris-300: #cbd2d9;
  --gris-200: #e4e7eb;
  --gris-100: #f3f4f6;
  --blanco: #fff;
  --rojo: #b42318;
  --rojo-claro: #fdecea;
  --verde: #1f7a4d;
  --ambar: #8a5a00;
  --radio: 10px;
  --sombra: 0 1px 2px rgba(31, 41, 51, .08), 0 1px 3px rgba(31, 41, 51, .06);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--gris-900); background: var(--gris-100); }
a { color: var(--azul-2); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.3rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
.muted { color: var(--gris-500); } .center { text-align: center; } .small { font-size: .85rem; }
[hidden] { display: none !important; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem 1rem; padding-top: max(.5rem, env(safe-area-inset-top)); background: var(--azul); color: var(--blanco); }
.brand { display: flex; align-items: center; gap: .6rem; color: inherit; text-decoration: none; }
.brand small { display: block; font-size: .75rem; opacity: .85; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; background: var(--blanco); color: var(--azul); font-weight: 800; }
.top-right { display: flex; align-items: center; gap: .4rem; }
.icon-btn { background: transparent; border: 1px solid rgba(255,255,255,.4); color: var(--blanco); border-radius: 8px; min-width: 44px; min-height: 40px; font-size: 1.2rem; }
.net-badge, .sync-badge { font-size: .75rem; border-radius: 999px; padding: .3rem .6rem; border: 0; }
.net-badge { background: var(--gris-700); color: var(--blanco); }
.sync-badge { background: var(--blanco); color: var(--azul); font-weight: 600; }
.menu { position: sticky; top: 56px; z-index: 9; background: var(--blanco); border-bottom: 1px solid var(--gris-300); box-shadow: var(--sombra); }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: .9rem 1rem; border: 0; border-bottom: 1px solid var(--gris-200); background: none; color: var(--gris-900); font: inherit; text-decoration: none; }
.menu .who { padding: .9rem 1rem; background: var(--azul-claro); font-size: .9rem; }

.app { max-width: 960px; margin: 0 auto; padding: 1rem 1rem 7rem; }
.card { background: var(--blanco); border: 1px solid var(--gris-200); border-radius: var(--radio); padding: 1rem; margin-bottom: .75rem; box-shadow: var(--sombra); }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grid { display: grid; gap: .75rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.three { grid-template-columns: repeat(3, 1fr); } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: .5rem; margin-bottom: .75rem; }
.stat { background: var(--blanco); border: 1px solid var(--gris-200); border-radius: var(--radio); padding: .6rem .75rem; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.stat b { display: block; font-size: 1.4rem; color: var(--azul); }
.stat span { font-size: .8rem; color: var(--gris-700); }
.stat.sel { outline: 2px solid var(--azul-2); }
.stat.devuelto b { color: var(--rojo); }

.alert { border-radius: var(--radio); padding: .9rem 1rem; margin-bottom: .75rem; border: 1px solid; }
.alert.danger { background: var(--rojo-claro); border-color: #f4b4ae; color: #7a1a12; }
.alert.info { background: var(--azul-claro); border-color: #b9cde8; color: var(--azul); }
.alert.warn { background: #fff7e0; border-color: #f0d48a; color: var(--ambar); }
.alert h3 { margin-bottom: .25rem; }

label { display: block; font-size: .85rem; font-weight: 600; color: var(--gris-700); margin-bottom: .25rem; }
.req::after { content: " *"; color: var(--rojo); }
input, select, textarea { width: 100%; min-height: 48px; padding: .6rem .7rem; font: inherit; color: var(--gris-900); background: var(--blanco); border: 1px solid var(--gris-300); border-radius: 8px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--azul-2); outline-offset: 0; border-color: var(--azul-2); }
input:disabled, select:disabled, textarea:disabled { background: var(--gris-100); color: var(--gris-700); }
.help { font-size: .78rem; color: var(--gris-500); margin-top: .2rem; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.check input { width: 22px; min-height: 22px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 48px; padding: .6rem 1rem; border-radius: 8px; border: 1px solid var(--azul); background: var(--azul); color: var(--blanco); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.sec { background: var(--blanco); color: var(--azul); }
.btn.gris { background: var(--gris-200); border-color: var(--gris-300); color: var(--gris-900); }
.btn.danger { background: var(--rojo); border-color: var(--rojo); }
.btn.ok { background: var(--verde); border-color: var(--verde); }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: .35rem .7rem; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 700; border: 1px solid transparent; white-space: nowrap; }
.b-Creado { background: var(--gris-200); color: var(--gris-700); }
.b-Pendiente { background: var(--azul-claro); color: var(--azul); border-color: #b9cde8; }
.b-Devuelto { background: var(--rojo); color: var(--blanco); }
.b-Cerrado { background: var(--gris-700); color: var(--blanco); }
.b-local { background: #fff7e0; color: var(--ambar); border-color: #f0d48a; }

.item { display: block; color: inherit; text-decoration: none; border-left: 5px solid var(--gris-300); }
.item.Pendiente { border-left-color: var(--azul-2); }
.item.Devuelto { border-left-color: var(--rojo); background: #fffafa; }
.item.Cerrado { border-left-color: var(--gris-700); }
.item .meta { font-size: .85rem; color: var(--gris-700); }
.item .motivo { margin-top: .4rem; font-size: .85rem; color: #7a1a12; font-weight: 600; }

.tabs { display: flex; gap: .25rem; overflow-x: auto; margin: .5rem 0 .75rem; border-bottom: 2px solid var(--gris-200); }
.tabs button { flex: 1 0 auto; min-height: 44px; padding: .5rem .8rem; border: 0; background: none; font: inherit; color: var(--gris-700); border-bottom: 3px solid transparent; margin-bottom: -2px; cursor: pointer; }
.tabs button.on { color: var(--azul); border-bottom-color: var(--azul); font-weight: 700; }

.child { border: 1px solid var(--gris-200); border-radius: 8px; padding: .75rem; margin-bottom: .5rem; background: var(--blanco); }
.child .row { justify-content: space-between; }
.kv { font-size: .85rem; color: var(--gris-700); }
.dirty { font-size: .7rem; color: var(--ambar); font-weight: 700; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 3px solid var(--gris-300); padding: .25rem 0 .75rem .75rem; position: relative; }
.timeline li.DEVOLUCION { border-left-color: var(--rojo); }
.timeline li.CIERRE { border-left-color: var(--gris-700); }
.timeline li.CORRECCION, .timeline li.CORRECCION_ADMIN { border-left-color: var(--azul-2); }
.timeline .t { font-weight: 700; font-size: .9rem; }
.timeline .d { font-size: .82rem; color: var(--gris-700); word-break: break-word; }

.actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 8; background: var(--blanco); border-top: 1px solid var(--gris-300); padding: .6rem 1rem; padding-bottom: max(.6rem, env(safe-area-inset-bottom)); box-shadow: 0 -2px 6px rgba(31,41,51,.08); }
.actions .inner { max-width: 960px; margin: 0 auto; display: flex; gap: .5rem; flex-wrap: wrap; }
.actions .btn { flex: 1 1 140px; }

details.filters > summary { cursor: pointer; font-weight: 600; color: var(--azul); min-height: 44px; display: flex; align-items: center; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--gris-200); vertical-align: top; }

.toast { position: fixed; left: 50%; bottom: 6rem; transform: translateX(-50%); max-width: 92vw; background: var(--gris-900); color: var(--blanco); padding: .7rem 1rem; border-radius: 8px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 30; }
.toast.on { opacity: 1; }
.toast.err { background: var(--rojo); }
dialog { width: min(560px, 94vw); max-height: 90vh; border: 0; border-radius: 12px; padding: 1rem; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(31, 41, 51, .5); }

/* ---- Planilla, verificaciones, categorías y kWh ---- */
.tab-link { flex: 1 0 auto; padding: .6rem .8rem; text-decoration: none; color: var(--gris-700); border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tab-link.on { color: var(--azul); font-weight: 700; border-bottom-color: var(--azul); }
.kwh { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem; background: var(--azul); color: var(--blanco); border-color: var(--azul); }
.kwh span { display: block; font-size: .8rem; opacity: .9; }
.kwh b { font-size: 1.5rem; }
.kwh .small b { font-size: 1rem; }
.cat-anomalo { background: #fff1e6; color: #8a3b00; border-color: #f2c29b; }
.cat-operativo { background: var(--gris-100); color: var(--gris-700); border-color: var(--gris-300); }
.item-n { display: inline-grid; place-items: center; min-width: 1.8rem; height: 1.8rem; border-radius: 6px; background: var(--azul-claro); color: var(--azul); font-weight: 700; font-size: .85rem; margin-right: .3rem; }
.total-row { background: var(--azul-claro); border-color: #b9cde8; font-size: .9rem; }
fieldset.verif { border: 0; border-bottom: 1px solid var(--gris-200); margin: 0; padding: .6rem 0; }
fieldset.verif legend { font-weight: 600; padding: 0; margin-bottom: .4rem; }
.seg { display: flex; gap: .4rem; flex-wrap: wrap; }
.seg label { flex: 1 1 0; margin: 0; position: relative; }
.seg input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; margin: 0; opacity: 0; cursor: pointer; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: .4rem .6rem; border: 1px solid var(--gris-300); border-radius: 8px; background: var(--blanco); font-weight: 600; color: var(--gris-700); cursor: pointer; }
.seg input:checked + span { background: var(--azul); border-color: var(--azul); color: var(--blanco); }
.seg input:focus-visible + span { outline: 2px solid var(--azul-2); }
.seg input:disabled + span { cursor: default; opacity: .8; }
.calc { background: var(--azul-claro); border: 1px solid #b9cde8; border-radius: 8px; padding: .7rem; margin-top: .75rem; color: var(--azul); }
.calc .btn { margin-top: .4rem; }
.pasos { padding-left: 1.2rem; margin: 0; }
.pasos li { margin-bottom: .3rem; }

.planilla { background: #fff; color: #000; border: 1px solid var(--gris-300); padding: 1rem; font-size: 13px; overflow-x: auto; }
.pl-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; border-bottom: 2px solid #000; padding-bottom: .4rem; margin-bottom: .6rem; }
.pl-line { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; margin: .45rem 0; }
.pl-line u { text-decoration: none; border-bottom: 1px solid #000; padding: 0 .4rem; min-width: 4rem; display: inline-block; font-weight: 600; }
.pl-titulo { text-align: center; font-size: 13px; margin: .9rem 0 .3rem; }
.pl-tabla { width: 100%; border-collapse: collapse; }
.pl-tabla th, .pl-tabla td { border: 1px solid #000; padding: .2rem .35rem; text-align: center; font-size: 12px; vertical-align: middle; }
.pl-tabla th { font-weight: 700; background: #f2f2f2; }
.pl-tabla td.obs, .pl-tabla th.izq { text-align: left; }
.pl-tabla tfoot th { background: #fff; }
.pl-verif { width: auto; margin: .6rem 0; }
.pl-verif td { min-width: 5rem; height: 1.6rem; }
.pl-firmas { margin-top: 1.2rem; }
.pl-firmas u { min-width: 10rem; }
.pl-formulas { font-size: 11px; margin: .8rem 0 .3rem; }
.pl-nota { font-size: 11px; color: #333; margin: .2rem 0; }

@media print {
  @page { size: letter landscape; margin: 10mm; }
  body { background: #fff; }
  .topbar, .menu, .actions, .toast, .no-print, #syncBadge, #netBadge { display: none !important; }
  .app { max-width: none; padding: 0; }
  .planilla { border: 0; padding: 0; overflow: visible; }
}

/* ---- Comparación pérdida / recuperado, tipo de dato, exportación por saneado ---- */
.comp-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
@media (min-width: 640px) { .comp-grid { grid-template-columns: repeat(4, 1fr); } }
.comp-grid div { background: var(--gris-100); border-radius: 8px; padding: .5rem .6rem; }
.comp-grid span { display: block; font-size: .78rem; color: var(--gris-700); }
.comp-grid b { font-size: 1.15rem; color: var(--azul); }
.barra { height: 10px; background: var(--gris-200); border-radius: 999px; margin-top: .6rem; overflow: hidden; }
.barra span { display: block; height: 100%; background: var(--azul-2); }
.req-ct { background: var(--azul-claro); border-color: #b9cde8; box-shadow: none; }
.seg.multi { margin-bottom: .75rem; }
input.auto { background: var(--gris-100); color: var(--azul); font-weight: 700; }
.item-wrap { position: relative; }
.item-wrap .item { padding-bottom: 2.6rem; }
.xls-item { position: absolute; right: .75rem; bottom: 1.4rem; min-height: 32px; }
.pl-comp { margin-top: .6rem; }

/* ---- Usuario en la barra, tipo de dato, desasociados ---- */
.quien { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; max-width: 42vw; text-align: right; }
.quien b { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.quien small { font-size: .7rem; opacity: .85; }
.brand small { white-space: nowrap; }
.dash-head { margin-bottom: 1rem; row-gap: .6rem; }
.fila-dato { display: grid; grid-template-columns: minmax(110px, 38%) 1fr auto; gap: .4rem; margin-bottom: .5rem; align-items: center; }
.fila-dato .btn { min-height: 48px; }
#otroDato { margin-bottom: .75rem; }
.comp-grid.des { margin-top: .6rem; grid-template-columns: repeat(2, 1fr); }
.comp-grid.des div { background: #fff7e0; }
.comp-grid.des b { color: var(--ambar); }

.fila-dato > * { min-width: 0; }
dialog form, dialog .grid { min-width: 0; }
dialog { overflow-x: hidden; }
@media (max-width: 430px) {
  .brand small { display: none; }
  .topbar { gap: .35rem; padding-left: .75rem; padding-right: .75rem; }
  .net-badge, .sync-badge { padding: .25rem .45rem; font-size: .7rem; }
  .quien { max-width: 34vw; }
}

/* Espacio para la barra de acciones fija (incluye el aviso de sincronización) */
.app { padding-bottom: 11rem; }
