:root {
  --bg: #e8eef2;
  --bg-glow: #d7e8e4;
  --sidebar: #0b2430;
  --sidebar-2: #123748;
  --accent: #0f9f8c;
  --accent-2: #0b7f70;
  --text: #102833;
  --muted: #5f7380;
  --card: #ffffff;
  --line: #d3e0e7;
  --danger: #dc2656;
  --warn: #d97706;
  --ok: #047857;
  --shadow: 0 8px 24px rgba(11, 36, 48, .08);
  --shadow-lg: 0 18px 50px rgba(11, 36, 48, .16);
  --radius: 16px;
  --waiting: #0ea5a4;
  --follow: #2563eb;
  --deal: #d97706;
  --weak: #94a3b8;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Vazirmatn, Tahoma, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 420px at 100% -10%, var(--bg-glow), transparent 55%),
    radial-gradient(700px 360px at -10% 20%, #dce7ef, transparent 50%),
    var(--bg);
  display: flex;
}

.sidebar {
  width: 248px;
  background: linear-gradient(185deg, var(--sidebar), var(--sidebar-2) 55%, #0a1d27);
  color: #dbeafe;
  min-height: 100vh;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand {
  font-weight: 700;
  font-size: 22px;
  letter-spacing: .2px;
  margin-bottom: 26px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.brand span {
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  background: rgba(15, 159, 140, .15);
  border: 1px solid rgba(15, 159, 140, .25);
  border-radius: 999px;
  padding: 2px 8px;
}
.sidebar nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.sidebar a {
  color: #c5d9e4;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 12px;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}
.sidebar a.active, .sidebar a:hover {
  background: rgba(15, 159, 140, .18);
  color: #fff;
}
.sidebar a.active { box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-user { font-size: 13px; color: #8eacbb; line-height: 1.6; }
.sidebar-user a {
  display: inline-flex;
  margin-top: 8px;
  color: #fda4af;
  padding: 0;
  background: transparent;
}

.nav-toggle {
  display: none;
  border: 0;
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.main { flex: 1; padding: 24px; min-width: 0; }

.topbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
  position: relative;
  z-index: 22;
}
.topbar h1 { margin: 0; font-size: 24px; flex: 1; letter-spacing: -.2px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.topbar h1 em {
  font-style: normal;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.topbar h1 em strong { color: var(--text); font-size: 14px; }
.search-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.search {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 11px 14px;
  min-width: 240px;
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.search:focus {
  outline: none;
  border-color: #8fd0c6;
  box-shadow: 0 0 0 3px rgba(15, 159, 140, .15);
}

.btn {
  border: 0;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #fff;
  border-radius: 12px;
  padding: 10px 16px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
  box-shadow: 0 6px 16px rgba(15, 159, 140, .25);
}
.btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.btn.secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: none;
}
.btn.danger {
  background: linear-gradient(180deg, #ef446f, var(--danger));
  box-shadow: 0 6px 16px rgba(220, 38, 86, .22);
}

.source-dropdown { position: relative; }
.source-trigger {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  white-space: nowrap;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.source-trigger:hover,
.source-dropdown.open .source-trigger {
  border-color: #8fd0c6;
  box-shadow: 0 0 0 3px rgba(15, 159, 140, .12);
}
.source-trigger.is-filtered {
  background: rgba(15, 159, 140, .08);
  border-color: rgba(15, 159, 140, .4);
  color: var(--accent-2);
}
.source-kicker {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.source-trigger.is-filtered .source-kicker { color: var(--accent-2); opacity: .8; }
.source-trigger-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #f3f7f9;
  padding: 2px 7px;
  border-radius: 8px;
}
.source-trigger.is-filtered .source-trigger-count {
  background: rgba(15, 159, 140, .16);
  color: var(--accent-2);
}
.caret {
  width: 7px;
  height: 7px;
  border-inline-end: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  margin-top: -4px;
  opacity: .55;
  transition: transform .16s ease;
}
.source-dropdown.open .caret {
  transform: rotate(-135deg);
  margin-top: 3px;
}
.source-menu {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  width: 260px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 8px;
  z-index: 25;
  display: none;
  animation: riseIn .16s ease;
}
.source-dropdown.open .source-menu { display: block; }
.source-menu-title {
  margin: 2px 10px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.source-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: right;
  padding: 10px 10px;
  border-radius: 11px;
  cursor: pointer;
}
.source-option:hover { background: #f4faf9; }
.source-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  box-shadow: none;
  accent-color: var(--accent);
  flex: 0 0 auto;
  appearance: auto;
}
.source-option input[type="checkbox"]:focus { box-shadow: none; }
.source-label { flex: 1; }
.source-n {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.source-sep {
  height: 1px;
  background: var(--line);
  margin: 6px 8px;
}
.source-menu-foot {
  padding: 8px 4px 4px;
}
.source-menu-foot .btn { width: 100%; justify-content: center; }

.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(230px, 1fr));
  gap: 14px;
  align-items: stretch;
}
.column {
  background: rgba(255, 255, 255, .55);
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: 18px;
  padding: 12px;
  min-height: 68vh;
  backdrop-filter: blur(6px);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.column.drop-target {
  border-color: rgba(15, 159, 140, .55);
  background: rgba(236, 253, 245, .75);
  box-shadow: inset 0 0 0 1px rgba(15, 159, 140, .25);
}
.column[data-status="waiting_call"] { --col: var(--waiting); }
.column[data-status="follow_up"] { --col: var(--follow); }
.column[data-status="waiting_deal"] { --col: var(--deal); }
.column[data-status="weak"] { --col: var(--weak); }
.column h2 {
  margin: 0 0 12px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.column h2::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--col, var(--accent));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--col, var(--accent)) 20%, transparent);
  margin-left: 4px;
}
.count {
  background: #fff;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  margin-right: auto;
}
.cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: calc(68vh - 48px);
}
.card {
  background: var(--card);
  border-radius: 14px;
  padding: 12px 12px 11px;
  box-shadow: var(--shadow);
  cursor: grab;
  border: 1px solid transparent;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
  animation: cardIn .28s ease both;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: #cfe4df;
}
.card.dragging {
  opacity: .45;
  transform: scale(.98);
  cursor: grabbing;
}
.card h3 { margin: 0 0 4px; font-size: 14px; line-height: 1.4; }
.card .phone {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: .2px;
  direction: ltr;
  text-align: right;
}
.card .meta {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.badge {
  display: inline-flex;
  align-items: center;
  background: #ecfdf5;
  color: var(--ok);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 600;
  margin-top: 10px;
}
.badge.off { background: #fff7ed; color: #c2410c; }

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.lead-tag {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--tag, var(--accent));
  background: color-mix(in srgb, var(--tag, var(--accent)) 14%, #fff);
  border: 1px solid color-mix(in srgb, var(--tag, var(--accent)) 28%, transparent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tag-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tag, var(--accent));
  flex: 0 0 auto;
}

.tags-section {
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.tags-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.tags-head label { margin: 0; }
.tag-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 36px;
  margin-bottom: 10px;
}
.tag-picker-empty {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}
.tag-chip {
  border: 1px solid color-mix(in srgb, var(--tag, var(--accent)) 30%, var(--line));
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.tag-chip:hover {
  border-color: var(--tag, var(--accent));
  background: color-mix(in srgb, var(--tag, var(--accent)) 10%, #fff);
}
.tag-chip.is-on {
  background: color-mix(in srgb, var(--tag, var(--accent)) 18%, #fff);
  color: color-mix(in srgb, var(--tag, var(--accent)) 70%, #102833);
  border-color: color-mix(in srgb, var(--tag, var(--accent)) 55%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tag, var(--accent)) 20%, transparent);
}
.tag-create-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.tag-create-row input { flex: 1; min-width: 0; }
.tag-create-row .btn { flex: 0 0 auto; white-space: nowrap; }
.tag-menu-create {
  padding: 4px 8px 8px;
}
.tag-menu-create .tag-create-row {
  gap: 6px;
}
.tag-menu-create .tag-create-row input {
  padding: 8px 10px;
  font-size: 13px;
}
.tag-menu-create .btn {
  padding: 8px 12px;
  font-size: 13px;
}
.tag-menu-empty {
  margin: 8px 10px;
  font-size: 12px;
  color: var(--muted);
}
.tag-menu-list {
  max-height: 220px;
  overflow: auto;
}

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(8, 24, 32, .52);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 40;
  backdrop-filter: blur(3px);
}
.modal-bg.open { display: flex; animation: fadeIn .16s ease; }
.modal {
  background: #fff;
  width: min(920px, 100%);
  max-height: 92vh;
  overflow: auto;
  border-radius: 20px;
  padding: 22px;
  box-shadow: var(--shadow-lg);
  animation: riseIn .2s ease;
}
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #8fd0c6;
  box-shadow: 0 0 0 3px rgba(15, 159, 140, .14);
}
textarea { min-height: 96px; resize: vertical; }

.audio-section {
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.audio-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.audio-head label { margin-bottom: 0; font-size: 13px; color: var(--text); font-weight: 600; }
.audio-hint { font-size: 12px; color: var(--muted); }
.audio-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.audio-list:empty { display: none; }
.audio-item {
  background: #f7fafb;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.audio-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.audio-item-name {
  font-size: 13px;
  font-weight: 600;
  word-break: break-word;
}
.audio-item-sub {
  font-size: 12px;
  color: var(--muted);
}
.audio-item-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.audio-item audio { width: 100%; height: 36px; }
.audio-upload {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.audio-upload input[type="file"] {
  flex: 1;
  min-width: 180px;
  padding: 8px 10px;
  background: #f8fafc;
}

.flash {
  background: #ecfdf5;
  color: #065f46;
  padding: 11px 14px;
  border-radius: 12px;
  margin-bottom: 16px;
  border: 1px solid #bbf7d0;
}
.flash.err {
  background: #fff1f2;
  color: #9f1239;
  border-color: #fecdd3;
}
.table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.table th, .table td {
  text-align: right;
  padding: 12px 14px;
  border-bottom: 1px solid #eef2f6;
  font-size: 14px;
}
.table th { background: #f7fafc; color: var(--muted); font-weight: 600; }
code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 12px;
}
.panel {
  background: #fff;
  padding: 18px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  max-width: 640px;
}
.docs {
  background: #fff;
  padding: 22px;
  border-radius: 18px;
  max-width: 900px;
  box-shadow: var(--shadow);
}
.docs p, .docs li { line-height: 1.9; }

.login-wrap {
  min-height: 100vh;
  width: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(700px 360px at 15% 20%, rgba(15, 159, 140, .28), transparent 55%),
    radial-gradient(800px 420px at 90% 80%, rgba(37, 99, 235, .18), transparent 50%),
    #0b2430;
  padding: 24px;
}
.login-card {
  width: min(420px, 92vw);
  background: rgba(255, 255, 255, .96);
  padding: 30px 28px;
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  animation: riseIn .28s ease;
}
.login-card h1 {
  margin: 0 0 6px;
  font-size: 28px;
}
.login-card .sub {
  color: var(--muted);
  margin: 0 0 20px;
  line-height: 1.7;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: #123040;
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: .22s ease;
  z-index: 60;
  box-shadow: var(--shadow-lg);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.err { background: #9f1239; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes riseIn {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: none; }
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 1100px) {
  .board { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 800px) {
  body { display: block; }
  .nav-toggle { display: inline-flex; }
  .sidebar {
    width: auto;
    min-height: auto;
    position: sticky;
    top: 0;
    padding-bottom: 12px;
  }
  .sidebar nav {
    display: none;
    flex-direction: row;
    flex-wrap: wrap;
  }
  body.nav-open .sidebar nav { display: flex; }
  .board, .grid { grid-template-columns: 1fr; }
  .column, .cards { min-height: 180px; }
  .search { min-width: 0; width: 100%; }
  .source-dropdown { width: 100%; }
  .source-trigger { width: 100%; }
  .source-trigger-label { flex: 1; }
  .source-menu { inset-inline: 0; width: auto; }
}
