:root {
  --accent: #0f7a5c;
  --bg: #f3f5f4;
  --surface: #ffffff;
  --text: #17201c;
  --muted: #66736d;
  --line: #e2e8e5;
  --sale: #c62f2f;
  --sale-bg: #fdeceb;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 8px 24px rgba(16, 24, 20, .06);
  --radius: 18px;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #18201c;
    --text: #eef3f0;
    --muted: #9aa8a1;
    --line: #26312c;
    --sale: #ff7b72;
    --sale-bg: #3a1d1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --accent-soft: color-mix(in srgb, var(--accent) 25%, transparent);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: justify-content .2s;
  overflow-x: clip;
}
body.has-query .app { justify-content: flex-start; }

/* ---------- الواجهة الأولى ---------- */
.hero { text-align: center; margin-bottom: 28px; transition: all .25s ease; }
.logo { max-height: 72px; max-width: 220px; object-fit: contain; }
.logo-mark {
  width: 64px; height: 64px; margin: 0 auto;
  display: grid; place-items: center;
  border-radius: 20px;
  background: var(--accent); color: #fff;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 35%, transparent);
}
.store-name { font-size: 1.75rem; font-weight: 700; margin: 16px 0 6px; letter-spacing: -.01em; }
.welcome { margin: 0; color: var(--muted); font-size: 1.05rem; }

body.has-query .hero { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; text-align: start; }
body.has-query .logo-mark { width: 36px; height: 36px; border-radius: 11px; margin: 0; box-shadow: none; }
body.has-query .logo-mark svg { width: 20px; height: 20px; }
body.has-query .logo { max-height: 36px; }
body.has-query .store-name { font-size: 1.1rem; margin: 0; }
body.has-query .welcome { display: none; }

/* ---------- خانة البحث ---------- */
.search {
  position: sticky; top: 10px; z-index: 5;
  display: flex; align-items: center;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 6px;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}
.search:focus-within { border-color: var(--accent); }
.search-icon { display: grid; place-items: center; color: var(--muted); padding: 0 12px 0 6px; }
.search input {
  flex: 1; min-width: 0;
  border: 0; outline: 0; background: transparent;
  font: inherit; font-size: 1.1rem; color: var(--text);
  padding: 12px 0;
}
.search input::placeholder { color: var(--muted); opacity: .8; }
.search input::-webkit-search-cancel-button { display: none; }
.clear-btn {
  border: 0; background: transparent; color: var(--muted);
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
}
.clear-btn:hover { background: var(--bg); }
.scan-btn {
  display: flex; align-items: center; gap: 6px;
  border: 0; border-radius: 999px;
  background: var(--accent); color: #fff;
  padding: 11px 18px; font-weight: 600; font-size: 1rem;
  flex-shrink: 0;
}
.scan-btn:active, .photo-btn:active { transform: scale(.97); }
.photo-btn {
  display: flex; align-items: center; gap: 6px;
  border: 0; border-radius: 999px; margin-inline-end: 6px;
  background: var(--accent-soft); color: var(--accent);
  padding: 11px 14px; font-weight: 600; font-size: 1rem; flex-shrink: 0;
}

/* ---------- النتائج ---------- */
.results { margin-top: 16px; min-width: 0; }
.status-msg { text-align: center; color: var(--muted); padding: 36px 12px; }
.status-msg strong { display: block; color: var(--text); font-size: 1.1rem; margin-bottom: 4px; }
.count { color: var(--muted); font-size: .9rem; margin: 2px 6px 10px; }

.list { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
.item {
  display: flex; align-items: center; gap: 14px;
  width: 100%; min-width: 0; text-align: start;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 10px; box-shadow: var(--shadow);
}
.item:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.thumb {
  width: 64px; height: 64px; flex-shrink: 0;
  border-radius: 12px; background: #fff; overflow: hidden;
  display: grid; place-items: center; color: #c5cfca;
  border: 1px solid var(--line);
}
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.item-body { flex: 1; min-width: 0; display: block; overflow: hidden; }
.item-title { font-weight: 600; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item-sub { display: block; color: var(--muted); font-size: .85rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: ltr; text-align: right; }
.item-price { display: block; text-align: center; flex-shrink: 0; min-width: 76px; }
.item-price .now { font-weight: 700; font-size: 1.15rem; white-space: nowrap; }
.item-price .was { color: var(--muted); text-decoration: line-through; font-size: .85rem; }
.item-price .tag { display: inline-block; margin-top: 3px; background: var(--sale-bg); color: var(--sale); border-radius: 999px; padding: 1px 8px; font-size: .78rem; font-weight: 700; }
.cur { font-size: .7em; font-weight: 500; color: var(--muted); margin-inline-start: 2px; }

/* ---------- بطاقة المنتج ---------- */
.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: transparent; color: var(--accent);
  font-weight: 600; padding: 6px 4px; margin-bottom: 8px;
}
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise .25s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card-media {
  background: #fff; position: relative; overflow: hidden;
  height: 280px; width: 100%;
  border-bottom: 1px solid var(--line); color: #c5cfca;
}
.card-media img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain; padding: 16px; box-sizing: border-box;
}
.card-media > svg { position: absolute; inset: 0; margin: auto; }
.badge {
  position: absolute; z-index: 1; top: 14px; inset-inline-start: 14px;
  background: var(--sale); color: #fff; font-weight: 700;
  border-radius: 999px; padding: 6px 14px; font-size: 1rem;
  box-shadow: 0 4px 14px rgba(198, 47, 47, .35);
}
.card-body { padding: 18px 20px 22px; }
.brand { display: inline-block; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: .82rem; border-radius: 999px; padding: 3px 12px; margin-bottom: 10px; }
.title-ar { font-size: 1.4rem; font-weight: 700; line-height: 1.5; margin: 0; }
.title-en { color: var(--muted); direction: ltr; text-align: right; margin: 4px 0 0; font-size: .98rem; }

.price-box {
  margin-top: 18px; padding: 16px 18px;
  border-radius: 14px; background: var(--bg);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.price-box.on-sale { background: var(--sale-bg); }
.price-label { color: var(--muted); font-size: .9rem; }
.price-now { font-size: 2.3rem; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.on-sale .price-now { color: var(--sale); }
.price-now .cur { font-size: 1rem; }
.price-was { text-align: end; }
.price-was s { color: var(--muted); font-size: 1.15rem; }
.save { display: block; color: var(--sale); font-weight: 600; font-size: .92rem; margin-top: 2px; }

.meta { margin-top: 16px; display: grid; gap: 8px; font-size: .92rem; }
.meta div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed var(--line); padding-bottom: 8px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-weight: 500; text-align: end; }
.mono { direction: ltr; font-variant-numeric: tabular-nums; letter-spacing: .03em; }
.desc { margin-top: 14px; color: var(--muted); line-height: 1.8; font-size: .95rem; }
.archived-note { margin-top: 12px; font-size: .85rem; color: var(--muted); }

.new-search {
  display: block; width: 100%; margin-top: 14px;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 14px; padding: 13px; font-weight: 600;
}

/* ---------- الكاميرا ---------- */
.scanner {
  position: fixed; inset: 0; z-index: 50;
  background: #000; color: #fff;
  display: flex; flex-direction: column;
}
.scanner-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  font-weight: 600;
}
.scanner-close { border: 0; background: rgba(255,255,255,.14); color: #fff; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; }
.scanner-view { position: relative; flex: 1; overflow: hidden; display: grid; place-items: center; }
#nativeVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute; z-index: 1; width: min(82vw, 380px); height: min(36vw, 170px);
  border-radius: 18px; box-shadow: 0 0 0 9999px rgba(0,0,0,.45);
  border: 3px solid rgba(255,255,255,.9); pointer-events: none;
}
.scan-frame i {
  position: absolute; left: 8%; right: 8%; top: 50%; height: 2px;
  background: #ff4d4d; box-shadow: 0 0 12px #ff4d4d;
  animation: scanline 1.6s ease-in-out infinite;
}
@keyframes scanline { 0%, 100% { transform: translateY(-55px); } 50% { transform: translateY(55px); } }
.scanner-msg { text-align: center; min-height: 1.5em; padding: 14px 20px 6px; margin: 0; color: #dfe6e2; }
.scanner-actions { text-align: center; padding: 6px 16px calc(18px + env(safe-area-inset-bottom)); }
.scanner-alt { border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.08); color: #fff; border-radius: 999px; padding: 10px 18px; font-size: .95rem; }

@media (max-width: 420px) {
  .scan-btn span, .photo-btn span { display: none; }
  .scan-btn, .photo-btn { padding: 11px 12px; }
  .search-icon { padding: 0 8px 0 4px; }
  .price-now { font-size: 2rem; }
  .title-ar { font-size: 1.25rem; }
  .store-name { font-size: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
