/* ============================================================
   BLUE — Mattress Selector page
   ONE page, FOUR ways to choose: Guided · Filters · Swipe ·
   Compare. Calm & decluttered — hairlines, paper cards,
   generous whitespace, no ornaments. EN (Poppins) + AR (Cairo,
   RTL) aware: logical properties throughout. Requires main.css
   tokens. finder.css is NOT loaded here, so the shared wizard /
   result / compare primitives live in this file too.
   ============================================================ */

/* ---------------------------------------------- page top: hero + switch */
.sel-top { padding-block: clamp(52px, 7vw, 92px) 0; }
.sel-hero {
  max-width: 660px; margin-inline: auto;
  display: grid; gap: 16px; justify-items: center; text-align: center;
}
.sel-hero .lead { max-width: 520px; }

.mode-switch {
  display: flex; gap: 4px;
  width: max-content; max-width: 100%;
  margin: clamp(28px, 4.5vw, 46px) auto 0;
  padding: 4px;
  background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--r-pill);
}
.sel-switch { flex-wrap: wrap; justify-content: center; }
.seg-btn {
  border: 0; background: none; border-radius: var(--r-pill);
  padding: 11px 22px;
  font-size: var(--text-sm); font-weight: 600; color: var(--ink-soft);
  transition: background .25s, color .25s;
  white-space: nowrap;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-on { background: var(--navy); color: #fff; }
.seg-btn:focus-visible { outline: 2px solid var(--royal); outline-offset: 2px; }

.sel-note {
  max-width: 560px; margin: 16px auto 0; text-align: center;
  font-size: var(--text-sm); color: var(--ink-soft);
}

/* ---------------------------------------------- panes */
.sel-pane { padding-block: clamp(40px, 6vw, 72px) var(--sect-pad); }

/* gentle step / result / card entrance */
.enter { animation: selIn .45s var(--ease-out); }
@keyframes selIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

/* shared toggle chip (filters + compare highlight) */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn {
  border: 1px solid var(--line); background: var(--paper);
  border-radius: var(--r-pill); padding: 9px 16px;
  font-size: var(--text-sm); font-weight: 600; color: var(--ink);
  transition: background .2s, color .2s, border-color .2s, transform .2s var(--ease-out);
}
.chip-btn:hover { border-color: var(--royal); transform: translateY(-1px); }
.chip-btn[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.chip-btn:focus-visible { outline: 2px solid var(--royal); outline-offset: 2px; }

/* ============================================================
   MODE 1 — GUIDED WIZARD
   ============================================================ */
.wiz { max-width: 720px; margin-inline: auto; }
.wiz-bar { height: 3px; border-radius: 3px; background: var(--powder); overflow: hidden; }
.wiz-fill { display: block; height: 100%; width: 0; background: var(--royal); border-radius: 3px; transition: width .5s var(--ease-out); }

.wiz-step { padding-top: clamp(30px, 4.5vw, 46px); }
.wiz-progtext {
  font-size: var(--text-xs); font-weight: 700;
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-soft); margin-bottom: 14px;
}
.wiz-q { font-size: var(--text-xl); margin-bottom: clamp(24px, 3.5vw, 36px); outline: none; }

.wiz-opts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.wiz-opts.cols-3 { grid-template-columns: repeat(3, 1fr); }
.wiz-opt {
  display: grid; gap: 12px; justify-items: center; align-content: center;
  min-height: 130px; padding: 24px 14px;
  background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--r-md);
  font-size: var(--text-md); font-weight: 600; color: var(--ink);
  text-align: center; line-height: 1.4;
  transition: border-color .25s, transform .3s var(--ease-out), box-shadow .3s var(--ease-out);
}
.wiz-opt:hover { border-color: var(--royal); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.wiz-opt:focus-visible { outline: 2px solid var(--royal); outline-offset: 2px; }
.wiz-opt.is-on { border-color: var(--royal); box-shadow: inset 0 0 0 1px var(--royal); }
.wiz-ico { display: inline-flex; color: var(--royal); }
.wiz-ico svg { width: 34px; height: 34px; }

.wiz-nav { margin-top: 24px; }
.wiz-back {
  border: 0; background: none; padding: 8px 0;
  font-size: var(--text-sm); font-weight: 600; color: var(--ink-soft);
  transition: color .2s;
}
.wiz-back:hover { color: var(--ink); }
.wiz-back:focus-visible { outline: 2px solid var(--royal); outline-offset: 2px; border-radius: var(--r-xs); }

/* ============================================================
   SHARED RESULT (guided + swipe)
   ============================================================ */
.res { max-width: 860px; margin-inline: auto; }
.res-note { text-align: center; font-size: var(--text-sm); color: var(--ink-soft); margin-bottom: 20px; }
.res-hero {
  display: grid; grid-template-columns: 1fr 1.1fr; align-items: center;
  gap: clamp(24px, 4vw, 44px);
  background: var(--paper);
  border: 1px solid var(--line-soft); border-radius: var(--r-lg);
  padding: clamp(20px, 3vw, 34px);
}
.res-media img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--r-md); background: var(--powder-2); }
.res-body { display: grid; gap: 12px; justify-items: start; }
.res-body .h2 { font-size: var(--text-2xl); }
.res-kind { font-size: var(--text-sm); color: var(--ink-soft); }
.res-why { display: grid; gap: 10px; margin-top: 2px; }
.res-why li { display: flex; gap: 10px; font-size: var(--text-sm); color: var(--ink-soft); line-height: 1.55; }
.res-why svg { width: 16px; height: 16px; color: var(--royal); flex: none; margin-top: 3px; }
.res-price { font-size: var(--text-lg); font-weight: 700; }
.res-price .from-lab { display: block; font-size: var(--text-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); }
.res-ctas { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }

.res-sub { font-family: var(--font-display); font-weight: 600; font-size: var(--text-lg); margin: clamp(32px, 5vw, 48px) 0 16px; }
.res-rgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.res-rcard {
  display: flex; align-items: center; gap: 14px;
  background: var(--paper);
  border: 1px solid var(--line-soft); border-radius: var(--r-md); padding: 12px;
  transition: transform .3s var(--ease-out), box-shadow .3s var(--ease-out);
}
.res-rcard:hover { transform: translateY(-3px); box-shadow: var(--shadow-sm); }
.res-rcard:focus-visible { outline: 2px solid var(--royal); outline-offset: 2px; }
.res-rcard img { width: 88px; height: 66px; object-fit: cover; flex: none; border-radius: var(--r-sm); background: var(--powder-2); }
.res-rbody { display: grid; gap: 2px; min-width: 0; }
.res-rbody b { font-family: var(--font-display); font-weight: 600; }
.res-rmeta { font-size: var(--text-xs); color: var(--ink-soft); }
.res-rpct {
  margin-inline-start: auto; flex: none;
  font-size: var(--text-2xs); font-weight: 700; letter-spacing: .04em;
  color: var(--royal-deep); background: var(--powder-2);
  border-radius: var(--r-pill); padding: 5px 11px;
}
.res-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; margin-top: clamp(30px, 4vw, 44px); }
.res-cmplink {
  border: 0; background: none; padding: 8px 0;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--text-sm); font-weight: 700; color: var(--royal);
}
.res-cmplink:hover { text-decoration: underline; }
.res-cmplink:focus-visible { outline: 2px solid var(--royal); outline-offset: 2px; border-radius: var(--r-xs); }

/* ============================================================
   MODE 2 — SMART FILTERS
   ============================================================ */
.flt-mount { display: grid; grid-template-columns: minmax(260px, 320px) 1fr; gap: clamp(20px, 3vw, 40px); align-items: start; }
.flt-panel {
  display: grid; gap: 22px;
  background: var(--paper); border: 1px solid var(--line-soft); border-radius: var(--r-lg);
  padding: clamp(20px, 2.4vw, 28px);
  position: sticky; top: calc(var(--header-h) + 14px);
}
.flt-ctrl { display: grid; gap: 12px; }
.flt-ctrl-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.flt-lab { font-size: var(--text-xs); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); }
.flt-read { font-size: var(--text-sm); font-weight: 700; color: var(--royal-deep); }

.flt-ctrl input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; background: transparent; cursor: pointer;
  accent-color: var(--royal);
}
/* track + thumb fallback for engines that ignore accent-color on range */
.flt-ctrl input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 3px; background: var(--powder); }
.flt-ctrl input[type="range"]::-moz-range-track { height: 4px; border-radius: 3px; background: var(--powder); }
.flt-ctrl input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; margin-top: -7px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--royal); border: 3px solid var(--paper); box-shadow: var(--shadow-sm);
}
.flt-ctrl input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--royal); border: 3px solid var(--paper); box-shadow: var(--shadow-sm);
}
.flt-ctrl input[type="range"]:focus-visible { outline: none; }
.flt-ctrl input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(var(--royal-rgb), .25); }
.flt-ctrl input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px rgba(var(--royal-rgb), .25); }
.flt-scale { display: flex; justify-content: space-between; font-size: var(--text-2xs); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); }

.flt-reset {
  justify-self: start; border: 0; background: none; padding: 6px 0;
  font-size: var(--text-sm); font-weight: 700; color: var(--royal);
}
.flt-reset:hover { text-decoration: underline; }
.flt-reset:focus-visible { outline: 2px solid var(--royal); outline-offset: 2px; border-radius: var(--r-xs); }

.flt-count { font-size: var(--text-xs); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 16px; }
.flt-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }

.fcard { display: flex; flex-direction: column; background: var(--paper); border: 1px solid var(--line-soft); border-radius: var(--r-md); overflow: hidden; }
.fcard-media { position: relative; aspect-ratio: 16 / 10; background: var(--powder-2); }
.fcard-media img { width: 100%; height: 100%; object-fit: cover; }
.fcard-badge { position: absolute; top: 12px; inset-inline-start: 12px; }
.fcard-body { display: grid; gap: 12px; padding: 16px 18px 18px; }
.fcard-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.fcard-titles { display: grid; gap: 3px; min-width: 0; }
.fcard-kind { font-size: var(--text-2xs); font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-soft); }
.fcard-name { font-family: var(--font-display); font-weight: 600; font-size: 1.24rem; line-height: 1.2; }
.fcard-why { font-size: var(--text-sm); color: var(--ink-soft); line-height: 1.5; min-height: 2.9em; }
.fcard-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.fcard-price { font-weight: 700; font-size: var(--text-sm); }
.fcard-price .from { display: block; font-size: var(--text-2xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); }
.fcard-ctas { display: inline-flex; gap: 8px; }
.fcard .feel { margin-top: -2px; }

/* match ring */
.ring { position: relative; flex: none; width: 50px; height: 50px; display: inline-grid; place-items: center; }
.ring svg { width: 50px; height: 50px; transform: rotate(-90deg); }
.ring .ring-bg { stroke: var(--powder); }
.ring .ring-fg { stroke: var(--royal); transition: stroke-dasharray .4s var(--ease-out); }
.ring-num { position: absolute; font-size: .72rem; font-weight: 700; color: var(--royal-deep); letter-spacing: -.02em; }
.ring-num i { font-style: normal; font-size: .5rem; margin-inline-start: .5px; }

/* ============================================================
   MODE 3 — SWIPE / THIS-OR-THAT
   ============================================================ */
.swipe-stage { display: flex; justify-content: center; }
.swipe-deck { position: relative; width: min(560px, 100%); min-height: 350px; margin-inline: auto; }
.swipe-card {
  position: absolute; inset: 0;
  display: grid; gap: clamp(20px, 3vw, 30px); align-content: center;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); padding: clamp(24px, 4vw, 40px);
  text-align: center; will-change: transform;
}
.swipe-card.is-top { z-index: 3; box-shadow: var(--shadow-md); transition: transform .25s var(--ease-out); }
.swipe-card[data-depth="1"] { z-index: 2; transform: translateY(14px) scale(.955); opacity: .7; }
.swipe-card[data-depth="2"] { z-index: 1; transform: translateY(28px) scale(.91); opacity: .4; }
.swipe-card.is-top { cursor: grab; touch-action: pan-y; }
.swipe-card.dragging { cursor: grabbing; transition: none; }
.swipe-card.flying { transition: transform .42s var(--ease-out), opacity .42s var(--ease-out); opacity: 0; }
.swipe-card:focus-visible { outline: 2px solid var(--royal); outline-offset: 3px; }

.swipe-q { font-family: var(--font-display); font-weight: 600; font-size: var(--text-lg); }
html[lang="ar"] .swipe-q { font-weight: 700; }
.swipe-choices { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: center; }
.swipe-choice {
  display: grid; gap: 12px; justify-items: center; align-content: center;
  min-height: 148px; padding: 22px 14px;
  background: var(--canvas); border: 1px solid var(--line); border-radius: var(--r-md);
  font-size: var(--text-md); font-weight: 600; color: var(--ink); line-height: 1.35;
  transition: border-color .2s, transform .25s var(--ease-out), box-shadow .25s var(--ease-out), background .2s;
}
.swipe-choice:hover { border-color: var(--royal); background: var(--paper); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.swipe-choice:focus-visible { outline: 2px solid var(--royal); outline-offset: 2px; }
.swipe-ic { display: inline-flex; color: var(--royal); }
.swipe-ic svg { width: 36px; height: 36px; }
.swipe-or { font-size: var(--text-xs); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); }

.swipe-prog { display: grid; justify-items: center; gap: 10px; margin-top: clamp(24px, 4vw, 40px); text-align: center; }
.swipe-count { font-size: var(--text-xs); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); }
.swipe-dots { display: inline-flex; gap: 7px; }
.swipe-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--powder); transition: background .3s, transform .3s; }
.swipe-dots i.done { background: var(--royal); }
.swipe-dots i.now { background: var(--royal); transform: scale(1.35); }
.swipe-hint { font-size: var(--text-xs); color: var(--ink-soft); }

/* ============================================================
   MODE 4 — COMPARE MATRIX
   ============================================================ */
.cmp-hl { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: clamp(22px, 3vw, 34px); }
.hl-title { font-size: var(--text-xs); font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-soft); }
.hl-callout {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(var(--royal-rgb), .09); color: var(--royal-deep);
  border-radius: var(--r-pill); padding: 8px 16px;
  font-size: var(--text-sm); font-weight: 700;
  width: 100%; justify-content: flex-start;
}
.hl-callout svg { width: 16px; height: 16px; flex: none; }

/* --cmp-cols is set by selector.js from MATTS.length — hardcoding 6 here meant
   the 7th and 8th mattress wrapped onto a second row and broke the whole table. */
.cmp-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.cmp-grid {
  display: grid;
  grid-template-columns: 118px repeat(var(--cmp-cols, 8), minmax(112px, 1fr));
  min-width: 100%;   /* NB: never width:max-content here — 1fr resolves against
                        content inside it and each column explodes to ~2200px */
  border-top: 1px solid var(--line-soft);
}
.cmp-cell {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  gap: 6px; padding: 18px 12px;
  border-bottom: 1px solid var(--line-soft);
  font-size: var(--text-sm); color: var(--ink);
  transition: background .2s;
}
.cmp-cell.hl { background: var(--powder-2); }
.cmp-cell.row-hl { background: rgba(var(--royal-rgb), .06); }
.cmp-cell.is-match { background: rgba(var(--royal-rgb), .05); }
.cmp-cell.col-best { background: rgba(var(--royal-rgb), .09); }
.cmp-cell.is-match.hl, .cmp-cell.col-best.hl { background: rgba(var(--royal-rgb), .13); }
.cmp-lab { font-size: var(--text-2xs); font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-soft); }
.cmp-head {
  position: sticky; top: var(--header-h); z-index: 4;
  background: var(--canvas); border-bottom: 1px solid var(--line);
  padding-block: 16px; justify-content: flex-start;
}
.cmp-head.is-match { background: #EFF3FB; }
.cmp-head.col-best { background: #E7EEFB; }
.cmp-head img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--r-sm); background: var(--powder-2); }
.cmp-name { font-family: var(--font-display); font-weight: 600; font-size: .98rem; line-height: 1.25; }
.cmp-name a:hover { color: var(--royal); }
.cmp-from { font-size: var(--text-xs); color: var(--ink-soft); }
.cmp-cta { font-size: var(--text-xs); font-weight: 700; color: var(--royal); display: inline-flex; align-items: center; gap: 4px; }
.cmp-cta:hover { text-decoration: underline; }
.cmp-chip { font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: #fff; background: var(--royal); border-radius: var(--r-pill); padding: 3px 10px; }
.cmp-feellab { font-size: var(--text-xs); color: var(--ink-soft); }
.cmp-cell .feel-track, .cmp-cell .feel-labels { width: 100%; max-width: 120px; }
.cmp-price { font-weight: 700; }

.dots { display: inline-flex; gap: 5px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--powder); }
.dots i.on { background: var(--royal); }

/* compare cards (mobile) */
.cmp-cards {
  display: flex; gap: 14px;
  overflow-x: auto; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
  margin-inline: calc(-1 * var(--gutter)); padding: 4px var(--gutter) 20px;
}
.cmp-card { flex: 0 0 min(320px, 84vw); scroll-snap-align: center; background: var(--paper); border: 1px solid var(--line-soft); border-radius: var(--r-md); overflow: hidden; }
.cmp-card.is-match { border-color: var(--royal); }
.cmp-card.col-best { border-color: var(--royal); box-shadow: 0 0 0 1px var(--royal); }
.cmp-card > img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--powder-2); }
.cmp-card-head { display: grid; gap: 5px; justify-items: start; padding: 14px 16px 13px; }
.cmp-card-head .cmp-name { font-size: 1.08rem; }
.cmp-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 16px; border-top: 1px solid var(--line-soft); font-size: var(--text-sm); transition: background .2s; }
.cmp-row.row-hl { background: rgba(var(--royal-rgb), .06); }
.cmp-row .k { flex: none; font-size: var(--text-2xs); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); }
.cmp-row .v { text-align: end; display: inline-flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.cmp-card-cta { padding: 14px 16px 16px; border-top: 1px solid var(--line-soft); }
.cmp-card-cta .btn { width: 100%; justify-content: center; }

/* ---------------------------------------------- responsive */
@media (min-width: 960px) { .cmp-cards { display: none; } }
@media (max-width: 959.98px) { .cmp-grid { display: none; } }
@media (max-width: 880px) {
  .flt-mount { grid-template-columns: 1fr; }
  .flt-panel { position: static; }
}
@media (max-width: 760px) {
  .res-hero { grid-template-columns: 1fr; }
  .res-rgrid { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .sel-switch { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
  .seg-btn { padding: 11px 14px; text-align: center; }
}
@media (max-width: 560px) {
  .wiz-opts, .wiz-opts.cols-3 { grid-template-columns: 1fr 1fr; }
  .wiz-opts.cols-3 .wiz-opt:last-child:nth-child(3) { grid-column: 1 / -1; }
  .wiz-opt { min-height: 116px; padding: 18px 10px; font-size: var(--text-sm); }
  .wiz-ico svg { width: 30px; height: 30px; }
  .res-ctas .btn { width: 100%; justify-content: center; }
  .swipe-choices { grid-template-columns: 1fr; }
  .swipe-or { display: none; }
  .swipe-choice { min-height: 96px; padding: 16px; flex-direction: row; }
  .swipe-choice { display: flex; align-items: center; gap: 14px; justify-content: center; }
  .swipe-ic svg { width: 28px; height: 28px; }
  .fcard-ctas { width: 100%; }
  .fcard-ctas .btn { flex: 1; justify-content: center; }
}
@media (max-width: 380px) {
  .sel-switch { grid-template-columns: 1fr; }
}

/* ---------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  .enter { animation: none; }
  .wiz-fill, .ring .ring-fg { transition: none; }
  .wiz-opt, .res-rcard, .chip-btn, .swipe-choice, .swipe-card, .swipe-card.is-top { transition: none; }
  .swipe-dots i { transition: none; }
}
