/* ===================================================================
   Sistema de horarios — estilos
   Color principal: #691B32, el burdeo de chocolatta.cl (meta theme-color)
   =================================================================== */
:root {
  --fondo: #F8F5F6;
  --superficie: #FFFFFF;
  --superficie-2: #FBF8F9;
  --borde: #E7DEE1;
  --texto: #2A1A20;
  --texto-suave: #6B5E63;
  --primario: #691B32;
  --primario-hover: #4F1325;
  --primario-claro: #F6E7EC;
  --ok: #1E7B4A;
  --ok-fondo: #E3F3EA;
  --aviso: #8A5A00;
  --aviso-fondo: #FFF3D6;
  --error: #B42318;
  --error-fondo: #FDECEA;
  --info: #1F5C99;
  --info-fondo: #E7F0FA;
  --radio: 10px;
  --sombra: 0 1px 2px rgba(42, 26, 32, .06), 0 2px 8px rgba(42, 26, 32, .05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fondo); color: var(--texto);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--primario); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: .25rem 0 .75rem; }
.suave { color: var(--texto-suave); }
.pequeno { font-size: .85rem; }

/* ---------- barra superior ---------- */
.barra {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1.25rem; background: var(--primario); color: #fff;
}
.marca { color: #fff; font-weight: 700; font-size: 1.1rem; text-decoration: none; white-space: nowrap; }
.marca span { opacity: .7; font-weight: 400; }
.menu { display: flex; gap: .25rem; overflow-x: auto; flex: 1; scrollbar-width: none; }
.menu::-webkit-scrollbar { display: none; }
.menu a {
  color: #F8E8EE; text-decoration: none; padding: .4rem .7rem; border-radius: 8px; white-space: nowrap; font-size: .95rem;
}
.menu a:hover { background: rgba(255,255,255,.12); }
.menu a.activo { background: #fff; color: var(--primario); font-weight: 600; }
.salir button { background: transparent; border: 1px solid rgba(255,255,255,.4); color: #fff; }
.salir button:hover { background: rgba(255,255,255,.12); }

.contenido { max-width: 1240px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.encabezado { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }

/* ---------- tarjetas ---------- */
.tarjeta {
  background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio);
  box-shadow: var(--sombra); padding: 1.25rem; margin-bottom: 1.25rem;
}
.tarjeta > h2:first-child { margin-top: 0; }
.columnas { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; }
.columnas-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 1.25rem; align-items: start; }

/* ---------- botones ---------- */
button, .boton {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; padding: .55rem 1rem; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--borde); background: var(--superficie); color: var(--texto); text-decoration: none;
  line-height: 1.2; min-height: 40px;
}
button:hover, .boton:hover { background: var(--superficie-2); }
.primario { background: var(--primario); border-color: var(--primario); color: #fff; }
.primario:hover { background: var(--primario-hover); }
.grande { padding: .8rem 1.5rem; font-size: 1.05rem; }
.peligro { color: var(--error); border-color: #F1C4BF; }
.peligro:hover { background: var(--error-fondo); }
.enlace { background: none; border: none; color: var(--primario); padding: .25rem .4rem; min-height: auto; font-weight: 500; }
.enlace:hover { background: none; text-decoration: underline; }
.enlace.peligro { color: var(--error); }
.acciones { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
form.en-linea { display: inline; }

/* ---------- formularios ---------- */
.campo { margin-bottom: 1rem; }
.campo > label, .etiqueta { display: block; font-weight: 600; margin-bottom: .3rem; }
.ayuda { color: var(--texto-suave); font-size: .85rem; margin-top: .25rem; }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], input[type=time], select, textarea {
  font: inherit; width: 100%; padding: .55rem .7rem; border: 1px solid #D2C5CA; border-radius: 8px;
  background: #fff; color: var(--texto); min-height: 40px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, .boton:focus-visible {
  outline: 3px solid #E2B8C5; outline-offset: 1px; border-color: var(--primario);
}
input[type=number] { max-width: 9rem; }
input[type=color] { width: 56px; height: 40px; padding: 2px; border: 1px solid #D2C5CA; border-radius: 8px; background: #fff; }
.lista-casillas { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .5rem 1rem; }
.fila-campos { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.con-error input, .con-error select { border-color: var(--error); }
.error-campo { color: var(--error); font-size: .85rem; margin-top: .25rem; font-weight: 600; }
.casilla { display: flex; align-items: center; gap: .5rem; font-weight: 500; cursor: pointer; }
.casilla input { width: 18px; height: 18px; accent-color: var(--primario); }
fieldset { border: none; padding: 0; margin: 0; }
.seccion { border-top: 1px solid var(--borde); padding-top: 1rem; margin-top: 1rem; }
.seccion:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }

/* ---------- selector de días ---------- */
.dias { display: flex; flex-wrap: wrap; gap: .4rem; }
.dia input { position: absolute; opacity: 0; pointer-events: none; }
.dia span {
  display: inline-flex; align-items: center; justify-content: center; min-width: 52px; height: 40px;
  padding: 0 .6rem; border: 1px solid #D2C5CA; border-radius: 999px; cursor: pointer; user-select: none;
  background: #fff; font-weight: 600; color: var(--texto-suave);
}
.dia input:checked + span { background: var(--primario); border-color: var(--primario); color: #fff; }
.dia input:focus-visible + span { outline: 3px solid #E2B8C5; }
.rapidos { display: flex; gap: .25rem; flex-wrap: wrap; margin-top: .4rem; }
.rapidos button { min-height: 30px; padding: .2rem .6rem; font-size: .8rem; font-weight: 500; }

/* ---------- días en 3 estados (Sí / Si falta / No) ---------- */
.dias-3 { display: grid; grid-template-columns: repeat(7, minmax(78px, 1fr)); gap: .4rem; }
.dia-3 { display: flex; flex-direction: column; border: 1px solid #D2C5CA; border-radius: 8px; overflow: hidden; background: #fff; }
.dia-3 strong { text-align: center; padding: .3rem 0; background: var(--superficie-2); border-bottom: 1px solid #D2C5CA; font-size: .9rem; }
.dia-3 label { position: relative; }
.dia-3 input { position: absolute; opacity: 0; }
.dia-3 span { display: block; text-align: center; padding: .35rem .2rem; cursor: pointer; font-size: .85rem; border-top: 1px solid #F0E8EB; }
.dia-3 label:nth-of-type(1) span { border-top: none; }
.dia-3 input[value=si]:checked + span { background: var(--primario); color: #fff; font-weight: 700; }
.dia-3 input[value=si_falta]:checked + span { background: #A8566F; color: #fff; font-weight: 700; }
.dia-3 input[value=no]:checked + span { background: #EFE9EB; color: var(--texto-suave); font-weight: 700; }
.dia-3 input:focus-visible + span { outline: 3px solid #E2B8C5; outline-offset: -3px; }

/* ---------- turnos agrupados por lugar ---------- */
.grupo-turnos { border: 1px solid var(--borde); border-radius: 8px; padding: .75rem .9rem; margin-bottom: .75rem; background: var(--superficie-2); }
.grupo-turnos-titulo { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.grupo-turnos-titulo legend { float: left; padding: 0; }
.grupo-turnos-titulo .rapidos { margin-top: 0; }

/* ---------- control segmentado (No / Sí / Solo si falta) ---------- */
.segmentado { display: inline-flex; border: 1px solid #D2C5CA; border-radius: 8px; overflow: hidden; }
.segmentado label { position: relative; }
.segmentado input { position: absolute; opacity: 0; }
.segmentado span { display: block; padding: .4rem .8rem; cursor: pointer; font-size: .9rem; border-left: 1px solid #D2C5CA; background: #fff; white-space: nowrap; }
.segmentado label:first-child span { border-left: none; }
.segmentado input:checked + span { background: var(--primario); color: #fff; font-weight: 600; }
.segmentado input[value=respaldo]:checked + span { background: #A8566F; }
.segmentado input:focus-visible + span { outline: 3px solid #E2B8C5; outline-offset: -3px; }

/* ---------- tablas ---------- */
.tabla-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--borde); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--texto-suave); font-weight: 700; background: var(--superficie-2); }
tr.inactivo td { opacity: .55; }
td.acciones-celda { text-align: right; white-space: nowrap; }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip {
  display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .55rem; border-radius: 999px;
  font-size: .82rem; font-weight: 600; background: var(--primario-claro); color: var(--texto); white-space: nowrap;
  border: 1px solid rgba(0,0,0,.06);
}
.chip.respaldo { background: #fff !important; border: 1px dashed #A8566F; color: #7E3A50; }
.chip.gris { background: #EFE9EB; color: var(--texto-suave); }
.muestra { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(0,0,0,.15); vertical-align: middle; }
.etiqueta-estado { font-size: .75rem; font-weight: 700; padding: .05rem .45rem; border-radius: 6px; background: #EFE9EB; color: var(--texto-suave); margin-left: .35rem; }

/* ---------- mensajes ---------- */
.mensajes { margin-bottom: 1rem; display: grid; gap: .5rem; }
.mensaje { padding: .75rem 1rem; border-radius: 8px; border: 1px solid; font-weight: 500; }
.mensaje.ok { background: var(--ok-fondo); border-color: #B5DFC6; color: #145A35; }
.mensaje.aviso { background: var(--aviso-fondo); border-color: #F0D58A; color: #6B4600; }
.mensaje.error { background: var(--error-fondo); border-color: #F4C2BD; color: #8F1B12; }
.lista-alertas { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }
.lista-alertas li { padding: .5rem .75rem; border-radius: 8px; border-left: 4px solid; font-size: .92rem; }
.lista-alertas li.error { background: var(--error-fondo); border-color: var(--error); }
.lista-alertas li.aviso { background: var(--aviso-fondo); border-color: #D9A21B; }
.lista-alertas li.info { background: var(--info-fondo); border-color: var(--info); }
.insignia { display: inline-block; min-width: 1.6rem; text-align: center; padding: .05rem .45rem; border-radius: 999px; font-size: .8rem; font-weight: 700; }
.insignia.error { background: var(--error); color: #fff; }
.insignia.aviso { background: #D9A21B; color: #fff; }
.insignia.ok { background: var(--ok); color: #fff; }

/* ---------- grilla del horario ---------- */
.grilla { min-width: 980px; table-layout: fixed; }
.grilla th, .grilla td { border: 1px solid var(--borde); padding: .35rem .4rem; text-align: center; font-size: .85rem; }
.grilla th.nombre, .grilla td.nombre { text-align: left; width: 210px; position: sticky; left: 0; background: var(--superficie); z-index: 1; }
.grilla th.nombre { background: var(--superficie-2); }
.grilla th.num, .grilla td.num { width: 62px; }
.grilla td.nombre strong { display: block; font-size: .9rem; }
.grilla td.nombre small { color: var(--texto-suave); font-size: .75rem; }
.grilla tr.grupo td { background: #3D1020; color: #fff; text-align: left; font-weight: 700; letter-spacing: .03em; font-size: .8rem; text-transform: uppercase; }
.grilla td.turno { font-weight: 600; line-height: 1.25; color: #1F181B; }
.grilla td.turno small { display: block; font-weight: 500; font-size: .75rem; }
.grilla td.turno.respaldo { font-style: italic; box-shadow: inset 0 0 0 2px #A8566F; }
.grilla td.libre { background: #F7D4D4; color: #8F1B12; font-weight: 700; }
.grilla td.vacaciones { background: #FFFFFF; font-weight: 700; color: var(--info); }
.grilla td.no_trabaja { background: #F3F0F1; color: #B3A7AC; }
.grilla td.cerrado { background: #DAD4D6; color: #6B5E63; }
.grilla tr.faltas td { background: var(--superficie-2); font-weight: 700; }
.grilla tr.faltas td.mal { background: var(--error-fondo); color: var(--error); }
.grilla tr.faltas td.bien { color: var(--ok); }

details { border: 1px solid var(--borde); border-radius: 8px; padding: .25rem .9rem; margin-top: .75rem; background: var(--superficie-2); }
details summary { cursor: pointer; font-weight: 600; padding: .5rem 0; }
details[open] { padding-bottom: .9rem; }

.resumen { display: flex; gap: 1rem; flex-wrap: wrap; margin: .5rem 0 1rem; }
.dato { background: var(--superficie-2); border: 1px solid var(--borde); border-radius: 8px; padding: .6rem .9rem; min-width: 120px; }
.dato { color: var(--texto); text-decoration: none; }
a.dato:hover { border-color: var(--primario); }
.dato strong { display: block; font-size: 1.4rem; line-height: 1.1; }
.dato span { color: var(--texto-suave); font-size: .85rem; }

/* ---------- pantalla de carga ---------- */
#cargando {
  position: fixed; inset: 0; background: rgba(248, 245, 246, .9); display: none; z-index: 50;
  align-items: center; justify-content: center; flex-direction: column; gap: 1rem; text-align: center; padding: 1rem;
}
#cargando.visible { display: flex; }
.rueda { width: 44px; height: 44px; border: 4px solid var(--primario-claro); border-top-color: var(--primario); border-radius: 50%; animation: girar 1s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }

/* ---------- entrar ---------- */
.caja-entrar { max-width: 380px; margin: 10vh auto 0; }
.caja-entrar h1 { text-align: center; margin-bottom: 1rem; }

/* ---------- requisitos del turno ---------- */
.fila-req { display: grid; grid-template-columns: 1fr 110px auto; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.fila-req input[type=number] { max-width: none; }

/* ---------- filtros de trabajadores ---------- */
.filtros { display: grid; grid-template-columns: 2fr repeat(5, minmax(140px, 1fr)); gap: .75rem; align-items: end; }
.filtros .campo { margin-bottom: 0; }
.filtros label { font-size: .85rem; }
.resultado-filtro { display: flex; align-items: center; gap: .75rem; margin: .9rem 0 .5rem; color: var(--texto-suave); font-size: .9rem; }

/* ---------- personas de un turno ---------- */
.grilla td.nombre a { color: inherit; text-decoration: none; }
.grilla td.nombre a:hover strong { text-decoration: underline; color: var(--primario); }
.personas-turno summary { cursor: pointer; color: var(--primario); font-weight: 600; white-space: nowrap; }
.personas-turno ul { margin: .4rem 0 .2rem; padding-left: 1.1rem; font-size: .9rem; columns: 2; column-gap: 1.5rem; }
.personas-turno li { break-inside: avoid; margin-bottom: .15rem; }
.celda-personas { min-width: 150px; }
@media (max-width: 860px) { .personas-turno ul { columns: 1; } }

/* ---------- deslizador de horario (dos manillas: entrada y salida) ---------- */
/* Caja que contiene todo el deslizador */
.rango { position: relative; padding: .4rem 0 0; user-select: none; }
/* Zona donde están la barra y las dos manillas, con altura fija */
.rango-zona { position: relative; height: 34px; }
/* Barra gris de fondo: representa todo el día (de la apertura al cierre) */
.rango-pista { position: absolute; left: 0; right: 0; top: 13px; height: 8px; border-radius: 99px; background: #EFE9EB; }
/* Parte pintada en burdeo: las horas que va a trabajar */
.rango-relleno { position: absolute; top: 0; bottom: 0; border-radius: 99px; background: var(--primario); }
/* Los dos controles se dibujan uno encima del otro, sin su barra propia */
.rango input[type=range] {
  position: absolute; left: 0; top: 4px; width: 100%; height: 26px; margin: 0;
  background: none; pointer-events: none; -webkit-appearance: none; appearance: none;
}
/* Manilla en Chrome/Edge/Safari: círculo blanco con borde burdeo, que sí recibe el mouse o el dedo */
.rango input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; pointer-events: auto; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; border: 3px solid var(--primario); cursor: grab; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
/* Manilla en Firefox (mismo dibujo) */
.rango input[type=range]::-moz-range-thumb {
  pointer-events: auto; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 3px solid var(--primario); cursor: grab;
}
/* Borde visible cuando se usa el teclado (accesibilidad) */
.rango input[type=range]:focus-visible::-webkit-slider-thumb { outline: 3px solid #E2B8C5; }
/* Fila de abajo: hora de apertura, el resultado al centro y la hora de cierre */
.rango-etiquetas { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; font-size: .8rem; color: var(--texto-suave); }
/* El resultado ("17:30 a 22:30 · 5 h") destacado */
.rango-texto { font-size: .95rem; font-weight: 700; color: var(--texto); text-align: center; }
/* Botones rápidos bajo el deslizador (Completo, primeras 5 h, últimas 5 h) */
.rango-rapidos { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .35rem; }
.rango-rapidos button { min-height: 30px; padding: .15rem .6rem; font-size: .8rem; font-weight: 500; }

/* ---------- horario propio en la ficha del trabajador ---------- */
/* Cada turno de la lista ocupa una fila con la casilla y el ajuste de horas */
.turno-fila { border-bottom: 1px dashed var(--borde); padding: .45rem 0; }
.turno-fila:last-child { border-bottom: none; }
/* El desplegable "Ajustar horario" */
.ajuste-horario { margin: .35rem 0 0 1.7rem; border: none; background: none; padding: 0; }
.ajuste-horario summary { font-size: .85rem; padding: .1rem 0; color: var(--primario); }
.ajuste-horario[open] { padding-bottom: .3rem; }
/* Si la casilla del turno no está marcada, el ajuste se ve apagado */
.turno-fila.apagado .ajuste-horario { opacity: .45; pointer-events: none; }
/* Etiqueta pequeña "horario propio" junto al nombre del turno */
.etiqueta-propio { font-size: .72rem; font-weight: 700; background: var(--primario-claro); color: var(--primario); border-radius: 6px; padding: .05rem .4rem; margin-left: .3rem; }

/* ---------- pie de página ---------- */
.pie { text-align: center; color: var(--texto-suave); font-size: .85rem; padding: 1.5rem 1rem 2rem; border-top: 1px solid var(--borde); }
.pie strong { color: var(--primario); }

/* ---------- celular ---------- */
@media (max-width: 860px) {
  .columnas, .columnas-2-1 { grid-template-columns: 1fr; }
  .barra { flex-wrap: wrap; gap: .5rem; padding: .5rem 1rem; }
  .menu { order: 3; flex-basis: 100%; }
  .salir { margin-left: auto; }
  .contenido { padding: 1rem 1rem 3rem; }
  .tarjeta { padding: 1rem; }
  h1 { font-size: 1.35rem; }
  .ocultar-movil { display: none; }
  .grilla { min-width: 820px; }
  .grilla th.nombre, .grilla td.nombre { width: 120px; }
  .grilla td.nombre small { display: none; }
  .grilla th.num, .grilla td.num { width: 46px; }
  .segmentado span { padding: .4rem .55rem; }
  .dias-3 { grid-template-columns: repeat(4, 1fr); }
  .filtros { grid-template-columns: 1fr 1fr; }
  .filtro-buscar { grid-column: 1 / -1; }
}
@media (min-width: 861px) and (max-width: 1150px) {
  .filtros { grid-template-columns: repeat(3, 1fr); }
  .filtro-buscar { grid-column: 1 / -1; }
}
@media print {
  .barra, .acciones, details, .no-imprimir { display: none !important; }
  body { background: #fff; }
  .tarjeta { box-shadow: none; border: none; padding: 0; }
}

/* Turno: panel "Agregar trabajador" */
.agregar-personas { margin: .25rem 0 1rem; padding: 0; border: none; background: none; }
.agregar-personas > summary { list-style: none; display: inline-flex; cursor: pointer; }
.agregar-personas > summary::-webkit-details-marker { display: none; }
.agregar-personas[open] > summary { background: var(--primario-claro); border-color: var(--primario); }
.agregar-caja { margin-top: .75rem; padding: .9rem 1rem; border: 1px solid var(--borde); border-radius: var(--radio); background: var(--superficie-2); }
.agregar-caja h3 { margin: .8rem 0 .2rem; font-size: 1rem; }
.lista-agregar { list-style: none; margin: .3rem 0 .6rem; padding: 0; max-height: 22rem; overflow-y: auto; }
.lista-agregar li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .45rem .3rem; border-bottom: 1px solid var(--borde); }
.lista-agregar li:last-child { border-bottom: none; }
.recien-agregado td { background: var(--aviso-fondo); }

/* v3.3: tabla de reglas del domingo en Configuración */
.tabla-reglas select { width: 100%; min-width: 7.5rem; }
.tabla-reglas td { padding: .35rem .4rem; }
