/* Jomla DZ catalogue — Telegram Mini App and website. Telegram injects --tg-theme-* variables; the web uses
   our own palette, light or dark. */
:root {
  --brand: #1f6f5c; --brand-2: #2a8a72; --gold: #e0a400;
  --bg: var(--tg-theme-secondary-bg-color, #f3f1ec);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --fg: var(--tg-theme-text-color, #1b1b19);
  --muted: var(--tg-theme-hint-color, #6b675e);
  --link: var(--tg-theme-link-color, #1f6f5c);
  --accent: var(--tg-theme-button-color, #1f6f5c);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--fg) 10%, transparent);
  --soft: color-mix(in srgb, var(--accent) 10%, var(--card));
  --danger: #c2410c;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #121311; --card: #1c1d1a; --fg: #f1efe9; --muted: #a29e94; --link: #6cd3b6; --accent: #2f9c80;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 15px/1.55 Cairo, system-ui, "Segoe UI", Tahoma, sans-serif; min-height: 100vh; overscroll-behavior-y: contain; }
a { color: var(--link); text-decoration: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
img { display: block; }
bdi { unicode-bidi: isolate; }
.muted { color: var(--muted); }

/* ---------- header and search ---------- */
.top { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: 10px 16px 8px;
       padding-top: max(10px, env(safe-area-inset-top)); }
.top-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--fg); font-weight: 800; font-size: 18px; }
.brand img { border-radius: 9px; }
.top-row .spacer { flex: 1; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--accent);
       color: var(--accent-fg); font-weight: 700; border-radius: 12px; padding: 11px 16px; min-height: 44px; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 13px; border-radius: 10px; }
.btn.ghost { background: var(--soft); color: var(--fg); }
.btn.wa { background: #1fa855; color: #fff; }
.btn:active { transform: scale(.98); }
.search { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 14px; padding: 0 12px;
          box-shadow: var(--shadow); height: 48px; }
.search input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--fg); font: inherit; font-size: 16px; min-width: 0; }
.search input::placeholder { color: var(--muted); }
.search .icon { font-size: 18px; opacity: .7; }
.search .filter { position: relative; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; }
.search .filter .dot { position: absolute; top: 6px; left: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.search .clear { width: 30px; height: 30px; border-radius: 50%; background: var(--soft); font-size: 14px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px 4px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; background: var(--card); border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: 14px;
        box-shadow: var(--shadow); white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-fg); }
.chip small { opacity: .7; font-weight: 400; }

/* ---------- results grid ---------- */
.bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 16px 2px; font-size: 13px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 8px 16px 24px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 960px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 1200px; margin: 0 auto; } }
.tile { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); color: var(--fg);
        display: flex; flex-direction: column; text-align: right; position: relative; }
.tile:active { transform: scale(.985); }
.ph { aspect-ratio: 1 / 1; width: 100%; background: var(--soft); display: grid; place-items: center; font-size: 40px; overflow: hidden; }
.ph img { width: 100%; height: 100%; object-fit: cover; }
.tile .body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.tile .name { font-weight: 700; font-size: 14px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2;
              -webkit-box-orient: vertical; overflow: hidden; min-height: 2.7em; }
.price { font-weight: 800; color: var(--brand); font-size: 17px; }
:root.tg .price, :root:not(.tg) .price { color: var(--accent); }
.price small { font-weight: 600; font-size: 12px; color: var(--muted); }
.price.none { font-size: 13px; color: var(--muted); font-weight: 600; }
.tile .meta { font-size: 12px; color: var(--muted); display: flex; gap: 4px; flex-wrap: wrap; }
.tile .merchant { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.badge.ad { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.6); color: #fff; }
.badge.mq { background: var(--soft); color: var(--fg); }
.skel { background: linear-gradient(90deg, var(--soft) 25%, var(--card) 50%, var(--soft) 75%); background-size: 200% 100%;
        animation: sh 1.2s infinite; border-radius: 8px; }
@keyframes sh { to { background-position: -200% 0; } }
.empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty .big { font-size: 48px; }
.more { display: block; margin: 0 auto 32px; }

/* ---------- offer and merchant pages ---------- */
.page { padding-bottom: 110px; max-width: 760px; margin: 0 auto; }
.hero { width: 100%; aspect-ratio: 1 / 1; max-height: 70vh; object-fit: contain; background: #000; }
.hero-wrap { background: #000; display: flex; align-items: center; justify-content: center; height: min(52vh, 420px);
             overflow: hidden; font-size: 72px; }
.hero-wrap img { max-width: 100%; max-height: 100%; object-fit: contain; }
.hero-ph { aspect-ratio: 16 / 9; display: grid; place-items: center; font-size: 72px; background: var(--soft); }
.section { background: var(--card); margin: 10px 12px; border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.section h1 { font-size: 20px; line-height: 1.35; margin: 0 0 4px; }
.section h2 { font-size: 16px; margin: 0 0 8px; }
.section .price { font-size: 26px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.fact { background: var(--soft); border-radius: 12px; padding: 8px 10px; font-size: 13px; }
.fact b { display: block; font-size: 15px; }
.mrow { display: flex; align-items: center; gap: 12px; color: var(--fg); }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: var(--soft); display: grid; place-items: center;
          font-weight: 800; font-size: 20px; overflow: hidden; flex: none; color: var(--accent); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.mrow .grow { flex: 1; min-width: 0; }
.mrow .n { font-weight: 800; }
.trust { font-size: 13px; padding: 10px 12px; border-radius: 12px; margin-top: 10px; background: var(--soft); }
.trust.warn { background: color-mix(in srgb, var(--danger) 14%, var(--card)); }
.post { white-space: pre-wrap; font-size: 14px; color: var(--fg); max-height: 9em; overflow: hidden; position: relative; }
.post.open { max-height: none; }
.post:not(.open)::after { content: ""; position: absolute; inset: auto 0 0 0; height: 3em; background: linear-gradient(transparent, var(--card)); }
.linkbtn { color: var(--link); font-weight: 700; margin-top: 6px; }
.actions { position: fixed; inset: auto 0 0 0; z-index: 20; display: flex; gap: 8px; padding: 10px 12px;
           padding-bottom: max(10px, env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 92%, transparent);
           backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
.actions .btn { flex: 1; }
.actions .icon-btn { flex: none; width: 48px; min-height: 48px; border-radius: 12px; background: var(--soft); font-size: 20px; display: grid; place-items: center; }
.actions .icon-btn.on { background: var(--accent); color: var(--accent-fg); }
.safety { font-size: 12px; color: var(--muted); padding: 4px 16px 16px; text-align: center; }

/* ---------- sheet and toast ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; }
.sheet[hidden] { display: none; }
.sheet .panel { background: var(--card); width: 100%; max-width: 760px; margin: 0 auto; border-radius: 20px 20px 0 0;
                padding: 8px 16px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); max-height: 85vh; overflow: auto;
                animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { margin: 4px 0 8px; font-size: 16px; }
.sheet .opts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.sheet .opts .chip { box-shadow: none; background: var(--soft); }
.sheet .opts .chip.on { background: var(--accent); color: var(--accent-fg); }
.sheet .row { display: flex; gap: 8px; margin-top: 8px; }
.sheet .row .btn { flex: 1; }
.toast { position: fixed; z-index: 60; left: 50%; bottom: 90px; transform: translateX(-50%); background: rgba(20,20,20,.92);
         color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 600; max-width: 90vw; text-align: center; }

/* ---------- server-rendered pages (/o/, /m/) ---------- */
body.ssr .top { display: flex; align-items: center; justify-content: space-between; }
body.ssr .page { padding: 0 16px 32px; }
body.ssr .offer-page .hero { border-radius: var(--radius); margin-top: 8px; max-height: 60vh; }
body.ssr .facts { display: flex; flex-direction: column; gap: 6px; }
body.ssr .price.big { font-size: 28px; }
body.ssr .actions { position: static; background: none; border: 0; flex-direction: column; padding: 12px 0; backdrop-filter: none; }
body.ssr .grid { padding: 8px 0; }
body.ssr .tile i { aspect-ratio: 1 / 1; background: var(--soft); display: block; }
body.ssr .tile img { aspect-ratio: 1 / 1; object-fit: cover; width: 100%; }
body.ssr .tile b { padding: 6px 10px 0; font-size: 14px; }
body.ssr .tile .price { padding: 0 10px 10px; }
body.ssr details.post { white-space: pre-wrap; max-height: none; }
body.ssr .foot { font-size: 12px; color: var(--muted); padding: 16px; text-align: center; border-top: 1px solid var(--line); }
