:root {
  --bg: #0f1416;
  --panel: #161d21;
  --panel-2: #1e282d;
  --text: #e8f0ee;
  --muted: #9cb1ab;
  --accent: #1ec17f;
  --accent-soft: rgba(30, 193, 127, 0.16);
  --danger: #ff6a6a;
  --line: rgba(255, 255, 255, 0.1);
  --new: #3a6ff8;
  --contacted: #f59f00;
  --qualified: #9775fa;
  --proposal: #00b4d8;
  --won: #20c997;
  --lost: #868e96;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: "Nunito", "Segoe UI", Tahoma, sans-serif;
  background: radial-gradient(circle at 10% 10%, #1b2a24, #0f1416 40%), var(--bg);
  color: var(--text);
  min-height: 100%;
}

.hidden {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.auth-card h1 {
  margin: 0 0 8px;
  font-size: 1.6rem;
}

.auth-card p {
  margin: 0 0 20px;
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-form label {
  display: grid;
  gap: 8px;
  font-weight: 700;
  font-size: 0.92rem;
}

.auth-form input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #11181b;
  color: var(--text);
  font: inherit;
}

.auth-form button {
  margin-top: 8px;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(140deg, #1ec17f, #17a86d);
  color: #062115;
  font-weight: 900;
  cursor: pointer;
}

.auth-error {
  min-height: 22px;
  margin-top: 12px;
  color: #ff9393;
  font-size: 0.92rem;
}

.crm-app {
  padding: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.topbar h2 {
  margin: 0;
  font-size: 1.3rem;
}

.topbar p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  color: #062115;
  background: linear-gradient(140deg, #1ec17f, #17a86d);
}

.btn.ghost {
  background: #202c2f;
  color: var(--text);
  border: 1px solid var(--line);
}

.btn.save {
  width: 100%;
  margin-top: 12px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.stat-card h4 {
  margin: 0 0 6px;
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-card .value {
  font-size: 1.35rem;
  font-weight: 900;
}

.filters {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 10px;
  margin-bottom: 12px;
}

.filters input,
.filters select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

.board {
  display: grid;
  grid-template-columns: repeat(6, minmax(240px, 1fr));
  gap: 10px;
  align-items: start;
  overflow-x: auto;
  padding-bottom: 12px;
}

.column {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  min-height: 240px;
  display: flex;
  flex-direction: column;
}

.column-header {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 900;
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}

.column-body {
  padding: 10px;
  display: grid;
  gap: 8px;
}

.badge {
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
  background: #273034;
}

.badge.new { background: color-mix(in srgb, var(--new) 20%, transparent); color: #9bb8ff; }
.badge.contacted { background: color-mix(in srgb, var(--contacted) 22%, transparent); color: #ffe08a; }
.badge.qualified { background: color-mix(in srgb, var(--qualified) 22%, transparent); color: #d8c5ff; }
.badge.proposal { background: color-mix(in srgb, var(--proposal) 22%, transparent); color: #9de8ff; }
.badge.won { background: color-mix(in srgb, var(--won) 20%, transparent); color: #a6f8d8; }
.badge.lost { background: color-mix(in srgb, var(--lost) 20%, transparent); color: #d3d8dc; }

.lead-card {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.lead-card:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
}

.lead-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.lead-name {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 900;
}

.lead-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.lead-meta {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-chip {
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 0.72rem;
}

.lead-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(520px, 100%);
  height: 100dvh;
  background: #12191d;
  border-left: 1px solid var(--line);
  box-shadow: -24px 0 60px rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.drawer-header h3 {
  margin: 0;
}

.icon-btn {
  border: none;
  background: #202c2f;
  color: var(--text);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 1.2rem;
  cursor: pointer;
}

.drawer-body {
  padding: 14px;
  overflow: auto;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-grid label {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.value {
  font-weight: 800;
  word-break: break-word;
}

.edit-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.edit-grid label,
.notes-wrap {
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 700;
}

.edit-grid input,
.edit-grid select,
.notes-wrap textarea,
.comment-form input,
.comment-form textarea,
.telegram-form input,
.telegram-form select,
.telegram-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #0f1619;
  color: var(--text);
  font: inherit;
}

.comments {
  margin-top: 18px;
}

.comments h4 {
  margin: 0 0 8px;
}

.comments-list {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.comment-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #1a2327;
  padding: 10px;
}

.comment-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.76rem;
  margin-bottom: 4px;
}

.comment-text {
  margin: 0;
  white-space: pre-wrap;
}

.comment-form {
  display: grid;
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: #11181b;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 120;
}

.toast.show {
  opacity: 1;
}

.empty-column {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 16px 8px;
  border: 1px dashed var(--line);
  border-radius: 10px;
}

@media (max-width: 1200px) {
  .stats {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
  }
}

@media (max-width: 900px) {
  .filters {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .board {
    grid-template-columns: repeat(6, minmax(220px, 1fr));
  }
}

.lead-page-shell {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 16px 10px;
}

.lead-page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.lead-page-header h1 {
  margin: 0;
  font-size: 1.35rem;
}

.lead-page-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.lead-page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.lead-page-layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.lead-main-card,
.lead-telegram-card,
.lead-side-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  padding: 14px;
}

.lead-telegram-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.telegram-head h4 {
  margin: 0;
}

.telegram-channel {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.telegram-messages {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #11181b;
  padding: 10px;
  min-height: 420px;
  max-height: 620px;
  overflow: auto;
  display: grid;
  gap: 8px;
}

.tg-message {
  max-width: 96%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #182127;
}

.tg-message.out {
  justify-self: end;
  background: rgba(30, 193, 127, 0.15);
  border-color: rgba(30, 193, 127, 0.35);
}

.tg-message.in {
  justify-self: start;
  background: #1a2327;
}

.tg-message-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 4px;
}

.tg-message-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.telegram-form {
  display: grid;
  gap: 8px;
}

.lead-history-block {
  margin-top: 14px;
}

@media (max-width: 1024px) {
  .lead-page-layout {
    grid-template-columns: 1fr;
  }

  .telegram-messages {
    min-height: 260px;
    max-height: 360px;
  }
}
