:root {
  --gold: #d3ba36;
  --gold-soft: rgba(211, 186, 54, 0.16);
  --bg: #131313;
  --bg-2: #1f1f1f;
  --bg-3: #181818;
  --panel: #161616;
  --surface: #202020;
  --surface-2: #252525;
  --white: #ffffff;
  --gray: #cccccc;
  --gray-soft: #9d9d9d;
  --border: #333333;
  --danger: #f87171;
  --success: #34d399;
  --info: #60a5fa;
  --residential: #5aa2ff;
  --commercial: #ff9b55;
  --parcel: #37c97f;
  --alerts: #b78cff;
  --routes: #f5dd73;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.3);
  --radius: 18px;
  --topbar-height: 92px;
  --transition: 160ms ease;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--white);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

img {
  display: block;
  max-width: 100%;
}

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

button,
select,
input,
textarea {
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--white);
}

button {
  cursor: pointer;
}

textarea,
input,
select {
  width: 100%;
  padding: 12px 14px;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background:
    radial-gradient(circle at top right, rgba(211, 186, 54, 0.16), transparent 26%),
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.05), transparent 22%),
    var(--bg);
}

.topbar {
  min-height: var(--topbar-height);
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.7fr) auto;
  align-items: center;
  gap: 18px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(24, 24, 24, 0.98), rgba(19, 19, 19, 0.96));
  position: sticky;
  top: 0;
  z-index: 1100;
  backdrop-filter: blur(18px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand-lockup__logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  border: 1px solid rgba(211, 186, 54, 0.25);
  box-shadow: var(--shadow);
  background: #111111;
  object-fit: cover;
  flex: none;
}

.brand-lockup h1,
.detail-panel h2,
.detail-empty h2,
.modal-card h2,
.section-heading h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 0.01em;
}

.brand-lockup h1 {
  font-size: 1.55rem;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--gray);
  font-size: 0.92rem;
  line-height: 1.4;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.topbar-status,
.topbar-actions,
.toolbar,
.toolbar-inline,
.toolbar--compact,
.toolbar--align-end {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-status {
  justify-content: center;
  flex-wrap: wrap;
}

.topbar-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.84rem;
  color: var(--gray);
  white-space: nowrap;
}

.status-chip__label {
  color: var(--gold);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.68rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--white);
  font-weight: 700;
  transition: transform var(--transition), border-color var(--transition), background var(--transition);
}

.button:hover,
.text-button:hover {
  transform: translateY(-1px);
}

.button--gold {
  background: linear-gradient(180deg, #e2cb54, #c4aa28);
  border-color: #ad9224;
  color: #191919;
}

.button--ghost {
  background: rgba(255, 255, 255, 0.03);
}

.text-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--gold);
  font-weight: 700;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(340px, 370px) minmax(0, 1fr) minmax(330px, 390px);
  min-height: 0;
}

.sidebar,
.detail-drawer {
  min-height: 0;
  overflow: auto;
  background: linear-gradient(180deg, rgba(31, 31, 31, 0.97), rgba(19, 19, 19, 0.98));
  border-right: 1px solid var(--border);
}

.detail-drawer {
  border-right: 0;
  border-left: 1px solid var(--border);
}

.panel-section {
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-section--flush {
  padding-bottom: 0;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}

.section-heading h2 {
  font-size: 1.1rem;
}

.metrics-grid,
.field-grid,
.detail-grid {
  display: grid;
  gap: 10px;
}

.metrics-grid,
.detail-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-grid--two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metric-card,
.storm-card,
.detail-stat,
.detail-callout,
.list-shell,
.map-legend,
.map-status__card,
.modal-card,
.empty-state {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric-card,
.detail-stat {
  padding: 14px;
}

.metric-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1.5rem;
  color: var(--gold);
}

.metric-card__label,
.detail-stat span,
.helper-text,
.storm-card__summary {
  color: var(--gray);
}

.storm-card {
  padding: 14px;
}

.storm-card__row,
.list-shell__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.storm-card__row + .storm-card__row,
.stack-list > * + *,
.toolbar + .toolbar,
.field-grid + .toolbar,
.toolbar + .field-grid,
.field-grid + .field-grid,
.detail-grid + .field-grid,
.preview-shell + .preview-shell {
  margin-top: 10px;
}

.storm-card__summary {
  margin: 12px 0 0;
  line-height: 1.5;
  font-size: 0.93rem;
}

.checkbox-list {
  display: grid;
  gap: 8px;
}

.checkbox-row,
.checkbox-stack {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.94rem;
}

.checkbox-stack {
  justify-content: space-between;
}

.checkbox-row input,
.checkbox-stack input {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--gray);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.helper-text {
  margin: 0;
  line-height: 1.45;
  font-size: 0.9rem;
}

.list-shell {
  padding: 12px;
}

.list-shell__header {
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--gray);
}

.stack-list {
  display: grid;
  gap: 8px;
}

.stack-card {
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
}

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

.stack-card__title strong {
  font-size: 0.98rem;
}

.stack-card__meta {
  margin-top: 8px;
  color: var(--gray);
  font-size: 0.86rem;
  line-height: 1.45;
}

.stack-card__actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.chip,
.score-pill,
.status-pill,
.type-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.chip {
  background: rgba(255, 255, 255, 0.05);
  color: var(--gray);
}

.score-pill {
  background: var(--gold-soft);
  color: #f8ea9d;
}

.status-pill.status-unworked {
  color: #e5e7eb;
  background: rgba(148, 163, 184, 0.2);
}

.status-pill.status-knocked {
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.14);
}

.status-pill.status-no_answer,
.status-pill.status-follow_up {
  color: #fcd34d;
  background: rgba(245, 158, 11, 0.18);
}

.status-pill.status-interested,
.status-pill.status-closed_won {
  color: #6ee7b7;
  background: rgba(16, 185, 129, 0.18);
}

.status-pill.status-inspection,
.status-pill.status-appointment {
  color: #c4b5fd;
  background: rgba(139, 92, 246, 0.18);
}

.status-pill.status-closed_lost {
  color: #fda4af;
  background: rgba(244, 63, 94, 0.18);
}

.type-pill.type-residential {
  color: #bad8ff;
  background: rgba(90, 162, 255, 0.16);
}

.type-pill.type-commercial {
  color: #ffd1ae;
  background: rgba(255, 155, 85, 0.16);
}

.type-pill.type-mixed {
  color: #dddddd;
  background: rgba(148, 163, 184, 0.16);
}

.map-stage {
  min-width: 0;
  min-height: 0;
  position: relative;
  background:
    radial-gradient(circle at top, rgba(211, 186, 54, 0.12), transparent 30%),
    #0f0f0f;
}

#map {
  width: 100%;
  height: 100%;
  min-height: calc(100vh - var(--topbar-height));
  min-height: calc(100dvh - var(--topbar-height));
}

.map-status {
  position: absolute;
  inset: 0;
  z-index: 950;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(12, 12, 12, 0.76);
  transition: opacity var(--transition), visibility var(--transition);
}

.map-status[data-state="ready"] {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.map-status__card {
  width: min(420px, 100%);
  padding: 20px;
}

.map-status__card h2 {
  font-size: 1.35rem;
}

.map-status__card p:last-of-type {
  color: var(--gray);
  line-height: 1.5;
}

.map-legend {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 700;
  width: min(320px, calc(100% - 36px));
  padding: 14px;
  backdrop-filter: blur(16px);
}

.map-legend__header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.88rem;
  color: var(--gray);
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.87rem;
  color: var(--gray);
}

.legend-row + .legend-row {
  margin-top: 8px;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  flex: none;
}

.swatch--residential {
  background: var(--residential);
}

.swatch--commercial {
  background: var(--commercial);
}

.swatch--parcel {
  background: var(--parcel);
}

.swatch--corridor {
  background: var(--gold);
}

.swatch--alerts {
  background: var(--alerts);
}

.swatch--routes {
  background: var(--routes);
}

.detail-drawer,
.detail-empty,
.detail-panel {
  min-height: 100%;
}

.detail-empty,
.detail-panel {
  padding: 22px;
}

.detail-empty {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

.detail-empty p:last-child {
  color: var(--gray);
  line-height: 1.55;
}

.detail-panel__header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.detail-panel h2 {
  font-size: 1.4rem;
}

.detail-callout {
  margin-top: 14px;
  padding: 14px;
}

.detail-callout p {
  margin: 8px 0 0;
  color: var(--gray);
  line-height: 1.55;
}

.table-wrap {
  border-top: 1px solid var(--border);
  overflow: auto;
}

.lead-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.lead-table th,
.lead-table td {
  padding: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  text-align: left;
  vertical-align: top;
  font-size: 0.86rem;
}

.lead-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(24, 24, 24, 0.98);
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.72rem;
}

.lead-table tbody tr {
  transition: background var(--transition);
}

.lead-table tbody tr:hover,
.lead-table tbody tr.is-selected {
  background: rgba(211, 186, 54, 0.08);
}

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

.empty-state {
  margin: 12px;
  padding: 18px;
  color: var(--gray);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(10, 10, 10, 0.8);
  backdrop-filter: blur(12px);
}

.modal-card {
  width: min(1000px, 100%);
  max-height: min(90vh, 900px);
  max-height: min(90dvh, 900px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.modal-card__header,
.modal-card__footer {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-card__footer {
  border-top: 1px solid var(--border);
  border-bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-card__body {
  min-height: 0;
  overflow: auto;
  padding: 20px;
}

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

.validation-summary {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--gray);
  line-height: 1.45;
}

.preview-shell {
  margin-top: 18px;
}

.preview-shell__header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--gray);
}

.preview-table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.preview-table th,
.preview-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  text-align: left;
  vertical-align: top;
  font-size: 0.84rem;
}

.preview-table th {
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.72rem;
}

.leaflet-container {
  background: #0d0d0d;
}

.leaflet-control-zoom,
.leaflet-bar,
.leaflet-control-layers {
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow) !important;
}

.leaflet-bar a,
.leaflet-control-layers,
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: rgba(19, 19, 19, 0.96);
  color: var(--white);
}

.leaflet-control-layers-expanded {
  padding: 12px;
}

.leaflet-popup-content {
  min-width: 260px;
}

.leaflet-popup-content strong {
  color: var(--gold);
}

.hidden {
  display: none !important;
}

.mobile-only {
  display: none;
}

@media (max-width: 1280px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr);
    justify-items: start;
  }

  .topbar-status,
  .topbar-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(50dvh, 58dvh) auto auto;
  }

  .map-stage {
    order: 1;
  }

  .sidebar {
    order: 2;
    border-right: 0;
    border-top: 1px solid var(--border);
  }

  .detail-drawer {
    order: 3;
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  #map {
    min-height: 50dvh;
  }
}

@media (max-width: 860px) {
  .brand-lockup {
    align-items: flex-start;
  }

  .brand-lockup__logo {
    width: 56px;
    height: 56px;
  }

  .metrics-grid,
  .detail-grid,
  .field-grid--two,
  .mapping-grid {
    grid-template-columns: 1fr;
  }

  .map-legend {
    top: auto;
    bottom: 14px;
    right: 14px;
  }

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