/* historias.css — Historias cercanas: feed vertical a pantalla completa (como TikTok) */

.hist {
  position: fixed; inset: 0; z-index: 210; background: #000; color: #fff;
  display: flex; flex-direction: column; overscroll-behavior: contain;
}
.hist[hidden] { display: none; }
body.hist-abierta .navbar { z-index: 215; }
/* Con la hoja de subir o reportar abierta, la barra no la tapa */
body:has(.hist-subida) .navbar { display: none !important; }

/* Barra de arriba, flotando sobre la historia */
.hist-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 3;
  display: flex; align-items: center; gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 14px 22px;
  background: linear-gradient(rgba(0,0,0,.55), transparent);
  pointer-events: none;
}
.hist-top > * { pointer-events: auto; }
.hist-x, .hist-subir {
  display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer;
  color: #fff; font: inherit; font-weight: 700; font-size: 13px;
  background: rgba(255,255,255,.16); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.hist-x { width: 38px; height: 38px; border-radius: 50%; justify-content: center; }
.hist-subir { padding: 9px 14px 9px 10px; border-radius: 20px; background: var(--lima, #c8f169); color: var(--lima-txt, #16301f); }
.hist-x .ico, .hist-subir .ico { width: 18px; height: 18px; }
.hist-titulo { flex: 1; min-width: 0; text-align: center; line-height: 1.2; text-shadow: 0 1px 4px rgba(0,0,0,.5); }
.hist-titulo b { display: block; font-size: 15px; }
.hist-titulo small { font-size: 11.5px; opacity: .85; }

/* El feed: una historia por pantalla, encaja al deslizar */
.hist-feed {
  flex: 1; overflow-y: auto; scroll-snap-type: y mandatory; scrollbar-width: none;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.hist-feed::-webkit-scrollbar { display: none; }
.hist-item, .hist-fin, .hist-vacio {
  position: relative; height: 100%; scroll-snap-align: start; scroll-snap-stop: always; overflow: hidden;
}
.hist-medio { position: absolute; inset: 0; display: grid; place-items: center; background: #111; }
.hist-medio img, .hist-medio video { width: 100%; height: 100%; object-fit: cover; }
@media (min-aspect-ratio: 4/5) {
  /* En pantallas anchas la historia se ve como un teléfono, centrada */
  .hist-medio img, .hist-medio video { width: min(100%, calc(100dvh * 9 / 16)); height: 100%; object-fit: cover; border-radius: 0; }
}
.hist-medio.pausado::after {
  content: '▶'; position: absolute; font-size: 64px; opacity: .8; text-shadow: 0 2px 12px rgba(0,0,0,.5);
}
.hist-sombra {
  position: absolute; inset: auto 0 0 0; height: 45%; pointer-events: none;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
}
.hist-sonido {
  position: absolute; top: calc(max(12px, env(safe-area-inset-top)) + 52px); right: 14px; z-index: 2;
  width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer; font-size: 17px;
  background: rgba(0,0,0,.4); color: #fff;
}

/* Botones de la derecha */
.hist-lado {
  position: absolute; right: 10px; bottom: 120px; z-index: 2;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.hist-av {
  width: 48px; height: 48px; padding: 0; border-radius: 50%; overflow: hidden; cursor: pointer;
  border: 2px solid #fff; background: var(--azul, #315bea); color: #fff; font: 700 18px/1 inherit;
  display: grid; place-items: center;
}
.hist-av img { width: 100%; height: 100%; object-fit: cover; }
.hist-accion {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: 0; background: none; color: #fff; cursor: pointer; font: inherit; font-size: 22px; line-height: 1;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,.6));
}
.hist-accion .ico { width: 30px; height: 30px; }
.hist-accion b { font-size: 11.5px; font-weight: 700; }
.hist-accion.on { color: #ff3b5c; }
.hist-accion.on .ico svg { fill: currentColor; }
.hist-accion.late .ico { animation: hist-late .45s ease; }
@keyframes hist-late { 40% { transform: scale(1.35); } }

/* Autor, lugar y texto abajo */
.hist-info {
  position: absolute; left: 14px; right: 80px; bottom: 112px; z-index: 2;
  text-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.hist-autor {
  display: inline-flex; align-items: center; gap: 5px; padding: 0; border: 0; background: none; cursor: pointer;
  color: #fff; font: inherit; font-size: 16px; font-weight: 800;
}
.hist-autor svg { width: 16px; height: 16px; }
.hist-meta { font-size: 12.5px; opacity: .9; margin-top: 2px; }
.hist-texto { margin: 8px 0 0; font-size: 14px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }

/* Vacío, cargando y fin */
.hist-vacio, .hist-fin {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 0 32px 90px; text-align: center;
  background: radial-gradient(circle at 50% 35%, #233a7a, #000 70%);
}
.hist-vacio h3 { margin: 0; font-size: 21px; }
.hist-vacio p, .hist-fin p { margin: 0; max-width: 320px; opacity: .85; line-height: 1.45; }
.hist-vacio-ico .ico { width: 56px; height: 56px; opacity: .9; }
.hist-girando { width: 42px; height: 42px; border-radius: 50%; border: 3px solid rgba(255,255,255,.25); border-top-color: #fff; animation: hist-gira .8s linear infinite; }
@keyframes hist-gira { to { transform: rotate(360deg); } }
.hist-btn {
  border: 0; border-radius: 22px; padding: 12px 22px; cursor: pointer;
  background: var(--lima, #c8f169); color: var(--lima-txt, #16301f); font: inherit; font-weight: 800; font-size: 14px;
}
.hist-btn.ancho { width: 100%; }
.hist-btn:disabled { opacity: .5; cursor: default; }

/* Hoja para subir o reportar */
.hist-subida {
  position: absolute; inset: 0; z-index: 5; display: grid; place-items: end center;
  background: rgba(0,0,0,.55); animation: hist-aparece .18s ease;
}
@keyframes hist-aparece { from { opacity: 0; } }
.hist-subida-caja {
  width: min(480px, 100%); max-height: 92%; overflow-y: auto;
  padding: 16px 16px max(18px, env(safe-area-inset-bottom)); border-radius: 22px 22px 0 0;
  background: var(--panel, #fff); color: var(--txt, #111);
  display: flex; flex-direction: column; gap: 12px;
}
@media (min-width: 700px) { .hist-subida { place-items: center; } .hist-subida-caja { border-radius: 22px; } }
.hist-subida-top { display: flex; align-items: center; justify-content: space-between; font-size: 17px; }
.hist-subida-top button { border: 0; background: var(--tinte-2, #eee); color: inherit; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }
.hist-subida-top .ico { width: 17px; height: 17px; }
.hist-previa { position: relative; display: flex; flex-direction: column; gap: 8px; }
.hist-previa img, .hist-previa video { width: 100%; max-height: 46vh; object-fit: contain; border-radius: 14px; background: #000; }
.hist-elegir {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 26px 12px; cursor: pointer;
  border: 2px dashed var(--line, #ccc); border-radius: 16px; background: var(--campo, #f6f6f6); color: inherit; font: inherit;
}
.hist-elegir .ico { width: 34px; height: 34px; color: var(--azul, #315bea); }
.hist-elegir small { color: var(--mut, #777); }
.hist-camaras { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hist-camaras button, .hist-motivos button {
  padding: 11px; border-radius: 12px; border: 1px solid var(--line, #ddd); cursor: pointer;
  background: var(--campo, #f6f6f6); color: inherit; font: inherit; font-weight: 600; font-size: 13.5px;
}
.hist-cambiar {
  position: absolute; top: 8px; right: 8px; border: 0; border-radius: 16px; padding: 7px 12px; cursor: pointer;
  background: rgba(0,0,0,.6); color: #fff; font: inherit; font-weight: 700; font-size: 12px;
}
.hist-subida textarea {
  width: 100%; box-sizing: border-box; resize: none; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--line, #ddd); background: var(--campo, #f6f6f6); color: inherit; font: inherit; font-size: 14px;
}
.hist-aviso { margin: 0; font-size: 12px; color: var(--mut, #777); line-height: 1.4; }
.hist-error { margin: 0; min-height: 0; font-size: 13px; color: var(--peligro, #d33); font-weight: 600; }
.hist-error:empty { display: none; }
.hist-motivos { display: flex; flex-direction: column; gap: 8px; }
.hist-motivos button { text-align: left; }

/* En computador la barra de navegación está a la izquierda: el feed deja su espacio */
@media (min-width: 1024px) {
  .hist { left: 136px; }
  .hist-info { bottom: 40px; }
  .hist-lado { bottom: 48px; right: calc(50% - min(28vh, 260px) - 70px); }
  .hist-info { left: calc(50% - min(28vh, 260px) + 14px); right: auto; max-width: min(42vh, 380px); }
}
@media (max-width: 1023px) {
  /* En el móvil la barra de abajo queda sobre el feed, oscura */
  body.hist-abierta .navbar { background: rgba(10,10,14,.82); border-color: rgba(255,255,255,.08); }
  body.hist-abierta .navbar button { color: rgba(255,255,255,.75); }
  body.hist-abierta .navbar button.on:not(.crear) { background: rgba(255,255,255,.14); color: #fff; }
}
@media (prefers-reduced-motion: reduce) {
  .hist-accion.late .ico, .hist-subida { animation: none; }
}

/* Barra de "Optimizando video…" sobre la vista previa */
.hist-progreso {
  position: absolute; left: 10px; right: 10px; bottom: 10px; height: 30px; border-radius: 15px; overflow: hidden;
  background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; font-size: 12.5px; font-weight: 700;
}
.hist-progreso i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--azul, #315bea); transition: width .2s; }
.hist-progreso span { position: relative; }

/* Lugar desde donde se subió, debajo del nombre */
.hist-lugar {
  display: flex; width: fit-content; align-items: center; gap: 4px; margin-top: 5px; padding: 3px 9px 3px 6px; border-radius: 12px;
  background: rgba(0,0,0,.35); font-size: 13px; font-weight: 700; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.hist-lugar .ico { width: 14px; height: 14px; }
.hist-desde { display: flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 700; color: var(--azul, #315bea); }
.hist-desde .ico { width: 16px; height: 16px; }
