.yt-analytics {
  padding: 1.5rem;
  max-width: 1200px;

  // Header
  &__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
  }

  &__title-section {
    h2 {
      margin: 0 0 0.25rem 0;
      font-size: 1.5rem;
      font-weight: 600;
      color: var(--theme-elevation-800);
    }

    p {
      margin: 0;
      font-size: 0.875rem;
      color: var(--theme-elevation-500);
    }
  }

  &__controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
  }

  &__channel-select,
  &__period-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--theme-elevation-250);
    border-radius: var(--style-radius-s, 4px);
    background-color: var(--theme-elevation-0);
    color: var(--theme-elevation-800);
    font-size: 0.875rem;
    cursor: pointer;
    transition: border-color 0.15s ease;

    &:hover {
      border-color: var(--theme-elevation-400);
    }

    &:focus {
      outline: none;
      border-color: var(--theme-success-500);
    }
  }

  &__refresh-btn {
    padding: 0.5rem;
    border: 1px solid var(--theme-elevation-250);
    border-radius: var(--style-radius-s, 4px);
    background-color: var(--theme-elevation-0);
    color: var(--theme-elevation-600);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;

    &:hover:not(:disabled) {
      background-color: var(--theme-elevation-100);
      border-color: var(--theme-elevation-400);
    }

    &:disabled {
      cursor: not-allowed;
      opacity: 0.5;
    }
  }

  // Tabs
  &__tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--theme-elevation-150);
    margin-bottom: 1.5rem;
  }

  &__tab {
    padding: 0.75rem 1.25rem;
    border: none;
    background: none;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--theme-elevation-500);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;

    &:hover {
      color: var(--theme-elevation-700);
    }

    &--active {
      color: var(--theme-success-500);
      border-bottom-color: var(--theme-success-500);
      font-weight: 600;
    }
  }

  // Stats Grid
  &__stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
  }

  &__stat-card {
    padding: 1.25rem;
    background-color: var(--theme-elevation-0);
    border: 1px solid var(--theme-elevation-150);
    border-radius: var(--style-radius-m, 8px);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border-left: 3px solid var(--theme-elevation-150);

    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }

    &--views {
      border-left-color: #3b82f6;
    }

    &--time {
      border-left-color: #8b5cf6;
    }

    &--ctr {
      border-left-color: #f59e0b;
    }

    &--subs {
      border-left-color: #10b981;
    }

    &--production {
      border-left-color: #6366f1;
    }

    &--warning {
      border-left-color: var(--theme-warning-500);
    }

    &--error {
      border-left-color: var(--theme-error-500);
    }

    &--success {
      border-left-color: var(--theme-success-500);
    }
  }

  &__stat-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
  }

  &__stat-icon {
    display: flex;
    color: var(--theme-elevation-500);
  }

  &__stat-label {
    font-size: 0.8125rem;
    color: var(--theme-elevation-500);
    font-weight: 500;
  }

  &__stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--theme-elevation-800);
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  // Trend
  &__trend {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 0.75rem;
    font-weight: 500;

    &--up {
      color: var(--theme-success-500);
    }

    &--down {
      color: var(--theme-error-500);
    }
  }

  // Content
  &__content {
    margin-top: 1rem;
  }

  // Section
  &__section {
    margin-bottom: 1.5rem;
    padding: 1.25rem;
    background-color: var(--theme-elevation-50);
    border: 1px solid var(--theme-elevation-150);
    border-radius: var(--style-radius-m, 8px);
  }

  &__section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 1rem 0;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--theme-elevation-700);
  }

  // Video List
  &__video-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  &__video-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background-color: var(--theme-elevation-100);
    border-radius: var(--style-radius-s, 4px);
  }

  &__video-title {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--theme-elevation-800);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  &__video-metric {
    font-size: 0.8125rem;
    color: var(--theme-elevation-600);
    min-width: 60px;
    text-align: right;
  }

  // Engagement
  &__engagement-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
  }

  &__engagement-item {
    text-align: center;
    padding: 1rem;
    background-color: var(--theme-elevation-100);
    border-radius: var(--style-radius-s, 4px);
  }

  &__engagement-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--theme-elevation-800);
  }

  &__engagement-label {
    font-size: 0.8125rem;
    color: var(--theme-elevation-500);
  }

  // Pipeline Bar
  &__pipeline-bar {
    display: flex;
    height: 40px;
    border-radius: var(--style-radius-s, 4px);
    overflow: hidden;
    margin-bottom: 1rem;
  }

  &__pipeline-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    min-width: 30px;
    transition: flex-basis 0.3s ease;
    position: relative;

    &--idea {
      background-color: var(--theme-elevation-400);
    }

    &--script {
      background-color: #6366f1;
    }

    &--review {
      background-color: #f59e0b;
    }

    &--production {
      background-color: #3b82f6;
    }

    &--editing {
      background-color: #8b5cf6;
    }

    &--ready {
      background-color: #10b981;
    }

    &--published {
      background-color: var(--theme-success-500);
    }
  }

  &__pipeline-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
    font-size: 0.75rem;
  }

  &__legend-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
  }

  &__legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
  }

  // Progress (Goals)
  &__progress-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
  }

  &__progress-label {
    width: 100px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--theme-elevation-600);
  }

  &__progress-bar {
    flex: 1;
    height: 8px;
    background-color: var(--theme-elevation-150);
    border-radius: 4px;
    overflow: hidden;
  }

  &__progress-fill {
    height: 100%;
    border-radius: 4px;
    background-color: var(--theme-success-500);
    transition: width 0.5s ease;

    &--at-risk {
      background-color: var(--theme-warning-500);
    }

    &--missed {
      background-color: var(--theme-error-500);
    }
  }

  &__progress-value {
    width: 60px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--theme-elevation-700);
    text-align: right;
  }

  // Status Badge
  &__status-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 500;

    &--on_track {
      background-color: rgba(16, 185, 129, 0.1);
      color: #10b981;
    }

    &--at_risk {
      background-color: rgba(245, 158, 11, 0.1);
      color: #f59e0b;
    }

    &--achieved {
      background-color: rgba(59, 130, 246, 0.1);
      color: #3b82f6;
    }

    &--missed {
      background-color: rgba(239, 68, 68, 0.1);
      color: #ef4444;
    }
  }

  // Community - Comments
  &__comment-item {
    padding: 0.75rem;
    background-color: var(--theme-elevation-100);
    border-radius: var(--style-radius-s, 4px);
    margin-bottom: 0.5rem;
  }

  &__comment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
  }

  &__comment-author {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--theme-elevation-800);
  }

  &__comment-meta {
    font-size: 0.75rem;
    color: var(--theme-elevation-500);
  }

  &__comment-message {
    font-size: 0.8125rem;
    color: var(--theme-elevation-600);
    line-height: 1.4;
  }

  // Community - Topics
  &__topic-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  &__topic-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.75rem;
    background-color: var(--theme-elevation-100);
    border-radius: 12px;
    font-size: 0.8125rem;
    color: var(--theme-elevation-700);
  }

  &__topic-count {
    font-weight: 600;
    color: var(--theme-elevation-500);
    font-size: 0.75rem;
  }

  // Community - Sentiment
  &__sentiment-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  &__sentiment-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  &__sentiment-label {
    width: 80px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--theme-elevation-600);
  }

  &__sentiment-bar-track {
    flex: 1;
    height: 8px;
    background-color: var(--theme-elevation-150);
    border-radius: 4px;
    overflow: hidden;
  }

  &__sentiment-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;

    &--positive {
      background-color: var(--theme-success-500);
    }

    &--neutral {
      background-color: var(--theme-elevation-400);
    }

    &--negative {
      background-color: var(--theme-error-500);
    }

    &--question {
      background-color: #3b82f6;
    }
  }

  &__sentiment-count {
    width: 40px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--theme-elevation-700);
    text-align: right;
  }

  // Pipeline - Schedule
  &__schedule-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background-color: var(--theme-elevation-100);
    border-radius: var(--style-radius-s, 4px);
    margin-bottom: 0.5rem;
  }

  &__schedule-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--theme-elevation-800);
    flex: 1;
  }

  &__schedule-date {
    font-size: 0.8125rem;
    color: var(--theme-elevation-500);
  }

  // Pipeline - Tasks
  &__task-item {
    padding: 0.75rem;
    background-color: rgba(var(--theme-error-500-rgb), 0.05);
    border: 1px solid rgba(var(--theme-error-500-rgb), 0.2);
    border-radius: var(--style-radius-s, 4px);
    margin-bottom: 0.5rem;
  }

  &__task-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
  }

  &__task-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--theme-elevation-800);
  }

  &__task-meta {
    font-size: 0.75rem;
    color: var(--theme-elevation-500);
  }

  &__task-detail {
    font-size: 0.8125rem;
    color: var(--theme-elevation-600);
  }

  // Loading State
  &__loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    color: var(--theme-elevation-500);
    gap: 1rem;

    p {
      margin: 0;
      font-size: 0.875rem;
    }
  }

  // Error State
  &__error {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background-color: rgba(var(--theme-error-500-rgb), 0.1);
    border: 1px solid rgba(var(--theme-error-500-rgb), 0.2);
    border-radius: var(--style-radius-s, 4px);
    color: var(--theme-error-500);

    p {
      margin: 0;
      font-size: 0.875rem;
    }
  }

  // Spinner
  &__spinner {
    animation: yt-analytics-spin 1s linear infinite;
  }
}

// Dark Mode
.dark .yt-analytics {
  &__stat-card {
    background-color: var(--theme-elevation-100);
    border-color: var(--theme-elevation-200);
  }

  &__section {
    background-color: var(--theme-elevation-100);
    border-color: var(--theme-elevation-200);
  }

  &__video-row,
  &__engagement-item,
  &__comment-item,
  &__schedule-item {
    background-color: var(--theme-elevation-200);
  }

  &__topic-tag {
    background-color: var(--theme-elevation-200);
  }
}

// Responsive
@media (max-width: 768px) {
  .yt-analytics {
    padding: 1rem;

    &__header {
      flex-direction: column;
    }

    &__stats-grid {
      grid-template-columns: repeat(2, 1fr);
    }

    &__tabs {
      overflow-x: auto;
    }

    &__engagement-grid {
      grid-template-columns: 1fr;
    }

    &__stat-card {
      padding: 1rem;
    }

    &__stat-value {
      font-size: 1.5rem;
    }

    &__video-row {
      flex-direction: column;
      align-items: flex-start;
      gap: 0.5rem;
    }

    &__video-metric {
      text-align: left;
    }

    &__schedule-item {
      flex-direction: column;
      align-items: flex-start;
      gap: 0.25rem;
    }
  }
}

// Keyframes
@keyframes yt-analytics-spin {
  to {
    transform: rotate(360deg);
  }
}
