*, *::before, *::after { box-sizing: border-box; }
:root {
    --bg: #f3f5f8;
    --card: #ffffff;
    --ink: #17202a;
    --muted: #6b7684;
    --line: #e3e7ed;
    --accent: #0b6bcb;
    --accent-soft: #e8f1fc;
    --call: #1e8e3e;
    --tg: #229ed9;
    --header: #17202a;
    --radius: 12px;
}
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 15px; line-height: 1.45; overflow-x: hidden;
}
body.no-scroll { overflow: hidden; }
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, select { font: inherit; }

/* --- Header --- */
.site-header { background: var(--header); color: #fff; position: sticky; top: 0; z-index: 50; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.header-inner, .search-wrap, .page, .footer-inner { max-width: 1200px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: 8px; }
.logo { color: #fff; display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; min-width: 0; }
.logo span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo-mark { background: #f5a623; color: var(--header); width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; font-size: 18px; flex: none; }
.header-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.lang-switch { display: flex; background: rgba(255,255,255,.1); border-radius: 8px; padding: 2px; }
.lang-switch button { background: none; border: 0; color: #cfd6de; padding: 5px 9px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600; }
.lang-switch button.active { background: #fff; color: var(--header); }
.search-wrap { padding-bottom: 12px; }
.search-box { position: relative; }
.search-box input {
    width: 100%; padding: 13px 40px 13px 42px; border-radius: 10px; border: 0; font-size: 16px;
    background: #fff; color: var(--ink); outline: 3px solid transparent;
}
.search-box input:focus { outline-color: #f5a62388; }
.search-box input::-webkit-search-cancel-button { display: none; }
.search-ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); opacity: .6; }
.photo-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; display: flex; flex-direction: column; gap: 6px; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 28px rgba(15, 23, 42, .22); }
.photo-menu button { display: flex; align-items: center; gap: 8px; padding: 11px 16px; border: 0; border-radius: 9px; background: var(--accent-soft); color: var(--ink); font: inherit; font-weight: 600; font-size: 15px; white-space: nowrap; cursor: pointer; }
.photo-menu button:active { background: #d6e6fb; }
.search-clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border: 0; background: #eef1f4; border-radius: 50%; width: 28px; height: 28px; cursor: pointer; display: none; color: var(--muted); }

/* --- Buttons --- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 16px; border-radius: 10px; border: 0; cursor: pointer; font-weight: 600; color: #fff; background: var(--accent); white-space: nowrap; }
.btn-sm { padding: 7px 11px; font-size: 13px; }
.btn-call { background: var(--call); color: #fff; }
.btn-sell { background: #f5a623; color: #17202a; font-weight: 700; white-space: nowrap; }
@media (max-width: 520px) { #headerCall #headerPhone { display: none; } .header-actions { gap: 6px; } }
.btn-tg { background: var(--tg); color: #fff; }
.btn-outline { background: #fff; color: var(--accent); border: 1.5px solid var(--accent); }

/* --- Page --- */
.page { padding-top: 18px; padding-bottom: 30px; }
.section-title { font-size: 18px; margin: 0 0 12px; }

.group-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.group-tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 16px 6px 13px; border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--card); cursor: pointer; font: inherit; color: var(--ink); transition: border-color .15s, transform .15s; }
.group-tab:hover { border-color: var(--accent); transform: translateY(-1px); }
.group-tab.active { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
.group-ico { font-size: 34px; line-height: 1; }
.group-name { font-size: 15px; font-weight: 700; }
.category-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.cat {
    background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 12px 8px 10px;
    display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; position: relative; color: var(--ink);
    transition: border-color .15s, transform .15s;
}
.cat:hover { border-color: var(--accent); transform: translateY(-1px); }
.cat.active { border-color: var(--accent); background: var(--accent-soft); }
.cat.empty-cat { opacity: .55; }
.cat-ico { font-size: 28px; line-height: 1; }
.cat-img { width: 44px; height: 44px; object-fit: contain; }
.cat-name { font-size: 12.5px; font-weight: 600; text-align: center; line-height: 1.25; }
.cat-count { position: absolute; top: 6px; right: 7px; font-size: 11px; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 22px 0 14px; scroll-margin-top: 130px; }
.toolbar select { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; max-width: 100%; }
.check { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.result-count { margin-left: auto; color: var(--muted); font-size: 14px; }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.card { background: var(--card); border-radius: var(--radius); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; border: 1px solid var(--line); transition: box-shadow .15s, transform .15s; }
.card:hover { box-shadow: 0 6px 20px rgba(23,32,42,.1); transform: translateY(-2px); }
.card-img { aspect-ratio: 4 / 3; background: #f7f8fa; display: grid; place-items: center; overflow: hidden; }
.card-img img { width: 100%; height: 100%; object-fit: contain; }
.noimg { font-size: 44px; opacity: .35; }
.noimg.big { font-size: 90px; }
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card-meta { font-size: 12px; color: var(--muted); }
.card-title { font-size: 14.5px; margin: 0; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-models { font-size: 12.5px; color: #34404d; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-pn { font-size: 12px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.card-foot { margin-top: auto; padding-top: 6px; }
.price { font-size: 18px; font-weight: 800; color: var(--ink); }
.price small { font-size: 12px; font-weight: 600; color: var(--muted); }
.price s { font-size: 13px; color: var(--muted); font-weight: 400; white-space: nowrap; }
.price.ask { font-size: 14px; color: var(--accent); font-weight: 700; }
.price.big { font-size: 26px; margin: 8px 0; }
.card-badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 20px; border: 1px solid var(--line); }
.badge-in { color: #1e8e3e; background: #e6f4ea; border-color: #c7e6d0; }
.badge-out { color: #8a6d00; background: #fff6d6; border-color: #f2e2a4; }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; grid-column: 1 / -1; }
#loadingBox { display: none; }
.more-wrap { text-align: center; margin-top: 18px; }
#moreBtn { display: none; }

.help-card { margin-top: 30px; background: linear-gradient(135deg, #17202a, #2c3e50); color: #fff; border-radius: var(--radius); padding: 20px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; }
.help-card h3 { margin: 0 0 4px; }
.help-card p { margin: 0; color: #cfd6de; }
.help-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.site-footer { background: #fff; border-top: 1px solid var(--line); padding: 22px 0 max(22px, env(safe-area-inset-bottom)); font-size: 14px; }
.footer-brand { font-weight: 800; font-size: 16px; margin-bottom: 6px; }
.footer-about { color: var(--muted); margin: 0 0 8px; }
.footer-rows { display: grid; gap: 3px; }
.footer-copy { color: var(--muted); font-size: 12px; margin-top: 12px; }

/* --- Product modal --- */
.modal { position: fixed; inset: 0; background: rgba(15,20,26,.55); z-index: 100; display: none; overflow-y: auto; padding: 20px 12px; }
.modal.open { display: block; }
.modal-box { background: #fff; max-width: 980px; margin: 0 auto; border-radius: 16px; padding: 22px; position: relative; }
.modal-close { position: absolute; top: 10px; right: 10px; width: 38px; height: 38px; border-radius: 50%; border: 0; background: #eef1f4; cursor: pointer; font-size: 16px; z-index: 2; }
.detail { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; }
.gallery-main { aspect-ratio: 1 / 1; background: #f7f8fa; border-radius: 12px; display: grid; place-items: center; overflow: hidden; }
.gallery-main img { width: 100%; height: 100%; object-fit: contain; cursor: zoom-in; }
.gallery-thumbs { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; }
.gallery-thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 2px solid transparent; cursor: pointer; flex: none; }
.gallery-thumbs img.active { border-color: var(--accent); }
.detail-title { margin: 4px 40px 0 0; font-size: 22px; line-height: 1.25; }
.order-box { background: #f0f7f2; border: 1px solid #cfe8d6; border-radius: 12px; padding: 14px; margin: 16px 0; font-size: 14px; }
.code-chip { margin: 8px 0 10px; background: #fff; border: 1.5px dashed #1e8e3e; border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 15px; }
.order-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.order-actions .btn { flex: 1 1 180px; white-space: normal; text-align: center; }
.specs { width: 100%; border-collapse: collapse; font-size: 14px; }
.specs th, .specs td { text-align: left; padding: 7px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.specs th { color: var(--muted); font-weight: 500; width: 45%; }
.detail h4 { margin: 18px 0 8px; }
.model-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; max-height: 240px; overflow-y: auto; }
.model-list li { background: var(--accent-soft); color: #0b4f96; padding: 4px 9px; border-radius: 6px; font-size: 13px; }
.desc { margin: 0; color: #34404d; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 200; display: none; align-items: center; justify-content: center; padding: 16px; cursor: zoom-out; }
.lightbox.open { display: flex; }
.lightbox img { max-height: 100%; object-fit: contain; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); background: #17202a; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .2s; z-index: 300; pointer-events: none; font-size: 14px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
    .detail { grid-template-columns: 1fr; gap: 14px; }
    .modal { padding: 0; }
    .modal-box { border-radius: 0; min-height: 100%; padding: 16px; padding-top: max(16px, env(safe-area-inset-top)); }
    .gallery-main { aspect-ratio: 4 / 3; }
}
@media (max-width: 520px) {
    #headerPhone { display: none; }
    .logo { font-size: 16px; }
    /* Telefonda kategoriyalar 2 qatorli gorizontal lenta — sahifa uzun bo'lib ketmasligi uchun */
    .category-grid { grid-template-columns: none; grid-auto-flow: column; grid-template-rows: repeat(2, auto); grid-auto-columns: 104px;
        overflow-x: auto; gap: 8px; margin: 0 -16px; padding: 0 16px 6px; scroll-snap-type: x proximity; scrollbar-width: none; }
    .category-grid::-webkit-scrollbar { display: none; }
    .cat { padding: 10px 4px 8px; scroll-snap-align: start; }
    .cat-ico { font-size: 24px; }
    .cat-name { font-size: 11.5px; }
    .product-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .card-body { padding: 8px 9px 10px; }
    .card-title { font-size: 13.5px; }
    .price { font-size: 16px; }
    .toolbar select { flex: 1 1 40%; min-width: 0; }
    .result-count { width: 100%; margin-left: 0; }
}

/* --- Sotuvchi ma'lumoti --- */
.card-seller { font-size: 12px; color: var(--muted); margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seller-line { margin-bottom: 6px; font-size: 15px; }
.order-phone { font-size: 19px; font-weight: 800; margin-bottom: 10px; }
.order-phone a { color: var(--ink); }
.footer-links { margin-top: 10px; }
#moreBtn:disabled { opacity: .6; }
