/*
 * Compare: the control on each card, and the tray it feeds.
 *
 * Colours come from the app's tokens so dark mode follows via light-dark(),
 * and every text pairing here clears WCAG AA. #5f6b7a on white is ~5.4:1 —
 * the same value .flight-detail-label uses, and for the same reason: the
 * shared .color-text-gray is ~2:1 and fails.
 */

/* ── Card control ─────────────────────────────────────────────────────────── */

.compare-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  line-height: 1.2;
}

.compare-toggle__add {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  /* 6px vertical padding on a 13px line clears the 24px pointer-target
     minimum without turning a text link into a button-sized block. */
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--color-first);
  font-weight: 600;
  cursor: pointer;
}

.compare-toggle__add:hover:not(.is-blocked) {
  text-decoration: underline;
}

.compare-toggle__add:focus-visible,
.compare-toggle__remove:focus-visible {
  outline: 2px solid var(--color-first);
  outline-offset: 2px;
  border-radius: 4px;
}

/*
 * Blocked, not `disabled` — see CompareToggle for why it stays focusable.
 * Opacity alone would leave it looking merely faint, so the cursor says
 * "not this" too.
 */
.compare-toggle__add.is-blocked {
  opacity: 0.45;
  cursor: not-allowed;
}

.compare-toggle--added {
  padding: 4px 8px 4px 10px;
  border: 1px solid var(--color-blue-light2, #d6e2e8);
  border-radius: 999px;
  background: var(--color-blue-light, #eef4f7);
  color: var(--color-first);
  font-weight: 600;
}

.compare-toggle__tick {
  flex-shrink: 0;
}

.compare-toggle__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* 24x24 target from a 14px glyph, pulled back so it does not stretch the pill. */
  width: 24px;
  height: 24px;
  margin: -5px -4px -5px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
  cursor: pointer;
}

.compare-toggle__remove:hover {
  background: rgb(0 0 0 / 6%);
}

/*
 * The reason the control declined.
 *
 * Present in the DOM whenever it applies so screen readers reach it through
 * aria-describedby; revealed visually on hover or keyboard focus. A `title`
 * would have been neither — touch has no hover, and titles are unreliable
 * to assistive tech.
 */
.compare-toggle__hint {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  z-index: 5;
  width: max-content;
  max-width: min(15rem, calc(100vw - 2rem));
  padding: 6px 9px;
  border: 1px solid var(--color-blue-light2, #d6e2e8);
  border-radius: 6px;
  background: var(--color-white, #fff);
  box-shadow: 0 4px 14px rgb(0 0 0 / 14%);
  color: #5f6b7a;
  font-size: 0.6875rem;
  font-weight: 400;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.compare-toggle:hover .compare-toggle__hint,
.compare-toggle__add:focus-visible ~ .compare-toggle__hint {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .compare-toggle__hint {
    transition: none;
  }
}

/* The row the control sits on: its own line under the card's main content. */
.flight-card-compare-row {
  display: flex;
  align-items: center;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--color-blue-light2, #eef1f4);
}

/* ── Tray ─────────────────────────────────────────────────────────────────── */

/*
 * Docked bottom-right on a pointer device; a full-width bar pinned to the
 * bottom on a phone, where there is no spare corner and the thumb is already
 * down there.
 *
 * z-index sits under the round-trip sticky bar's own layer so the two cannot
 * fight for the same corner — see .round-trip-sticky-bar.
 */
.compare-tray {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1035;
  display: flex;
  flex-direction: column;
  /* Two plain declarations rather than `min(23rem, calc(100vw - 32px))`:
     the nested calc survived authoring but not minification, and a browser
     that drops the declaration leaves the tray at full page width. */
  width: 23rem;
  max-width: calc(100vw - 32px);
  max-height: min(70vh, 32rem);
  border: 1px solid var(--color-blue-light2, #d6e2e8);
  border-radius: 12px;
  background: var(--color-white, #fff);
  box-shadow: 0 10px 30px rgb(0 0 0 / 18%);
  overflow: hidden;
}

.compare-tray__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: var(--color-first);
  color: var(--color-white, #fff);
}

.compare-tray__title {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
}

.compare-tray__minimise,
.compare-tray__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}

/*
 * White on the teal header, stated rather than inherited.
 *
 * `color: inherit` is only as reliable as whatever the cascade hands the
 * header, and a global rule reaching a bare <button> is enough to make this
 * glyph vanish into its own background — which is what happened.
 */
.compare-tray__minimise {
  color: #fff;
  opacity: 0.92;
}

.compare-tray__minimise:hover {
  background: rgb(255 255 255 / 22%);
  opacity: 1;
}

.compare-tray__remove {
  color: #5f6b7a;
}

.compare-tray__remove {
  flex-shrink: 0;
}

.compare-tray__remove:hover {
  background: rgb(0 0 0 / 6%);
}

.compare-tray__minimise:focus-visible,
.compare-tray__remove:focus-visible,
.compare-tray__clear:focus-visible,
.compare-tray__compare:focus-visible,
.compare-tray__pill-btn:focus-visible {
  outline: 2px solid var(--color-first);
  outline-offset: 2px;
}

.compare-tray__minimise:focus-visible {
  outline-color: var(--color-white, #fff);
}

.compare-tray__list {
  flex: 1 1 auto;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
}

.compare-tray__row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-blue-light2, #eef1f4);
}

.compare-tray__logo {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  object-fit: contain;
}

/* min-width:0 is what lets the airline name actually truncate: without it a
   flex child refuses to shrink below its content. */
.compare-tray__detail {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1 1 auto;
}

.compare-tray__airline {
  overflow: hidden;
  color: var(--color-dark, #333);
  font-size: 0.75rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compare-tray__times {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--color-dark, #333);
  font-size: 0.8125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.compare-tray__nextday {
  color: var(--color-second);
  font-size: 0.625rem;
  font-weight: 600;
}

.compare-tray__meta {
  color: #5f6b7a;
  font-size: 0.6875rem;
}

.compare-tray__price {
  flex-shrink: 0;
  color: var(--color-dark, #333);
  font-size: 0.8125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* The mini route line: a rule with a dot per stop sitting on it. */
.compare-tray__routeline {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 8px;
}

.compare-tray__routeline-track {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
  background: #c3ccd6;
}

.compare-tray__routeline-stop {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--color-second);
  transform: translate(-50%, -50%);
}

.compare-tray__routeline-stop:nth-child(3) {
  left: 70%;
}

.compare-tray__slot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  color: #5f6b7a;
  font-size: 0.75rem;
}

.compare-tray__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--color-blue-light2, #eef1f4);
  /* Stated, not inherited: this strip previously took its background from the
     global <footer> rule and its text disappeared into it. */
  background: var(--color-white, #fff);
  color: var(--color-dark, #333);
}

.compare-tray__clear {
  padding: 8px 6px;
  border: 0;
  background: none;
  /* 5.4:1 on white. */
  color: #5f6b7a;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.compare-tray__clear:hover {
  text-decoration: underline;
}

.compare-tray__cta {
  position: relative;
}

.compare-tray__compare {
  padding: 9px 18px;
  border: 0;
  border-radius: 8px;
  background: var(--color-second);
  /* The site's own white token, so a global <footer> colour cannot claim it. */
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.compare-tray__compare[aria-disabled='true'] {
  opacity: 0.5;
  cursor: not-allowed;
}

.compare-tray__hint {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  width: max-content;
  max-width: 13rem;
  padding: 6px 9px;
  border: 1px solid var(--color-blue-light2, #d6e2e8);
  border-radius: 6px;
  background: var(--color-white, #fff);
  box-shadow: 0 4px 14px rgb(0 0 0 / 14%);
  color: #5f6b7a;
  font-size: 0.6875rem;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.compare-tray__cta:hover .compare-tray__hint,
.compare-tray__compare:focus-visible ~ .compare-tray__hint {
  opacity: 1;
}

/* Minimised: a pill in the same corner, so the tray never fully disappears. */
.compare-tray--pill {
  width: auto;
  max-height: none;
  border: 0;
  background: none;
  box-shadow: none;
}

.compare-tray__pill-btn {
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--color-first);
  color: var(--color-white, #fff);
  font-size: 0.8125rem;
  font-weight: 600;
  box-shadow: 0 6px 20px rgb(0 0 0 / 22%);
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .compare-tray__hint {
    transition: none;
  }
}

/*
 * Phone: a full-width bar along the bottom edge rather than a floating corner.
 * The list is capped so the tray can never grow over the results it is meant
 * to help choose between.
 */
@media (max-width: 767.98px) {
  /* Edge to edge apart from a gap each side, so the tray reads as a sheet
     over the results rather than a panel welded to the screen — and the
     results stay visible down both margins. */
  .compare-tray {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    width: auto;
    max-width: none;
    max-height: 60vh;
    border-radius: 12px;
  }

  .compare-tray--pill {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    left: auto;
    width: auto;
    border-radius: 999px;
    padding-bottom: 0;
  }
}

/*
 * Round trip: the pair bar already owns the bottom edge.
 *
 * Both are fixed and both want the same corner, so the tray is lifted clear of
 * it rather than layered over it — a traveller mid-comparison still needs to
 * see the outbound they have chosen and the Continue button that acts on it.
 */
/* `:has` rather than a sibling combinator: the tray renders before the pair
   bar in the DOM, so `.round-trip-sticky-bar ~ .compare-tray` could never
   match, and a rule that silently does nothing is worse than no rule. */
body:has(.round-trip-sticky-bar.show) .compare-tray {
  bottom: 124px;
}

@media (max-width: 767.98px) {
  body:has(.round-trip-sticky-bar.show) .compare-tray {
    bottom: 150px;
  }

  body:has(.round-trip-sticky-bar.show) .compare-tray--pill {
    bottom: calc(150px + env(safe-area-inset-bottom, 0px));
  }
}
