/* Modal Component System */

/* ========== Modal Backdrop ========== */
.modal-backdrop,
.overlay,
.selection-overlay {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease-out, visibility 0.3s;
}

.compare-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  align-items: center;
  justify-content: center;
}

/* Active state - shows modal with animation */
.modal-backdrop.active,
.overlay.active,
.selection-overlay.active {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

/* Backdrop overlay */
.modal-backdrop::before,
.overlay::before,
.selection-overlay::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--backdrop-color);
  backdrop-filter: blur(2px);
  z-index: -1;
}

/* Compare modal specific backdrop (separate element) */
.compare-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--backdrop-color);
  backdrop-filter: blur(2px);
}

/* Compare modal with animation */
.compare-modal {
  opacity: 0;
  transition: opacity var(--transition-medium);
}

.compare-modal.active {
  display: flex;
  opacity: 1;
}

.compare-modal.exiting {
  opacity: 0;
  transition: opacity 0.15s var(--ease-exit);
}

.compare-modal.exiting .compare-modal-content {
  transform: scale(0.97);
  transition: transform 0.15s var(--ease-exit);
}

/* ========== Modal Content Container ========== */
.modal-content,
.overlay-content,
.selection-content {
  position: relative;
  background: white;
  border-radius: var(--radius-md);
  border-top: 3px solid var(--topic-accent, var(--gray-200));
  padding: 2rem;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-2);
  transform: scale(0.95) translateY(12px);
  opacity: 0;
  transition: transform 0.35s var(--ease-entrance), opacity 0.25s ease-out;
}

/* Animate content in when modal is active */
.modal-backdrop.active .modal-content,
.overlay.active .overlay-content,
.selection-overlay.active .selection-content {
  transform: scale(1) translateY(0);
  opacity: 1;
}

/* Exit animation — applied by JS before removing .active */
.modal-backdrop.exiting,
.overlay.exiting,
.selection-overlay.exiting {
  opacity: 0;
  transition: opacity 0.15s var(--ease-exit), visibility 0.15s;
}

.modal-backdrop.exiting .modal-content,
.overlay.exiting .overlay-content,
.selection-overlay.exiting .selection-content {
  transform: scale(0.97) translateY(6px);
  opacity: 0;
  transition: transform 0.15s var(--ease-exit), opacity 0.15s var(--ease-exit);
}

/* Selection modal - wider */
.selection-content {
  max-width: 600px;
  max-height: 80vh;
}

/* Compare modal - large, full featured */
.compare-modal-content {
  position: relative;
  background: color-mix(in srgb, var(--modal-accent, transparent) 8%, white);
  border-radius: var(--radius-lg);
  border-top: 4px solid var(--modal-accent, var(--gray-300));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 95%;
  max-width: 1200px;
  height: min(90vh, 800px);
  display: flex;
  flex-direction: column;
  transform: scale(0.93) translateY(10px);
  transition: transform 0.35s var(--ease-entrance);
  overflow: hidden;
}

.compare-modal.active .compare-modal-content {
  transform: scale(1) translateY(0);
}

/* ========== Modal Header ========== */
.modal-header,
.overlay-header,
.compare-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.compare-modal-header {
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid color-mix(in srgb, var(--modal-accent, var(--gray-300)) 20%, var(--gray-200));
  margin-bottom: 0;
}

/* Modal title */
.modal-title,
.overlay-title {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-text);
}

.compare-modal-header h2 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-text);
}

/* Modal subtitle / description text */
.modal-subtitle {
  color: var(--color-text-secondary, #6b7280);
  margin-bottom: 1.5rem;
  text-align: center;
  font-size: 0.95rem;
  line-height: 1.6;
}

/* ========== Modal Body ========== */
.modal-body {
  flex: 1;
  overflow-y: auto;
}

/* ========== Close Button ========== */
.modal-close,
.close-button {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-500);
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-short);
}

.modal-close:hover,
.close-button:hover {
  color: var(--color-text);
}

/* Compare modal close button - special white circular style */
.compare-modal-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 2rem;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-short);
  line-height: 1;
  padding: 0;
}

.compare-modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(90deg);
}

/* ========== Modal Footer / Actions ========== */
.modal-footer,
.form-actions {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--gray-200);
}

/* ========== Modal Off-Path Help Banner ========== */
.modal-offpath-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
  color: white;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-offpath-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 1.25rem;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
}

.modal-offpath-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ========== Off-Path Floating Popup (like SoftGuardrails) ========== */
.modal-offpath-popup {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  animation: modalOffpathFadeIn 0.3s ease;
}

@keyframes modalOffpathFadeIn {
  from { opacity: 0; transform: translateX(-50%) scale(0.95); }
  to { opacity: 1; transform: translateX(-50%) scale(1); }
}

.modal-offpath-popup-content {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: linear-gradient(to bottom, #f59e0b, #d97706);
  color: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25), 0 2px 8px rgba(0, 0, 0, 0.15);
  font-size: 1rem;
  font-weight: 500;
}

.modal-offpath-popup .modal-offpath-message {
  white-space: nowrap;
}

.modal-offpath-popup-btn {
  padding: 0.5rem 1rem;
  background: white;
  color: #d97706;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.modal-offpath-popup-btn:hover {
  background: #fef3c7;
  transform: translateY(-1px);
}

.modal-offpath-popup-close {
  background: transparent;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 0.25rem;
  opacity: 0.8;
  transition: opacity 0.15s;
}

.modal-offpath-popup-close:hover {
  opacity: 1;
}

/* Legacy banner styles (kept for backwards compatibility) */
.modal-offpath-reset {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: white;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.modal-offpath-reset:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ========== Help Toggle Button ========== */
/* Higher specificity to override .btn-help from buttons.css */

/* Active state - amber styling like .sidebar-card.graph-transform-active */
.btn.btn-help.btn-help-on {
  background: #fffbeb;
  border-color: #f59e0b;
  color: #b45309;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3);
}

.btn.btn-help.btn-help-on:hover {
  background: #fef3c7;
  border-color: #d97706;
}

/* Inactive state - neutral gray */
.btn.btn-help.btn-help-off {
  background: white;
  border-color: var(--gray-300);
  color: var(--gray-500);
}

.btn.btn-help.btn-help-off:hover {
  background: var(--gray-50);
  border-color: var(--gray-400);
}

/* ========== Balance Modal: Algebraic Entry ========== */

.balance-algebraic-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 8px;
}

.balance-algebraic-entry label {
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-700);
  white-space: nowrap;
}

.balance-source-input {
  width: 130px;
  padding: 6px 10px;
  font-size: 16px;
  font-family: 'MJXTEX', 'KaTeX_Main', serif;
  border: 2px solid var(--gray-300);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s;
}

.balance-source-input:focus {
  border-color: #3b82f6;
}

.balance-source-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.balance-source-create-btn {
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background: #3b82f6;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.balance-source-create-btn:hover {
  background: #2563eb;
}

.balance-source-create-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.balance-algebraic-hint {
  font-size: 13px;
  color: var(--gray-500);
  margin: 0 0 4px;
}

/* GM keyboard must render above modal overlays (z-index: 2000) */
#gm-keyboard {
  z-index: 2100 !important;
}

/* FOIL labels legend row */
.foil-labels {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1.25rem;
  padding: 0.5rem 1rem;
  background: var(--gray-50);
  border-radius: var(--radius-sm, 4px);
  margin: 0 1.5rem;
}

.foil-label {
  font-weight: var(--font-weight-semibold, 600);
  font-size: var(--text-sm, 0.875rem);
  letter-spacing: 0.02em;
}
