:root {
  --bg: #f2f4f8;
  --panel: #ffffff;
  --line: #d9dfe8;
  --text: #17202b;
  --muted: #66707e;
  --accent: #0e6db5;
  --accent-soft: #e3f0fb;
  --dark: #0f1b2d;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; width: 100%; max-width: 100%; overflow-x: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
}
body.locked { overflow: hidden; }
button { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--dark); color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px;
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; }
.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; }
.lang-switch { display: flex; gap: 4px; }
.lang-switch button {
  border: 1px solid rgba(255,255,255,.25); background: transparent; color: #dfe7f2;
  border-radius: 7px; min-width: 40px; min-height: 32px; font-size: 13px; padding: 2px 8px;
}
.lang-switch button.on { background: #fff; color: var(--dark); font-weight: 700; }
.searchrow { display: flex; gap: 6px; margin-top: 8px; }
.searchrow input {
  flex: 1; min-height: 44px; border: 0; border-radius: 9px; padding: 8px 12px; font-size: 16px;
}
.iconbtn {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 9px; min-width: 44px; min-height: 44px; font-size: 17px; cursor: pointer;
}
.iconbtn.ghost { background: rgba(255,255,255,.14); border-color: transparent; color: #fff; }
.chiprow {
  display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch; padding-bottom: 2px;
}
.chiprow::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid rgba(255,255,255,.25); background: transparent;
  color: #dfe7f2; border-radius: 999px; min-height: 34px; padding: 5px 13px; font-size: 13px;
  cursor: pointer; white-space: nowrap;
}
.chip.on { background: #fff; color: var(--dark); border-color: #fff; font-weight: 700; }

/* ---------- grid ---------- */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px; padding: 8px;
}
@media (min-width: 720px) { .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; cursor: pointer; display: flex; flex-direction: column;
}
.card:active { transform: scale(.985); }
.card .media { position: relative; width: 100%; aspect-ratio: 3 / 4; background: #e7ebf1; }
.card .media img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s; }
.card .media img.ok { opacity: 1; }
.card .media .vidbadge {
  position: absolute; right: 6px; bottom: 6px; background: rgba(10,16,24,.75); color: #fff;
  border-radius: 999px; font-size: 11px; padding: 3px 8px; font-weight: 700;
}
.card .cnt {
  position: absolute; left: 6px; top: 6px; background: rgba(10,16,24,.6); color: #fff;
  border-radius: 999px; font-size: 11px; padding: 2px 7px;
}
.card .info { padding: 7px 8px 9px; min-width: 0; }
.card .t {
  font-size: 13px; font-weight: 600; line-height: 1.35; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 2.6em;
}
.card .m { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sentinel { height: 8px; }
.foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 10px 0 calc(18px + var(--safe-b)); }
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 60px 20px; font-size: 15px; }

/* ---------- product sheet ---------- */
.sheetwrap { position: fixed; inset: 0; z-index: 30; }
.sheet-scrim { position: absolute; inset: 0; background: rgba(8,14,22,.55); }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh;
  background: var(--panel); border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column; overscroll-behavior: contain;
}
.sheet-grip { width: 44px; height: 4px; background: var(--line); border-radius: 2px; margin: 8px auto 0; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 14px 8px 16px; border-bottom: 1px solid var(--line);
}
.sheet-head strong { font-size: 16px; line-height: 1.3; min-width: 0; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 14px calc(16px + var(--safe-b)); }
.facts { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.fact {
  border: 1px solid var(--line); background: #f7f9fc; color: #46505e;
  border-radius: 999px; padding: 4px 10px; font-size: 12.5px;
}
.desc { color: #3a4452; font-size: 14px; line-height: 1.55; margin: 0 0 12px; white-space: pre-wrap; }
.actions { display: flex; gap: 8px; margin-bottom: 12px; }
.btn {
  flex: 1; min-height: 48px; border: 0; border-radius: 10px; font-size: 15px; font-weight: 700;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); border: 1px solid #bcd9f2; }
.btn:disabled { opacity: .5; }
.thumbgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.thumbgrid img, .thumbgrid .vwrap { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 8px; background: #e7ebf1; display: block; cursor: zoom-in; }
.thumbgrid video { width: 100%; aspect-ratio: 3 / 4; border-radius: 8px; background: #000; display: block; }

/* ---------- fullscreen viewer ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 40; background: rgba(7,11,17,.97);
  display: flex; flex-direction: column; color: #fff;
}
.viewer-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 6px;
}
.viewer-pos { font-size: 13px; color: #c8d2e0; }
.stage { flex: 1; min-height: 0; overflow: hidden; position: relative; touch-action: pan-y; }
.strip {
  display: flex; height: 100%; will-change: transform;
}
.slide { flex: 0 0 100%; height: 100%; display: grid; place-items: center; position: relative; }
.slide img {
  max-width: 100%; max-height: 100%; object-fit: contain; user-select: none;
  -webkit-user-select: none; transition: opacity .2s; opacity: 0;
}
.slide img.ok { opacity: 1; }
.slide .spin {
  position: absolute; width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.25); border-top-color: #fff;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.viewer-caption {
  padding: 6px 14px calc(10px + var(--safe-b)); text-align: center; font-size: 13px;
  color: #c8d2e0; min-height: 2em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%);
  background: rgba(12,18,28,.92); color: #fff; border-radius: 10px; padding: 10px 16px;
  font-size: 14px; z-index: 60; max-width: 86vw; text-align: center;
}

/* ---------- RTL ---------- */
.sync-notice { margin:8px 0 0; color:var(--muted); font-size:12px; line-height:1.5; }
.sync-notice.stale, .source-warning { color:#8a5300; background:#fff6df; border-radius:8px; padding:8px 10px; }
.source-warning { font-size:13px; line-height:1.6; }
.admin-dialog { border:1px solid var(--line); border-radius:16px; width:min(440px,90vw); max-height:85vh; padding:20px; color:#182739; }
.admin-dialog::backdrop { background:rgba(7,11,17,.55); }
.admin-head { display:flex; justify-content:space-between; align-items:center; }
.admin-head h2 { margin:0 0 16px; font-size:20px; }
.admin-dialog label { display:block; margin-bottom:16px; font-size:14px; }
.admin-dialog input { display:block; box-sizing:border-box; width:100%; min-height:46px; border:1px solid #bdc7d5; border-radius:8px; padding:10px; font:inherit; margin-top:6px; }
#adminControls .btn { width:100%; margin-top:10px; }
#adminMessage { color:#755000; font-size:13px; }
.private-contacts { border:1px solid #d3e3ee; border-radius:10px; padding:12px; margin-bottom:12px; overflow-wrap:anywhere; }
.private-contacts p { margin:6px 0; }
.history-item { border-top:1px solid var(--line); padding:12px 0; overflow-wrap:anywhere; font-size:13px; }
.history-item button { margin-top:8px; }
@media(max-width:480px) { .topbar-row { flex-wrap:wrap; gap:8px; } .topbar-row h1 { font-size:18px; } }

/* ---------- RTL ---------- */
html[dir="rtl"] .topbar-row { flex-direction: row-reverse; }
html[dir="rtl"] body { font-family: Tahoma, "Segoe UI", sans-serif; }

/* ---------- swap panel (phase 3) ---------- */
.swappanel {
  border: 1px solid #cfe3f6; background: #f4f9ff; border-radius: 12px;
  padding: 10px 12px; margin: 0 0 12px;
}
.swaphead { font-weight: 700; font-size: 14.5px; color: #0b5a94; margin-bottom: 8px; }
.swappresets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip.dark {
  border: 1px solid #b9d4ec; background: #fff; color: #22536f; border-radius: 999px;
  min-height: 34px; padding: 5px 12px; font-size: 12.5px; cursor: pointer;
}
.chip.dark:active { background: var(--accent-soft); }
.swapnote { font-size: 12px; color: #8a6d1d; background: #fff8e1; border: 1px solid #f0e0a0;
  border-radius: 8px; padding: 6px 9px; margin: 8px 0; line-height: 1.45; }
.swapstatus { font-size: 13.5px; color: var(--muted); padding: 6px 0; }
.swapout { min-width: 0; }
.swappair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.swapcell { position: relative; min-width: 0; }
.swapcell img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 8px;
  background: #e7ebf1; display: block; }
.swaplabel { text-align: center; font-size: 12px; color: var(--muted); margin-top: 4px; }
.swaplabel.ai { color: #8a4d00; font-weight: 700; }
