/* CFCA Compare Lights — page-scoped styles (loaded only when
   html_page_compare). Mobile-first: base targets the narrow viewport;
   min-width layers widen columns on tablet/desktop. Self-contained under
   .cmp so nothing leaks into the shared site-v2 cascade.

   The table is always drawn complete: a fixed 4 light columns (Layout A) /
   rows (Layout B). Filled slots show a light; empty slots are faint
   placeholders. Grids span the full container width so the navy header band
   always reaches the right edge; on narrow viewports the per-column minmax
   floor forces a horizontal scroll with a sticky label column.

   Layout A (.cmp-view--a): specs as rows, lights as columns. CSS grid with
   display:contents per column so the row template keeps every cell aligned.
   Layout B (.cmp-view--b): lights as rows, specs as columns. Numeric columns
   are right-aligned tabular-nums so magnitudes stack by place value. */

.cmp {
  --cmp-ink: #0a0e13;
  --cmp-ink-soft: #41506a;
  --cmp-muted: #6a7585;
  --cmp-line: #d4d7dc;
  --cmp-bg-alt: #f4f6f9;
  --cmp-bg-zebra: #fcfcfd;
  --cmp-bg-zebra-label: #eef1f6;
  --cmp-bg-empty: #fafbfd;
  --cmp-brand: #1f2a36;
  --cmp-brand-deep: #131a23;
  --cmp-danger: #b13a3a;
  --cmp-ctrl-h: var(--field-h, 44px);
  --cmp-col-min: 108px;
  --cmp-label-w: 116px;
}
.cmp *,
.cmp *::before,
.cmp *::after {
  box-sizing: border-box;
}

/* ── add bar + toggle ─────────────────────────────────────────────────── */
.cmp-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 0.75rem;
  align-items: center;
  margin: 0 0 1rem;
}
.cmp-adder {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  align-items: center;
  flex: 1 1 300px;
  min-width: 0;
}
.cmp-adder__label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--cmp-ink-soft);
  white-space: nowrap;
}
.cmp-adder__select {
  flex: 1 1 auto;
  min-width: 0;
  height: var(--cmp-ctrl-h);
  font: inherit;
  font-size: 16px; /* iOS: 16px+ prevents focus-zoom */
  padding: 0 0.7rem;
  border: 1px solid var(--cmp-line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--cmp-ink);
}
.cmp-adder__select:disabled {
  opacity: 0.55;
}
.cmp-adder__go {
  height: var(--cmp-ctrl-h);
  flex: 0 0 auto;
  font: inherit;
  font-weight: 600;
  padding: 0 1.1rem;
  border: 1px solid var(--cmp-brand);
  border-radius: var(--radius-sm);
  background: var(--cmp-brand);
  color: #fff;
  cursor: pointer;
}
.cmp-adder__go:hover {
  background: var(--cmp-brand-deep);
}
.cmp-toggle {
  display: inline-flex;
  height: var(--cmp-ctrl-h);
  border: 1px solid var(--cmp-line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.cmp-toggle__btn {
  height: 100%;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 0 1.1rem;
  border: 0;
  background: #fff;
  color: var(--cmp-ink-soft);
  cursor: pointer;
}
.cmp-toggle__btn + .cmp-toggle__btn {
  border-left: 1px solid var(--cmp-line);
}
.cmp-toggle__btn.is-active {
  background: var(--cmp-brand);
  color: #fff;
}

/* ── layout switching ─────────────────────────────────────────────────── */
.cmp[data-layout='a'] .cmp-view--b {
  display: none;
}
.cmp[data-layout='b'] .cmp-view--a {
  display: none;
}

.cmp-scroller {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--cmp-line);
  border-radius: 8px;
}

/* ── Layout A: specs rows / lights columns ────────────────────────────── */
.cmp-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(8, auto); /* 1 header + 7 spec rows */
  grid-template-columns: var(--cmp-label-w) repeat(4, minmax(var(--cmp-col-min), 1fr));
  width: 100%;
}
.cmp-col {
  display: contents;
}
.cmp-cell {
  padding: 0.6rem 0.7rem;
  border-bottom: 1px solid var(--cmp-line);
  border-right: 1px solid var(--cmp-line);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  min-height: 2.4rem;
}
.cmp-cell--head {
  border-right-color: var(--cmp-line);
}
.cmp-cell--label {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--cmp-bg-alt);
  font-weight: 600;
  color: var(--cmp-ink-soft);
  border-right: 1px solid var(--cmp-line);
}
.cmp-grid > .cmp-col > .cmp-cell:nth-child(even) {
  background: var(--cmp-bg-zebra);
}
.cmp-grid > .cmp-col > .cmp-cell--label:nth-child(even) {
  background: var(--cmp-bg-zebra-label);
}
.cmp-cell--head {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 0.3rem;
  background: var(--cmp-brand);
  color: #fff;
  border-bottom: 1px solid var(--cmp-line);
  min-height: 3.2rem;
  position: relative;
}
.cmp-cell--head.cmp-cell--label {
  /* Top-left corner = sticky-left (like the body labels) AND a header. The
     single-class .cmp-cell--head rule above sets position:relative, which would
     win over .cmp-cell--label's sticky by source order; restate sticky here
     (2-class specificity) so the "Specification" corner stays put on h-scroll. */
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--cmp-brand-deep);
  color: #cfd6df;
}
.cmp-ttl {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

/* product thumbnail (white tile so a tight white-bg shot reads on any bg) */
.cmp-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  background: #fff;
  border-radius: 6px;
  overflow: hidden;
}
.cmp-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
/* Layout A header: image fills the full column width, with the remove
   button overlaid on its top-right corner; image + model both link to PDP. */
.cmp-head-media {
  position: relative;
  width: 100%;
}
.cmp-cell--head .cmp-thumb {
  width: 100%;
  height: 96px;
  padding: 4px;
}
.cmp-cell--head .cmp-thumb--empty {
  display: block;
  height: 96px;
}
/* Layout A overlays the remove × on the image corner; look comes from the
   shared .c-icon-btn--on-media primitive, only positioning is compare-local. */
.cmp-head-media .c-icon-btn {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
}
.cmp-ttl-link {
  color: #fff;
  text-decoration: none;
}
.cmp-ttl-link:hover .cmp-ttl {
  text-decoration: underline;
}
.cmp-cell--head .cmp-thumb--empty {
  background: rgba(255, 255, 255, 0.1);
}
.cmp-hcell--model .cmp-thumb--empty {
  display: block;
  height: 64px;
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--cmp-line);
}

/* empty placeholder column (Layout A) — blanked: no dark header fill, no
   placeholder thumbnail tile, no em-dash. An unused column reads as truly
   empty rather than a dummy light. */
.cmp-col--empty .cmp-cell {
  background: var(--cmp-bg-empty);
}
.cmp-col--empty .cmp-cell--head {
  background: var(--cmp-bg-empty);
}
.cmp-col--empty .cmp-thumb--empty,
.cmp-col--empty .cmp-ttl {
  display: none;
}

/* ── Layout B: lights rows / specs columns ────────────────────────────── */
.cmp-hgrid {
  display: grid;
  grid-auto-flow: row;
  grid-auto-rows: auto;
  /* Proportional: the two "lm / time" columns carry the longest text and get
     the most room; beam / length / weight are short numerics and stay narrow;
     battery is medium. Per-column minmax floors force the mobile h-scroll. */
  grid-template-columns:
    var(--cmp-label-w)
    minmax(90px, 0.8fr)
    minmax(124px, 1.5fr) minmax(124px, 1.5fr)
    minmax(76px, 0.7fr) minmax(76px, 0.7fr) minmax(78px, 0.7fr)
    minmax(104px, 1fr);
  width: 100%;
}
.cmp-hrow {
  display: contents;
}
.cmp-hcell {
  padding: 0.6rem 0.7rem;
  border-bottom: 1px solid var(--cmp-line);
  border-right: 1px solid var(--cmp-line);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  min-height: 2.4rem;
  background: #fff;
}
.cmp-hcell--head {
  border-right-color: var(--cmp-line);
}
.cmp-hgrid > .cmp-hrow:nth-child(even) > .cmp-hcell {
  background: var(--cmp-bg-zebra);
}
.cmp-hcell--model {
  position: sticky;
  left: 0;
  z-index: 2;
  /* Image-led, mirroring the Table-view header: a large image on top with the
     model name below; both link to the PDP. */
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  font-weight: 600;
  color: var(--cmp-ink-soft);
  border-right: 1px solid var(--cmp-line);
  background: var(--cmp-bg-alt);
}
.cmp-hcell--model .cmp-thumb {
  width: 100%;
  height: 64px;
  padding: 3px;
}
.cmp-hcell--model .cmp-ttl-link {
  color: var(--cmp-ink-soft);
}
.cmp-hcell--model .cmp-ttl-link:hover .cmp-hcell__model-name {
  text-decoration: underline;
}
/* Layout B: model name + remove button share the bottom line, button right. */
.cmp-model-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}
.cmp-hcell__model-name {
  min-width: 0;
  overflow-wrap: break-word;
}
.cmp-hgrid > .cmp-hrow:nth-child(even) > .cmp-hcell--model {
  background: var(--cmp-bg-zebra-label);
}
.cmp-hcell--head {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--cmp-brand);
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--cmp-line);
  min-height: 2.8rem;
}
.cmp-hcell--head.cmp-hcell--model {
  z-index: 4;
  background: var(--cmp-brand-deep);
  color: #cfd6df;
}
.cmp-hcell--rt {
  justify-content: flex-end;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* empty placeholder row (Layout B) */
.cmp-hrow--empty .cmp-hcell {
  background: var(--cmp-bg-empty);
}
.cmp-hrow--empty .cmp-hcell--model {
  color: var(--cmp-muted);
  font-weight: 400;
}
/* Blank empty rows (Layout B): hide the placeholder thumbnail + em-dash. */
.cmp-hrow--empty .cmp-thumb--empty,
.cmp-hrow--empty .cmp-hcell__model-name {
  display: none;
}


/* ── searchable combobox (JS-enhanced "Add a light") ──────────────────── */
.cmp-adder--enhanced .cmp-adder__select,
.cmp-adder--enhanced .cmp-adder__go {
  display: none;
}
.cmp-combo {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}
.cmp-combo__input {
  width: 100%;
  height: var(--cmp-ctrl-h);
  font: inherit;
  font-size: 16px; /* iOS: 16px+ prevents focus-zoom */
  padding: 0 0.7rem;
  border: 1px solid var(--cmp-line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--cmp-ink);
}
.cmp-combo__input:disabled {
  opacity: 0.55;
}
.cmp-combo__list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 30;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  max-height: 300px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--cmp-line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(15, 23, 35, 0.16);
}
.cmp-combo__list[hidden] {
  display: none;
}
.cmp-combo__opt {
  padding: 0.5rem 0.6rem;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.92rem;
  color: var(--cmp-ink);
}
.cmp-combo__opt:hover {
  background: var(--cmp-bg-alt);
}
/* :hover variant included so a keyboard-active option (dark bg, white text)
   stays readable when the pointer is also over it — otherwise .cmp-combo__opt
   :hover (higher specificity) repaints the bg light while the white text
   remains, going white-on-white. */
.cmp-combo__opt--active,
.cmp-combo__opt--active:hover {
  background: var(--cmp-brand);
  color: #fff;
}
.cmp-combo__empty {
  padding: 0.5rem 0.6rem;
  color: var(--cmp-muted);
  font-size: 0.9rem;
}

/* ── tablet / desktop ─────────────────────────────────────────────────── */
@media (min-width: 768px) {
  .cmp {
    --cmp-col-min: 128px;
    --cmp-label-w: 150px;
  }
  .cmp-cell,
  .cmp-hcell,
  .cmp-hcell--head {
    font-size: 0.95rem;
  }
  .cmp-hgrid {
    grid-template-columns:
      var(--cmp-label-w)
      minmax(104px, 0.8fr)
      minmax(150px, 1.5fr) minmax(150px, 1.5fr)
      minmax(96px, 0.7fr) minmax(96px, 0.7fr) minmax(96px, 0.7fr)
      minmax(120px, 1fr);
  }
}

/* Mobile / tablet (< 1024px): Table layout only — hide the A/B toggle and
   force Layout A, overriding any data-layout the user set on desktop before
   resizing down. Desktop (>= 1024px) keeps the toggle. */
@media (max-width: 1023px) {
  .cmp-toggle {
    display: none;
  }
  .cmp[data-layout] .cmp-view--a {
    display: block;
  }
  .cmp[data-layout] .cmp-view--b {
    display: none;
  }
}
