@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap");

:root {
  --bg: #f4f6f8;
  --panel-bg: #ffffff;
  --panel-border: #d2dbe3;
  --text: #16222f;
  --muted: #5c6e82;
  --accent: #0a7a68;
  --accent-strong: #075d50;
  --chip-bg: #eef2f6;
  --chip-border: #c9d3de;
  --match: #ffd166;
  --selected: #eb5e28;
  --connected: #2a9d8f;
  --shadow: 0 8px 24px rgba(12, 26, 44, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(circle at 15% 10%, #e2edf8 0%, var(--bg) 55%, #edf4f0 100%);
  font-family: "Manrope", "Segoe UI", sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: 390px 1fr;
  gap: 12px;
  min-height: 100vh;
  padding: 10px;
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(247, 250, 252, 0.96));
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-header h1 {
  margin: 0;
  font-size: 1.3rem;
  line-height: 1.2;
}

.panel-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.card {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: var(--panel-bg);
  padding: 12px;
}

.selected-card {
  order: -1;
  position: sticky;
  top: 0;
  z-index: 2;
}

.card h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
}

.field-label {
  display: block;
  margin-top: 8px;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

input[type="text"],
select,
button {
  width: 100%;
  border: 1px solid var(--chip-border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  color: inherit;
  background: #fff;
}

input[type="text"]:focus,
select:focus,
button:focus {
  outline: 2px solid rgba(10, 122, 104, 0.18);
  border-color: var(--accent);
}

.inline-row {
  margin-top: 6px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid var(--chip-border);
  border-radius: 999px;
  background: var(--chip-bg);
  color: #324154;
  padding: 5px 9px;
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}

.chip.active {
  border-color: var(--accent);
  color: #063b33;
  background: #d7f2ed;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

button {
  background: #edf3f8;
  cursor: pointer;
}

button:hover {
  background: #e3edf5;
}

.district-info {
  font-size: 0.9rem;
  line-height: 1.45;
  max-height: 36vh;
  overflow: auto;
  padding-right: 4px;
}

.district-info h3 {
  margin: 2px 0 6px;
}

.district-info ul {
  margin: 6px 0;
  padding-left: 18px;
}

.district-info .tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.district-info .tag {
  border-radius: 999px;
  background: #eef4f9;
  border: 1px solid #d2dce8;
  padding: 2px 8px;
  font-size: 0.75rem;
}

.district-info .connection-item {
  margin-bottom: 5px;
}

.muted {
  color: var(--muted);
}

.mono {
  font-family: "IBM Plex Mono", monospace;
}

.map-wrap {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid #c8d5df;
  box-shadow: var(--shadow);
  min-height: 92vh;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 92vh;
}

.legend {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 800;
  display: block;
  visibility: visible;
  opacity: 1;
  background: rgba(255, 255, 255, 0.93);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.78rem;
  max-width: 240px;
}

.legend .row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.legend .swatch {
  width: 14px;
  height: 10px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.2);
}

.district-label {
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  max-width: 230px;
  width: max-content;
  padding: 4px 9px;
  border-radius: 10px;
  border: 1px solid rgba(18, 30, 45, 0.55);
  background: rgba(255, 255, 255, 0.96);
  color: #08131f;
  font-size: 0.77rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.05;
  text-align: center;
  letter-spacing: 0.01em;
  box-shadow: 0 2px 10px rgba(7, 15, 27, 0.2);
  pointer-events: none;
  backdrop-filter: blur(2px);
}

.district-label.dim {
  opacity: 0.45;
}

.district-badge {
  transform: translate(-50%, -50%);
  display: inline-block;
  width: max-content;
  min-height: 20px;
  max-width: 240px;
  padding: 3px 7px;
  border-radius: 6px;
  border: 1px solid rgba(9, 18, 30, 0.2);
  background: rgba(251, 255, 245, 0.88);
  color: #122336;
  font-size: 0.72rem;
  line-height: 1.12;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  box-shadow: 0 1px 8px rgba(9, 18, 30, 0.15);
}

.district-badge.bubble-stack {
  transform: none;
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
  min-height: 0;
  overflow: visible;
  max-width: none;
}

.district-badge .bubble-stack-inner {
  display: inline-block;
  width: max-content;
  position: relative;
  transform: translate(-50%, var(--bubble-offset, 18px));
  border-radius: 6px;
  border: 1px solid rgba(9, 18, 30, 0.2);
  background: rgba(251, 255, 245, 0.88);
  color: #122336;
  font-size: 0.72rem;
  line-height: 1.12;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: top;
  box-shadow: 0 1px 8px rgba(9, 18, 30, 0.15);
  padding: 3px 7px;
  max-width: 240px;
}

.district-badge.cost-indicator {
  font-size: 0.78rem;
  font-weight: 800;
}

.district-badge.cost-indicator .bubble-stack-inner {
  min-width: 0;
  max-width: 100px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  color: #2f1948;
  background: rgba(255, 245, 229, 0.98);
  border-color: rgba(60, 41, 18, 0.34);
  padding: 2px 8px;
}

.district-badge.cost {
  overflow: visible;
}

.district-badge.cost .bubble-stack-inner {
  background: rgba(247, 239, 255, 0.97);
  max-width: 340px;
  min-width: 210px;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.28;
  padding: 6px 9px;
}

.cost-pill-title {
  font-size: 0.74rem;
  font-weight: 800;
  color: #24103d;
  margin-bottom: 2px;
}

.cost-pill-text {
  font-size: 0.72rem;
  color: #2d2340;
}

@media (min-resolution: 2dppx) {
  .district-badge,
  .district-label {
    text-rendering: geometricPrecision;
  }
}

.station-tooltip {
  background: rgba(8, 28, 43, 0.84);
  color: #fff;
  border: 0;
  border-radius: 6px;
  box-shadow: none;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
}

.station-tooltip:before {
  display: none;
}

.station-icon {
  background: none;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.station-icon:hover {
  transform: scale(1.2);
}

.station-icon svg {
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.3));
}

.station-hbf svg {
  filter: drop-shadow(0 1px 3px rgba(217, 4, 41, 0.4));
}

.station-airport svg {
  filter: drop-shadow(0 1px 3px rgba(106, 0, 244, 0.4));
}

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

  .panel {
    max-height: 52vh;
  }

  .district-info {
    max-height: 28vh;
  }

  .map-wrap,
  #map {
    min-height: 65vh;
  }
}
