/* ══════════════════════════════════════════════════
   Modal Dialog — confirmation & informational overlay
   Replaces SweetAlert v1/v2 across the entire app.
   Design system matches status-modal & dark-toast.
   ══════════════════════════════════════════════════ */

/* ── Variables ── */
.md-overlay {
  --md-navy: #1E1B4B;
  --md-surface: #252249;
  --md-border: rgba(255, 255, 255, 0.06);
  --md-text-primary: #F1F0F7;
  --md-text-secondary: #9896B8;
  --md-accent: #F59E0B;
  --md-accent-glow: rgba(245, 158, 11, 0.15);
  --md-accent-glow-strong: rgba(245, 158, 11, 0.35);
  --md-accent-ring: rgba(245, 158, 11, 0.2);
  --md-accent-bg: rgba(245, 158, 11, 0.12);
  --md-accent-bg-subtle: rgba(245, 158, 11, 0.04);
  --md-accent-shadow: rgba(245, 158, 11, 0.3);
  --md-accent-shadow-hover: rgba(245, 158, 11, 0.4);
  --md-accent-dark: #D97706;
}

/* ── Variant overrides ── */
.md-overlay.md--error {
  --md-accent: #F43F5E;
  --md-accent-glow: rgba(244, 63, 94, 0.15);
  --md-accent-glow-strong: rgba(244, 63, 94, 0.35);
  --md-accent-ring: rgba(244, 63, 94, 0.2);
  --md-accent-bg: rgba(244, 63, 94, 0.12);
  --md-accent-bg-subtle: rgba(244, 63, 94, 0.04);
  --md-accent-shadow: rgba(244, 63, 94, 0.3);
  --md-accent-shadow-hover: rgba(244, 63, 94, 0.4);
  --md-accent-dark: #E11D48;
}

.md-overlay.md--success {
  --md-accent: #22C55E;
  --md-accent-glow: rgba(34, 197, 94, 0.15);
  --md-accent-glow-strong: rgba(34, 197, 94, 0.35);
  --md-accent-ring: rgba(34, 197, 94, 0.2);
  --md-accent-bg: rgba(34, 197, 94, 0.12);
  --md-accent-bg-subtle: rgba(34, 197, 94, 0.04);
  --md-accent-shadow: rgba(34, 197, 94, 0.3);
  --md-accent-shadow-hover: rgba(34, 197, 94, 0.4);
  --md-accent-dark: #16A34A;
}

/* warning is the default accent above */

.md-overlay.md--info,
.md-overlay.md--confirm-neutral {
  --md-accent: #6D4AE8;
  --md-accent-glow: rgba(109, 74, 232, 0.15);
  --md-accent-glow-strong: rgba(109, 74, 232, 0.35);
  --md-accent-ring: rgba(109, 74, 232, 0.2);
  --md-accent-bg: rgba(109, 74, 232, 0.12);
  --md-accent-bg-subtle: rgba(109, 74, 232, 0.04);
  --md-accent-shadow: rgba(109, 74, 232, 0.3);
  --md-accent-shadow-hover: rgba(109, 74, 232, 0.4);
  --md-accent-dark: #5B3AC4;
}

.md-overlay.md--confirm-destructive {
  --md-accent: #F59E0B;
  --md-accent-glow: rgba(245, 158, 11, 0.15);
  --md-accent-glow-strong: rgba(245, 158, 11, 0.35);
  --md-accent-ring: rgba(245, 158, 11, 0.2);
  --md-accent-bg: rgba(245, 158, 11, 0.12);
  --md-accent-bg-subtle: rgba(245, 158, 11, 0.04);
  --md-accent-shadow: rgba(245, 158, 11, 0.3);
  --md-accent-shadow-hover: rgba(245, 158, 11, 0.4);
  --md-accent-dark: #D97706;
}

/* ── Backdrop / overlay ── */
.md-overlay {
  position: fixed;
  inset: 0;
  z-index: 100001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s ease, visibility .3s ease;
}

.md-overlay.md--visible {
  opacity: 1;
  visibility: visible;
}

.md-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 9, 30, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* ── Ambient glow ── */
.md-ambient {
  position: absolute;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--md-accent-glow) 0%, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%);
  pointer-events: none;
  animation: md-pulse-glow 3s ease-in-out infinite;
}

@keyframes md-pulse-glow {
  0%, 100% { opacity: 0.5; transform: translate(-50%, -55%) scale(1); }
  50% { opacity: 0.8; transform: translate(-50%, -55%) scale(1.08); }
}

/* ── Modal card ── */
.md-modal {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 400px;
  background: var(--md-surface);
  border: 1px solid var(--md-border);
  border-radius: 24px;
  padding: 40px 36px 32px;
  text-align: center;
  font-family: 'Outfit', 'Cairo', sans-serif;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.03) inset,
    0 24px 80px rgba(0, 0, 0, 0.5),
    0 8px 32px rgba(0, 0, 0, 0.3);
  transform: translateY(24px) scale(0.96);
  opacity: 0;
  transition: transform .45s cubic-bezier(0.16, 1, 0.3, 1), opacity .45s cubic-bezier(0.16, 1, 0.3, 1);
}

.md--visible .md-modal {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* Noise texture */
.md-modal::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 24px;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
}

/* ── Floating particles ── */
.md-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: 24px;
}

.md-particle {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--md-accent);
  opacity: 0;
}

.md-particle:nth-child(1) { top: 18%; left: 12%; animation: md-particle-float 5s 0s infinite; }
.md-particle:nth-child(2) { top: 32%; right: 15%; animation: md-particle-float 6s 1.5s infinite; }
.md-particle:nth-child(3) { bottom: 28%; left: 20%; animation: md-particle-float 4.5s 0.8s infinite; }
.md-particle:nth-child(4) { top: 60%; right: 10%; animation: md-particle-float 5.5s 2s infinite; }

@keyframes md-particle-float {
  0%   { opacity: 0;    transform: translateY(8px) scale(0.5); }
  20%  { opacity: 0.25; }
  50%  { opacity: 0.15; transform: translateY(-12px) scale(1); }
  80%  { opacity: 0.25; }
  100% { opacity: 0;    transform: translateY(-24px) scale(0.5); }
}

/* ── Icon ring ── */
.md-icon-container {
  margin-bottom: 28px;
  opacity: 0;
  transform: scale(0.5) rotate(-10deg);
  transition: opacity .5s .15s cubic-bezier(0.34, 1.56, 0.64, 1),
              transform .5s .15s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.md--visible .md-icon-container {
  opacity: 1;
  transform: scale(1) rotate(0);
}

.md-icon-ring {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  animation: md-float 4s ease-in-out infinite;
}

@keyframes md-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* Rotating conic ring */
.md-icon-ring::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  background: conic-gradient(from 180deg, transparent, var(--md-accent-glow-strong), transparent);
  animation: md-ring-rotate 6s linear infinite;
}

@keyframes md-ring-rotate {
  to { transform: rotate(360deg); }
}

.md-icon-ring-inner {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--md-accent-bg), var(--md-accent-bg-subtle));
  border: 1.5px solid var(--md-accent-ring);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
}

/* ── SVG icon base ── */
.md-icon-svg {
  width: 36px;
  height: 36px;
  fill: none;
  stroke: var(--md-accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Icon draw animations (Lucide 24x24 paths) ── */

/* Shared: circle draw (r=10 → circumference ≈ 62.83) */
.md-icon-svg .md-circle {
  stroke-dasharray: 63;
  stroke-dashoffset: 63;
}
.md--visible .md-icon-svg .md-circle {
  animation: md-draw 0.8s 0.4s ease-out forwards;
}

/* ── x-circle (error): circle + two X strokes ── */
.md-icon-svg .md-x1,
.md-icon-svg .md-x2 {
  stroke-dasharray: 9;
  stroke-dashoffset: 9;
}
.md--visible .md-icon-svg .md-x1 { animation: md-draw 0.3s 1.0s ease-out forwards; }
.md--visible .md-icon-svg .md-x2 { animation: md-draw 0.3s 1.15s ease-out forwards; }

/* ── check-circle (success): open arc + checkmark ── */
/* The arc path (M21.801 10A10 10...) is ~60 long */
.md-icon-svg .md-check {
  stroke-dasharray: 24;
  stroke-dashoffset: 24;
}
.md--visible .md-icon-svg .md-check { animation: md-draw 0.5s 1.0s ease-out forwards; }

/* ── alert-triangle (warning): triangle outline + exclamation ── */
.md-icon-svg .md-tri {
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
}
.md--visible .md-icon-svg .md-tri { animation: md-draw 0.7s 0.4s ease-out forwards; }

.md-icon-svg .md-excl-line {
  stroke-dasharray: 4;
  stroke-dashoffset: 4;
}
.md-icon-svg .md-excl-dot {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}
.md--visible .md-icon-svg .md-excl-line { animation: md-draw 0.3s 1.0s ease-out forwards; }
.md--visible .md-icon-svg .md-excl-dot  { animation: md-draw 0.2s 1.2s ease-out forwards; }

/* Gentle pulse after triangle draws */
.md--visible .md-icon-svg .md-tri {
  animation: md-draw 0.7s 0.4s ease-out forwards, md-tri-pulse 2s 1.4s ease-in-out infinite;
}
@keyframes md-tri-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ── info: circle + "i" (line + dot) ── */
.md-icon-svg .md-info-line {
  stroke-dasharray: 4;
  stroke-dashoffset: 4;
}
.md-icon-svg .md-info-dot {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}
.md--visible .md-icon-svg .md-info-dot  { animation: md-draw 0.3s 1.0s ease-out forwards; }
.md--visible .md-icon-svg .md-info-line { animation: md-draw 0.35s 1.15s ease-out forwards; }

/* ── help-circle (question): circle + ? curve + dot ── */
.md-icon-svg .md-q-curve {
  stroke-dasharray: 12;
  stroke-dashoffset: 12;
}
.md-icon-svg .md-q-dot {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}
.md--visible .md-icon-svg .md-q-curve { animation: md-draw 0.5s 1.0s ease-out forwards; }
.md--visible .md-icon-svg .md-q-dot   { animation: md-draw 0.2s 1.3s ease-out forwards; }

/* ── trash-2: body draws, lid draws then lifts, lines draw ── */
.md-icon-svg .md-trash-body {
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
}
.md-icon-svg .md-trash-lid {
  stroke-dasharray: 18;
  stroke-dashoffset: 18;
}
.md-icon-svg .md-trash-lid2 {
  stroke-dasharray: 18;
  stroke-dashoffset: 18;
}
.md-icon-svg .md-trash-line {
  stroke-dasharray: 6;
  stroke-dashoffset: 6;
}
.md--visible .md-icon-svg .md-trash-body { animation: md-draw 0.5s 0.5s ease-out forwards; }
.md--visible .md-icon-svg .md-trash-lid2 { animation: md-draw 0.4s 0.7s ease-out forwards; }
.md--visible .md-icon-svg .md-trash-lid  { animation: md-trash-lid-anim 0.6s 0.9s ease-out forwards; }
.md--visible .md-icon-svg .md-trash-line { animation: md-draw 0.25s 1.2s ease-out forwards; }

@keyframes md-trash-lid-anim {
  0%   { stroke-dashoffset: 18; transform: translateY(0); }
  50%  { stroke-dashoffset: 0;  transform: translateY(-1.5px); }
  100% { stroke-dashoffset: 0;  transform: translateY(0); }
}

/* ── circle-off (stop): two arcs + diagonal slash ── */
.md-icon-svg .md-stop-arc1 {
  stroke-dasharray: 30;
  stroke-dashoffset: 30;
}
.md-icon-svg .md-stop-arc2 {
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
}
.md-icon-svg .md-stop-slash {
  stroke-dasharray: 29;
  stroke-dashoffset: 29;
}
.md--visible .md-icon-svg .md-stop-arc1  { animation: md-draw 0.5s 0.4s ease-out forwards; }
.md--visible .md-icon-svg .md-stop-arc2  { animation: md-draw 0.6s 0.5s ease-out forwards; }
.md--visible .md-icon-svg .md-stop-slash { animation: md-draw 0.4s 1.0s ease-out forwards; }

/* ── unlink (link-break): two link halves draw, then separate ── */
.md-icon-svg .md-link-l,
.md-icon-svg .md-link-r {
  stroke-dasharray: 32;
  stroke-dashoffset: 32;
}
.md-icon-svg .md-link-tick {
  stroke-dasharray: 3;
  stroke-dashoffset: 3;
}
.md--visible .md-icon-svg .md-link-r { animation: md-link-r-anim 0.6s 0.5s ease-out forwards; }
.md--visible .md-icon-svg .md-link-l { animation: md-link-l-anim 0.6s 0.5s ease-out forwards; }
.md--visible .md-icon-svg .md-link-tick { animation: md-draw 0.25s 1.0s ease-out forwards; }

@keyframes md-link-l-anim {
  0%   { stroke-dashoffset: 32; transform: translateX(0); }
  60%  { stroke-dashoffset: 0;  transform: translateX(0); }
  100% { stroke-dashoffset: 0;  transform: translate(-1px, 1px); }
}

@keyframes md-link-r-anim {
  0%   { stroke-dashoffset: 32; transform: translateX(0); }
  60%  { stroke-dashoffset: 0;  transform: translateX(0); }
  100% { stroke-dashoffset: 0;  transform: translate(1px, -1px); }
}

/* ── user-minus: head circle + body arc + minus line ── */
.md-icon-svg .md-user-head {
  stroke-dasharray: 26;
  stroke-dashoffset: 26;
}
.md-icon-svg .md-user-body {
  stroke-dasharray: 32;
  stroke-dashoffset: 32;
}
.md-icon-svg .md-user-minus {
  stroke-dasharray: 6;
  stroke-dashoffset: 6;
}
.md--visible .md-icon-svg .md-user-head  { animation: md-draw 0.5s 0.5s ease-out forwards; }
.md--visible .md-icon-svg .md-user-body  { animation: md-draw 0.5s 0.8s ease-out forwards; }
.md--visible .md-icon-svg .md-user-minus { animation: md-draw 0.3s 1.2s ease-out forwards; }

/* ── Shared keyframe ── */
@keyframes md-draw {
  to { stroke-dashoffset: 0; }
}

/* ── Text ── */
.md-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--md-text-primary);
  letter-spacing: -0.02em;
  margin: 0 0 8px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .4s .25s cubic-bezier(0.16, 1, 0.3, 1),
              transform .4s .25s cubic-bezier(0.16, 1, 0.3, 1);
}

.md--visible .md-title {
  opacity: 1;
  transform: translateY(0);
}

.md-message {
  font-size: 14.5px;
  font-weight: 400;
  color: var(--md-text-secondary);
  line-height: 1.6;
  margin: 0 0 24px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .4s .35s cubic-bezier(0.16, 1, 0.3, 1),
              transform .4s .35s cubic-bezier(0.16, 1, 0.3, 1);
}

.md--visible .md-message {
  opacity: 1;
  transform: translateY(0);
}

/* HTML content container */
.md-html-content {
  font-size: 14px;
  color: var(--md-text-secondary);
  line-height: 1.6;
  margin: 0 0 24px;
  text-align: left;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .4s .35s cubic-bezier(0.16, 1, 0.3, 1),
              transform .4s .35s cubic-bezier(0.16, 1, 0.3, 1);
}

[dir="rtl"] .md-html-content {
  text-align: right;
}

.md--visible .md-html-content {
  opacity: 1;
  transform: translateY(0);
}

.md-html-content strong {
  color: var(--md-text-primary);
  font-weight: 600;
}

/* ── Warning callout pill ── */
.md-warning-callout {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  margin: 0 0 20px;
  border-radius: 10px;
  border: 1px solid rgba(245, 158, 11, 0.25);
  background: rgba(245, 158, 11, 0.08);
  font-size: 13px;
  font-weight: 500;
  color: #FBBF24;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .4s .4s cubic-bezier(0.16, 1, 0.3, 1),
              transform .4s .4s cubic-bezier(0.16, 1, 0.3, 1);
}

.md-warning-callout.md--active {
  display: flex;
}

.md--visible .md-warning-callout {
  opacity: 1;
  transform: translateY(0);
}

.md-warning-callout svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Buttons ── */
.md-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .4s .5s cubic-bezier(0.16, 1, 0.3, 1),
              transform .4s .5s cubic-bezier(0.16, 1, 0.3, 1);
}

.md--visible .md-actions {
  opacity: 1;
  transform: translateY(0);
}

/* Side-by-side layout for confirm types */
.md-actions.md-actions--confirm {
  flex-direction: row;
}

.md-btn {
  flex: 1;
  padding: 13px 24px;
  border-radius: 14px;
  border: none;
  font-family: 'Outfit', 'Cairo', sans-serif;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.md-btn:focus-visible {
  outline: 2px solid var(--md-accent);
  outline-offset: 2px;
}

.md-btn-primary {
  background: linear-gradient(135deg, var(--md-accent) 0%, var(--md-accent-dark) 100%);
  color: white;
  box-shadow:
    0 4px 16px var(--md-accent-shadow),
    0 1px 2px rgba(0, 0, 0, 0.2),
    0 0 0 1px rgba(255, 255, 255, 0.06) inset;
}

.md-btn-primary:hover {
  box-shadow:
    0 6px 24px var(--md-accent-shadow-hover),
    0 1px 2px rgba(0, 0, 0, 0.2),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.md-btn-primary:active {
  transform: translateY(0);
  filter: brightness(0.95);
}

.md-btn-ghost {
  background: transparent;
  color: var(--md-text-secondary);
  border: 1px solid var(--md-border);
}

.md-btn-ghost:hover {
  color: var(--md-text-primary);
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
}

/* Danger variant: filled red instead of accent for destructive confirms */
.md-overlay.md--confirm-destructive .md-btn-primary {
  --md-accent: #EF4444;
  --md-accent-dark: #DC2626;
  --md-accent-shadow: rgba(239, 68, 68, 0.3);
  --md-accent-shadow-hover: rgba(239, 68, 68, 0.45);
  background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
}

/* ── RTL ── */
[dir="rtl"] .md-modal {
  font-family: 'Cairo', 'Outfit', sans-serif;
}

[dir="rtl"] .md-btn {
  font-family: 'Cairo', 'Outfit', sans-serif;
}

/* ── Shake ── */
@keyframes md-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-6px) rotate(-1deg); }
  30% { transform: translateX(5px) rotate(1deg); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(3px); }
  75% { transform: translateX(-1px); }
}

.md-modal.md--shake {
  animation: md-shake 0.5s ease;
}
