:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-muted: #eef3f7;
  --text: #19202a;
  --muted: #667085;
  --line: #d9e1ea;
  --accent: #0f766e;
  --accent-strong: #075e57;
  --danger: #be123c;
  --shadow: 0 18px 40px rgba(23, 32, 45, 0.16);
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

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

.sidebar {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 18px;
  height: 100vh;
  padding: 24px;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.sidebar-header h1 {
  margin: 4px 0 10px;
  font-size: 28px;
  line-height: 1.08;
  letter-spacing: 0;
}

.eyebrow,
.source-note,
.details-kicker,
.details-note,
.sidebar-footer {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.eyebrow {
  color: var(--accent);
  font-weight: 800;
  text-transform: uppercase;
}

.api-panel,
.controls,
.district-details {
  padding: 14px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.api-panel.is-loaded {
  display: none;
}

.api-form label,
.range-label,
.toggle {
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

.api-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 8px;
}

.api-row input,
.search {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  color: var(--text);
  background: #fff;
  border: 1px solid #c8d3df;
  border-radius: 8px;
  outline: none;
}

.api-row input:focus,
.search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.button,
.icon-button,
.text-button,
.district-item {
  border: 0;
  cursor: pointer;
}

.button {
  min-height: 40px;
  padding: 0 14px;
  color: #fff;
  background: var(--accent);
  border-radius: 8px;
  font-weight: 800;
}

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

.text-button {
  padding: 0;
  color: var(--accent-strong);
  background: transparent;
  font-weight: 800;
}

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

.tool-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: #243447;
  background: #fff;
  border: 1px solid #c8d3df;
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
}

.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.range-label {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.range-label input {
  width: 100%;
  accent-color: var(--accent);
}

.district-details {
  display: grid;
  gap: 8px;
}

.district-details h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.18;
  letter-spacing: 0;
}

.district-details p {
  margin: 0;
  line-height: 1.45;
}

.district-list-wrap {
  min-height: 0;
}

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

.district-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 10px 12px;
  color: var(--text);
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.district-item:hover,
.district-item.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.district-swatch {
  width: 12px;
  height: 32px;
  border-radius: 999px;
}

.district-title {
  display: block;
  overflow: hidden;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.district-subtitle {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.district-count {
  color: #475467;
  font-size: 12px;
  font-weight: 800;
}

.sidebar-footer a {
  color: var(--accent-strong);
  font-weight: 800;
}

.content-area {
  min-width: 0;
  background: var(--bg);
}

.top-menu {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 8px 18px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.top-menu-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 14px;
  color: #243447;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 800;
}

.top-menu-link:hover,
.top-menu-link:focus {
  color: var(--accent-strong);
  background: var(--surface-muted);
  border-color: var(--line);
  outline: none;
}

.map-area {
  position: relative;
  min-height: calc(100vh - 56px);
}

.map {
  position: absolute;
  inset: 0;
  background: #dbe6ef;
}

.map-status {
  position: absolute;
  left: 24px;
  bottom: 24px;
  max-width: min(520px, calc(100% - 48px));
  padding: 12px 14px;
  color: #17202d;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(23, 32, 45, 0.14);
}

.map-status.is-hidden {
  display: none;
}

.inventory-panel {
  padding: 28px;
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.inventory-header {
  max-width: 960px;
}

.inventory-header h2 {
  margin: 4px 0 8px;
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: 0;
}

.inventory-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 20px 0;
}

.inventory-card {
  display: grid;
  gap: 5px;
  min-height: 92px;
  padding: 12px;
  color: var(--text);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.inventory-card:hover,
.inventory-card:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
  outline: none;
}

.inventory-card-label,
.inventory-card-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.inventory-card strong {
  font-size: 24px;
  line-height: 1;
}

.inventory-toolbar {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(180px, 260px) minmax(240px, 1fr);
  gap: 12px;
  margin: 0 0 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.inventory-toolbar label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

.inventory-toolbar select,
.inventory-toolbar input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  color: var(--text);
  background: #fff;
  border: 1px solid #c8d3df;
  border-radius: 8px;
  outline: none;
}

.inventory-toolbar select:focus,
.inventory-toolbar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.inventory-table-meta {
  min-height: 24px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.inventory-table-wrap {
  overflow: auto;
  max-height: 68vh;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.inventory-table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
}

.inventory-table th,
.inventory-table td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.35;
}

.inventory-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #344054;
  background: var(--surface-muted);
  font-weight: 900;
}

.inventory-table tr {
  cursor: pointer;
}

.inventory-table tr:hover,
.inventory-table tr:focus {
  background: #f7fbfb;
  outline: none;
}

.inventory-table tr.has-coords .inventory-address {
  color: var(--accent-strong);
  font-weight: 800;
}

.inventory-address {
  max-width: 320px;
}

.inventory-number {
  text-align: right;
  font-weight: 900;
  white-space: nowrap;
}

@media (max-width: 880px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .content-area {
    grid-row: 1;
  }

  .map-area {
    min-height: 360px;
  }

  .sidebar {
    grid-row: 2;
    height: auto;
    min-height: 48vh;
    padding: 18px;
    border-top: 1px solid var(--line);
    border-right: 0;
    box-shadow: 0 -16px 32px rgba(23, 32, 45, 0.12);
  }

  .sidebar-header h1 {
    font-size: 24px;
  }

  .api-row {
    grid-template-columns: 1fr;
  }

  .inventory-panel {
    padding: 20px 16px;
  }

  .inventory-toolbar {
    grid-template-columns: 1fr;
  }

  .top-menu {
    overflow-x: auto;
    padding: 8px 12px;
  }
}
