:root {
  --azul: #1D4ED8; --azul-osc: #1E3A8A; --verde: #16A34A; --verde-cl: #DCFCE7;
  --amarillo: #CA8A04; --amarillo-cl: #FEF9C3; --rojo: #DC2626; --rojo-cl: #FEE2E2;
  --gris: #6B7280; --borde: #E2E8F0; --fondo: #F8FAFC; --tarjeta: #FFFFFF; --texto: #0F172A;
  --radio: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--texto);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--fondo); min-height: 100vh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); font-size: 16px; }
body.sin-nav { padding-bottom: 0; }

.barra { position: sticky; top: 0; z-index: 5; background: var(--azul-osc); color: #fff;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top)); }
.barra h1 { font-size: 1.1rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.usuario { font-size: .85rem; opacity: .85; white-space: nowrap; }

main { max-width: 900px; margin: 0 auto; padding: 16px; }
h2 { font-size: 1.25rem; margin: 4px 0 12px; }
h3 { font-size: 1.05rem; margin: 20px 0 8px; }
.cargando, .vacio { color: var(--gris); text-align: center; padding: 24px 0; }
.ayuda { color: var(--gris); font-size: .9rem; margin: 4px 0 12px; }

/* navegación inferior */
.nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; background: #fff; border-top: 1px solid var(--borde);
  display: flex; justify-content: space-around; padding-bottom: env(safe-area-inset-bottom); }
.nav a { flex: 1; text-align: center; padding: 8px 2px 10px; color: var(--gris); text-decoration: none; font-size: .75rem; min-height: 60px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; }
.nav a .ico { font-size: 1.35rem; line-height: 1.3; }
.nav a.activo { color: var(--azul); font-weight: 600; }

/* tarjetas y listas */
.tarjeta { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px; margin-bottom: 12px; }
a.tarjeta { display: block; color: inherit; text-decoration: none; }
a.tarjeta:active { background: #F1F5F9; }
.fila { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.sub { color: var(--gris); font-size: .88rem; }
.chip { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: #E0E7FF; color: var(--azul-osc); }
.chip.terminado, .chip.inactivo { background: #F1F5F9; color: var(--gris); }

.cifras { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin: 10px 0; }
.cifra { background: var(--fondo); border-radius: 10px; padding: 10px; }
.cifra .et { font-size: .78rem; color: var(--gris); }
.cifra .val { font-size: 1.1rem; font-weight: 700; }
.pos { color: var(--verde); } .neg { color: var(--rojo); }
.barra-uso { height: 8px; background: var(--borde); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.barra-uso span { display: block; height: 100%; background: var(--verde); width: 0; }
.barra-uso span.alerta { background: var(--amarillo); } .barra-uso span.peligro { background: var(--rojo); }

/* formularios y botones */
label { display: block; font-size: .88rem; color: #334155; margin: 10px 0 4px; }
input, select, textarea { width: 100%; font: inherit; padding: 12px; border: 1px solid #CBD5E1; border-radius: 10px; background: #fff; min-height: 48px; }
textarea { min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 3px solid #BFDBFE; border-color: var(--azul); }
.casilla { display: flex; align-items: center; gap: 10px; padding: 10px 0; margin: 0; font-size: 1rem; color: var(--texto); border-bottom: 1px solid var(--borde); }
.casilla input { width: 22px; height: 22px; min-height: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; border: 0; border-radius: 10px;
  padding: 12px 18px; min-height: 48px; cursor: pointer; background: var(--azul); color: #fff; text-decoration: none; }
.btn.sec { background: #E2E8F0; color: var(--texto); }
.btn.peligro { background: var(--rojo-cl); color: var(--rojo); }
.btn.chico { min-height: 38px; padding: 6px 12px; font-size: .88rem; }
.btn.ancho { width: 100%; }
.btn:disabled { opacity: .5; }
.botones { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.error { color: var(--rojo); font-size: .9rem; margin: 8px 0; min-height: 1em; }
.flotante { position: fixed; right: 16px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 4; border-radius: 99px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }

/* asistencia */
.selector-fecha { display: flex; gap: 8px; align-items: center; }
.selector-fecha input { flex: 1; }
.selector-fecha .btn { min-width: 48px; padding: 0; }
.trab { background: #fff; border: 1px solid var(--borde); border-radius: var(--radio); padding: 12px; margin-bottom: 10px; }
.trab.completo { border-color: var(--verde); background: #F0FDF4; }
.trab.medio { border-color: var(--amarillo); background: #FEFCE8; }
.trab.ausente { border-color: var(--rojo); background: #FEF2F2; }
.trab .nombre { font-weight: 600; }
.marcas { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.marca { font: inherit; font-weight: 600; min-height: 54px; border-radius: 10px; border: 2px solid var(--borde); background: #fff; cursor: pointer; color: var(--texto); }
.marca.on.completo { background: var(--verde); border-color: var(--verde); color: #fff; }
.marca.on.medio { background: var(--amarillo); border-color: var(--amarillo); color: #fff; }
.marca.on.ausente { background: var(--rojo); border-color: var(--rojo); color: #fff; }
.marca:disabled { opacity: .5; }
.resumen-dia { position: sticky; top: 52px; z-index: 3; background: var(--fondo); padding: 8px 0; font-size: .9rem; display: flex; gap: 12px; flex-wrap: wrap; }

/* tablas */
.tabla-cont { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--borde); border-radius: var(--radio); background: #fff; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--borde); text-align: left; white-space: nowrap; }
th { background: #F1F5F9; font-weight: 600; position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 700; background: #F8FAFC; }
.grilla td, .grilla th { padding: 4px 6px; text-align: center; font-size: .8rem; }
.grilla td:first-child, .grilla th:first-child { text-align: left; position: sticky; left: 0; background: #fff; }
.g-completo { background: var(--verde-cl); } .g-medio { background: var(--amarillo-cl); } .g-ausente { background: var(--rojo-cl); }

/* lista de movimientos */
.mov { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--borde); }
.mov:last-child { border-bottom: 0; }
.x { background: none; border: 0; color: var(--gris); font-size: 1.2rem; min-width: 40px; min-height: 40px; cursor: pointer; }

/* pestañas */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; }
.tabs button { font: inherit; border: 1px solid var(--borde); background: #fff; border-radius: 99px; padding: 8px 14px; white-space: nowrap; cursor: pointer; }
.tabs button.on { background: var(--azul); color: #fff; border-color: var(--azul); }

/* modal y aviso */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 40px); }
dialog::backdrop { background: rgba(15,23,42,.5); }
dialog form, dialog .cuerpo { padding: 16px; }
.aviso { position: fixed; left: 16px; right: 16px; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 20; max-width: 480px; margin: 0 auto;
  background: var(--texto); color: #fff; padding: 12px 16px; border-radius: 10px; text-align: center; }
.aviso.mal { background: var(--rojo); }

.acceso { max-width: 400px; margin: 24px auto; }
.pie { text-align: center; color: var(--gris); font-size: .78rem; margin: 28px 0 8px; }
.pie a { color: var(--gris); }
.solo-print { display: none; }

@media (min-width: 720px) {
  .nav { top: 0; bottom: auto; left: auto; right: 16px; border: 0; background: transparent; z-index: 6; gap: 4px; padding-top: env(safe-area-inset-top); }
  .nav a { flex-direction: row; min-height: 50px; color: #C7D2FE; font-size: .9rem; padding: 0 10px; }
  .nav a .ico { font-size: 1rem; }
  .nav a.activo { color: #fff; }
  body { padding-bottom: 0; }
  .barra { padding-right: 560px; }
  .flotante { bottom: 24px; }
  .aviso { bottom: 24px; }
}

@media print {
  .barra, .nav, .botones, .flotante, .no-print, .tabs, .aviso { display: none !important; }
  body { background: #fff; padding: 0; font-size: 11pt; }
  main { max-width: none; padding: 0; }
  .tarjeta, .tabla-cont { border: 0; padding: 0; }
  .tabla-cont { overflow: visible; }
  th { position: static; }
  .solo-print { display: block; }
  .grilla td, .grilla th { font-size: 7pt; padding: 2px; }
}
