/*
 * ============================================================================
 * COMPONENTS - Consolidated UI Component Library
 * ============================================================================
 *
 * This file consolidates all interactive UI components following Powell's
 * minimal CSS philosophy while maintaining Rails conventions.
 *
 * Contents:
 * Page back button and the unsubscribe pages' wrapper
 * 5. Modals - Native dialog based modal system
 * 6. Flash Messages & Notifications - User feedback and alerts
 *
 * Architecture:
 * - Mobile-first responsive design
 * - Accessibility built-in (focus states, reduced motion)
 * - Modern CSS (custom properties, oklch colors)
 * - Turbo-ready (progressive enhancement)
 */

/* ============================================================================
   5. MODALS
   ============================================================================ */

/* Modal Styles - Native dialog based */
dialog.modal-dialog {
  border: none;
  padding: var(--sp-2);
  background: transparent;
  color: inherit;
  margin: 0;
  max-width: 100dvw;
  max-height: 100dvh;
  width: 100dvw;
  height: 100dvh;
}

dialog.modal-dialog[open] {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease-out;
}

dialog.modal-dialog::backdrop {
  background: var(--scrim);
}

@media (min-width: 48rem) {
  dialog.modal-dialog::backdrop {
    background: color-mix(in oklch, var(--scrim) 60%, transparent);
    backdrop-filter: blur(4px);
  }
}


/* Prevent body scroll when modal is open */
body:has(dialog.modal-dialog[open]) {
  overflow: hidden;
}

/* ============================================================================
   SLIDE-IN PANEL / BOTTOM SHEET
   ============================================================================ */

/* Prevent body scroll when panel is open */
body:has(turbo-frame#panel:not(:empty)) {
  overflow: hidden;
}

/* ============================================================================
   6. FLASH MESSAGES & NOTIFICATIONS
   ============================================================================ */

/* Flash Messages Container */
#flash-messages {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--sp-4);
  padding-top: calc(var(--sp-4) + var(--safe-inset-top));
  pointer-events: none;
  gap: var(--sp-2);
}

/* Flash: a banner on a translucent material, as iOS notifications are. It
   drops in from the top edge with a little bounce and leaves the same way
   (flash_controller.js), and can be swiped up at any time. */
.flash {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: min(100%, 440px);
  padding: 12px var(--sp-4);
  border: 0.5px solid var(--material-edge);
  border-radius: var(--r-modal);
  background: var(--material);
  -webkit-backdrop-filter: var(--material-filter);
  backdrop-filter: var(--material-filter);
  box-shadow: var(--sh-2);
  color: var(--tx);
  font: var(--fw-regular) var(--t-body) var(--font);
  touch-action: none;
  cursor: grab;
  user-select: none;
  animation: flash-drop var(--spring-bounce-dur) var(--spring-bounce) backwards;
}

.flash:active {
  cursor: grabbing;
}

.flash__body {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}

.flash__action {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: var(--r-pill);
  background: var(--ac);
  color: var(--ac-ink);
  font: var(--fw-semibold) var(--t-label) var(--font);
  white-space: nowrap;
  text-decoration: none;
}

.flash__action:hover {
  background: color-mix(in oklch, var(--ac) 92%, black);
  color: var(--ac-ink);
}

/* The icon carries the kind: a filled accent disc for done, warning colour
   for an alert */
.flash--success .flash__icon {
  width: 28px;
  height: 28px;
  border-radius: var(--r-pill);
  background: var(--ac);
  color: var(--ac-ink);
}

.flash--success .flash__icon .icon {
  width: 16px;
  height: 16px;
}

.flash--alert .flash__icon {
  color: var(--warn);
}

@keyframes flash-drop {
  from {
    opacity: 0;
    transform: translateY(calc(-100% - 24px));
  }
}

/* Flash Icon */
.flash__icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.flash__icon .icon {
  width: 20px;
  height: 20px;
}

/* Flash Text */
.flash__text {
  flex: 1;
  font-weight: var(--fw-medium);
  word-wrap: break-word;
}

/* Close Button */
.flash__close {
  flex-shrink: 0;
  padding: var(--sp-1);
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  opacity: 0.7;
  color: inherit;
  transition: opacity 0.15s ease;
}

.flash__close .icon {
  width: 16px;
  height: 16px;
}

.flash__close:hover {
  opacity: 1;
}

/* Responsive Design */
@media (max-width: 68.6875rem) {
  #flash-messages {
    padding-left: var(--sp-2);
    padding-right: var(--sp-2);
  }

  .flash {
    width: 100%;
  }

  .flash--alert {
    align-items: flex-start;
  }

  .flash--alert .flash__body {
    flex-direction: column;
    gap: var(--sp-1);
    padding-top: 2px;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .flash__close {
    border: var(--bw) solid currentColor;
  }
}

/* ============================================================================
   REDUCED MOTION SUPPORT
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {

  .flash {
    animation: none;
  }

  #flash-messages {
    animation: none;
  }
}
