/* Ozon-style: pink/magenta accent, rounded cards, white surfaces, soft greys.
   Optimized for Telegram WebApp (no fixed positioning that conflicts with TG headers). */
:root {
  --ozon-primary: #f1117e;        /* Ozon pink */
  --ozon-primary-dark: #cc0066;
  --ozon-secondary: #005bff;       /* Ozon blue accent */
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --text: #001a34;
  --text-secondary: #707f8d;
  --text-tertiary: #a0a8b3;
  --border: #ebeef0;
  --shadow: 0 1px 3px rgba(0, 0, 0, .04), 0 1px 2px rgba(0, 0, 0, .03);
  --radius: 10px;
  --radius-lg: 16px;
  --bonus-bg: #5b51de;
  --bonus-text: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161a;
    --surface: #1d1e22;
    --surface-2: #25262c;
    --text: #f3f3f5;
    --text-secondary: #a4a8af;
    --text-tertiary: #707378;
    --border: #2a2c33;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--tg-theme-bg-color, var(--bg));
  color: var(--tg-theme-text-color, var(--text));
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "SF Pro Text", "Helvetica Neue", Onest, sans-serif;
  font-size: 14px; line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  /* Honor iOS/Android safe areas (notch + bottom home indicator) */
  padding-bottom: env(safe-area-inset-bottom, 0);
  overscroll-behavior-y: none;  /* prevent rubber-band */
}

/* ===== top bar ===== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: max(14px, env(safe-area-inset-top, 0px) + 10px) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(8px);
  position: relative;
}
.brand {
  display: flex; align-items: baseline; gap: 8px; justify-content: center;
}
.logo {
  font-weight: 800; font-size: 22px; letter-spacing: -0.5px;
  color: var(--ozon-primary);
}
.tag { color: var(--text-secondary); font-size: 13px; font-weight: 500; }
.stats { display: none; }   /* hide bottom row with the count */
.icon-btn {
  /* Invisible but still clickable (for fullscreen close) — no background, no icon visible. */
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent;
  color: transparent;
  border-radius: 50%; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  opacity: 0;
}
.icon-btn:active { transform: translateY(-50%) scale(0.88); }
.close-btn { font-size: 0; padding: 0; }
.close-btn svg { display: block; }

/* ===== filters ===== */
.filters {
  margin: 8px 12px; padding: 14px;
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
  min-width: 0; max-width: calc(100vw - 24px);
  overflow: hidden;
}
html, body { overflow-x: hidden; max-width: 100vw; }

.search input {
  width: 100%; height: 40px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text); font-size: 14px;
  outline: none; transition: border-color .15s;
}
.search input:focus { border-color: var(--ozon-primary); }

.row {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px;
}
.select {
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
  font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px;
}
.select select, .select input {
  width: 100%; min-width: 0;
  height: 38px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text); font-size: 14px;
  text-transform: none; letter-spacing: normal;
  outline: none;
  text-overflow: ellipsis; overflow: hidden; white-space: nowrap;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%23707f8d' stroke-width='1.6' stroke-linecap='round'><polyline points='1.5,1.5 6,6 10.5,1.5'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
  background-size: 10px;
  padding-right: 28px;
}
.select select:focus, .select input:focus { border-color: var(--ozon-primary); }

/* ===== sliders ===== */
.slider-block { display: flex; flex-direction: column; gap: 4px; }
.slider-head {
  display: flex; justify-content: space-between; align-items: baseline;
}
.slider-label { font-size: 12px; color: var(--text-secondary); }
.slider-value {
  font-weight: 700; color: var(--ozon-primary); font-size: 16px;
  font-variant-numeric: tabular-nums;
}
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; background: var(--border); border-radius: 2px;
  outline: none; padding: 0; margin: 8px 0 4px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--ozon-primary);
  border: 3px solid var(--surface);
  box-shadow: 0 1px 4px rgba(241, 17, 126, .4);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--ozon-primary);
  border: 3px solid var(--surface);
  box-shadow: 0 1px 4px rgba(241, 17, 126, .4);
  cursor: pointer; border-width: 3px;
}
.slider-marks {
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--text-tertiary);
}

/* ===== dual-range slider (price) ===== */
.dual-range {
  position: relative; height: 24px; margin: 8px 0 4px;
}
.dual-track {
  position: absolute; left: 0; right: 0; top: 50%;
  height: 4px; background: var(--border); border-radius: 2px;
  transform: translateY(-50%);
}
.dual-fill {
  position: absolute; top: 50%; height: 4px;
  background: var(--ozon-primary); border-radius: 2px;
  transform: translateY(-50%);
  pointer-events: none;
}
.dual-range input[type="range"] {
  position: absolute; left: 0; right: 0; top: 0; width: 100%;
  margin: 0; height: 24px;
  background: transparent; pointer-events: none;
  -webkit-appearance: none; appearance: none;
}
.dual-range input[type="range"]::-webkit-slider-thumb {
  pointer-events: auto;
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--ozon-primary);
  border: 3px solid var(--surface);
  box-shadow: 0 1px 4px rgba(241, 17, 126, .4);
  cursor: pointer;
  position: relative; z-index: 2;
}
.dual-range input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--ozon-primary); border: 3px solid var(--surface);
  cursor: pointer; box-shadow: 0 1px 4px rgba(241, 17, 126, .4);
}
.dual-range input[type="range"]::-webkit-slider-runnable-track {
  background: transparent; height: 4px;
}
.dual-range input[type="range"]::-moz-range-track {
  background: transparent; height: 4px;
}

.adjusted {
  font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: rgba(241,17,126,.12); color: var(--ozon-primary);
  margin-left: 4px;
}

/* When a slider thumb is at its absolute min/max — show a subtle dot before the value
   so user understands it's the data extreme (no ∞ symbol). */
.slider-value .at-max {
  position: relative;
  padding-left: 9px;
}
.slider-value .at-max::before {
  content: "";
  position: absolute; left: 0; top: 50%;
  width: 5px; height: 5px;
  background: var(--ozon-primary);
  border-radius: 50%;
  transform: translateY(-50%);
  opacity: 0.6;
  box-shadow: 0 0 0 2px rgba(241, 17, 126, .12);
}

.apply {
  height: 44px; border: none; border-radius: var(--radius);
  background: var(--ozon-primary); color: white;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.apply:hover { background: var(--ozon-primary-dark); }
.apply:active { transform: scale(0.99); }

/* ===== results ===== */
.results { padding: 4px 12px 24px; }
.results-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 4px; font-size: 13px; color: var(--text-secondary);
}
.loader {
  font-size: 12px; color: var(--ozon-primary);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 480px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 768px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.card {
  background: var(--surface); border-radius: var(--radius-lg);
  overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  text-decoration: none; color: inherit;
  position: relative; transition: transform .12s;
}
.card:active { transform: scale(0.985); }
.card-img {
  width: 100%; aspect-ratio: 3/4;
  background: var(--surface-2);
  background-size: cover; background-position: center;
}
.bonus-badge {
  position: absolute; left: 8px; bottom: calc(100% / (1 + 4/3) + 8px);
  background: var(--bonus-bg); color: var(--bonus-text);
  border-radius: 8px; padding: 4px 8px;
  font-size: 11px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 4px;
  box-shadow: 0 2px 6px rgba(91, 81, 222, .35);
}
.bonus-badge::before {
  content: "↓"; font-weight: 800;
}
.card-body {
  padding: 8px 10px 12px; display: flex; flex-direction: column; gap: 6px;
  flex: 1;
}
.price-row { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.price { font-size: 17px; font-weight: 700; color: var(--text); }
.ratio {
  margin-left: auto;
  font-size: 11px; padding: 2px 6px; border-radius: 6px;
  background: rgba(241, 17, 126, .1); color: var(--ozon-primary);
  font-weight: 600;
}
.name {
  font-size: 12px; color: var(--text-secondary);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; min-height: 50px;
}
.cat {
  font-size: 10px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.3px;
  margin-top: auto;
}

.more { display: flex; justify-content: center; padding: 16px; }
.more button {
  height: 40px; padding: 0 24px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: 14px;
  cursor: pointer;
}
.more button:hover { border-color: var(--ozon-primary); color: var(--ozon-primary); }

.empty {
  text-align: center; padding: 60px 20px; color: var(--text-secondary);
}
