:root {
  --bg: #f4f7f8;
  --sidebar: #0f172a;
  --sidebar-2: #164e63;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #64748b;
  --primary: #0f9aa6;
  --primary-strong: #0b7f89;
  --brand: #31b9c1;
  --accent: #31b9c1;
  --danger: #ef4444;
  --success: #16a34a;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(15, 23, 42, .06);
  --font: "Vazirmatn", "Tahoma", sans-serif;
  --sidebar-width: 268px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  z-index: 55; backdrop-filter: blur(2px);
}
.sidebar-overlay.is-open { display: block; }

.sidebar {
  width: var(--sidebar-width);
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(49, 185, 193, .28), transparent 55%),
    radial-gradient(90% 50% at 0% 100%, rgba(15, 118, 110, .35), transparent 50%),
    linear-gradient(180deg, #0b1220 0%, #0f172a 42%, #0b3a42 100%);
  color: #fff;
  padding: 14px 12px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  flex-shrink: 0;
  z-index: 60;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(148, 163, 184, .12);
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, .25); border-radius: 999px; }

.sidebar .brand {
  display: flex; align-items: center; gap: 12px;
  padding: 12px;
  margin-bottom: 10px;
  border-radius: 16px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.sidebar .brand-mark {
  width: 42px; height: 42px; border-radius: 12px; overflow: hidden; flex-shrink: 0;
  box-shadow: 0 8px 18px rgba(0,0,0,.25);
}
.sidebar .brand-mark img { width: 100%; height: 100%; display: block; }
.sidebar .brand-copy { min-width: 0; display: grid; gap: 4px; }
.sidebar .brand-logo {
  height: 22px; width: auto; max-width: 132px; display: block; object-fit: contain;
}
.sidebar .brand-sub {
  color: #99f6e4; font-size: .72rem; font-weight: 600; opacity: .9;
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-left: 2px;
}
.sidebar-nav::-webkit-scrollbar { width: 5px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, .28); border-radius: 999px; }
.sidebar .nav-group {
  margin-bottom: 10px;
  padding: 8px;
  border-radius: 14px;
  background: rgba(15, 23, 42, .28);
  border: 1px solid rgba(255,255,255,.05);
}
.sidebar .nav-section {
  color: #5eead4; font-size: .7rem; margin: 2px 8px 8px;
  font-weight: 700; letter-spacing: .04em; text-transform: none; opacity: .95;
}
.sidebar a.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 11px; border-radius: 11px; color: #cbd5e1; margin-bottom: 3px;
  font-weight: 600; font-size: .92rem;
  min-height: 44px;
  transition: background .15s, color .15s, transform .15s;
}
.sidebar a.nav-item > span:last-child {
  min-width: 0;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar a.nav-item:last-child { margin-bottom: 0; }
.sidebar a.nav-item .nav-ico {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center; flex-shrink: 0;
  background: rgba(255,255,255,.06); color: #99f6e4;
}
.sidebar a.nav-item .nav-ico svg { width: 16px; height: 16px; }
.sidebar a.nav-item:hover {
  background: rgba(49, 185, 193, .12); color: #fff;
}
.sidebar a.nav-item:hover .nav-ico { background: rgba(49, 185, 193, .22); }
.sidebar a.nav-item.active {
  background: linear-gradient(90deg, rgba(49, 185, 193, .28), rgba(49, 185, 193, .08));
  color: #fff;
  box-shadow: inset -3px 0 0 var(--brand);
}
.sidebar a.nav-item.active .nav-ico {
  background: rgba(49, 185, 193, .35); color: #ecfeff;
}

.sidebar-foot {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: grid; gap: 8px;
  flex-shrink: 0;
}
.sidebar-foot-card {
  display: grid; gap: 2px; padding: 10px 12px; border-radius: 12px;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.07);
}
.sidebar-foot-card strong { font-size: .86rem; }
.sidebar-foot-card small { color: #99f6e4; font-size: .72rem; }
.sidebar-foot-link {
  color: #94a3b8; font-size: .78rem; font-weight: 600; padding: 0 4px;
}
.sidebar-foot-link:hover { color: #5eead4; }

.sidebar-close {
  display: none; position: absolute; top: 12px; left: 10px; z-index: 2;
  width: 36px; height: 36px; border: 0; border-radius: 10px;
  background: rgba(255,255,255,.08); color: #fff; cursor: pointer; font-size: 1.2rem;
}

.main { flex: 1; min-width: 0; }
.topbar {
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 10px 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  position: sticky; top: 0; z-index: 20;
  min-height: 64px;
}
.topbar-menu-btn {
  display: none; width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--border); background: #fff; color: #334155;
  cursor: pointer; place-items: center; flex-shrink: 0;
}
.topbar-brand-mobile {
  display: none; align-items: center; gap: 8px; flex-shrink: 0;
}
.topbar-brand-mobile img { height: 28px; width: auto; display: block; }
.topbar-search {
  flex: 1; max-width: 480px; position: relative;
}
.topbar-search-icon {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  color: #94a3b8; display: grid; place-items: center; pointer-events: none;
}
.topbar-search input {
  width: 100%; border: 1px solid #e2e8f0; border-radius: 12px;
  padding: 11px 42px 11px 72px; background: #f8fafc;
  color: var(--text); transition: border-color .15s, box-shadow .15s, background .15s;
}
.topbar-search input::placeholder { color: #94a3b8; }
.topbar-search input:hover { background: #fff; border-color: #cbd5e1; }
.topbar-search input:focus {
  outline: none; background: #fff; border-color: #5eead4;
  box-shadow: 0 0 0 3px rgba(49, 185, 193, .18);
}
.topbar-search-hint {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-family: inherit; font-size: .72rem; font-weight: 600;
  color: #94a3b8; background: #fff; border: 1px solid #e2e8f0;
  border-radius: 6px; padding: 3px 7px; pointer-events: none;
}
.topbar .search-results {
  position: absolute; top: calc(100% + 8px); right: 0; left: 0; background: #fff;
  border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 16px 40px rgba(15, 23, 42, .12);
  display: none; overflow: hidden; z-index: 30;
}
.topbar .search-results a {
  display: block; padding: 12px 14px; border-bottom: 1px solid #f1f5f9;
}
.topbar .search-results a:last-child { border-bottom: 0; }
.topbar .search-results a:hover { background: #f8fbff; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.topbar-divider {
  width: 1px; height: 28px; background: #e2e8f0; margin: 0 2px;
}
.topbar-cta {
  display: inline-flex; align-items: center; gap: 6px;
  box-shadow: 0 1px 2px rgba(37, 99, 235, .2);
}
.user-chip {
  display: inline-flex; align-items: center; gap: 10px;
  background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 999px;
  padding: 5px 12px 5px 6px; min-height: 40px;
}
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #31b9c1, #0f766e);
  color: #fff; font-size: .85rem; font-weight: 800;
}
.user-meta { display: grid; line-height: 1.2; text-align: right; }
.user-meta strong { font-size: .86rem; font-weight: 700; }
.user-meta small { color: var(--muted); font-size: .72rem; margin-top: 2px; }
.logout-form { margin: 0; }
.btn-logout {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid #e2e8f0; background: #fff; color: #475569;
  border-radius: 10px; padding: 8px 12px; cursor: pointer;
  font: inherit; font-size: .85rem; font-weight: 600;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-logout:hover {
  background: #fef2f2; border-color: #fecaca; color: #b91c1c;
}
.content { padding: 22px; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  margin-bottom: 18px;
}
.page-head h1 { margin: 0; font-size: 1.45rem; }
.page-head p { margin: 6px 0 0; color: var(--muted); }
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.crm-tabs {
  display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden;
  padding-bottom: 8px; margin-bottom: 16px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.crm-tabs a {
  white-space: nowrap; padding: 8px 14px; border-radius: 999px;
  background: #fff; border: 1px solid var(--border); color: var(--muted); font-size: .9rem;
  flex: 0 0 auto;
}
.crm-tabs a.active { background: #ecfeff; border-color: #99f6e4; color: #0f766e; font-weight: 700; }

.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
.card h3 { margin: 0 0 10px; font-size: 1rem; }
.kpi { min-height: 110px; }
.kpi .label { color: var(--muted); font-size: .9rem; }
.kpi .value { font-size: 1.7rem; font-weight: 800; margin-top: 8px; line-height: 1.2; word-break: break-word; }
.kpi .value.kpi-money { font-size: 1.1rem; }
.kpi.purple { background: linear-gradient(135deg, #7c3aed, #4f46e5); color: #fff; border: 0; }
.kpi.purple .label { color: rgba(255,255,255,.85); }
.kpi.danger .value { color: var(--danger); }
a.card.kpi-link {
  color: inherit;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  cursor: pointer;
}
a.card.kpi-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(15, 23, 42, .1);
}
a.card.kpi-link:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
a.stage-link {
  color: inherit;
  border-radius: 10px;
  padding-inline: 8px;
  margin-inline: -8px;
  transition: background .15s ease;
}
a.stage-link:hover {
  background: #f8fafc;
}
a.stage-link:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer;
  background: var(--primary); color: #fff; font-weight: 700;
}
.btn:hover { filter: brightness(.96); }
.btn-outline { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--success); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 7px 10px; font-size: .85rem; border-radius: 8px; }

.table-wrap { overflow: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td {
  padding: 12px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap;
}
table.data th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.badge {
  display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 999px;
  font-size: .78rem; background: #ecfeff; color: #0f766e;
}
.badge.green { background: #dcfce7; color: #166534; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.amber { background: #fef3c7; color: #92400e; }
.badge.gray { background: #f1f5f9; color: #475569; }

/* اولویت‌ها — یکسان در کل پنل */
.badge.priority-low,
.priority-low.badge { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }
.badge.priority-normal,
.priority-normal.badge { background: #dbeafe; color: #1d4ed8; border: 1px solid #93c5fd; }
.badge.priority-high,
.priority-high.badge { background: #ffedd5; color: #c2410c; border: 1px solid #fdba74; }
.badge.priority-urgent,
.priority-urgent.badge { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; font-weight: 800; }

.select.priority-select.priority-low {
  background: #f8fafc; border-color: #94a3b8; color: #334155; font-weight: 700;
}
.select.priority-select.priority-normal {
  background: #eff6ff; border-color: #60a5fa; color: #1d4ed8; font-weight: 700;
}
.select.priority-select.priority-high {
  background: #fff7ed; border-color: #fb923c; color: #c2410c; font-weight: 700;
}
.select.priority-select.priority-urgent {
  background: #fef2f2; border-color: #f87171; color: #b91c1c; font-weight: 800;
}
option.priority-low { background: #f8fafc; color: #475569; }
option.priority-normal { background: #eff6ff; color: #1d4ed8; }
option.priority-high { background: #fff7ed; color: #c2410c; }
option.priority-urgent { background: #fef2f2; color: #b91c1c; }

/* انتخاب فشرده محصولات */
.product-picker-list {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.product-chip {
  display: inline-flex; align-items: stretch; margin: 0; cursor: pointer;
  max-width: 100%;
}
.product-chip input {
  position: absolute; opacity: 0; pointer-events: none;
}
.product-chip-body {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: #fff;
  min-width: 160px; transition: .15s ease;
}
.product-chip-name {
  font-size: .88rem; font-weight: 700; color: var(--text); line-height: 1.35;
}
.product-chip-price {
  font-size: .75rem; color: var(--muted); font-weight: 600; direction: ltr; text-align: right;
}
.product-chip input:checked + .product-chip-body {
  border-color: #5eead4; background: #ecfeff;
  box-shadow: inset 0 0 0 1px #99f6e4;
}
.product-chip input:checked + .product-chip-body .product-chip-name { color: #0f766e; }
.product-chip input:checked + .product-chip-body .product-chip-price { color: #0f9aa6; }
.product-chip:hover .product-chip-body { border-color: #5eead4; }

.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; margin-bottom: 6px; color: var(--muted); font-size: .9rem; }
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; background: #fff;
}
.textarea { min-height: 100px; resize: vertical; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters a, .filters .chip {
  padding: 7px 12px; border-radius: 999px; background: #fff; border: 1px solid var(--border); color: var(--muted);
}
.filters a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.filters-grid .filters-q { max-width: 240px; }
.filters-grid .select { max-width: 180px; }
.filters-grid .filters-submit { flex: 0 0 auto; }
.filters-dates { align-items: flex-end; }
.filters-dates .filters-date { min-width: 180px; flex: 0 1 200px; }
.filters-dates .filters-date .input { width: 100%; }
.stage-list { display: grid; gap: 0; }
.stage-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid #e2e8f0;
}
.stage-row:last-child { border-bottom: 0; }
.report-panels { margin-top: 14px; }
.report-overdue { margin-top: 14px; }
.overdue-row {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px 12px;
  padding: 10px 0; border-bottom: 1px solid #e2e8f0;
}
.overdue-row:last-child { border-bottom: 0; }
.overdue-meta { color: var(--muted); font-size: .86rem; }
.table-pager { margin-top: 12px; }

.alert {
  padding: 12px 14px; border-radius: 10px; margin-bottom: 14px;
  background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0;
}
.alert.error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.empty {
  text-align: center; color: var(--muted); padding: 40px 16px;
}
.timeline { display: grid; gap: 0; position: relative; padding-right: 18px; }
.timeline::before {
  content: ""; position: absolute; top: 8px; bottom: 8px; right: 5px;
  width: 2px; background: #e2e8f0;
}
.timeline-item {
  position: relative; padding: 0 22px 22px 0;
}
.timeline-item:last-child { padding-bottom: 4px; }
.timeline-item .tl-dot {
  position: absolute; top: 4px; right: -1px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #94a3b8; border: 2px solid #fff; box-shadow: 0 0 0 2px #e2e8f0;
}
.timeline-item.tl-call .tl-dot { background: #2563eb; box-shadow: 0 0 0 2px #bfdbfe; }
.timeline-item.tl-meeting .tl-dot { background: #7c3aed; box-shadow: 0 0 0 2px #ddd6fe; }
.timeline-item.tl-sms .tl-dot { background: #0891b2; box-shadow: 0 0 0 2px #a5f3fc; }
.timeline-item.tl-stage .tl-dot { background: #ea580c; box-shadow: 0 0 0 2px #fed7aa; }
.timeline-item.tl-note .tl-dot { background: #64748b; box-shadow: 0 0 0 2px #e2e8f0; }
.timeline-item .tl-card {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; box-shadow: 0 1px 2px rgba(15, 23, 42, .03);
}
.timeline-item .meta {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  color: var(--muted); font-size: .8rem; margin-bottom: 6px;
}
.timeline-item .tl-type {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 999px; font-size: .72rem; font-weight: 700;
  background: #f1f5f9; color: #475569;
}
.timeline-item.tl-call .tl-type { background: #eff6ff; color: #1d4ed8; }
.timeline-item.tl-meeting .tl-type { background: #f5f3ff; color: #6d28d9; }
.timeline-item.tl-sms .tl-type { background: #ecfeff; color: #0e7490; }
.timeline-item.tl-stage .tl-type { background: #fff7ed; color: #c2410c; }
.timeline-item .tl-title { font-weight: 700; margin: 0 0 4px; }
.timeline-item .tl-body { color: #334155; font-size: .92rem; white-space: pre-wrap; line-height: 1.6; }

.score-meters {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px;
  margin: 4px 0 12px;
}
.score-meter {
  background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
}
.score-meter-label { font-size: .82rem; margin-bottom: 8px; }
.score-meter-track {
  height: 8px; border-radius: 999px; overflow: hidden;
}
.score-meter-track > span { display: block; height: 100%; border-radius: 999px; }
.score-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 999px; font-size: .78rem; font-weight: 700;
  background: #ecfeff; color: #0f766e;
}
.score-pill.completion { background: #f0fdf4; color: #166534; }
.field-hint-range {
  display: block; margin-top: 4px; color: var(--muted); font-size: .78rem;
}
.lead-workspace { display: grid; gap: 14px; max-width: 820px; }
.lead-facts {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px;
}
@media (min-width: 720px) {
  .lead-facts { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.lead-fact {
  display: block; width: 100%; text-align: right; border: 1px solid var(--border);
  background: #fff; border-radius: 12px; padding: 12px 14px; cursor: pointer;
  color: inherit; box-shadow: 0 1px 2px rgba(15, 23, 42, .03);
}
.lead-fact:hover { border-color: #93c5fd; background: #f8fbff; }
.lead-fact .label { color: var(--muted); font-size: .78rem; margin-bottom: 6px; }
.lead-fact .value { font-weight: 700; font-size: .95rem; line-height: 1.4; }
.lead-fact.is-warn { border-color: #fecaca; background: #fff7f7; }
.lead-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.lead-timeline-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px;
}
.lead-timeline-head h2 { margin: 0; font-size: 1.05rem; }
.lead-empty-hint { color: var(--muted); font-size: .9rem; padding: 28px 8px; text-align: center; }

body.modal-open { overflow: hidden; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 80;
  display: none; align-items: flex-start; justify-content: center;
  padding: 48px 16px 24px; background: rgba(15, 23, 42, .45);
  overflow: auto;
}
.modal-backdrop.is-open { display: flex; }
.modal-panel {
  width: min(560px, 100%); background: #fff; border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .2); border: 1px solid var(--border);
  margin: auto 0;
}
.modal-panel.modal-wide { width: min(680px, 100%); }
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 18px 0;
}
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-head .hint { margin: 4px 0 0; }
.modal-close {
  border: 0; background: #f1f5f9; color: #475569; width: 34px; height: 34px;
  border-radius: 10px; cursor: pointer; font-size: 1.2rem; line-height: 1;
}
.modal-close:hover { background: #e2e8f0; }
.modal-body { padding: 14px 18px 18px; }
.modal-body .form-grid { grid-template-columns: 1fr; }
.tabs-local { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs-local a, .tabs-local button {
  padding: 8px 12px; border-radius: 8px; background: #f1f5f9; border: 0;
  color: inherit; cursor: pointer; font: inherit;
}
.tabs-local a.active, .tabs-local button.active {
  background: #ecfeff; color: #0f766e; font-weight: 700;
}
.tab-panels > .tab-panel { display: none; }
.tab-panels > .tab-panel.is-active { display: block; }
.choice-row { display: flex; flex-wrap: wrap; gap: 10px; }
.choice {
  flex: 1; min-width: 180px; display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
  background: #fff; cursor: pointer; color: var(--text); font-weight: 600;
}
.choice input { accent-color: var(--primary); }
.choice.active { border-color: #5eead4; background: #ecfeff; color: #0f766e; box-shadow: inset 0 0 0 1px #99f6e4; }
.hint { color: var(--muted); font-size: .8rem; margin-top: 6px; }
.deal-box { border-color: #dbeafe; background: linear-gradient(180deg, #f8fbff, #fff); }
.form-actions {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-top: 16px; padding-top: 4px;
}
.btn-link { color: var(--muted); font-weight: 600; padding: 8px 4px; }
.btn-link:hover { color: var(--danger); }
.search-dropdown {
  display: none; margin-top: 8px; border: 1px solid var(--border); border-radius: 12px;
  background: #fff; box-shadow: var(--shadow); overflow: hidden; max-height: 240px; overflow-y: auto;
}
.search-option {
  display: block; width: 100%; text-align: right; border: 0; background: #fff;
  padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.search-option:hover { background: #f8fafc; }
.search-empty { padding: 12px; color: var(--muted); }
.lookup-field { position: relative; }
.lookup-field .search-dropdown { position: absolute; right: 0; left: 0; z-index: 40; }
.dup-box {
  display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; align-items: flex-start;
  padding: 14px; border-radius: 12px; background: #fff7ed; border: 1px solid #fdba74; color: #9a3412;
}
.dup-box-info {
  background: #eff6ff; border-color: #93c5fd; color: #1e3a8a;
}
.dup-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mode-status {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 10px; padding: 8px 12px; border-radius: 999px;
  font-size: .85rem; font-weight: 600;
}
.mode-status .mode-dot {
  width: 8px; height: 8px; border-radius: 50%; background: currentColor;
}
.mode-status.mode-new {
  background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0;
}
.mode-status.mode-existing {
  background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe;
}
.lead-lower-panels.is-collapsed > .card {
  display: none;
}
.panel-toggle {
  display: flex; width: 100%; align-items: center; justify-content: space-between;
  gap: 12px; border: 0; background: transparent; padding: 0 0 12px;
  font: inherit; font-weight: 700; color: inherit; cursor: pointer; text-align: right;
}
.panel-toggle .panel-chevron {
  transition: transform .15s ease; color: var(--muted); font-size: 1rem;
}
.panel-toggle[aria-expanded="false"] .panel-chevron { transform: rotate(-90deg); }
.panel-toggle[aria-expanded="false"] + .panel-body { display: none; }
.card:has(> .panel-toggle) { padding-top: 14px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.jalali-field { position: relative; }
.jalali-field .jdp-display {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%2364748b' stroke-width='1.6' viewBox='0 0 24 24'%3E%3Crect x='3' y='5' width='18' height='16' rx='2'/%3E%3Cpath d='M3 10h18M8 3v4M16 3v4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  padding-left: 40px;
}
jdp-container, .jdp-container, [class*="jdp"] {
  font-family: var(--font) !important;
}
.message-list { display: grid; gap: 10px; }
.message {
  padding: 12px; border-radius: 12px; background: #f8fafc; border: 1px solid var(--border);
}
.message.customer { background: #eff6ff; }
.message.operator { background: #f0fdf4; }
.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background:
    radial-gradient(circle at top left, rgba(49, 185, 193, .22), transparent 42%),
    radial-gradient(circle at bottom right, rgba(15, 23, 42, .08), transparent 40%),
    #f4f7f8;
  padding: 20px;
}
.login-card { width: 100%; max-width: 420px; }
.login-brand {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  margin-bottom: 18px; text-align: center;
}
.login-brand img { height: 42px; width: auto; }
.login-brand p { margin: 0; color: var(--muted); font-size: .9rem; }

.pagination { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0; flex-wrap: wrap; }
.pagination .page-item .page-link,
.pagination > li > a, .pagination > li > span {
  display: inline-flex; padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
}
.pagination .active .page-link,
.pagination > .active > span {
  background: var(--primary); color: #fff; border-color: var(--primary);
}

body.sidebar-open { overflow: hidden; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    height: 100dvh;
    width: min(86vw, 320px);
    max-width: 100%;
    padding: 12px 10px calc(14px + env(safe-area-inset-bottom, 0px));
    transform: translateX(105%);
    transition: transform .22s ease;
    box-shadow: -16px 0 40px rgba(15, 23, 42, .2);
    overflow: hidden;
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-close { display: grid; place-items: center; }
  .sidebar .brand {
    padding: 10px 40px 10px 10px;
    margin-bottom: 8px;
    gap: 10px;
  }
  .sidebar .brand-mark { width: 36px; height: 36px; border-radius: 10px; }
  .sidebar .brand-logo { height: 18px; max-width: 120px; }
  .sidebar .brand-sub { font-size: .68rem; }
  .sidebar .nav-group {
    margin-bottom: 8px;
    padding: 6px;
    border-radius: 12px;
  }
  .sidebar .nav-section {
    margin: 2px 8px 6px;
    font-size: .68rem;
  }
  .sidebar a.nav-item {
    gap: 8px;
    padding: 9px 10px;
    margin-bottom: 2px;
    border-radius: 10px;
    font-size: .9rem;
    min-height: 46px;
  }
  .sidebar a.nav-item .nav-ico {
    width: 32px; height: 32px; border-radius: 9px;
  }
  .sidebar a.nav-item .nav-ico svg { width: 17px; height: 17px; }
  .sidebar-foot {
    margin-top: 8px;
    padding-top: 10px;
  }
  .sidebar-foot-card {
    padding: 9px 11px;
  }
  .topbar-menu-btn { display: grid; }
  .topbar-brand-mobile { display: inline-flex; margin-left: auto; }
  .topbar {
    display: grid;
    grid-template-columns: auto auto 1fr;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    min-height: 0;
  }
  .topbar-menu-btn { grid-column: 1; grid-row: 1; }
  .topbar-brand-mobile { grid-column: 2; grid-row: 1; margin-left: 0; }
  .topbar-actions { grid-column: 3; grid-row: 1; justify-self: end; gap: 6px; }
  .topbar-search { grid-column: 1 / -1; grid-row: 2; max-width: none; width: 100%; order: initial; }
  .topbar-search-hint { display: none; }
  .topbar-search input {
    padding: 9px 40px 9px 12px;
    font-size: .9rem;
  }
  .topbar-divider { display: none; }
  .user-meta { display: none; }
  .user-chip { padding: 3px; min-height: 0; border: 0; background: transparent; }
  .user-avatar { width: 34px; height: 34px; }
  .btn-logout {
    width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: 10px;
  }
  .btn-logout span { display: none; }
  .topbar-cta {
    width: 36px; height: 36px; padding: 0; border-radius: 10px;
    justify-content: center;
  }
  .topbar-cta span { display: none; }
  .content { padding: 12px; }
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 12px; }
  .page-head h1 { font-size: 1.2rem; }
  .hide-on-mobile { display: none !important; }
  .filters .input, .filters .select { max-width: none !important; flex: 1 1 140px; }
  .filters-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: stretch;
  }
  .filters-grid .filters-q {
    grid-column: 1 / -1;
    max-width: none;
  }
  .filters-grid .select { max-width: none; width: 100%; }
  .filters-grid .filters-submit {
    grid-column: 1 / -1;
    width: 100%;
    min-height: 42px;
  }
  .filters-dates {
    align-items: stretch;
  }
  .filters-dates .filters-date {
    min-width: 0;
    flex: none;
  }
  .filters-dates .filters-submit {
    align-self: end;
    min-height: 44px;
  }
  .report-panels { margin-top: 10px; gap: 10px; }
  .report-overdue { margin-top: 10px; }
  .overdue-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  .page-head .btn, .page-head .btn-sm { width: 100%; }
  .page-head-actions { width: 100%; }
  .page-head-actions .btn,
  .page-head-actions .btn-sm { flex: 1 1 calc(50% - 4px); width: auto; }
  .crm-tabs {
    margin-inline: -12px;
    padding-inline: 12px;
    scroll-padding-inline: 12px;
  }
  .crm-tabs a { padding: 8px 12px; font-size: .84rem; }
  .modal-backdrop { padding: 16px 10px; }
  .modal-panel, .modal-panel.modal-wide { width: 100%; }
  .lead-workspace { max-width: none; }
  .score-meters { grid-template-columns: 1fr 1fr; gap: 8px; }
  .lead-facts { grid-template-columns: 1fr 1fr; gap: 8px; }
  .lead-actions .btn { flex: 1 1 auto; }
  .grid { gap: 10px; }
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .card.kpi {
    min-height: 0;
    padding: 12px;
  }
  .kpi .label { font-size: .78rem; line-height: 1.35; }
  .kpi .value { font-size: 1.25rem; margin-top: 6px; }
  .kpi .value.kpi-money { font-size: 1rem; }
  .form-actions {
    position: sticky;
    bottom: 0;
    z-index: 15;
    margin: 16px -12px -12px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, .96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 24px rgba(15, 23, 42, .08);
    flex-wrap: nowrap;
    gap: 8px;
  }
  .form-actions .btn {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
    white-space: nowrap;
  }
  .form-actions .btn-outline { flex: 1.2 1 auto; }
  .form-actions .btn-link {
    flex: 0 0 auto;
    padding: 8px 6px;
    white-space: nowrap;
  }
  #lead-create-form { padding-bottom: 8px; }
}

@media (max-width: 720px) {
  .grid-3, .grid-2, .form-grid { grid-template-columns: 1fr; }
  .lead-facts, .score-meters { grid-template-columns: 1fr 1fr; }
  .choice { min-width: 0; width: 100%; }
  .crm-tabs, .tabs-local, .filters { gap: 6px; }
  .table-wrap {
    margin-inline: 0;
    padding: 10px;
    border-radius: 12px;
  }
  table.data th, table.data td { padding: 10px 8px; font-size: .88rem; }
  .topbar-brand-mobile img { height: 22px; }

  table.data-cards thead { display: none; }
  table.data-cards,
  table.data-cards tbody {
    display: block;
    width: 100%;
  }
  table.data-cards tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
    padding: 12px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
  }
  table.data-cards tr:last-child { margin-bottom: 0; }
  table.data-cards tr.is-empty {
    display: block;
    border: 0;
    padding: 0;
    background: transparent;
  }
  table.data-cards td {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 0;
    border: 0;
    white-space: normal;
    min-width: 0;
  }
  table.data-cards td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: .72rem;
    font-weight: 700;
  }
  table.data-cards td[data-label=""]::before,
  table.data-cards td.td-actions::before { display: none; }
  table.data-cards td.td-title,
  table.data-cards tr:not(:has(.td-title)) > td:first-child {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: 8px;
    margin-bottom: 2px;
    border-bottom: 1px dashed #e2e8f0;
  }
  table.data-cards td.td-title::before,
  table.data-cards tr:not(:has(.td-title)) > td:first-child::before { display: none; }
  table.data-cards td.td-title strong,
  table.data-cards tr:not(:has(.td-title)) > td:first-child strong { font-size: .98rem; }
  table.data-cards td.td-title { order: -1; }
  table.data-cards td.td-actions {
    grid-column: 1 / -1;
    margin-top: 4px;
  }
  table.data-cards td.td-actions .btn {
    width: 100%;
    min-height: 40px;
  }
  table.data-cards td.td-comment,
  table.data-cards td.td-badges {
    grid-column: 1 / -1;
  }
  table.data-cards td.td-badges {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }
  table.data-cards .empty { padding: 28px 12px; }
  .table-pager { margin-top: 10px; overflow-x: auto; }
}

@media (max-width: 480px) {
  .topbar { padding: 8px 10px; gap: 6px; }
  .topbar-actions { gap: 4px; }
  .topbar-menu-btn, .topbar-cta, .btn-logout, .user-avatar {
    width: 34px; height: 34px;
  }
  .btn-sm { padding: 7px 9px; }
  .grid-4 { gap: 6px; }
  .card.kpi { padding: 10px; border-radius: 12px; }
  .kpi .label { font-size: .74rem; }
  .kpi .value { font-size: 1.15rem; }
  .kpi .value.kpi-money { font-size: .92rem; }
  .content { padding: 10px; }
  .page-head p { display: none; }
  .form-actions {
    margin-inline: -10px;
    margin-bottom: -10px;
    padding-inline: 10px;
    gap: 6px;
  }
  .form-actions .btn {
    font-size: .82rem;
    padding: 10px 8px;
  }
  .form-actions .btn-outline { font-size: .78rem; }
  .sidebar {
    width: min(92vw, 100%);
    padding-top: 10px;
  }
  .sidebar .nav-group {
    margin-bottom: 6px;
    padding: 4px;
    background: transparent;
    border-color: transparent;
  }
  .sidebar .nav-section {
    margin: 4px 8px 4px;
  }
  .sidebar a.nav-item {
    min-height: 48px;
    padding: 10px 12px;
    font-size: .92rem;
  }
  .sidebar a.nav-item > span:last-child {
    white-space: normal;
  }
}

