// ==========================================================================
// Monitor.Cat — Speed Optimizer Module Page
// ==========================================================================

@use 'tokens' as *;

.monitorcat-wrap {
  // ---------------------------------------------------------------------------
  // Page header with actions
  // ---------------------------------------------------------------------------
  .mc-speed-page .mc-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
  }

  .mc-speed-page .mc-page-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  // ---------------------------------------------------------------------------
  // Loading state
  // ---------------------------------------------------------------------------
  .mc-speed-loading-card {
    text-align: center;
    padding: 3rem 2rem;

    h2 {
      margin-top: 1.25rem;
      margin-bottom: 0.5rem;
    }
  }

  .mc-speed-loading-steps {
    list-style: none;
    padding: 0;
    margin: 1.5rem auto 0;
    max-width: 360px;
    text-align: left;
  }

  .mc-speed-loading-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    font-size: 0.875rem;
    color: $mc-text-light;
    transition: color 0.3s $mc-ease-spring, opacity 0.3s $mc-ease-spring;

    &.is-active {
      color: $mc-text;
      font-weight: 500;
    }

    &.is-done {
      color: $mc-mint-strong;
    }

    i {
      width: 20px;
      text-align: center;
      flex-shrink: 0;
    }
  }

  // ---------------------------------------------------------------------------
  // Hero score card
  // ---------------------------------------------------------------------------
  .mc-speed-hero {
    margin-bottom: 1.5rem;
    background: $mc-white;
    overflow: hidden;
  }

  .mc-speed-hero-content {
    display: flex;
    align-items: center;
    gap: 2rem;
  }

  .mc-speed-hero-ring {
    flex-shrink: 0;
  }

  .mc-speed-hero-info {
    flex: 1;
    min-width: 0;

    h2 {
      font-family: $mc-font-heading;
      font-size: 1.25rem;
      font-weight: 600;
      color: $mc-text;
      margin: 0 0 0.25rem 0;
    }

    p {
      margin: 0 0 0.75rem 0;
    }
  }

  .mc-speed-hero-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  // ---------------------------------------------------------------------------
  // Score color helpers
  // ---------------------------------------------------------------------------
  .mc-text-good {
    color: $mc-mint-strong;
    font-weight: 700;
    font-family: $mc-font-heading;
    font-size: 1.125rem;
  }

  .mc-text-ok {
    color: $mc-primary;
    font-weight: 700;
    font-family: $mc-font-heading;
    font-size: 1.125rem;
  }

  .mc-text-bad {
    color: $mc-coral-strong;
    font-weight: 700;
    font-family: $mc-font-heading;
    font-size: 1.125rem;
  }

  // ---------------------------------------------------------------------------
  // Lighthouse comparison card
  // ---------------------------------------------------------------------------
  .mc-speed-lighthouse {
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, rgba($mc-lavender, 0.06) 0%, rgba($mc-cyan, 0.04) 100%);
    border: 1px solid rgba($mc-lavender, 0.15);
  }

  .mc-speed-lighthouse-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    padding: 0.25rem 0;
  }

  .mc-speed-lighthouse-info {
    flex: 1;
    min-width: 0;
  }

  .mc-speed-lighthouse-heading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    color: $mc-text;

    i {
      font-size: 1.125rem;
    }
  }

  .mc-speed-lighthouse-btn {
    flex-shrink: 0;
    white-space: nowrap;
  }

  @media (max-width: 768px) {
    .mc-speed-lighthouse-inner {
      flex-direction: column;
      align-items: flex-start;
    }
  }

  // ---------------------------------------------------------------------------
  // Active Optimizations banner
  // ---------------------------------------------------------------------------
  .mc-speed-optimizations {
    margin-bottom: 1.5rem;
    padding: 1.25rem;
  }

  .mc-speed-optimizations-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
  }

  .mc-speed-optimizations-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: $mc-cyan-strong;

    i {
      font-size: 1.125rem;
    }
  }

  .mc-speed-optimizations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 0.75rem;
  }

  .mc-speed-opt-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: $mc-base;
    border-radius: $mc-radius-inset;
    border: 1px solid transparent;
    transition: background $mc-transition-base, border-color $mc-transition-base, box-shadow $mc-transition-base;

    &.is-active {
      background: rgba($mc-mint, 0.06);
      border-color: rgba($mc-mint-strong, 0.15);
    }

    &:hover {
      box-shadow: $mc-shadow-pedestal;
    }
  }

  .mc-speed-opt-info {
    flex: 1;
    min-width: 0;
  }

  .mc-speed-opt-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: $mc-text;
    margin-bottom: 0.125rem;
  }

  .mc-speed-opt-detail {
    font-size: 0.75rem;
    color: $mc-text-light;
    line-height: 1.4;
  }

  // Toggle switch
  .mc-toggle {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
    cursor: pointer;

    input {
      opacity: 0;
      width: 0;
      height: 0;
      position: absolute;
    }

    .mc-toggle-slider {
      position: absolute;
      inset: 0;
      background: $mc-base-alt;
      border-radius: 999px;
      transition: background $mc-transition-base;

      &::before {
        content: '';
        position: absolute;
        left: 3px;
        top: 3px;
        width: 16px;
        height: 16px;
        background: $mc-white;
        border-radius: 50%;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
        transition: transform $mc-transition-base;
      }
    }

    input:checked + .mc-toggle-slider {
      background: $mc-mint-strong;

      &::before {
        transform: translateX(18px);
      }
    }

    input:focus-visible + .mc-toggle-slider {
      outline: 2px solid $mc-cyan-strong;
      outline-offset: 2px;
    }
  }

  // ---------------------------------------------------------------------------
  // Tab styling (shared pattern with SEO)
  // ---------------------------------------------------------------------------
  .mc-speed-tabs {
    margin-bottom: 2rem;
  }

  // ---------------------------------------------------------------------------
  // Category card grid
  // ---------------------------------------------------------------------------
  .mc-speed-category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1.25rem;
  }

  // ---------------------------------------------------------------------------
  // Tab summary line
  // ---------------------------------------------------------------------------
  .mc-speed-tab-summary {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
  }

  // ---------------------------------------------------------------------------
  // Card stagger animation
  // ---------------------------------------------------------------------------
  .mc-speed-check-card {
    opacity: 0;
    transform: translateY(12px);
    animation: mc-speed-card-appear 0.4s $mc-ease-spring forwards;
  }

  @for $i from 1 through 10 {
    .mc-speed-category-grid .mc-speed-check-card:nth-child(#{$i + 1}) {
      animation-delay: #{$i * 80}ms;
    }
  }

  @keyframes mc-speed-card-appear {
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  // ---------------------------------------------------------------------------
  // Individual check card
  // ---------------------------------------------------------------------------
  .mc-speed-check-card {
    padding: 1.25rem;
    transition: transform $mc-transition-base, box-shadow $mc-transition-base;

    &:hover {
      transform: translateY(-2px);
      box-shadow: $mc-shadow-card-hover;
    }
  }

  .mc-speed-check-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
  }

  .mc-speed-check-header-info {
    flex: 1;
    min-width: 0;

    .mc-heading-sm {
      margin: 0 0 0.25rem 0;
    }
  }

  .mc-speed-check-score {
    flex-shrink: 0;
    font-family: $mc-font-heading;
    font-weight: 700;
  }

  .mc-speed-check-progress {
    margin-bottom: 1rem;
  }

  // ---------------------------------------------------------------------------
  // Checklist items
  // ---------------------------------------------------------------------------
  .mc-speed-checklist {
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .mc-speed-check-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.625rem 0;
    border-bottom: 1px solid $mc-border-color;

    &:last-child {
      border-bottom: none;
      padding-bottom: 0;
    }

    &:first-child {
      padding-top: 0;
    }
  }

  .mc-speed-check-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.6875rem;

    &.is-good {
      background: $mc-mint-light;
      color: $mc-mint-strong;
    }

    &.is-critical {
      background: $mc-coral-light;
      color: $mc-coral-strong;
    }

    &.is-warn {
      background: $mc-primary-light;
      color: $mc-primary-hover;
    }
  }

  .mc-speed-check-content {
    flex: 1;
    min-width: 0;
  }

  .mc-speed-check-title {
    font-weight: 500;
    font-size: 0.875rem;
    color: $mc-text;
    margin-bottom: 0.125rem;
  }

  .mc-speed-check-desc {
    font-size: 0.8125rem;
    color: $mc-text-medium;
    line-height: 1.5;
  }

  .mc-speed-check-value {
    font-size: 0.75rem;
    color: $mc-text-light;
    font-family: monospace;
    margin-top: 0.25rem;
    padding: 2px 8px;
    background: $mc-base;
    border-radius: 4px;
    display: inline-block;
  }

  // ---------------------------------------------------------------------------
  // Fixable check items
  // ---------------------------------------------------------------------------
  .mc-speed-check-item.is-fixable {
    cursor: pointer;
    border-radius: $mc-radius-inset;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    margin: 0 -0.5rem;
    transition: background $mc-transition-base;

    &:hover {
      background: rgba($mc-primary, 0.04);
    }
  }

  .mc-speed-check-chevron {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: $mc-text-light;
    font-size: 0.625rem;
    transition: transform 0.3s $mc-ease-spring, color $mc-transition-base;

    .is-fixable:hover & {
      color: $mc-primary;
    }

    .is-expanded & {
      transform: rotate(180deg);
    }
  }

  .mc-speed-fix-panel {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.35s $mc-ease-spring, opacity 0.25s ease, margin 0.25s ease;
    margin-top: 0;

    .is-expanded & {
      max-height: 200px;
      opacity: 1;
      margin-top: 0.5rem;
    }
  }

  .mc-speed-fix-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    background: linear-gradient(135deg, rgba($mc-primary, 0.06) 0%, rgba($mc-primary, 0.02) 100%);
    border-radius: $mc-radius-inset;
    border-left: 2px solid $mc-primary;

    i {
      flex-shrink: 0;
      margin-top: 2px;
    }
  }

  .mc-speed-fix-tip {
    font-size: 0.8125rem;
    color: $mc-text;
    line-height: 1.5;
  }

  .mc-speed-fix-btn {
    margin-top: 0.5rem;
    font-size: 0.75rem;
  }

  // ---------------------------------------------------------------------------
  // Collapsed / expanded card (passing checks)
  // ---------------------------------------------------------------------------
  .mc-speed-check-card {
    .mc-speed-checklist,
    .mc-speed-check-progress {
      overflow: hidden;
      transition: max-height 0.35s $mc-ease-spring, opacity 0.25s ease;
      max-height: 600px;
      opacity: 1;
    }

    .mc-speed-collapse-toggle {
      display: none;
      width: 100%;
      border: none;
      background: none;
      cursor: pointer;
      padding: 0.375rem 0 0;
      border-top: 1px solid $mc-border-color;
      margin-top: 0.5rem;
      color: $mc-text-light;
      font-size: 0.75rem;
      font-family: $mc-font-body;
      text-align: center;
      transition: color $mc-transition-base;

      i {
        margin-left: 4px;
        transition: transform 0.3s $mc-ease-spring;
      }

      &:hover {
        color: $mc-primary;
      }
    }
  }

  .mc-speed-check-card.is-collapsible {
    .mc-speed-collapse-toggle {
      display: block;
    }
  }

  .mc-speed-check-card.is-collapsed {
    cursor: pointer;

    .mc-speed-checklist,
    .mc-speed-check-progress {
      max-height: 0;
      opacity: 0;
    }

    .mc-speed-check-header {
      margin-bottom: 0;
    }

    .mc-speed-collapse-toggle i {
      transform: rotate(180deg);
    }
  }

  // ---------------------------------------------------------------------------
  // Status border accent on cards
  // ---------------------------------------------------------------------------
  .mc-speed-check-good {
    border-left: 3px solid $mc-mint-strong;
  }

  .mc-speed-check-warning {
    border-left: 3px solid $mc-primary;
  }

  .mc-speed-check-critical {
    border-left: 3px solid $mc-coral-strong;
  }

  // ---------------------------------------------------------------------------
  // Database cleanup section
  // ---------------------------------------------------------------------------
  .mc-db-cleanup-section {
    margin-top: 1.5rem;
  }

  .mc-db-cleanup-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;

    h3 {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      margin: 0 0 0.25rem 0;
    }

    p {
      margin: 0;
    }
  }

  .mc-db-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
  }

  .mc-db-stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1rem 0.75rem;
    background: $mc-base;
    border-radius: $mc-radius-inset;
    border: 1px solid transparent;
    transition: border-color $mc-transition-base, box-shadow $mc-transition-base;

    &.has-items {
      border-color: rgba($mc-primary, 0.2);
      background: rgba($mc-primary, 0.03);
    }
  }

  .mc-db-stat-top {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;

    i {
      font-size: 1.125rem;
    }
  }

  .mc-db-stat-count {
    font-family: $mc-font-heading;
    font-size: 1.5rem;
    font-weight: 700;
    color: $mc-text;
    line-height: 1;

    .has-items & {
      color: $mc-primary;
    }
  }

  .mc-db-stat-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: $mc-text-medium;
    margin-bottom: 0.75rem;
  }

  // ---------------------------------------------------------------------------
  // Responsive
  // ---------------------------------------------------------------------------
  @media (max-width: 768px) {
    .mc-speed-hero-content {
      flex-direction: column;
      text-align: center;
    }

    .mc-speed-hero-badges {
      justify-content: center;
    }

    .mc-speed-category-grid {
      grid-template-columns: 1fr;
    }

    .mc-speed-page .mc-page-header {
      flex-direction: column;
      align-items: flex-start;
    }

    .mc-speed-optimizations-grid {
      grid-template-columns: 1fr;
    }

    .mc-db-stats-grid {
      grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    }

    .mc-db-cleanup-header {
      flex-direction: column;
    }
  }
}
