.analytics-page-shell {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100%;

  .loading-container,
  .error-container {
    flex: 1;
  }
}

// Loading and error states
.loading-container,
.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 400px;
  gap: 16px;
  color: var(--text-secondary);

  .spin {
    animation: analyticsSpin 1s linear infinite;
  }

  p.loading-status {
    margin: 0;
    font-size: 14px;
    color: var(--text-primary);
  }

  .progress-bar-wrapper {
    width: 280px;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 999px;
    overflow: hidden;
    position: relative;
  }

  .progress-bar-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: var(--primary);
    transition: width 0.3s ease;
    border-radius: 999px;
  }

  .progress-percent {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
  }

  .error-actions {
    display: flex;
    align-items: center;
    gap: 8px;
  }
}

@keyframes analyticsSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

// Page scroll content
.page-scroll {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.page-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;

  h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
  }
}

// Stats overview cards
.stats-overview {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 16px;
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border-color);

  .stat-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light);
    border-radius: 10px;
    color: var(--primary);
    flex-shrink: 0;
  }

  .stat-info {
    display: flex;
    flex-direction: column;
    gap: 2px;

    .stat-value {
      font-size: 22px;
      font-weight: 700;
      color: var(--text-primary);
      letter-spacing: -0.5px;
    }

    .stat-label {
      font-size: 12px;
      color: var(--text-tertiary);
    }
  }
}

.time-range {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);

  svg {
    color: var(--text-tertiary);
    flex-shrink: 0;
  }
}

// Charts
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.chart-card {
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  padding: 20px;

  &.wide {
    grid-column: span 2;
  }

  h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 12px;
  }
}

// Rankings
.rankings-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ranking-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  transition: background 0.15s ease;

  &:hover {
    background: var(--bg-hover);
  }

  .rank {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;

    &.top {
      background: var(--primary);
      color: var(--on-primary);
    }
  }

  .contact-avatar {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    position: relative;

    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      object-fit: cover;
    }

    .avatar-placeholder {
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      background: var(--bg-tertiary);
      border-radius: 50%;
      color: var(--text-tertiary);
    }

    .medal {
      position: absolute;
      right: -4px;
      bottom: -4px;
      width: 16px;
      height: 16px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 50%;
      border: 2px solid var(--bg-primary);

      &.medal-1 {
        background: linear-gradient(135deg, #ffd700, #ffb800);
        color: #fff;
      }

      &.medal-2 {
        background: linear-gradient(135deg, #c0c0c0, #a8a8a8);
        color: #fff;
      }

      &.medal-3 {
        background: linear-gradient(135deg, #cd7f32, #b87333);
        color: #fff;
      }

      svg {
        width: 8px;
        height: 8px;
      }
    }
  }

  .contact-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;

    .contact-name {
      font-size: 14px;
      font-weight: 500;
      color: var(--text-primary);
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .contact-stats {
      font-size: 12px;
      color: var(--text-tertiary);
    }
  }

  .message-count {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    flex-shrink: 0;
  }
}

// Responsive
@media (max-width: 1200px) {
  .stats-overview {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 800px) {
  .stats-overview {
    grid-template-columns: 1fr;
  }

  .charts-grid {
    grid-template-columns: 1fr;

    .chart-card.wide {
      grid-column: span 1;
    }
  }
}

// Exclude friends modal
.exclude-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.exclude-modal {
  width: 520px;
  max-width: calc(100vw - 48px);
  background: var(--bg-secondary-solid, var(--bg-secondary));
  border-radius: 16px;
  border: 1px solid var(--border-color);
  padding: 20px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2);

  .exclude-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;

    h3 {
      margin: 0;
      font-size: 16px;
      font-weight: 600;
      color: var(--text-primary);
    }
  }

  .modal-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: all 0.15s;

    &:hover {
      background: var(--bg-hover);
      color: var(--text-primary);
    }
  }

  .exclude-modal-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    margin-bottom: 12px;
    color: var(--text-tertiary);

    input {
      flex: 1;
      border: none;
      outline: none;
      background: transparent;
      color: var(--text-primary);
      font-size: 13px;
    }

    .clear-search {
      background: none;
      border: none;
      cursor: pointer;
      color: var(--text-tertiary);
      padding: 2px;

      &:hover {
        color: var(--text-primary);
      }
    }
  }

  .exclude-modal-body {
    max-height: 380px;
    overflow: auto;
    padding-right: 4px;
  }

  .exclude-loading,
  .exclude-error,
  .exclude-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-secondary);
    padding: 24px 0;
    font-size: 13px;
  }

  .exclude-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .exclude-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;

    &:hover {
      background: var(--bg-hover);
    }

    &.active {
      border-color: rgba(16, 163, 127, 0.3);
      background: rgba(16, 163, 127, 0.06);
    }

    input {
      margin: 0;
      accent-color: var(--primary);
    }
  }

  .exclude-avatar {
    flex-shrink: 0;
  }

  .exclude-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 1px;
  }

  .exclude-name {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .exclude-username {
    font-size: 12px;
    color: var(--text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .exclude-modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 14px;
  }

  .exclude-footer-left {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .exclude-count {
    font-size: 12px;
    color: var(--text-tertiary);
  }

  .btn-text {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.15s;

    &:hover {
      color: var(--primary);
      background: var(--primary-light);
    }

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

  .exclude-actions {
    display: flex;
    gap: 8px;
  }
}
