/*
 * In-App Push Notifications — shared module
 * iOS-style banners that drop from top, used by:
 *   - Live system (global injection via /inc/in-app-push.php)
 *   - Preview page (/mobile/push-preview.php)
 *
 * Innovation:
 *   - Spatial throw: tap a notif and it flies toward its pill-nav tab
 *   - Group stacking: multiple notifs from same sender collapse with count
 *   - Live typing: DMs show "typing now…" from Spine presence
 */

#iap-stack {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 12px);
  max-width: 420px;
  z-index: 99999;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.iap-notif {
  pointer-events: auto;
  background: oklch(15% .02 260 / .82);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid oklch(100% 0 0 / .09);
  border-radius: 17px;
  padding: 11px 13px 11px 13px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  box-shadow:
    0 14px 36px oklch(0% 0 0 / .5),
    0 1px 0 oklch(100% 0 0 / .05) inset;
  transform: translateY(-160%) scale(.96);
  opacity: 0;
  transition:
    transform .55s cubic-bezier(.32, 1.5, .55, 1),
    opacity .25s;
  will-change: transform, opacity;
  position: relative;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  color: oklch(95% 0 0);
}

.iap-notif.iap-in {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.iap-notif.iap-out-side {
  transform: translateX(120%);
  opacity: 0;
}

.iap-notif.iap-out-up {
  transform: translateY(-160%);
  opacity: 0;
}

/* Spatial throw — flies toward the pill-nav tab the notif deep-links to */
.iap-notif.iap-throw {
  transition:
    transform .45s cubic-bezier(.45, 0, .3, 1),
    opacity .45s cubic-bezier(.45, 0, .3, 1);
  transform: var(--throw-transform, translateY(120vh) scale(.2));
  opacity: 0;
}

.iap-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, oklch(72% .20 350), oklch(45% .18 300));
  display: grid;
  place-items: center;
  font-size: 18px;
  color: white;
  overflow: hidden;
  box-shadow: 0 2px 8px oklch(0% 0 0 / .3);
}

.iap-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.iap-icon-badge {
  position: absolute;
  top: 6px;
  left: 35px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: oklch(55% .25 25);
  color: white;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
  border: 2px solid oklch(15% .02 260);
}

.iap-body {
  flex: 1;
  min-width: 0;
}

.iap-row1 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 1px;
}

.iap-title {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.005em;
}

.iap-time {
  font-size: 11px;
  color: oklch(60% .02 260);
  flex-shrink: 0;
}

.iap-msg {
  font-size: 14px;
  color: oklch(88% 0 0);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  line-height: 1.35;
}

.iap-typing {
  font-size: 12px;
  color: oklch(70% .15 260);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.iap-typing::before {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: oklch(70% .15 260);
  animation: iap-typing-pulse 1s infinite;
}

@keyframes iap-typing-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

.iap-thumb {
  margin-top: 7px;
  width: 100%;
  height: 90px;
  border-radius: 11px;
  background-size: cover;
  background-position: center;
  background-color: oklch(20% 0 0);
}

.iap-actions {
  display: flex;
  gap: 7px;
  margin-top: 10px;
}

.iap-act {
  flex: 1;
  appearance: none;
  border: none;
  cursor: pointer;
  background: oklch(28% .02 260 / .85);
  color: oklch(95% 0 0);
  border-radius: 11px;
  padding: 8px 12px;
  min-height: 44px; /* a11y / senior-friendly touch target */
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: -0.005em;
  touch-action: manipulation;
  transition: transform .12s, background .14s;
}

.iap-act:active {
  transform: scale(.95);
}

.iap-act:focus-visible {
  outline: 2px solid oklch(80% .16 200);
  outline-offset: 2px;
}

.iap-act.iap-primary {
  background: oklch(72% .20 350);
  color: white;
}

.iap-act.iap-danger {
  background: oklch(28% .02 260 / .85);
  color: oklch(70% .22 25);
}

.iap-quick-reply {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.iap-quick-reply input {
  flex: 1;
  appearance: none;
  border: 1px solid oklch(30% 0 0 / .5);
  background: oklch(8% 0 0 / .5);
  color: white;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
}

.iap-quick-reply input:focus {
  border-color: oklch(72% .20 350);
}

.iap-quick-reply button {
  appearance: none;
  border: none;
  background: oklch(72% .20 350);
  color: white;
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.iap-live {
  position: absolute;
  top: 7px;
  right: 9px;
  background: oklch(55% .25 0);
  color: white;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

/* Stack depth: 4+ collapse */
#iap-stack > .iap-notif:nth-last-child(n+4) {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .iap-notif {
    transition: opacity .2s;
  }
  .iap-notif.iap-in {
    transform: translateY(0) scale(1);
  }
}


/* ── Long-press action menu (muzzle / ghost / block / report / reply) ── */
.iap-action-menu {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.iap-action-menu .iap-mi {
  appearance: none;
  border: none;
  background: oklch(0.22 0.02 260 / 0.85);
  color: oklch(0.95 0 0);
  border-radius: 10px;
  padding: 9px 12px;
  font: 500 13px/1 inherit;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms, background 150ms;
}
.iap-action-menu .iap-mi:active { transform: scale(.95); }
.iap-action-menu .iap-mi-primary { background: oklch(0.72 0.20 350); color: white; }
.iap-action-menu .iap-mi-danger  { color: oklch(0.72 0.22 25); }

/* ── In-notif toast for action results ── */
.iap-flash {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: oklch(0.10 0.02 260 / 0.96);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-radius: inherit;
  color: oklch(0.72 0.18 145);
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 200ms ease-out;
  pointer-events: none;
}
.iap-flash.on { opacity: 1; }

/* ── Cruising safety — make absolutely sure the stack doesn't block taps
   below it (only the banner cards themselves intercept). ── */
#iap-stack { pointer-events: none; }
#iap-stack > * { pointer-events: auto; }

/* ── Sound toggle (per-notif tap, state is global / persisted) ── */
.iap-sound-toggle {
  appearance: none;
  border: 0;
  background: oklch(22% .02 260 / .55);
  color: oklch(82% .02 260);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  padding: 0;
  margin-left: 6px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 140ms, transform 120ms, color 140ms;
  touch-action: manipulation;
}
.iap-sound-toggle:hover { background: oklch(28% .02 260 / .8); color: oklch(95% 0 0); }
.iap-sound-toggle:active { transform: scale(.92); }
.iap-sound-toggle[data-state="mute"] {
  background: oklch(28% .05 25 / .55);
  color: oklch(70% .18 25);
}
.iap-sound-toggle[data-state="soft"] {
  color: oklch(72% .15 90);
}

/* ── User preview row (renders when payload has nick/avatar/distance/vibe) ── */
.iap-userpreview {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 6px 0 4px;
  padding: 6px 8px 6px 6px;
  border-radius: 12px;
  background: oklch(20% .015 260 / .55);
  border: 1px solid oklch(100% 0 0 / .06);
}
.iap-up-avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  background: oklch(25% .02 260);
  box-shadow: 0 1px 0 oklch(100% 0 0 / .08) inset;
}
.iap-up-avatar-fallback {
  background: linear-gradient(135deg, oklch(40% .18 320), oklch(50% .15 260));
}
.iap-up-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.iap-up-line1 {
  display: flex;
  align-items: center;
  gap: 5px;
  font: 600 13.5px/1.15 inherit;
  color: oklch(95% 0 0);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.iap-up-line2 {
  display: flex;
  align-items: center;
  gap: 7px;
  font: 500 11.5px/1.2 inherit;
  color: oklch(72% .02 260);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.iap-up-nick { font-weight: 700; }
.iap-up-age  { font-weight: 500; opacity: .72; }
.iap-up-online {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: oklch(72% .22 145);
  box-shadow: 0 0 0 2px oklch(15% .02 260), 0 0 8px oklch(72% .22 145 / .6);
  display: inline-block;
}
.iap-up-vip {
  font: 800 9px/1 ui-monospace, "SF Mono", monospace;
  letter-spacing: .06em;
  padding: 2px 5px;
  border-radius: 4px;
  background: linear-gradient(135deg, oklch(72% .20 90), oklch(68% .22 60));
  color: oklch(12% .02 80);
}
.iap-up-vibe {
  font-size: 14px;
  line-height: 1;
}
.iap-up-doppler {
  font-weight: 600;
  white-space: nowrap;
}
.iap-up-city {
  opacity: .58;
  font-style: italic;
}

/* ── Sender local time ("their clock") — sits in preview line2 ── */
.iap-up-time {
  font-weight: 600;
  white-space: nowrap;
  color: oklch(70% .04 250);
}
.iap-up-time::before {
  content: "";
  display: inline-block;
  width: 4px; height: 4px;
  margin-right: 5px;
  border-radius: 50%;
  background: oklch(60% .03 250);
  vertical-align: middle;
}

/* ── Attachment mini-previews (render under the message when present) ── */
.iap-attwrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.iap-att {
  width: 54px;
  height: 54px;
  border-radius: 10px;
  background-size: cover;
  background-position: center;
  background-color: oklch(22% .015 260);
  border: 1px solid oklch(100% 0 0 / .08);
  flex-shrink: 0;
  display: grid;
  place-items: center;
}
.iap-att-glyph,
.iap-att-more {
  font: 700 10px/1 ui-monospace, "SF Mono", monospace;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: oklch(78% .04 260);
  background: oklch(24% .02 260 / .9);
}
.iap-att-more { color: oklch(72% .20 350); }

/* keyboard focus for the quick-reply input */
.iap-quick-reply input:focus-visible {
  outline: 2px solid oklch(72% .20 350);
  outline-offset: 1px;
}

/* high-contrast support (senior-friendly) */
@media (prefers-contrast: more) {
  .iap-notif { border-color: oklch(100% 0 0 / .35); }
  .iap-msg   { color: oklch(98% 0 0); }
  .iap-time, .iap-up-line2 { color: oklch(86% 0 0); }
}
