/* assets/css/decision-engine.css */

.engine-wizard,
.engine-results,
.engine-compare-bar,
.engine-compare-scroll {
  /* Scope base styles */
}

.engine-wizard [hidden],
.engine-results [hidden],
.engine-compare-bar[hidden] {
  display: none !important;
}

.engine-wizard {
  max-width: 48rem;
  margin-inline: auto;
}

.engine-steps {
  margin: 0;
  padding: 0;
  list-style: none;
}

.engine-step {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.engine-step:focus-visible,
.engine-step-title:focus-visible {
  outline: var(--rule-fine) solid var(--color-focus);
  outline-offset: 3px;
}

.engine-wizard fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.engine-wizard legend {
  font-weight: 700;
  margin-block-end: var(--space-sm);
  padding: 0;
}

.engine-wizard fieldset label {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: var(--space-2xs) var(--space-md);
  border: var(--rule-hair) solid var(--color-rule);
  border-radius: var(--radius-pill);
  background: var(--color-paper);
  color: var(--color-ink);
  cursor: pointer;
  transition: all var(--dur-micro) var(--ease-out);
  margin-right: var(--space-xs);
  margin-bottom: var(--space-xs);
}

.engine-wizard fieldset input[type="radio"],
.engine-wizard fieldset input[type="checkbox"] {
  width: 1.2rem;
  height: 1.2rem;
  margin-right: var(--space-xs);
  accent-color: var(--color-accent);
}

.engine-wizard fieldset label:has(input:checked) {
  border-color: var(--color-accent-strong);
  background: var(--color-paper-2);
}

.engine-wizard fieldset label:has(input:focus-visible) {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
}

.engine-progress {
  margin-block: var(--space-md);
  color: var(--color-muted);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  display: flex;
  flex-direction: column;
}

.engine-progress::after {
  content: "";
  display: block;
  height: 4px;
  background: var(--color-rule);
  border-radius: var(--radius-pill);
  margin-top: var(--space-xs);
  width: 100%;
}

.engine-nav {
  display: flex;
  gap: var(--space-md);
  margin-block-start: var(--space-lg);
  justify-content: space-between;
}

.engine-score {
  display: inline-block;
  background: var(--color-accent);
  color: var(--color-accent-ink);
  padding: var(--space-3xs) var(--space-sm);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  margin-block-end: var(--space-xs);
}

.engine-result--best .engine-score {
  background: var(--color-success);
  color: var(--color-paper);
}
.engine-result--value .engine-score {
  background: var(--color-accent-strong);
}
.engine-result--upgrade .engine-score {
  background: var(--color-ink);
}

.engine-why,
.engine-tradeoffs {
  list-style: none;
  padding: 0;
  margin-block: var(--space-sm);
  font-size: var(--text-sm);
}

.engine-why li,
.engine-tradeoffs li {
  position: relative;
  padding-inline-start: 1.5rem;
  margin-block-end: var(--space-2xs);
}

.engine-why li::before {
  content: "\2713";
  position: absolute;
  left: 0;
  color: var(--color-success);
  font-weight: bold;
}

.engine-tradeoffs li::before {
  content: "\2212";
  position: absolute;
  left: 0;
  color: var(--color-muted);
  font-weight: bold;
}

.engine-price {
  display: block;
  font-size: var(--text-lg);
  color: var(--color-ink);
  margin-block-start: var(--space-md);
}

.engine-price-note {
  font-size: var(--text-xs);
  color: var(--color-muted);
}

.engine-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  margin-block-start: var(--space-lg);
  align-items: center;
}

.engine-compare-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  cursor: pointer;
  min-height: 44px;
}

.engine-compare-toggle:focus-within {
  outline: var(--rule-fine) solid var(--color-focus);
  outline-offset: 3px;
  border-radius: var(--radius-input);
}

.engine-vessel,
.engine-result-label {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-accent-strong);
  margin-block-end: var(--space-xs);
}

.engine-compare-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-sticky);
  background: var(--color-surface);
  color: var(--color-ink);
  border-block-start: var(--rule-fine) solid var(--color-accent);
  padding: var(--space-md);
  padding-right: 5rem;
  box-shadow: var(--shadow-sticky);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.engine-compare-count {
  font-weight: 700;
  font-size: var(--text-sm);
}

.engine-compare-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: var(--text-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
}

.engine-compare-list li {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.engine-compare-message {
  font-weight: 700;
  color: var(--color-error);
}

.engine-compare-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-block: var(--space-xl);
}

.engine-compare-table {
  width: 100%;
  min-width: 48rem;
  border-collapse: collapse;
  text-align: left;
}

.engine-compare-table th,
.engine-compare-table td {
  padding: var(--space-sm) var(--space-md);
  border-block-end: var(--rule-hair) solid var(--color-rule);
}

.engine-compare-table th[scope="row"] {
  position: sticky;
  left: 0;
  background: var(--color-paper);
  z-index: 2;
  box-shadow: 2px 0 4px -2px rgba(0,0,0,0.3);
}

.engine-compare-table thead th {
  background: var(--color-surface);
  font-weight: 700;
}

.engine-derived {
  cursor: help;
  color: var(--color-accent);
  font-weight: bold;
  font-size: 1.2em;
  vertical-align: super;
  line-height: 0;
}

@media (min-width: 48rem) {
  .engine-compare-bar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding-right: var(--space-md);
  }
  
  .engine-compare-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--space-md);
  }
  
  .engine-compare-list li::after {
    content: "•";
    margin-left: var(--space-md);
    color: var(--color-rule);
  }
  
  .engine-compare-list li:last-child::after {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .engine-wizard fieldset label {
    transition: none !important;
  }
}

/* ------------------------------------------------------------------
   Density
   ------------------------------------------------------------------
   A shortlist is only useful if you can read it. These rules exist
   because the first mobile build ran to seven screens: the site card
   is built for a picture, a title and a paragraph, while a result card
   carries a score, reasons, trade-offs, a price and three actions.
   ------------------------------------------------------------------ */

/* The shared card body declares five grid rows, one of them 1fr, and
   stretches to full height. A result card has eight children, so that
   1fr row absorbed ~250px of empty space per card. Pack the rows
   instead and let the card be as tall as its content. */
.engine-result {
  height: auto;
}

.engine-result > div {
  grid-template-rows: none;
  grid-auto-rows: min-content;
  align-content: start;
}

.engine-why,
.engine-tradeoffs {
  line-height: 1.5;
}

.engine-result-actions > a {
  white-space: nowrap;
}

@media (max-width: 47.99rem) {
  /* A finder page is a task, not a brochure. The hero must not spend a
     whole screen before the first question. */
  .hero:has(+ .engine-wizard-section) .hero-picture,
  .hero:has(+ .engine-compare-prompt) .hero-picture,
  .hero:has(+ .engine-compare-intro) .hero-picture,
  .hero:has(+ .engine-results) .hero-picture,
  .hero:has(+ .engine-compare-scroll) .hero-picture {
    aspect-ratio: 21 / 9;
  }

  .hero:has(+ .engine-wizard-section) .hero-copy,
  .hero:has(+ .engine-compare-prompt) .hero-copy,
  .hero:has(+ .engine-compare-intro) .hero-copy,
  .hero:has(+ .engine-results) .hero-copy,
  .hero:has(+ .engine-compare-scroll) .hero-copy {
    gap: var(--space-xs);
    padding-block: var(--space-lg) var(--space-lg);
  }

  .hero:has(+ .engine-wizard-section) .hero-copy > p,
  .hero:has(+ .engine-results) .hero-copy > p {
    font-size: var(--text-sm);
  }

  /* On a results page the hero is already-read decoration standing between the
     traveller and the answer they asked for. */
  .hero:has(+ .engine-results) .hero-copy > h1 {
    font-size: var(--text-2xl);
  }

  .hero:has(+ .engine-results) .hero-copy > p,
  .hero:has(+ .engine-results) .hero-copy > a {
    display: none;
  }

  /* Result cards: three of these have to fit in a couple of thumb
     scrolls, or the shortlist stops being a shortlist. */
  .engine-result .card-media {
    aspect-ratio: 3 / 1;
  }

  .engine-result h3 {
    font-size: var(--text-md);
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }

  .engine-why,
  .engine-tradeoffs {
    font-size: var(--text-xs);
    line-height: 1.4;
    margin-block: var(--space-xs);
  }

  .engine-why li,
  .engine-tradeoffs li {
    padding-inline-start: 1.15rem;
    margin-block-end: var(--space-3xs);
  }

  .engine-price {
    font-size: var(--text-md);
    margin-block-start: var(--space-xs);
  }

  .engine-price-note {
    margin-block: var(--space-3xs) 0;
  }

  .engine-result-actions {
    gap: var(--space-xs);
    margin-block-start: var(--space-sm);
  }

  /* The wizard's option chips are the other half of the length problem. */
  .engine-wizard fieldset label {
    padding-block: var(--space-3xs);
    padding-inline: var(--space-sm);
    margin-right: var(--space-2xs);
    margin-bottom: var(--space-2xs);
    font-size: var(--text-sm);
  }

  .engine-step {
    gap: var(--space-sm);
  }

  .engine-progress {
    margin-block: var(--space-sm);
  }
}

/* The floating WhatsApp button and the compare bar share a z-index and
   the same corner. Lift the button while the bar is open rather than
   letting one cover the other. */
body:has(.engine-compare-bar:not([hidden])) .wa {
  inset-block-end: calc(var(--space-md) + 5.5rem);
}

/* The option groups were laid out as a flex column, so thirteen "how many
   days" chips stacked into 975px for a single step. They are chips: they
   should wrap. The legend is forced onto its own line so it still reads as
   the group's heading. */
.engine-wizard fieldset {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
}

.engine-wizard legend,
.engine-wizard fieldset > label[for] {
  flex: 0 0 100%;
}

.engine-wizard fieldset > label:has(input[type="radio"]),
.engine-wizard fieldset > label:has(input[type="checkbox"]) {
  flex: 0 0 auto;
}

.engine-wizard fieldset input[type="number"],
.engine-wizard fieldset select {
  min-height: 44px;
  padding: var(--space-xs) var(--space-sm);
  border: var(--rule-hair) solid var(--color-rule);
  border-radius: var(--radius-input);
  background: var(--color-paper);
  color: var(--color-ink);
  font: inherit;
  max-width: 100%;
}

/* An empty trade-offs list must not still cost a grid gap. */
.engine-why:empty,
.engine-tradeoffs:empty {
  display: none;
}

@media (max-width: 47.99rem) {
  .engine-result > div {
    gap: var(--space-xs);
    padding: var(--space-md);
  }

  .engine-result-actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: var(--space-xs);
  }

  .engine-result-actions > a[data-engine-customize] {
    grid-column: 1 / -1;
    justify-content: center;
  }

  .engine-wizard-section > .head,
  .engine-results > .head {
    margin-block-end: var(--space-sm);
  }

  .engine-wizard-section > .head > p,
  .engine-results > .head > p {
    font-size: var(--text-sm);
  }
}

/* "Refine your answers" — the wizard after it has been used once. Native
   <details>, so it works with no JavaScript and announces itself correctly. */
.engine-refine > summary {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  min-height: 44px;
  padding: var(--space-sm) var(--space-md);
  border: var(--rule-hair) solid var(--color-rule);
  border-radius: var(--radius-input);
  background: var(--color-paper-2);
  color: var(--color-ink);
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.engine-refine > summary::-webkit-details-marker {
  display: none;
}

.engine-refine > summary::after {
  content: "\25BE";
  margin-inline-start: auto;
  color: var(--color-accent);
}

.engine-refine[open] > summary::after {
  content: "\25B4";
}

.engine-refine > summary:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
}

.engine-refine .engine-wizard-section {
  padding-inline: 0;
}

.engine-refine-section {
  padding-block: var(--space-lg);
}
