/**
 * Mobile-First Modal Base Styles
 * Provides consistent modal behavior across all screen sizes
 */

/* Modal Overlay - Mobile First */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150000;
  padding: var(--modal-padding);
  /* Mobile: Full screen with minimal padding */
  padding: 0;
}

/* Tablet and up: Add padding around modal */
@media (min-width: 768px) {
  .modal-overlay {
    padding: var(--modal-padding);
  }
}

/* Modal Content - Mobile First */
.modal-content {
  background: white;
  border-radius: var(--modal-border-radius);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  height: 80vh;
  max-height: 80vh;
  position: relative;
}

/* Tablet and up: Constrain size */
@media (min-width: 768px) {
  .modal-content {
    width: 90vw;
    max-width: 800px;
    height: 90vh;
    max-height: 90vh;
    border-radius: var(--modal-border-radius);
  }
}

/* Desktop and up: Larger modal */
@media (min-width: 1024px) {
  .modal-content {
    width: 80vw;
    max-width: 1200px;
  }
}

/* Large desktop: Maximum size */
@media (min-width: 1440px) {
  .modal-content {
    max-width: 1400px;
  }
}

/* Modal Header - Mobile First */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--modal-header-padding);
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: #111827;
  margin: 0;
  flex: 1;
}

/* Tablet and up: Larger title */
@media (min-width: 768px) {
  .modal-title {
    font-size: 20px;
  }
}

/* Desktop and up: Even larger */
@media (min-width: 1024px) {
  .modal-title {
    font-size: 24px;
  }
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 24px;
  color: #6b7280;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  min-width: 44px;
  min-height: 44px; /* Touch-friendly */
}

.modal-close:hover {
  background-color: #f3f4f6;
  color: #374151;
}

.modal-close:active {
  background-color: #e5e7eb;
}

/* Modal Body - Mobile First */
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--modal-body-padding);
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  overscroll-behavior: contain; /* Prevent scroll chaining */
}

/* Modal Footer - Mobile First */
.modal-footer {
  display: flex;
  flex-direction: column;
  gap: var(--button-gap);
  padding: var(--modal-footer-padding);
  border-top: 1px solid #e5e7eb;
  background: white;
  position: sticky;
  bottom: 0;
  z-index: 10;
  flex-shrink: 0;
}

/* Tablet and up: Side by side buttons */
@media (min-width: 768px) {
  .modal-footer {
    flex-direction: row;
    justify-content: flex-end;
  }
}

/* Footer Button Styles */
.footer-button {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 500;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px; /* Touch-friendly */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Tablet and up: Auto width for buttons */
@media (min-width: 768px) {
  .footer-button {
    width: auto;
    min-width: 120px;
  }
}

.footer-button-primary {
  background: linear-gradient(90deg, #10b981, #22c55e);
  color: white;
  border: 1px solid #16a34a;
}

.footer-button-primary:hover {
  background: linear-gradient(90deg, #059669, #16a34a);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.footer-button-secondary {
  background: white;
  color: #374151;
  border: 1px solid #d1d5db;
}

.footer-button-secondary:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}

.footer-button-danger {
  background: linear-gradient(90deg, #dc2626, #ef4444);
  color: white;
  border: 1px solid #b91c1c;
}

.footer-button-danger:hover {
  background: linear-gradient(90deg, #b91c1c, #dc2626);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

/* Card Styles - Mobile First */
.modal-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  margin-bottom: var(--card-gap);
  overflow: hidden;
}

.card-header {
  padding: 14px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #f8fafc;
  font-size: 14px;
  font-weight: 600;
  color: #0f172a;
  margin: 0;
}

.card-body {
  padding: 12px 16px;
}

/* Tablet and up: Larger card padding */
@media (min-width: 768px) {
  .card-header {
    padding: 16px 20px;
    font-size: 16px;
  }
  
  .card-body {
    padding: 16px 20px;
  }
}

/* Form Styles - Mobile First */
.modal-form {
  display: flex;
  flex-direction: column;
  gap: var(--form-gap);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-label {
  font-size: 14px;
  font-weight: 500;
  color: #374151;
  margin: 0;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px; /* Prevents zoom on iOS */
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: white;
  transition: all 0.2s ease;
  min-height: 44px; /* Touch-friendly */
}

.form-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-input::placeholder {
  color: #9ca3af;
}

/* Tablet and up: Larger form inputs */
@media (min-width: 768px) {
  .form-input {
    padding: 16px 20px;
    font-size: 16px;
  }
}

/* Grid Layout - Mobile First */
.modal-grid {
  display: flex;
  flex-direction: column;
  gap: var(--card-gap);
}

/* Tablet and up: Two columns */
@media (min-width: 768px) {
  .modal-grid {
    display: grid;
    grid-template-columns: repeat(var(--grid-columns), 1fr);
  }
}

/* Responsive Table - Mobile First */
.responsive-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.responsive-table th,
.responsive-table td {
  padding: 8px 4px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: middle;
}

.responsive-table th {
  background: #f8fafc;
  font-weight: 600;
  color: #0f172a;
  position: sticky;
  top: 0;
  z-index: 1;
}

/* Hide less important columns on mobile */
.table-cell-mobile-hidden {
  display: none;
}

/* Tablet and up: Show more columns */
@media (min-width: 768px) {
  .table-cell-mobile-hidden {
    display: table-cell;
  }
}

/* Loading and Error States */
.loading-banner {
  padding: 10px 12px;
  border: 1px solid #dbeafe;
  background: #eff6ff;
  color: #1e40af;
  border-radius: 10px;
  margin-bottom: 12px;
  display: block;
  font-size: 14px;
}

.error-banner {
  padding: 10px 12px;
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #991b1b;
  border-radius: 10px;
  margin-bottom: 12px;
  display: none;
  font-size: 14px;
}

/* Progress Bar */
.progress-bar-container {
  width: 100%;
  height: 10px;
  background: #f1f5f9;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #22c55e);
  width: 0%;
  transition: width 0.3s ease;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  .modal-close,
  .footer-button,
  .form-input,
  .progress-bar {
    transition: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .modal-content {
    border: 2px solid #000;
  }
  
  .modal-header {
    border-bottom: 2px solid #000;
  }
  
  .modal-footer {
    border-top: 2px solid #000;
  }
}
