:root {
  color-scheme: light;
  --bg: #f1f5fc; --card: #fff; --ink: #0f172a; --muted: #55657f; --line: #d5e0f1; --field: #f6f9fe;
  --brand: #1d4ed8; --brand-2: #2f6df0; --brand-ink: #fff; --brand-soft: #e4ecff;
  --warn: #b45309; --warn-soft: #fff3df; --bad: #b91c1c; --bad-soft: #fdeaea; --ok: #15803d; --ok-soft: #e3f6e9;
  --sombra: 0 1px 2px rgba(15,40,100,.06), 0 6px 18px rgba(15,40,100,.07);
  --alto-nav: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }

/* ---------- Encabezado y navegación ---------- */
.top { position: sticky; top: 0; z-index: 5; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; box-shadow: 0 2px 12px rgba(0,0,0,.18); }
.top-fila { display: flex; justify-content: space-between; align-items: center; gap: 10px; max-width: 760px; margin: 0 auto; }
.marca { display: flex; align-items: center; gap: 10px; min-width: 0; }
.marca img { width: 46px; height: 46px; border-radius: 12px; background: #fff; padding: 2px; object-fit: contain; box-shadow: 0 0 0 2px rgba(255,255,255,.45); }
.top h1 { font-size: 17px; margin: 0; line-height: 1.15; letter-spacing: .01em; }
.top small { display: block; font-size: 12px; opacity: .85; font-weight: 400; }
.top button#salir, .top button#actualizar, .top button#ayuda, .top button#campana { background: rgba(255,255,255,.16); color: #fff; border: 1px solid rgba(255,255,255,.35); }
.top-botones { display: flex; gap: 8px; flex: 0 0 auto; }
/* Avisos del sistema (certificado por vencer, SUNAT sin responder…) */
.estado-sistema { max-width: 760px; margin: 8px auto 0; padding: 0 16px; }
.estado-sistema .aviso { margin: 6px 0; }
/* Reporte por día */
.tabla { width: 100%; border-collapse: collapse; font-size: 15px; }
.tabla th { text-align: left; font-size: 12px; font-weight: 650; color: var(--muted); padding: 6px 4px; border-bottom: 1px solid var(--line); }
.tabla td { padding: 9px 4px; border-bottom: 1px dashed var(--line); }
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; }
.tabla .verde { color: var(--ok); font-weight: 700; }
.tabla .cero { opacity: .35; }
.tabla tfoot td { font-weight: 700; border-bottom: 0; border-top: 1px solid var(--line); }
nav { display: flex; gap: 4px; max-width: 760px; margin: 8px auto 0; background: rgba(0,0,0,.18); padding: 4px; border-radius: 12px; }
nav button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px; border: 0; background: none; color: rgba(255,255,255,.82); padding: 9px 8px; font: inherit; font-size: 14px; border-radius: 9px; cursor: pointer; transition: background .15s, color .15s; }
nav button svg { width: 18px; height: 18px; flex: none; }
nav button.activo { background: #fff; color: var(--brand); font-weight: 650; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
/* En el celular las pestañas pasan abajo, al alcance del pulgar */
@media (max-width: 700px) {
  nav { position: fixed; left: 0; right: 0; bottom: 0; margin: 0; max-width: none; border-radius: 0; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 18px rgba(0,0,0,.12); z-index: 6; }
  nav button { flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); padding: 7px 4px; }
  nav button.activo { background: var(--brand-soft); color: var(--brand); box-shadow: none; }
  main { padding-bottom: calc(var(--alto-nav) + 28px + env(safe-area-inset-bottom)) !important; }
  #toast { bottom: calc(var(--alto-nav) + 18px + env(safe-area-inset-bottom)) !important; }
}

main { max-width: 760px; margin: 0 auto; padding: 18px 16px 40px; }
h2 { font-size: 21px; margin: 6px 0 14px; letter-spacing: -.01em; }
h3 { font-size: 12px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; font-weight: 700; }
h3:first-child { margin-top: 0; }

/* ---------- Tarjetas y formularios ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 14px; box-shadow: var(--sombra); }
.fila { display: flex; gap: 12px; flex-wrap: wrap; }
.fila > * { flex: 1 1 170px; }
label { display: block; font-size: 13px; font-weight: 550; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea { width: 100%; min-height: 46px; font: inherit; color: var(--ink); background: var(--field); border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; transition: border-color .15s, box-shadow .15s, background .15s; }
textarea { min-height: 76px; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 65%, transparent); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 22%, transparent); background: var(--card); }
input[type=checkbox] { min-height: 0; width: 20px; height: 20px; accent-color: var(--brand); }

/* ---------- Botones ---------- */
button.btn { font: inherit; font-size: 15px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; padding: 11px 16px; min-height: 44px; cursor: pointer; transition: transform .08s, box-shadow .15s, background .15s; }
button.btn:hover { background: var(--field); }
button.btn:active { transform: scale(.98); }
button.btn.primario { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: var(--brand-ink); border-color: transparent; font-weight: 650; box-shadow: 0 3px 10px color-mix(in srgb, var(--brand) 35%, transparent); }
button.btn.primario:hover { filter: brightness(1.06); background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
button.btn.peligro { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
button.btn.chico { padding: 6px 11px; font-size: 13px; min-height: 34px; border-radius: 8px; }
button.btn:disabled { opacity: .5; cursor: default; transform: none; }
.acciones { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
form > .acciones { position: sticky; bottom: calc(var(--alto-nav) + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); margin: 6px -16px 0; padding: 12px 16px; border-top: 1px solid var(--line); z-index: 4; }
form > .acciones .btn { flex: 1 1 140px; }
@media (min-width: 701px) { form > .acciones { bottom: 0; } }

/* ---------- Lista de guías ---------- */
.item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 10px 13px 14px; margin: 0 -2px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 10px; position: relative; transition: background .12s; }
.item:hover { background: var(--field); }
.item:last-child { border-bottom: 0; }
.item strong { font-size: 17px; letter-spacing: .01em; }
.meta { color: var(--muted); font-size: 13px; }
.item .meta { margin-top: 2px; }
.etiqueta { display: inline-block; font-size: 12px; font-weight: 650; padding: 2px 10px; border-radius: 99px; background: var(--field); color: var(--muted); border: 1px solid var(--line); vertical-align: 2px; }
.etiqueta.aceptada { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.etiqueta.enviada, .etiqueta.en_proceso { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.etiqueta.rechazada, .etiqueta.error_envio, .etiqueta.anulada { color: var(--bad); background: var(--bad-soft); border-color: transparent; }

/* ---------- Avisos, datos y ventanas ---------- */
.aviso { border-left: 4px solid var(--warn); background: var(--warn-soft); padding: 11px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
.aviso ul { margin: 6px 0 0; padding-left: 20px; }
.aviso.mal { border-left-color: var(--bad); background: var(--bad-soft); }
.aviso.bien { border-left-color: var(--ok); background: var(--ok-soft); }
.modal-fondo { position: fixed; inset: 0; background: rgba(10,20,50,.55); backdrop-filter: blur(3px); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal { background: var(--card); color: var(--ink); width: 100%; max-width: 580px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 20px 18px calc(22px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 40px rgba(0,0,0,.35); animation: sube .2s ease-out; }
.modal .card { box-shadow: none; }
@keyframes sube { from { transform: translateY(24px); opacity: .5; } to { transform: none; opacity: 1; } }
@media (min-width: 600px) { .modal-fondo { align-items: center; } .modal { border-radius: 18px; } }
.dato { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.dato:last-child { border-bottom: 0; }
.dato .k { flex: 0 0 38%; color: var(--muted); font-size: 13px; }
.dato .v { flex: 1; font-weight: 600; word-break: break-word; }
.bien { border: 1.5px solid var(--line); background: var(--field); border-radius: 12px; padding: 4px 12px 12px; margin-bottom: 12px; }
.foto { max-height: 70vh; overflow: auto; border: 1.5px solid var(--line); border-radius: 12px; margin-top: 10px; background: #000; }
.foto canvas { width: 100%; height: auto; display: block; }
.foto.grande canvas { width: 200%; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(10px); background: var(--ink); color: var(--bg); padding: 11px 20px; border-radius: 99px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 92%; text-align: center; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.3); z-index: 60; }
#toast.ver { opacity: 1; transform: translateX(-50%); }

/* ---------- Invitación a instalar la app ---------- */
.banner-instalar { position: fixed; left: 12px; right: 12px; bottom: calc(var(--alto-nav) + 12px + env(safe-area-inset-bottom)); z-index: 40; display: flex; align-items: center; gap: 8px; background: var(--card); color: var(--ink); border: 1.5px solid var(--brand); padding: 10px 12px; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.3); max-width: 560px; margin: 0 auto; font-size: 14px; animation: sube .25s ease-out; }
.banner-instalar span { flex: 1; }
.banner-actualizar { z-index: 50; font-weight: 650; border-color: var(--ok); }
@media (min-width: 701px) { .banner-instalar { bottom: 16px; } }

/* ---------- Avisos de fotos recibidas ---------- */
nav button { position: relative; }
.insignia { position: absolute; top: 2px; right: calc(50% - 30px); min-width: 20px; height: 20px; padding: 0 5px; border-radius: 99px; background: #e11d48; color: #fff; font-size: 12px; line-height: 20px; text-align: center; box-shadow: 0 0 0 2px var(--card); }
.insignia[hidden] { display: none; }
@media (min-width: 701px) { .insignia { top: 4px; right: 12px; box-shadow: 0 0 0 2px #1d4ed8; } }
.banner-nueva { position: fixed; left: 12px; right: 12px; top: calc(12px + env(safe-area-inset-top)); z-index: 70; display: flex; align-items: center; gap: 8px; background: var(--ink); color: var(--bg); padding: 10px 12px; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: 560px; margin: 0 auto; animation: sube .25s ease-out; }
.banner-nueva span { flex: 1; font-weight: 600; }
.banner-nueva .btn { color: var(--ink); }
.banner-nueva .btn.primario { color: var(--brand-ink); }

/* ---------- Catálogos por secciones ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -2px 4px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: flex; align-items: center; gap: 8px; font: inherit; font-size: 14px; color: var(--ink); background: var(--card); border: 1.5px solid var(--line); border-radius: 99px; padding: 8px 14px; min-height: 40px; cursor: pointer; box-shadow: var(--sombra); transition: background .15s, border-color .15s; }
.chip .cuenta { font-size: 12px; font-weight: 700; color: var(--muted); background: var(--field); border-radius: 99px; padding: 1px 8px; }
.chip.activo { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 650; }
.chip.activo .cuenta { background: var(--brand); color: var(--brand-ink); }
.cab-seccion { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.form-cat { background: var(--field); border: 1.5px dashed var(--line); border-radius: 12px; padding: 12px 14px 14px; margin-bottom: 14px; }
.form-cat[hidden] { display: none; }
.form-cat input { background: var(--card); }
input[type=search] { margin-bottom: 6px; }

/* ---------- Pantalla de acceso ---------- */
.centro { max-width: 390px; margin: 9vh auto 0; text-align: center; padding: 26px 22px; }
.centro h2 { font-size: 24px; }
.centro .logo { width: 150px; height: 150px; object-fit: contain; background: #fff; border-radius: 24px; box-shadow: var(--sombra); margin: 0 auto 10px; display: block; }
.centro input { text-align: center; font-size: 17px; }
.centro .acciones { justify-content: center; }
.centro .acciones .btn { width: 100%; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } html { scroll-behavior: auto; } }
.fechas-reporte { display: flex; gap: 10px; margin: 0 0 8px; }
.fechas-reporte label { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fechas-reporte input { width: 100%; min-width: 0; }
/* Lo que la foto no pudo leer, dentro de la ventana de revisión */
.sin-leer { display: grid; gap: 8px; margin: 10px 0; padding: 10px 12px; border: 1.5px solid var(--bad); border-radius: 12px; background: color-mix(in srgb, var(--bad) 9%, transparent); }
.sin-leer strong { color: var(--bad); }
.sin-leer select, .sin-leer input { width: 100%; }
.sin-leer strong small { font-weight: 600; opacity: .85; }
.sin-leer.opcional { border-color: var(--line); background: transparent; }
.sin-leer.opcional strong { color: var(--muted); }
/* Historial de guías */
.tabla.historial { font-size: 13px; }
.tabla.historial th, .tabla.historial td { text-align: left; padding: 6px 4px; vertical-align: top; }
.tabla.historial .hora { white-space: nowrap; }
.tabla.historial tr.dia td { padding-top: 12px; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--line); }
.tabla.historial tr.de-baja td { text-decoration: line-through; opacity: .6; }
.tabla.historial tr.de-baja td small { text-decoration: none; }

/* El atributo hidden siempre esconde, aunque la clase tenga su propio display */
[hidden] { display: none !important; }

/* ---------- Página «Nueva guía»: dos columnas en pantallas anchas y secciones numeradas ---------- */
body.ancho .top-fila, body.ancho nav { max-width: 1060px; }
main.form-ancho { max-width: 1060px; }
.form-guia { display: grid; gap: 14px; counter-reset: paso; }
.form-guia > h2 { margin: 2px 0 0; }
.form-guia .subtitulo { margin: -8px 0 4px; color: var(--muted); font-size: 14px; }
.form-guia .card { margin-bottom: 0; min-width: 0; }
.form-guia > .card > h3:first-child { display: flex; align-items: center; gap: 9px; color: var(--brand); font-size: 13px; margin-bottom: 10px; }
.form-guia > .card > h3:first-child::before { counter-increment: paso; content: counter(paso); flex: none; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 12px; font-weight: 700; letter-spacing: 0; }
@media (min-width: 900px) {
  .form-guia { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; align-items: start; }
  .form-guia > :not(.card), .form-guia > .card.ancha { grid-column: 1 / -1; }
}
.card.ancha { }
form > .acciones { background: color-mix(in srgb, var(--bg) 92%, transparent); }
.form-guia .bien { background: var(--field); }
button.btn.primario { letter-spacing: .01em; }


/* Campana de avisos en el encabezado */
#campana { position: relative; display: inline-flex; align-items: center; padding: 6px 9px; }
#campana svg { width: 19px; height: 19px; }
#campana .tachado { display: none; }
#campana[data-estado=inactivo] .tachado, #campana[data-estado=bloqueado] .tachado, #campana[data-estado=sin] .tachado { display: block; }
#campana::after { content: ''; position: absolute; top: 2px; right: 2px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--brand); background: #94a3b8; }
#campana[data-estado=activo]::after { background: #22c55e; }
#campana[data-estado=inactivo]::after { background: #f59e0b; animation: latido 1.6s ease-in-out infinite; }
#campana[data-estado=bloqueado]::after, #campana[data-estado=sin]::after { background: #ef4444; }
@keyframes latido { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.35); } }
