* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  font-family: 'Vazirmatn', system-ui, Tahoma, sans-serif;
  direction: rtl;
  font-size: var(--text-base);
  line-height: 1.8;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  /* room for the fixed tab bar + iOS home indicator */
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--space-4));
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0 0 var(--space-2); line-height: 1.45; font-weight: 700; }
h1 { font-size: var(--text-2xl); letter-spacing: -.02em; }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }
p { margin: 0 0 var(--space-3); }
img { max-width: 100%; }

::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 6px; }

.wrap { width: min(1120px, 100% - var(--space-8)); margin: 0 auto; }
.stack { display: grid; gap: var(--space-4); }
.row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.subtle { color: var(--subtle); font-size: var(--text-sm); }
.center { text-align: center; }
.hide { display: none !important; }

/* ───────────────────────────────────────────────── chrome */
.appbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--nav-h);
  background: var(--nav-bg);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-nav);
  display: flex; align-items: center;
}
.appbar .wrap { display: flex; align-items: center; gap: var(--space-3); }
.brand { display: flex; align-items: center; gap: var(--space-2); font-weight: 800; }
.brand .mark {
  width: 30px; height: 30px; border-radius: var(--radius-sm);
  background: linear-gradient(140deg, var(--green), var(--blue));
  color: #fff; display: grid; place-items: center;
  font-size: var(--text-xs); font-weight: 800; letter-spacing: -.03em;
}
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer;
  font-size: var(--text-md); position: relative; flex: none;
}
.icon-btn:hover { background: var(--fill-3); }
.icon-btn .dot {
  position: absolute; top: -5px; inset-inline-start: -5px;
  min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 999px; background: var(--green); color: var(--on-accent);
  font-size: 10px; font-weight: 700; display: grid; place-items: center;
}

.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 45;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--tabbar-bg);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-tabbar);
  display: flex; align-items: stretch;
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px;
  font-size: var(--text-xs); color: var(--muted);
  transition: color .15s ease;
}
.tabbar a .ico { font-size: var(--text-lg); line-height: 1; }
.tabbar a.on { color: var(--green); font-weight: 700; }
.tabbar .tab-dot {
  position: absolute; transform: translate(14px, -22px);
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px;
  background: var(--green); color: var(--on-accent);
  font-size: 10px; font-weight: 700; display: grid; place-items: center;
}
.tabbar a { position: relative; }

/* ───────────────────────────────────────────────── surfaces */
.card {
  background: var(--surface);
  backdrop-filter: blur(var(--glass-blur)); -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-glass);
  padding: var(--space-5);
}
.card.tight { padding: var(--space-4); }
.hero {
  background: linear-gradient(135deg, var(--hero-start) 0%, var(--hero-mid) 55%, var(--hero-end) 100%);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-2xl);
  padding: var(--space-6);
  color: var(--on-hero);
}

/* ───────────────────────────────────────────────── controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  border: 1px solid transparent; border-radius: var(--radius-md);
  padding: 11px 18px; font: inherit; font-weight: 600;
  background: var(--green); color: var(--on-accent);
  box-shadow: var(--shadow-green); cursor: pointer;
  transition: filter .15s ease, transform .12s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn.ghost { background: var(--surface-2); border-color: var(--border); color: var(--text); box-shadow: none; }
.btn.ghost:hover { background: var(--fill-3); }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); box-shadow: none; }
.btn.sm { padding: 7px 12px; font-size: var(--text-sm); border-radius: var(--radius-sm); }
.btn.block { width: 100%; }

label { display: block; font-size: var(--text-sm); color: var(--muted); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; padding: 11px 14px; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); outline: none;
  transition: border-color .15s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); }
::placeholder { color: var(--subtle); opacity: 1; }
select option { background: var(--surface-solid); color: var(--text); }
.field { margin-bottom: var(--space-3); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-2); font-size: var(--text-sm); cursor: pointer;
  white-space: nowrap;
}
.chip.on { border-color: var(--green-border); background: var(--green-glow); color: var(--green); font-weight: 700; }
.chips { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-xs); padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); background: var(--surface-2);
}
.badge.ok      { color: var(--status-ok);      border-color: var(--green-border); }
.badge.warn    { color: var(--status-warn); }
.badge.danger  { color: var(--status-expired); }
.badge.info    { color: var(--status-info); }
.badge .pulse { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

/* ───────────────────────────────────────────────── catalogue */
.cat-grid {
  display: grid; gap: var(--space-3);
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.cat {
  display: block; padding: var(--space-4);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-glass);
  transition: transform .15s ease, border-color .15s ease;
}
.cat:hover { transform: translateY(-2px); border-color: var(--green-border); }
.cat .emoji { font-size: 26px; line-height: 1; }
.cat .name { font-weight: 700; margin-top: var(--space-2); }
.cat .meta { color: var(--subtle); font-size: var(--text-xs); }

.grid {
  display: grid; gap: var(--space-3);
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
}
.product {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow-glass);
  transition: transform .15s ease, border-color .15s ease;
}
.product:hover { transform: translateY(-2px); border-color: var(--green-border); }
.product .shot {
  aspect-ratio: 1; background: var(--fill-1);
  display: grid; place-items: center; position: relative;
}
.product .shot img { width: 100%; height: 100%; object-fit: contain; }
.product .shot .ar-tag {
  position: absolute; top: 8px; inset-inline-start: 8px;
  font-size: 10px; padding: 3px 8px; border-radius: 999px;
  background: var(--nav-bg); border: 1px solid var(--border); color: var(--text-2);
  backdrop-filter: blur(8px);
}
.product .body { padding: var(--space-3); display: grid; gap: 4px; }
.product .title { font-weight: 600; font-size: var(--text-base); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.product .price { font-weight: 800; color: var(--green); }
.product .shopname { color: var(--subtle); font-size: var(--text-xs); }

.empty { padding: var(--space-8) var(--space-4); text-align: center; color: var(--muted); }
.empty .emoji { font-size: 34px; }

/* ───────────────────────────────────────────────── AR viewer */
model-viewer {
  width: 100%; height: min(58vh, 460px);
  background-color: transparent;
  border-radius: var(--radius-lg);
  --poster-color: transparent;
}
#arOverlay { position: fixed; inset: 0; z-index: 90; display: none; background: #000; }
#arOverlay.on { display: block; }
#arOverlay video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#arOverlay model-viewer { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 0; }
#arOverlay .ar-bar {
  position: absolute; inset-inline: 0; bottom: env(safe-area-inset-bottom, 16px);
  display: flex; justify-content: center; gap: var(--space-2); padding: var(--space-4);
}
#arOverlay .ar-tip {
  position: absolute; top: var(--space-4); inset-inline: 0; text-align: center;
  font-size: var(--text-sm); color: #fff; text-shadow: 0 2px 8px #000; padding: 0 var(--space-4);
}

/* ───────────────────────────────────────────────── misc */
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg);
  padding: var(--space-4); text-align: center; color: var(--muted);
  transition: border-color .15s ease, background .15s ease;
}
.dropzone.over { border-color: var(--green); background: var(--green-glow); }
.dropzone img { max-height: 190px; border-radius: var(--radius-sm); object-fit: contain; }

/* extra capture angles */
.angle-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.angle-slot {
  position: relative; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-md);
  padding: var(--space-2); background: var(--surface-2);
  transition: border-color .15s ease;
}
.angle-slot:hover { border-color: var(--green); }
.angle-slot.filled { border-style: solid; border-color: var(--green-border); }
.angle-slot .ico { font-size: 22px; line-height: 1.6; }
.angle-slot img { width: 100%; aspect-ratio: 1; object-fit: contain; border-radius: var(--radius-sm); }
.angle-slot .lbl { font-size: var(--text-sm); font-weight: 600; margin-top: 2px; }
.angle-slot .rm {
  position: absolute; top: 4px; inset-inline-end: 4px;
  border: 0; border-radius: 8px; padding: 2px 7px; font: inherit; font-size: 11px;
  background: var(--red); color: #fff; cursor: pointer;
}

/* scene composer */
.scene-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) 0; border-bottom: 1px solid var(--border);
}
.scene-row:last-child { border-bottom: 0; }
.scene-row img {
  width: 54px; height: 54px; flex: none; object-fit: contain;
  border-radius: var(--radius-sm); background: var(--fill-1);
}

.toast {
  position: fixed; inset-inline: 0; bottom: calc(var(--tabbar-h) + var(--space-4));
  margin: auto; width: max-content; max-width: 90vw; z-index: 95;
  background: var(--surface-solid); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: var(--radius-md); box-shadow: var(--shadow-card);
  opacity: 0; transform: translateY(12px); transition: .25s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { border-color: var(--red); color: var(--red); }

.list-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) 0; border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: 0; }
.list-row .thumb {
  width: 62px; height: 62px; flex: none; border-radius: var(--radius-sm);
  background: var(--fill-1); object-fit: contain;
}

.stat { text-align: center; padding: var(--space-3); }
.stat .n { font-size: var(--text-2xl); font-weight: 800; color: var(--green); }
.stat .l { font-size: var(--text-xs); color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); }

.skeleton {
  background: linear-gradient(90deg, var(--fill-1), var(--fill-3), var(--fill-1));
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite;
  border-radius: var(--radius-lg);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

@media (max-width: 640px) {
  .wrap { width: calc(100% - var(--space-6)); }
  .grid2 { grid-template-columns: 1fr; }
  .card { padding: var(--space-4); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; transition-duration: .01ms !important;
  }
}
