/* Colores tomados de la plantilla original */
:root {
  --encabezado: #fff2cc;     /* amarillo claro de los encabezados de fecha */
  --borde: #222;
  --rojo-horario: #e0261b;
  --primario: #1f5fa8;
  --peligro: #b3261e;
  --gris: #6b6b6b;
  --fondo: #f6f6f4;
  --exito: #e6f4ea;
  --error: #fdecea;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: #1b1b1b;
  font-size: 16px;
}

/* Barra superior */
.barra {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: #fff; border-bottom: 1px solid #ddd; padding: .6rem 1rem;
  position: sticky; top: 0; z-index: 10;
}
.marca { font-weight: 700; text-decoration: none; color: inherit; }
.barra nav { display: flex; gap: .25rem; flex: 1; }
.barra nav a { text-decoration: none; color: var(--gris); padding: .4rem .7rem; border-radius: 6px; }
.barra nav a.activo { background: var(--encabezado); color: #000; font-weight: 600; }
.salir { margin: 0; }

.contenido { max-width: 980px; margin: 0 auto; padding: 1rem; }
h1 { font-size: 1.4rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.1rem; }

.encabezado { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.encabezado h1 { margin: 0; }

/* Botones (tamaño cómodo para el dedo) */
.btn {
  display: inline-block; min-height: 44px; padding: .55rem 1rem;
  border: 1px solid #bbb; border-radius: 8px; background: #fff; color: inherit;
  font: inherit; text-decoration: none; cursor: pointer; line-height: 1.6;
}
.btn:hover { background: #f0f0f0; }
.btn-primario { background: var(--primario); border-color: var(--primario); color: #fff; font-weight: 600; }
.btn-primario:hover { background: #174a83; }
.btn-peligro { color: var(--peligro); border-color: #e2b4b0; }
.btn-chico { min-height: 36px; padding: .3rem .7rem; font-size: .9rem; }
.btn-link { background: none; border: 0; color: var(--gris); cursor: pointer; font: inherit; text-decoration: underline; }
button:disabled { opacity: .6; cursor: wait; }

/* Mensajes */
.mensajes { list-style: none; padding: 0; margin: 0 0 1rem; }
.mensajes li { padding: .7rem 1rem; border-radius: 8px; margin-bottom: .4rem; background: var(--exito); }
.mensajes .msg-error { background: var(--error); }

.vacio {
  background: #fff; border: 2px dashed #ccc; border-radius: 10px;
  padding: 1.5rem; text-align: center; margin: 1rem 0; color: #444;
}
.nota { color: var(--gris); font-size: .9rem; }
.error { color: var(--peligro); margin: .2rem 0 0; font-size: .9rem; }

/* Formularios */
.form-simple, .modal form { display: flex; flex-direction: column; gap: .35rem; max-width: 420px; }
.form-simple label, .modal label { font-weight: 600; margin-top: .5rem; }
input[type=text], input[type=search], input[type=password], input[type=time], input[type=date], select {
  font: inherit; padding: .6rem .7rem; border: 1px solid #bbb; border-radius: 8px; min-height: 44px; width: 100%;
  background: #fff;
}
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
label.check input { width: 22px; height: 22px; }
.grupo-radios { border: 0; padding: 0; margin: .5rem 0 0; display: flex; flex-direction: column; gap: .25rem; }
.grupo-radios legend { font-weight: 600; padding: 0; }
.grupo-radios label { font-weight: 400; display: flex; align-items: center; gap: .5rem; margin: 0;
  padding: .45rem .6rem; border: 1px solid #ddd; border-radius: 8px; }
.grupo-radios input { width: 20px; height: 20px; }
.acciones { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.modal-errores { background: var(--error); color: var(--peligro); border-radius: 8px; padding: .5rem .8rem; }
.modal-errores p { margin: .2rem 0; }

/* Modal */
.modal { border: 0; border-radius: 12px; padding: 1.2rem; width: min(440px, 94vw); }
.modal::backdrop { background: rgba(0, 0, 0, .4); }
.modal h2 { margin: 0 0 .5rem; }

/* Personas */
.filtros { display: flex; gap: .5rem; margin: 1rem 0; flex-wrap: wrap; }
.filtros input { flex: 1 1 200px; width: auto; }
.filtros select { width: auto; }
.grupo-titulo { background: #d9d9d9; padding: .4rem .7rem; border-radius: 6px; margin: 1.2rem 0 .4rem; }
.cuenta { font-weight: 400; color: var(--gris); font-size: .9rem; }
.lista-personas { list-style: none; margin: 0; padding: 0; background: #fff; border-radius: 8px; border: 1px solid #e3e3e3; }
.lista-personas li {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .5rem .7rem; border-bottom: 1px solid #eee;
}
.lista-personas li:last-child { border-bottom: 0; }
.lista-personas .nombre { font-weight: 600; flex: 1 1 auto; }
.lista-personas li.inactiva .nombre { color: var(--gris); text-decoration: line-through; }
.etiqueta { font-size: .75rem; background: #eee; border-radius: 99px; padding: .1rem .5rem; color: #444; }
.etiqueta-info { background: #e3eefb; }
.acciones-fila { display: flex; gap: .35rem; flex-wrap: wrap; }
.acciones-fila form { margin: 0; }

/* Tabla tipo plantilla */
.tabla-plantilla { border-collapse: collapse; background: #fff; text-align: center; }
.tabla-plantilla th, .tabla-plantilla td { border: 2px solid var(--borde); padding: .45rem .8rem; }
.tabla-plantilla th { background: var(--encabezado); font-weight: 700; }
.fila-horario td, .fila-horario th { color: var(--rojo-horario); font-weight: 700; background: #fff; }

.login { max-width: 380px; margin: 3rem auto; background: #fff; padding: 1.5rem; border-radius: 12px; }

@media (max-width: 600px) {
  .contenido { padding: .7rem; }
  .acciones-fila { width: 100%; }
}

/* ---------- Grilla de la plantilla ---------- */
.plantilla-contenedor { overflow-x: auto; margin: .5rem 0 1rem; -webkit-overflow-scrolling: touch; }
.grilla { width: 100%; min-width: 340px; table-layout: fixed; }
.grilla th, .grilla td { padding: 0; height: 44px; }
.grilla col, .grilla th:first-child { width: 18%; }
.grilla .fila-cabecera th { height: 40px; }
.grilla .celda-rol { background: #fff; }
.grilla .col-central { width: 22%; }
.celda {
  width: 100%; height: 100%; min-height: 44px; border: 0; background: #fff; font: inherit;
  cursor: pointer; padding: .2rem .3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.celda:empty::after { content: "+"; color: #c4c4c4; font-size: 1.2rem; }
.celda:hover, .celda:focus-visible { background: #fffbea; outline: 2px solid var(--primario); outline-offset: -2px; }
.celda.inactiva { color: var(--gris); font-style: italic; }
.con-error { background: var(--error) !important; box-shadow: inset 0 0 0 3px var(--peligro); }
.celda-fecha { position: relative; }
.btn-fecha { background: none; border: 0; font: inherit; font-weight: 700; cursor: pointer; padding: .3rem; width: 100%; }
.btn-fecha .flecha { font-size: .7rem; color: var(--gris); margin-left: .15rem; }
.btn-fecha.no-viernes { color: var(--peligro); text-decoration: underline wavy; }
.input-fecha-oculto { position: absolute; inset: 0; opacity: 0; pointer-events: none; width: 100%; }
.quitar-fecha {
  position: absolute; top: 2px; left: 2px; border: 0; background: none; color: #a0a0a0; cursor: pointer;
  font-size: .75rem; padding: .1rem .25rem;
}
.quitar-fecha:hover { color: var(--peligro); }
.celda-central { background: #fff; }
.toggle-central {
  width: 100%; height: 132px; border: 0; background: #fff; font: inherit; font-weight: 700;
  color: #9a9a9a; cursor: pointer;
}
.toggle-central.si { color: #1d7a35; background: #eef8f0; }
.fila-horario input[type=time] {
  border: 0; color: var(--rojo-horario); font-weight: 700; text-align: center; min-height: 40px; padding: 0; background: transparent;
}

.barra-acciones {
  display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; align-items: center;
  position: sticky; bottom: 0; background: var(--fondo); padding: .6rem 0; border-top: 1px solid #e1e1e1;
}
.barra-acciones form { margin: 0; }
.btn-grande { min-width: 140px; font-size: 1.05rem; }
.aviso { background: #fff7e0; border: 1px solid #f0d58a; border-radius: 8px; padding: .6rem .8rem; margin: .5rem 0; }
.texto-alerta { color: #a15c00; }
.etiqueta-alerta { background: #ffe6bf; color: #7a4300; }
#errores-grilla ul { margin: .3rem 0 0; padding-left: 1.2rem; }

/* Selector de personas */
.selector { width: min(460px, 96vw); max-height: 85vh; display: none; flex-direction: column; gap: .5rem; padding: .9rem; }
.selector[open] { display: flex; }
.selector-cabecera { display: flex; justify-content: space-between; align-items: center; }
.selector-lista { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 120px; }
.opcion {
  display: flex; justify-content: space-between; align-items: center; width: 100%; min-height: 46px;
  border: 0; border-bottom: 1px solid #eee; background: #fff; font: inherit; text-align: left; cursor: pointer; padding: .4rem .6rem;
}
.opcion:hover:not(:disabled) { background: #fffbea; }
.opcion:disabled { color: #aaa; cursor: not-allowed; }
.opcion.actual { font-weight: 700; background: var(--encabezado); }
.opcion-vacia { color: var(--gris); }
.opcion-nueva { color: var(--primario); font-weight: 600; }
.grupo-chico { color: var(--gris); font-size: .75rem; }
.sin-resultados { padding: .6rem; }

/* Preview */
.modal-ancho { width: min(720px, 96vw); }
.preview-bloque { margin-bottom: .8rem; overflow-x: auto; }
.tabla-preview { width: 100%; font-size: .9rem; }
.tabla-preview th, .tabla-preview td { padding: .3rem .4rem; border-width: 1px; }
.tabla-preview td.vacia { color: #aaa; }

@media (max-width: 600px) {
  .grilla { font-size: .85rem; }
  .barra-acciones { justify-content: stretch; }
  .barra-acciones .btn { flex: 1; }
}

/* Ajustes de grilla para pantallas chicas */
.btn-fecha { white-space: nowrap; padding-left: 1rem; }
.tabla-preview { table-layout: fixed; }
@media (max-width: 600px) {
  .barra { gap: .4rem; padding: .4rem .6rem; }
  .marca { display: none; }
  .barra nav a { padding: .4rem .5rem; }
  .grilla th:first-child { width: 21%; }
  .grilla .col-central { width: 19%; font-size: .7rem; }
  .btn-fecha { font-size: .8rem; padding-left: .8rem; padding-right: 0; }
  .btn-fecha .flecha { display: none; }
  .quitar-fecha { top: 0; left: 0; }
  .encabezado h1 { font-size: 1.2rem; }
}

/* ---------- Planificaciones por mes ---------- */
.tarjetas-meses { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .6rem; }
.tarjeta-mes {
  display: flex; flex-direction: column; gap: .3rem; padding: .9rem 1rem; background: #fff;
  border: 1px solid #e3e3e3; border-left: 6px solid #f2d98a; border-radius: 10px; text-decoration: none; color: inherit;
}
.tarjeta-mes:hover { border-color: var(--primario); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.tarjeta-mes-nombre { font-weight: 700; font-size: 1.1rem; }
.tarjeta-mes-fechas { color: var(--gris); font-size: .9rem; }
.tarjeta-mes-etiquetas { display: flex; gap: .3rem; flex-wrap: wrap; }

.nav-mes { display: flex; align-items: center; gap: .5rem; }
.nav-mes h1 { margin: 0; min-width: 9ch; text-align: center; }
.pestanias { display: flex; gap: .25rem; margin: 1rem 0 .5rem; border-bottom: 2px solid #ddd; }
.pestanias a {
  padding: .55rem 1.1rem; text-decoration: none; color: var(--gris); border-radius: 8px 8px 0 0;
  margin-bottom: -2px; border-bottom: 3px solid transparent; font-weight: 600;
}
.pestanias a.activa { color: #000; border-bottom-color: var(--primario); background: #fff; }
.punto { color: #e08a00; font-size: .7rem; vertical-align: middle; }

.grilla-lectura td { padding: .3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: #fff; }
.grilla-lectura td.vacia { color: #9a9a9a; }
.grilla-lectura .celda-fecha { padding: .3rem; }
.celda-central-lectura { font-weight: 700; color: #9a9a9a; }
.celda-central-lectura.si { color: #1d7a35; background: #eef8f0 !important; }
.grilla-lectura td.cambio, .muestra-cambio { background: #ffe6bf !important; box-shadow: inset 0 0 0 2px #e0a040; }
.muestra-cambio { display: inline-block; width: 1em; height: 1em; vertical-align: middle; border-radius: 3px; }

.mas-acciones { position: relative; }
.mas-acciones summary { list-style: none; }
.mas-acciones summary::-webkit-details-marker { display: none; }
.mas-acciones-menu {
  position: absolute; bottom: 110%; left: 0; background: #fff; border: 1px solid #ddd; border-radius: 10px;
  padding: .5rem; display: flex; flex-direction: column; gap: .35rem; min-width: 190px; box-shadow: 0 4px 16px rgba(0,0,0,.12); z-index: 5;
}
.mas-acciones-menu .btn { width: 100%; text-align: left; }

.selector-mes { display: flex; align-items: center; gap: .6rem; margin: .8rem 0; flex-wrap: wrap; }
.selector-mes label { font-weight: 600; }
.selector-mes input { width: auto; }
@media (max-width: 600px) {
  .barra-acciones { flex-wrap: nowrap; }
  .barra-acciones form, .barra-acciones .mas-acciones { flex: 1; }
  .barra-acciones form .btn, .barra-acciones .mas-acciones summary { width: 100%; text-align: center; font-size: .9rem; }
  .barra-acciones .btn-grande { min-width: 0; }
}

/* ---------- Matriz ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.filtros-matriz { margin: 0; }
.contenido:has(.matriz) { max-width: none; }
.matriz-contenedor {
  overflow: auto; max-height: 75vh; background: #fff; border: 1px solid #ccc; border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}
.matriz { border-collapse: separate; border-spacing: 0; font-size: .85rem; }
.matriz th, .matriz td {
  border-right: 1px solid #d0d0d0; border-bottom: 1px solid #d0d0d0; padding: .3rem .4rem;
  text-align: center; white-space: nowrap; min-width: 2.6rem; background: #fff;
}
.matriz .fila-meses th { background: #fff; font-weight: 700; }
.matriz .fila-fechas th { background: #fff2cc; font-weight: 600; }
.matriz .fila-fechas a { color: inherit; text-decoration: none; }
.matriz .fila-fechas a:hover { text-decoration: underline; }
.matriz .fila-tipo th { background: #93c47d; font-weight: 400; font-size: .75rem; }
.matriz .col-nombre {
  position: sticky; left: 0; z-index: 1; text-align: left; min-width: 9rem; max-width: 11rem;
  overflow: hidden; text-overflow: ellipsis; font-weight: 600; background: #fff;
  border-right: 2px solid #999;
}
.matriz .fila-grupo th, .matriz .fila-grupo td { background: #d9d9d9; font-weight: 700; }
.matriz tr.inactiva .col-nombre { color: var(--gris); font-style: italic; }
.matriz .col-total { background: #f4f7fb; font-size: .8rem; }
.matriz thead .col-total { background: #dbe5f1; white-space: normal; min-width: 4.2rem; font-size: .72rem; line-height: 1.1; }
.matriz .fuerte { font-weight: 700; }
.matriz td.t-M1 { background: #e3effd; }
.matriz td.t-M2 { background: #e6f5e6; }
.matriz td.t-M3 { background: #fdeede; }
.matriz tfoot th, .matriz tfoot td { background: #dbe5f1; font-weight: 600; }
.matriz tfoot .col-nombre { background: #dbe5f1; }
.matriz .etiqueta-resumen { font-size: .72rem; text-align: right; }
.matriz td.central-no { color: var(--peligro); }
/* Encabezado fijo como un bloque (evita que las filas se superpongan al hacer scroll) */
.matriz thead { position: sticky; top: 0; z-index: 4; }
.matriz thead th.col-nombre { position: sticky; left: 0; z-index: 5; }
@media (max-width: 600px) {
  .barra { flex-wrap: nowrap; }
  .barra nav { overflow-x: auto; scrollbar-width: none; }
  .barra nav a { font-size: .88rem; padding: .4rem .45rem; white-space: nowrap; }
  .salir .btn-link { font-size: .88rem; }
}
.etiqueta-central { background: #eef8f0; color: #1d6b31; }
.toggle-central:empty::after { content: "+"; color: #c4c4c4; font-size: 1.2rem; font-weight: 400; }
.toggle-central { color: #1b1b1b; padding: .3rem; overflow-wrap: anywhere; }
.toggle-central.si { color: #1d6b31; }
.toggle-central.inactiva { font-style: italic; color: var(--gris); }
.toggle-central:hover, .toggle-central:focus-visible { outline: 2px solid var(--primario); outline-offset: -2px; }

/* ---------- Eventos especiales ---------- */
.acciones-encabezado { display: flex; gap: .5rem; flex-wrap: wrap; }
.tarjeta-mes-eventos { font-size: .85rem; color: #6a3fa0; }
.etiqueta-evento { background: #efe6fa; color: #5a2d91; }
.titulo-eventos { margin: 1.2rem 0 .5rem; }
.eventos { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .6rem; }
.evento { background: #fff; border: 1px solid #e3e3e3; border-left: 6px solid #b28ae0; border-radius: 10px; padding: .7rem .9rem; display: flex; flex-direction: column; gap: .5rem; }
.evento header { display: flex; flex-direction: column; }
.evento-modificado { border-left-color: #e0a040; }
.evento-personas { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .3rem; }
.evento-personas li { background: #f1f1f1; border-radius: 99px; padding: .15rem .6rem; font-size: .9rem; }
.evento-personas li.cambio { background: #ffe6bf; box-shadow: inset 0 0 0 1px #e0a040; }
.evento-personas li.falto { text-decoration: line-through; color: var(--gris); background: #fafafa; }
.campos-evento { display: grid; grid-template-columns: 2fr 1fr; gap: .8rem; max-width: 620px; }
.campos-evento label, .personas-evento legend { font-weight: 600; display: block; margin-bottom: .25rem; }
.campos-evento .opcional { font-weight: 400; color: #777; font-size: .85em; }
.personas-evento { border: 0; padding: 0; margin: 1rem 0 0; }
.personas-evento input[type=search] { max-width: 420px; margin-bottom: .5rem; }
.ev-grupo .grupo-titulo { margin: .7rem 0 .3rem; font-size: .95rem; }
.ev-opciones { display: flex; flex-wrap: wrap; gap: .4rem; }
.ev-persona { display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .7rem; min-height: 44px;
  border: 1px solid #ccc; border-radius: 99px; background: #fff; cursor: pointer; font-weight: 400; }
.ev-persona input { width: 20px; height: 20px; }
.ev-persona:has(input:checked) { background: #efe6fa; border-color: #8f5fd0; font-weight: 600; }
.ev-persona.inactiva { font-style: italic; color: var(--gris); }
.ev-persona[hidden] { display: none; }
@media (max-width: 600px) { .campos-evento { grid-template-columns: 1fr; } }
.matriz .fila-fechas th.col-evento { background: #efe6fa; }
.matriz .fila-tipo th.col-evento { background: #c9b0ea; font-weight: 600; }
.matriz td.t-EV { background: #efe6fa; font-weight: 600; color: #5a2d91; }
