/* ============================================
   MODAL SYSTEM - UNIFIED & PROFESSIONAL
   Consistent styling for all modals across app
   ============================================ */

:root {
  /* Modal sizing */
  --modal-xs: 300px;
  --modal-sm: 400px;
  --modal-md: 500px;
  --modal-lg: 600px;
  --modal-xl: 700px;
  --modal-2xl: 800px;
  
  /* Modal colors - LIGHT MODE */
  --modal-bg: #ffffff;
  --modal-text: #111827;
  --modal-border: #e5e7eb;
  --modal-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --modal-overlay-bg: rgba(0, 0, 0, 0.5);
}

/* Dark mode */
[data-theme="dark"],
:root.dark {
  --modal-bg: #1e293b;
  --modal-text: #f1f5f9;
  --modal-border: #334155;
  --modal-overlay-bg: rgba(0, 0, 0, 0.7);
}

/* ============================================
   MODAL OVERLAY - BACKDROP
   ============================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: var(--modal-overlay-bg);
  z-index: 9999;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.hidden {
  display: none !important;
}

.modal-overlay.show,
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
  animation: fadeIn 0.2s ease-in;
}

.modal-overlay.closing {
  animation: fadeOut 0.2s ease-out forwards;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ============================================
   MODAL CONTAINER
   ============================================ */

.modal-content {
  background-color: var(--modal-bg);
  color: var(--modal-text);
  border-radius: 12px;
  box-shadow: var(--modal-shadow);
  max-height: 90vh;
  width: 100%;
  max-width: var(--modal-md, 500px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease-out;
  border: 1px solid var(--modal-border);
}

.modal-content.closing {
  animation: slideDown 0.2s ease-out forwards;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideDown {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(20px);
  }
}

/* Modal sizes */
.modal-xs { --modal-md: var(--modal-xs); }
.modal-sm { --modal-md: var(--modal-sm); }
.modal-md { --modal-md: 500px; }
.modal-lg { --modal-md: var(--modal-lg); }
.modal-xl { --modal-md: var(--modal-xl); }
.modal-2xl { --modal-md: var(--modal-2xl); }

/* Responsive sizing */
@media (max-width: 640px) {
  .modal-content {
    max-width: 100% !important;
    max-height: 95vh !important;
  }
}

/* ============================================
   MODAL HEADER
   ============================================ */

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem;
  border-bottom: 1px solid var(--modal-border);
  flex-shrink: 0;
  gap: 1rem;
  background-color: var(--modal-bg);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  padding: 0;
  color: inherit;
  flex: 1;
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  color: #6b7280;
  transition: all 0.15s ease;
  padding: 0;
  margin: 0;
}

.modal-close:hover {
  background: #f3f4f6;
  color: #1f2937;
}

.modal-close svg {
  width: 1.25rem;
  height: 1.25rem;
  stroke-width: 2;
}

/* Dark mode close button */
[data-theme="dark"] .modal-close {
  color: #9ca3af;
}

[data-theme="dark"] .modal-close:hover {
  background: #374151;
  color: #f3f4f6;
}

/* ============================================
   MODAL BODY
   ============================================ */

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  -webkit-overflow-scrolling: touch;
}

/* Scrollbar styling */
.modal-body::-webkit-scrollbar {
  width: 8px;
}

.modal-body::-webkit-scrollbar-track {
  background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* Dark scrollbar */
[data-theme="dark"] .modal-body::-webkit-scrollbar-thumb {
  background: #4b5563;
}

[data-theme="dark"] .modal-body::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

/* ============================================
   MODAL FOOTER
   ============================================ */

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1.5rem;
  border-top: 1px solid var(--modal-border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.modal-footer-spacer {
  margin-right: auto;
}

/* ============================================
   FORM ELEMENTS IN MODALS
   ============================================ */

.modal-body .form-group,
.modal-body .panel-form-group {
  margin-bottom: 1rem;
}

.modal-body .form-label,
.modal-body .panel-form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #374151;
}

[data-theme="dark"] .modal-body .form-label,
[data-theme="dark"] .modal-body .panel-form-label {
  color: #d1d5db;
}

.modal-body input[type="text"],
.modal-body input[type="email"],
.modal-body input[type="password"],
.modal-body input[type="number"],
.modal-body input[type="date"],
.modal-body textarea,
.modal-body select,
.modal-body .panel-form-input,
.modal-body .form-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.875rem;
  transition: all 0.15s ease;
  box-sizing: border-box;
}

.modal-body input[type="text"]:focus,
.modal-body input[type="email"]:focus,
.modal-body input[type="password"]:focus,
.modal-body input[type="number"]:focus,
.modal-body input[type="date"]:focus,
.modal-body textarea:focus,
.modal-body select:focus,
.modal-body .panel-form-input:focus,
.modal-body .form-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Dark mode form elements */
[data-theme="dark"] .modal-body input[type="text"],
[data-theme="dark"] .modal-body input[type="email"],
[data-theme="dark"] .modal-body input[type="password"],
[data-theme="dark"] .modal-body input[type="number"],
[data-theme="dark"] .modal-body input[type="date"],
[data-theme="dark"] .modal-body textarea,
[data-theme="dark"] .modal-body select,
[data-theme="dark"] .modal-body .panel-form-input,
[data-theme="dark"] .modal-body .form-input {
  background: #374151;
  border-color: #4b5563;
  color: #f3f4f6;
}

/* ============================================
   MODAL BUTTONS
   ============================================ */

.modal-btn {
  padding: 0.6rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 100px;
}

.modal-btn-primary {
  background: #2563eb;
  color: white;
  border-color: #2563eb;
}

.modal-btn-primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.modal-btn-secondary {
  background: #f3f4f6;
  color: #1f2937;
  border-color: #d1d5db;
}

.modal-btn-secondary:hover {
  background: #e5e7eb;
  border-color: #9ca3af;
}

.modal-btn-danger {
  background: #ef4444;
  color: white;
  border-color: #ef4444;
}

.modal-btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.modal-btn-success {
  background: #10b981;
  color: white;
  border-color: #10b981;
}

.modal-btn-success:hover {
  background: #059669;
  border-color: #059669;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.modal-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================
   MODAL STATES
   ============================================ */

.modal-loading {
  opacity: 0.6;
  pointer-events: none;
}

.modal-error {
  border-color: #ef4444;
}

.modal-warning {
  border-color: #f59e0b;
}

.modal-success {
  border-color: #10b981;
}

/* ============================================
   MODAL CONTENT SECTIONS
   ============================================ */

.modal-section {
  margin-bottom: 1.5rem;
}

.modal-section:last-child {
  margin-bottom: 0;
}

.modal-section-title {
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--modal-border);
}

/* ============================================
   SPECIAL MODAL LAYOUTS
   ============================================ */

/* Confirmation modal (small) */
.modal-confirm {
  --modal-md: var(--modal-sm);
}

.modal-confirm .modal-body {
  padding: 2rem 1.5rem;
  text-align: center;
}

.modal-confirm .modal-title {
  text-align: center;
}

.modal-confirm .modal-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

/* Form modal (standard) */
.modal-form {
  --modal-md: var(--modal-lg);
}

/* Full-width modal (15-column grid) */
.modal-fullwidth {
  --modal-md: 900px;
}

@media (max-width: 1024px) {
  .modal-fullwidth .modal-content {
    max-width: 95vw;
  }
}

/* ============================================
   UTILITY CLASSES FOR SPACING IN MODALS
   ============================================ */

.modal-spacer {
  height: 1rem;
}

.modal-divider {
  height: 1px;
  background: var(--modal-border);
  margin: 1rem 0;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 768px) {
  .modal-overlay {
    padding: 0.75rem;
  }

  .modal-content {
    max-width: 100% !important;
    border-radius: 12px;
  }

  .modal-header {
    padding: 1.25rem;
  }

  .modal-body {
    padding: 1.25rem;
  }

  .modal-footer {
    padding: 1.25rem;
    flex-direction: column;
  }

  .modal-footer-spacer {
    margin-right: 0;
    margin-bottom: 0.75rem;
    width: 100%;
  }

  .modal-footer > .modal-btn {
    width: 100%;
  }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

.modal-overlay:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.modal-close:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.modal-btn:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .modal-overlay,
  .modal-content,
  .modal-close,
  .modal-btn {
    animation: none !important;
    transition: none !important;
  }
}
