/* --- Compare page --- */

.compare-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 24px;
}

.compare-header .compare-heading {
  margin: 0;
}

.compare-heading {
  margin: 0 0 24px;
  font-size: 22px;
}

.compare-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 32px;
}

.compare-side {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  position: relative;
}

/* Stack the side's actual content above the absolutely-positioned
 * stock photo. The autocomplete dropdown sits inside .compare-search,
 * so it inherits this stacking context and renders above the image. */
.compare-side > h3,
.compare-side > .compare-search {
  position: relative;
  z-index: 1;
}

/* While this side's search is focused, lift its whole stacking context
 * above the sibling side's .compare-search (also z-index: 1) and the
 * sticky table header (z-index: 2) so the dropdown isn't painted over. */
.compare-side > .compare-search:focus-within {
  z-index: 30;
}

.compare-stock-img {
  position: absolute;
  top: 0;
  right: 0;
  width: 80%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transform: translateX(24px);
  transition: opacity 600ms ease, transform 600ms ease;
  -webkit-mask-image: linear-gradient(to right, transparent 0%, black 50%);
  mask-image: linear-gradient(to right, transparent 0%, black 50%);
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
}

.compare-stock-img.loaded {
  opacity: 1;
  transform: translateX(0);
}

.compare-side h3 {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.compare-select {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.compare-select:last-child {
  margin-bottom: 0;
}

.compare-select label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.compare-select select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  width: 100%;
}

.compare-select select:disabled {
  opacity: 0.5;
}

.compare-search {
  position: relative;
}

.compare-search input[type="search"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  width: 100%;
  font-family: inherit;
  box-sizing: border-box;
}

.compare-search input[type="search"]:focus {
  outline: none;
  border-color: var(--accent);
}

.compare-prompt {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  font-size: 14px;
}

.common-comparisons {
  margin-bottom: 24px;
}

.common-comparisons h4 {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.common-comparisons .link-row .suggestion-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}

.common-comparisons .link-row .suggestion-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.compare-result {
  position: relative;
}

/* Stack the table + TLDR above the per-row stock photos that
 * renderRowStockPhotos paints behind them (z-index: 0). */
.compare-result > .compare-tldr,
.compare-result > .compare-table {
  position: relative;
  z-index: 1;
}

/* Stock photo behind a single row whose winner has a significant
 * advantage. JS sizes it to the row's bounding rect after layout.
 * 0.15 opacity keeps the row's text legible. object-position centers
 * the car body in the typically-narrow horizontal strip. */
.compare-row-stock-img {
  position: absolute;
  object-fit: cover;
  object-position: center;
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transition: opacity 600ms ease;
}

.compare-row-stock-img.loaded {
  opacity: 0.15;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.compare-table th,
.compare-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.compare-table th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
}

.compare-table .field-label {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  font-weight: 500;
}

.compare-table tr.same-row {
  opacity: 0.15;
}

.compare-table tr.diff-row {
  border-left: 2px solid var(--accent);
}

.compare-table td.val-better {
  font-weight: 750;
  font-size: 14px;
  color: var(--text);
}

.compare-table td.val-worse {
  font-weight: 100;
  color: var(--muted);
}

.diff-cell {
  max-width: 360px;
}

.pct-badge {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  margin-bottom: 4px;
}

.pct-badge.pct-md { font-size: 12px; padding: 2px 7px; }
.pct-badge.pct-lg { font-size: 13px; padding: 3px 8px; }
.pct-badge.pct-xl { font-size: 15px; padding: 4px 10px; }

/* Green for better (car A wins) */
.pct-badge.pct-better { color: #7ee787; background: rgba(126, 231, 135, 0.08); border-color: rgba(126, 231, 135, 0.2); }
.pct-badge.pct-better.pct-md { color: #7ee787; background: rgba(126, 231, 135, 0.12); border-color: rgba(126, 231, 135, 0.25); }
.pct-badge.pct-better.pct-lg { color: #a5f0ad; background: rgba(126, 231, 135, 0.18); border-color: rgba(126, 231, 135, 0.35); }
.pct-badge.pct-better.pct-xl { color: #c8f7cd; background: rgba(126, 231, 135, 0.25); border-color: rgba(126, 231, 135, 0.5); }

/* Red for worse (car B wins) */
.pct-badge.pct-worse { color: #f47067; background: rgba(244, 112, 103, 0.08); border-color: rgba(244, 112, 103, 0.2); }
.pct-badge.pct-worse.pct-md { color: #f47067; background: rgba(244, 112, 103, 0.12); border-color: rgba(244, 112, 103, 0.25); }
.pct-badge.pct-worse.pct-lg { color: #f79a93; background: rgba(244, 112, 103, 0.18); border-color: rgba(244, 112, 103, 0.35); }
.pct-badge.pct-worse.pct-xl { color: #fbc4c0; background: rgba(244, 112, 103, 0.25); border-color: rgba(244, 112, 103, 0.5); }

.explanation {
  display: block;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.persona-side {
  margin-top: 8px;
}

.persona-side + .persona-side {
  margin-top: 10px;
}

.persona-car {
  margin: 0 0 3px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.persona-impacts {
  list-style: none;
  margin: 0;
  padding: 0 0 0 14px;
  font-size: 12px;
  line-height: 1.5;
}

.persona-impacts li {
  display: block;
  color: var(--muted);
}

.persona-impacts .persona-name {
  color: var(--text);
  font-weight: 500;
}

.persona-impacts .persona-name::after {
  content: " — ";
  color: var(--muted);
  font-weight: 400;
}

.compare-tldr {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 24px;
}

.compare-tldr h3 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tldr-section + .tldr-section {
  margin-top: 16px;
}

.tldr-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.tldr-name {
  font-size: 14px;
  font-weight: 600;
}

.tldr-personas {
  font-size: 12px;
  color: var(--muted);
}

.tldr-personas::before {
  content: "— ";
}

/* Persona highlight: when the user's saved persona maps to a TL;DR
   section, mark it so the recommendation reads as personal. The
   highlighted persona token uses <mark> for accessibility; the section
   gets a left rule + "you" badge so it stands out at a glance. */
.tldr-persona-you {
  background: color-mix(in srgb, var(--accent) 24%, transparent);
  color: var(--text);
  padding: 0 4px;
  border-radius: 3px;
  font-weight: 600;
}

.tldr-section-matches-you {
  position: relative;
  padding-left: 12px;
  border-left: 3px solid var(--accent);
}

.tldr-you-badge {
  display: inline-block;
  margin-bottom: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.tldr-summary {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

.compare-tldr li .pct-badge {
  margin-right: 6px;
}

.compare-tldr li .explanation {
  display: inline;
}

.compare-table .same-value {
  text-align: center;
  color: var(--muted);
}

.compare-table thead a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dashed var(--border);
  transition: color 120ms ease, border-color 120ms ease;
}

.compare-table thead a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

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

  .compare-tldr {
    padding: 16px;
  }

  .compare-table,
  .compare-table thead,
  .compare-table tbody,
  .compare-table tr {
    display: block;
  }

  .compare-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
  }

  .compare-table thead tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 8px 10px;
  }

  .compare-table thead th {
    padding: 0;
    border: none;
    position: static;
    white-space: normal;
    font-size: 11px;
    line-height: 1.3;
  }

  .compare-table thead th:first-child,
  .compare-table thead th:last-child {
    display: none;
  }

  .compare-table tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 12px;
    row-gap: 4px;
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
  }

  .compare-table tbody td {
    display: block;
    padding: 0;
    border: none;
    max-width: none;
    min-width: 0;
  }

  .compare-table tbody td.field-label {
    grid-column: 1 / -1;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 2px;
  }

  .compare-table tbody td.same-value {
    grid-column: 1 / -1;
    text-align: left;
  }

  .compare-table tbody td.diff-cell {
    grid-column: 1 / -1;
    margin-top: 6px;
  }
}
