/* ==========================================
   BENEFIQ — OPTIMIZER PAGE (Categories)
   Data table with colored indicator dots
   ========================================== */

@layer pages {

  /* ==========================================
     CATEGORY INDICATOR DOTS
     ========================================== */
  .category-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
  }

  .category-dot--dining { background: var(--purple-500); }
  .category-dot--travel { background: var(--accent-blue-500); }
  .category-dot--groceries { background: var(--color-success); }
  .category-dot--gas { background: var(--brand-500); }
  .category-dot--streaming { background: var(--purple-400); }
  .category-dot--online { background: var(--accent-blue-600); }
  .category-dot--transit { background: var(--brand-300); }
  .category-dot--drugstore { background: var(--color-success); }
  .category-dot--entertainment { background: var(--purple-600); }
  .category-dot--fitness { background: var(--accent-blue-400); }
  .category-dot--home_improvement { background: var(--brand-600); }
  .category-dot--wholesale { background: var(--purple-300); }
  .category-dot--telecom { background: var(--color-success); }
  .category-dot--office_supply { background: var(--brand-400); }
  .category-dot--shipping { background: var(--accent-blue-500); }
  .category-dot--advertising { background: var(--purple-700); }
  .category-dot--department_store { background: var(--brand-500); }
  .category-dot--other { background: var(--surface-400); }

  /* ==========================================
     CARD SWATCH IN TABLE ROW
     ========================================== */
  .category-card-swatch {
    width: 24px;
    height: 16px;
    border-radius: 3px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  }

  .category-card-name {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    min-width: 0;
  }

  .opt-category-flex {
    align-items: center;
  }

  .opt-category-name {
    font-weight: var(--weight-medium);
  }

  .opt-best-card-flex {
    flex-wrap: wrap;
  }

  .opt-best-card-block {
    min-width: 0;
  }

  .opt-mobile-alt {
    display: none;
  }

  /* ==========================================
     PAGE SPACING — match other pages' content start
     ========================================== */
  #page-optimizer .data-table {
    margin-top: var(--space-8);
  }

  /* ==========================================
     EMPTY STATE
     ========================================== */
  .optimizer-empty {
    text-align: center;
    padding: var(--space-12) var(--space-5);
    margin-top: var(--space-6);
    background: var(--bg-elevated);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-sm);
  }

  .optimizer-empty-icon {
    font-size: 4rem;
    margin-bottom: var(--space-4);
    opacity: 0.3;
  }

  .optimizer-empty h3 {
    font-size: var(--text-lg);
    margin-bottom: var(--space-2);
  }

  .optimizer-empty p {
    color: var(--text-muted);
    margin-bottom: var(--space-5);
  }

  /* ==========================================
     OPTIMIZER TABLE — proper <table> element
     for reliable sticky columns on all browsers
     ========================================== */
  .optimizer-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
  }

  /* Header row — darker background */
  .optimizer-table thead th {
    padding: var(--space-3) var(--space-5);
    background: var(--surface-100);
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    white-space: nowrap;
  }

  /* Add gap between best rate and runner-up columns */
  .optimizer-table thead th:nth-child(4),
  .optimizer-table tbody td:nth-child(4) {
    padding-left: var(--space-8);
  }

  /* Data rows — lighter background */
  .optimizer-table tbody td {
    padding: var(--space-4) var(--space-5);
    background: rgba(255, 255, 255, 0.4);
    border-bottom: 1px solid var(--border);
  }

  .optimizer-table tbody tr:last-child td {
    border-bottom: none;
  }

  /* Inner flex layout for icon + text cells */
  .opt-cell-flex {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
  }

  .opt-cell-rate {
    text-align: right;
    font-weight: 800;
    font-family: var(--font-body);
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
  }

  .opt-cell-rate--secondary {
    color: var(--text-secondary);
  }

  /* Rotating/offer tag (Q1 badge) */
  .opt-rate-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 5px;
    background: var(--brand-500);
    color: var(--text-inverse);
    font-size: 9px;
    font-weight: var(--weight-bold);
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.02em;
  }

  /* Mobile: horizontal scroll reveals Runner-Up columns. Header row and Category column stay frozen. */
  @media (max-width: 640px) {
    #page-optimizer .data-table {
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }

    .optimizer-table {
      width: max-content;
      min-width: 100%;
      table-layout: fixed;
    }

    .optimizer-table thead th,
    .optimizer-table tbody td {
      padding: var(--space-3) var(--space-2);
      vertical-align: middle;
    }

    /* Fixed column widths (px) so the table extends past the viewport and scrolls */
    .optimizer-table thead th:nth-child(1),
    .optimizer-table tbody td:nth-child(1) {
      width: 110px;
    }

    .optimizer-table thead th:nth-child(2),
    .optimizer-table tbody td:nth-child(2),
    .optimizer-table thead th:nth-child(4),
    .optimizer-table tbody td:nth-child(4) {
      width: 150px;
    }

    .optimizer-table thead th:nth-child(3),
    .optimizer-table tbody td:nth-child(3),
    .optimizer-table thead th:nth-child(5),
    .optimizer-table tbody td:nth-child(5) {
      width: 50px;
      text-align: right;
    }

    /* Frozen header row (sticky to viewport top) */
    .optimizer-table thead th {
      position: sticky;
      top: 0;
      background: var(--surface-100);
      z-index: 3;
    }

    /* Frozen first column (sticky to scroll container left) */
    .optimizer-table tbody td:nth-child(1) {
      position: sticky;
      left: 0;
      background: var(--bg-elevated);
      z-index: 2;
      box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
    }

    /* Top-left header intersection: sits above both */
    .optimizer-table thead th:nth-child(1) {
      left: 0;
      z-index: 4;
      box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
    }

    .optimizer-table .opt-category-flex {
      align-items: center;
      gap: 6px;
      min-width: 0;
    }

    .optimizer-table .opt-category-name {
      white-space: normal;
      overflow-wrap: break-word;
      line-height: 1.2;
    }

    .optimizer-table .opt-best-card-flex,
    .optimizer-table tbody td:nth-child(4) .opt-cell-flex {
      flex-wrap: nowrap;
      align-items: center;
      gap: 6px;
      min-width: 0;
    }

    .optimizer-table .opt-card-thumb {
      position: relative;
      display: inline-flex;
      flex-shrink: 0;
    }

    .optimizer-table .category-card-swatch {
      width: 26px;
      height: 17px;
    }

    /* Q-tag overlays the card swatch as a corner badge */
    .optimizer-table .opt-card-thumb .opt-rate-tag {
      position: absolute;
      top: -5px;
      right: -7px;
      padding: 1px 4px;
      font-size: 8px;
      line-height: 1.1;
      border-radius: 999px;
      box-shadow: 0 0 0 1.5px var(--bg-elevated);
      pointer-events: none;
    }

    .optimizer-table .category-card-name {
      font-size: var(--text-sm);
      white-space: normal;
      word-break: normal;
      overflow-wrap: normal;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
      line-height: 1.2;
      flex: 1 1 auto;
      min-width: 0;
    }

    .optimizer-table .opt-cell-rate {
      display: table-cell;
      white-space: nowrap;
      font-size: var(--text-base);
      line-height: 1.2;
      text-align: right;
    }
  }

}
