.lean-dem,
.lean-even,
.lean-rep {
  width: 13px;
  height: 9px;
  border-radius: 2px;
  background: #3976c5;
}

.lean-even { background: #e4e1dc; }
.lean-rep { background: #c94b4b; }

.map-layer-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.layer-choice,
.layer-select,
.visibility-toggle {
  min-height: 45px;
  padding: 8px 11px;
  border-radius: 11px;
  background: #fff;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.layer-select {
  gap: 9px;
}

.layer-select select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 25px 5px 7px;
  background: #fbfaf6;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}

.population-gradient {
  width: 84px;
  height: 9px;
  border-radius: 2px;
  background: linear-gradient(90deg,#c94b4b,#d5b94c,#438c5a);
}

.demographic-list { margin: 10px 0 16px; }
.demographic-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 3px 10px;
  margin: 9px 0;
  color: var(--muted);
  font-size: 10px;
}
.demographic-row > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.demographic-row > b { color: var(--ink); }
.demographic-row > i {
  height: 5px;
  border-radius: 3px;
  background: #e7e5df;
  overflow: hidden;
}
.demographic-row > i > em { display: block; height: 100%; background: #6a9274; border-radius: inherit; }
.demographic-row > small { text-align: right; }

.layer-choice input,
.visibility-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.layer-choice i {
  position: relative;
  width: 32px;
  height: 18px;
  border-radius: 10px;
  background: #6a9274;
  transition: .2s;
}

.layer-choice i::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  transition: .2s;
}

.layer-choice input:checked + i { background: linear-gradient(90deg,#3976c5,#c94b4b); }
.layer-choice input:checked + i::after { transform: translateX(14px); }
.layer-choice input:focus-visible + i { outline: 2px solid var(--ink); outline-offset: 2px; }

.visibility-toggle span::before {
  content: '✓';
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-right: 6px;
  border: 1px solid var(--green);
  border-radius: 4px;
  background: var(--green);
  color: #fff;
  font-size: 10px;
}

.visibility-toggle span {
  height: 18px;
  display: flex;
  align-items: center;
  line-height: 18px;
}

.visibility-toggle span::before { flex: 0 0 16px; }

.visibility-toggle input:not(:checked) + span { color: var(--muted); }
.visibility-toggle input:not(:checked) + span::before { content: ''; background: #fff; border-color: var(--line); }

@media(max-width:1100px) {
  .map-layer-controls { flex-wrap: wrap; }
  .layer-choice, .layer-select, .visibility-toggle { min-height: 36px; }
}

.mobile-library-toggle,
.sidebar-backdrop { display: none; }

@media(max-width:780px) {
  :root { --mobile-header-height: 68px; }

  .shell { display: block; }
  .sidebar {
    position: fixed;
    inset: 0 0 auto 0;
    width: 100%;
    height: var(--mobile-header-height);
    z-index: 30;
    overflow: hidden;
    border: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 5px 20px #203c2b18;
    transform: none;
    transition: height .25s ease;
  }
  .sidebar.hidden { transform: none; }
  .sidebar.mobile-open { height: min(82vh,680px); }

  .brand {
    flex: 0 0 var(--mobile-header-height);
    height: var(--mobile-header-height);
    padding: 12px 16px;
  }
  .brand-mark { width: 40px; height: 40px; }
  .brand-copy { min-width: 0; }
  .brand strong { font-size: 17px; white-space: nowrap; }

  .mobile-library-toggle {
    margin-left: auto;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f4f3ed;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--green);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
  }
  .mobile-library-toggle i,
  .mobile-library-toggle i::before,
  .mobile-library-toggle i::after {
    width: 16px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
    display: block;
    transition: .2s;
  }
  .mobile-library-toggle i { position: relative; }
  .mobile-library-toggle i::before,
  .mobile-library-toggle i::after { content: ''; position: absolute; left: 0; }
  .mobile-library-toggle i::before { top: -5px; }
  .mobile-library-toggle i::after { top: 5px; }
  .mobile-open .mobile-library-toggle i { background: transparent; }
  .mobile-open .mobile-library-toggle i::before { top: 0; transform: rotate(45deg); }
  .mobile-open .mobile-library-toggle i::after { top: 0; transform: rotate(-45deg); }

  .sidebar .search { flex: 0 0 auto; margin: 14px 16px 10px; }
  .sidebar nav { flex: 0 0 auto; padding: 0 10px 12px; }
  .sidebar .collection { flex: 1 1 auto; padding-top: 12px; overflow-y: auto; }
  .sidebar footer { flex: 0 0 auto; }

  .sidebar-backdrop {
    position: fixed;
    inset: var(--mobile-header-height) 0 0;
    z-index: 25;
    border: 0;
    background: #15271f66;
    backdrop-filter: blur(1px);
  }
  .sidebar.mobile-open + .sidebar-backdrop { display: block; }

  main { position: fixed; inset: var(--mobile-header-height) 0 0; }
  .map-top {
    top: 10px !important;
    left: 10px !important;
    right: 10px;
    transform: none !important;
    display: grid;
    grid-template-columns: 42px minmax(0,1fr);
    gap: 7px;
    align-items: start;
    max-height: 128px;
  }
  .round-btn { width: 42px; height: 42px; }
  .map-top > label { min-height: 42px; padding: 6px 9px !important; font-size: 9px !important; }
  .map-top > label input { width: 54px !important; }
  .map-layer-controls {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0,1.35fr) 1fr 1fr;
    gap: 6px;
  }
  .layer-select,
  .visibility-toggle { min-width: 0; min-height: 36px; padding: 6px 8px; box-shadow: 0 5px 18px #203c2b20; }
  .layer-select > span { display: none; }
  .layer-select select { width: 100%; min-width: 0; }
  .visibility-toggle { justify-content: center; font-size: 9px; }
  .visibility-toggle span::before { margin-right: 4px; }

  .map-bottom { left: 10px; right: 10px; bottom: 10px; }
  .map-bottom #toggle-panel { display: none; }

  .detail-panel {
    position: fixed;
    z-index: 22;
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    height: auto;
    max-height: min(72vh,620px);
    padding: 28px 20px calc(22px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -14px 45px #13291f38;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .detail-panel.open::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    width: 42px;
    height: 4px;
    margin-left: -21px;
    border-radius: 4px;
    background: #c8cbc5;
  }
  .detail-panel h2 { font-size: 24px; }

  dialog { max-height: 92vh; max-width: calc(100vw - 20px); overflow-y: auto; }
  #editor-form { padding: 20px 16px; }
  .row { grid-template-columns: 1fr; }
}

@media(max-width:390px) {
  .brand-copy span { display: none; }
  .mobile-library-toggle span { display: none; }
  .map-layer-controls { grid-template-columns: 1fr 1fr; }
  .layer-select { grid-column: 1 / -1; }
}
