/* Advanced Mix Modal - Modern Dark Theme */

.advanced-mix-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  backdrop-filter: blur(8px);
}

/* A full page opened as a modal (Import/Generate/Backup-Restore/Status)
   carries its own tables/forms sized for a full-width page, not a 700px
   dialog - wider than the default so that content isn't cramped. */
.advanced-mix-modal.page-modal {
  max-width: 90vw;
}

/* page_modal.html reuses the target page's own "content" block verbatim,
   which starts with that page's own <h1 class="page-title"> (some wrapped
   in a .page-header div, some bare - e.g. "Generate a Mix", "Status &
   Reports") - redundant once the modal chrome above already shows that
   same name as .advanced-mix-title. */
.page-modal .page-title {
  display: none;
}

.advanced-mix-modal {
  background: var(--gradient-card);
  border-radius: var(--radius-xl);
  max-width: 90vw;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
  border: 1px solid var(--border);
  overflow: hidden;
}

/* Every real modal partial wraps .advanced-mix-content/.advanced-mix-actions
   in a <form> (schedule_form.html, mix_advanced_form.html, etc.), which sits
   between them and .advanced-mix-modal in the DOM - a plain <form> has no
   display:flex of its own, so it silently broke the flex column chain
   above: .advanced-mix-content's flex:1/min-height:0 (further down) had
   nothing to size against, so it never shrank to fit and never scrolled,
   and the whole modal just grew past its own max-height instead - cut off
   at the bottom of the viewport on any form tall enough to need it (which
   is most of them, on a phone). Making the form itself part of the flex
   column restores the chain without touching a single partial. */
.advanced-mix-modal > form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.advanced-mix-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2rem 2rem 1.5rem 2rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.advanced-mix-title { 
  font-size: 1.5rem; 
  font-weight: 700; 
  color: var(--text-primary); 
  margin: 0;
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.advanced-mix-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.75rem;
  cursor: pointer;
  padding: 0;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
  transition: all 0.2s ease;
}

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

.advanced-mix-content {
  padding: 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow-y: auto;
  flex: 1;
  /* Flex items default to min-height:auto, which floors this at its own
     content height and blocks overflow-y:auto from ever kicking in - the
     modal (bounded by max-height above) would just grow past the
     viewport instead of scrolling internally, on any form long enough to
     need it (easy to hit on mobile, where the viewport is short). */
  min-height: 0;
}

.form-group { display: flex; flex-direction: column; gap: 0.5rem; }
.form-label { font-size: 0.875rem; font-weight: 500; color: var(--text-primary); }
.form-label-small { font-size: 0.8125rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 0.25rem; }

.form-hint {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  line-height: 1.4;
}

.form-input {
  width: 100%;
  padding: 0.75rem;
  background-color: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: all 0.2s ease;
}

.form-input:focus { outline: none; border-color: var(--primary-color); }
.form-input::placeholder { color: var(--text-muted); }

.form-select {
  width: 100%;
  padding: 0.75rem;
  background-color: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.form-select:focus { outline: none; border-color: var(--primary-color); }
.form-select:disabled { opacity: 0.5; cursor: not-allowed; }
.form-select option { background-color: var(--surface); color: var(--text-primary); }

/* Track Slider */
.track-slider {
  width: 100%;
  height: 6px;
  background: linear-gradient(to right, var(--primary-color) 0%, var(--primary-color) var(--value), var(--border) var(--value), var(--border) 100%);
  border-radius: 3px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.track-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  background-color: #ffffff;
  border: 2px solid var(--primary-color);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
}

.track-slider::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 4px var(--primary-glow);
}

.track-slider::-moz-range-thumb {
  width: 16px; height: 16px;
  background-color: #ffffff;
  border: 2px solid var(--primary-color);
  border-radius: 50%;
  cursor: pointer;
}

/* Search Results Dropdown */
.search-results-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 0.25rem;
  max-height: 300px;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.search-result-item {
  padding: 0.75rem;
  cursor: pointer;
  transition: background-color 0.15s;
  border-bottom: 1px solid var(--border);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background-color: var(--surface-hover);
}

.search-result-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
}

/* Selected Item Badge */
.selected-item-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background-color: rgba(47, 143, 255, 0.12);
  border: 1px solid rgba(47, 143, 255, 0.3);
  border-radius: var(--radius-sm);
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--primary-color);
}

.remove-badge-btn {
  background: none;
  border: none;
  color: var(--primary-color);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.15s;
}

.remove-badge-btn:hover {
  background-color: rgba(47, 143, 255, 0.2);
}

/* Tag Grid for Moods/Genres */
.tag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem;
  max-height: 300px;
  overflow-y: auto;
  padding: 0.5rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.tag-button {
  padding: 0.5rem 0.75rem;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.tag-button:hover {
  background-color: var(--surface-hover);
  border-color: var(--border-light);
  color: var(--text-primary);
}

.tag-button.selected,
.tag-button:has(input:checked) {
  background-color: rgba(47, 143, 255, 0.15);
  border-color: var(--primary-color);
  color: var(--primary-color);
  font-weight: 500;
}

.tag-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Year Range Inputs */
.year-range-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* Checkbox Label */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.5rem 0;
  transition: color 0.2s ease;
}

.checkbox-label:hover { color: var(--text-primary); }
.checkbox-label input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary-color); }

/* Actions */
.advanced-mix-actions {
  display: flex;
  gap: 0.75rem;
  padding: 1.5rem 2rem 2rem 2rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.2);
}

.btn-generate {
  flex: 1;
  padding: 1rem 1.5rem;
  background: transparent;
  color: var(--accent-cyan);
  border: 1px solid var(--accent-cyan);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-generate:hover:not(:disabled) {
  background: rgba(0, 229, 255, 0.12);
  box-shadow: 0 0 14px rgba(0, 229, 255, 0.4);
}

.btn-generate:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-schedule {
  padding: 1rem 1.5rem;
  background: var(--primary-color);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 12px rgba(255, 107, 107, 0.3);
  white-space: nowrap;
}

.btn-schedule:hover:not(:disabled) {
  box-shadow: 0 4px 20px rgba(255, 107, 107, 0.5);
  transform: translateY(-1px);
}

.btn-schedule:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-cancel {
  padding: 1rem 1.5rem;
  background-color: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-cancel:hover:not(:disabled) {
  background-color: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
  transform: translateY(-1px);
}

.btn-cancel:disabled { opacity: 0.5; cursor: not-allowed; }

/* Scrollbar */
.advanced-mix-content::-webkit-scrollbar { width: 6px; }
.advanced-mix-content::-webkit-scrollbar-track { background: transparent; }
.advanced-mix-content::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
.advanced-mix-content::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.tag-grid::-webkit-scrollbar { width: 6px; }
.tag-grid::-webkit-scrollbar-track { background: transparent; }
.tag-grid::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
.tag-grid::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

@media (max-width: 768px) {
  .advanced-mix-modal { max-width: 100%; max-height: 100vh; border-radius: 0; }
  .advanced-mix-header, .advanced-mix-content, .advanced-mix-actions { padding: 1rem; }
  .year-range-inputs { grid-template-columns: 1fr; }
  .tag-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .advanced-mix-actions { flex-direction: column; gap: 0.75rem; }
  .btn-generate, .btn-schedule, .btn-cancel { width: 100%; }
  /* 32px is under the ~44px touch-target guideline (Apple HIG/Material) -
     fine with a mouse cursor, easy to mis-tap on a phone. */
  .advanced-mix-close { width: 44px; height: 44px; font-size: 2rem; }
}
