:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #eef4f8;
  --line: #d9e2ea;
  --text: #18232e;
  --muted: #627282;
  --accent: #167c80;
  --accent-strong: #0f5f63;
  --danger: #b4233a;
  --shadow: 0 16px 46px rgba(31, 44, 58, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

.small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.danger {
  background: var(--danger);
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.secondary {
  color: var(--text);
  background: var(--panel-soft);
}

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

.auth-panel {
  width: min(440px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand > span {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.message,
.topbar p,
td,
.list span {
  color: var(--muted);
}

.form {
  display: grid;
  gap: 13px;
  margin-top: 20px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
  outline: 0;
}

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

nav {
  display: grid;
  gap: 8px;
}

.nav {
  justify-content: flex-start;
  color: var(--muted);
  background: transparent;
  text-align: left;
}

.nav.active,
.nav:hover {
  color: var(--text);
  background: var(--panel-soft);
}

.sidebar .secondary {
  margin-top: auto;
}

.content {
  min-width: 0;
  padding: 28px;
}

.topbar,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.metrics article,
.card,
.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 18px;
}

.metrics span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 34px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  background: var(--panel-soft);
}

td strong {
  color: var(--text);
}

.users-grid,
.searches-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 14px;
}

.map-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 14px;
  min-height: calc(100vh - 140px);
}

.pipeline-toolbar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 220px;
  gap: 12px;
  margin-bottom: 14px;
}

.pipeline-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(260px, 1fr));
  gap: 14px;
  align-items: start;
  overflow-x: auto;
  padding-bottom: 8px;
}

.pipeline-column {
  min-height: 420px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.pipeline-column.drop-target {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pipeline-column h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.pipeline-column h2 span {
  color: var(--muted);
  font-size: 13px;
}

.pipeline-list {
  display: grid;
  gap: 10px;
}

.pipeline-card,
.empty-column {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.pipeline-card {
  cursor: pointer;
}

.pipeline-card:active {
  cursor: grabbing;
}

.pipeline-card:hover {
  border-color: var(--accent);
}

.pipeline-card strong,
.pipeline-card span,
.pipeline-card small {
  display: block;
}

.pipeline-card span,
.pipeline-card small,
.empty-column {
  color: var(--muted);
}

.map-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.map {
  min-height: calc(100vh - 140px);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.legend {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.lead-dot {
  background: #2563eb;
}

.cold-dot {
  background: #f59e0b;
}

.client-dot {
  background: #16a34a;
}

.stale-dot {
  background: #ea580c;
}

.leaflet-popup-content {
  display: grid;
  gap: 4px;
}

.leaflet-popup-content span {
  display: block;
  color: var(--muted);
}

.card {
  padding: 18px;
}

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

.list article {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.list strong,
.list span {
  display: block;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--text);
  box-shadow: var(--shadow);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(24, 35, 46, 0.38);
}

.modal {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 21;
  width: min(520px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal textarea {
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  resize: vertical;
}

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

.crm-actions {
  display: grid;
  margin-top: 14px;
}

.crm-panel {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.compact-form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.mini-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.mini-list article {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.mini-list strong,
.mini-list span {
  display: block;
}

.mini-list span,
.mini-list p {
  color: var(--muted);
  margin: 3px 0 0;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .metrics,
  .users-grid,
  .searches-grid,
  .map-layout,
  .pipeline-toolbar {
    grid-template-columns: 1fr;
  }

  .map,
  .map-layout {
    min-height: 520px;
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .row-actions {
    justify-content: flex-start;
  }
}
