/* Modal Component v2 — UI Comprehensive Refactor
 * Requires: tokens.css, spacing.css, typography.css
 * Keeps existing .modal / .modal-overlay / .modal-content selectors.
 * z-index: 1050 (below confirm-dialog at 10000, below toast at 9999).
 */

/* ── Backdrop trigger (JS sets display:flex via .active) ───────────────── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.70);
  z-index: 1050;
  justify-content: center;
  align-items: center;
  padding: var(--space-4);
}

.modal.active {
  display: flex;
}

/* ── Overlay variant (used by dynamic modals) ──────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.70);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1050;
  padding: var(--space-4);
}

/* ── Dialog box ────────────────────────────────────────────────────────── */
.modal-content {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  animation: modal-scale-in 0.2s ease-out forwards;
  display: flex;
  flex-direction: column;
}

/* ── Header ────────────────────────────────────────────────────────────── */
.modal-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-shrink: 0;
}

.modal-title {
  font-size: var(--font-md);     /* .card-title */
  font-weight: var(--weight-semi, 600);
  color: var(--text-primary);
  margin: 0;
  line-height: var(--line-snug);
}

/* ── Close button ──────────────────────────────────────────────────────── */
.modal-close {
  background: none;
  border: none;
  padding: var(--space-1);
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-base);
  transition: background 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}

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

.modal-close svg { width: 16px; height: 16px; }

/* ── Body ──────────────────────────────────────────────────────────────── */
.modal-body {
  padding: var(--space-5) var(--space-6);
  flex: 1;
  overflow-y: auto;
}

/* ── Footer ────────────────────────────────────────────────────────────── */
.modal-footer {
  padding: var(--space-5) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  flex-shrink: 0;
}

/* ── Animation ─────────────────────────────────────────────────────────── */
@keyframes modal-scale-in {
  from { opacity: 0; transform: scale(0.94); }
  to   { opacity: 1; transform: scale(1);    }
}

@media (prefers-reduced-motion: reduce) {
  .modal-content { animation: none; }
}

/* ── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .modal-content {
    max-width: none;
    width: calc(100% - var(--space-4));
    max-height: 90vh;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: var(--space-4) var(--space-4);
  }
}
