:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --tile: #ffffff;
  --ink: #16161a;
  --muted: #6d6c75;
  --line: #e4e2dc;
  --accent: #ff5a2c;
  --accent-ink: #ffffff;
  --shadow: 0 1px 2px rgb(22 22 26 / 6%), 0 8px 24px rgb(22 22 26 / 6%);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --surface: #1b1b1f;
    --tile: #ffffff;
    --ink: #f2f1ee;
    --muted: #9c9ba6;
    --line: #2c2c33;
    --accent: #ff6a3d;
    --accent-ink: #16161a;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p, dl, dd { margin: 0; }
a { color: inherit; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand svg { width: 30px; height: 30px; flex: none; }
.brand svg rect { fill: var(--ink); }
.brand svg path { fill: var(--accent); }

.tabs { display: flex; gap: 4px; }
.tabs a {
  padding: 7px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { background: var(--ink); color: var(--bg); }

/* The catalog exists only where the server offers it; see app.js. */
.no-catalog .tabs, .no-catalog .topbar-note { display: none; }
.no-catalog .key { margin-left: auto; }

.topbar-note { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }

.key {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding: 0 12px;
  height: 36px;
  width: 190px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  transition: border-color .15s;
}
.topbar-note + .key { margin-left: 0; }
.key:focus-within { border-color: var(--ink); }
.key.missing { border-color: var(--accent); }
.key svg { width: 16px; height: 16px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.key input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: inherit; font: inherit; font-size: 13px; }
.key input::placeholder { color: var(--muted); }

/* Layout */

main { flex: 1; width: 100%; max-width: 1440px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px) 56px; }

.hero { padding: clamp(28px, 5vw, 56px) 0 20px; max-width: 720px; }
.hero h1 { font-size: clamp(28px, 4vw, 42px); line-height: 1.1; letter-spacing: -0.025em; }
.hero p { margin-top: 10px; color: var(--muted); font-size: 16px; }

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
  padding: 0 8px 0 18px;
  height: 56px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}
.search:focus-within { border-color: var(--ink); }
.search svg { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 17px;
}
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { display: none; }

.ghost {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.ghost:hover { background: var(--line); color: var(--ink); }

.chips {
  display: flex;
  gap: 8px;
  padding: 4px 0 6px;
  margin: 0 calc(-1 * clamp(16px, 4vw, 40px));
  padding-inline: clamp(16px, 4vw, 40px);
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.chip small { color: var(--muted); font-size: 12px; font-weight: 400; }
.chip:hover { border-color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip[aria-pressed="true"] small { color: inherit; opacity: .7; }

.summary { min-height: 22px; margin: 18px 0 14px; color: var(--muted); }
.summary strong { color: var(--ink); font-weight: 600; }

/* Cards */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: transparent; }

/* The photo is taken out of the flow, so its own proportions never stretch the tile. */
.card-image {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  background: var(--tile);
}
.card-image img {
  position: absolute;
  inset: 12px;
  width: calc(100% - 24px);
  height: calc(100% - 24px);
  object-fit: contain;
  transition: transform .25s ease;
}
.card:hover .card-image img { transform: scale(1.04); }
.card-image.missing::after { content: "нет фото"; color: #a3a2ab; font-size: 13px; }
.card-image.missing img { display: none; }

.card-body { display: flex; flex-direction: column; gap: 3px; padding: 12px 14px 14px; border-top: 1px solid var(--line); }

.eyebrow { color: var(--muted); font-size: 11.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; }

.card-name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  min-height: 2.7em;
  font-weight: 600;
  line-height: 1.35;
}

.muted { color: var(--muted); }
.card .muted { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.score {
  position: absolute;
  z-index: 1;
  top: 10px;
  left: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.score.best { background: var(--accent); color: var(--accent-ink); }

.skeleton { pointer-events: none; }
.skeleton .card-image, .skeleton .line {
  background: linear-gradient(100deg, var(--line) 40%, color-mix(in srgb, var(--line) 50%, var(--surface)) 50%, var(--line) 60%) 0 0 / 300% 100%;
  animation: shimmer 1.3s linear infinite;
}
.skeleton .line { height: 12px; border-radius: 6px; }
.skeleton .line.short { width: 40%; }
.skeleton .line.long { width: 85%; height: 14px; margin: 4px 0; }
@keyframes shimmer { to { background-position: -150% 0; } }

.more { display: grid; place-items: center; min-height: 72px; margin-top: 24px; color: var(--muted); }

.empty {
  grid-column: 1 / -1;
  padding: 56px 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
}
.empty strong { display: block; margin-bottom: 4px; color: var(--ink); font-size: 17px; }
.empty.error strong { color: var(--accent); }

/* Buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: opacity .15s, background .15s;
}
.button:hover { opacity: .86; }
.button.secondary { background: none; border-color: var(--line); color: var(--ink); }
.button.secondary:hover { border-color: var(--ink); opacity: 1; }
.button[disabled] { opacity: .5; cursor: progress; }

/* Photo search */

.photo-layout { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 28px; align-items: start; }
.photo-side { position: sticky; top: 84px; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 44px 24px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.dropzone svg { width: 34px; height: 34px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dropzone strong { font-size: 17px; }
.dropzone span { color: var(--muted); }
.dropzone small { margin-top: 6px; color: var(--muted); font-size: 12.5px; }

.preview { display: flex; flex-direction: column; gap: 16px; }
.preview-frame {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.preview-frame img { width: 100%; }
.preview-frame.busy img { opacity: .55; }
.preview-frame.busy::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 35%, rgb(255 255 255 / 45%) 50%, transparent 65%) 0 0 / 300% 100%;
  animation: shimmer 1.1s linear infinite;
}
.box {
  position: absolute;
  border: 2px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 0 0 1px rgb(255 255 255 / 70%);
  pointer-events: none;
}
.box span {
  position: absolute;
  top: -2px;
  left: -2px;
  padding: 1px 7px;
  border-radius: 8px 0 8px 0;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
}

.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { font-weight: 500; overflow-wrap: anywhere; }

/* Product dialog */

dialog {
  width: min(960px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 80px rgb(0 0 0 / 35%);
  overflow: auto;
}
dialog::backdrop { background: rgb(12 12 14 / 55%); backdrop-filter: blur(3px); }
dialog[open] { animation: pop .18s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } }

.close { position: absolute; top: 10px; right: 10px; z-index: 1; background: var(--surface); }

.product { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
.gallery { padding: 24px; background: var(--tile); }
.gallery-main { position: relative; display: grid; place-items: center; aspect-ratio: 4 / 3; }
.gallery-main img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.gallery-main.missing::after { content: "нет фото"; color: #a3a2ab; }
.gallery-main.missing img { display: none; }
.gallery-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.thumb {
  width: 64px;
  height: 48px;
  padding: 3px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb[aria-pressed="true"] { border-color: #16161a; }

.product-info { display: flex; flex-direction: column; gap: 10px; padding: 40px 28px 28px; }
.product-info h2 { font-size: 24px; line-height: 1.2; letter-spacing: -0.015em; }
.product-info .facts { margin-top: 10px; padding-top: 16px; border-top: 1px solid var(--line); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: auto; padding-top: 24px; }

/* Footer */

.footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: #3fb26f; }
.dot.down { background: var(--accent); }

@media (max-width: 860px) {
  .topbar { gap: 12px; }
  .topbar-note { display: none; }
  .photo-layout { grid-template-columns: 1fr; }
  .photo-side { position: static; }
  .product { grid-template-columns: 1fr; }
  .product-info { padding: 24px 20px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
