:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --text: #121417;
  --muted: #687080;
  --border: #e3e6ea;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f4f2;
  --ok: #157f3b;
  --ok-bg: #e3f6e9;
  --zero: #b42318;
  --zero-bg: #fde8e7;
  --mark: #fff1b8;
  --header: rgba(255, 255, 255, 0.92);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.06);
  --radius: 14px;
  color-scheme: light;
}

/* Tungi rejim: tizim sozlamasi bo'yicha, Telegram ichida esa Telegram mavzusi bo'yicha (data-theme) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f12;
    --surface: #171a1f;
    --surface-2: #1d2127;
    --text: #eceef1;
    --muted: #9198a3;
    --border: #2a2f37;
    --accent: #2cc5b2;
    --accent-ink: #062521;
    --accent-soft: rgba(44, 197, 178, 0.14);
    --ok: #5ad48a;
    --ok-bg: rgba(90, 212, 138, 0.13);
    --zero: #ff7b72;
    --zero-bg: rgba(255, 123, 114, 0.13);
    --mark: rgba(250, 204, 21, 0.28);
    --header: rgba(17, 20, 24, 0.92);
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0f12;
  --surface: #171a1f;
  --surface-2: #1d2127;
  --text: #eceef1;
  --muted: #9198a3;
  --border: #2a2f37;
  --accent: #2cc5b2;
  --accent-ink: #062521;
  --accent-soft: rgba(44, 197, 178, 0.14);
  --ok: #5ad48a;
  --ok-bg: rgba(90, 212, 138, 0.13);
  --zero: #ff7b72;
  --zero-bg: rgba(255, 123, 114, 0.13);
  --mark: rgba(250, 204, 21, 0.28);
  --header: rgba(17, 20, 24, 0.92);
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}

button, input, select { font: inherit; color: inherit; }

/* ---------- Header ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--header);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.top-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 16px 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "brand toggle"
    "search search"
    "filters filters";
  align-items: center;
  gap: 10px;
}
.brand { grid-area: brand; }
.chip-toggle { grid-area: toggle; }
.search { grid-area: search; }
.filters { grid-area: filters; }

@media (min-width: 960px) {
  .top-inner {
    grid-template-columns: auto minmax(280px, 1fr) auto auto;
    grid-template-areas: "brand search filters toggle";
    gap: 14px;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
}

.search input {
  width: 100%;
  height: 48px;
  padding: 0 44px 0 44px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 17px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.search input::-webkit-search-cancel-button { display: none; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input::placeholder { color: var(--muted); }

.search-icon {
  position: absolute;
  left: 14px;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

.clear {
  position: absolute;
  right: 6px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.clear:hover { background: var(--surface-2); }
.clear svg { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2.2; stroke-linecap: round; }

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.filters.single { grid-template-columns: 1fr; }
@media (min-width: 960px) {
  .filters { display: flex; }
}
.chip[hidden] { display: none; }

.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  height: 36px;
  padding: 0 8px 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.chip-label { color: var(--muted); flex: none; }
.chip select {
  flex: 1;
  min-width: 0;
  width: 100%;
  border: 0;
  background: transparent;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  padding-right: 2px;
  text-overflow: ellipsis;
}
@media (min-width: 960px) {
  .chip select { width: auto; max-width: 220px; }
}
.chip select option { color: #121417; background: #fff; }
.chip-toggle input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.chip-toggle:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* ---------- List ---------- */

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px calc(28px + env(safe-area-inset-bottom));
}

.status {
  color: var(--muted);
  font-size: 13.5px;
  min-height: 20px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.status:empty { display: none; }

.refresh {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13.5px;
  font-weight: 650;
  padding: 6px 8px;
  margin: -6px -8px -6px 0;
  border-radius: 8px;
  cursor: pointer;
}
.refresh:hover { background: var(--accent-soft); }
.refresh svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.refresh.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.list {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}
@media (min-width: 720px) { .list { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1080px) { .list { grid-template-columns: 1fr 1fr 1fr; } }

.card {
  display: flex;
  gap: 12px;
  align-items: stretch;
  width: 100%;
  text-align: left;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.05s;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.card:active { transform: scale(0.99); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.thumb {
  flex: none;
  width: 76px;
  height: 76px;
  border-radius: 10px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.thumb svg, .hero-img svg { width: 34px; height: 34px; fill: none; stroke: var(--muted); stroke-width: 1.5; opacity: 0.6; }

.info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.name {
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.name mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }

.meta {
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.row {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 4px;
}

.price {
  font-size: 19px;
  font-weight: 750;
  letter-spacing: -0.015em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.price small { font-size: 12.5px; font-weight: 600; color: var(--muted); letter-spacing: 0; }

.qty {
  flex: none;
  font-weight: 700;
  font-size: 14px;
  padding: 4px 10px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.qty.ok { color: var(--ok); background: var(--ok-bg); }
.qty.zero { color: var(--zero); background: var(--zero-bg); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 56px 16px;
}
.empty svg { width: 46px; height: 46px; fill: none; stroke: currentColor; stroke-width: 1.5; opacity: 0.55; margin-bottom: 8px; }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

.error-box {
  border: 1px solid var(--zero);
  background: var(--zero-bg);
  color: var(--text);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.btn {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  padding: 9px 14px;
  cursor: pointer;
  white-space: nowrap;
}

.sentinel { height: 1px; }
.more { margin-top: 14px; }
.more:empty { display: none; }
.btn-more { display: block; margin: 0 auto; padding: 12px 22px; }
.error-box .btn-more { margin: 0; padding: 9px 14px; }
.loading-more { text-align: center; padding: 12px; color: var(--muted); }

.skeleton .thumb, .skeleton .sk {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: sh 1.2s infinite linear;
}
.sk { height: 12px; border-radius: 6px; }
@keyframes sh { to { background-position: -200% 0; } }

/* ---------- Detail sheet ---------- */

.sheet {
  border: 0;
  padding: 0;
  margin: 0;
  width: 100%;
  max-width: 100%;
  max-height: 92vh;
  max-height: 92dvh;
  top: auto;
  bottom: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
.sheet[open] { animation: up 0.22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0.4; } }

@media (min-width: 720px) {
  .sheet {
    width: min(560px, calc(100% - 32px));
    top: 50%;
    bottom: auto;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 20px;
    max-height: 88vh;
  }
  .sheet[open] { animation: none; }
}

.sheet-body {
  max-height: inherit;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 18px calc(22px + env(safe-area-inset-bottom));
}

.sheet-grip {
  width: 40px; height: 5px; border-radius: 3px; background: var(--border);
  margin: 2px auto 6px;
}
@media (min-width: 720px) { .sheet-grip { display: none; } }

.sheet-close {
  position: sticky;
  top: 0;
  float: right;
  margin: 2px -6px 0 0;
  width: 38px; height: 38px;
  border: 0; border-radius: 999px;
  background: var(--surface-2);
  display: grid; place-items: center;
  cursor: pointer;
  z-index: 2;
}
.sheet-close svg { width: 18px; height: 18px; fill: none; stroke: var(--text); stroke-width: 2.2; stroke-linecap: round; }

.hero-img {
  width: 200px;
  height: 200px;
  margin: 6px auto 14px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--border);
  display: grid; place-items: center;
  overflow: hidden;
}
.hero-img img { width: 100%; height: 100%; object-fit: contain; }

.d-name { font-size: 20px; font-weight: 700; line-height: 1.25; margin: 0 0 4px; letter-spacing: -0.01em; word-break: break-word; }
.d-group { color: var(--muted); font-size: 13.5px; margin-bottom: 14px; }

.d-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.d-tile {
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 12px;
  min-width: 0;
}
.d-tile .lbl { color: var(--muted); font-size: 12.5px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-tile .val { font-size: 22px; font-weight: 750; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.d-tile .val small { font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: 0; }
.d-tile.ok .val { color: var(--ok); }
.d-tile.zero .val { color: var(--zero); }

.d-sec { margin: 0 0 18px; }
.d-sec h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 6px; font-weight: 650; }

.d-rows { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.d-r {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.d-r:first-child { border-top: 0; }
.d-r .k { color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.d-r .v { font-weight: 650; text-align: right; white-space: nowrap; }
.d-r.cur { background: var(--accent-soft); }
.d-r.cur .k::after { content: " •"; color: var(--accent); }
.d-r .v.ok { color: var(--ok); }
.d-r .v.zero { color: var(--zero); }
.d-r .v.muted { color: var(--muted); font-weight: 500; }
.d-r .sub { color: var(--muted); font-size: 12px; font-weight: 500; }
.d-r.wrap .v { white-space: normal; overflow-wrap: anywhere; }

.d-loading { color: var(--muted); padding: 12px; font-size: 14px; }

.d-upd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  padding-top: 2px;
}

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