:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #86868b;
  --line: #e8e8ed;
  --accent: #0071e3;
  --accent-press: #0060c0;
  --green: #34c759;
  --red: #ff3b30;
  --amber: #ff9f0a;
  --radius: 18px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

/* ---------- Бренд ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1d1d1f, #3a3a3c);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  display: grid;
  place-items: center;
}
.brand-name {
  font-weight: 700;
  font-size: 19px;
}
.brand.small .brand-mark {
  width: 30px;
  height: 30px;
  font-size: 16px;
}
.brand.small .brand-name {
  font-size: 17px;
}

/* ---------- Логин ---------- */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  background: #0d0906 url('assets/login-bg.webp') center / cover no-repeat fixed;
}
.login-view::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(10, 7, 4, 0.35) 0%,
    rgba(10, 7, 4, 0.62) 100%
  );
}
.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 390px;
  background: rgba(28, 20, 14, 0.5);
  backdrop-filter: blur(26px) saturate(150%);
  -webkit-backdrop-filter: blur(26px) saturate(150%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 24px;
  padding: 42px 36px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  color: #fff;
}
.login-logo {
  display: block;
  width: 150px;
  height: auto;
  margin: 0 auto 26px;
}
.login-title {
  font-size: 23px;
  font-weight: 700;
  text-align: center;
  color: #fff;
}
.login-sub {
  color: rgba(255, 255, 255, 0.6);
  text-align: center;
  margin: 6px 0 28px;
  font-size: 14px;
}
.field {
  display: block;
  margin-bottom: 16px;
}
.field span {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.65);
  margin-bottom: 7px;
}
.field input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 13px 15px;
  font-size: 15px;
  font-family: inherit;
  color: #fff;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.field input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}
.field input:focus {
  outline: none;
  border-color: rgba(201, 138, 60, 0.8);
  box-shadow: 0 0 0 3px rgba(201, 138, 60, 0.25);
  background: rgba(255, 255, 255, 0.12);
}
.login-error {
  background: rgba(255, 69, 58, 0.18);
  border: 1px solid rgba(255, 69, 58, 0.3);
  color: #ff9d96;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 14px;
}
.login-card .btn-primary {
  background: linear-gradient(135deg, #d29648, #a5641b);
  box-shadow: 0 8px 24px rgba(165, 100, 27, 0.35);
}
.login-card .btn-primary:hover {
  background: linear-gradient(135deg, #dba455, #b06e22);
}
.topbar-logo {
  height: 26px;
  width: auto;
  display: block;
}

/* ---------- Кнопки ---------- */
.btn-primary {
  width: 100%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-weight: 600;
  font-size: 15px;
  padding: 14px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.btn-primary:hover {
  background: var(--accent-press);
}
.btn-primary:active {
  transform: scale(0.99);
}
.btn-ghost {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-weight: 500;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-ghost:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text);
}

/* ---------- Топбар ---------- */
.topbar {
  height: 60px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.tabs {
  display: flex;
  gap: 4px;
  background: #ececf0;
  padding: 4px;
  border-radius: 12px;
}
.tab {
  border: none;
  background: transparent;
  font-family: inherit;
  font-weight: 500;
  font-size: 14px;
  color: var(--muted);
  padding: 7px 18px;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.15s;
}
.tab.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.content {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 22px 60px;
}

/* ---------- WhatsApp таб ---------- */
.wa-stage {
  min-height: 66vh;
  display: grid;
  place-items: center;
}
.wa-card {
  background: var(--surface);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 44px 40px;
  text-align: center;
  max-width: 420px;
  width: 100%;
  animation: fadeUp 0.4s ease;
}
.wa-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin-top: 20px;
}
.wa-card p {
  margin-top: 6px;
  font-size: 14px;
}
.qr-box {
  width: 260px;
  height: 260px;
  margin: 24px auto 8px;
  border-radius: 18px;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  background: #fff;
  overflow: hidden;
}
.qr-box img {
  width: 240px;
  height: 240px;
}
.wa-steps {
  text-align: left;
  margin: 22px auto 0;
  max-width: 300px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.9;
  padding-left: 18px;
}
.wa-steps b {
  color: var(--text);
  font-weight: 600;
}

/* Успех — пульс */
.pulse-ring {
  width: 96px;
  height: 96px;
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
}
.pulse-ring::before,
.pulse-ring::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--green);
  animation: pulse 2s ease-out infinite;
}
.pulse-ring::after {
  animation-delay: 1s;
}
.pulse-core {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: grid;
  place-items: center;
  animation: pop 0.5s ease;
  z-index: 1;
}
@keyframes pulse {
  0% {
    transform: scale(0.7);
    opacity: 0.8;
  }
  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}
@keyframes pop {
  0% {
    transform: scale(0);
  }
  60% {
    transform: scale(1.15);
  }
  100% {
    transform: scale(1);
  }
}
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
  background: rgba(52, 199, 89, 0.12);
  color: #248a3d;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 20px;
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: blink 1.6s ease-in-out infinite;
}
@keyframes blink {
  0%,
  100% {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.5);
  }
  50% {
    opacity: 0.5;
    box-shadow: 0 0 0 6px rgba(52, 199, 89, 0);
  }
}

/* Спиннер */
.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Дашборд ---------- */
.dashboard {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}
.stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.stat .val {
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
}
.stat .lbl {
  color: var(--muted);
  font-size: 13px;
  margin-top: 8px;
}
.stat.accent .val {
  color: var(--green);
}

/* ---------- CRM тулбар ---------- */
.crm-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.search-wrap {
  position: relative;
  flex: 1;
  max-width: 360px;
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
#search {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 11px 14px 11px 38px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
#search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}
.btn-export {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-weight: 500;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-export:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Канбан ---------- */
.kanban {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  align-items: start;
}
.col {
  background: #ededf1;
  border-radius: var(--radius);
  padding: 14px;
  min-height: 200px;
  transition: background 0.15s;
}
.col.drop-hover {
  background: #e2e8f5;
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}
.col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 12px;
}
.col-title {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.col-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}
.col[data-stage='new'] .col-dot {
  background: var(--accent);
}
.col[data-stage='bought'] .col-dot {
  background: var(--green);
}
.col[data-stage='lost'] .col-dot {
  background: var(--muted);
}
.col-count {
  background: rgba(0, 0, 0, 0.06);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 20px;
}

.card {
  background: var(--surface);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  cursor: grab;
  transition: box-shadow 0.15s, transform 0.15s;
  animation: fadeUp 0.3s ease;
}
.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}
.card.dragging {
  opacity: 0.4;
}
.card .phone {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.card .name {
  color: var(--muted);
  font-size: 13.5px;
  margin-top: 3px;
}
.card .meta {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card .chip {
  display: inline-block;
  margin-top: 12px;
  background: rgba(52, 199, 89, 0.12);
  color: #248a3d;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 8px;
}
.card .note-preview {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--muted);
  background: #f5f5f7;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  gap: 6px;
  line-height: 1.35;
}
.card .note-preview svg {
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--amber);
}
.src-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 6px;
  margin-bottom: 10px;
  letter-spacing: 0.02em;
}
.src-instagram {
  background: rgba(214, 41, 118, 0.12);
  color: #c13584;
}
.src-telegram {
  background: rgba(34, 158, 217, 0.14);
  color: #1c8fc4;
}
.src-bot {
  background: rgba(88, 86, 214, 0.13);
  color: #5856d6;
}
.src-organic {
  background: rgba(52, 199, 89, 0.13);
  color: #248a3d;
}
.empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 30px 10px;
}

/* ---------- Модалка ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  z-index: 50;
  animation: fadeIn 0.2s ease;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: 22px;
  padding: 30px;
  max-width: 460px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: fadeUp 0.25s ease;
  text-align: center;
}
.modal h3 {
  font-size: 20px;
  font-weight: 700;
}
.modal .muted {
  font-size: 13.5px;
  margin-top: 6px;
}
.purchase-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 22px 0 14px;
}
.purchase-item {
  border: 1px solid var(--line);
  background: #fbfbfd;
  border-radius: 14px;
  padding: 16px 14px;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  text-align: left;
  transition: all 0.13s;
}
.purchase-item:hover {
  border-color: var(--accent);
  background: #fff;
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.modal-cancel {
  margin-top: 4px;
}

/* Модалка клиента */
.lead-modal {
  text-align: left;
}
.lead-phone {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.lead-name {
  font-size: 14px;
  margin-top: 2px;
}
.lead-detail {
  margin-top: 16px;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.7;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.lead-detail b {
  color: var(--text);
  font-weight: 600;
}
.note-label {
  display: block;
  margin-top: 18px;
}
.note-label span {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 8px;
}
#lead-note {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfbfd;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#lead-note:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
  background: #fff;
}
.lead-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.btn-primary.compact {
  width: auto;
  padding: 11px 22px;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ---------- Адаптив ---------- */
@media (max-width: 900px) {
  .dashboard {
    grid-template-columns: repeat(2, 1fr);
  }
  .kanban {
    grid-template-columns: 1fr;
  }
}
