:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --text: #1d1d1b;
  --muted: #6b6a65;
  --line: #e2e0da;
  --accent: #b4231f;          /* rojo estación */
  --accent-text: #ffffff;
  --focus: #2b6cb0;
  --warn-bg: #fff4d6;
  --warn-text: #7a5300;
  --bad-bg: #fde8e7;
  --bad-text: #9b1c17;
  --ok-text: #2f6b2f;
  --sug-bg: #eef4fb;
  --sug-line: #9fbbe0;
  --t-m: #f7d774;  --t-m-text: #4a3b00;
  --t-t: #f2a65a;  --t-t-text: #4a2300;
  --t-n: #3d4a7a;  --t-n-text: #ffffff;
  --t-d: #d9d7d0;  --t-d-text: #4a4a46;
  --t-x: #b9d7b0;  --t-x-text: #213d1b;
  --radius: 8px;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
h1 { font-size: 17px; margin: 0; letter-spacing: .01em; }
h2 { font-size: 15px; margin: 24px 0 8px; }
h3 { margin: 0; font-size: 16px; }
.sub { color: var(--muted); font-size: 13px; }

.top {
  display: flex; align-items: center; gap: 24px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.top { flex-wrap: wrap; row-gap: 8px; }
.top h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px; }
.tabs { display: flex; gap: 4px; }
.tab { white-space: nowrap; }
.tab {
  border: 0; background: transparent; color: var(--muted); font: inherit; padding: 6px 12px;
  border-radius: 6px; cursor: pointer;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.activo { background: var(--surface-2); color: var(--text); font-weight: 600; }

main { padding: 16px 20px 40px; }

.barra { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.nav-semana, .acciones, .filtros { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sem-titulo { font-weight: 600; font-size: 16px; min-width: 210px; text-align: center; }

.btn {
  font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-block;
}
.btn:hover { border-color: var(--muted); }
.btn.suave { background: transparent; }
.btn.primario { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primario:disabled { opacity: .45; cursor: default; }
.btn.mini { padding: 1px 6px; font-size: 12px; }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

input, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 8px;
}

.aviso {
  background: var(--sug-bg); border: 1px solid var(--sug-line); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 12px;
}
.aviso.festivo { background: var(--warn-bg); border-color: transparent; color: var(--warn-text); }
.aviso p { margin: 0; }
.aviso p + p { margin-top: 4px; }

.tabla-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }

/* Grilla semanal */
.grilla { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 1040px; }
.grilla th, .grilla td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 6px; vertical-align: top; }
.grilla tr > *:last-child { border-right: 0; }
.grilla thead th { background: var(--surface-2); font-size: 12px; font-weight: 600; text-align: center; position: sticky; top: 0; }
.grilla thead th .fecha { display: block; font-size: 15px; color: var(--text); }
.grilla thead th.domfest { color: var(--accent); }
.grilla thead th .fest { display: block; font-weight: 500; font-size: 11px; color: var(--accent); }
.grilla th.emp { text-align: left; font-size: 13px; font-weight: 600; min-width: 170px; background: var(--surface); position: sticky; left: 0; z-index: 1; }
.grilla thead th.emp { background: var(--surface-2); z-index: 2; }
.grilla th.emp .inactivo { font-weight: 400; color: var(--muted); font-size: 11px; display: block; }
.grilla td.celda { min-width: 118px; vertical-align: middle; }
.grilla td.celda.sugerido { background: var(--sug-bg); box-shadow: inset 0 0 0 1px var(--sug-line); }
.grilla td.tot { font-size: 12px; min-width: 90px; text-align: center; vertical-align: middle; }
.grilla.con-detalle td.tot { min-width: 200px; text-align: left; }
.grilla.con-detalle td.celda { min-width: 150px; vertical-align: top; }
.grilla tbody th.emp { vertical-align: middle; }
.grilla tfoot td { background: var(--surface-2); font-size: 12px; text-align: center; color: var(--muted); }
.grilla tfoot th { background: var(--surface-2); }

.celda-top { display: flex; gap: 4px; align-items: center; }
.sel-turno {
  flex: 1; min-width: 0; padding: 6px 6px; font-weight: 600; border-radius: 6px; cursor: pointer; font-size: 14px;
}
.sel-turno.t-vacio { color: var(--muted); font-weight: 400; }
.pill { display: inline-block; padding: 3px 8px; border-radius: 5px; font-weight: 600; font-size: 13px; }
.t-M { background: var(--t-m); color: var(--t-m-text); border-color: transparent; }
.t-T { background: var(--t-t); color: var(--t-t-text); border-color: transparent; }
.t-N { background: var(--t-n); color: var(--t-n-text); border-color: transparent; }
.t-D { background: var(--t-d); color: var(--t-d-text); border-color: transparent; }
.t-X { background: var(--t-x); color: var(--t-x-text); border-color: transparent; }
.doble { flex: 1; display: flex; gap: 3px; flex-wrap: wrap; cursor: pointer; border: 0; background: none; padding: 0; text-align: left; }
.lapiz { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 2px 4px; border-radius: 4px; font-size: 13px; }
.lapiz:hover { background: var(--surface-2); color: var(--text); }
.chips { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; margin-top: 4px; min-height: 18px; }
.chip { font-size: 11px; padding: 0 5px; border-radius: 4px; background: var(--surface-2); color: var(--text); white-space: nowrap; }
.chip b { font-weight: 600; color: var(--muted); }
.nota-ico { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }

.tot .h { font-weight: 600; font-size: 14px; }
.grilla.con-detalle .tot .h { margin-bottom: 2px; }
.interruptor { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; margin-right: 8px; }
.interruptor input { width: 16px; height: 16px; accent-color: var(--accent); }
.alerta { display: inline-block; margin-top: 3px; padding: 1px 6px; border-radius: 4px; font-size: 11px; white-space: normal; }
.alerta.warn { background: var(--warn-bg); color: var(--warn-text); }
.alerta.bad { background: var(--bad-bg); color: var(--bad-text); }

.leyenda { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: 12px; margin-top: 10px; }
.muestra-sugerido { background: var(--sug-bg); border: 1px solid var(--sug-line); padding: 0 6px; border-radius: 4px; }

/* Tablas de datos */
.datos { border-collapse: collapse; width: 100%; }
.datos th, .datos td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.datos th:first-child, .datos td:first-child { text-align: left; }
.datos thead th { background: var(--surface-2); font-size: 12px; font-weight: 600; }
.datos tfoot td { font-weight: 700; background: var(--surface-2); }
.datos .izq { text-align: left; }
.datos td.alerta-col { white-space: normal; min-width: 260px; max-width: 420px; }
.datos.compacta th, .datos.compacta td { padding: 4px 6px; }
.datos .grupo { text-align: center; border-left: 1px solid var(--line); }
.datos .borde-izq { border-left: 1px solid var(--line); }
.nota-pie { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* Ajustes */
.ajustes { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 16px 16px; min-width: 0; overflow-x: auto; }
#tabla-turnos input { padding: 3px 5px; }
#tabla-turnos input[name="horario"] { width: 11em; }
.lista { list-style: none; margin: 8px 0; padding: 0; max-height: 340px; overflow: auto; }
.lista li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.lista li .apagado { color: var(--muted); text-decoration: line-through; }
.lista.festivos li.pasado { color: var(--muted); }
.fila-form { display: flex; gap: 6px; margin-top: 8px; }
.fila-form.wrap { flex-wrap: wrap; }
.fila-form input[name="nombre"] { flex: 1; min-width: 0; }
.form-param { display: grid; gap: 10px; }
.form-param label { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.form-param label > span, .campo > span { display: flex; flex-direction: column; }
.form-param small, .campo small { color: var(--muted); font-size: 12px; font-weight: 400; }
.form-param input { width: 9em; flex-shrink: 0; }
.form-param .btn { justify-self: start; }
details.agregar { margin-top: 12px; }
details.agregar summary { cursor: pointer; color: var(--focus); }
details.agregar form { margin-top: 10px; }
.switch { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); cursor: pointer; }

/* Diálogo */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); width: min(520px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dlg { padding: 18px 20px; display: grid; gap: 14px; max-height: 88vh; overflow: auto; }
.dlg-filas { display: grid; gap: 12px; }
.bloque { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 10px; }
.bloque-titulo { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.campo { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.campo select { min-width: 13em; font-weight: 600; }
.campo input.nota { flex: 1; max-width: 17em; }
.campo input[type="number"] { width: 6em; text-align: right; }
.bloque details summary { cursor: pointer; color: var(--focus); }
.bloque details .campos { display: grid; gap: 10px; margin-top: 10px; padding-left: 12px; border-left: 2px solid var(--line); }
.bloque .quitar { justify-self: start; padding: 4px 10px; }
.mini-ancho { justify-self: start; }
.dlg-acciones { display: flex; gap: 8px; align-items: center; }
.espacio { flex: 1; }
.quitar { color: var(--bad-text); }

/* Quincenas cerradas */
.grilla thead th.cerrado { background: #e9e7e1; }
.grilla thead th .fest-cerrado { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }
.grilla td.celda.cerrada { background: #f1f0ec; }
.fijo { display: flex; gap: 3px; flex-wrap: wrap; flex: 1; }
.fijo .pill { opacity: .85; }
.candado { font-weight: 500; }
.estado-quincena { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  border-radius: var(--radius); padding: 12px 14px; margin: 10px 0 12px; border: 1px solid var(--line); }
.estado-quincena.abierta { background: var(--surface); }
.estado-quincena.cerrada { background: #f1f0ec; }
.estado-quincena:empty { display: none; }

/* Cuenta (encabezado) */
.cuenta { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cuenta-correo { color: var(--muted); font-size: 13px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.error-form { margin: 0; padding: 8px 10px; border-radius: 6px; background: var(--bad-bg); color: var(--bad-text); }
#dlg-clave { width: min(460px, 94vw); }
#dlg-clave h3 { margin-bottom: 4px; }

/* Ingreso */
.pagina-login { min-height: 100vh; display: grid; place-items: start center; }
.login { width: min(400px, 100%); padding: 12vh 16px 40px; }
.login h1 { font-size: 22px; text-align: center; margin-bottom: 20px; }
.tarjeta { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; display: grid; gap: 14px; }
.tarjeta h2 { margin: 0; font-size: 18px; }
.tarjeta .sub { margin: 0; }
.campo-col { display: grid; gap: 5px; font-weight: 500; }
.campo-col small { color: var(--muted); font-weight: 400; }
.campo-col input { padding: 9px 10px; font-size: 15px; }
.btn.ancho { width: 100%; padding: 9px 12px; font-size: 15px; }

/* Administración */
.admin { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.sin-margen { margin: 0; }
.lista-empresas { display: grid; gap: 14px; margin-top: 12px; }
.empresa { padding: 14px 16px; overflow: visible; }
.empresa.inactiva { opacity: .7; }
.empresa-cab { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.empresa-cab h3 { font-size: 17px; }
.empresa .usuarios { margin-bottom: 4px; }
.acciones-fila { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }
.estado { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 500; vertical-align: middle; }
.estado.ok { background: #e3f1e3; color: var(--ok-text); }
.estado.pendiente { background: var(--warn-bg); color: var(--warn-text); }
.estado.apagado { background: var(--surface-2); color: var(--muted); }
.form-usuario input { flex: 1; min-width: 0; }
.sel-perfil { padding: 3px 6px; }
@media (max-width: 900px) { .admin { grid-template-columns: 1fr; } }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px; font-weight: 500; z-index: 20;
}
.toast.error { background: var(--bad-text); color: #fff; }

@media (max-width: 640px) {
  .top { flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
  main { padding: 12px 16px 32px; }
  .sem-titulo { min-width: 0; }
}

/* Presentación (página pública de inicio) */
.pagina-inicio { background: var(--bg); }
.inicio-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.marca { font-weight: 700; font-size: 17px; }
.pagina-inicio main { max-width: 1080px; margin: 0 auto; padding: 32px 24px 48px; }
.btn.grande { padding: 10px 18px; font-size: 15px; }

.portada { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 36px; align-items: center; padding: 16px 0 40px; }
.portada h1 { font-size: 34px; line-height: 1.15; margin: 0 0 14px; letter-spacing: -.01em; }
.portada p { font-size: 16px; color: var(--muted); margin: 0 0 10px; max-width: 34em; }
.portada .entrada { font-size: 18px; color: var(--text); }
.portada-acciones { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }

.muestra { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06); }
.muestra figcaption { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }
.muestra-tabla { width: 100%; border-collapse: collapse; font-size: 13px; }
.muestra-tabla th, .muestra-tabla td { padding: 6px 4px; text-align: center; border-bottom: 1px solid var(--line); }
.muestra-tabla thead th { font-size: 11px; font-weight: 600; color: var(--muted); }
.muestra-tabla thead th.dom { color: var(--accent); }
.muestra-tabla tbody th { text-align: left; font-weight: 600; padding-right: 8px; }
.muestra-tabla td.num { font-weight: 700; }
.t { display: inline-block; min-width: 24px; padding: 3px 0; border-radius: 5px; font-weight: 700; font-size: 12px; text-align: center; }
.muestra .muestra-nota { font-size: 12px; max-width: none; color: var(--muted); margin: 10px 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.muestra-nota .t { min-width: 20px; padding: 1px 0; font-size: 11px; }

.bloque-inicio { padding: 28px 0; border-top: 1px solid var(--line); scroll-margin-top: 64px; }
.bloque-inicio h2 { font-size: 22px; margin: 0 0 16px; }
.tarjetas { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.tarjeta-info { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.tarjeta-info h3 { font-size: 15px; margin: 0 0 6px; }
.tarjeta-info p { margin: 0; color: var(--muted); }

.dos-columnas { display: grid; grid-template-columns: 1fr 1fr; gap: 36px; }
.dos-columnas p { margin: 0 0 10px; }
.lista-reglas, .lista-roles { margin: 0 0 12px; padding-left: 18px; display: grid; gap: 8px; }

.pasos { margin: 0 0 22px; padding: 0; list-style: none; counter-reset: paso; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.pasos li { counter-increment: paso; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: var(--muted); }
.pasos li::before { content: counter(paso); display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.pasos li b { color: var(--text); }

.inicio-pie { border-top: 1px solid var(--line); padding: 18px 24px 28px; text-align: center; color: var(--muted); font-size: 13px; }
.inicio-pie p { margin: 0; }
.login-inicio { text-align: center; margin-top: 14px; font-size: 13px; }
.login-inicio a { color: var(--focus); }

@media (max-width: 900px) {
  .portada { grid-template-columns: 1fr; gap: 24px; }
  .tarjetas { grid-template-columns: 1fr 1fr; }
  .pasos { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .inicio-top { padding: 10px 16px; }
  .pagina-inicio main { padding: 20px 16px 36px; }
  .portada h1 { font-size: 26px; }
  .portada .entrada { font-size: 16px; }
  .tarjetas, .pasos, .dos-columnas { grid-template-columns: 1fr; }
  .dos-columnas { gap: 20px; }
  .muestra { padding: 12px 10px; }
  .muestra-tabla { font-size: 12px; }
  .muestra-tabla th, .muestra-tabla td { padding: 5px 2px; }
  .t { min-width: 20px; }
}
