/* ════════════════════════════════════════════════════════════════════
   Pupito — notificaciones (public/js/notifications.js, docs/NOTIFICATIONS.md): la campana de la
   barra superior con su insignia, el panel (desplegable en el ordenador, hoja a todo el ancho en el
   móvil), el aviso pequeño en vivo y el diálogo «Invitar a tu sala». Base común y, debajo, cada tema
   bajo :root[data-style='brutal'] / :root[data-style='retro'] (claro y oscuro). El retro está
   retirado por ahora (public/js/theme.js): sus reglas quedan aquí, sin efecto, para cuando vuelva.
   ════════════════════════════════════════════════════════════════════ */

/* ───────────────────────────── Campana ───────────────────────────── */

.notif-bell {
  position: relative;
}

.notif-bell[hidden] {
  display: none;
}

.notif-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
  background: var(--pink);
  color: #fff;
  pointer-events: none;
}

.notif-badge[hidden] {
  display: none;
}

.notif-bell.ring svg {
  animation: notif-ring 0.9s ease-in-out;
  transform-origin: 50% 12%;
}

/* Con la campana (sólo con cuenta) la barra lleva un botón más y, en el móvil, los iconos de la
   navegación quedaban aplastados (en el neo-brutalista, con sus bordes gruesos, ya desde 412 px; en el
   retro, por debajo de 360). Ahí se juntan un poco los botones: huecos, monedero y los dos iconos. */
@media (max-width: 640px) {
  :root[data-style='brutal'] .topbar.with-bell .container {
    gap: 4px;
  }

  :root[data-style='brutal'] .topbar.with-bell .topbar-right {
    gap: 3px;
  }

  :root[data-style='brutal'] .topbar.with-bell .topbar-right .icon-btn {
    width: 34px;
  }

  :root[data-style='brutal'] .topbar.with-bell .coin-pill {
    gap: 6px;
    padding: 0 7px 0 5px;
  }
}

@media (max-width: 380px) {
  :root[data-style='brutal'] .topbar.with-bell .nav {
    gap: 3px !important;
  }

  :root[data-style='brutal'] .topbar.with-bell .nav a[data-nav] {
    padding-inline: 3px !important;
  }
}

/* Por debajo de 360 px, además, el monedero sólo con la cifra (sigue siendo la píldora amarilla). */
@media (max-width: 359px) {
  :root[data-style] .topbar.with-bell .container {
    gap: 3px;
  }

  :root[data-style] .topbar.with-bell .topbar-right {
    gap: 3px;
  }

  .topbar.with-bell .nav {
    gap: 3px !important;
  }

  .topbar.with-bell .nav a[data-nav] {
    padding-inline: 3px !important;
  }

  :root[data-style] .topbar.with-bell .topbar-right .icon-btn {
    width: 31px;
  }

  :root[data-style] .topbar.with-bell .coin-pill {
    gap: 0;
    padding: 0 7px;
  }

  :root[data-style] .topbar.with-bell .coin-pill .coin-ico {
    display: none;
  }
}

@keyframes notif-ring {
  0%,
  100% {
    transform: rotate(0);
  }
  15% {
    transform: rotate(16deg);
  }
  30% {
    transform: rotate(-14deg);
  }
  45% {
    transform: rotate(10deg);
  }
  60% {
    transform: rotate(-6deg);
  }
  75% {
    transform: rotate(3deg);
  }
}

/* ───────────────────────────── Panel ───────────────────────────── */

.notif-panel {
  position: fixed;
  z-index: 150;
  top: var(--np-top, calc(var(--topbar-h) + 10px));
  right: var(--np-right, 16px);
  width: min(400px, calc(100vw - 16px));
  max-height: calc(100dvh - var(--np-top, var(--topbar-h)) - 16px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.notif-panel[hidden] {
  display: none;
}

.notif-panel:focus,
:root .notif-panel:focus-visible,
:root[data-style] .notif-panel:focus-visible {
  outline: none;
}

.notif-panel.is-in {
  animation: notif-in 0.18s var(--ease) both;
}

@keyframes notif-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

.notif-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 10px 10px 16px;
  border-bottom: 1px solid var(--border);
}

.notif-title {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 1.05rem;
}

.notif-readall {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.notif-readall svg {
  width: 15px;
  height: 15px;
}

.notif-readall:hover:not(:disabled) {
  background: var(--surface-2);
}

.notif-readall:disabled {
  color: var(--text-3);
  opacity: 0.7;
  cursor: default;
}

.notif-close {
  display: none;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}

.notif-close svg {
  width: 20px;
  height: 20px;
}

.notif-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.notif-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  display: grid;
  gap: 2px;
}

.notif-item {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 12px;
  border-radius: calc(var(--radius) - 4px);
  cursor: pointer;
  transition: background 0.15s;
}

.notif-item:hover {
  background: var(--surface-2);
}

.notif-item.is-off {
  cursor: default;
}

.notif-item.is-new {
  background: var(--accent-soft);
}

.notif-item.is-new::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background: var(--accent);
}

.notif-item .avatar {
  width: 40px;
  height: 40px;
  font-size: 1.3rem;
}

.notif-ava-gift {
  --c: var(--pink);
}

.notif-ava-logro {
  --c: var(--yellow);
}

.notif-ava-gift.sm {
  width: 26px;
  height: 26px;
  font-size: 0.95rem;
}

.notif-main {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.notif-text {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.notif-text b {
  font-weight: 700;
}

.notif-detail {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-2);
}

.notif-time {
  font-size: 0.76rem;
  color: var(--text-3);
}

.notif-item.is-new .notif-time {
  color: var(--accent);
  font-weight: 700;
}

.notif-act {
  flex: none;
  white-space: nowrap;
}

.notif-off {
  max-width: 96px;
  font-size: 0.74rem;
  line-height: 1.25;
  text-align: right;
  color: var(--text-3);
}

.notif-item.is-off .notif-text,
.notif-item.is-off .avatar {
  opacity: 0.7;
}

.notif-empty {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 30px 22px;
  text-align: center;
  color: var(--text-2);
  font-size: 0.9rem;
}

.notif-empty b {
  color: var(--text);
}

.notif-empty-ico svg {
  width: 34px;
  height: 34px;
  color: var(--text-3);
}

.notif-more {
  display: block;
  margin: 2px auto 10px;
}

.notif-more[hidden] {
  display: none;
}

/* Pie: «Activar avisos del navegador» (un interruptor) */
.notif-foot {
  padding: 10px 16px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-solid-2);
}

.notif-foot[hidden] {
  display: none;
}

.notif-switch {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
}

.notif-switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.notif-switch-ui {
  position: relative;
  flex: none;
  width: 40px;
  height: 24px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  transition: background 0.15s;
}

.notif-switch-ui::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-2);
  transition: transform 0.15s, background 0.15s;
}

.notif-switch input:checked + .notif-switch-ui {
  background: var(--green);
}

.notif-switch input:checked + .notif-switch-ui::after {
  transform: translateX(16px);
  background: #fff;
}

.notif-switch input:focus-visible + .notif-switch-ui {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.notif-switch input:disabled + .notif-switch-ui {
  opacity: 0.5;
}

.notif-switch:has(input:disabled) {
  cursor: default;
}

.notif-foot-note {
  margin: 4px 0 0 50px;
  font-size: 0.76rem;
  line-height: 1.35;
  color: var(--text-3);
}

/* Fondo atenuado bajo la hoja del móvil (tocarlo la cierra) */
.notif-scrim {
  position: fixed;
  z-index: 149;
  inset: var(--topbar-h) 0 0;
  background: rgba(0, 0, 0, 0.38);
  animation: notif-fade 0.18s ease both;
}

.notif-scrim[hidden] {
  display: none;
}

@keyframes notif-fade {
  from {
    opacity: 0;
  }
}

/* Móvil: hoja a todo el ancho bajo la barra superior */
@media (max-width: 640px) {
  .notif-panel {
    top: var(--topbar-h);
    left: 0;
    right: 0;
    width: auto;
    max-height: min(82dvh, calc(100dvh - var(--topbar-h)));
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    border-top: 0;
    border-left: 0;
    border-right: 0;
  }

  .notif-panel.is-in {
    animation-name: notif-down;
  }

  @keyframes notif-down {
    from {
      transform: translateY(-14px);
      opacity: 0;
    }
  }

  /* Cabecera en dos filas: «Notificaciones» y cerrar arriba; «Marcar todo como leído» debajo. */
  .notif-head {
    flex-wrap: wrap;
    row-gap: 0;
    padding: 8px 8px 6px 16px;
  }

  .notif-title {
    flex: 1 0 calc(100% - 52px);
  }

  .notif-close {
    display: inline-grid;
    order: 2;
  }

  .notif-readall {
    order: 3;
    margin-left: -8px;
  }

  .notif-item {
    padding: 10px 8px 10px 12px;
  }

  .notif-foot {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .notif-bell.ring svg,
  .notif-panel.is-in,
  .notif-scrim {
    animation: none;
  }
}

/* ───────────────────────────── Aviso en vivo ───────────────────────────── */

.toast.notif .t-icon {
  display: none;
}

.notif-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.notif-toast-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

.notif-toast-go {
  flex: none;
  margin-left: auto;
  font-weight: 700;
  font-size: 0.85rem;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ───────────────────────────── «Invitar a tu sala» ───────────────────────────── */

.inv-modal {
  width: min(460px, calc(100vw - 24px));
}

.inv-body {
  display: grid;
  gap: 10px;
}

.inv-intro {
  margin: 0;
  font-size: 0.9rem;
}

.inv-search[hidden] {
  display: none;
}

.inv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: min(52dvh, 420px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.inv-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
}

.inv-row .avatar {
  width: 36px;
  height: 36px;
  font-size: 1.15rem;
}

.inv-who {
  min-width: 0;
  display: grid;
}

.inv-who b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inv-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-2);
  min-width: 0;
}

.inv-status .dot {
  width: 8px;
  height: 8px;
  animation: none;
}

.inv-btn {
  min-width: 92px;
  justify-content: center;
}

.inv-btn svg {
  width: 15px;
  height: 15px;
}

.inv-btn.is-busy {
  opacity: 0.6;
}

.inv-row.is-offline .avatar,
.inv-row.is-offline .inv-who b {
  opacity: 0.7;
}

.inv-empty {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 18px 12px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-2);
}

.inv-empty b {
  color: var(--text);
}

@media (max-width: 640px) {
  .inv-modal .modal-actions {
    flex-wrap: wrap;
  }

  .inv-modal .modal-actions .btn {
    flex: 1 1 auto;
  }
}

/* ════════════════════════════ Neo-brutalista ════════════════════════════ */

:root[data-style='brutal'] .notif-badge {
  top: -9px;
  right: -9px;
  border: 2px solid var(--px-line);
  border-radius: 6px;
  background: var(--pink);
  color: #111;
  font-family: var(--font-display);
  font-weight: 400;
}

:root[data-style='brutal'] .notif-bell.is-open {
  background: var(--yellow);
  color: #111;
}

:root[data-style='brutal'] .notif-panel {
  border: 3px solid var(--px-line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

:root[data-style='brutal'] .notif-head {
  border-bottom: 3px solid var(--px-line);
  background: var(--yellow);
  color: #111;
}

:root[data-style='brutal'] .notif-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.1rem;
}

:root[data-style='brutal'] .notif-readall,
:root[data-style='brutal'] .notif-close {
  color: #111;
}

:root[data-style='brutal'] .notif-readall:hover:not(:disabled),
:root[data-style='brutal'] .notif-close:hover {
  background: rgba(17, 17, 17, 0.1);
}

:root[data-style='brutal'] .notif-readall:disabled {
  color: rgba(17, 17, 17, 0.5);
}

:root[data-style='brutal'] .notif-item {
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
}

:root[data-style='brutal'] .notif-item:hover {
  background: var(--surface-2);
  border-color: var(--px-line);
}

:root[data-style='brutal'] .notif-item.is-new {
  background: var(--surface-2);
  border-color: var(--px-line);
  box-shadow: inset 6px 0 0 var(--pink);
}

:root[data-style='brutal'] .notif-item.is-new::before {
  display: none;
}

:root[data-style='brutal'] .notif-item.is-new .notif-time {
  color: var(--text);
}

:root[data-style='brutal'] .notif-ava-gift {
  background: var(--pink);
}

:root[data-style='brutal'] .notif-ava-logro {
  background: var(--yellow);
}

:root[data-style='brutal'] .notif-foot {
  border-top: 3px solid var(--px-line);
  background: var(--bg);
}

:root[data-style='brutal'] .notif-switch-ui {
  border: 2px solid var(--px-line);
  background: var(--surface);
}

:root[data-style='brutal'] .notif-switch-ui::after {
  top: 1px;
  left: 1px;
  border: 2px solid var(--px-line);
  background: var(--surface);
}

:root[data-style='brutal'] .notif-switch input:checked + .notif-switch-ui {
  background: var(--green);
}

:root[data-style='brutal'] .notif-switch input:checked + .notif-switch-ui::after {
  background: #fff;
}

:root[data-style='brutal'] .notif-scrim {
  background: rgba(17, 17, 17, 0.42);
}

:root[data-style='brutal'] .toast.notif {
  background: var(--yellow);
  color: #111;
}

:root[data-style='brutal'] .toast.notif .notif-toast-go {
  color: #111;
}

:root[data-style='brutal'] .inv-row {
  border: 2px solid var(--px-line);
  background: var(--surface);
}

:root[data-style='brutal'] .inv-status .dot {
  width: 10px;
  height: 10px;
}

@media (max-width: 640px) {
  :root[data-style='brutal'] .notif-panel {
    border-top: 0;
    border-left: 0;
    border-right: 0;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    box-shadow: 0 6px 0 var(--px-drop);
  }
}

/* ════════════════════════════ Retro (8-bit) ════════════════════════════ */

:root[data-style='retro'] .notif-badge {
  top: -8px;
  right: -8px;
  border-radius: 0;
  background: var(--pink);
  color: #fff;
  font-family: var(--font-arcade);
  font-size: 0.5rem;
  font-weight: 400;
  box-shadow: 0 0 0 2px #0b0620;
}

:root[data-style='retro'] .notif-bell.ring svg {
  animation-timing-function: steps(4);
}

:root[data-style='retro'] .notif-bell.is-open {
  background: #6b4ee6;
}

:root[data-style='retro'] .notif-panel {
  border: 0;
  border-radius: 0;
  background: var(--surface);
  box-shadow: var(--px-outline), var(--shadow);
}

:root[data-style='retro'] .notif-panel.is-in {
  animation-timing-function: steps(3);
}

:root[data-style='retro'] .notif-head {
  border-bottom: 4px solid var(--px-line);
  background: var(--purple);
  color: #fff;
}

:root[data-style='retro'] .notif-title {
  font-family: var(--font-display);
  font-size: 0.9rem;
  text-transform: uppercase;
  color: #ffd23f;
}

:root[data-style='retro'] .notif-readall {
  border-radius: 0;
  font-family: var(--font-display);
  font-size: 0.66rem;
  text-transform: uppercase;
  color: #fff;
}

:root[data-style='retro'] .notif-readall:disabled {
  color: rgba(255, 255, 255, 0.5);
}

:root[data-style='retro'] .notif-readall:hover:not(:disabled),
:root[data-style='retro'] .notif-close:hover {
  background: rgba(255, 255, 255, 0.14);
}

:root[data-style='retro'] .notif-close {
  border-radius: 0;
  color: #fff;
}

:root[data-style='retro'] .notif-item {
  border-radius: 0;
}

:root[data-style='retro'] .notif-item.is-new {
  background: var(--accent-soft);
  box-shadow: inset 4px 0 0 var(--green);
}

:root[data-style='retro'] .notif-item.is-new::before {
  display: none;
}

:root[data-style='retro'] .notif-item.is-new .notif-time {
  color: var(--green);
}

:root[data-style='retro'][data-theme='light'] .notif-item.is-new .notif-time {
  color: #0f7a50;
}

:root[data-style='retro'] .notif-item .avatar,
:root[data-style='retro'] .inv-row .avatar {
  border-radius: 0;
}

:root[data-style='retro'] .notif-time {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1;
}

:root[data-style='retro'] .notif-foot {
  border-top: 4px solid var(--px-line);
  background: var(--surface-2);
}

:root[data-style='retro'] .notif-switch {
  font-family: var(--font-display);
  font-size: 0.72rem;
  text-transform: uppercase;
}

:root[data-style='retro'] .notif-switch-ui {
  border: 0;
  border-radius: 0;
  background: var(--surface-3);
  box-shadow: 0 0 0 3px var(--px-line);
}

:root[data-style='retro'] .notif-switch-ui::after {
  border-radius: 0;
  background: #fff;
  transition-timing-function: steps(2);
}

:root[data-style='retro'] .notif-scrim {
  background: rgba(11, 6, 32, 0.55);
}

:root[data-style='retro'] .toast.notif {
  background: var(--green);
  color: #0c2a1f;
}

:root[data-style='retro'] .toast.notif .notif-toast-go {
  color: #0c2a1f;
}

:root[data-style='retro'] .inv-row {
  border: 0;
  border-radius: 0;
  background: var(--surface-2);
  box-shadow: 0 0 0 3px var(--px-line);
  margin: 3px;
}

:root[data-style='retro'] .inv-status .dot {
  border-radius: 0;
}

@media (max-width: 640px) {
  :root[data-style='retro'] .notif-panel {
    box-shadow: 0 4px 0 var(--px-line), 0 10px 0 var(--px-drop);
  }
}
