/* Agend One – Notificaciones globales (flash / avisos)
   Inspirado en Uiverse (JohnnyCSilva) pero adaptado:
   - prefijo ao- para no chocar con Bootstrap (.card)
   - colores con tokens (--card, --ink, --muted, --border, --brand-*)
   - animación entrada/salida + reduce motion
   - “glass / cristal Apple”: blur + saturate + capas + borde luminoso
*/

:root {
  --ao-notify-w: 320px;
  --ao-notify-radius: 18px;

  /* Sombra tipo burbuja */
  --ao-notify-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);

  /* Borde base (se mezcla con blanco/negro según modo) */
  --ao-notify-border: rgba(148, 163, 184, 0.22);

  /* Glass tuning */
  --ao-notify-blur: 28px;
  --ao-notify-sat: 1.6;

  /* Edge blur (anillo) */
  --ao-edge-pad: 10px; /* grosor del borde “cristal” */
  --ao-edge-blur: 46px; /* blur extra SOLO en el borde */

  --ao-notify-z: 2147483000;

  /* =========
     Fluid Glass (lens) – sin dependencias
     ========= */
  --ao-lens-size: 96px;
  --ao-lens-blur: 10px;
  --ao-lens-sat: 1.6;
  --ao-lens-opacity: 0.92;
  --ao-lens-edge: rgba(255, 255, 255, 0.38);
  --ao-lens-shadow: 0 14px 30px rgba(15, 23, 42, 0.18);

  /* =========
     Fluid Glass Background (fondo “vivo”, NO sigue ratón)
     ========= */
  --ao-fluid-opacity: 0.55;
  --ao-fluid-blur: 18px;
  --ao-fluid-grain: 0.24;
}

/* Stack (top-center) */
.ao-notify-stack {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top, 0px));
  left: 50%;
  right: auto;
  z-index: var(--ao-notify-z);
  isolation: isolate;
  transform: translateX(-50%) translateZ(0);

  display: grid;
  gap: 10px;
  width: min(var(--ao-notify-w), calc(100vw - 28px));
  pointer-events: none;
}

/* Tarjeta */
.ao-notify {
  pointer-events: auto;
  position: relative;
  isolation: isolate;

  display: flex;
  align-items: center;
  gap: 10px;

  width: 100%;
  min-height: 74px;

  border-radius: var(--ao-notify-radius);

  /* GLASS: el truco es que el fondo tenga ALFA (no opaco), si no, el blur no “se ve” */
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.28),
    rgba(255, 255, 255, 0.16)
  );

  /* Borde luminoso (no “gris plano”) */
  border: 1px solid color-mix(in srgb, #ffffff 42%, var(--ao-notify-border));

  /* “tinte” del anillo (se sobreescribe en dark mode) */
  --ao-edge-bg: rgba(255, 255, 255, 0.12);
  --ao-edge-stroke: rgba(255, 255, 255, 0.28);

  /* Blur real (Safari necesita -webkit-) */
  -webkit-backdrop-filter: blur(var(--ao-notify-blur))
    saturate(var(--ao-notify-sat)) contrast(1.08);
  backdrop-filter: blur(var(--ao-notify-blur)) saturate(var(--ao-notify-sat))
    contrast(1.08);

  /* Sombra + brillo interno */
  box-shadow:
    var(--ao-notify-shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    inset 0 -1px 0 rgba(255, 255, 255, 0.18);

  overflow: hidden;

  transform: translateY(-14px);
  opacity: 0;
  animation: aoNotifyIn 0.32s cubic-bezier(0.2, 0.9, 0.2, 1) forwards;

  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease;
}

/* Capa “sheen” (reflejo suave, estilo burbuja) */
.ao-notify::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;

  background:
    radial-gradient(
      900px 140px at 35% 0%,
      rgba(255, 255, 255, 0.55),
      rgba(255, 255, 255, 0) 55%
    ),
    radial-gradient(
      500px 220px at 110% 40%,
      rgba(0, 0, 0, 0.06),
      rgba(0, 0, 0, 0) 55%
    );

  opacity: 0.65;
}

/* =========
   WebGL Glass Background (React/R3F) – host del canvas
   ========= */
.ao-notify__webgl {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
  pointer-events: none;
  z-index: 0; /* debajo del edge (1) y del contenido (3) */
}

.ao-notify__webgl canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* Opcional pero recomendado: si activas WebGL, que el “fondo CSS” no pelee */
.ao-notify.ao-notify--webgl {
  background: transparent;
}

/* =========
   Fluid Glass Background (inyectado por JS)
   - Fondo “vivo” con capas, grano y ligerísima aberración
   - NO sigue ratón (animación suave)
   ========= */
.ao-notify__fluid {
  position: absolute;
  inset: -20%;
  border-radius: inherit;
  pointer-events: none;
  z-index: 0;

  opacity: var(--ao-fluid-opacity);
  mix-blend-mode: overlay; /* mezcla tipo “cristal” :contentReference[oaicite:2]{index=2} */
  filter: blur(var(--ao-fluid-blur)) saturate(1.25);

  transform: translate3d(var(--ao-fluid-x1, -10%), var(--ao-fluid-y1, -8%), 0)
    scale(1.2) rotate(var(--ao-fluid-rot, 0deg));

  background:
    radial-gradient(
      900px 520px at 22% 28%,
      rgba(255, 255, 255, 0.55),
      rgba(255, 255, 255, 0) 62%
    ),
    radial-gradient(
      860px 520px at 78% 78%,
      rgba(0, 0, 0, 0.12),
      rgba(0, 0, 0, 0) 60%
    ),
    conic-gradient(
      from 210deg at 50% 50%,
      rgba(255, 0, 90, 0.06),
      rgba(0, 180, 255, 0.06),
      rgba(255, 255, 255, 0.02),
      rgba(255, 0, 90, 0.06)
    );

  animation: aoFluidMove var(--ao-fluid-speed, 7.5s) ease-in-out infinite
    alternate;
  animation-delay: var(--ao-fluid-delay, 0s);
  will-change: transform, filter;
}

/* Grano suave (sin assets) */
.ao-notify__fluid::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;

  background:
    repeating-linear-gradient(
      115deg,
      rgba(255, 255, 255, 0.04) 0 2px,
      rgba(255, 255, 255, 0) 2px 7px
    ),
    repeating-linear-gradient(
      35deg,
      rgba(0, 0, 0, 0.035) 0 1px,
      rgba(0, 0, 0, 0) 1px 6px
    );

  opacity: var(--ao-fluid-grain);
  mix-blend-mode: soft-light;
  animation: aoFluidGrain 2.2s steps(6) infinite;
}

/* “cromático” super sutil */
.ao-notify__fluid::after {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: inherit;
  pointer-events: none;

  background:
    radial-gradient(circle at 36% 26%, rgba(255, 0, 90, 0.12), transparent 58%),
    radial-gradient(circle at 72% 78%, rgba(0, 180, 255, 0.1), transparent 60%);

  opacity: 0.55;
  filter: blur(8px);
  mix-blend-mode: screen;
}

@keyframes aoFluidMove {
  0% {
    transform: translate3d(var(--ao-fluid-x1, -10%), var(--ao-fluid-y1, -8%), 0)
      scale(1.18) rotate(var(--ao-fluid-rot, 0deg));
    filter: blur(var(--ao-fluid-blur)) saturate(1.2);
  }
  100% {
    transform: translate3d(var(--ao-fluid-x2, 10%), var(--ao-fluid-y2, 8%), 0)
      scale(1.22) rotate(calc(0deg - var(--ao-fluid-rot, 0deg)));
    filter: blur(calc(var(--ao-fluid-blur) - 3px)) saturate(1.35);
  }
}

@keyframes aoFluidGrain {
  0% {
    transform: translate3d(0, 0, 0);
    opacity: var(--ao-fluid-grain);
  }
  100% {
    transform: translate3d(1.5%, -1.2%, 0);
    opacity: calc(var(--ao-fluid-grain) * 0.9);
  }
}

/* =========
   Edge Blur Ring (cristal fuerte en bordes)
   ========= */
.ao-notify__edge {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 1; /* antes 0: subimos para que el ring quede por encima del “fluid” */

  /* El truco: este overlay tiene blur más fuerte,
     pero lo “recortamos” para que sólo quede el anillo */
  padding: var(--ao-edge-pad);

  background: var(--ao-edge-bg);
  border: 1px solid var(--ao-edge-stroke);

  -webkit-backdrop-filter: blur(var(--ao-edge-blur)) saturate(1.85)
    contrast(1.12);
  backdrop-filter: blur(var(--ao-edge-blur)) saturate(1.85) contrast(1.12);

  /* Máscara para dejar SOLO el borde (ring) */
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude; /* :contentReference[oaicite:3]{index=3} */

  /* un pelín de “bisel” interno para que cante */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

/* =========
   Fluid Glass Lens (elemento inyectado por JS)
   - Sigue el puntero con easing (JS)
   - Da sensación de “lente/refracción” con backdrop-filter + capas
   ========= */
.ao-notify__lens {
  position: absolute;
  z-index: 2;
  pointer-events: none;

  width: var(--ao-lens-size);
  height: var(--ao-lens-size);
  border-radius: 999px;

  left: var(--ao-lens-x, 50%);
  top: var(--ao-lens-y, 45%);
  transform: translate(-50%, -50%) translateZ(0);

  opacity: 0;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;

  /* “lente” */
  background:
    radial-gradient(
      circle at 32% 28%,
      rgba(255, 255, 255, 0.82),
      rgba(255, 255, 255, 0.18) 42%,
      rgba(255, 255, 255, 0) 70%
    ),
    radial-gradient(
      circle at 70% 78%,
      rgba(0, 0, 0, 0.08),
      rgba(0, 0, 0, 0) 55%
    );

  border: 1px solid var(--ao-lens-edge);

  -webkit-backdrop-filter: blur(var(--ao-lens-blur))
    saturate(var(--ao-lens-sat));
  backdrop-filter: blur(var(--ao-lens-blur)) saturate(var(--ao-lens-sat));

  box-shadow:
    var(--ao-lens-shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    inset 0 -1px 0 rgba(0, 0, 0, 0.08);

  mix-blend-mode: overlay;
  will-change: left, top, transform;
  display: none !important;
}

/* Brillo “cromático” (aberración suave) */
.ao-notify__lens::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 999px;
  pointer-events: none;

  background:
    radial-gradient(circle at 40% 35%, rgba(255, 0, 90, 0.18), transparent 58%),
    radial-gradient(
      circle at 62% 68%,
      rgba(0, 180, 255, 0.16),
      transparent 60%
    ),
    radial-gradient(
      circle at 50% 50%,
      rgba(255, 255, 255, 0.12),
      transparent 62%
    );
  filter: blur(2px);
  opacity: 0.9;
}

/* “Micro-sheen” animado dentro de la lente */
.ao-notify__lens::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 999px;
  pointer-events: none;

  background: conic-gradient(
    from 180deg at 50% 50%,
    rgba(255, 255, 255, 0) 0deg,
    rgba(255, 255, 255, 0.22) 40deg,
    rgba(255, 255, 255, 0) 90deg,
    rgba(255, 255, 255, 0.18) 140deg,
    rgba(255, 255, 255, 0) 220deg,
    rgba(255, 255, 255, 0.16) 280deg,
    rgba(255, 255, 255, 0) 360deg
  );

  opacity: 0.6;
  animation: aoLensSheen 2.4s ease-in-out infinite;
}

.ao-notify:hover .ao-notify__lens,
.ao-notify.ao-notify--glass-on .ao-notify__lens {
  opacity: var(--ao-lens-opacity);
}

.ao-notify:hover .ao-notify__lens {
  transform: translate(-50%, -50%) scale(1.03) translateZ(0);
}

/* Asegura que el contenido quede por encima del sheen (sin romper la lente) */
.ao-notify
  > :not(.ao-notify__lens):not(.ao-notify__edge):not(.ao-notify__fluid):not(
    .ao-notify__webgl
  ) {
  position: relative;
  z-index: 3;
}

/* Hover: elevación + sombra */
.ao-notify:hover {
  transform: translateY(0) scale(1.02);
  box-shadow:
    0 16px 44px rgba(15, 23, 42, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.75),
    inset 0 -1px 0 rgba(255, 255, 255, 0.2);
  cursor: pointer;
}

/* “Img” (cuadradito con color por severidad + logo) */
.ao-notify__img {
  width: 52px;
  height: 52px;
  margin-left: 12px;
  border-radius: 12px;
  flex: 0 0 auto;

  position: relative;
  overflow: hidden;

  background: var(
    --ao-notify-img-bg,
    linear-gradient(135deg, var(--brand-2, #60a5fa), var(--brand-3, #a78bfa))
  );

  /* pequeño brillo tipo sticker */
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 6px 16px rgba(15, 23, 42, 0.16);

  transition:
    filter 0.25s ease,
    transform 0.25s ease;
}

/* Logo encima del color */
.ao-notify__img::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("/static/img/logo_ao.png") center / 72% no-repeat;
  opacity: 0.95;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
}

.ao-notify:hover .ao-notify__img {
  filter: saturate(1.2) contrast(1.1);
  transform: scale(1.03);
}

/* Contenido */
.ao-notify__text {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 44px 10px 0;
  /* deja hueco a la X */
  color: var(--ink, #0f172a);
  font-family: var(
    --font-sans,
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Arial,
    sans-serif
  );
}

.ao-notify__head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-width: 0;
}

.ao-notify__title {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.1px;
  color: var(--ink, #0f172a);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
  min-width: 0;
}

.ao-notify__meta {
  font-size: 11px;
  color: color-mix(in srgb, var(--muted, #64748b) 92%, transparent);
  white-space: nowrap;
  flex: 0 0 auto;
}

.ao-notify__meta::before {
  content: "·";
  margin-right: 6px;
  opacity: 0.7;
}

.ao-notify__msg {
  margin: 2px 0 0 0;
  font-size: 12.5px;
  line-height: 1.25rem;
  color: color-mix(in srgb, var(--ink, #0f172a) 86%, transparent);

  /* Antes: clamp a 2 líneas (se “cortaba” el flash).
      Ahora: mínimo igual si el texto es corto, pero crece si hay más contenido. */
  display: block;
  overflow: visible;
  white-space: pre-line;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Botón cerrar */
.ao-notify__close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 4;

  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;

  border: 0;
  border-radius: 10px;

  background: transparent;
  color: color-mix(in srgb, var(--muted, #64748b) 86%, transparent);
  transition:
    background 0.15s ease,
    color 0.15s ease,
    transform 0.15s ease;
}

.ao-notify__close:hover {
  background: rgba(255, 255, 255, 0.45);
  color: var(--ink, #0f172a);
  transform: scale(1.04);
}

/* Acento lateral (barrita) */
.ao-notify::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  z-index: 2;

  background: color-mix(in srgb, var(--brand-2, #60a5fa) 80%, transparent);
  opacity: 0.9;
}

/* Variantes (solo afectan el “img” y el acento lateral) */
.ao-notify--success {
  --ao-notify-img-bg: linear-gradient(135deg, #34d399, #10b981);
}

.ao-notify--info {
  --ao-notify-img-bg: linear-gradient(135deg, #60a5fa, #3b82f6);
}

.ao-notify--warning {
  --ao-notify-img-bg: linear-gradient(135deg, #fbbf24, #f59e0b);
}

.ao-notify--danger {
  --ao-notify-img-bg: linear-gradient(135deg, #fb7185, #ef4444);
}

.ao-notify--success::before {
  background: #10b981;
}

.ao-notify--info::before {
  background: #3b82f6;
}

.ao-notify--warning::before {
  background: #f59e0b;
}

.ao-notify--danger::before {
  background: #ef4444;
}

/* Salida */
.ao-notify.ao-notify--out {
  animation: aoNotifyOut 0.22s ease forwards;
}

@keyframes aoNotifyIn {
  from {
    opacity: 0;
    transform: translateY(-16px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes aoNotifyOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  to {
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
  }
}

@keyframes aoLensSheen {
  0% {
    transform: rotate(0deg);
    opacity: 0.45;
  }
  50% {
    transform: rotate(22deg);
    opacity: 0.7;
  }
  100% {
    transform: rotate(0deg);
    opacity: 0.45;
  }
}

/* Dark mode: cristal oscuro (tipo iOS dark) */
:where(body.dark-mode, [data-bs-theme="dark"]) .ao-notify {
  --ao-edge-bg: rgba(255, 255, 255, 0.06);
  --ao-edge-stroke: rgba(255, 255, 255, 0.14);

  background: linear-gradient(
    180deg,
    rgba(17, 24, 39, 0.52),
    rgba(17, 24, 39, 0.34)
  );
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow:
    0 14px 40px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -1px 0 rgba(0, 0, 0, 0.25);
}

:where(body.dark-mode, [data-bs-theme="dark"]) .ao-notify::after {
  opacity: 0.55;
}

:where(body.dark-mode, [data-bs-theme="dark"]) .ao-notify__close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.9);
}

:where(body.dark-mode, [data-bs-theme="dark"]) .ao-notify__lens {
  --ao-lens-edge: rgba(255, 255, 255, 0.22);
  --ao-lens-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  mix-blend-mode: screen;
}

:where(body.dark-mode, [data-bs-theme="dark"]) .ao-notify__lens::before {
  opacity: 0.75;
}

:where(body.dark-mode, [data-bs-theme="dark"]) .ao-notify__fluid {
  opacity: 0.42;
  mix-blend-mode: screen;
  filter: blur(var(--ao-fluid-blur)) saturate(1.35);
}

/* Fallback: si NO hay backdrop-filter, hacemos “burbuja” sin blur (pero decente) */
@supports not (
  (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))
) {
  .ao-notify {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: color-mix(in srgb, var(--card, #ffffff) 92%, transparent);
  }

  /* Sin backdrop-filter, el “fluid” pierde el sentido de cristal: lo apagamos */
  .ao-notify__fluid {
    display: none;
  }

  /* Sin backdrop-filter la “lente” pierde sentido: la apagamos */
  .ao-notify__lens {
    display: none;
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .ao-notify {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .ao-notify.ao-notify--out {
    animation: none;
  }

  .ao-notify:hover {
    transform: none;
  }

  .ao-notify__fluid,
  .ao-notify__fluid::before,
  .ao-notify__fluid::after,
  .ao-notify__lens,
  .ao-notify__lens::after {
    animation: none !important;
    transition: none !important;
    opacity: 0 !important;
  }
}
