/**
 * iOS-style Modal Styles
 * Theme-aware dialogs with frosted glass effect
 * Uses CSS variables from themes.css for color consistency
 */

/* ============================================
   CSS Variables for Modal Colors
   ============================================ */
:root {
  /* Default light theme modal colors */
  --modal-bg: rgba(255, 255, 255, 0.92);
  --modal-title-color: #000000;
  --modal-message-color: rgba(0, 0, 0, 0.6);
  --modal-border-color: rgba(0, 0, 0, 0.15);
  --modal-btn-color: #007AFF;
  --modal-btn-active-bg: rgba(0, 0, 0, 0.05);
  --modal-backdrop-bg: rgba(0, 0, 0, 0.4);
  --toast-bg: rgba(0, 0, 0, 0.85);
  --toast-text: #ffffff;
  --paper-shadow-color: rgba(0, 0, 0, 0.2);
}

/* Dark themes - use theme variables with high contrast */
.theme-midnight-cyan,
.theme-monokai,
.theme-solarized,
.theme-dracula,
.theme-nord,
.theme-darkgreen,
.theme-griege-dark {
  --modal-bg: rgba(30, 30, 32, 0.95);
  --modal-title-color: var(--text-primary, #ffffff);
  --modal-message-color: var(--text-secondary, rgba(255, 255, 255, 0.7));
  --modal-border-color: rgba(255, 255, 255, 0.12);
  --modal-btn-color: var(--heading-color, #007AFF);
  --modal-btn-active-bg: rgba(255, 255, 255, 0.1);
  --modal-backdrop-bg: rgba(0, 0, 0, 0.5);
  --toast-bg: rgba(60, 60, 65, 0.95);
  --toast-text: var(--text-primary, #ffffff);
}

/* Light themes - ensure good contrast on light backgrounds */
.theme-maize-yello,
.theme-rouge,
.theme-almond,
.theme-autumn,
.theme-meadow,
.theme-lavender,
.theme-bamboo {
  --modal-bg: rgba(255, 255, 255, 0.95);
  --modal-title-color: var(--text-primary, #1a1a1a);
  --modal-message-color: var(--text-secondary, rgba(0, 0, 0, 0.6));
  --modal-border-color: rgba(0, 0, 0, 0.12);
  --modal-btn-color: var(--heading-color, #007AFF);
  --modal-btn-active-bg: rgba(0, 0, 0, 0.05);
  --modal-backdrop-bg: rgba(0, 0, 0, 0.35);
  --toast-bg: var(--text-primary, rgba(0, 0, 0, 0.85));
  --toast-text: var(--bg-primary, #ffffff);
}

/* ============================================
   Modal Container
   ============================================ */
.ios-modal-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.ios-modal-container.ios-modal-visible {
  opacity: 1;
  visibility: visible;
}

.ios-modal-container.ios-modal-hiding {
  opacity: 0;
}

/* Backdrop with blur */
.ios-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--modal-backdrop-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Dialog Box */
.ios-modal-dialog {
  position: relative;
  width: 90%;
  max-width: 320px;
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ios-modal-visible .ios-modal-dialog {
  transform: scale(1);
}

.ios-modal-hiding .ios-modal-dialog {
  transform: scale(0.9);
}

/* Modal Content - Frosted Glass Effect */
.ios-modal-content {
  background: var(--modal-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-radius: 14px;
  overflow: hidden;
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.25),
    0 0 0 0.5px var(--modal-border-color) inset;
}

/* Header */
.ios-modal-header {
  padding: 20px 16px 16px;
  text-align: center;
}

.ios-modal-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--modal-title-color);
  line-height: 1.3;
}

.ios-modal-message {
  margin: 6px 0 0;
  font-size: 13px;
  font-weight: 400;
  color: var(--modal-message-color);
  line-height: 1.4;
}

/* Actions */
.ios-modal-actions {
  display: flex;
  border-top: 0.5px solid var(--modal-border-color);
}

/* Single button layout */
.ios-modal-actions:has(.ios-modal-btn-primary:only-child) {
  flex-direction: column;
}

/* Buttons */
.ios-modal-btn {
  flex: 1;
  padding: 12px 8px;
  min-height: 44px;
  font-size: 17px;
  font-weight: 400;
  background: transparent;
  border: none;
  border-left: 0.5px solid var(--modal-border-color);
  color: var(--modal-btn-color);
  cursor: pointer;
  transition: background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.ios-modal-btn:first-child {
  border-left: none;
}

.ios-modal-btn:active {
  background: var(--modal-btn-active-bg);
}

.ios-modal-btn:focus {
  outline: none;
}

.ios-modal-btn:focus-visible {
  outline: 2px solid var(--modal-btn-color);
  outline-offset: -2px;
}

/* Cancel button */
.ios-modal-btn-cancel {
  font-weight: 400;
}

/* Confirm button */
.ios-modal-btn-confirm {
  font-weight: 600;
}

/* Primary button (for alerts) */
.ios-modal-btn-primary {
  font-weight: 600;
}

/* Destructive action - always red for visibility */
.ios-modal-btn-destructive {
  color: #FF3B30 !important;
}

/* ============================================
   Toast Notifications
   ============================================ */

.ios-toast-container {
  position: fixed;
  top: calc(20px + var(--safe-area-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10001;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.ios-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: var(--toast-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 100px;
  color: var(--toast-text);
  font-size: 15px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translateY(-20px) scale(0.9);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: auto;
}

.ios-toast-show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.ios-toast-hide {
  opacity: 0;
  transform: translateY(-10px) scale(0.95);
}

.ios-toast-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
}

/* Toast type colors - consistent across themes */
.ios-toast-success .ios-toast-icon {
  background: #34C759;
  color: #ffffff;
}

.ios-toast-error .ios-toast-icon {
  background: #FF3B30;
  color: #ffffff;
}

.ios-toast-info .ios-toast-icon {
  background: #007AFF;
  color: #ffffff;
}

.ios-toast-message {
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================
   Mobile Responsive
   ============================================ */

@media (max-width: 576px) {
  .ios-modal-dialog {
    width: calc(100% - 32px);
    max-width: none;
  }

  .ios-modal-btn {
    min-height: 48px;
  }
}

/* ============================================
   Reduced Motion Support
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .ios-modal-container,
  .ios-modal-dialog,
  .ios-toast {
    transition: opacity 0.15s ease;
  }

  .ios-modal-dialog {
    transform: none;
  }

  .ios-modal-visible .ios-modal-dialog,
  .ios-modal-hiding .ios-modal-dialog {
    transform: none;
  }
}
