:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1a1d29;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --border: #e5e7eb;
  --success: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --soft-success: #dcfce7;
  --soft-danger: #fee2e2;
  --soft-warn: #fef3c7;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
}

@font-face {
  font-family: 'Vazirmatn';
  src: url('https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/fonts/webfonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/fonts/webfonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Vazirmatn', Tahoma, system-ui, sans-serif;
  direction: rtl;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }

.container { max-width: 1200px; margin: 0 auto; padding: 16px; }

/* NAV */
.nav {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav h1 { font-size: 18px; margin: 0; margin-left: auto; }
.nav a {
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 500;
}
.nav a:hover { background: var(--accent-light); color: var(--accent); }
.nav a.active { background: var(--accent); color: white; }
.nav .last-sync { color: var(--muted); font-size: 12px; margin-right: 16px; }

/* FILTERS */
.filters {
  background: var(--card);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.filters-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 12px; color: var(--muted); font-weight: 500; }
.filter-group .range { display: flex; gap: 6px; }
.filter-group input, .filter-group select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  background: white;
  min-width: 0;
}
.filter-group input[type="number"] { width: 100%; }
.filter-group input:focus, .filter-group select:focus {
  outline: 2px solid var(--accent-light);
  border-color: var(--accent);
}

/* بخش محله: multi-select با checkbox */
.district-select {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
}
.district-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: #f3f4f6;
  border-radius: 100px;
  cursor: pointer;
  font-size: 12px;
  user-select: none;
  transition: 0.15s;
}
.district-chip.active {
  background: var(--accent);
  color: white;
}
.district-chip input { display: none; }

.checkbox-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.checkbox-row label {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  cursor: pointer;
}

.filters-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 8px;
}
.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
}
.btn:hover { background: #f9fafb; }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: #1e40af; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }

/* OPPORTUNITY TABS */
.opp-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.opp-tab {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: var(--card);
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
}
.opp-tab.active { background: var(--accent); color: white; border-color: var(--accent); }
.opp-tab .count {
  margin-right: 4px;
  opacity: 0.7;
  font-size: 11px;
}

/* STATS BAR */
.stats-bar {
  display: flex;
  gap: 16px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.stats-bar strong { color: var(--text); }

/* LISTINGS */
.listing-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  overflow: hidden;
  transition: 0.15s;
}
.listing-card.inactive { opacity: 0.55; }
.listing-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  cursor: pointer;
}
.listing-row:hover { background: #fafbff; }
.bookmark-btn {
  background: transparent;
  border: none;
  padding: 4px;
  cursor: pointer;
  font-size: 22px;
  color: var(--muted);
  display: flex;
  align-items: center;
}
.bookmark-btn.active { color: #f59e0b; }
.listing-main { min-width: 0; }
.listing-title {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.listing-meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.listing-meta span { white-space: nowrap; }
.listing-meta .pill {
  display: inline-block;
  padding: 1px 6px;
  background: #f3f4f6;
  border-radius: 4px;
}
.listing-prices {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 13px;
  margin-top: 2px;
}
.price-total { font-weight: 700; color: var(--text); font-size: 14px; }
.price-ppm { color: var(--muted); }
.deviation {
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}
.deviation.above { background: var(--soft-danger); color: var(--danger); }
.deviation.below { background: var(--soft-success); color: var(--success); }
.deviation.neutral { background: #f3f4f6; color: var(--muted); }

.listing-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}
.listing-actions a, .listing-actions button {
  padding: 6px 10px;
  background: var(--accent-light);
  color: var(--accent);
  border: none;
  border-radius: 6px;
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.listing-actions a:hover { background: #bfdbfe; }

/* BADGES on bookmarks */
.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.badge {
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.badge-drop { background: var(--soft-success); color: var(--success); }
.badge-rise { background: var(--soft-danger); color: var(--danger); }
.badge-edit { background: var(--soft-warn); color: var(--warn); }
.badge-removed { background: #27272a; color: white; }

/* DETAILS DRAWER */
.listing-details {
  padding: 0 16px 16px 16px;
  border-top: 1px solid var(--border);
  background: #fafbff;
}
.details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px 20px;
  margin: 12px 0;
}
.detail-item { display: flex; gap: 6px; font-size: 13px; }
.detail-item .key { color: var(--muted); min-width: 90px; }
.detail-item .val { color: var(--text); font-weight: 500; }
.description {
  background: white;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  white-space: pre-wrap;
  line-height: 1.9;
  margin-top: 12px;
  max-height: 400px;
  overflow-y: auto;
}
.history-list {
  background: white;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-top: 12px;
  font-size: 13px;
}
.history-list h4 { margin: 0 0 8px 0; font-size: 13px; }
.history-item {
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.history-item:last-child { border-bottom: none; }
.history-time { color: var(--muted); font-size: 11px; white-space: nowrap; }

/* HISTOGRAM PAGE */
.hist-card {
  background: var(--card);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.hist-card h3 { margin: 0 0 4px 0; }
.hist-stats {
  color: var(--muted);
  font-size: 12px;
  display: flex;
  gap: 14px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

/* LOADING / EMPTY */
.loading, .empty {
  text-align: center;
  color: var(--muted);
  padding: 40px;
  font-size: 14px;
}

@media (max-width: 640px) {
  .nav { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .nav h1 { font-size: 16px; margin: 0; }
  .listing-row { grid-template-columns: auto 1fr; }
  .listing-actions { grid-column: 1 / -1; justify-content: flex-end; }
}
