/* ============================================================
   COMPARE PAGE
   Philosophy: the table is the product. One unified panel,
   no floating card soup. Dense, scannable, utility-first.
   ============================================================ */

/* ── Beta Banner ───────────────────────────────────────────── */

.compare-beta-banner {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  background: var(--bg-surface);
  border-bottom: 1px solid transparent;
  transition:
    max-height 360ms var(--ease-out),
    opacity 260ms var(--ease-out),
    border-color 260ms;
}

.compare-beta-banner--visible {
  max-height: 48px;
  opacity: 1;
  border-bottom-color: var(--border-subtle);
}

.compare-beta-banner-inner {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: var(--container-xl);
  margin-inline: auto;
  padding: 7px var(--space-5);
  color: var(--text-tertiary);
  font-size: 11px;
  line-height: 1.4;
}

.compare-beta-banner svg {
  flex-shrink: 0;
  color: var(--text-tertiary);
}

.compare-beta-banner strong {
  color: var(--text-secondary);
  font-weight: var(--weight-medium);
}

/* ── Page Layout ───────────────────────────────────────────── */

.compare-page {
  min-height: calc(100vh - var(--header-height));
  padding-bottom: var(--space-20);
}

.compare-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding-top: var(--space-5);
}

/* ── Category Tabs — underline, not pills ──────────────────── */

.category-selector {
  display: flex;
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  border-bottom: 1px solid var(--border-subtle);
}

.category-selector::-webkit-scrollbar {
  display: none;
}

.cat-btn {
  display: inline-flex;
  align-items: center;
  padding: 9px var(--space-4);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--text-tertiary);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition:
    color var(--duration-fast),
    border-color var(--duration-fast);
}

.cat-btn:hover {
  color: var(--text-secondary);
}

.cat-btn.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
  font-weight: var(--weight-semibold);
}

/* ── Search Panel ──────────────────────────────────────────── */

.search-panel {
  position: relative;
}

.search-field-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 0 var(--space-4);
  height: 44px;
  transition: border-color var(--duration-fast);
}

.search-field-wrap:focus-within {
  border-color: var(--accent);
}

.search-field-icon {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.search-field {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--text-primary);
  padding: 0;
}

.search-field::placeholder {
  color: var(--text-tertiary);
}

.search-limit-badge {
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 3px;
  padding: 2px 7px;
  white-space: nowrap;
  flex-shrink: 0;
  font-feature-settings: "tnum";
  transition: background var(--duration-fast), color var(--duration-fast);
}

.search-limit-badge.full {
  background: var(--warning-subtle);
  color: var(--warning);
  border-color: rgba(212, 164, 62, 0.3);
}

/* Search Dropdown */
.search-results-wrap {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.search-results {
  max-height: 360px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}

.search-result-item {
  display: grid;
  grid-template-columns: 36px 1fr auto auto;
  align-items: center;
  gap: var(--space-3);
  padding: 8px var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background var(--duration-fast);
  animation: result-in 160ms var(--ease-out) both;
}

@keyframes result-in {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: 1; transform: translateY(0); }
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: var(--bg-surface);
}

.search-result-item.already-added {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.search-result-img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  padding: 2px;
  flex-shrink: 0;
}

.search-result-info {
  min-width: 0;
}

.search-result-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-company {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 1px;
}

/* Spec preview — visible but subdued */
.search-result-specs {
  display: flex;
  gap: var(--space-3);
  margin-top: 2px;
}

.search-result-spec {
  font-size: 10px;
  color: var(--text-tertiary);
}

.search-result-spec strong {
  color: var(--text-secondary);
  font-weight: var(--weight-medium);
}

.search-result-price {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  white-space: nowrap;
  font-feature-settings: "tnum";
}

.search-result-add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 3px;
  background: var(--accent-subtle);
  color: var(--accent);
  border: none;
  flex-shrink: 0;
  transition: background var(--duration-fast);
}

.search-result-item:hover .search-result-add {
  background: var(--accent);
  color: var(--text-inverse);
}

.search-no-results {
  padding: var(--space-6) var(--space-4);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}

/* ── Compare Workspace — single unified panel ──────────────── */

.compare-workspace {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* ── Slots — compact header strip, not cards ───────────────── */

.compare-slots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border-subtle);
}

/* Empty slot */
.compare-slot.empty {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  border-right: 1px solid var(--border-subtle);
}

.compare-slot.empty:last-child {
  border-right: none;
}

.slot-empty-label {
  font-size: 11px;
  color: var(--text-tertiary);
  margin: 0;
  letter-spacing: 0.01em;
}

/* Filled slot */
.compare-slot.filled {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 10px 8px 12px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  position: relative;
  animation: slot-appear 180ms var(--ease-out) both;
}

.compare-slot.filled:last-child {
  border-right: none;
}

@keyframes slot-appear {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.slot-remove-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    color var(--duration-fast),
    background var(--duration-fast);
}

.slot-remove-btn:hover {
  color: var(--error);
  background: var(--error-subtle);
}

.slot-loading {
  color: var(--text-tertiary);
  font-size: var(--text-xs);
}

.slot-product-image {
  width: 36px;
  height: 36px;
  object-fit: contain;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 2px;
  flex-shrink: 0;
}

.slot-product-details {
  flex: 1;
  min-width: 0;
  padding-right: var(--space-5);
}

.slot-product-name {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  line-height: var(--leading-snug);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot-product-company {
  font-size: 10px;
  color: var(--text-tertiary);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot-product-price {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: var(--weight-medium);
  margin: 1px 0 0;
  font-feature-settings: "tnum";
}

.slot-product-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  align-items: center;
}

.slot-view-link,
.slot-buy-link {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: var(--weight-medium);
  padding: 2px 8px;
  border-radius: 3px;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background var(--duration-fast),
    color var(--duration-fast),
    border-color var(--duration-fast);
}

.slot-view-link {
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--text-tertiary);
}

.slot-view-link:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.slot-buy-link {
  background: var(--accent-subtle);
  border: 1px solid transparent;
  color: var(--accent-text);
}

.slot-buy-link:hover {
  background: var(--accent);
  color: var(--text-inverse);
}

/* ── Controls Bar ──────────────────────────────────────────── */

.compare-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 5px 12px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  animation: fade-in 180ms var(--ease-out);
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

.controls-label strong {
  color: var(--text-secondary);
  font-weight: var(--weight-medium);
}

.controls-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Winner Toggle */
.winner-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: var(--weight-medium);
  padding: 3px 10px;
  border-radius: 3px;
  border: 1px solid var(--border-default);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--duration-fast);
}

.winner-toggle[data-on="true"] {
  background: var(--warning-subtle);
  border-color: rgba(212, 164, 62, 0.35);
  color: var(--warning);
}

.clear-all-btn {
  font-size: 11px;
  color: var(--text-tertiary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 3px;
  transition: color var(--duration-fast);
}

.clear-all-btn:hover {
  color: var(--error);
}

/* ── Comparison Table ──────────────────────────────────────── */

.compare-table-outer {
  animation: fade-in 220ms var(--ease-out) both;
}

.compare-table-scroll {
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 480px;
}

.compare-table .col-label {
  width: 140px;
}

/* thead */
.compare-table thead tr {
  background: var(--bg-surface);
}

.compare-table thead th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border-default);
  vertical-align: bottom;
}

.compare-table thead th.th-label {
  font-size: 10px;
  font-weight: var(--weight-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.compare-table thead th.th-item {
  text-align: center;
}

.th-item-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding-bottom: var(--space-1);
}

.th-item-img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  padding: 4px;
}

.th-item-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  line-height: var(--leading-snug);
  text-align: center;
  max-width: 160px;
}

.th-item-company {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 1px;
}

/* tbody */
.compare-table tbody tr {
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--duration-fast);
  animation: row-in 160ms var(--ease-out) both;
}

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

/* Alternating rows for scanability */
.compare-table tbody tr:nth-child(odd) {
  background: var(--bg-base);
}

.compare-table tbody tr:nth-child(even) {
  background: var(--bg-surface);
}

.compare-table tbody tr:hover {
  background: var(--bg-elevated);
}

.compare-table td {
  padding: 7px var(--space-4);
  font-size: var(--text-sm);
  vertical-align: middle;
}

/* Label column — always sticky-looking via bg */
.compare-table td.td-label {
  font-size: 10px;
  font-weight: var(--weight-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  border-right: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.compare-table td.td-value {
  text-align: center;
  color: var(--text-secondary);
  font-weight: var(--weight-medium);
  font-feature-settings: "tnum";
}

.compare-table td.td-value .null-value {
  color: var(--text-tertiary);
  font-weight: var(--weight-normal);
  opacity: 0.5;
}

/* Long-text rows */
.compare-table tr.row-pros td.td-value,
.compare-table tr.row-cons td.td-value,
.compare-table tr.row-best_use_cases td.td-value,
.compare-table tr.row-key_features td.td-value,
.compare-table tr.row-upgrade_path td.td-value,
.compare-table tr.row-tips_for_optimal_use td.td-value,
.compare-table tr.row-popular_alternatives td.td-value,
.compare-table tr.row-description td.td-value,
.compare-table tr.row-included_accessories td.td-value,
.compare-table tr.row-mount_compatibility td.td-value,
.compare-table tr.row-compatibility td.td-value {
  text-align: left;
  white-space: normal;
  font-size: var(--text-xs);
  font-weight: var(--weight-normal);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
  vertical-align: top;
  padding-top: var(--space-2);
  padding-bottom: var(--space-2);
}

.compare-table tr.row-pros td.td-label,
.compare-table tr.row-cons td.td-label,
.compare-table tr.row-best_use_cases td.td-label,
.compare-table tr.row-key_features td.td-label,
.compare-table tr.row-upgrade_path td.td-label,
.compare-table tr.row-tips_for_optimal_use td.td-label,
.compare-table tr.row-popular_alternatives td.td-label,
.compare-table tr.row-description td.td-label,
.compare-table tr.row-included_accessories td.td-label,
.compare-table tr.row-mount_compatibility td.td-label,
.compare-table tr.row-compatibility td.td-label {
  vertical-align: top;
  padding-top: var(--space-2);
}

/* Winner highlight */
.compare-table.show-winners td.td-winner {
  color: var(--warning);
  font-weight: var(--weight-semibold);
}

.winner-mark {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  vertical-align: middle;
}

.winner-arrow {
  font-size: 0.6em;
  line-height: 1;
  opacity: 0.7;
}

/* Price row */
.compare-table tr.row-price td.td-value {
  font-size: var(--text-base);
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
}

.compare-table.show-winners tr.row-price td.td-winner {
  color: var(--warning);
}

/* Row stagger animation */
.compare-table tbody tr:nth-child(1)  { animation-delay: 0ms; }
.compare-table tbody tr:nth-child(2)  { animation-delay: 20ms; }
.compare-table tbody tr:nth-child(3)  { animation-delay: 40ms; }
.compare-table tbody tr:nth-child(4)  { animation-delay: 60ms; }
.compare-table tbody tr:nth-child(5)  { animation-delay: 80ms; }
.compare-table tbody tr:nth-child(6)  { animation-delay: 100ms; }
.compare-table tbody tr:nth-child(7)  { animation-delay: 120ms; }
.compare-table tbody tr:nth-child(8)  { animation-delay: 140ms; }
.compare-table tbody tr:nth-child(9)  { animation-delay: 160ms; }
.compare-table tbody tr:nth-child(10) { animation-delay: 180ms; }

@keyframes row-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Nudge — minimal empty state ───────────────────────────── */

.compare-nudge {
  padding: var(--space-10) var(--space-6);
  text-align: center;
  background: var(--bg-base);
}

.compare-nudge p {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  max-width: 280px;
  margin: 0 auto;
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 768px) {
  .compare-slots {
    grid-template-columns: 1fr;
  }

  .compare-slot.empty {
    min-height: 40px;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }

  .compare-slot.empty:last-child {
    border-bottom: none;
  }

  .compare-slot.filled {
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }

  .compare-slot.filled:last-child {
    border-bottom: none;
  }

  .compare-controls {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
    padding: 8px 12px;
  }

  .compare-table .col-label {
    width: 100px;
  }

  .compare-table td,
  .compare-table th {
    padding: 6px var(--space-3);
  }

  .th-item-img {
    width: 44px;
    height: 44px;
  }
}

@media (max-width: 480px) {
  .cat-btn {
    padding: 8px 12px;
    font-size: var(--text-xs);
  }

  .slot-product-actions {
    display: none;
  }
}
