:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #191d24;
  --text: #eff2f8;
  --muted: #a8b2c3;
  --line: #303949;
  --accent: #67a7ff;
  --danger: #ff8080;
  --ok: #7fd18b;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app {
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 12px;
}

.header {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header h1 {
  margin: 0;
  font-size: 22px;
}

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

.banner {
  padding: 10px 12px;
  border: 1px solid #7a3b3b;
  border-radius: 10px;
  background: #3a1d1d;
  color: #ffd7d7;
}

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

.controls {
  display: grid;
  gap: 12px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 230px;
}

.field.grow {
  flex: 1 1 360px;
}

.field.small {
  min-width: 170px;
}

.field.checkbox {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: auto;
  min-height: 38px;
}

.field-label {
  color: var(--muted);
  font-size: 13px;
  margin-right: 4px;
}

.small-hint {
  font-size: 12px;
  max-width: 460px;
  line-height: 1.35;
}

input,
select,
button,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11151c;
  color: var(--text);
  padding: 8px 10px;
  font-size: 14px;
}

textarea {
  resize: vertical;
}

button {
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #07101f;
  font-weight: 600;
}

.primary:hover:not(:disabled) {
  background: #7db5ff;
  border-color: #7db5ff;
}

.danger {
  color: var(--danger);
  border-color: #5a2c2c;
}

.danger:hover:not(:disabled) {
  border-color: var(--danger);
}

.file-drop {
  display: grid;
  gap: 4px;
  flex: 1 1 340px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.file-drop:hover,
.file-drop.drag {
  border-color: var(--accent);
  background: rgba(103, 167, 255, 0.08);
}

.file-drop input {
  display: none;
}

.file-title {
  font-weight: 600;
}

.file-hint {
  font-size: 13px;
}

.import-status {
  flex: 1 1 320px;
  font-size: 13px;
  line-height: 1.4;
  max-width: 620px;
}

.import-status.error {
  color: var(--danger);
}

.filters summary {
  cursor: pointer;
  font-weight: 600;
  list-style-position: inside;
}

.filters[open] summary {
  margin-bottom: 10px;
}

.filters .row + .row {
  margin-top: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #07101f;
  font-size: 12px;
  font-weight: 700;
}

.tools {
  align-items: center;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}

.stat {
  display: grid;
  gap: 4px;
}

.stat b {
  font-size: 18px;
}

.table-wrap {
  overflow: auto;
  padding: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 1180px;
}

.col-company {
  width: 32%;
}

.col-city {
  width: 6%;
}

.col-rating,
.col-reviews {
  width: 5%;
}

.col-contacts {
  width: 18%;
}

.col-call {
  width: 23%;
}

.col-channels {
  width: 11%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}

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

a:hover {
  text-decoration: underline;
}

.cell-company b {
  display: block;
  font-size: 15px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.cell-address,
.cell-niches {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.cell-call {
  min-width: 0;
}

.cell-call .call-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 6px;
}

.cell-call .call-head .status-select,
.cell-call .call-head .date-input {
  width: 100%;
}

.cell-call .comment-input {
  width: 100%;
  margin-top: 6px;
}

.quick-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 4px;
}

.quick-date {
  padding: 2px 6px;
  font-size: 11px;
  line-height: 1.2;
  border-radius: 999px;
  color: var(--muted);
  background: #11151c;
}

.quick-date:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--text);
}

.quick-date.is-active {
  border-color: var(--accent);
  background: rgba(103, 167, 255, 0.16);
  color: var(--text);
}

.comment-input {
  min-height: 34px;
}

.contact-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  display: inline-block;
  vertical-align: -2px;
}

.contact-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 7px;
  white-space: normal;
  overflow-wrap: anywhere;
  color: var(--accent);
  transition: border-color 0.15s, background 0.15s;
}

.contact-chip:hover {
  border-color: currentColor;
  filter: brightness(1.12);
  text-decoration: none;
}

.contact-chip-site {
  color: #67a7ff;
  border-color: rgba(103, 167, 255, 0.38);
  background: rgba(103, 167, 255, 0.08);
}

.contact-chip-email {
  color: #f0b45c;
  border-color: rgba(240, 180, 92, 0.38);
  background: rgba(240, 180, 92, 0.08);
}

.contact-chip-whatsapp {
  color: #3ddc84;
  border-color: rgba(61, 220, 132, 0.38);
  background: rgba(61, 220, 132, 0.08);
}

.contact-chip-telegram {
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.38);
  background: rgba(56, 189, 248, 0.08);
}

.contact-chip-vk {
  color: #6f8cff;
  border-color: rgba(111, 140, 255, 0.38);
  background: rgba(111, 140, 255, 0.08);
}

.contact-chip-phone {
  color: #2dd4bf;
  border-color: rgba(45, 212, 191, 0.38);
  background: rgba(45, 212, 191, 0.08);
}

.channels {
  display: grid;
  grid-template-columns: repeat(2, minmax(52px, auto));
  gap: 6px 10px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.channels label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.channels input {
  width: 15px;
  height: 15px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 14px;
}

.pagination .page-info {
  color: var(--muted);
}

.pagination .page-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pagination .page-btn {
  padding: 6px 10px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.pagination .page-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.pagination .page-btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.pagination .page-num {
  font-weight: 600;
  min-width: 60px;
  text-align: center;
  color: var(--text);
}

.empty {
  color: var(--muted);
  padding: 20px 8px;
}

.cards {
  display: grid;
  gap: 10px;
}

.lead-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 10px;
}

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

.lead-head b {
  font-size: 16px;
}

.lead-rating {
  color: #ffd479;
  white-space: nowrap;
  font-size: 13px;
}

.lead-niches {
  color: var(--muted);
  font-size: 12px;
  margin-top: -4px;
}

.contact-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.contact-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #11151c;
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
}

.contact-button:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.contact-button-call {
  border-color: #2e9e63;
  background: #1f8a4c;
  color: #f2fff7;
}

.contact-button-call:hover {
  border-color: #46c07f;
  background: #25a35a;
}

.contact-button-site {
  color: #67a7ff;
  border-color: rgba(103, 167, 255, 0.38);
  background: rgba(103, 167, 255, 0.08);
}

.contact-button-email {
  color: #f0b45c;
  border-color: rgba(240, 180, 92, 0.38);
  background: rgba(240, 180, 92, 0.08);
}

.contact-button-whatsapp {
  color: #3ddc84;
  border-color: rgba(61, 220, 132, 0.38);
  background: rgba(61, 220, 132, 0.08);
}

.contact-button-telegram {
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.38);
  background: rgba(56, 189, 248, 0.08);
}

.contact-button-vk {
  color: #6f8cff;
  border-color: rgba(111, 140, 255, 0.38);
  background: rgba(111, 140, 255, 0.08);
}

.call-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.call-controls select,
.call-controls input {
  min-height: 44px;
}

.lead-card .comment-input {
  min-height: 58px;
  font-size: 14px;
}

.mobile-only {
  display: none;
}

.desktop-only {
  display: block;
}

#nextFloat {
  display: none;
}

@media (max-width: 760px) {
  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: block;
  }

  .cards.mobile-only {
    display: grid;
  }

  .pagination.mobile-only {
    display: flex;
  }

  .app {
    padding: 10px 10px 90px;
    gap: 10px;
  }

  .header {
    gap: 10px;
  }

  .header h1 {
    font-size: 20px;
  }

  .field,
  .field.grow {
    min-width: 100%;
    flex: 1 1 100%;
  }

  .field.small {
    min-width: calc(50% - 5px);
    flex: 1 1 calc(50% - 5px);
  }

  .field.checkbox {
    min-width: 100%;
    flex: 1 1 100%;
    min-height: 44px;
  }

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

  .stat b {
    font-size: 16px;
  }

  input,
  select,
  button,
  textarea {
    font-size: 16px;
  }

  button {
    min-height: 42px;
  }

  .pagination {
    gap: 8px;
    font-size: 13px;
    flex-wrap: wrap;
  }

  .call-controls {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .quick-dates {
    gap: 6px;
  }

  .quick-date {
    min-height: 30px;
    padding: 3px 10px;
    font-size: 12px;
  }

  #nextFloat {
    display: block;
    position: fixed;
    right: 12px;
    bottom: 12px;
    z-index: 20;
    min-height: 48px;
    padding: 10px 18px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  }
}

/* --------------------------------------------------------------------------
   Серверная панель: навигация, роли, административные экраны
   -------------------------------------------------------------------------- */
.app-header {
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.header-left h1 {
  font-size: 22px;
}

.header-right {
  justify-content: flex-end;
}

.badge-muted {
  background: #2b3444;
  color: var(--muted);
}

.badge-ok {
  background: rgba(61, 220, 132, 0.16);
  color: #7fe0aa;
}

.badge-warn {
  background: rgba(240, 180, 92, 0.16);
  color: #f0b45c;
}

.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--accent);
}

.nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.nav-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
}

.nav-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.nav-btn.is-active {
  color: #07101f;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.view {
  display: grid;
  gap: 12px;
}

body:not(.is-admin) .admin-only,
body:not(.is-admin) .admin-col {
  display: none !important;
}

body.is-admin .manager-only {
  display: none !important;
}

body.is-admin .col-company {
  width: 27%;
}

body.is-admin .col-city {
  width: 6%;
}

body.is-admin .col-rating,
body.is-admin .col-reviews {
  width: 5%;
}

body.is-admin .col-contacts {
  width: 16%;
}

body.is-admin .col-call {
  width: 26%;
}

body.is-admin .col-manager {
  width: 15%;
}

body:not(.is-admin) .col-company {
  width: 35%;
}

body:not(.is-admin) .col-city {
  width: 7%;
}

body:not(.is-admin) .col-rating,
body:not(.is-admin) .col-reviews {
  width: 6%;
}

body:not(.is-admin) .col-contacts {
  width: 18%;
}

body:not(.is-admin) .col-call {
  width: 28%;
}

.lead-name {
  display: block;
  font-size: 15px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.lead-sub {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.lead-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.lead-badges .badge {
  margin-left: 0;
  height: 18px;
  font-size: 10px;
  font-weight: 600;
}

.badge-hidden {
  background: #3a2a1d;
  color: #f0b45c;
}

.badge-pool {
  background: rgba(103, 167, 255, 0.15);
  color: var(--accent);
}

.badge-assigned {
  background: rgba(61, 220, 132, 0.13);
  color: #7fe0aa;
}

.manager-select {
  width: 100%;
  min-height: 34px;
  font-size: 12px;
}

.claim-btn {
  width: 100%;
  min-height: 36px;
  border-color: #2e9e63;
  background: #1f8a4c;
  color: #f2fff7;
  font-weight: 600;
}

.claim-btn:hover:not(:disabled) {
  border-color: #46c07f;
  background: #25a35a;
}

.outreach-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
}

.outreach-row label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.outreach-row input {
  width: 14px;
  height: 14px;
  margin: 0;
}

.copy-btn {
  border: 1px solid var(--line);
  background: #11151c;
  color: var(--muted);
  border-radius: 7px;
  padding: 4px 7px;
  font-size: 11px;
  margin-top: 6px;
}

.copy-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.simple-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  table-layout: auto;
}

.simple-table th,
.simple-table td {
  padding: 8px;
  font-size: 13px;
  vertical-align: middle;
}

.simple-table th {
  position: static;
}

.simple-table td.actions {
  white-space: nowrap;
}

.simple-table td.actions button,
.simple-table td.actions a {
  margin-right: 4px;
}

.scope-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  max-width: 260px;
}

.scope-tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #222b39;
  color: var(--muted);
}

.import-results {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  font-size: 13px;
}

.import-result {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11151c;
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: #11151c;
  overflow: hidden;
  margin-top: 10px;
}

.progress > div {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s;
}

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

.distribution-grid h3 {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--muted);
}

.check-list {
  max-height: 210px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: #11151c;
  display: grid;
  gap: 2px;
}

.check-list label {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 12px;
  line-height: 1.3;
  padding: 2px 0;
  cursor: pointer;
}

.check-list input {
  width: 15px;
  height: 15px;
  margin: 1px 0 0;
  flex: 0 0 15px;
}

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

.scope-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.scope-grid h3 {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--muted);
}

.scope-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
}

.scope-head h3 {
  margin: 0;
}

.scope-actions {
  display: flex;
  gap: 4px;
}

.scope-actions .ghost {
  min-height: 26px;
  padding: 2px 8px;
  font-size: 11px;
}

.scope-name {
  flex: 1;
}

.scope-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.scope-summary {
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11151c;
  font-size: 12px;
  line-height: 1.4;
}

.scope-summary b {
  color: var(--text);
}

.dialog-actions {
  margin-top: 14px;
}

dialog {
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  background: var(--panel);
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

dialog h2 {
  margin: 0 0 12px;
  font-size: 19px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 100;
  max-width: min(560px, calc(100vw - 24px));
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid #2e9e63;
  background: #173d2a;
  color: #eafff2;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  font-size: 13px;
}

.toast.error {
  border-color: #7a3b3b;
  background: #3a1d1d;
  color: #ffd7d7;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 20% 0%, rgba(103, 167, 255, 0.14), transparent 40%),
    radial-gradient(circle at 100% 100%, rgba(61, 220, 132, 0.08), transparent 35%),
    var(--bg);
}

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

.login-logo {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #07101f;
  font-weight: 800;
  font-size: 22px;
}

.login-card h1 {
  margin: 0;
  font-size: 26px;
}

.login-card p {
  margin: 0;
  line-height: 1.45;
}

.login-form {
  display: grid;
  gap: 12px;
  margin-top: 8px;
}

.login-form .field {
  min-width: 0;
}

.login-form .primary {
  min-height: 44px;
  margin-top: 4px;
}

.login-foot {
  font-size: 12px;
  margin-top: 4px;
}

.empty-cell {
  color: var(--muted);
  padding: 18px 8px;
  text-align: center;
}

@media (max-width: 760px) {
  .app-header {
    align-items: flex-start;
  }

  .header-right {
    gap: 6px;
  }

  .header-right .ghost {
    min-height: 36px;
    padding: 6px 9px;
  }

  .nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .nav-btn {
    flex: 0 0 auto;
  }

  .distribution-grid,
  .form-grid,
  .scope-grid {
    grid-template-columns: 1fr;
  }

  .simple-table {
    min-width: 700px;
  }

  .lead-card {
    padding: 12px;
  }

  .lead-card .manager-select {
    min-height: 40px;
  }

  .login-card {
    padding: 22px;
  }
}

.contact-chip-max,
.contact-button-max {
  color: #a78bfa;
  border-color: rgba(167, 139, 250, 0.38);
  background: rgba(167, 139, 250, 0.08);
}

.contact-chip-viber,
.contact-button-viber {
  color: #8b7cff;
  border-color: rgba(139, 124, 255, 0.38);
  background: rgba(139, 124, 255, 0.08);
}

.contact-chip-ok {
  color: #f59e0b;
  border-color: rgba(245, 158, 11, 0.38);
  background: rgba(245, 158, 11, 0.08);
}

.contact-chip-youtube {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.38);
  background: rgba(239, 68, 68, 0.08);
}
