:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #5b6475;
  --line: #d8dee8;
  --panel: #ffffff;
  --soft: #f4f7fb;
  --accent: #0f766e;
  --good: #047857;
  --warn: #b45309;
  --bad: #b91c1c;
}

/* Local Leaflet layout baseline. This keeps tiles positioned even if CDN CSS is blocked. */
.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  top: 0;
  left: 0;
}

.leaflet-container {
  position: relative;
  overflow: hidden;
  background: #dce7ef;
  outline-offset: 1px;
}

.leaflet-map-pane,
.leaflet-tile-pane,
.leaflet-overlay-pane,
.leaflet-shadow-pane,
.leaflet-marker-pane,
.leaflet-tooltip-pane,
.leaflet-popup-pane {
  position: absolute;
  top: 0;
  left: 0;
}

.leaflet-map-pane,
.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-container img,
.leaflet-container canvas,
.leaflet-container .leaflet-overlay-pane svg {
  max-width: none;
  max-height: none;
}

.leaflet-control-container .leaflet-top,
.leaflet-control-container .leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  float: left;
  clear: both;
  pointer-events: auto;
}

.leaflet-right .leaflet-control {
  float: right;
  margin-right: 10px;
}

.leaflet-bottom .leaflet-control {
  margin-bottom: 10px;
}

.leaflet-left .leaflet-control {
  margin-left: 10px;
}

.leaflet-top .leaflet-control {
  margin-top: 10px;
}

.leaflet-control-zoom a {
  display: block;
  width: 30px;
  height: 30px;
  color: #111827;
  background: #fff;
  border-bottom: 1px solid #cfd6df;
  text-align: center;
  text-decoration: none;
  font: 700 20px/30px system-ui, sans-serif;
}

.leaflet-control-zoom a:last-child {
  border-bottom: 0;
}

.leaflet-control-attribution {
  padding: 2px 6px;
  color: #243044;
  background: rgb(255 255 255 / 80%);
  font-size: 11px;
}

.leaflet-popup {
  position: absolute;
  text-align: left;
}

.leaflet-popup-content-wrapper {
  padding: 1px;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 3px 14px rgb(0 0 0 / 25%);
}

.leaflet-popup-content {
  margin: 12px 16px;
  font-size: 0.84rem;
  line-height: 1.38;
}

.leaflet-popup-close-button {
  position: absolute;
  top: 5px;
  right: 7px;
  z-index: 2;
  color: #475569;
  text-decoration: none;
  font-size: 22px;
  line-height: 1;
}

.postal-card-popup .leaflet-popup-content {
  width: min(340px, calc(100vw - 56px)) !important;
  margin: 0;
}

.postal-card {
  padding: 15px;
}

.postal-card header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-right: 18px;
}

.postal-card header strong {
  font-size: 1.02rem;
}

.postal-card header span,
.postal-card p span,
.control-impact,
.planning-status {
  color: var(--muted);
  font-size: 0.72rem;
}

.postal-card dl {
  display: grid;
  gap: 0;
  margin: 12px 0;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
}

.postal-card dl div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 7px 9px;
  border-bottom: 1px solid #edf1f6;
}

.postal-card dl div:last-child {
  border-bottom: 0;
}

.postal-card dt {
  color: var(--muted);
}

.postal-card dd {
  margin: 0;
  text-align: right;
  font-weight: 700;
}

.postal-card p {
  display: grid;
  gap: 3px;
  margin: 0;
}

.postal-card-select {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.75rem;
}

.leaflet-interactive {
  cursor: pointer;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(440px, 34vw);
  min-height: 100vh;
}

.map-stage {
  position: relative;
  overflow: hidden;
  min-height: 100vh;
}

#map {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #dce7ef;
}

.map-title {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 600;
  max-width: min(700px, calc(100% - 36px));
  padding: 16px 18px;
  background: rgb(255 255 255 / 93%);
  border: 1px solid rgb(216 222 232 / 88%);
  box-shadow: 0 12px 32px rgb(15 23 42 / 14%);
}

.map-title h1 {
  margin: 0;
  font-size: 1.28rem;
  line-height: 1.15;
  letter-spacing: 0;
}

.map-title .prototype-label {
  margin: 8px 0 0;
  color: #065f46;
  font-size: 0.78rem;
  font-weight: 750;
  line-height: 1.25;
}

.map-title .map-description {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.42;
}

.panel {
  z-index: 700;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: 100vh;
  overflow: auto;
  padding: 18px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 28px rgb(15 23 42 / 10%);
}

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

.section:last-child {
  border-bottom: 0;
}

.section h2 {
  margin: 0 0 12px;
  font-size: 0.98rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.control-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.control-row strong {
  color: var(--ink);
  font-weight: 750;
  text-align: right;
}

.mode-note {
  margin: -4px 0 10px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.verdict {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  margin-bottom: 8px;
  padding: 4px 9px;
  color: #172033;
  background: #edf2f7;
  border: 1px solid #d8dee8;
  border-radius: 8px;
  font-size: 0.82rem;
}

.verdict.good {
  color: #065f46;
  background: #ecfdf5;
  border-color: #bbf7d0;
}

.verdict.warn {
  color: #8a3b05;
  background: #fff7ed;
  border-color: #fed7aa;
}

.verdict.bad {
  color: #991b1b;
  background: #fef2f2;
  border-color: #fecaca;
}

.narrative {
  margin: 0;
  padding: 12px 13px;
  color: #23314a;
  background: #eef7f5;
  border: 1px solid #c7e2dc;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.42;
}

.planning-status {
  min-height: 18px;
  margin: 6px 0;
}

.primary-action,
.secondary-action {
  min-height: 38px;
  padding: 8px 11px;
  border-radius: 8px;
  font-weight: 750;
}

.primary-action {
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
}

.secondary-action {
  color: var(--ink);
  background: #fff;
  border: 1px solid #cfd8e5;
}

.primary-action:disabled,
.secondary-action:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.full-width-action {
  width: 100%;
}

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

.kpi {
  min-height: 78px;
  padding: 12px;
  background: var(--soft);
  border: 1px solid #e1e7f0;
  border-radius: 8px;
}

.kpi span,
.comparison-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.25;
}

.kpi strong {
  display: block;
  margin-top: 8px;
  font-size: 1.22rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid #d8dee8;
  border-radius: 8px;
}

.workload-summary {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.workload-summary div:nth-child(2) {
  border-right: 1px solid #edf1f6;
}

.workload-summary div:last-child {
  border-right: 0;
}

.workload-summary div:nth-last-child(-n + 3) {
  border-bottom: 0;
}

.comparison-grid div {
  min-height: 64px;
  padding: 10px 12px;
  background: #fff;
  border-right: 1px solid #edf1f6;
  border-bottom: 1px solid #edf1f6;
}

.comparison-grid div:nth-child(2n) {
  border-right: 0;
}

.comparison-grid div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.comparison-grid strong {
  display: block;
  margin-top: 7px;
  font-size: 1rem;
}

.control {
  display: grid;
  gap: 7px;
  margin: 0 0 12px;
}

.control label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.control output {
  color: var(--ink);
  font-weight: 750;
  text-align: right;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.range-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 30px;
  gap: 8px;
  align-items: center;
}

.stepper {
  width: 30px;
  height: 30px;
  padding: 0;
  color: #172033;
  background: #fff;
  border: 1px solid #cfd8e5;
  border-radius: 8px;
  font-size: 1.12rem;
  font-weight: 800;
  line-height: 1;
}

.stepper:hover {
  color: #0f766e;
  border-color: #0f766e;
}

.stepper:focus-visible,
.toggle-row input:focus-visible,
.primary-action:focus-visible,
.secondary-action:focus-visible,
select:focus-visible {
  outline: 3px solid rgb(15 118 110 / 24%);
  outline-offset: 2px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 32px;
  margin-top: 8px;
  color: var(--ink);
  font-size: 0.84rem;
}

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

.filter-row {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 12px;
  align-items: end;
}

.select-control {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.select-control select,
.postal-card-select select {
  width: 100%;
  min-height: 36px;
  padding: 6px 30px 6px 9px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cfd8e5;
  border-radius: 7px;
}

.site-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.site-summary div {
  padding: 9px 10px;
  background: var(--soft);
  border: 1px solid #e1e7f0;
  border-radius: 7px;
}

.site-summary span,
.site-summary strong {
  display: block;
}

.site-summary span {
  color: var(--muted);
  font-size: 0.7rem;
}

.site-summary strong {
  margin-top: 4px;
}

.control-impact {
  margin-top: -3px;
}

.target-mix-controls {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.target-share-details {
  border-top: 1px solid var(--line);
}

.target-share-details summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.82rem;
}

.target-share-details summary strong {
  color: var(--muted);
  font-size: 0.76rem;
  text-align: right;
}

.target-share-table-wrap {
  max-height: 430px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.target-share-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff;
}

.target-share-table th:first-child,
.target-share-table td:first-child {
  width: 42%;
  white-space: normal;
}

.target-share-table th:nth-child(2),
.target-share-table td:nth-child(2) {
  width: 12%;
  text-align: right;
}

.target-share-table th:last-child,
.target-share-table td:last-child {
  width: 46%;
  text-align: right;
}

.target-share-table tr.manually-set {
  background: #ecfdf5;
}

.target-facility-button {
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  text-align: left;
}

.target-facility-button:hover {
  color: var(--accent);
}

.target-share-row-control {
  display: grid;
  grid-template-columns: minmax(70px, 1fr) 44px;
  gap: 8px;
  align-items: center;
}

.target-share-row-control input {
  width: 100%;
  accent-color: var(--accent);
}

.target-share-details > button {
  margin-top: 9px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.route-notes-table {
  max-height: 340px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

th,
td {
  padding: 9px 10px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid #edf1f6;
}

th:first-child,
td:first-child,
th:last-child,
td:last-child {
  text-align: left;
}

.route-notes-table th:nth-child(2),
.route-notes-table td:nth-child(2) {
  text-align: left;
}

.facility-select-button {
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  text-align: left;
  white-space: nowrap;
}

.facility-select-button:hover {
  color: var(--accent);
  text-decoration: underline;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.empty-cell {
  color: var(--muted);
  text-align: left;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 7px;
  border-radius: 50%;
  vertical-align: -1px;
}

.note {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.42;
}

.note.compact {
  margin-bottom: 10px;
  font-size: 0.76rem;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .map-stage {
    min-height: 58vh;
  }

  .panel {
    max-height: none;
    border-top: 1px solid var(--line);
    border-left: 0;
    box-shadow: 0 -10px 24px rgb(15 23 42 / 10%);
  }

  .map-title {
    top: 12px;
    left: 12px;
    padding: 13px 14px;
  }

  .map-title h1 {
    font-size: 1.08rem;
  }
}

@media (max-width: 680px) {
  .kpi-grid,
  .comparison-grid {
    grid-template-columns: 1fr;
  }

  .comparison-grid div,
  .comparison-grid div:nth-child(2n),
  .comparison-grid div:nth-last-child(-n + 2) {
    border-right: 0;
    border-bottom: 1px solid #edf1f6;
  }

  .comparison-grid div:last-child {
    border-bottom: 0;
  }

  .panel {
    padding: 14px;
  }

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

  th,
  td {
    padding: 8px;
  }
}
