/* ==========================================
   CUSTOM MODAL SYSTEM
   Modern, accessible modals and toasts
   ========================================== */

/*
  Variable aliases to match the global design system.
  This maps old modal-specific tokens to the unified design system variables
  so styles remain consistent regardless of auth state or page context.
*/
:root {
  --surface-primary: var(--surface);
  --surface-secondary: var(--surface-hover);
  --surface-tertiary: var(--bg-tertiary);
  --border-color: var(--border-light);
  --gradient-primary: linear-gradient(135deg, var(--accent-primary), var(--accent-hover));
  --status-success: var(--success);
  --status-error: var(--error);
  --status-warning: var(--warning);
}

/* Modal Root Container */
#modal-root {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
  pointer-events: none;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  /* Softer, clearer overlay */
  background: rgba(15, 23, 42, 0.45); /* slate-900 @45% */
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: auto;
  transition: opacity 0.3s ease;
  z-index: 10000;
}

.modal-overlay.modal-show {
  opacity: 1;
}

/* Modal Dialog */
.modal-dialog {
  position: relative;
  background: var(--surface-primary);
  border-radius: 24px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95) translateY(20px);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-show .modal-dialog {
  transform: scale(1) translateY(0);
}

.modal-dialog.modal-small {
  max-width: 400px;
}

.modal-dialog.modal-medium {
  max-width: 600px;
}

.modal-dialog.modal-large {
  max-width: 800px;
}

/* Modal Close Button */
.modal-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-secondary);
  border: none;
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 1;
}

.modal-close:hover {
  background: var(--surface-tertiary);
  color: var(--text-primary);
  transform: rotate(90deg);
}

/* Confirm/Alert Modal Styles */
.modal-confirm,
.modal-alert {
  padding: 40px;
  text-align: center;
}

.modal-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
  color: white;
}

.modal-icon svg {
  width: 32px;
  height: 32px;
  stroke-width: 2.5;
}

.modal-icon-info {
  background: var(--gradient-primary);
}

.modal-icon-success {
  background: linear-gradient(135deg, var(--status-success), #059669);
}

.modal-icon-error {
  background: linear-gradient(135deg, var(--status-error), #dc2626);
}

.modal-icon-warning {
  background: linear-gradient(135deg, var(--status-warning), #d97706);
}

.modal-icon-question {
  background: var(--gradient-primary);
}

/* Limit spacing to confirm/alert content only to avoid affecting other modals that reuse .modal-content */
.modal-confirm .modal-content,
.modal-alert .modal-content {
  margin-bottom: 32px;
  display: inline-block;
}

.modal-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.modal-message {
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 0;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.modal-actions .btn {
  min-width: 120px;
  padding: 12px 24px;
  font-weight: 600;
}

/* Custom Modal Styles */
.modal-header {
  padding: 32px 32px 24px;
  border-bottom: 2px solid var(--border-color);
}

.modal-header .modal-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  padding-right: 40px;
}

.modal-body {
  padding: 32px;
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.7;
}

.modal-body + .modal-actions {
  padding: 0 32px 32px;
  justify-content: flex-end;
}

/* ==========================================
   LEGACY EXAM MODAL (practiceModal)
   Center overlay and dialog alignment
   ========================================== */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  z-index: 10000;
}

.modal.hidden {
  display: none;
}

.modal .modal-content {
  position: relative;
  background: var(--surface);
  border-radius: 24px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
}

/* ==========================================
   TOAST NOTIFICATIONS
   ========================================== */

.toast-container {
  position: fixed;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
  max-width: 420px;
}

.toast-container.toast-top-right {
  top: 24px;
  right: 24px;
}

.toast-container.toast-top-left {
  top: 24px;
  left: 24px;
}

.toast-container.toast-bottom-right {
  bottom: 24px;
  right: 24px;
}

.toast-container.toast-bottom-left {
  bottom: 24px;
  left: 24px;
}

.toast-container.toast-top-center {
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
}

.toast-container.toast-bottom-center {
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--surface-primary);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  pointer-events: auto;
  opacity: 0;
  transform: translateX(100px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast-container.toast-top-left .toast,
.toast-container.toast-bottom-left .toast {
  transform: translateX(-100px);
}

.toast-container.toast-top-center .toast,
.toast-container.toast-bottom-center .toast {
  transform: translateY(-50px);
}

.toast.toast-show {
  opacity: 1;
  transform: translate(0, 0);
}

.toast-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: white;
}

.toast-icon svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.5;
}

.toast-info .toast-icon {
  background: var(--gradient-primary);
}

.toast-success .toast-icon {
  background: linear-gradient(135deg, var(--status-success), #059669);
}

.toast-error .toast-icon {
  background: linear-gradient(135deg, var(--status-error), #dc2626);
}

.toast-warning .toast-icon {
  background: linear-gradient(135deg, var(--status-warning), #d97706);
}

.toast-message {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text-primary);
}

.toast-close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-secondary);
  border: none;
  border-radius: 8px;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.toast-close:hover {
  background: var(--surface-tertiary);
  color: var(--text-primary);
}

/* Border colors for toast types */
.toast-info {
  border-color: var(--accent-primary);
}

.toast-success {
  border-color: var(--status-success);
}

.toast-error {
  border-color: var(--status-error);
}

.toast-warning {
  border-color: var(--status-warning);
}

/* ==========================================
   RESPONSIVE
   ========================================== */

@media (max-width: 768px) {
  .modal-overlay {
    padding: 16px;
  }

  .modal-dialog {
    border-radius: 20px;
  }

  .modal-confirm,
  .modal-alert {
    padding: 32px 24px;
  }

  .modal-header {
    padding: 24px 24px 20px;
  }

  .modal-body {
    padding: 24px;
  }

  .modal-body + .modal-actions {
    padding: 0 24px 24px;
  }

  .modal-icon {
    width: 56px;
    height: 56px;
  }

  .modal-icon svg {
    width: 28px;
    height: 28px;
  }

  .modal-title {
    font-size: 20px;
  }

  .modal-message {
    font-size: 15px;
  }

  .modal-actions {
    flex-direction: column;
  }

  .modal-actions .btn {
    width: 100%;
  }

  .toast-container {
    left: 16px;
    right: 16px;
    max-width: none;
  }

  .toast-container.toast-top-center,
  .toast-container.toast-bottom-center {
    transform: none;
    left: 16px;
    right: 16px;
  }

  .toast {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .modal-close {
    top: 16px;
    right: 16px;
  }
}
