﻿/* =========================================================
   Layout — header, menu, search, bottom search bar, footer
   (the markup is generated by assets/js/layout.js and
    assets/js/search-ui.js)
   ========================================================= */

/* ---------- Header ---------- */
#site-header { min-height: var(--header-h); position: sticky; top: 0; z-index: 100; }

.site-header {
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.site-header__bar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--header-h);
}

/* The logo is shown in its original colours in light mode, and in black &
   white (the white version, with its details cut out) in dark mode. */
.brand { display: inline-flex; align-items: center; flex: none; margin-right: auto; }
.brand__logo { height: 38px; width: auto; }
.brand__logo--white { display: none; }
:root[data-theme="dark"] .brand__logo--color { display: none; }
:root[data-theme="dark"] .brand__logo--white { display: block; }

.site-nav { display: none; align-items: center; gap: 2px; }
.site-nav__link {
  position: relative;
  padding: 10px 11px;
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.2;
  color: var(--text-2);
  transition: color 0.18s var(--ease);
}
.site-nav__link:lang(km) { font-size: 0.9375rem; line-height: 1.5; }
.site-nav__link:hover { color: var(--text); }
.site-nav__link.is-active { color: var(--text); }
.site-nav__link.is-active::after {
  content: "";
  position: absolute;
  left: 11px; right: 11px; bottom: 2px;
  height: 3px;
  background: var(--grad-warm);
}

.site-header__actions { display: flex; align-items: center; gap: 6px; }
.header-cta { display: none; margin-left: 4px; }

.theme-toggle .icon--moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon--sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon--moon { display: block; }

.menu-btn .icon--close { display: none; }
.menu-btn[aria-expanded="true"] .icon--menu { display: none; }
.menu-btn[aria-expanded="true"] .icon--close { display: block; }

/* Language switch: EN | ខ្មែរ */
.lang-switch {
  display: inline-flex;
  flex: none;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.lang-switch__btn {
  min-width: 40px;
  height: 38px;
  padding: 0 9px;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
  color: var(--text-2);
  transition: background-color 0.18s var(--ease), color 0.18s var(--ease);
}
.lang-switch__btn:hover { color: var(--text); background: var(--surface-2); }
.lang-switch__btn[aria-pressed="true"] { background: var(--text); color: var(--bg); }

/* ---------- Search trigger (looks like a search box, opens the search pop-up) ---------- */
.search-trigger {
  display: none;
  align-items: center;
  gap: 10px;
  height: 46px;
  padding: 0 10px 0 14px;
  background: var(--surface);
  border: 1.5px solid var(--text);
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: 0.9375rem;
  font-weight: 500;
  text-align: left;
  cursor: text;
  transition: box-shadow 0.18s var(--ease), background-color 0.18s var(--ease);
}
.search-trigger:hover { box-shadow: 0 0 0 3px var(--brand-soft); }
.search-trigger .icon { width: 18px; height: 18px; color: var(--text); }
.search-trigger__text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-trigger__key {
  flex: none;
  min-width: 22px;
  padding: 2px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  color: var(--text-3);
}

@media (min-width: 1024px) {
  .brand { margin-right: 14px; }
  .brand__logo { height: 44px; }
  .site-nav { display: flex; }
  .site-header .search-trigger { display: flex; flex: 1 1 200px; max-width: 400px; min-width: 150px; margin-left: auto; margin-right: 6px; }
  .menu-btn { display: none; }
}
@media (min-width: 1280px) {
  .header-cta { display: inline-flex; }
  .site-nav__link { padding-inline: 14px; }
  .site-nav__link.is-active::after { left: 14px; right: 14px; }
}

/* ---------- Bottom search bar (phone and tablet): within reach of the thumb ---------- */
.dock { display: none; }
@media (max-width: 1023.98px) {
  .dock {
    display: block;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 95;
    padding: 10px max(var(--gutter), env(safe-area-inset-left)) calc(10px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-right));
    background: var(--header-bg);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    backdrop-filter: saturate(160%) blur(14px);
    border-top: 1px solid var(--line);
  }
  .dock .search-trigger { display: flex; width: 100%; height: 50px; font-size: 1rem; }
  .dock .search-trigger__key { display: none; }
  body.is-locked .dock { display: none; }
}

/* ---------- Search pop-up ---------- */
.search { position: fixed; inset: 0; z-index: 200; }
.search__backdrop { position: absolute; inset: 0; background: var(--overlay); }
.search__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
}
.search__bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 0 16px;
  border-bottom: 1px solid var(--line);
}
.search__bar > .icon { color: var(--text); }
.search__input {
  flex: 1;
  min-width: 0;
  height: 60px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 1.125rem;
  font-weight: 500;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.search__input::placeholder { color: var(--text-3); font-weight: 400; }
.search__input::-webkit-search-cancel-button { display: none; }
.search__close {
  flex: none;
  min-height: 44px;
  padding: 8px 12px;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
}
.search__close:hover { color: var(--text); }

.search__body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.search__group { display: flex; flex-direction: column; flex: none; padding-bottom: 6px; }
.search__group-title { padding: 14px 16px 6px; }
.search__list { display: flex; flex-direction: column; }

.search-item {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 8px 16px;
}
.search-item:hover,
.search-item.is-active { background: var(--surface-2); }
.search-item.is-active { box-shadow: inset 3px 0 0 var(--accent); }
.search-item__thumb {
  position: relative;
  width: 52px; height: 52px;
  background: var(--media-bg);
  border: 1px solid var(--line);
  overflow: hidden;
}
.search-item__thumb img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.search-item__thumb .media-placeholder { padding: 0; font-size: 0; }
.search-item__text { min-width: 0; display: grid; gap: 1px; }
.search-item__brand { font-size: 0.8125rem; }
.search-item__name { font-weight: 600; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-item__model { font-size: 0.8125rem; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-item--simple { grid-template-columns: minmax(0, 1fr) auto; min-height: 48px; padding-block: 10px; font-weight: 600; }
.search-item--simple .muted { font-weight: 400; font-size: 0.875rem; }

.search__all {
  order: 99;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--brand);
}
.search__all:hover,
.search__all.is-active { background: var(--surface-2); }
.search__quick { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 16px 12px; }
.search__empty { padding: 28px 16px; color: var(--text-2); }
.search__empty strong { display: block; color: var(--text); font-size: 1.0625rem; margin-bottom: 4px; }

/* Laptop: a pop-up at the top of the screen */
@media (min-width: 1024px) {
  .search__panel {
    width: min(760px, calc(100% - 48px));
    max-height: min(82vh, 760px);
    margin: 8px auto 0;
    border: 1.5px solid var(--text);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-pop);
    overflow: hidden;
  }
}

/* Phone and tablet: the box sits at the BOTTOM, just above the keyboard,
   and results stack upward from it so the best match is nearest the thumb. */
@media (max-width: 1023.98px) {
  .search__panel {
    position: absolute;
    left: 0; right: 0; top: 0;
    height: 100%;
    flex-direction: column-reverse;
  }
  .search__bar {
    border-bottom: 0;
    border-top: 1.5px solid var(--text);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .search__body { flex-direction: column-reverse; }
  .search__list { flex-direction: column-reverse; }
  .search__all { order: -1; border-top: 0; border-bottom: 1px solid var(--line); }
  .search__quick { flex-direction: row; }
}

/* ---------- Phone / tablet menu ---------- */
.mobile-menu {
  position: fixed;
  left: 0; right: 0;
  top: calc(var(--header-h) + env(safe-area-inset-top));
  bottom: 0;
  z-index: 99;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding-block: 12px calc(32px + env(safe-area-inset-bottom));
}
.mobile-menu__nav { display: grid; }
.mobile-menu__nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.75rem;
  line-height: 1.1;
  text-transform: uppercase;
}
.mobile-menu__nav a:lang(km) { font-size: 1.25rem; line-height: 1.6; }
.mobile-menu__nav a .icon { color: var(--text-3); }
.mobile-menu__nav a.is-active { color: var(--brand); }
.mobile-menu__label { margin: 26px 0 4px; }
.mobile-menu__cats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 20px; }
.mobile-menu__cats a {
  display: flex;
  align-items: center;
  min-height: 46px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-weight: 500;
  line-height: 1.3;
}
.mobile-menu__cta { margin-top: 26px; display: grid; gap: 10px; }

@media (min-width: 640px) {
  .mobile-menu__cats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .mobile-menu__cta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .mobile-menu { display: none !important; }
}

/* ---------- Footer (on the mat) ---------- */
.site-footer {
  margin-top: var(--section-y);
  font-size: 0.9375rem;
}
/* The two-colour bar from the logo */
.site-footer::before {
  content: "";
  display: block;
  height: 6px;
  background:
    linear-gradient(90deg, #006565, #19a39c) left / 62% 100% no-repeat,
    linear-gradient(90deg, #cc322f, #ef5f43) right / 38% 100% no-repeat;
}

.site-footer__grid {
  display: grid;
  gap: 36px 32px;
  padding-block: 44px 36px;
  grid-template-columns: minmax(0, 1fr);
}
.site-footer__brand .brand__logo { height: 48px; }
.site-footer__brand p,
.site-footer__brand address { margin-top: 14px; color: var(--text-2); }
.site-footer__brand .tagline {
  font-family: var(--font-display);
  font-size: 1.375rem;
  font-weight: 700;
  text-transform: uppercase;
  line-height: 1.1;
  color: var(--text);
}

.site-footer__title { margin-bottom: 12px; }
.site-footer__list { display: grid; gap: 2px; }
.site-footer__list--2col { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 20px; }
.site-footer__list a { display: inline-block; padding: 5px 0; color: var(--text-2); }
.site-footer__list a:hover { color: var(--text); text-decoration: underline; text-underline-offset: 4px; }

.site-footer__base {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 24px;
  padding-block: 18px calc(18px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--text-3);
  font-size: 0.8125rem;
}

/* Leave room for the bottom search bar */
@media (max-width: 1023.98px) {
  .site-footer__base { padding-bottom: calc(18px + var(--dock-h) + env(safe-area-inset-bottom)); }
}

@media (min-width: 640px) {
  .site-footer__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .site-footer__catalog { grid-column: 1 / -1; }
  .site-footer__list--2col { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .site-footer__grid { grid-template-columns: 1.3fr 1.7fr 0.8fr 0.9fr; gap: 48px; padding-block: 60px 44px; }
  .site-footer__catalog { grid-column: auto; }
  .site-footer__list--2col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* =========================================================
   Motion — search pop-up animation and smooth transitions
   ========================================================= */

/* Search: backdrop fades, panel slides (down from the top on laptop, up from the bottom on phone) */
.search__backdrop { opacity: 0; transition: opacity 0.26s var(--ease); }
.search__panel { opacity: 0; transition: opacity 0.22s var(--ease), transform 0.3s cubic-bezier(0.2, 0.9, 0.25, 1); }
.search.is-open .search__backdrop { opacity: 1; }
.search.is-open .search__panel { opacity: 1; transform: none; }
@media (min-width: 1024px) {
  .search__panel { transform: translateY(-16px) scale(0.98); transform-origin: top center; }
}
@media (max-width: 1023.98px) {
  .search__panel { transform: translateY(40px); }
}

/* Each result row glides in, one after another */
@keyframes mood-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes mood-drop { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.search.is-open .search__group,
.search.is-open .search__empty,
.search.is-open .search__all { animation: mood-drop 0.28s var(--ease) both; }
@media (max-width: 1023.98px) {
  .search.is-open .search__group,
  .search.is-open .search__empty,
  .search.is-open .search__all { animation-name: mood-rise; }
}
.search__list > *,
.search__quick > * { animation: mood-drop 0.26s var(--ease) both; }
@media (max-width: 1023.98px) { .search__list > *, .search__quick > * { animation-name: mood-rise; } }
.search__list > :nth-child(2), .search__quick > :nth-child(2) { animation-delay: 0.03s; }
.search__list > :nth-child(3), .search__quick > :nth-child(3) { animation-delay: 0.06s; }
.search__list > :nth-child(4), .search__quick > :nth-child(4) { animation-delay: 0.09s; }
.search__list > :nth-child(5), .search__quick > :nth-child(5) { animation-delay: 0.12s; }
.search__list > :nth-child(n+6), .search__quick > :nth-child(n+6) { animation-delay: 0.15s; }
.search-item { transition: background-color 0.15s var(--ease), box-shadow 0.15s var(--ease); }

/* Search box in the header / bottom bar: presses in when tapped */
.search-trigger { transition: box-shadow 0.18s var(--ease), background-color 0.18s var(--ease), transform 0.15s var(--ease); }
.search-trigger:active { transform: scale(0.98); }

/* Smooth page changes: pages appear in place (no fade or slide on load, which
   looked like a refresh). Browsers that support it cross-fade between pages
   once the site is online; the header stays put during the fade. */
@keyframes mood-page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 0.18s; animation-timing-function: var(--ease); }
.site-header { view-transition-name: site-header; }
::view-transition-group(site-header) { animation: none; }
::view-transition-old(site-header) { display: none; }
::view-transition-new(site-header) { animation: none; }

/* Product grids and lists ease in only when filters change, not on page load
   (layout.js adds .is-ready once the page has finished its first render) */
.is-ready .product-grid > :not(.is-shown), .is-ready .brand-grid > :not(.is-shown) { animation: mood-page-in 0.3s var(--ease) both; }

/* Theme switch: colours change smoothly instead of snapping */
body, .site-header, .product-card__media, .brand-tile, .pill, .btn, .field input, .select {
  transition-property: background-color, border-color, color, box-shadow, transform;
  transition-duration: 0.25s;
  transition-timing-function: var(--ease);
}

/* Menu on phone slides down */
@keyframes mood-menu-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
.mobile-menu:not([hidden]) { animation: mood-menu-in 0.25s var(--ease) both; }

@media (prefers-reduced-motion: reduce) {
  .is-ready .product-grid > *, .is-ready .brand-grid > *, .search__list > *, .search__quick > *, .mobile-menu { animation: none !important; }
  .search__panel { transform: none !important; }
}
