// ==========================================================================
// Monitor.Cat — Diagnostics Module Page
// ==========================================================================

@use 'tokens' as *;

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

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

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

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

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

  .mc-diag-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 health card
  // ---------------------------------------------------------------------------
  .mc-diag-hero {
    margin-bottom: 1.5rem;
    background: $mc-white;
    overflow: hidden;
  }

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

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

  .mc-diag-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-diag-hero-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  // ---------------------------------------------------------------------------
  // Actionable insights banner
  // ---------------------------------------------------------------------------
  .mc-diag-insights {
    margin-bottom: 1.5rem;
    padding: 1.25rem;
  }

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

  .mc-diag-insights-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: $mc-primary-hover;

    i {
      font-size: 1.125rem;
    }
  }

  .mc-diag-insights-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .mc-diag-insight-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: $mc-base;
    border-radius: $mc-radius-inset;
    border-left: 3px solid transparent;
    transition: background $mc-transition-base;

    &.mc-diag-insight-warning {
      border-left-color: $mc-primary;
      background: rgba($mc-primary, 0.04);
    }

    &.mc-diag-insight-critical {
      border-left-color: $mc-coral-strong;
      background: rgba($mc-coral-strong, 0.04);
    }
  }

  .mc-diag-insight-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    margin-top: 2px;
  }

  .mc-diag-insight-content {
    flex: 1;
    min-width: 0;
  }

  .mc-diag-insight-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;

    strong {
      font-size: 0.875rem;
      font-weight: 600;
      color: $mc-text;
    }
  }

  .mc-diag-insight-section {
    font-size: 0.6875rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 8px;
    background: $mc-base-alt;
    border-radius: 999px;
    color: $mc-text-light;
  }

  .mc-diag-insight-value {
    font-size: 0.8125rem;
    color: $mc-text-medium;
    margin: 0 0 0.375rem 0;
    line-height: 1.5;
  }

  .mc-diag-insight-tip {
    display: flex;
    align-items: flex-start;
    gap: 0.375rem;
    padding: 0.5rem 0.625rem;
    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;
      font-size: 0.75rem;
    }

    span {
      font-size: 0.8125rem;
      color: $mc-text;
      line-height: 1.5;
    }
  }

  // ---------------------------------------------------------------------------
  // Tab bar (same pattern as SEO/Speed)
  // ---------------------------------------------------------------------------
  .mc-diag-tabs {
    margin-bottom: 2rem;
  }

  .mc-diag-tabs .mc-tab-bar {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.25rem;
    border-bottom: 2px solid $mc-base-alt;
    padding-bottom: 0;
  }

  .mc-diag-tabs .mc-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    font-family: $mc-font-body;
    font-size: 0.875rem;
    font-weight: 500;
    color: $mc-text-light;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: color $mc-transition-base, border-color $mc-transition-base;
    white-space: nowrap;

    i {
      font-size: 0.875rem;
    }

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

    &.is-active {
      color: $mc-primary;
      border-bottom-color: $mc-primary;
      font-weight: 600;
    }
  }

  .mc-diag-tabs .mc-tab-panel {
    display: none;

    &.is-active {
      display: block;
    }
  }

  // Tab count badges
  .mc-tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    font-size: 0.6875rem;
    font-weight: 700;
    border-radius: 999px;
    padding: 0 6px;
    margin-left: 4px;
    vertical-align: middle;
  }

  .mc-tab-count-warning {
    background: $mc-primary-light;
    color: $mc-primary-hover;
  }

  // ---------------------------------------------------------------------------
  // Detail card grid — max 2 columns to keep key-value rows readable
  // ---------------------------------------------------------------------------
  .mc-diag-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 1.25rem;
    max-width: 1100px;
  }

  // ---------------------------------------------------------------------------
  // Detail card
  // ---------------------------------------------------------------------------
  .mc-diag-detail-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-diag-detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
  }

  .mc-diag-detail-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;

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

  // ---------------------------------------------------------------------------
  // Status dot indicator
  // ---------------------------------------------------------------------------
  .mc-diag-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-right: 0.25rem;

    &.mc-diag-dot-good {
      background: $mc-mint-strong;
    }

    &.mc-diag-dot-warning {
      background: $mc-primary;
    }

    &.mc-diag-dot-critical {
      background: $mc-coral-strong;
    }
  }

  // ---------------------------------------------------------------------------
  // Value color variants
  // ---------------------------------------------------------------------------
  .mc-val-good {
    color: $mc-mint-strong;
  }

  .mc-val-warning {
    color: $mc-primary-hover;
  }

  .mc-val-critical {
    color: $mc-coral-strong;
  }

  // ---------------------------------------------------------------------------
  // System info rows (key-value pairs)
  // ---------------------------------------------------------------------------
  .mc-diag-detail-card .mc-sys-info {
    .mc-sys-info-row {
      display: flex;
      align-items: baseline;
      gap: 0.5rem;
      padding: 0.625rem 0;
      border-bottom: 1px solid $mc-border-color;

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

    .mc-sys-info-key {
      font-size: 0.875rem;
      color: $mc-text-medium;
      flex-shrink: 0;
    }

    .mc-sys-info-val {
      font-size: 0.875rem;
      font-weight: 600;
      color: $mc-text;
      text-align: right;
      overflow-wrap: break-word;
      word-break: break-word;
      margin-left: auto;
      min-width: 0;
    }

    // Long value — gradient fade + copy button
    .mc-sys-info-val-long {
      display: flex;
      align-items: center;
      gap: 0.375rem;
      margin-left: auto;
      min-width: 0;
      max-width: 65%;
    }

    .mc-sys-info-val-text {
      font-size: 0.875rem;
      font-weight: 600;
      color: $mc-text;
      white-space: nowrap;
      overflow: hidden;
      min-width: 0;
      mask-image: linear-gradient(to right, #000 70%, transparent 100%);
      -webkit-mask-image: linear-gradient(to right, #000 70%, transparent 100%);
    }

    .mc-sys-info-copy {
      flex-shrink: 0;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 28px;
      height: 28px;
      border: 1px solid $mc-border-color;
      border-radius: $mc-radius-inset;
      background: $mc-white;
      color: $mc-text-light;
      font-size: 0.75rem;
      cursor: pointer;
      transition: color $mc-transition-base, border-color $mc-transition-base,
                  background-color $mc-transition-base;

      &:hover {
        color: $mc-primary;
        border-color: $mc-primary;
        background: $mc-primary-light;
      }

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

  // ---------------------------------------------------------------------------
  // Plugin card & table
  // ---------------------------------------------------------------------------
  .mc-diag-plugins-section {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-width: 1100px;
  }

  .mc-diag-plugin-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-diag-plugin-list {
    border: 1px solid $mc-border-color;
    border-radius: $mc-radius-inset;
    overflow: hidden;
  }

  .mc-diag-plugin-row {
    display: grid;
    grid-template-columns: 2fr 0.7fr 1.3fr;
    gap: 1rem;
    padding: 0.625rem 1rem;
    border-bottom: 1px solid $mc-border-color;
    font-size: 0.8125rem;
    align-items: center;

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

    &:nth-child(even):not(.mc-diag-plugin-row-header) {
      background: rgba($mc-base, 0.5);
    }
  }

  .mc-diag-plugin-row-header {
    background: $mc-base;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: $mc-text-light;
    padding: 0.5rem 1rem;
  }

  .mc-diag-plugin-name {
    font-weight: 500;
    color: $mc-text;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mc-diag-plugin-version {
    color: $mc-text-medium;
    font-family: monospace;
    font-size: 0.75rem;
  }

  .mc-diag-plugin-author {
    color: $mc-text-light;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

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

  @for $i from 1 through 10 {
    .mc-diag-detail-grid .mc-diag-card-appear:nth-child(#{$i}) {
      animation-delay: #{($i - 1) * 80}ms;
    }

    .mc-diag-plugins-section .mc-diag-card-appear:nth-child(#{$i}) {
      animation-delay: #{($i - 1) * 80}ms;
    }
  }

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

  // ---------------------------------------------------------------------------
  // Responsive
  // ---------------------------------------------------------------------------

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

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

    .mc-diag-detail-grid {
      grid-template-columns: 1fr;
    }

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

    .mc-diag-tabs .mc-tab-bar {
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }

    .mc-diag-plugin-row {
      grid-template-columns: 1fr 0.5fr;
      gap: 0.5rem;
    }

    .mc-diag-plugin-author {
      display: none;
    }

    .mc-diag-plugin-row-header .mc-diag-plugin-author {
      display: none;
    }

    .mc-diag-insight-item {
      flex-direction: column;
      gap: 0.5rem;
    }
  }

  // Small mobile
  @media (max-width: 480px) {
    .mc-diag-detail-card {
      padding: 1rem;
    }

    .mc-diag-detail-card .mc-sys-info {
      .mc-sys-info-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.125rem;
        padding: 0.5rem 0;
      }

      .mc-sys-info-key {
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: $mc-text-light;
      }

      .mc-sys-info-val {
        font-size: 0.875rem;
        text-align: left;
        margin-left: 0;
      }

      .mc-sys-info-val-long {
        max-width: 100%;
        margin-left: 0;
      }

      .mc-sys-info-val-text {
        white-space: normal;
        overflow-wrap: break-word;
        word-break: break-word;
        mask-image: none;
        -webkit-mask-image: none;
      }
    }

    .mc-diag-plugin-card {
      padding: 1rem;
    }

    .mc-diag-plugin-row {
      grid-template-columns: 1fr auto;
      padding: 0.5rem 0.75rem;
    }

    .mc-diag-tabs .mc-tab {
      padding: 0.625rem 0.875rem;
      font-size: 0.8125rem;
    }
  }
}
