:root {
  --indigo-950: #1e1b4b; --indigo-900: #312e81; --indigo-700: #4338ca; --indigo-600: #4f46e5; --indigo-100: #e0e7ff; --indigo-50: #eef2ff;
  --amber-500: #f59e0b; --amber-100: #fef3c7; --amber-800: #92400e;
  --green-600: #16a34a; --green-100: #dcfce7; --green-800: #166534;
  --red-600: #dc2626; --red-100: #fee2e2; --red-800: #991b1b;
  --slate-50: #f8fafc; --slate-100: #f1f5f9; --slate-200: #e2e8f0; --slate-300: #cbd5e1; --slate-400: #94a3b8;
  --slate-500: #64748b; --slate-600: #475569; --slate-700: #334155; --slate-900: #0f172a;
  --radius: 10px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs: 1;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --surface: #fff; --indigo-25: #f5f7ff; --yellow-100: #fef9c3; --yellow-800: #854d0e;
  --code-bg: #0f172a; --toast-bg: #0f172a; --link: var(--indigo-600); --acento-txt: var(--indigo-700);
  --delta-bien: #15803d; --delta-mal: #b91c1c; --ambar-txt: #b45309; --rojo-txt: #b91c1c;
}
/* Tema oscuro: lo activa app.js con <html data-tema="oscuro"> (auto = sigue al móvil) */
:root[data-tema="oscuro"] {
  color-scheme: dark;
  --indigo-950: #14123a; --indigo-900: #1e1b4b; --indigo-100: #3a3a8a; --indigo-50: #1b1f45; --indigo-25: #161a3c;
  --amber-100: #3a2c0b; --amber-800: #fcd34d; --green-100: #0f2b1b; --green-800: #86efac; --red-100: #3a1414; --red-800: #fca5a5;
  --yellow-100: #3a3410; --yellow-800: #fde68a;
  --slate-50: #0b1120; --slate-100: #172033; --slate-200: #26324a; --slate-300: #37445e; --slate-400: #64748b;
  --slate-500: #94a3b8; --slate-600: #b4c0d2; --slate-700: #cbd5e1; --slate-900: #e8edf5;
  --surface: #111a2e; --code-bg: #0b1120; --toast-bg: #334155; --link: #a5b4fc; --acento-txt: #a5b4fc;
  --delta-bien: #4ade80; --delta-mal: #f87171; --ambar-txt: #fbbf24; --rojo-txt: #f87171;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 1px 3px rgba(0,0,0,.5);
}
:root[data-tema="oscuro"] .toast.ok { background: #166534; }
:root[data-tema="oscuro"] .toast.error { background: #991b1b; }
:root[data-tema="oscuro"] .btn.peligro { border-color: #7f1d1d; }
/* Evita el destello blanco antes de que cargue app.js en móviles en modo oscuro */
@media (prefers-color-scheme: dark) { html:not([data-tema]) body { background: #0b1120; color: #e8edf5; } }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--slate-50); color: var(--slate-900); font-size: calc(15px * var(--fs, 1)); line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link); }
[hidden] { display: none !important; }

/* Layout */
.shell { display: flex; min-height: 100%; }
.sidebar { width: 232px; flex: none; background: var(--indigo-900); color: #fff; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: calc(17px * var(--fs, 1)); }
.brand small { display: block; font-weight: 400; font-size: calc(12px * var(--fs, 1)); color: #c7d2fe; }
.brand .logo { width: 48px; height: 36px; flex: none; display: grid; place-items: center; }
.brand .logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: #c7d2fe; text-decoration: none; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.activo { background: var(--indigo-600); color: #fff; }
.nav .grupo { display: flex; justify-content: space-between; align-items: center; width: 100%; margin: 12px 0 2px; padding: 4px 12px; background: none; border: 0; cursor: pointer; font: inherit; font-size: calc(11px * var(--fs, 1)); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #a5b4fc; text-align: left; }
.nav .grupo:hover { color: #fff; }
.nav .items { display: flex; flex-direction: column; gap: 2px; }
.nav .chev { transition: transform .15s; }
.nav .bloque.cerrado .items { display: none; }
.nav .bloque.cerrado .chev { transform: rotate(-90deg); }
.menu-btn { display: none; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.25); color: #fff; border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; }
.nav .sep { height: 1px; background: rgba(255,255,255,.12); margin: 8px 6px; }
.sidebar .pie { margin-top: auto; padding-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.sidebar .pie button { width: 100%; background: transparent; border: 1px solid rgba(255,255,255,.25); color: #c7d2fe; border-radius: 8px; padding: 8px; cursor: pointer; }
.sidebar .pie button:hover { background: rgba(255,255,255,.08); color: #fff; }
.main { flex: 1; min-width: 0; padding: 26px 30px 60px; max-width: 1400px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: calc(24px * var(--fs, 1)); margin: 0; }
.page-head .sub { color: var(--slate-500); font-size: calc(14px * var(--fs, 1)); margin-top: 2px; }

/* Componentes */
.card { background: var(--surface); border: 1px solid var(--slate-200); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.card h2 { font-size: calc(15px * var(--fs, 1)); margin: 0 0 12px; color: var(--slate-700); }
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.kpi .label { color: var(--slate-500); font-size: calc(13px * var(--fs, 1)); }
.kpi .valor { font-size: calc(26px * var(--fs, 1)); font-weight: 700; margin: 2px 0; letter-spacing: -.02em; }
.kpi .detalle { color: var(--slate-500); font-size: calc(13px * var(--fs, 1)); }
.kpi.alerta .valor { color: var(--amber-800); }
.kpi.bien .valor { color: var(--green-800); }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--slate-300); background: var(--surface); cursor: pointer; font-weight: 500; text-decoration: none; color: var(--slate-700); white-space: nowrap; }
.btn:hover { background: var(--slate-100); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primario { background: var(--indigo-600); border-color: var(--indigo-600); color: #fff; }
.btn.primario:hover { background: var(--indigo-700); }
.btn.ok { background: var(--green-600); border-color: var(--green-600); color: #fff; }
.btn.peligro { color: var(--red-600); border-color: #fecaca; }
.btn.peligro:hover { background: var(--red-100); }
.btn.chico { padding: 4px 9px; font-size: calc(13px * var(--fs, 1)); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: calc(12px * var(--fs, 1)); font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--green-100); color: var(--green-800); }
.badge.pend { background: var(--amber-100); color: var(--amber-800); }
.badge.gris { background: var(--slate-100); color: var(--slate-600); }
.badge.rojo { background: var(--red-100); color: var(--red-800); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .espacio { flex: 1; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=email], input[type=password], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--slate-300); border-radius: 8px; background: var(--surface); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--indigo-100); border-color: var(--indigo-600); }
.toolbar input, .toolbar select { width: auto; }
.toolbar input[type=search] { min-width: 220px; }
textarea { resize: vertical; min-height: 70px; }

.tabla-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: calc(12px * var(--fs, 1)); text-transform: uppercase; letter-spacing: .04em; color: var(--slate-500); padding: 10px 12px; border-bottom: 1px solid var(--slate-200); background: var(--slate-50); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--slate-100); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tbody tr.clic { cursor: pointer; }
tbody tr.clic:hover { background: var(--indigo-50); }
.der { text-align: right; } .centro { text-align: center; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.desc { max-width: 380px; color: var(--slate-700); }
.corto { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mudo { color: var(--slate-500); }
td.notas { min-width: 180px; max-width: 320px; color: var(--slate-700); }
tfoot .total-row td { border-top: 2px solid var(--slate-200); }
.vacio { text-align: center; color: var(--slate-500); padding: 34px 10px; }
.total-row td { font-weight: 700; background: var(--slate-50); }

/* Formularios */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-inline { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 12px 14px; align-items: end; }
.form-ruta { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px 14px; align-items: end; }
.kpi.destacado { background: var(--indigo-50); border-color: var(--indigo-600); }
.kpi.destacado .valor { color: var(--acento-txt); }
label.campo { display: block; font-size: calc(13px * var(--fs, 1)); font-weight: 600; color: var(--slate-600); }
label.campo > span { display: block; margin-bottom: 4px; }
label.campo .ayuda { font-weight: 400; color: var(--slate-500); font-size: calc(12px * var(--fs, 1)); margin-top: 3px; display: block; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
label.check input { width: auto; }
.totales { display: flex; gap: 18px; flex-wrap: wrap; background: var(--indigo-50); border-radius: 8px; padding: 10px 14px; font-size: calc(14px * var(--fs, 1)); }
.totales b { font-size: calc(16px * var(--fs, 1)); }
.hint { background: var(--amber-100); color: var(--amber-800); border-radius: 8px; padding: 8px 12px; font-size: calc(13px * var(--fs, 1)); }
.error-form { background: var(--red-100); color: var(--red-800); border-radius: 8px; padding: 8px 12px; font-size: calc(14px * var(--fs, 1)); }
details.asistente { border: 1px dashed var(--slate-300); border-radius: 8px; padding: 8px 12px; }
details.asistente summary { cursor: pointer; font-weight: 600; color: var(--acento-txt); font-size: calc(14px * var(--fs, 1)); }
details.asistente .form-grid { margin-top: 10px; grid-template-columns: repeat(3, 1fr); }

/* Modal */
.modal-fondo { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 12px; overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 640px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal.ancho { max-width: 960px; }
.modal-cab { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--slate-200); gap: 10px; }
.modal-cab h3 { margin: 0; font-size: calc(17px * var(--fs, 1)); }
.modal-cab .x { border: none; background: none; font-size: calc(22px * var(--fs, 1)); line-height: 1; cursor: pointer; color: var(--slate-500); padding: 2px 8px; }
.modal-cuerpo { padding: 16px 18px 18px; }
.modal-pie { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.visor { width: 100%; height: 72vh; border: 1px solid var(--slate-200); border-radius: 8px; background: var(--slate-100); }
.visor-img { max-width: 100%; max-height: 72vh; display: block; margin: 0 auto; }
pre.codigo { background: var(--code-bg); color: #e2e8f0; padding: 14px; border-radius: 8px; overflow: auto; max-height: 68vh; font-family: var(--mono); font-size: calc(12.5px * var(--fs, 1)); line-height: 1.5; white-space: pre-wrap; word-break: break-word; margin: 0; }

/* Detalle de factura */
.detalle-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.bloque { background: var(--slate-50); border-radius: 8px; padding: 10px 12px; }
.bloque .t { font-size: calc(12px * var(--fs, 1)); text-transform: uppercase; letter-spacing: .04em; color: var(--slate-500); margin-bottom: 4px; }
.desglose { width: 100%; }
.desglose td { padding: 3px 0; border: none; }
.desglose tr.tot td { font-weight: 700; font-size: calc(16px * var(--fs, 1)); border-top: 1px solid var(--slate-300); padding-top: 6px; }

/* Explorador */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-family: var(--mono); font-size: calc(13px * var(--fs, 1)); }
.crumbs button { border: none; background: none; color: var(--acento-txt); cursor: pointer; padding: 2px 4px; border-radius: 4px; font-family: inherit; }
.crumbs button:hover { background: var(--indigo-50); }
.crumbs .sep { color: var(--slate-400); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--slate-300); background: var(--surface); border-radius: 99px; padding: 3px 11px; font-size: calc(13px * var(--fs, 1)); cursor: pointer; }
.chip:hover { background: var(--indigo-50); border-color: var(--indigo-600); }
.fila-arch { display: flex; align-items: center; gap: 10px; }
.fila-arch .ico { font-size: calc(18px * var(--fs, 1)); width: 24px; text-align: center; flex: none; }
.fila-arch .nombre { word-break: break-all; }
tr.bloqueada { opacity: .55; }
.dropzone { border: 2px dashed var(--slate-300); border-radius: 10px; padding: 16px; text-align: center; color: var(--slate-500); }
.dropzone.encima { border-color: var(--indigo-600); background: var(--indigo-50); color: var(--acento-txt); }

/* Toast */
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--toast-bg); color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: calc(14px * var(--fs, 1)); animation: sube .2s ease-out; }
.toast.ok { background: var(--green-800); } .toast.error { background: var(--red-800); }
@keyframes sube { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--indigo-950), var(--indigo-700)); }
.login { background: var(--surface); border-radius: 16px; padding: 28px; width: 100%; max-width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.login-logo { width: 120px; height: 92px; margin: 0 auto 14px; padding: 10px; box-sizing: border-box; border-radius: 18px; background: var(--indigo-900); display: grid; place-items: center; }
.login-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.login h1 { margin: 0 0 4px; font-size: calc(22px * var(--fs, 1)); text-align: center; }
.login p { margin: 0 0 18px; color: var(--slate-500); font-size: calc(14px * var(--fs, 1)); text-align: center; }
.login .btn { width: 100%; justify-content: center; margin-top: 12px; padding: 10px; }

.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--slate-300); border-top-color: var(--indigo-600); border-radius: 50%; animation: gira .7s linear infinite; vertical-align: -3px; }
@keyframes gira { to { transform: rotate(360deg); } }
.cargando { text-align: center; padding: 40px; color: var(--slate-500); }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: sticky; top: 0; z-index: 30; padding: 10px; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; max-height: 100vh; overflow-y: auto; }
  .brand { padding: 0 8px 0 4px; } .brand small { display: none; }
  .menu-btn { display: inline-flex; margin-left: auto; }
  .nav, .sidebar .pie { display: none; width: 100%; }
  .sidebar.abierto .nav { display: flex; }
  .sidebar.abierto .pie { display: flex; margin: 6px 0 0; padding: 10px 0 0; border-top: 1px solid rgba(255,255,255,.12); flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav a { padding: 11px 12px; }
  .sidebar .pie button { width: auto; padding: 8px 12px; }
  .main { padding: 16px 12px 50px; }
  .form-grid, details.asistente .form-grid, .detalle-grid, .form-inline, .form-ruta { grid-template-columns: 1fr; }
  .toolbar input[type=search] { min-width: 0; flex: 1 1 100%; }
  .toolbar select { flex: 1 1 130px; min-width: 0; }
  .toolbar .espacio { display: none; }
  .toolbar .mudo { flex: 1 1 100%; }
  .desc { max-width: 220px; }
}

/* Tablas de balance */
table.calc th, table.calc td { padding: 8px 10px; }
table.calc td { white-space: nowrap; }
table.calc td:first-child { white-space: normal; min-width: 170px; }
table.calc tr.total-row td { border-top: 1px solid var(--slate-300); }
.nota { font-size: calc(12.5px * var(--fs, 1)); margin: 10px 0 0; line-height: 1.5; }
@media (max-width: 900px) { table.calc th, table.calc td { padding: 7px 8px; font-size: calc(13px * var(--fs, 1)); } table.calc td:first-child { min-width: 140px; } }

/* Modelos 130 / 303 */
.casilla { display: inline-block; min-width: 38px; text-align: center; font-family: var(--mono); font-size: calc(11.5px * var(--fs, 1)); background: var(--indigo-50); color: var(--acento-txt); border-radius: 5px; padding: 1px 5px; margin-right: 8px; }
table.modelo td:first-child { min-width: 260px; }
tr.seccion td { background: var(--slate-100); font-size: calc(11.5px * var(--fs, 1)); text-transform: uppercase; letter-spacing: .04em; color: var(--slate-600); font-weight: 700; padding-top: 6px; padding-bottom: 6px; }
.in-gestor { width: 118px; text-align: right; padding: 5px 8px; }
.dif { min-width: 92px; }
.dif.ok { color: var(--green-800); font-weight: 600; } .dif.aviso { color: var(--amber-800); font-weight: 600; } .dif.mal { color: var(--red-800); font-weight: 700; }
tr.sel td { background: var(--indigo-50); }
.lista-avisos { margin: 0; padding-left: 20px; font-size: calc(13.5px * var(--fs, 1)); color: var(--slate-700); line-height: 1.5; }
.lista-avisos li { margin-bottom: 4px; }
@media (max-width: 900px) { .in-gestor { width: 92px; } table.modelo td:first-child { min-width: 200px; } }

/* Estado de la Raspberry (web en el NAS) */
.estado-pi { font-size: calc(12.5px * var(--fs, 1)); padding: 8px 10px; border-radius: 8px; margin-bottom: 8px; background: rgba(255,255,255,.08); color: #c7d2fe; }
.estado-pi.mal { background: #7f1d1d; color: #fecaca; font-weight: 600; }
@media (max-width: 900px) { .estado-pi { margin: 0 8px 0 0; white-space: nowrap; padding: 6px 9px; } }

/* Escáner de documentos */
.escaner { display: flex; flex-direction: column; gap: 10px; }
.escaner-visor { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 3/4; max-height: 62vh; display: grid; place-items: center; }
.escaner-visor video, .escaner-visor canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.escaner-visor .cargando-lib { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; background: rgba(15,23,42,.75); font-size: calc(13.5px * var(--fs, 1)); text-align: center; padding: 16px; gap: 8px; flex-direction: column; }
.escaner-botones { display: flex; justify-content: center; align-items: center; gap: 14px; }
.escaner-disparo { width: 62px; height: 62px; border-radius: 50%; background: var(--surface); border: 4px solid var(--indigo-600); cursor: pointer; padding: 0; }
.escaner-disparo:active { background: var(--indigo-100); }
.escaner-paginas { display: flex; gap: 8px; overflow-x: auto; padding: 2px; min-height: 62px; }
.escaner-pagina { position: relative; flex: none; width: 46px; height: 62px; border-radius: 6px; overflow: hidden; border: 1px solid var(--slate-300); }
.escaner-pagina img { width: 100%; height: 100%; object-fit: cover; display: block; }
.escaner-pagina button { position: absolute; top: -1px; right: -1px; width: 18px; height: 18px; border-radius: 50%; border: none; background: var(--red-600); color: #fff; font-size: calc(12px * var(--fs, 1)); line-height: 1; cursor: pointer; padding: 0; }
.escaner-vacio { display: grid; place-items: center; color: var(--slate-500); font-size: calc(12.5px * var(--fs, 1)); width: 100%; }

/* Clientes: tarjetas en móvil, tabla en pantallas grandes */
.cli-cards { display: none; }
.cli-card { padding: 14px; border-bottom: 1px solid var(--slate-100, var(--slate-200)); display: grid; gap: 6px; }
.cli-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.cli-num { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
@media (max-width: 720px) { #tcli table { display: none; } #tcli .cli-cards { display: block; } }

.fila-cat.activa td { background: var(--indigo-50); }
.fila-cat:hover td { background: var(--indigo-25); }

/* Gastos: total por categoría (funciona igual en móvil y escritorio) */
.resumen-cat { margin-bottom: 14px; padding: 6px 14px 10px; }
.resumen-tit { font-weight: 700; padding: 10px 0 4px; }
.cat-row { padding: 9px 8px; border-bottom: 1px solid var(--slate-200); border-radius: 8px; }
.cat-row.activa { background: var(--indigo-50); }
.cat-linea { display: flex; justify-content: space-between; gap: 10px; }
.cat-barra { height: 5px; background: var(--slate-200); border-radius: 3px; margin: 5px 0; overflow: hidden; }
.cat-barra span { display: block; height: 100%; background: #4f46e5; border-radius: 3px; }
.cat-det { font-size: calc(13px * var(--fs, 1)); }
.cat-total { border-bottom: 0; border-top: 2px solid var(--slate-300); border-radius: 0; margin-top: 4px; }

/* Inicio: resumen del trimestre, antigüedad de pendientes */
.resumen-trim { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-top: 8px; }
.rt-item { background: var(--slate-100, #f1f5f9); border-radius: 10px; padding: 10px 12px; }
.rt-valor { font-size: calc(19px * var(--fs, 1)); font-weight: 700; letter-spacing: -.01em; }
.rt-sub { font-size: calc(12px * var(--fs, 1)); }
.delta { font-size: calc(12px * var(--fs, 1)); font-weight: 700; }
.delta.bien { color: var(--delta-bien); } .delta.mal { color: var(--delta-mal); }
.ambar { color: var(--ambar-txt); font-weight: 600; } .rojo { color: var(--rojo-txt); font-weight: 700; }
/* Gastos: donut y colores por categoría */
.donut-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 6px 0 10px; }
.donut { width: 130px; height: 130px; flex: none; }
.donut-leyenda { display: flex; flex-direction: column; gap: 4px; font-size: calc(13px * var(--fs, 1)); }
.donut-leyenda i, .punto { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }

/* Búsqueda global */
#fab-buscar { position: fixed; right: 16px; bottom: 16px; z-index: 40; width: 52px; height: 52px; border-radius: 50%; border: 0; background: #4f46e5; color: #fff; font-size: calc(22px * var(--fs, 1)); box-shadow: 0 6px 18px rgba(49,46,129,.35); cursor: pointer; }
#busq { position: fixed; inset: 0; z-index: 60; background: rgba(15,23,42,.45); display: flex; justify-content: center; align-items: flex-start; padding: 4vh 10px; }
#busq[hidden] { display: none; }
.busq-caja { background: var(--surface); border-radius: 14px; width: min(720px, 100%); max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.busq-cab { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--slate-200); }
.busq-cab input { flex: 1; min-width: 0; }
.busq-res { overflow-y: auto; padding: 4px 8px 12px; }
.busq-tit { font-weight: 700; padding: 12px 6px 4px; }
.busq-item { display: flex; justify-content: space-between; gap: 12px; padding: 9px 8px; border-radius: 8px; cursor: pointer; }
.busq-item:hover, .busq-item:active { background: var(--indigo-50); }
tr.resaltado td { background: var(--yellow-100); animation: resalte 3s ease-out forwards; }
@keyframes resalte { to { background: transparent; } }

/* Formulario de gastos: leer ticket con la cámara/OCR */
.leer-ticket { display: flex; flex-direction: column; align-items: stretch; gap: 8px; margin-bottom: 14px; }
.leer-ticket .btn.ancho { width: 100%; text-align: center; cursor: pointer; }
.separador-o { display: flex; align-items: center; gap: 10px; color: var(--slate-400); font-size: calc(12px * var(--fs, 1)); margin: 2px 0; }
.separador-o::before, .separador-o::after { content: ''; flex: 1; height: 1px; background: var(--slate-200); }
.leer-ticket-estado { font-size: calc(13px * var(--fs, 1)); padding: 8px 10px; border-radius: 8px; }
.leer-ticket-estado.ok { background: var(--green-100); color: var(--green-800); }
.leer-ticket-estado.aviso { background: var(--yellow-100); color: var(--yellow-800); }
.leer-ticket-estado.error { background: var(--red-100); color: var(--red-800); }

/* Ranking de clientes en Inicio: filas clicables (mismo estilo que las de categoría) */
.cat-row.clic { cursor: pointer; }
.cat-row.clic:hover { background: var(--indigo-25); }

/* Calendario: vista de agenda, agrupada por día */
.agenda-dia { border-left: 3px solid transparent; }
.agenda-dia.agenda-hoy { border-left-color: #4f46e5; background: var(--indigo-25); }
.agenda-fecha { font-weight: 700; text-transform: capitalize; margin-bottom: 6px; }
.agenda-ev { padding: 6px 0; }
.agenda-ev-fila { display: flex; align-items: center; gap: 6px; }
.agenda-ev-link { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; text-decoration: none; color: inherit; }
.agenda-ev-link:hover .agenda-tit { text-decoration: underline; }
.agenda-ico { flex: none; }
.agenda-tit { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agenda-desc { margin: 2px 0 0 26px; font-size: .9em; white-space: pre-line; }

/* Móvil instalado como app (pantalla de inicio): respetar muescas y barra inferior */
@media (max-width: 900px) {
  .sidebar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .sidebar .pie { flex: none; }
  .sidebar .pie button { white-space: nowrap; }
  .brand, .nav { flex: none; }
  .main { padding-bottom: calc(50px + env(safe-area-inset-bottom)); }
}
#fab-buscar { bottom: calc(16px + env(safe-area-inset-bottom)); right: calc(16px + env(safe-area-inset-right)); }
#toasts { bottom: calc(16px + env(safe-area-inset-bottom)); }

/* Tablas como tarjetas en el móvil (app.js pone data-label en cada celda) */
@media (max-width: 720px) {
  .tabla-wrap { overflow-x: visible; }
  table.resp, table.resp tbody { display: block; }
  table.resp thead { display: none; }
  table.resp tr { display: block; padding: 12px 14px; border-bottom: 1px solid var(--slate-200); }
  table.resp td { display: block; position: relative; padding: 0 0 0 40%; min-width: 0 !important; max-width: none !important; border: 0; text-align: left; white-space: normal; }
  table.resp td + td { margin-top: 6px; }
  table.resp td.der, table.resp td.num, table.resp td.centro { text-align: left; }
  table.resp td::before { content: attr(data-label); position: absolute; left: 0; top: 0; width: 36%; font-size: calc(11.5px * var(--fs, 1)); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--slate-500); }
  table.resp td:not([data-label]) { padding-left: 0; }
  table.resp td:not([data-label])::before { content: none; }
  table.resp td:empty { display: none; }
}
