:root {
  --fondo: #ffffff;
  --panel: #ffffff;
  --lateral: #ffffff;
  --texto: #1b1f24;
  --suave: #5f6b7a;
  --borde: #e3e7ec;
  --acento: #3b5bdb;
  --acento-suave: #e8edff;
  --acento-texto: #ffffff;
  --chip: #f0f2f5;
  --hover: #f3f5f8;
  --sombra: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.08);
  --alto-top: 60px;
  --ancho-lateral: 240px;
  --ancho-linea: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #111418;
    --panel: #181c22;
    --lateral: #111418;
    --texto: #e7eaee;
    --suave: #98a2ae;
    --borde: #262c34;
    --acento: #7c9cff;
    --acento-suave: #1f2944;
    --acento-texto: #0b0d10;
    --chip: #1d222a;
    --hover: #1a1f26;
    --sombra: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
/* `hidden` siempre gana: sin esto, reglas como .personas { display: grid } lo pisan
   y el elemento "oculto" se sigue viendo (pasaba con el formulario de privadas). */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--fondo);
  color: var(--texto);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, select, input { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: currentColor; flex: none; }

/* ---------- barra superior ---------- */
.top {
  position: sticky; top: 0; z-index: 30; height: var(--alto-top);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--fondo) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--borde);
}
.logo { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 600; width: calc(var(--ancho-lateral) - 28px); color: var(--acento); }
.logo span { color: var(--texto); letter-spacing: -.01em; }
.logo svg { width: 28px; height: 28px; }
.buscador {
  flex: 0 1 560px; display: flex; align-items: center; gap: 8px;
  background: var(--chip); border-radius: 999px; padding: 0 14px; height: 42px; color: var(--suave);
}
.buscador:focus-within { box-shadow: 0 0 0 2px var(--acento); background: var(--panel); }
#buscar { flex: 1; min-width: 0; border: 0; background: none; outline: none; color: var(--texto); }
.icono-btn { border: 0; background: none; width: 40px; height: 40px; border-radius: 999px; cursor: pointer; display: none; place-items: center; }
.icono-btn:hover { background: var(--hover); }

/* ---------- estructura ---------- */
.app { display: flex; align-items: flex-start; }
.lateral {
  position: sticky; top: var(--alto-top); flex: none;
  width: var(--ancho-lateral); height: calc(100dvh - var(--alto-top));
  overflow-y: auto; padding: 12px 12px 24px 0; background: var(--lateral);
  scrollbar-width: thin; scrollbar-color: var(--borde) transparent;
}
.item {
  display: flex; align-items: center; gap: 16px; width: 100%;
  border: 0; background: none; cursor: pointer; text-align: left;
  padding: 10px 16px 10px 24px; border-radius: 0 999px 999px 0; color: var(--texto);
}
.item:hover { background: var(--hover); }
.item.activo { background: var(--acento-suave); color: var(--acento); font-weight: 600; }
.item svg { color: var(--suave); }
.item.activo svg { color: var(--acento); }
.item .n { margin-left: auto; font-size: 12px; color: var(--suave); font-weight: 400; }
.item.sub { padding-left: 62px; font-size: 14px; }
.item .etq { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grupo { margin: 18px 0 4px 24px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--suave); }
.almacen { margin: 22px 12px 0 24px; padding-top: 16px; border-top: 1px solid var(--borde); }
.almacen p { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.almacen p svg { width: 18px; height: 18px; color: var(--suave); }
.barra-uso { height: 6px; border-radius: 999px; background: var(--chip); overflow: hidden; }
.barra-uso div { height: 100%; background: var(--acento); border-radius: 999px; }
.barra-uso div.alto { background: #e8590c; }
.almacen small { display: block; margin-top: 8px; color: var(--suave); font-size: 12px; }
.sync { margin: 18px 12px 0 24px; padding-top: 14px; border-top: 1px solid var(--borde); }
.sync p { display: flex; align-items: center; gap: 10px; margin: 0 0 6px; font-size: 14px; font-weight: 600; }
.sync p svg { width: 18px; height: 18px; color: var(--suave); }
.sync small { display: block; color: var(--suave); font-size: 12px; }
.sync button {
  margin-top: 8px; width: 100%; border: 1px solid var(--borde); background: var(--panel); color: var(--texto);
  border-radius: 999px; padding: 7px 12px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.sync button:hover:not(:disabled) { border-color: var(--acento); color: var(--acento); }
.sync button:disabled { opacity: .6; cursor: default; }
.sync-estado { margin-top: 8px; line-height: 1.35; }
.sync-estado.ok { color: #2f9e44; }
.sync-estado.mal { color: #e03131; }
.velo { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; }

main { flex: 1; min-width: 0; padding: 0 calc(var(--ancho-linea) + 8px) 60px 16px; }
.cabecera { display: flex; align-items: baseline; gap: 14px; margin: 18px 2px 4px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.estado { color: var(--suave); font-size: 14px; }
.activos { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; }
.activos:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--borde);
  background: var(--panel); border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 14px;
}
.chip img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; margin-left: -6px; }
.chip button { border: 0; background: var(--chip); border-radius: 999px; width: 22px; height: 22px; cursor: pointer; line-height: 1; }

/* ---------- grilla ---------- */
.mes { scroll-margin-top: calc(var(--alto-top) + 8px); }
.mes h2 {
  font-size: 15px; font-weight: 600; margin: 22px 2px 10px;
  display: flex; gap: 8px; align-items: baseline;
}
.mes h2 small { color: var(--suave); font-weight: 400; font-size: 13px; }
.celdas {
  display: grid; gap: 3px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.celda {
  position: relative; aspect-ratio: 1; border: 0; padding: 0; cursor: pointer;
  background: var(--chip); overflow: hidden;
}
.celda img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s, transform .2s; }
.celda img.ok { opacity: 1; }
.celda:hover img { transform: scale(1.03); }
.celda:focus-visible { outline: 3px solid var(--acento); outline-offset: 1px; z-index: 1; }
.celda .dur {
  position: absolute; right: 6px; top: 6px; font-size: 12px; color: #fff; font-weight: 600;
  text-shadow: 0 1px 3px rgba(0,0,0,.7);
}
.celda .dur::after { content: " ▶"; }
.celda .fav { position: absolute; left: 6px; bottom: 4px; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.7); }
#centinela { height: 1px; }

/* ---------- personas ---------- */
.personas { display: grid; gap: 22px 14px; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); margin-top: 14px; }
.persona-card { border: 0; background: none; cursor: pointer; padding: 0; text-align: center; }
.persona-card img {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 18px; display: block;
  background: var(--chip); transition: transform .15s, box-shadow .15s;
}
.persona-card:hover img { transform: translateY(-2px); box-shadow: var(--sombra); }
.persona-card b { display: block; margin-top: 8px; font-weight: 600; }
.persona-card small { color: var(--suave); }

/* ---------- línea de tiempo (derecha) ---------- */
.linea {
  position: fixed; right: 0; top: var(--alto-top); bottom: 0; width: var(--ancho-linea);
  z-index: 20; cursor: pointer; user-select: none; touch-action: none;
  padding: 10px 0 14px;
}
.linea[hidden] { display: none; }
#linea-anios { position: relative; height: 100%; }
.anio {
  position: absolute; left: 0; right: 0; border-top: 1px solid transparent;
  display: flex; justify-content: flex-end; padding-right: 10px;
}
.anio span { font-size: 12px; line-height: 1; color: var(--suave); background: var(--fondo); padding: 0 2px; }
.anio::after {
  content: ""; position: absolute; right: 4px; top: 0; bottom: 0; width: 3px; border-radius: 2px;
  background: var(--borde);
}
.anio.actual span { color: var(--acento); font-weight: 700; }
.anio.actual::after { background: var(--acento); }
.linea-marca { position: absolute; right: 0; left: 8px; height: 2px; background: var(--acento); pointer-events: none; }
.linea-tip {
  position: absolute; right: calc(100% + 6px); transform: translateY(-50%); white-space: nowrap;
  background: var(--acento); color: var(--acento-texto); font-size: 13px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; pointer-events: none; box-shadow: var(--sombra);
}

/* ---------- mapa ---------- */
#mapa {
  height: calc(100dvh - var(--alto-top) - 90px); border-radius: 14px; overflow: hidden; margin-top: 12px; border: 1px solid var(--borde);
  /* Leaflet usa z-index de 400 a 1000 en sus capas: sin esto quedan por encima de la
     barra de arriba y del visor, y la foto se abre DETRÁS del mapa. */
  position: relative; z-index: 0; isolation: isolate;
}
@media (prefers-color-scheme: dark) {
  /* mapa de OpenStreetMap "oscurecido" para que combine con el tema */
  #mapa .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9); }
  #mapa { background: #1b1f24; }
}
.pin { width: 44px; height: 44px; border-radius: 8px; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4); background: var(--acento) center / cover no-repeat; cursor: pointer; }
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large { background: rgba(79,140,255,.35); }
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div { background: rgba(59,91,219,.9); color: #fff; font-weight: 600; }

/* ---------- celular ---------- */
@media (max-width: 900px) {
  :root { --ancho-linea: 34px; }
  .icono-btn { display: grid; }
  .logo { width: auto; }
  .logo span { display: none; }
  .lateral {
    position: fixed; left: 0; top: 0; height: 100dvh; z-index: 40;
    transform: translateX(-100%); transition: transform .2s; box-shadow: var(--sombra);
    padding-top: calc(12px + env(safe-area-inset-top));
  }
  .lateral.abierto { transform: none; }
  main { padding: 0 calc(var(--ancho-linea) + 2px) 60px 6px; }
  /* sin barra de años (Personas, Mapa, Privadas bloqueada) no se reserva su lugar */
  body.sin-linea main { padding-right: 6px; }
  .logo { display: none; }
  .top { gap: 6px; padding-left: 8px; padding-right: 10px; }
  .buscador { flex: 1; }
  .celdas { grid-template-columns: repeat(3, 1fr); gap: 2px; }
  .visor-top { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .visor-top .txt { display: none; }
  .visor-top button, .visor-top a { width: 40px; padding: 0; }
  #visor-pos { font-size: 13px; }
  .anio span { font-size: 10px; }
  .personas { grid-template-columns: repeat(3, 1fr); gap: 16px 10px; }
}
@media (min-width: 400px) and (max-width: 900px) {
  .celdas { grid-template-columns: repeat(4, 1fr); }
  #mapa { height: calc(100dvh - var(--alto-top) - 80px); }
}

/* ---------- login ---------- */
.pagina-login { min-height: 100dvh; display: grid; place-items: center; background: var(--chip); }
.login { width: 100%; padding: 16px; display: grid; place-items: center; }
.login-caja {
  width: 100%; max-width: 380px; background: var(--panel); border-radius: 20px; padding: 32px 28px 28px;
  box-shadow: var(--sombra); display: grid; gap: 16px;
}
.login-caja .logo { width: auto; justify-content: center; }
.login-caja h1 { text-align: center; font-size: 20px; font-weight: 600; margin: 0 0 4px; }
.login-caja label { display: grid; gap: 6px; font-size: 14px; color: var(--suave); }
.login-caja input {
  background: var(--chip); border: 1px solid transparent; border-radius: 12px; padding: 12px 14px;
  outline: none; color: var(--texto); font-size: 16px;
}
.login-caja input:focus { border-color: var(--acento); background: var(--panel); }
.login-caja button {
  margin-top: 6px; border: 0; background: var(--acento); color: var(--acento-texto); border-radius: 12px;
  padding: 12px; font-weight: 600; cursor: pointer; font-size: 16px;
}
.login-caja button:disabled { opacity: .6; cursor: default; }
.login-error { margin: 0; color: #e03131; font-size: 14px; }
.sesion { margin: 14px 12px 0 24px; font-size: 13px; color: var(--suave); }
.sesion b { color: var(--texto); font-weight: 600; }
.sesion button { display: block; border: 0; background: none; color: var(--acento); padding: 8px 0 0; cursor: pointer; font-size: 13px; text-align: left; }

/* ---------- visor ---------- */
.visor {
  position: fixed; inset: 0; z-index: 50; background: #000; color: #fff;
  display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto 1fr;
}
.visor[hidden] { display: none; }
.visor-top {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 14px;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: linear-gradient(#000c, #0000); position: absolute; left: 0; right: 0; top: 0; z-index: 2;
}
.visor-top button, .visor-top a {
  background: rgba(255,255,255,.12); border: 0; color: #fff; border-radius: 999px;
  min-width: 40px; height: 40px; padding: 0 12px; cursor: pointer; text-decoration: none; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; flex: none;
}
#visor-pos { flex: 1; min-width: 0; opacity: .75; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.visor-top svg { width: 20px; height: 20px; }
.visor-top .peligro:hover { background: #c92a2a; }
.visor-top .peligro[hidden], #privar[hidden] { display: none; }
.aviso { max-width: 520px; margin: 40px auto; text-align: center; color: var(--suave); }
.aviso svg { width: 48px; height: 48px; color: var(--acento); }
.aviso b { display: block; color: var(--texto); font-size: 18px; margin: 10px 0 6px; }
form.aviso { display: grid; justify-items: center; gap: 10px; max-width: 360px; grid-column: 1 / -1; justify-self: center; width: 100%; margin-top: 30px; }
form.aviso b { margin: 4px 0 0; }
.aviso input {
  width: 100%; background: var(--chip); border: 1px solid transparent; border-radius: 12px;
  padding: 12px 14px; outline: none; color: var(--texto); font-size: 16px; text-align: center;
}
.aviso input:focus { border-color: var(--acento); background: var(--panel); }
.aviso .login-error { text-align: center; }
.bloquear {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--borde);
  background: var(--panel); border-radius: 999px; padding: 5px 14px 5px 10px; cursor: pointer; font-size: 14px;
}
.bloquear svg { width: 18px; height: 18px; color: var(--acento); }
.bloquear[hidden] { display: none; }
.aviso button { margin-top: 14px; border: 0; background: var(--acento); color: var(--acento-texto); border-radius: 999px; padding: 8px 18px; cursor: pointer; font-weight: 600; }
.visor-media {
  grid-row: 1 / -1; grid-column: 1; display: flex; align-items: center; justify-content: center;
  overflow: hidden; touch-action: pan-y pinch-zoom;
}
.visor-media img, .visor-media video { max-width: 100%; max-height: 100dvh; object-fit: contain; }
.nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  background: rgba(255,255,255,.12); border: 0; color: #fff; font-size: 34px;
  width: 48px; height: 64px; border-radius: 10px; cursor: pointer;
}
.nav.izq { left: 10px; }
.nav.der { right: 10px; }
.visor.con-info .nav.der { right: 330px; }
@media (hover: none) { .nav { display: none; } }
.info {
  grid-row: 1 / -1; grid-column: 2; width: 320px; background: #15181d; padding: 64px 18px 18px;
  overflow-y: auto; display: none; font-size: 14px;
}
.visor.con-info .info { display: block; }
@media (max-width: 700px) {
  .visor { grid-template-columns: 1fr; }
  .info { grid-column: 1; grid-row: 2; align-self: end; width: 100%; max-height: 45dvh; padding-top: 16px; border-radius: 14px 14px 0 0; z-index: 3; }
  .visor.con-info .nav.der { right: 10px; }
}
.info dt { color: #98a2ae; font-size: 12px; margin-top: 12px; text-transform: uppercase; letter-spacing: .04em; }
.info dd { margin: 3px 0 0; word-break: break-word; }
.info .persona, .info .lugar {
  display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,.1); border: 0; color: #fff;
  border-radius: 999px; padding: 3px 10px 3px 3px; margin: 3px 4px 0 0; cursor: pointer;
}
.info .lugar { padding-left: 10px; }
.info .persona img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }
