/* =========================
   Modal.css
   Centralized modal system
========================= */

/* ---------- Overlay ---------- */
#modals-root,
.modal,
.column-selector-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  padding: 20px;
  backdrop-filter: blur(2px);
  animation: modalFadeIn 0.2s ease-out;
}

/* JS toggles */
.modal.is-open,
#modals-root.is-open,
.column-selector-modal.is-open {
  display: flex;
}

/* Fade out animation */
.modal.is-closing,
#modals-root.is-closing,
.column-selector-modal.is-closing {
  animation: modalFadeOut 0.2s ease-out;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modalFadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ---------- App wrapper scale fix ---------- */
#modals-root,
#modals-root .modal,
#app-wrapper #modals-root {
  transform: none !important;
  transform-origin: center center !important;
}

/* ---------- Modal container ---------- */
.modal-content,
.csm-dialog {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 6px 25px rgba(0,0,0,0.25);
  width: 90%;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  position: relative;
  margin: auto;
  animation: modalSlideIn 0.25s ease-out;
}

/* Smooth scrolling */
.modal-body,
.csm-list {
  scroll-behavior: smooth;
}

/* Custom scrollbar for modal body */
.modal-body::-webkit-scrollbar,
.csm-list::-webkit-scrollbar {
  width: 8px;
}

.modal-body::-webkit-scrollbar-track,
.csm-list::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb,
.csm-list::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover,
.csm-list::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* ---------- Base width ---------- */
.modal-content {
  max-width: 600px;
}

/* ---------- Width variants ---------- */
.modal-content.modal-wide {
  max-width: 1120px;
}

.modal-content.modal-extra-wide {
  max-width: 1500px;
}

/* ---------- Modal structure ---------- */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: 16px 18px;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}

.modal-title {
  margin: 0;
  font-size: 1.125rem;
  line-height: 1.4;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: 16px 18px;
  border-top: 1px solid #e5e7eb;
  flex-shrink: 0;
}

.modal-footer:empty {
  display: none;
}

.modal-gap {
  height: 2rem;
  border-top: 1px solid #e5e7eb;
  margin-top: 1rem;
  opacity: 0.5;
}

/* ---------- Close button ---------- */
.modal .close,
.modal-header .btn[aria-label="Close"] {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 20px;
  font-weight: 700;
  color: #555;
  cursor: pointer;
  background: transparent;
  border: none;
  border-radius: 999px;
  line-height: 1;
  z-index: 1;
  transition: all 0.2s ease;
}

.modal-header .btn[aria-label="Close"] {
  padding: 6px 10px;
}

.modal .close:hover,
.modal-header .btn[aria-label="Close"]:hover {
  color: #000;
  background: rgba(0, 0, 0, 0.05);
}

.modal .close:active,
.modal-header .btn[aria-label="Close"]:active {
  transform: scale(0.95);
}

.modal .close:focus,
.modal-header .btn[aria-label="Close"]:focus {
  outline: 2px solid #295237;
  outline-offset: 2px;
}

/* ---------- Column selector modal ---------- */
.csm-dialog {
  max-width: 300px;
  max-height: calc(100vh - 40px);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.csm-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.csm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

/* ---------- Modal tabs ---------- */
.modal-tab-panels {
  width: 100%;
}
.modal-tab-content {
  display: none;
}

.modal-tab-content.active {
  display: block;
}

/* =========================
   Modal Layout Helpers
========================= */

/* Two-column form grid inside modals */
.modal .bio-form-grid,
.modal-tab-content .bio-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px 16px;
}

/* Full-width rows */
.modal .bio-form-row.wide-row {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
}

/* Responsive collapse */
@media (max-width: 720px) {
  .modal .bio-form-grid,
  .modal-tab-content .bio-form-grid {
    grid-template-columns: 1fr;
  }
  
  #modals-root,
  .modal,
  .column-selector-modal {
    padding: 10px;
  }
  
  .modal-content,
  .csm-dialog {
    max-height: calc(100vh - 20px);
    width: 95%;
  }
}

/* ---------- Body scroll lock ---------- */
body.modal-open {
  overflow: hidden;
  height: 100vh;
  position: fixed;
  width: 100%;
}

/* =========================
   Accessibility Improvements
========================= */

/* Focus trap styling */
.modal-content:focus,
.csm-dialog:focus {
  outline: none;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .modal-content,
  .csm-dialog,
  #modals-root,
  .modal,
  .column-selector-modal,
  .modal .close,
  .modal-header .btn[aria-label="Close"] {
    animation: none !important;
    transition: none !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .modal-content,
  .csm-dialog {
    border: 2px solid #000;
  }
  
  .modal-header,
  .modal-footer {
    border-color: #000;
  }
}

/* Dark mode support (optional - can be customized) */
@media (prefers-color-scheme: dark) {
  .modal-content,
  .csm-dialog {
    background: #1f2937;
    color: #f9fafb;
  }
  
  .modal-header,
  .modal-footer {
    border-color: #374151;
  }
  
  .modal .close,
  .modal-header .btn[aria-label="Close"] {
    color: #d1d5db;
  }
  
  .modal .close:hover,
  .modal-header .btn[aria-label="Close"]:hover {
    color: #f9fafb;
    background: rgba(255, 255, 255, 0.1);
  }
  
  .modal-body::-webkit-scrollbar-track,
  .csm-list::-webkit-scrollbar-track {
    background: #374151;
  }
  
  .modal-body::-webkit-scrollbar-thumb,
  .csm-list::-webkit-scrollbar-thumb {
    background: #6b7280;
  }
  
  .modal-body::-webkit-scrollbar-thumb:hover,
  .csm-list::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
  }
}

/* Print styles */
@media print {
  #modals-root,
  .modal,
  .column-selector-modal {
    display: none !important;
  }
}

.input-with-suffix {
  display: flex;
  align-items: center;
  gap: 6px;
}

.input-suffix {
  opacity: 0.7;
  font-size: 0.9em;
}

/* =========================
   Modal Tabs (Generic + Specific)
========================= */

.modal-tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid #ddd;
  margin-bottom: 1rem;
}

.modal-tab {
  background: none;
  border: none;
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: #444;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color .2s ease, border-color .2s ease;
}

.modal-tab:hover {
  color: #295237;
}
  
.modal-tab.active {
  color: #295237;
  border-color: #295237;
}

.modal-tab-content {
  display: none;
}

.modal-tab-content.active {
  display: block;
  animation: fadeIn .25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

input[readonly] {
  background: #f3f3f3;
  color: #555;
  cursor: not-allowed;
}