/* Car page (src/car.js, public/js/car.js), on car pages only. Shared pieces stay in site.css: .crumbs, .studio, .band,
   .badge, .price, .tabs, .ccard. One moving thing per screen: the photo stage, the 360° view or the story — never two. */

/* ---------- top: the name and the price, the photos under them ---------- */
.car-top { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "title buy" "media media" "facts facts"; align-items: end; gap: 16px 32px; padding-top: 8px; }
.car-top__title { grid-area: title; min-width: 0; }
.car-top__badges { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.car-top__name { margin-top: 10px; font-size: clamp(34px, 5vw, 64px); font-weight: 700; line-height: 1.02; letter-spacing: -0.02em; text-transform: uppercase; overflow-wrap: anywhere; }
.car-top__trim { margin-top: 6px; color: var(--muted); }
.car-top__buy { grid-area: buy; display: grid; justify-items: end; gap: 4px; text-align: right; }
.car-top__price { display: grid; justify-items: end; }
.car-top__price .price { font-size: clamp(26px, 2.6vw, 34px); line-height: 1.2; }
.car-top__incl { color: var(--muted); font-size: 13px; font-weight: 500; text-underline-offset: 3px; }
.car-top__incl:hover { color: var(--ink); }
.car-top__cta { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 10px; }
.car-top__media { grid-area: media; min-width: 0; }
.car-top > .highlights { grid-area: facts; }
.uah { display: block; min-height: 1.5em; color: var(--muted); font-size: 15px; font-weight: 600; white-space: nowrap; } /* filled by the browser; empty without NBU */

.highlights { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--line); }
.highlights li { padding: 20px 24px; background: #fff; }
.highlights b { display: block; font-size: clamp(22px, 2.4vw, 32px); font-weight: 700; line-height: 1.2; white-space: nowrap; }
.highlights span { color: var(--muted); font-size: 13px; }

/* ---------- the stage: one photo at a time, crossfade; signed thumbnails ---------- */
.cg { display: grid; gap: 12px; }
.cg__tabs { justify-self: start; }
.cg__stage { position: relative; width: 100%; aspect-ratio: 16 / 9; max-height: 76vh; overflow: hidden; border-radius: var(--r-lg); background-color: #e8e9eb; touch-action: pan-y; }
.cg__stage > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transform: scale(1.015); transition: opacity 0.45s cubic-bezier(0.2, 0.7, 0.2, 1), transform 0.9s cubic-bezier(0.2, 0.7, 0.2, 1); -webkit-user-select: none; user-select: none; }
.cg__stage > img.is-on { opacity: 1; transform: none; }
.cg__stage.studio > img { object-fit: contain; transform: none; } /* a cut-out on the showroom backdrop (site.css .studio) */
.cg__nav, .cg__zoom { position: absolute; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.88); color: var(--graphite); cursor: pointer; transition: background-color 0.15s; }
.cg__nav:hover, .cg__zoom:hover { background: #fff; }
.cg__nav { top: 50%; transform: translateY(-50%); }
.cg__nav--prev { left: 14px; }
.cg__nav--next { right: 14px; }
.cg__zoom { top: 14px; right: 14px; cursor: zoom-in; }
.cg__count { position: absolute; right: 14px; bottom: 14px; padding: 6px 12px; border-radius: 999px; background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }

.cg__thumbs { position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 10px; }
.cg__thumbs button { display: grid; align-content: start; gap: 6px; min-width: 0; padding: 0; border: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 600; line-height: 1.3; text-align: left; cursor: pointer; }
.cg__thumb { display: block; aspect-ratio: 16 / 9; overflow: hidden; border: 2px solid transparent; border-radius: var(--r-sm); background-color: #e8e9eb; transition: border-color 0.2s; }
.cg__thumb img { width: 100%; height: 100%; object-fit: cover; }
.cg__thumb.studio img { object-fit: contain; }
.cg__thumbs [aria-pressed="true"] { color: var(--ink); }
.cg__thumbs [aria-pressed="true"] .cg__thumb { border-color: var(--graphite); }
.cg__thumbs button:hover .cg__thumb { border-color: var(--line); }
.cg__thumbs [aria-pressed="true"]:hover .cg__thumb { border-color: var(--graphite); }

.cg__real { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 12px; }
.cg__tile, .cg-tile { position: relative; display: block; overflow: hidden; padding: 0; border: 0; border-radius: var(--r-lg); background: #e8e9eb; cursor: zoom-in; }
.cg__tile { aspect-ratio: 16 / 10; }
.cg__tile img, .cg-tile img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.8s cubic-bezier(0.2, 0.7, 0.2, 1); }
.cg__tile:hover img, .cg-tile:hover img { transform: scale(1.03); }

/* ---------- the cabin: a bento of the set's interior shots, the trunk next to «come and see» ---------- */
.cg-inside { padding-top: clamp(56px, 8vw, 104px); }
.cg-inside__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 24px; margin-bottom: 20px; }
.cg-inside__head h2 { font-size: clamp(28px, 3.4vw, 44px); }
.cg-inside__head p { color: var(--muted); font-size: 14px; }
.cg-bento { display: grid; grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; gap: 12px; height: clamp(420px, 50vw, 660px); }
.cg-bento .cg-tile:first-child { grid-row: span 2; }
.cg-bento[data-n="2"] { grid-template-columns: 1fr 1fr; grid-template-rows: none; height: auto; }
.cg-bento[data-n="1"] { grid-template-columns: 1fr; grid-template-rows: none; height: auto; }
.cg-bento:not([data-n="3"]) .cg-tile { grid-row: auto; aspect-ratio: 16 / 9; }
.cg-tile > span { position: absolute; left: 14px; bottom: 14px; padding: 6px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.9); color: var(--graphite); font-size: 13px; font-weight: 600; }
.cg-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.cg-row > .cg-tile { aspect-ratio: 16 / 9; }
.cg-row > .cg-band:only-child { grid-column: 1 / -1; }
.cg-band { margin: 0; align-content: center; }
.cg-band h3 { font-size: 24px; }

/* ---------- details: specs, about, charging; the price box beside them (sticky on desktop) ---------- */
.car-more { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); grid-template-areas: "main buy"; align-items: start; gap: clamp(24px, 4vw, 64px); padding-block: clamp(56px, 7vw, 96px) 64px; }
.car-more__main { grid-area: main; display: grid; gap: 48px; min-width: 0; }
.car-more__main h2 { margin-bottom: 8px; font-size: 26px; }
.car-more__desc { max-width: 860px; }
.car-more__desc p { margin-top: 10px; color: #2c2e31; }
.specs { display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; border-top: 1px solid var(--line); }
.specs div { padding: 12px 0; border-bottom: 1px solid var(--line); }
.specs dt { color: var(--muted); font-size: 12px; }
.specs dd { margin-top: 2px; font-size: 15px; font-weight: 600; }
.charge__note { max-width: 62ch; margin-top: 14px; font-size: 15px; }
.charge__how { max-width: 62ch; margin-top: 10px; color: var(--muted); font-size: 13px; }
.charge__go { margin-top: 16px; }

.car-buy { grid-area: buy; display: grid; gap: 16px; padding: clamp(20px, 2vw, 28px); border: 1px solid var(--line); border-radius: var(--r-lg); background: #fff; }
@media (min-width: 961px) and (min-height: 620px) { .car-buy { position: sticky; top: 96px; } } /* only while it fits the screen */
.car-buy__price .price { font-size: 30px; line-height: 1.2; }
.car-buy__units { margin-top: 4px; color: var(--muted); font-size: 13px; }
.car-buy__cta { display: grid; gap: 10px; }
.car-buy__pair { display: flex; gap: 10px; }
.car-buy__pair > .btn { flex: 1; padding-inline: 16px; }
.car-buy__watch { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-md); background: var(--mist); color: var(--graphite); text-decoration: none; transition: background-color 0.15s; }
.car-buy__watch:hover { background: var(--mist-2); }
.car-buy__watch .i { width: 22px; height: 22px; }
.car-buy__watch b { display: block; font-size: 14px; font-weight: 600; }
.car-buy__watch small { display: block; color: var(--muted); font-size: 12px; line-height: 1.4; }
.car-buy__tel { display: inline-flex; align-items: center; justify-self: center; gap: 8px; font-size: 15px; font-weight: 600; text-decoration: none; }

.car-incl .tk-link, .car-incl .tk-teaser { margin-top: 20px; }
.incl { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); gap: 14px 24px; margin-top: 16px; }
.incl__row { display: grid; grid-template-columns: 24px minmax(0, 1fr); align-items: start; gap: 10px; font-size: 14px; line-height: 1.4; }
.incl__mark { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; font-size: 14px; font-weight: 700; }
.incl__mark .i { width: 15px; height: 15px; stroke-width: 2.2; }
.incl__row--yes .incl__mark { background: var(--ok-bg); color: var(--ok); }
.incl__row--ask .incl__mark { background: var(--warn-bg); color: var(--warn); }
.incl__row--no .incl__mark { background: var(--mist-2); color: var(--muted); }
.incl b { display: block; font-weight: 600; }
.incl small { display: block; margin-top: 1px; color: var(--muted); font-size: 13px; }

/* ---------- similar cars: the catalog's cards ---------- */
.similar { padding-bottom: 72px; }
.similar h2 { margin-bottom: 24px; font-size: clamp(26px, 3vw, 36px); }
.similar__grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; }

/* ---------- lightbox: a native <dialog>, scroll-snap swipes; pinch-zoom is the browser's own ---------- */
.lb { width: 100vw; max-width: none; height: 100vh; height: 100dvh; max-height: none; margin: 0; padding: 0; border: 0; background: #0d0e10; color: #fff; }
.lb::backdrop { background: #0d0e10; }
.lb[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; animation: lb-in 0.25s ease-out; }
@keyframes lb-in { from { opacity: 0; } }
.lb__top { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.lb__btn { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.12); color: #fff; cursor: pointer; }
.lb__btn:hover { background: rgba(255, 255, 255, 0.22); }
.lb__track { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior: contain; }
.lb__track::-webkit-scrollbar { display: none; }
.lb__track figure { flex: 0 0 100%; display: grid; place-items: center; min-width: 0; padding: 0 clamp(8px, 4vw, 72px); scroll-snap-align: center; scroll-snap-stop: always; }
.lb__track img { max-width: 100%; max-height: calc(100dvh - 150px); width: auto; height: auto; object-fit: contain; border-radius: 8px; }
.lb__bottom { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 12px 16px calc(20px + env(safe-area-inset-bottom)); }
.lb__cap { min-width: 12em; max-width: 60ch; color: rgba(255, 255, 255, 0.82); font-size: 14px; text-align: center; }

/* ---------- 360° viewer: drag the car round, then look at the interior and open the trunk ---------- */
.viewer { display: grid; gap: 12px; }
.viewer__tabs { justify-self: start; }
.viewer__stage { position: relative; aspect-ratio: 2.1 / 1; max-height: 74vh; overflow: hidden; border-radius: var(--r-lg); cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.viewer__stage:active { cursor: grabbing; }
.viewer__stage img { width: 100%; height: 100%; pointer-events: none; }
/* spin frames are whole frames with room around the car, wheels on the 78% line: zoom in around that line */
.viewer__stage.studio { --floor: 11cqw; }
.viewer__stage.studio::after { left: 10%; right: 10%; }
.viewer__stage.studio img { padding: 0; object-position: 50% 50%; transform: scale(1.18); transform-origin: 50% 78%; }
.viewer__stage.is-plain { background: #15161a; }
.viewer__stage.is-plain::after { display: none; }
.viewer__stage.is-plain img { object-fit: cover; filter: none; -webkit-box-reflect: none; }
.viewer__hint {
  position: absolute; left: 50%; bottom: 14px; display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px;
  border-radius: 999px; background: rgba(255, 255, 255, 0.88); color: var(--graphite); font-size: 13px; font-weight: 600; white-space: nowrap;
  transform: translateX(-50%); pointer-events: none; transition: opacity 0.4s; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.viewer__hint .i { width: 18px; height: 18px; }
.viewer__stage.is-touched .viewer__hint { opacity: 0; }
.viewer__load { position: absolute; left: 0; bottom: 0; width: 100%; height: 3px; background: var(--graphite); transform: scaleX(var(--p, 0)); transform-origin: left; transition: transform 0.2s, opacity 0.5s; }
.viewer__load.is-done { opacity: 0; }
.viewer__full { position: absolute; top: 12px; right: 12px; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.88); cursor: pointer; }
.viewer.is-full { position: fixed; inset: 0; z-index: 90; grid-template-rows: auto 1fr; padding: 16px; background: #fff; }
.viewer.is-full .viewer__stage { aspect-ratio: auto; height: 100%; max-height: none; }
/* points on the car, chips under it, the camera flying in, the real door clip */
.viewer__bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.viewer__chips { display: flex; flex-wrap: wrap; gap: 6px; }
.viewer__chip { min-height: 38px; padding: 8px 14px; border: 1.5px solid var(--line); border-radius: 999px; background: #fff; color: var(--graphite); font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer; transition: border-color 0.2s; }
.viewer__chip:hover { border-color: var(--graphite); }
.viewer__scene { position: absolute; inset: 0; transition: transform 0.8s cubic-bezier(0.2, 0.7, 0.2, 1); }
.viewer__stage.is-zoomed { cursor: zoom-out; }
.viewer__spot {
  position: absolute; z-index: 2; left: calc(50% + (var(--x) - 50) * 1.18%); top: calc(78% + (var(--y) - 78) * 1.18%);
  display: flex; align-items: center; gap: 8px; padding: 0; border: 0; background: none; transform: translate(-17px, -50%); cursor: pointer;
}
.viewer__spot i { position: relative; flex: none; width: 34px; height: 34px; border-radius: 50%; background: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28); }
.viewer__spot i::before { content: ""; position: absolute; inset: 11px; border-radius: 50%; background: var(--graphite); }
.viewer__spot i::after { content: ""; position: absolute; inset: 0; border: 2px solid #fff; border-radius: 50%; animation: ping 1.8s ease-out infinite; }
@keyframes ping { from { transform: scale(1); opacity: 0.9; } to { transform: scale(2.1); opacity: 0; } }
.viewer__spot span { padding: 7px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.95); color: var(--graphite); font-size: 13px; font-weight: 600; white-space: nowrap; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); }
.viewer__clip { position: absolute; inset: 0; z-index: 3; width: 100%; height: 100%; object-fit: cover; background: #111; opacity: 0; pointer-events: none; transition: opacity 0.45s ease; }
.viewer__clip.is-on { opacity: 1; }
.viewer__back {
  position: absolute; z-index: 4; left: 12px; top: 12px; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 8px 16px;
  border: 0; border-radius: 999px; background: rgba(255, 255, 255, 0.92); color: var(--graphite); font-size: 13px; font-weight: 600; cursor: pointer;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.viewer__back .i { width: 16px; height: 16px; }

/* ---------- the buy bar: phones only, once the price box has scrolled away ---------- */
.buybar { display: none; }

@media (max-width: 1100px) {
  .similar__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  .car-more { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main" "buy"; }
  .car-buy { position: static; }
}
@media (max-width: 760px) {
  /* the photos right under the name; the price and the buttons after them, then in the bar */
  .car-top { grid-template-columns: minmax(0, 1fr); grid-template-areas: "title" "media" "buy" "facts"; gap: 14px; }
  .car-top__buy { justify-items: start; text-align: left; }
  .car-top__price { justify-items: start; }
  .car-top__cta { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); justify-content: stretch; width: 100%; margin-top: 6px; }
  .highlights { grid-template-columns: 1fr 1fr; }
  .highlights li { padding: 16px; }
  .cg__nav { display: none; }
  .cg__stage { border-radius: var(--r-md); }
  .cg__zoom { top: 10px; right: 10px; width: 40px; height: 40px; }
  .cg__count { right: 10px; bottom: 10px; }
  .cg__thumbs { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
  .cg__thumbs::-webkit-scrollbar { display: none; }
  .cg__thumbs button { flex: 0 0 30%; scroll-snap-align: start; }
  .cg-bento, .cg-bento[data-n] { grid-template-columns: 1fr; grid-template-rows: none; height: auto; }
  .cg-bento .cg-tile, .cg-bento .cg-tile:first-child { grid-row: auto; aspect-ratio: 16 / 10; }
  .cg-row { grid-template-columns: 1fr; }
  .car-buy { padding: 0; border: 0; }
  .car-buy__head, .car-buy__pair { display: none; } /* the top and the bar have them */
  .charge .specs { grid-template-columns: 1fr; } /* long values; the specs above stay in two columns */
  .similar__grid { display: flex; gap: 12px; margin-inline: calc(-1 * var(--gutter)); padding-inline: var(--gutter); overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-inline: var(--gutter); scrollbar-width: none; }
  .similar__grid::-webkit-scrollbar { display: none; }
  .similar__grid > * { flex: 0 0 82%; scroll-snap-align: start; }
  .viewer__stage { aspect-ratio: 1.6 / 1; }
  .viewer__bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: calc(-1 * var(--gutter)); padding-inline: var(--gutter); }
  .viewer__bar::-webkit-scrollbar { display: none; }
  .viewer__chips { flex-wrap: nowrap; }
  .viewer__tabs { flex: none; }
  .viewer__spot span { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); } /* the point keeps its name */
  .lb__track img { max-height: calc(100dvh - 140px); }

  .buybar {
    position: fixed; z-index: 45; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 10px;
    padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    transform: translateY(110%); visibility: hidden; transition: transform 0.25s cubic-bezier(0.2, 0.7, 0.2, 1), visibility 0s 0.25s;
  }
  .buybar.is-on { transform: none; visibility: visible; transition: transform 0.25s cubic-bezier(0.2, 0.7, 0.2, 1); }
  .buybar__price { display: grid; flex: 1; min-width: 0; line-height: 1.2; }
  .buybar__price .price { font-size: 20px; }
  .buybar__price .price--ask { font-size: 14px; }
  .buybar__price .uah { font-size: 12px; font-weight: 500; }
  .buybar .btn { min-height: 44px; padding-inline: 18px; }
  .buybar__reach { display: grid; flex: none; place-items: center; width: 44px; height: 44px; border: 1.5px solid var(--graphite); border-radius: 50%; color: var(--graphite); }
  html.has-buybar .ai { opacity: 0; visibility: hidden; } /* the assistant's pill steps aside while the bar is up */
}
@media (prefers-reduced-motion: reduce) {
  .cg__stage > img, .cg__tile img, .cg-tile img { transform: none; transition: none; }
  .viewer__spot i::after { animation: none; }
  .viewer__scene { transition: none; }
}

/* «Де заряджатися»: the open-data charging map, filtered by this car's connector (src/chargers.js) */
.charge__map { margin-top: 14px; }
.charge__map a { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; text-decoration: none; }
.charge__map a:hover { text-decoration: underline; text-underline-offset: 4px; }
.charge__map .i { width: 16px; height: 16px; }

/* «Економія з цим авто»: what this EV saves against a petrol crossover, opening /ekonomiia/ on it (src/savings.js) */
.car-save { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-md); background: var(--ok-bg); color: var(--ok); text-decoration: none; transition: background-color 0.15s; }
.car-save:hover { background: #d8eee2; }
.car-save .i { width: 22px; height: 22px; }
.car-save b { display: block; font-size: 14px; font-weight: 700; }
.car-save small { display: block; color: var(--graphite); font-size: 12px; line-height: 1.4; }

/* the dealer's licence under the request buttons (owner, 14.10.2026) */
.car-top__trust { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: var(--graphite); font-size: 14px; font-weight: 500; }
.car-top__trust .i { flex: none; width: 20px; height: 20px; color: var(--ok); }
