/* Header & Controls - Clean modern design for Outliers and Channels */

/* ==========================================================================
   SHARED HEADER STYLES (Outliers & Channels)
   ========================================================================== */

#outliers-view .content-header,
#channels-view .content-header,
#favorites-view .content-header {
  padding: var(--space-4) 0 var(--space-4);
  margin-bottom: var(--space-4);
  padding-top: 0;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
}

.header-text h2 {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
  margin: 0 0 var(--space-2) 0;
  letter-spacing: -0.02em;
}

.header-subtitle {
  font-size: var(--font-size-base);
  color: var(--color-text-secondary);
  margin: 0;
  font-weight: var(--font-weight-normal);
}

.last-outlier-refresh {
  display: none;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  margin-right: var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--color-text-tertiary);
  font-weight: var(--font-weight-normal);
}

.last-outlier-refresh i {
  font-size: var(--font-size-xs);
  opacity: 0.7;
}

.header-actions {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}

/* Channel count badge in header */
.channels-header-count {
  display: flex;
  align-items: center;
  margin-left: auto;
  margin-right: var(--space-3);
}

.channel-count-badge {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface-elevated);
  border: var(--border-width-thin) solid var(--color-border-medium);
  border-radius: var(--border-radius-base);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  box-shadow: var(--shadow-xs);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.channel-count-badge .count-number {
  position: relative;
  display: inline-block;
  color: var(--color-text-primary);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  min-width: 1.2em;
  text-align: center;
  transition: color 0.2s ease;
}

.channel-count-badge .count-separator {
  color: var(--color-text-tertiary);
  font-weight: var(--font-weight-normal);
}

.channel-count-badge .count-limit {
  color: var(--color-text-secondary);
  font-size: var(--font-size-base);
}

/* Visual feedback when approaching limit (80-99%) - Disabled */
/* .channel-count-badge.near-limit {
  background: var(--color-surface-elevated);
  border-color: var(--color-border-medium)
} */

/* .channel-count-badge.near-limit .count-number {
  color: var(--color-text-primary);
} */

/* Visual feedback when at limit (100%) */
.channel-count-badge.at-limit {
  /*background: var(--color-primary-50);*/
  border-color: var(--color-primary-200);
  animation: pulse-gentle 3.5s ease-in-out;
}

.channel-count-badge.at-limit .count-number {
  color: var(--color-primary-700);
}

@keyframes pulse-gentle {
  0%, 100% {
    box-shadow: var(--shadow-xs);
  }
  50% {
    box-shadow: 0 0 0 4px var(--color-primary-100);
  }
}

/* Animation for number increment */
@keyframes slide-up-fade-in {
  0% {
    transform: translateY(100%);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slide-up-fade-out {
  0% {
    transform: translateY(0);
    opacity: 1;
  }
  100% {
    transform: translateY(-100%);
    opacity: 0;
  }
}

/* Animation for number decrement */
@keyframes slide-down-fade-in {
  0% {
    transform: translateY(-100%);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slide-down-fade-out {
  0% {
    transform: translateY(0);
    opacity: 1;
  }
  100% {
    transform: translateY(100%);
    opacity: 0;
  }
}

/* Scale animation for the badge on change */
@keyframes badge-pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

/* Applied when count increases */
.channel-count-badge.count-increasing {
  animation: badge-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.channel-count-badge.count-increasing .count-number {
  animation: slide-up-fade-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Applied when count decreases */
.channel-count-badge.count-decreasing {
  animation: badge-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.channel-count-badge.count-decreasing .count-number {
  animation: slide-down-fade-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Header Buttons */
.sensitivity-btn,
.refresh-btn,
.update-channels-btn,
.add-channel-btn,
.ai-search-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  border: none;
  border-radius: var(--border-radius-base);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
}

.sensitivity-btn,
.ai-search-btn {
  background: var(--color-gray-button);
  color: var(--color-text-inverse);
}

.sensitivity-btn:hover,
.ai-search-btn:hover {
  background: var(--color-gray-900);
  transform: translateY(-1px);
  box-shadow: var(--shadow-base);
}

/* Dark mode: Add subtle purple tint for better visibility */
:root[data-theme="dark"] .sensitivity-btn,
:root[data-theme="dark"] .ai-search-btn {
  background: linear-gradient(135deg, #2d1b4e 0%, #1f1437 100%);
  border: 1px solid rgba(139, 92, 246, 0.2);
  color: #e9d5ff;
}

:root[data-theme="dark"] .sensitivity-btn:hover,
:root[data-theme="dark"] .ai-search-btn:hover {
  background: linear-gradient(135deg, #3d2a5f 0%, #2d1b4e 100%);
  border-color: rgba(139, 92, 246, 0.35);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.15);
}

.refresh-btn,
.add-channel-btn {
  background: var(--color-primary-700);
  color: var(--color-text-inverse);
}

.refresh-btn:hover,
.add-channel-btn:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-base);
}

.update-channels-btn {
  background: var(--color-gray-button);
  color: var(--color-text-inverse);
}

.update-channels-btn:hover {
  background: var(--color-gray-900);
  transform: translateY(-1px);
  box-shadow: var(--shadow-base);
}

.sensitivity-btn i,
.refresh-btn i,
.update-channels-btn i,
.add-channel-btn i,
.ai-search-btn i {
  font-size: var(--font-size-base);
}

/* Refresh progress */
.refresh-progress {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border-light);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  width: 520px; /* fixed width to prevent stutter from varying text lengths */
  max-width: 560px;
  min-height: 82px; /* prevent layout jump when texts change */
  margin-right: var(--space-6); /* extra breathing room to the right */
}

.refresh-progress .rp-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.refresh-progress .rp-done {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  opacity: 0;
  transform: translateY(4px) scale(0.9);
  transition: opacity 200ms ease, transform 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

.refresh-progress .rp-done .rp-check {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-success);
  position: relative;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
}

.refresh-progress .rp-done .rp-check::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 3px;
  width: 6px;
  height: 10px;
  border: solid var(--color-white);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.refresh-progress.is-complete .rp-bar {
  background: var(--color-success-light);
}
.refresh-progress.is-complete .rp-bar-fill {
  background: linear-gradient(90deg, var(--color-success), var(--color-success-dark));
}
.refresh-progress.is-complete .rp-percent {
  color: var(--color-success-dark);
}
.refresh-progress.is-complete .phase-pill {
  background: var(--color-success-light);
  color: var(--color-success-dark);
  border-color: var(--color-success);
}

.refresh-progress .rp-done.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.refresh-progress .rp-percent {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.refresh-progress .rp-bar {
  position: relative;
  width: 100%;
  height: 8px;
  background: var(--color-border-light);
  border-radius: 999px;
  overflow: hidden;
}

.refresh-progress .rp-bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(0);
  background: linear-gradient(90deg, var(--color-primary-500), var(--color-primary-300));
  /* GSAP handles animations, no CSS transition needed */
}

.refresh-progress .rp-subtext {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  min-height: 22px; /* keep row height stable during animations */
}

.refresh-progress .phase-pill {
  padding: 2px 8px;
  background: var(--color-primary-50);
  color: var(--color-primary-700);
  border: 1px solid var(--color-primary-100);
  border-radius: 999px;
  font-size: var(--font-size-xs);
}

.refresh-progress .rp-chan {
  position: relative;
  min-width: 0;
  flex: 1;
  display: flex;
  gap: var(--space-2);
  align-items: center;
  /* reserve horizontal space so varying channel name lengths don't resize the box */
  min-width: 240px;
  overflow: hidden;
}

.refresh-progress .rp-chan-text {
  display: inline-block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
}

@keyframes slideOutUp {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-6px); }
}

@keyframes slideInDown {
  0% { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}

.refresh-progress .rp-chan-text.slide-out {
  animation: slideOutUp 180ms ease forwards;
}

.refresh-progress .rp-chan-text.slide-in {
  animation: slideInDown 220ms ease forwards;
}

.refresh-progress .rp-meta {
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
  white-space: nowrap;
}

.refresh-progress .rp-dot {
  color: var(--color-text-tertiary);
}

.refresh-btn.is-disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ==========================================================================
   CONTROLS (Outliers & Channels)
   ========================================================================== */

.outliers-controls,
.channels-controls,
#favorites-view .outliers-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin: 0 0 var(--space-8);
  gap: var(--space-3);
  
}

/* Search Container - Takes majority of width */
.search-container {
  position: relative;
  flex: 1;
}

.search-container i {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-tertiary);
  font-size: var(--font-size-sm);
}

.search-input {
  width: 100%;
  padding: var(--space-3) var(--space-4) var(--space-3) var(--space-10);
  border: var(--border-width-thin) solid var(--color-border-light);
  border-radius: var(--border-radius-base);
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  background: var(--color-surface-elevated);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.search-input:focus {
  outline: none;
  border-color: var(--color-primary-300);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.search-input::placeholder {
  color: var(--color-text-tertiary);
}

/* Sort & Filter Menu - Fixed width */
.sort-menu-container,
.filter-menu-container {
  position: relative;
  flex-shrink: 0;
}

.sort-menu-btn,
.filter-menu-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-elevated);
  color: var(--color-text-primary);
  border: var(--border-width-thin) solid var(--color-border-light);
  border-radius: var(--border-radius-base);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}

/* Lucide icon sizing in sort/filter buttons */
.sort-menu-btn i[data-lucide],
.filter-menu-btn i[data-lucide] {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

.sort-menu-btn:hover,
.filter-menu-btn:hover {
  background: var(--color-gray-50);
  border-color: var(--color-border-medium);
}

/* Dark mode: Fix filter button hover */
[data-theme="dark"] .sort-menu-btn:hover,
[data-theme="dark"] .filter-menu-btn:hover {
  background: var(--color-primary-50);
  border-color: var(--color-primary-300);
  color: var(--color-primary-700);
}

.sort-menu-btn.active,
.filter-menu-btn.active {
  background: var(--color-primary-50);
  border-color: var(--color-primary-300);
  color: var(--color-primary-700);
}

.sort-menu-btn i:first-child,
.filter-menu-btn i:first-child {
  font-size: var(--font-size-sm);
}

.sort-menu-btn i:last-child,
.filter-menu-btn i:last-child {
  font-size: var(--font-size-xs);
  transition: transform 0.2s ease;
}

.sort-menu-btn.active i:last-child,
.filter-menu-btn.active i:last-child {
  transform: rotate(180deg);
}

/* Sort & Filter Dropdown */
.sort-menu-dropdown,
.filter-menu-dropdown {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  min-width: 240px;
  background: var(--color-surface-elevated);
  border: var(--border-width-thin) solid var(--color-border-light);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-4);
  display: none;
  z-index: 100;
}

.sort-menu-dropdown.open,
.filter-menu-dropdown.open {
  display: block;
}

.filter-section {
  margin-bottom: var(--space-4);
}

.filter-section:last-child {
  margin-bottom: 0;
}

.filter-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
}

.filter-section select {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: var(--border-width-thin) solid var(--color-border-light);
  border-radius: var(--border-radius-sm);
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  background: var(--color-surface-elevated);
  cursor: pointer;
  transition: border-color 0.2s ease;
}

/* Dark mode: Fix select dropdown styling */
[data-theme="dark"] .filter-section select {
  background: var(--color-gray-800);
  color: var(--color-text-primary);
  border-color: var(--color-border-light);
}

[data-theme="dark"] .filter-section select option {
  background: var(--color-gray-800);
  color: var(--color-text-primary);
}

.filter-section select:focus {
  outline: none;
  border-color: var(--color-primary-300);
}

/* Segmented Control - Modern Pill Toggle with Sliding Background */
.segmented-control {
  position: relative;
  display: inline-flex;
  background: var(--color-surface);
  border: var(--border-width-thin) solid var(--color-border-light);
  border-radius: var(--border-radius-base);
  padding: 2px;
  gap: 2px;
}

.segmented-control input[type="radio"] {
  display: none;
}

.segmented-control label {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: calc(var(--border-radius-base) - 2px);
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  user-select: none;
  white-space: nowrap;
}

.segmented-control label:hover {
  color: var(--color-text-primary);
}

.segmented-control input[type="radio"]:checked + label {
  background: var(--color-primary-700);
  color: var(--color-text-inverse);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transform: scale(1.02);
}

.segmented-control input[type="radio"]:checked + label:hover {
  color: var(--color-text-inverse);
}

/* Dark mode segmented control */
[data-theme="dark"] .segmented-control {
  background: var(--color-gray-800);
  border-color: var(--color-border-light);
}

[data-theme="dark"] .segmented-control input[type="radio"]:checked + label {
  background: var(--color-primary-600);
  color: var(--color-text-inverse);
}

[data-theme="dark"] .segmented-control input[type="radio"]:checked + label:hover {
  color: var(--color-text-inverse);
}

/* Duration Filter Styles (also used by Multiplier Range) */
.duration-filter {
  width: 100%;
}

.duration-slider-container {
  position: relative;
  height: 20px;
  margin-bottom: var(--space-3);
}

.duration-slider {
  position: absolute;
  width: 100%;
  height: 4px;
  background: transparent;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  pointer-events: none;
}

.duration-slider::-webkit-slider-track {
  width: 100%;
  height: 3px;
  background: var(--color-border-light);
  border-radius: 2px;
}

.duration-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--color-primary-700);
  border-radius: 50%;
  cursor: pointer;
  pointer-events: all;
  position: relative;
  z-index: 2;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.duration-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 0 0 4px var(--color-primary-light);
}

.duration-slider::-moz-range-track {
  width: 100%;
  height: 4px;
  background: var(--color-border-light);
  border-radius: 2px;
  border: none;
}

.duration-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--color-primary-500);
  border-radius: 50%;
  cursor: pointer;
  pointer-events: all;
  border: none;
  position: relative;
  z-index: 2;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.duration-slider::-moz-range-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 0 0 4px var(--color-primary-light);
}

.duration-slider:focus::-webkit-slider-thumb {
  outline: none;
  border-color: var(--color-primary-300);
  box-shadow: 0 0 0 3px var(--color-primary-light);
  border: none;
}

.duration-slider:focus::-moz-range-thumb {
  outline: none;
  border-color: var(--color-primary-300);
  box-shadow: 0 0 0 3px var(--color-primary-light);
  border: none;
}

#duration-max {
  z-index: 1;
}

#duration-min {
  z-index: 2;
}

#multiplier-max {
  z-index: 1;
}

#multiplier-min {
  z-index: 2;
}

.duration-values {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.duration-min-value {
  text-align: left;
}

.duration-separator {
  font-weight: var(--font-weight-normal);
  text-align: center;
  padding: 0 var(--space-2);
}

.duration-max-value {
  text-align: right;
}

.duration-slider-container .duration-range-line {
  position: absolute;
  top: 8px; /* centered over 3-4px track */
  height: 2px;
  background: var(--color-error); /* red line */
  border-radius: 2px;
  left: 0;
  right: 100%;
  pointer-events: none;
  z-index: 0;
}

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

/* Responsive breakpoint for when progress bar causes text wrapping */
@media (max-width: 1200px) {
  .header-content:has(.refresh-progress) {
    flex-direction: column;
    gap: var(--space-3);
    align-items: flex-start;
  }
  
  .header-content:has(.refresh-progress) .header-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    gap: var(--space-4);
    align-items: flex-start;
    padding: 0 var(--space-4);
  }
  .refresh-progress {
    width: 100%;
    margin-right: 0; /* remove extra margin on narrow screens */
  }
  
  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }
  
  .channels-header-count {
    margin-left: 0;
    margin-right: 0;
    order: -1; /* Move to top on mobile */
  }
  
  .channel-count-badge {
    font-size: var(--font-size-sm);
    padding: var(--space-2) var(--space-3);
  }
  
  .channel-count-badge .count-number {
    font-size: var(--font-size-base);
  }
  
  .outliers-controls,
  .channels-controls {
    flex-direction: column;
    gap: var(--space-4);
    padding: 0 var(--space-4);
  }
  
  .search-container {
    margin-right: 0;
    width: 100%;
  }
  
  .filter-menu-dropdown {
    right: auto;
    left: 0;
    width: 100%;
    min-width: auto;
  }
}

@media (max-width: 480px) {
  .header-actions {
    flex-direction: column;
    width: 100%;
  }
  
  .sensitivity-btn,
  .ai-search-btn,
  .refresh-btn {
    width: 100%;
    justify-content: center;
  }
} 

@media (max-width: 360px) {
  .refresh-progress .rp-dot,
  .refresh-progress .rp-time {
    display: none;
  }
}