/* ==========================================================================
   Base Modal System
   Reusable modal components with theme variants
   ========================================================================== */

/* ==========================================================================
   Base Modal Overlay
   ========================================================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--overlay-warm-grey-dark);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 10vh;
}

.modal-overlay.mobile-menu-modal {
  /* Override centering for drawer layout */
  justify-content: flex-start;
  align-items: stretch;
  padding-top: 0;
}

/* Hidden state handled by base.css with opacity transition */

/* ==========================================================================
   Base Modal Content Container
   ========================================================================== */

.modal-content {
  background-color: var(--parchment-light);
  border: 2px solid var(--parchment-dark);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 600px;
  box-shadow: 0 8px 32px var(--shadow-warm-grey-dark-heavy);
  overflow: hidden;
}

/* Size variants */
.modal-content--narrow {
  max-width: 500px;
}

.modal-content--wide {
  max-width: 700px;
}

/* Theme variants */
.modal-content--dark {
  /* Command palette admin theme */
  --cp-bg-dark: #2d2d2d;
  --cp-bg-base: #3a3a3a;
  --cp-bg-light: #4a4a4a;
  --cp-bg-hover: #525252;
  --cp-text-primary: #f0f0f0;
  --cp-text-secondary: #a0a0a0;
  --cp-text-muted: #707070;
  --cp-border: #555;

  background-color: var(--cp-bg-dark);
  border: 1px solid var(--cp-border);
}

.modal-content--eldritch {
  /* Questioning Cthulhu horror theme */
  background-color: var(--eldritch-deep);
  border: 2px solid var(--eldritch-glow);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.7),
              0 0 40px rgba(15, 255, 136, 0.15);
}

.modal-content--drawer {
  /* Slide-in drawer from left (mobile menu) */
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 85%;
  max-width: 320px;
  border-radius: 0;
  border-right: 2px solid var(--parchment-dark);
  border-top: none;
  border-left: none;
  border-bottom: none;
  transform: translateX(-100%);
  transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay:not(.hidden) .modal-content--drawer {
  transform: translateX(0);
}

/* ==========================================================================
   Base Modal Footer (keyboard shortcuts)
   ========================================================================== */

.modal-footer {
  display: flex;
  gap: var(--space-lg);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--parchment-100);
  border-top: 1px solid var(--parchment-400);
  font-size: 0.8rem;
  color: var(--grey-600);
}

.modal-footer--dark {
  background-color: var(--cp-bg-base);
  border-top: 1px solid var(--cp-border);
  color: var(--cp-text-secondary);
}

.modal-footer--eldritch {
  background-color: var(--eldritch-dark);
  border-top: 1px solid var(--eldritch-medium);
  color: var(--eldritch-text-dim);
}

.modal-shortcut {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.modal-shortcut kbd {
  padding: 0.15rem 0.4rem;
  font-family: inherit;
  font-size: 0.75rem;
  background-color: var(--parchment-base);
  border: 1px solid var(--parchment-dark);
  border-radius: 3px;
}

.modal-footer--dark .modal-shortcut kbd {
  background-color: var(--cp-bg-light);
  border: 1px solid var(--cp-border);
  color: var(--cp-text-primary);
}

.modal-footer--eldritch .modal-shortcut kbd {
  background-color: var(--eldritch-medium);
  border: 1px solid var(--eldritch-glow);
  color: var(--eldritch-text);
}

/* ==========================================================================
   Responsive Styles
   ========================================================================== */

@media (max-width: 768px) /* tablet */ {
  .modal-overlay {
    padding: var(--space-md);  /* Add horizontal padding */
    padding-top: 5vh;  /* Reduce top padding on mobile */
    align-items: flex-start;  /* Keep aligned to top */
  }

  .modal-content {
    max-width: 100%;  /* Full width minus padding */
  }

  /* Hide keyboard shortcut footers on mobile - not relevant for touch devices */
  .modal-footer {
    display: none;
  }
}

/* ==========================================================================
   Icon Selector Modal
   Dropdown on desktop, full-screen on mobile
   ========================================================================== */

.icon-selector-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2000;
  max-width: 600px;
  width: 90%;
}

.icon-selector-modal.hidden {
  display: none;
}

.icon-selector-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1999;
}

.icon-selector-content {
  position: relative;
  z-index: 2001;
  display: flex;
  flex-direction: column;
  max-height: 500px;
  background-color: var(--parchment-light);
  border: 2px solid var(--parchment-dark);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px var(--shadow-warm-grey-dark-heavy);
}

.icon-selector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  background-color: var(--parchment-base);
  border-bottom: 2px solid var(--parchment-dark);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.icon-selector-header h2 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--grey-900);
}

.icon-selector-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--grey-600);
  transition: color 150ms ease;
}

.icon-selector-close svg {
  width: 20px;
  height: 20px;
}

.icon-selector-close:hover {
  color: var(--grey-900);
}

.icon-selector-grid {
  overflow-y: auto;
  padding: var(--space-md);
  display: grid;
  grid-template-columns: repeat(10, 48px);
  gap: var(--space-xs);
  align-content: start;
  justify-content: center;

  /* Show ~6 rows: (48px icon + 4px gap) * 6 rows = 312px */
  max-height: 320px;
}

.icon-selector-loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--space-xl);
  color: var(--grey-600);
  font-style: italic;
}

.icon-selector-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: var(--space-xs);
  background-color: var(--parchment-base);
  border: 2px solid var(--parchment-400);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 150ms ease;
}

.icon-selector-item:hover {
  background-color: var(--parchment-100);
  border-color: var(--grey-400);
  transform: scale(1.05);
}

.icon-selector-item.selected {
  background-color: var(--primary-100);
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px var(--primary-200);
}

.icon-selector-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

/* Icon preview in form */
.icon-preview {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

/* Mobile: Full-screen modal */
@media (max-width: 768px) {
  .icon-selector-modal {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    transform: none;
    max-width: none;
    width: 100%;
    height: 100vh;
  }

  .icon-selector-overlay {
    background-color: rgba(0, 0, 0, 0.85);
  }

  .icon-selector-content {
    max-height: none;
    height: 100vh;
    border: none;
    border-radius: 0;
  }

  .icon-selector-header {
    padding: var(--space-lg) var(--space-xl);
    border-radius: 0;
  }

  .icon-selector-header h2 {
    font-size: 1.75rem;
  }

  .icon-selector-grid {
    flex: 1;
    padding: var(--space-xl);
    grid-template-columns: repeat(auto-fill, 48px);
    max-height: none;
  }

  .icon-selector-close {
    width: 40px;
    height: 40px;
  }

  .icon-selector-close svg {
    width: 24px;
    height: 24px;
  }
}
