/* ---------- Fonts ---------- */
@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Medium.woff2') format('woff2');
  font-weight: 500; font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700; font-display: swap;
}

/* ---------- Theme ---------- */
:root {
  --bg: #f2f4f9;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --border: #e3e7f0;
  --fg: #141a26;
  --muted: #6f7a90;
  --accent: #4f46e5;
  --accent-soft: #ecebfd;
  --accent-ink: #ffffff;
  --success: #0f9d76;
  --success-bg: #e3f7f0;
  --danger: #dc3b45;
  --danger-bg: #fdeced;
  --warn: #c47a00;
  --warn-bg: #fdf3e0;
  --shadow-sm: 0 1px 2px rgba(20, 26, 38, .06);
  --shadow: 0 4px 16px rgba(20, 26, 38, .07);
  --shadow-lg: 0 12px 32px rgba(20, 26, 38, .18);
  --radius: 18px;
  --radius-sm: 12px;
  --nav-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0e14;
    --surface: #161a23;
    --surface-2: #1e232f;
    --border: #272d3b;
    --fg: #eaeef7;
    --muted: #8d99b0;
    --accent: #8b87ff;
    --accent-soft: #221f3d;
    --accent-ink: #0b0e14;
    --success: #34d8a4;
    --success-bg: #11302a;
    --danger: #ff6b72;
    --danger-bg: #3a1d1f;
    --warn: #f0b453;
    --warn-bg: #33290f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 4px 16px rgba(0, 0, 0, .45);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Vazirmatn', system-ui, 'Tahoma', sans-serif;
  background: var(--bg);
  color: var(--fg);
  direction: rtl;
  line-height: 1.65;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 640px;
  margin-inline: auto;
  padding: 0 14px calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px);
}
body.no-nav .wrap { padding-bottom: 40px; }

/* ---------- App bar ---------- */
.hero {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: calc(env(safe-area-inset-top) + 14px) 16px 12px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow-sm);
}
.hero .brand {
  width: 42px; height: 42px; flex: none;
  display: grid; place-items: center;
  font-size: 1.3rem; border-radius: 13px;
  background: var(--accent-soft); color: var(--accent);
}
.hero .titles { min-width: 0; flex: 1; }
.hero h1 {
  margin: 0; font-size: 1.06rem; font-weight: 700; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hero p {
  margin: 1px 0 0; color: var(--muted); font-size: .82rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hero .act {
  flex: none; width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center; font-size: 1.05rem;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--fg); text-decoration: none; cursor: pointer;
}
.hero form { margin: 0; display: flex; }

/* ---------- Bottom navigation ---------- */
.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
@supports (backdrop-filter: blur(1px)) {
  .tabbar {
    background: color-mix(in srgb, var(--surface) 86%, transparent);
    backdrop-filter: saturate(180%) blur(18px);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
  }
}
.tabbar a {
  flex: 1; min-height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none;
  font-size: .72rem; font-weight: 500;
}
.tabbar a .ico { font-size: 1.22rem; line-height: 1.1; }
.tabbar a.on { color: var(--accent); }
.tabbar a:active { background: var(--surface-2); }

/* ---------- Search ---------- */
.searchbox { position: relative; margin-top: 14px; }
.searchbox .icon {
  position: absolute; inset-inline-start: 14px; top: 50%; transform: translateY(-50%);
  font-size: 1.05rem; opacity: .55; pointer-events: none;
}
input, select, textarea, button { font-family: inherit; font-size: inherit; }
input[type=text], input[type=password], input[type=number], input[type=search] {
  width: 100%; font-size: 1rem; color: var(--fg);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 13px 42px 13px 14px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input { padding-inline-start: 14px; padding-inline-end: 14px; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; }
#q { font-size: 1.05rem; box-shadow: var(--shadow); border-radius: var(--radius); padding-block: 15px; }

/* ---------- Public result cards ---------- */
#results { margin-top: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 16px; margin-top: 10px;
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card .info { min-width: 0; }
.card .name { font-size: 1.05rem; font-weight: 700; overflow-wrap: anywhere; }
.card .price { color: var(--accent); font-weight: 700; margin-top: 1px; }
.card .price small { color: var(--muted); font-weight: 400; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  font-size: .82rem; font-weight: 500; padding: 5px 11px; border-radius: 999px;
}
.badge.ok { color: var(--success); background: var(--success-bg); }
.badge.low { color: var(--warn); background: var(--warn-bg); }
.badge.out { color: var(--danger); background: var(--danger-bg); }

/* ---------- List rows ---------- */
.prow {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 15px; margin-top: 10px;
  box-shadow: var(--shadow-sm);
}
.prow .head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.prow .name { font-size: 1.02rem; font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.prow .meta {
  color: var(--muted); margin-top: 5px;
  display: flex; gap: 4px 14px; flex-wrap: wrap; font-size: .86rem;
}
.prow .meta .price { color: var(--accent); font-weight: 600; }
.prow .actions { display: flex; gap: 8px; margin-top: 12px; }
.prow .actions form { margin: 0; flex: 1; display: flex; }
.prow .actions > a, .prow .actions button { flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit; font-size: .94rem; font-weight: 500;
  padding: 11px 16px; border: 1px solid transparent; border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  white-space: nowrap; transition: transform .06s, filter .15s;
}
.btn:active { transform: scale(.975); }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.btn.ghost { background: var(--surface-2); color: var(--fg); border-color: var(--border); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.block { width: 100%; padding: 14px; font-size: 1rem; }
.btn.sm { padding: 9px 12px; font-size: .86rem; }

/* Floating action button */
.fab {
  position: fixed; inset-inline-end: 16px;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 25;
  height: 54px; padding: 0 20px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: .98rem; text-decoration: none;
  box-shadow: var(--shadow-lg);
}
.fab:active { transform: scale(.96); }
/* keeps the last row clear of the floating button */
.fab-space { height: 74px; }

/* ---------- Chips ---------- */
.chip-row {
  display: flex; gap: 8px; margin-top: 14px;
  overflow-x: auto; scrollbar-width: none; padding-bottom: 2px;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: .88rem; line-height: 1.65;
  padding: 8px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--fg); text-decoration: none;
  cursor: pointer; user-select: none;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip.on a { color: inherit; text-decoration: none; opacity: .75; }

/* ---------- Panels & forms ---------- */
.panel, .range-form {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-top: 14px; box-shadow: var(--shadow-sm);
}
.field { margin-top: 14px; }
.panel .field:first-of-type, .range-form .field:first-of-type { margin-top: 0; }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.field .hint { color: var(--muted); font-size: .78rem; margin-top: 5px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.grid2 .field { margin-top: 0; }

/* ---------- Autocomplete ---------- */
.suggest-wrap { position: relative; }
.suggest {
  position: absolute; inset-inline: 0; top: calc(100% + 6px); z-index: 15;
  margin: 0; padding: 4px; list-style: none;
  max-height: 232px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
}
.suggest li {
  padding: 11px 12px; border-radius: 9px; cursor: pointer;
  font-size: .95rem; overflow-wrap: anywhere;
}
.suggest li:hover, .suggest li:focus { background: var(--accent-soft); color: var(--accent); outline: none; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stats.two { grid-template-columns: repeat(2, 1fr); }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 8px; text-align: center;
  box-shadow: var(--shadow-sm); min-width: 0;
}
.stat .num {
  font-size: 1.08rem; font-weight: 700; letter-spacing: -.02em;
  overflow-wrap: anywhere; line-height: 1.35;
}
.stat .lbl { color: var(--muted); font-size: .74rem; margin-top: 1px; }

/* ---------- Buyer breakdown ---------- */
.fold {
  margin-top: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.fold summary {
  padding: 13px 16px; font-weight: 600; cursor: pointer; list-style: none;
  display: flex; align-items: center; gap: 8px;
}
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after { content: '⌄'; color: var(--muted); font-size: 1.15rem; line-height: 1; }
.fold[open] summary::after { content: '⌃'; }
.fold summary .count {
  background: var(--surface-2); color: var(--muted);
  border-radius: 999px; padding: 1px 9px; font-size: .78rem; margin-inline-end: auto;
}
.buyer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-top: 1px solid var(--border);
  color: inherit; text-decoration: none;
}
.buyer:active { background: var(--surface-2); }
.buyer .who { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.buyer .figs { text-align: end; flex: none; }
.buyer .figs b { display: block; color: var(--accent); font-size: .95rem; }
.buyer .figs small { color: var(--muted); font-size: .76rem; }

/* ---------- Alerts ---------- */
.alert { border-radius: var(--radius-sm); padding: 11px 14px; margin-top: 13px; font-size: .9rem; font-weight: 500; }
.alert.error { color: var(--danger); background: var(--danger-bg); }
.alert.success { color: var(--success); background: var(--success-bg); }
.alert.warn { color: var(--warn); background: var(--warn-bg); }

.flash {
  border-radius: var(--radius-sm); padding: 12px 15px; margin-top: 14px;
  color: var(--success); background: var(--success-bg); font-weight: 500; font-size: .92rem;
}

/* ---------- Misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 44px 16px; }
.empty .em { font-size: 2.1rem; display: block; margin-bottom: 6px; }

.pager { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; margin-top: 18px; }
.pager .pg {
  font-family: inherit; font-size: .9rem; min-width: 44px; padding: 10px 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--fg);
  border-radius: var(--radius-sm); cursor: pointer; text-decoration: none; text-align: center;
}
.pager .pg.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; cursor: default; }
.pager .pg[disabled], .pager .pg[aria-disabled="true"] { opacity: .4; cursor: default; pointer-events: none; }
.pager .dots { color: var(--muted); padding: 0 2px; }

.link { color: var(--accent); text-decoration: none; font-weight: 500; }
.center { text-align: center; }
.mt { margin-top: 14px; }

@media (min-width: 620px) {
  .stat .num { font-size: 1.22rem; }
  .prow .actions form { flex: 0 1 auto; }
  .prow .actions > a, .prow .actions button { flex: 0 1 auto; }
}
