/* Base reset */
html {
  font-size: 16px;
}

/* ── Kalles motion language (kx-*) ──────────────────────────────────────────
 * Extracted from the reference theme (reference/kalles-5-2/PARITY.md) — every
 * duration/easing value here was read off the live theme's CSS, not guessed.
 * Blocks reference these tokens (node-factories.mjs, shared-sections.mjs) via
 * `var(--kx-*)` and `data-kx-*` attributes; this file is what actually gives
 * those attributes motion. See PARITY.md for the full porting spec.
 */
:root {
  --kx-dur-short: 0.1s;
  --kx-dur-default: 0.2s;
  --kx-dur-long: 0.5s;
  --kx-dur-extra-long: 0.6s;
  --kx-ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
  --kx-ease-zoom: cubic-bezier(0, 0, 0.44, 1.18);
  --kx-ease-reveal: cubic-bezier(0, 0, 0.3, 1);
  --kx-ease-drawer: cubic-bezier(0.645, 0.045, 0.355, 1);
}

/* 1. Product-card hover — the 2nd image's rest state + slow "breathing" zoom.
 * Rest lives here (not inline) so an unset bind.style never leaves it visible —
 * see the comment on `image2` in node-factories.mjs productCard. */
[data-kx-hover-img] {
  opacity: 0;
  transform: scale(1);
  transition:
    opacity var(--kx-dur-long) var(--kx-ease-standard),
    transform 2s var(--kx-ease-zoom);
}

/* 3. Mega-menu open — fade + slide-down, replayed each time the panel flips
 * to display:flex (a CSS animation restarts on display:none → non-none). */
@keyframes kx-menu-open {
  0% {
    opacity: 0;
    transform: translateY(-1.5rem);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

[data-kx-menu] {
  animation: kx-menu-open var(--kx-dur-extra-long) var(--kx-ease-reveal);
}

/* 4. Drawers / overlays — the engine's generic overlay (overlay-styles.ts,
 * `[data-nd-overlay]`) shows via `[data-open]` → display:flex, so the same
 * "animation restarts on display change" trick applies to panels here. */
@keyframes kx-overlay-fade {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

@keyframes kx-pop-in {
  0% {
    opacity: 0;
    transform: scale(0.96);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes kx-slide-up {
  0% {
    transform: translateY(100%);
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes kx-slide-in-right {
  0% {
    transform: translateX(100%);
    opacity: 0;
  }
  100% {
    transform: translateX(0);
    opacity: 1;
  }
}

[data-nd-overlay][data-open] .nd-overlay__backdrop {
  animation: kx-overlay-fade var(--kx-dur-long) var(--kx-ease-standard);
}

[data-nd-overlay][data-open] .nd-overlay__panel {
  animation: kx-pop-in var(--kx-dur-long) var(--kx-ease-drawer);
}

[data-nd-overlay][data-nd-presentation="sheet"][data-open] .nd-overlay__panel {
  animation: kx-slide-up var(--kx-dur-long) var(--kx-ease-drawer);
}

/* Cart is a right-side, full-height drawer in Kalles — not the engine's
 * default bottom sheet or centered modal. Override presentation for this
 * specific overlay identity only; every other overlay (quick-view, etc.)
 * keeps the engine default. */
#cart-overlay[data-nd-overlay] {
  align-items: stretch;
  justify-content: flex-end;
  padding: 0;
}

#cart-overlay[data-nd-overlay] .nd-overlay__panel {
  width: min(420px, 100%);
  height: 100%;
  max-height: 100%;
  border-radius: 0;
}

#cart-overlay[data-nd-overlay][data-open] .nd-overlay__panel {
  animation: kx-slide-in-right var(--kx-dur-long) var(--kx-ease-drawer);
}

/* 5. Scroll reveal — gated behind `.kx-js` (set by an early inline script in
 * <head>, before paint) so content is never stuck invisible with JS off or a
 * slow script load; kx-reveal.js observes `[data-kx-reveal]` and flips
 * `data-kx-inview` + sets `--kx-order` per element for the 75ms cascade. */
@keyframes kx-reveal-slide-in {
  0% {
    transform: translateY(2rem);
    opacity: 0.01;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes kx-reveal-fade-in {
  0% {
    opacity: 0.01;
  }
  100% {
    opacity: 1;
  }
}

html.kx-js [data-kx-reveal]:not([data-kx-inview]) {
  opacity: 0.01;
}

html.kx-js [data-kx-reveal="slide"]:not([data-kx-inview]) {
  transform: translateY(2rem);
}

html.kx-js [data-kx-reveal="slide"][data-kx-inview] {
  animation: kx-reveal-slide-in var(--kx-dur-extra-long) var(--kx-ease-reveal) forwards;
  animation-delay: calc(var(--kx-order, 0) * 75ms);
}

html.kx-js [data-kx-reveal="fade"][data-kx-inview] {
  animation: kx-reveal-fade-in var(--kx-dur-extra-long) var(--kx-ease-reveal) forwards;
  animation-delay: calc(var(--kx-order, 0) * 75ms);
}

@media (prefers-reduced-motion: reduce) {
  [data-kx-hover-img],
  [data-kx-menu],
  [data-nd-overlay][data-open] .nd-overlay__backdrop,
  [data-nd-overlay][data-open] .nd-overlay__panel,
  html.kx-js [data-kx-reveal="slide"][data-kx-inview],
  html.kx-js [data-kx-reveal="fade"][data-kx-inview] {
    animation: none;
    transition: none;
  }
  html.kx-js [data-kx-reveal]:not([data-kx-inview]) {
    opacity: 1;
    transform: none;
  }
}

/* Interactive defaults — every <button> shows a pointer on hover; disabled
 * buttons get the native "not-allowed" cursor. Individual templates that
 * wanted this added inline forgot to on a few (hamburger, product back
 * button), so we cover it globally once. */
button {
  cursor: pointer;
}
/* Children of buttons (icons, SVGs, spans wrapping them) should never
 * override the button's cursor — so hover shows a pointer anywhere inside
 * the button hit area, not just on padding. */
button * {
  cursor: inherit;
}
button:disabled,
button[aria-disabled="true"] {
  cursor: not-allowed;
}

html,
body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: var(--line-height);
  font-size: var(--text-base);
  font-weight: var(--font-normal);
}

/*
 * Storefront layout — mobile render everywhere, clamped to a phone-width
 * column on desktop (LinkedIn/Instagram style). The wrapper is emitted by
 * `pageWrapperSchema` and sits between <body> and the page-specific
 * template, so every page inherits the column automatically.
 */
.page-wrapper {
  width: 100%;
  min-height: 100vh;
  background: var(--bg-page);
  margin-inline: auto;
  display: flex;
  flex-direction: column;
}

.page-wrapper > #page-content {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.page-wrapper footer {
  margin-top: auto;
}

@media (min-width: 768px) {
  body {
    background: #f3f4f6;
  }
  .page-wrapper {
    max-width: 520px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05), 0 10px 40px rgba(0, 0, 0, 0.06);
  }
  /* Marketplace storefronts are dense — Daraz / Flipkart / Amazon scale
     to the viewport. Drop the phone-width clamp and ditch the side
     shadow so the layout uses the full window. The inner page templates
     keep their own desktop max-widths (e.g. 1280-1440px) so we don't go
     edge-to-edge on ultrawide. */
  .page-wrapper--wide {
    max-width: none;
    box-shadow: none;
    background: var(--bg-page);
  }
  /* Wide-wrapper pages with feed-column content (checkout, cart, orders,
     profile) — without anchor, the 640px column floats unframed in the
     middle of the wide page background. Give it a soft surface so it
     reads as a card rather than a void. Scoped to wide wrapper so it
     doesn't touch the existing column-clamped variants. */
  .page-wrapper--wide .feed-column-anchor,
  .page-wrapper--wide #checkout-page,
  .page-wrapper--wide #cart-page {
    background: var(--bg-surface, #ffffff);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.04);
  }
}

/* Typography */
h1,
h2,
h3 {
  color: var(--text-heading);
  font-weight: var(--font-bold);
}

h1 {
  margin: 0;
}

small,
.caption {
  color: var(--text-muted);
  font-size: var(--text-xs);
}

/* Input base */
input {
  height: var(--h-10);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  width: 100%;
  margin: 0;
  box-sizing: border-box;
  /* Bind the input surface + text to theme tokens. Previously unset, so the
     browser used its own white box while text inherited the (light, on dark
     presets) body colour — i.e. white-on-white. Now both follow the active
     theme/style and keep their guaranteed contrast pairing. */
  color: var(--text-main);
  background: var(--bg-surface);
  font-family: var(--font-sans);
}

/* Textarea — mirror the input surface/text binding so multi-line fields theme
   identically (templates historically styled textareas only inline). */
textarea {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  width: 100%;
  margin: 0;
  box-sizing: border-box;
  color: var(--text-main);
  background: var(--bg-surface);
  font-family: var(--font-sans);
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

input::placeholder,
textarea::placeholder {
  letter-spacing: normal;
  font-size: var(--text-sm) !important;
  color: var(--text-muted);
}

/* Checkbox */
input[type="checkbox"] {
  padding: 0.7rem 0.6rem;
  width: auto;
  height: auto;
  appearance: none;
  border: 2px solid var(--color-primary);
  border-radius: 0;
  background: var(--bg-surface);
  cursor: pointer;
  position: relative;
  vertical-align: middle;
}

input[type="checkbox"]:checked::after {
  content: "";
  display: block;
  position: absolute;
  left: 5px;
  top: 2px;
  width: 6px;
  height: 12px;
  border: solid var(--button-text);
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
}

/* Radio */
input[type="radio"] {
  width: 20px;
  height: 20px;
  padding: 0;
  appearance: none;
  border: 2px solid var(--color-primary);
  border-radius: 50%;
  background: var(--bg-surface);
  cursor: pointer;
  position: relative;
  vertical-align: middle;
  box-sizing: border-box;
  display: inline-block;
}

input[type="radio"]:checked::after {
  content: "";
  display: block;
  position: absolute;
  left: 3px;
  top: 3px;
  width: 8px;
  height: 8px;
  background: var(--color-primary);
  border-radius: 50%;
}

/* Select */
select {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--bg-surface);
  cursor: pointer;
  font-size: var(--text-xs);
  color: var(--text-main);
  appearance: none;
  /* Mid-grey arrow (#888) reads on both light and dark theme surfaces — a data
     URI can't reference a CSS var, so #333 went invisible on dark presets. */
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20fill%3D%22%23888888%22%20d%3D%22M7.41%208.59L12%2013.17l4.59-4.58L18%2010l-6%206-6-6z%22%2F%3E%3C%2Fsvg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1rem;
}

/* Links */
a {
  text-decoration: none;
  color: var(--text-main);
}

/* Error styles */
.input-error {
  color: var(--text-error);
  font-size: var(--text-xs);
}

.form-error {
  color: var(--text-error);
  font-size: var(--text-lg);
}

.text-error {
  color: var(--text-error);
  font-size: var(--text-base);
}

/* Navigation */
.nav a {
  color: var(--text-on-dark);
  text-decoration: none;
  margin-right: var(--space-md);
}

.nav a:hover {
  color: var(--color-secondary);
}

/* Outline button */
.outline-btn:hover,
.outline-btn:focus,
.outline-btn.active {
  background: var(--bg-surface);
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.outline-btn.selected {
  border-color: var(--color-primary) !important;
  box-shadow: var(--shadow-sm) !important;
}

/* Circular button */
.circular-btn {
  border-radius: var(--radius-full);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
}

.light-circular-btn {
  background-color: var(--text-on-dark);
}

.light-circular-btn:hover,
.light-circular-btn:focus,
.light-circular-btn.selected,
.light-circular-btn.active {
  border-color: var(--color-primary);
  background-color: var(--color-primary);
  color: var(--button-text) !important;
}

/* Chip button — bound to theme tokens (was pinned to --color-white/black, so
   chips never followed a style change). */
.chip-button {
  background-color: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.chip-button.active {
  background-color: var(--color-primary);
  color: var(--button-text);
  border-color: var(--color-primary);
}

/* Search modal */
.search-modal {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  display: none;
  z-index: var(--z-modal);
}

/* Utility */
.divider {
  height: 1px;
  background-color: var(--border-color);
  width: 100%;
  margin: 4px 0;
}

/* Responsive */
@media (max-width: 767px) {
  .responsive-container {
    width: 100%;
    min-width: unset;
    border-radius: 0;
  }
}

@media (min-width: 768px) {
  body {
    margin-left: auto;
    margin-right: auto;
  }
}

/* Add to cart animation */
.flying-image {
  position: fixed;
  z-index: 1000;
  width: var(--product-image-width);
  height: var(--product-image-height);
  transition:
    transform 1s ease-in,
    opacity 1s ease-in;
  pointer-events: none;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25%,
  75% {
    transform: translateX(-5px);
  }
  50% {
    transform: translateX(5px);
  }
}

#add-to-cart-btn.shake {
  animation: shake 0.5s;
}

/* Bottom-nav ongoing-order "live / in-progress" badge: a radar-style pulse on
   the accent dot, signalling the active order is in flight. Uses currentColor
   (the dot's color is var(--color-accent)) so it reskins with the theme. */
.bottom-nav-order-live {
  animation: bottom-nav-live-pulse 1.6s ease-out infinite;
}

@keyframes bottom-nav-live-pulse {
  0% {
    box-shadow: 0 0 0 0 currentColor;
  }
  70% {
    box-shadow: 0 0 0 6px transparent;
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bottom-nav-order-live {
    animation: none;
  }
}

/* Hero overlay text scales with the hero's OWN width (cqw) instead of the
   viewport (vw). On a mobile-only template the hero is the ~520px phone column,
   so on a laptop the old vw clamps maxed out and rendered desktop-sized hero
   text; cqw keeps it column-sized. Marketplace (full-width hero) still scales up. */
.hero-section {
  container-type: inline-size;
}
