:root{
  --round: 20px;
  --round-sm: 12px;
  --glass-bg: rgba(255,255,255,.10);
  --glass-bg-strong: rgba(255,255,255,.16);
  --glass-brd: rgba(255,255,255,.22);
  --glass-brd-soft: rgba(255,255,255,.14);
  --text: #fff;
  --text-dim: rgba(255,255,255,.72);
  --shadow: 0 10px 40px rgba(0,0,0,.35);
}

*{ box-sizing:border-box; }
/* El atributo hidden SIEMPRE oculta, aunque una regla le ponga display:flex/grid
   (sin esto, .modal-overlay y .fs-menu quedaban visibles y tapaban la app). */
[hidden]{ display:none !important; }
html,body{ margin:0; height:100%; }
body{
  font-family:-apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI",Roboto,system-ui,sans-serif;
  color:var(--text);
  min-height:100dvh;
  padding:max(16px,env(safe-area-inset-top)) max(14px,env(safe-area-inset-right)) 24px max(14px,env(safe-area-inset-left));
  -webkit-font-smoothing:antialiased;
  overflow-x:hidden;
  -webkit-tap-highlight-color:transparent;
}

/* Fondo — versión mobile en pantallas chicas, completa en desktop. Las dos
   URLs se declaran dentro de @media para que el browser NO descargue la que
   no va a usar (image-set() tiende a probar todas). */
.bg-layer{
  position:fixed; inset:0; z-index:-2;
  background-image:url("assets/chillan-bg.jpg");
  background-position:center; background-size:cover; background-repeat:no-repeat;
  background-attachment:fixed;
  transform:scale(1.04); /* evita borde blanco al hacer scroll elástico */
}
@media (max-width:900px){
  .bg-layer{ background-image:url("assets/chillan-bg-mobile.jpg"); }
}
body::before{ /* velo para legibilidad */
  content:""; position:fixed; inset:0; z-index:-1;
  background:linear-gradient(180deg, rgba(8,12,28,.30), rgba(8,12,28,.52));
}

/* Glass */
.glass{
  background:var(--glass-bg);
  -webkit-backdrop-filter:blur(22px) saturate(180%);
  backdrop-filter:blur(22px) saturate(180%);
  border:1px solid var(--glass-brd);
  box-shadow:var(--shadow);
  border-radius:var(--round);
  position:relative;
}
.glass::after{ /* highlight especular superior */
  content:""; position:absolute; inset:0; border-radius:inherit; pointer-events:none;
  background:linear-gradient(180deg, rgba(255,255,255,.18), rgba(255,255,255,0) 38%);
  mix-blend-mode:overlay;
}
.glass-soft{
  background:var(--glass-bg);
  -webkit-backdrop-filter:blur(12px) saturate(160%);
  backdrop-filter:blur(12px) saturate(160%);
  border:1px solid var(--glass-brd-soft);
  border-radius:var(--round-sm);
}

/* Layout */
.app{
  max-width:min(1400px, 100%); margin:0 auto; padding:16px clamp(12px,3vw,26px) 18px;
}
.topbar{
  display:flex; flex-wrap:wrap; gap:12px 16px; align-items:center; justify-content:space-between;
  margin-bottom:14px;
}
.title h1{ font-size:clamp(22px,2.8vw,36px); margin:0; font-weight:700; letter-spacing:.2px; }
.title .subtitle{ margin:2px 0 0; color:var(--text-dim); font-size:13px; }

.nav{ display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
.btn{
  border:1px solid var(--glass-brd); background:var(--glass-bg); color:var(--text);
  -webkit-backdrop-filter:blur(12px) saturate(160%); backdrop-filter:blur(12px) saturate(160%);
  border-radius:999px; padding:8px 14px; font-size:14px; cursor:pointer;
  touch-action:manipulation;
  transition:transform .08s ease, background .15s ease;
}
.btn:hover{ background:var(--glass-bg-strong); }
.btn:active{ transform:scale(.96); }
.btn.icon{ width:38px; height:38px; padding:0; font-size:20px; line-height:1; display:grid; place-items:center; }
.btn.primary{ background:linear-gradient(180deg,#3b82f6,#2563eb); border-color:rgba(255,255,255,.25); font-weight:600; }
.btn.ghost{ background:transparent; }
.btn:disabled{ opacity:.4; cursor:not-allowed; }

select.glass, input.glass{
  border:1px solid var(--glass-brd); background:var(--glass-bg); color:var(--text);
  -webkit-backdrop-filter:blur(12px) saturate(160%); backdrop-filter:blur(12px) saturate(160%);
  border-radius:999px; padding:8px 12px; font-size:14px; outline:none;
}
select.glass option{ color:#111; }
input[type=date].glass::-webkit-calendar-picker-indicator{ filter:invert(1) opacity(.85); }

/* Leyenda (referencia de colores, no interactiva) */
.legend{ display:flex; flex-wrap:wrap; gap:8px 16px; padding:10px 14px; margin-bottom:12px; }
.chip{ display:inline-flex; align-items:center; gap:7px; font-size:13px; color:var(--text-dim); }
.dot{ width:12px; height:12px; border-radius:50%; box-shadow:0 0 0 1px rgba(255,255,255,.25); }

/* Selector de familia (dropdown liquid glass) */
.fam-picker{ display:flex; align-items:center; gap:12px; flex-wrap:wrap; margin-bottom:10px; padding:0 4px; }
.fp-label{ font-size:13px; color:var(--text-dim); font-weight:600; }
.fam-select{ position:relative; }
.fs-trigger{
  display:inline-flex; align-items:center; gap:10px; font:inherit; font-size:14px; color:var(--text);
  cursor:pointer; padding:9px 16px 9px 12px; border-radius:999px; min-width:210px;
  background:rgba(255,255,255,.22);
  -webkit-backdrop-filter:blur(28px) saturate(180%); backdrop-filter:blur(28px) saturate(180%);
  border:1px solid var(--glass-brd);
  transition:background .15s ease, box-shadow .15s ease;
}
.fs-trigger:hover{ background:rgba(255,255,255,.28); }
.fs-trigger .dot{ width:14px; height:14px; box-shadow:0 0 0 1px rgba(255,255,255,.3); }
.fs-trigger .fs-label{ flex:1; text-align:left; }
.fs-trigger .fs-chev{ opacity:.7; font-size:12px; transition:transform .2s ease; }
.fs-trigger.open .fs-chev{ transform:rotate(180deg); }
.fs-trigger.selected{
  border-color:var(--c);
  box-shadow:inset 0 0 0 1px var(--c), 0 8px 22px -8px var(--c);
}
.fs-menu{
  position:absolute; top:calc(100% + 8px); left:0; z-index:30; min-width:100%; width:max-content;
  padding:6px; display:flex; flex-direction:column; gap:2px; animation:pop .12s ease;
  /* fondo oscuro + opaco para que el menú flote sobre el calendario sin
     solaparse visualmente. Mantiene el ADN glass con blur + saturate. */
  background:rgba(15,20,40,.72);
  -webkit-backdrop-filter:blur(32px) saturate(180%); backdrop-filter:blur(32px) saturate(180%);
  border:1px solid var(--glass-brd);
  box-shadow:0 18px 48px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.06) inset;
}
.fs-row{
  display:flex; align-items:center; gap:10px; font:inherit; font-size:14px; color:var(--text);
  cursor:pointer; padding:9px 12px; border-radius:10px; text-align:left; min-width:190px;
  border:1px solid transparent; background:transparent;
  touch-action:manipulation;
}
.fs-row:hover{
  background:rgba(255,255,255,.12);
  background:color-mix(in srgb, var(--c) 22%, transparent);
  border-color:color-mix(in srgb, var(--c) 45%, transparent);
}
.fs-row:focus-visible{ outline:2px solid #fff; outline-offset:2px; }
.fs-row.selected{
  background:rgba(255,255,255,.16);
  background:color-mix(in srgb, var(--c) 28%, transparent);
  border-color:color-mix(in srgb, var(--c) 50%, transparent);
}
.fs-row.selected::after{ content:"✓"; margin-left:auto; font-weight:700; }
.fs-row .dot{ width:13px; height:13px; box-shadow:0 0 0 1px rgba(255,255,255,.25); }

/* Calendario */
.calendar{ display:flex; flex-direction:column; gap:8px; }
.weekdays{ display:grid; grid-template-columns:repeat(7,1fr); gap:6px; }
.weekdays div{ text-align:center; font-size:12px; font-weight:600; color:var(--text-dim); padding:6px 0; text-transform:uppercase; letter-spacing:.06em; }
.grid{ display:grid; grid-template-columns:repeat(7,1fr); gap:6px; }

.cell{
  position:relative; min-height:clamp(64px,6.5vw,130px);
  border-radius:var(--round-sm);
  border:1px solid var(--glass-brd-soft);
  background:rgba(255,255,255,.06);
  -webkit-backdrop-filter:blur(8px) saturate(150%); backdrop-filter:blur(8px) saturate(150%);
  padding:6px 6px 18px; cursor:pointer; overflow:hidden;
  touch-action:manipulation;
  transition:background .15s ease, transform .08s ease;
}
.cell:hover{ background:rgba(255,255,255,.12); }
.cell.blank{ background:transparent; border-color:transparent; cursor:default; }
.cell .num{ font-size:13px; font-weight:600; opacity:.92; }
.cell.today{ box-shadow:0 0 0 2px #fff inset, 0 0 18px rgba(255,255,255,.35); }

.segments{ position:absolute; left:4px; right:4px; top:26px; display:flex; flex-direction:column; gap:3px; pointer-events:none; }
.seg{
  height:clamp(13px, 1.4vw, 18px); border-radius:0; display:flex; align-items:center; padding:0 6px;
  font-size:clamp(9.5px, 1.05vw, 12px); font-weight:600; color:#fff; white-space:nowrap; overflow:hidden;
  pointer-events:auto; cursor:pointer;
  text-shadow:0 1px 1px rgba(0,0,0,.35);
  box-shadow:0 1px 3px rgba(0,0,0,.25);
}
.seg.start{ border-top-left-radius:7px; border-bottom-left-radius:7px; }
.seg.end{ border-top-right-radius:7px; border-bottom-right-radius:7px; }
.seg.pill{ border-radius:7px; }

/* Footer */
.foot{ margin-top:14px; display:flex; justify-content:center; align-items:center; gap:10px; }
.admin-btn{ font-size:12px; padding:5px 12px; }
.admin-btn.on{ background:linear-gradient(180deg,#f59e0b,#d97706); border-color:rgba(255,255,255,.3); font-weight:600; }
body.admin-mode .app{ box-shadow:0 0 0 2px #f59e0b, var(--shadow); }
.mode-badge{
  font-size:11px; color:var(--text-dim); padding:5px 12px; border-radius:999px;
  border:1px solid var(--glass-brd-soft); background:rgba(255,255,255,.06);
}
.mode-badge.live{ color:#7CFFB2; border-color:rgba(124,255,178,.35); }

/* Modal */
.modal-overlay{
  position:fixed; inset:0; z-index:50; display:grid; place-items:center;
  background:rgba(6,8,18,.45); -webkit-backdrop-filter:blur(6px); backdrop-filter:blur(6px);
  padding:16px; animation:fade .15s ease;
}
.modal{ width:min(440px,100%); padding:22px; animation:pop .16s ease; }
.modal h2{ margin:0 0 16px; font-size:20px; }
.field{ display:block; margin-bottom:14px; }
.field .lbl{ display:block; font-size:12px; color:var(--text-dim); margin-bottom:6px; font-weight:600; }
.field .lbl em{ font-style:normal; opacity:.6; }
.field input[type=text], .field input[type=date]{ width:100%; border-radius:12px; padding:10px 12px; }
.row{ display:flex; gap:12px; }
.row .field{ flex:1; }
.families{ display:flex; flex-direction:column; gap:6px; }
.fam-opt{
  display:flex; align-items:center; gap:10px; padding:9px 12px; border-radius:12px; cursor:pointer;
  border:1px solid var(--glass-brd-soft); background:rgba(255,255,255,.05);
}
.fam-opt input{ accent-color:#3b82f6; width:18px; height:18px; }
.fam-opt .swatch{ width:14px; height:14px; border-radius:50%; box-shadow:0 0 0 1px rgba(255,255,255,.3); }
.fam-opt .nm{ font-size:14px; }
.fam-opt:has(input:checked){ background:rgba(255,255,255,.16); border-color:var(--glass-brd); }
.hint{ color:#ffd2d2; font-size:12px; min-height:14px; margin:2px 2px 12px; }
.modal-actions{ display:flex; justify-content:flex-end; gap:10px; }
.modal-actions .btn{ border-radius:12px; padding:10px 18px; }

/* Popover */
.popover{
  position:fixed; z-index:60; width:240px; padding:12px; font-size:13px;
  animation:pop .12s ease;
}
.popover .ptitle{ font-weight:600; margin-bottom:8px; }
.popover .prow{ display:flex; justify-content:space-between; gap:10px; padding:7px 0; border-top:1px solid var(--glass-brd-soft); }
.popover .prow:first-of-type{ border-top:none; }
.popover .pdel{
  margin-top:10px; width:100%; border-radius:10px; padding:8px;
  background:rgba(255,80,80,.18); border:1px solid rgba(255,120,120,.4); color:#ffd6d6; cursor:pointer;
}
.popover .pdel:hover{ background:rgba(255,80,80,.3); }

@keyframes fade{ from{opacity:0} to{opacity:1} }
@keyframes pop{ from{opacity:0; transform:translateY(8px) scale(.98)} to{opacity:1; transform:none} }

/* Barra de ayuda */
.hint-bar{
  text-align:center; font-size:13px; color:var(--text-dim);
  padding:8px 14px; margin-bottom:12px; border-radius:999px;
  transition:color .15s ease, background .15s ease;
}
.hint-bar.active{ color:var(--text); background:rgba(255,255,255,.14); }

/* Días bloqueados (pasados / margen Airbnb) */
.cell.blocked{
  opacity:.45; cursor:not-allowed;
  background:repeating-linear-gradient(135deg,
    rgba(0,0,0,.18) 0 6px, rgba(255,255,255,.03) 6px 12px);
}

/* Previsualización de selección (pincel). Cada regla lleva un fondo sólido
   antes del color-mix(): así la selección se ve aunque el navegador no soporte
   color-mix() (Safari < 16.2). */
.cell.in-range{
  background:rgba(255,255,255,.18);
  background:color-mix(in srgb, var(--brush) 30%, rgba(255,255,255,.05));
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.35);
  box-shadow:inset 0 0 0 1px color-mix(in srgb, var(--brush) 50%, transparent);
}
.cell.range-start{
  background:rgba(255,255,255,.22);
  background:color-mix(in srgb, var(--brush) 38%, rgba(255,255,255,.05));
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.4);
  box-shadow:inset 0 0 0 1px color-mix(in srgb, var(--brush) 60%, transparent);
  border-radius:var(--round-sm) 2px 2px var(--round-sm);
}
.cell.range-end{
  background:rgba(255,255,255,.22);
  background:color-mix(in srgb, var(--brush) 38%, rgba(255,255,255,.05));
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.4);
  box-shadow:inset 0 0 0 1px color-mix(in srgb, var(--brush) 60%, transparent);
  border-radius:2px var(--round-sm) var(--round-sm) 2px;
}
.cell.single{
  background:rgba(255,255,255,.26);
  background:color-mix(in srgb, var(--brush) 42%, rgba(255,255,255,.05));
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.45);
  box-shadow:inset 0 0 0 1px color-mix(in srgb, var(--brush) 65%, transparent);
}

/* Barra flotante de confirmación */
.brush-bar{
  position:fixed; left:50%; bottom:18px; transform:translate(-50%,160%);
  z-index:40; display:flex; align-items:center; gap:12px;
  padding:9px 12px 9px 18px; border-radius:999px;
  opacity:0; pointer-events:none;
  transition:transform .22s cubic-bezier(.2,.8,.2,1), opacity .18s ease;
  max-width:calc(100vw - 24px);
}
.brush-bar.show{ transform:translate(-50%,0); opacity:1; pointer-events:auto; }
.brush-bar .bb-fam{ font-weight:700; font-size:14px; white-space:nowrap; }
.brush-bar .bb-range{ font-size:13px; color:var(--text-dim); white-space:nowrap; }
.brush-bar .bb-confirm{ border-radius:999px; padding:8px 16px; font-weight:600; }
.brush-bar .bb-cancel{ width:34px; height:34px; }

/* Tip dentro del modal */
.modal-tip{
  margin:-6px 0 14px; font-size:12px; color:var(--text-dim);
  padding:8px 12px; border-radius:10px; background:rgba(255,255,255,.06);
  border:1px solid var(--glass-brd-soft);
}

/* ---------- Lock screen ---------- */
body.locked{ overflow:hidden; }
body.locked .app{
  filter:blur(14px) saturate(140%) brightness(.85);
  transform:scale(1.015);
  pointer-events:none;
  transition:filter .7s cubic-bezier(.16,1,.3,1), transform .7s cubic-bezier(.16,1,.3,1);
}
.lock-overlay{
  position:fixed; inset:0; z-index:200; display:grid; place-items:center;
  background:rgba(8,12,28,.35);
  -webkit-backdrop-filter:blur(18px) saturate(150%);
  backdrop-filter:blur(18px) saturate(150%);
  padding:16px;
  animation:lockFadeIn .25s ease;
}
.lock-overlay.unlocking{
  animation:lockFadeOut .55s cubic-bezier(.16,1,.3,1) forwards;
}
.lock-overlay.unlocking .lock-card{
  animation:lockOut .55s cubic-bezier(.16,1,.3,1) forwards;
}
/* Flash radial: halo blanco que se expande al desbloquear. Va en el overlay
   para que no quede recortado por el border-radius de la card. */
.lock-overlay::before{
  content:""; position:absolute; left:50%; top:50%;
  width:520px; height:520px; margin-left:-260px; margin-top:-260px;
  background:radial-gradient(circle, rgba(255,255,255,.55) 0%, rgba(255,255,255,.18) 35%, rgba(255,255,255,0) 70%);
  opacity:0; pointer-events:none; transform:scale(.2);
}
.lock-overlay.unlocking::before{
  animation:lockFlash .75s cubic-bezier(.16,1,.3,1) forwards;
}
.lock-card{
  position:relative;
  width:min(360px, calc(100% - 32px));
  padding:28px 24px 22px;
  text-align:center;
  border-radius:var(--round);
  animation:lockPopIn .55s cubic-bezier(.16,1,.3,1) both;
  animation-delay:.05s;
}
.lock-icon{ font-size:28px; margin-bottom:6px; }
.lock-card h2{ margin:0 0 4px; font-size:20px; font-weight:700; letter-spacing:.2px; }
.lock-sub{ margin:0 0 18px; font-size:13px; color:var(--text-dim); }
.lock-pins{ display:flex; gap:10px; justify-content:center; margin:6px 0 4px; }
.lock-pin{
  width:54px; height:64px;
  border-radius:14px; border:1px solid var(--glass-brd);
  background:rgba(255,255,255,.18);
  -webkit-backdrop-filter:blur(20px) saturate(180%);
  backdrop-filter:blur(20px) saturate(180%);
  color:var(--text); font-size:26px; font-weight:700;
  text-align:center; outline:none;
  -webkit-text-security:disc; text-security:disc;
  touch-action:manipulation;
  transition:transform .15s ease, border-color .15s ease, background .15s ease, box-shadow .15s ease;
  caret-color:transparent;
}
.lock-pin:focus{
  border-color:rgba(255,255,255,.7);
  box-shadow:0 0 0 3px rgba(255,255,255,.18);
  transform:translateY(-1px);
}
.lock-pin.filled{ background:rgba(255,255,255,.28); }
.lock-pin.wrong{
  border-color:rgba(255,120,120,.75);
  animation:lockShake .5s;
}
.lock-err{ min-height:18px; margin:10px 0 0; color:#ffd2d2; font-size:12px; }

@keyframes lockFadeIn{ from{opacity:0} to{opacity:1} }
@keyframes lockFadeOut{ to{opacity:0; -webkit-backdrop-filter:blur(0px) saturate(100%); backdrop-filter:blur(0px) saturate(100%)} }
@keyframes lockPopIn{
  from{opacity:0; transform:translateY(12px) scale(.96); filter:blur(8px)}
  to{opacity:1; transform:none; filter:none}
}
@keyframes lockOut{
  0%  {opacity:1; transform:translateY(0) scale(1); filter:blur(0)}
  100%{opacity:0; transform:translateY(-10px) scale(1.04); filter:blur(10px)}
}
@keyframes lockFlash{
  0%  {opacity:0; transform:scale(.2)}
  35% {opacity:.55}
  100%{opacity:0; transform:scale(1.6)}
}
@keyframes lockShake{
  10%,90%{transform:translateX(-2px)}
  20%,80%{transform:translateX(3px)}
  30%,50%,70%{transform:translateX(-5px)}
  40%,60%{transform:translateX(5px)}
}
@keyframes popUp{
  from{opacity:0; transform:translateY(20px)}
  to{opacity:1; transform:none}
}

@media (max-width:560px){
  .nav .btn:not(.icon):not(.primary):not(#today):not(#undo){ display:none; } /* deja ‹ › Hoy + Reserva + Deshacer en móvil */
  .title h1{ font-size:20px; }
  .weekdays div, .cell .num{ font-size:10px; }
  .seg{ font-size:0; padding:0; height:10px; }
  /* Popover como bottom sheet en móvil */
  .popover{
    left:8px !important; right:8px !important; width:auto !important;
    top:auto !important; bottom:12px;
    border-radius:18px 18px 14px 14px;
    animation:popUp .18s ease;
  }
}

/* Landscape en celular (alto ≤500): celdas más bajas, hint-bar oculto */
@media (orientation:landscape) and (max-height:500px){
  .topbar{ margin-bottom:6px; }
  .title h1{ font-size:18px; }
  .title .subtitle{ display:none; }
  .fam-picker{ margin-bottom:6px; }
  .cell{ min-height:46px; padding:4px 4px 14px; }
  .grid{ gap:4px; }
  .calendar{ gap:4px; }
  .weekdays{ gap:4px; }
  .hint-bar{ display:none; }
  .lock-card{ padding:18px 18px 14px; }
  .lock-card h2{ font-size:17px; }
  .lock-pin{ width:44px; height:52px; font-size:22px; }
  .lock-pins{ gap:8px; margin:10px 0 0; }
}

/* Tablet portrait / celu grande: tipografía y padding más aireado. Excluye
   landscape de celular (que tiene su propio breakpoint más abajo). */
@media (max-width:900px) and (min-width:561px) and (orientation:portrait){
  .app{ padding:12px 16px 16px; }
  .title h1{ font-size:24px; }
  .cell{ min-height:72px; }
}
