:root {
  --fijo: #b7e1cd;          /* verde, como la planilla */
  --fijo-borde: #4f9a6e;
  --ocasional: #fcd5a8;     /* naranja */
  --ocasional-borde: #d9822b;
  --liberado: repeating-linear-gradient(135deg, #fff 0 6px, #eef7f1 6px 12px);
  --linea: #d9d9d9;
  --linea-fuerte: #9a9a9a;
  --cab-semana: #e06666;
  --cab-finde: #f1c232;
  --hoy: #1f6f3a;
  --texto: #1d1d1d;
  --suave: #6b6b6b;
  --fondo: #f6f6f4;
  --celda-alto: 26px;
  --cancha-ancho: 92px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--texto);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--fondo); }
button, input, select, textarea { font: inherit; }
[hidden] { display: none !important; }

/* ---------- Entrada ---------- */
.entrada { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.caja-entrada { background: #fff; border-radius: 14px; padding: 28px 24px; width: min(380px, 100%); box-shadow: 0 2px 16px rgba(0,0,0,.08); text-align: center; }
.caja-entrada h1 { margin: 8px 0 20px; font-size: 22px; }
.caja-entrada form { display: grid; gap: 10px; text-align: left; }
.caja-entrada input { padding: 12px; border: 1px solid #bbb; border-radius: 8px; font-size: 17px; }
#codigo { font-size: 26px; letter-spacing: 6px; text-align: center; }
.error { color: #b42318; min-height: 1.2em; }

/* ---------- Botones ---------- */
.btn { border: 1px solid #c8c8c8; background: #fff; border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.btn:hover { background: #f2f2f2; }
.btn.primario { background: var(--hoy); border-color: var(--hoy); color: #fff; font-weight: 600; padding: 11px 14px; }
.btn.primario:hover { background: #185a2f; }
.btn.peligro { color: #b42318; border-color: #e7b2ad; }
.btn.link { border: 0; background: none; color: var(--hoy); text-decoration: underline; }
.btn.icono { border: 0; background: none; font-size: 20px; padding: 4px 8px; }
.btn[disabled] { opacity: .5; cursor: default; }
.fila-btn { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }

/* ---------- Barra ---------- */
.barra { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: #fff; border-bottom: 1px solid var(--linea); }
#selComplejo { font-weight: 700; border: 1px solid #ccc; border-radius: 8px; padding: 6px 8px; background: #fff; }
.pestanas { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.pestanas button { border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; color: var(--suave); }
.pestanas button.activa { background: #e8f3ec; color: var(--hoy); font-weight: 700; }
.barra-der { display: flex; align-items: center; gap: 4px; }
.estado-red { width: 10px; height: 10px; border-radius: 50%; background: #3fb950; }
.estado-red.guardando { background: #f0b429; }
.estado-red.error { background: #e5534b; }
.menu { position: fixed; right: 8px; top: 48px; z-index: 40; background: #fff; border: 1px solid var(--linea); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.12); padding: 6px; display: grid; min-width: 200px; }
.menu button { text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: #f2f2f2; }
.aviso-prueba { background: #fff4d6; color: #6a4b00; font-size: 13px; padding: 5px 12px; border-bottom: 1px solid #f0dca0; }

main { padding: 0; }
.contenido { padding: 14px; max-width: 980px; margin: 0 auto; }
.contenido h2 { margin: 6px 0 12px; font-size: 19px; }

/* ---------- Controles de la grilla ---------- */
.controles { display: flex; align-items: center; gap: 8px; padding: 8px 10px; flex-wrap: wrap; background: #fff; border-bottom: 1px solid var(--linea); position: sticky; top: 45px; z-index: 25; }
.controles .titulo-semana { font-weight: 700; min-width: 150px; text-align: center; }
.controles .sep { flex: 1; }
.leyenda { display: flex; gap: 10px; font-size: 12px; color: var(--suave); align-items: center; }
.leyenda i { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }
.dias-movil { display: none; gap: 4px; overflow-x: auto; padding: 6px 10px; background: #fff; border-bottom: 1px solid var(--linea); }
.dias-movil button { border: 1px solid #ddd; background: #fff; border-radius: 8px; padding: 6px 9px; white-space: nowrap; font-size: 13px; }
.dias-movil button.activa { background: var(--hoy); color: #fff; border-color: var(--hoy); }

/* ---------- Grilla ---------- */
.grilla-scroll { overflow: auto; height: calc(100vh - 100px); height: calc(100dvh - 100px); background: #fff; }
.grilla { display: grid; position: relative; min-width: max-content; font-size: 13px; }
.g-esquina { position: sticky; left: 0; top: 0; z-index: 12; background: #fff; border-right: 1px solid var(--linea-fuerte); border-bottom: 1px solid var(--linea); }
.g-dia { position: sticky; top: 0; z-index: 10; text-align: center; font-weight: 800; padding: 4px 2px; color: #fff; background: var(--cab-semana); border-left: 2px solid var(--linea-fuerte); font-size: 12px; letter-spacing: .3px; }
.g-dia.finde { background: var(--cab-finde); color: #3d3000; }
.g-dia.hoy { box-shadow: inset 0 -4px 0 var(--hoy); }
.g-dia.hoy::after { content: " · HOY"; }
.g-dia.pasado { opacity: .55; }
.g-cancha { position: sticky; top: 24px; z-index: 10; background: #f3f3f3; text-align: center; font-size: 11px; color: #444; padding: 3px 2px; border-bottom: 1px solid var(--linea-fuerte); border-left: 1px solid var(--linea); white-space: nowrap; overflow: hidden; }
.g-cancha.primera { border-left: 2px solid var(--linea-fuerte); }
.g-hora { position: sticky; left: 0; z-index: 8; background: #fafafa; text-align: right; padding: 0 6px; font-size: 12px; color: #555; border-right: 1px solid var(--linea-fuerte); border-bottom: 1px solid var(--linea); line-height: var(--celda-alto); font-variant-numeric: tabular-nums; }
.g-hora.en-punto { font-weight: 700; color: #222; }
.g-celda { position: relative; height: var(--celda-alto); border-bottom: 1px solid var(--linea); border-left: 1px solid var(--linea); cursor: cell; display: flex; align-items: center; gap: 3px; padding: 0 3px 0 2px; min-width: 0; }
.g-celda.primera { border-left: 2px solid var(--linea-fuerte); }
.g-celda.pasado { background: #fbfbfb; }
.g-celda:hover { outline: 2px solid #7bb38f; outline-offset: -2px; z-index: 2; }
.g-celda .chk { flex: none; width: 13px; height: 13px; border: 1.5px solid #aaa; border-radius: 3px; background: #fff; display: grid; place-items: center; font-size: 10px; line-height: 1; color: #fff; cursor: pointer; }
.g-celda .txt { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; flex: 1; min-width: 0; }
.g-celda.ocup .chk { background: #333; border-color: #333; }
.g-celda.ocup .chk::after { content: "✓"; }
.g-celda.fijo { background: var(--fijo); }
.g-celda.ocasional { background: var(--ocasional); }
.g-celda.ini .txt { font-weight: 700; }
.g-celda.fin { border-bottom: 2px solid #555; }
.g-celda.fijo.fin { border-bottom-color: var(--fijo-borde); }
.g-celda.ocasional.fin { border-bottom-color: var(--ocasional-borde); }
.g-celda.info .txt { font-style: italic; color: #333; font-size: 12px; }
.g-celda.liberado { background: var(--liberado); }
.g-celda.liberado .txt { color: #8aa; font-size: 11px; }
.g-celda.sel { outline: 2px solid var(--hoy); outline-offset: -2px; z-index: 3; }
.g-celda.previa { box-shadow: inset 0 0 0 2px #1f6f3a; background: #d9eee1; }
.g-celda.previa-mal { box-shadow: inset 0 0 0 2px #e5534b; }
.g-celda .tirador { position: absolute; left: 20%; right: 20%; bottom: -4px; height: 8px; cursor: ns-resize; z-index: 4; border-radius: 4px; }
.g-celda.fin:hover .tirador { background: rgba(0,0,0,.25); }
.g-celda input.editor { position: absolute; inset: 0; width: 100%; border: 2px solid var(--hoy); padding: 0 4px; font-size: 13px; z-index: 6; outline: 0; }
/* cada turno recuadrado como un bloque */
.g-celda.ocup { border-left: 2px solid var(--borde-turno); border-right: 2px solid var(--borde-turno); }
.g-celda.ocup:not(.fin) { border-bottom-color: transparent; }
.g-celda.ocup.ini { border-top: 2px solid var(--borde-turno); }
.g-celda.ocup.fin { border-bottom: 2px solid var(--borde-turno); }
.g-celda.fijo { --borde-turno: var(--fijo-borde); }
.g-celda.ocasional { --borde-turno: var(--ocasional-borde); }
.g-celda.ocup.info .chk { opacity: .55; }
.g-celda.con-tel .txt::after { content: " 📞"; font-size: 10px; }
.g-celda.elegida { box-shadow: inset 0 0 0 2px #2b6cb0; background-image: linear-gradient(rgba(43,108,176,.14), rgba(43,108,176,.14)); }
.barra-sel { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 45; background: #fff; border: 1px solid #c9d6e8; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.18); padding: 8px 10px; display: flex; gap: 8px; align-items: center; }
.btn.activo { background: #e3edf9; border-color: #2b6cb0; color: #1d4f8a; }

/* ---------- Panel lateral ---------- */
.velo { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 49; }
.panel { position: fixed; right: 0; top: 0; bottom: 0; width: min(400px, 100%); background: #fff; z-index: 50; box-shadow: -4px 0 20px rgba(0,0,0,.15); display: flex; flex-direction: column; }
.panel-cab { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--linea); }
.panel-cab h2 { margin: 0; font-size: 17px; }
.panel-cuerpo { padding: 14px; overflow: auto; flex: 1; }
.panel-cuerpo label { display: block; font-size: 13px; color: var(--suave); margin: 10px 0 4px; }
.panel-cuerpo input, .panel-cuerpo select, .panel-cuerpo textarea { width: 100%; padding: 9px; border: 1px solid #c8c8c8; border-radius: 8px; }
.etiqueta { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 10px; font-weight: 700; }
.etiqueta.fijo { background: var(--fijo); color: #1f5a3a; }
.etiqueta.ocasional { background: var(--ocasional); color: #7a4100; }
.duracion { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.duracion .valor { font-size: 20px; font-weight: 800; min-width: 70px; text-align: center; }
.dato { color: var(--suave); font-size: 13px; margin: 6px 0; }

/* ---------- Diálogo y toast ---------- */
.dialogo { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 70; display: grid; place-items: center; padding: 18px; }
.dialogo-caja { background: #fff; border-radius: 12px; padding: 18px; width: min(420px, 100%); box-shadow: 0 8px 30px rgba(0,0,0,.2); }
.dialogo-caja p { margin: 0 0 14px; white-space: pre-line; }
.dlg-botones { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 80; max-width: 92vw; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.toast.error { background: #b42318; }

/* ---------- Tablas y formularios ---------- */
table.lista { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; }
table.lista th, table.lista td { padding: 8px 10px; border-bottom: 1px solid #eee; text-align: left; font-size: 14px; }
table.lista th { background: #f3f3f3; font-size: 12px; color: #555; text-transform: uppercase; letter-spacing: .4px; }
table.lista td.num, table.lista th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.lista tr.clic { cursor: pointer; }
table.lista tr.clic:hover td { background: #f7faf8; }
table.lista tr.anulado td { color: #999; text-decoration: line-through; }
.tarjeta { background: #fff; border-radius: 12px; padding: 14px; margin-bottom: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.form-linea { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; align-items: end; }
.form-linea label { display: grid; gap: 4px; font-size: 13px; color: var(--suave); }
.form-linea input, .form-linea select { padding: 9px; border: 1px solid #c8c8c8; border-radius: 8px; background: #fff; }
.totales { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.totales div { background: #fff; border-radius: 10px; padding: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.totales b { display: block; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.saldo-grande { font-size: 30px; font-weight: 800; margin: 4px 0 10px; }
.debe { color: #b42318; }
.vacio { color: var(--suave); padding: 20px; text-align: center; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 10px; background: #eee; font-size: 12px; margin: 1px; }
.interruptor { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* ---------- Celular ---------- */
@media (max-width: 760px) {
  :root { --celda-alto: 34px; --cancha-ancho: 1fr; }
  .dias-movil { display: flex; }
  .controles { top: 45px; }
  .leyenda { display: none; }
  .grilla-scroll { height: calc(100dvh - 140px); }
  .g-celda { font-size: 14px; }
  .g-celda .chk { width: 18px; height: 18px; font-size: 13px; }
  .pestanas button { padding: 8px 7px; font-size: 14px; }
}
