/* SsangYong Parts storefront — SYA-SHOP-1.
   No build step, no framework, no external font or asset: the page must load
   under the CSP api.js sends (default-src 'self'), with product photography
   from autopart.tn the single permitted remote origin. */

:root {
  --ink: #14181d;
  --ink-soft: #5b6672;
  --line: #dfe3e8;
  --surface: #fff;
  --ground: #f5f6f8;
  --accent: #0d3b66;
  --accent-soft: #e8eef5;
  --stock: #1c7a4a;
  --order: #a8620a;
  --radius: 6px;
}

* { box-sizing: border-box; }

/* The UI hides views by setting the `hidden` property. An author rule that
   sets `display` — `.layout { display: grid }`, `.paging { display: flex }` —
   beats the user-agent's `[hidden] { display: none }` outright, because author
   styles always win over UA styles. Without this rule the catalogue view and
   the paging control stay on screen underneath a product page. Found by
   headless-browser review; the DOM harness in the test suite cannot see it,
   because the property is set correctly and only CSS overrides the effect. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--ground);
}

a { color: var(--accent); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- header ---------- */

.site-header {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; flex-direction: column; text-decoration: none; color: var(--ink); }
.brand-mark { font-size: 20px; font-weight: 700; letter-spacing: .02em; }
.brand-sub { font-size: 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .08em; }

/* min-width:0 here is load-bearing, and it must be on the FORM, not just the
   input. `.search` is a flex item of `.site-header` with `min-width: auto`,
   which resolves to its content-based minimum. Being itself a row flex
   container, that minimum is driven by its children — and the text input
   carries the UA's default intrinsic width (`size=20`, ~257px at this font).
   The form was therefore floored at 257 + 8 gap + 119 button = 384px and
   refused to shrink, identical at 360px and 390px viewports, pushing the
   submit button past the edge (scrollWidth 408 vs 390). Measured in a
   headless browser, not inferred. The min-width:0 on the input below is the
   complementary inner-level guard; on its own it does nothing for this, since
   it governs the input inside the form rather than the form inside the
   header. */
.search { display: flex; flex: 1 1 240px; min-width: 0; gap: 8px; max-width: 560px; }
.search input {
  flex: 1; min-width: 0; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  font: inherit; background: var(--surface);
}
.search button { white-space: nowrap; }
.search input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

button {
  font: inherit; cursor: pointer;
  padding: 9px 16px; border-radius: var(--radius);
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
button:disabled { opacity: .45; cursor: default; }

/* ---------- catalogue layout ---------- */

.layout {
  display: grid; grid-template-columns: 260px minmax(0, 1fr);
  gap: 24px; padding: 24px; align-items: start;
}

.filters {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 4px 16px 16px;
  position: sticky; top: 16px;
}

.filter-block { border-bottom: 1px solid var(--line); padding: 12px 0; }
.filter-block:last-of-type { border-bottom: 0; }
.filter-block h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin: 4px 0 10px; }

.filters label { display: block; font-size: 13px; color: var(--ink-soft); margin: 10px 0 4px; }
.filters select {
  width: 100%; padding: 8px 10px; font: inherit;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
.hint { font-size: 12px; color: var(--ink-soft); margin: 10px 0 2px; }

/* 42 brands, so this list always scrolls. Left unlabelled it reads as a
   9-item list that happens to end at BSG — the count in the heading and the
   ruled edge are what tell the visitor there is more below. */
.facet {
  list-style: none; margin: 0; padding: 0;
  max-height: 340px; overflow-y: auto;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.facet-count { color: var(--ink-soft); font-weight: 400; }
.facet li { margin: 0; }
.facet button {
  display: flex; justify-content: space-between; gap: 8px; width: 100%;
  padding: 6px 8px; text-align: left;
  background: none; border: 0; border-radius: var(--radius); color: var(--ink);
}
.facet button:hover { background: var(--ground); }
.facet button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.facet .n { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.facet button[aria-pressed="true"] .n { color: inherit; }

.reset { width: 100%; margin-top: 14px; background: none; color: var(--accent); }

/* ---------- results ---------- */

.results-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.results-head h1 { font-size: 22px; margin: 0 0 12px; }
.results-count { color: var(--ink-soft); font-size: 14px; margin: 0 0 12px; }

.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden;
}
.card a { display: flex; flex-direction: column; height: 100%; text-decoration: none; color: inherit; }
.card .photo {
  aspect-ratio: 4 / 3; background: var(--ground);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.card img { max-width: 100%; max-height: 100%; object-fit: contain; }
.card .no-photo { color: var(--ink-soft); font-size: 13px; }
.card .body { padding: 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card .brand-line { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
.card h3 { font-size: 14px; font-weight: 600; margin: 0; line-height: 1.35; }
.card .ref { font-size: 12px; color: var(--ink-soft); }
.card .price { margin-top: auto; font-size: 17px; font-weight: 700; }

.tag { font-size: 12px; font-weight: 600; }
.tag.stock { color: var(--stock); }
.tag.order { color: var(--order); }

.paging { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 24px 0; }
.paging span { color: var(--ink-soft); font-size: 14px; }

/* ---------- product detail ---------- */

.product { padding: 24px; max-width: 1100px; margin: 0 auto; }
.crumbs { margin: 0 0 16px; }
.product-body {
  display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 32px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px;
}

.gallery img {
  width: 100%; aspect-ratio: 1; object-fit: contain;
  background: var(--ground); border-radius: var(--radius);
}
.thumbs { list-style: none; display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 0; padding: 0; }
.thumbs button { padding: 0; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.thumbs button[aria-pressed="true"] { border-color: var(--accent); }
.thumbs img { width: 60px; height: 60px; object-fit: contain; display: block; }

.product-info h1 { font-size: 22px; margin: 4px 0 10px; line-height: 1.3; }
.product-brand { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin: 0; }
.product-ref { color: var(--ink-soft); font-size: 14px; margin: 0 0 16px; }
.product-ref strong { color: var(--ink); }
.price { font-size: 28px; font-weight: 700; margin: 0 0 4px; }
.availability { margin: 0 0 20px; font-weight: 600; }

.product-info section { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }
.product-info h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin: 0 0 12px; }

.specs { display: grid; grid-template-columns: minmax(140px, auto) 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
.specs dt { color: var(--ink-soft); }
.specs dd { margin: 0; }

.fitment { width: 100%; border-collapse: collapse; font-size: 14px; }
.fitment th, .fitment td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.fitment th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
.fitment td { font-variant-numeric: tabular-nums; }

.source { font-size: 12px; color: var(--ink-soft); margin-top: 20px; }

/* ---------- state + footer ---------- */

.state { padding: 32px 24px; text-align: center; color: var(--ink-soft); margin: 0; }
.state.error { color: #9b1c1c; }
.state:empty { display: none; }

.site-footer {
  padding: 24px; border-top: 1px solid var(--line);
  background: var(--surface); color: var(--ink-soft); font-size: 13px;
}
.site-footer p { margin: 0 0 4px; }
.footer-note { font-style: italic; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .filters { position: static; }
  .product-body { grid-template-columns: 1fr; }
}
