/* ============================================================
   Flash messages, "Nuno dice". Markup: shared/_flashes.html.erb.
   Behavior: controllers/shared/flash_controller.js. Dark only.
   ============================================================ */

/* A focused #main-content (after a flash closes) is a target, not a control. */
#main-content:focus { outline: none; }

/* A floating card near the top.
   It overlays the page and pushes nothing down, so a flash that arrives
   mid-page (Turbo Stream) is always in view. --flash-top clears whatever
   holds the top edge: the header (normal screens, and every screen from
   820px), or the back chevron bar of a pushed screen on the phone. */
body { --flash-top: calc(var(--safe-t) + var(--s4)); } /* no header: signed-out pages, admin */

.note-region {
  position: fixed;
  z-index: 60;
  top: var(--flash-top);
  left: calc(env(safe-area-inset-left, 0px) + var(--s4));
  right: calc(env(safe-area-inset-right, 0px) + var(--s4));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  max-height: calc(100dvh - var(--flash-top) - var(--safe-b) - var(--s4));
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  pointer-events: none;
}

/* The app shell: clear its header, plus a gap. */
body:has(.shell:not(.shell--bare)) {
  --flash-top: calc(var(--safe-t) + var(--s2) + var(--tap) + var(--s2) + var(--s2));
}

/* Pushed screen on the phone: no header; clear the back chevron bar instead. */
body:has(.shell--pushed) {
  --flash-top: calc(var(--safe-t) + var(--s4) + var(--s2) + 3.5rem + var(--s2)); /* page top padding + .story-bar */
}

.note-fold {
  display: grid;
  grid-template-rows: 1fr;
  width: 100%;
  max-width: var(--sheet-w);
  min-width: 0;
  transition: grid-template-rows .32s var(--ease), opacity .24s var(--ease);
}

.note-fold > .note { min-height: 0; }
.note-fold + .note-fold > .note { margin-top: var(--s2); }
.note-fold.is-leaving { grid-template-rows: 0fr; opacity: 0; }

.note {
  --tint: var(--accent-soft);

  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  min-width: 0;
  overflow: hidden;
  padding: var(--s3) 0 var(--s4) var(--s4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  background: var(--surface-sheet);
  box-shadow: var(--shadow-float);
  pointer-events: auto;
  animation: note-in .4s var(--ease) backwards;
}

.note--success { --tint: var(--success); }
.note--alert { --tint: var(--danger); background: var(--danger-surface); }
.note-mascot { flex: none; width: 2.75rem; height: auto; margin-top: var(--s1); }
.note--alert .note-mascot { width: 3.5rem; }
.note-body { flex: 1; min-width: 0; padding-top: var(--s1); }
.note-title { margin: 0 0 2px; color: var(--tint); font: 650 var(--text-base) / 1.25 var(--font-display); letter-spacing: -.01em; }

.note-text {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9375rem;
  line-height: 1.45;
  overflow-wrap: anywhere; /* a Stripe request id has no spaces */
}

.note-action {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  margin-top: var(--s3);
  padding: 0 var(--s5);
  border-radius: var(--r-pill);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  text-decoration: none;
}

.note-action:active { background: var(--accent-pressed); }

.note-close {
  display: grid;
  place-items: center;
  flex: none;
  width: var(--tap);
  height: var(--tap);
  margin-right: var(--s1);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}

.note-close svg { fill: currentcolor; }
.note-close:active { background: var(--surface-pressed); }

@keyframes note-in {
  from { opacity: 0; transform: translateY(calc(var(--s3) * -1)); }
}

/* ========== 820px and up: header everywhere, rail on the left ========== */
@media (width >= 820px) {
  body:has(.shell--pushed) {
    --flash-top: calc(var(--safe-t) + var(--s2) + var(--tap) + var(--s2) + var(--s2));
  }

  body:has(.shell:not(.shell--bare)) :is(.note-region, #sd-ios-install-banner),
  body:has(.shell--pushed) :is(.note-region, #sd-ios-install-banner) {
    left: calc(var(--rail-w) + var(--s6));
    right: var(--s6);
  }
}

@media (width >= 1200px) {
  body:has(.shell:not(.shell--bare)) :is(.note-region, #sd-ios-install-banner) { left: calc(6rem + var(--s6)); } /* the rail at this width (shell.css) */
}

/* Reduced motion: no travel or fold; a plain fade stays. */
@media (prefers-reduced-motion: reduce) {
  .note { animation: none; }
  .note-fold { transition: opacity .2s linear; }
}

/* The iOS "add to home screen" hint (controllers/sweetdreams/pwa_controller.js):
   the same floating card as a flash, at the same height, under any flash. */
#sd-ios-install-banner {
  position: fixed;
  z-index: 59;
  top: var(--flash-top);
  left: calc(env(safe-area-inset-left, 0px) + var(--s4));
  right: calc(env(safe-area-inset-right, 0px) + var(--s4));
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.sd-ios-banner-inner {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  max-width: var(--sheet-w);
  padding: var(--s3) 0 var(--s3) var(--s4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  background: var(--surface-sheet);
  box-shadow: var(--shadow-float);
  font-family: var(--font-body);
  pointer-events: auto;
  animation: note-in .4s var(--ease) backwards;
}

.sd-ios-banner-icon { flex: none; width: 2.75rem; height: 2.75rem; border-radius: var(--r-md); }
.sd-ios-banner-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sd-ios-banner-text strong { color: var(--text-primary); font: 650 var(--text-base) / 1.25 var(--font-display); letter-spacing: -.01em; }
.sd-ios-banner-text span { color: var(--text-secondary); font-size: 0.875rem; line-height: 1.4; }
.sd-ios-banner-text em { font-style: normal; font-weight: 700; color: var(--accent-soft); }
.sd-ios-banner-guide { margin-top: var(--s1); color: var(--accent-soft); font-size: 0.875rem; font-weight: 600; text-underline-offset: 2px; }

.sd-ios-banner-close {
  display: grid;
  place-items: center;
  flex: none;
  width: var(--tap);
  height: var(--tap);
  margin-right: var(--s1);
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}
