:root {
  --ink: #15202b;
  --muted: #5c6672;
  --line: #d5dbe3;
  --panel: #f3f6f8;
  --accent: #1f4e5f;
  --air: #0b6e4f;
  --land: #1d4e89;
  --link: #c45c26;
  --metro: #6b5b95;
  --rail-w: 340px;
  --font: "IBM Plex Sans", "Helvetica Neue", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: #e4eaef;
}

a { color: var(--accent); }

.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-shrink: 0;
  padding: 0.55rem 1rem;
  background: #fff;
  border-bottom: 1px solid var(--line);
  z-index: 6;
}

.top__brand {
  display: flex;
  flex-direction: column;
  gap: 0.02rem;
}

.top__brand a {
  font-size: 0.72rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--muted);
}

.top__brand a.top__title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.tabs { display: flex; gap: 0.35rem; }

.tabs button,
.modes button {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 0.38rem 0.7rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.tabs button.is-on,
.modes button.is-on {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.app {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  flex: 1;
  min-height: 0;
}

.rail {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  z-index: 5;
}

.rail-close {
  display: none;
  position: absolute;
  top: 8px;
  right: 8px;
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 0.12rem 0.45rem;
  font: inherit;
  cursor: pointer;
}

.rail__section {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
}

.rail__section--detail {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.rail__label {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.rail__hint {
  margin: 0.45rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.modes { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.stat {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat__value {
  margin: 0.15rem 0 0.55rem;
  font-family: var(--mono);
  font-size: 1.25rem;
  color: var(--accent);
}

.sys {
  padding: 0.65rem 0;
  border-top: 1px solid var(--line);
}

.sys h3 {
  margin: 0;
  font-size: 0.92rem;
}

.sys p {
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.tag {
  display: inline-block;
  margin-right: 0.3rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tag--airside { color: var(--air); }
.tag--landside { color: var(--land); }
.tag--connector { color: var(--link); }
.tag--building { color: var(--muted); }

.rail__foot {
  padding: 0.7rem 1rem 0.9rem;
}

.rail__foot details {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.rail__foot summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
}

.rail__foot p { margin: 0.45rem 0 0; }

.map-pane { position: relative; min-width: 0; min-height: 0; }

.map {
  width: 100%;
  height: 100%;
  background: #dce5ec;
}

.map-legend {
  position: absolute;
  right: 12px;
  bottom: 18px;
  z-index: 500;
  margin: 0;
  padding: 0.45rem 0.55rem;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.72rem;
  color: var(--muted);
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 99px;
  margin-right: 0.25rem;
}

.rail-toggle {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1000;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  cursor: pointer;
}

.app[hidden],
.insights[hidden] {
  display: none !important;
}

.insights {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #eef2f5;
}

.insights__inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.25rem 1.1rem 3rem;
}

.insights__head h1,
.outliers h2,
.city-compare h2,
.inventory h2,
.sources h2 {
  margin: 0;
  letter-spacing: -0.03em;
}

.insights__head p {
  margin: 0.4rem 0 0.85rem;
  color: var(--muted);
  line-height: 1.45;
  max-width: 46rem;
}

.insights__head .modes { margin-bottom: 0.9rem; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.chart-note {
  margin: 0 0 0.85rem;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
  max-width: 46rem;
}

.pair-chart {
  display: grid;
  gap: 0.7rem;
  margin-bottom: 0.4rem;
}

.pair-block {
  display: grid;
  grid-template-columns: 9.6rem 14.5rem 1fr;
  gap: 0.65rem 0.85rem;
  align-items: center;
  padding: 0.45rem 0.55rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.pair-block.is-on,
.pair-block:hover { background: #f6f9fb; }

.pair-block__city {
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.pair-block__who strong {
  display: block;
  font-size: 0.86rem;
}

.pair-block__who span {
  display: block;
  margin-top: 0.12rem;
  font-size: 0.72rem;
  color: var(--metro);
  line-height: 1.35;
}

.pair-bars { display: grid; gap: 0.28rem; }

.pair-bar {
  display: grid;
  grid-template-columns: 1fr 6.4rem;
  gap: 0.45rem;
  align-items: center;
}

.pair-bar i {
  display: block;
  position: relative;
  height: 9px;
  border-radius: 99px;
  background: #e2e8ee;
  overflow: hidden;
}

.pair-bar i b {
  display: block;
  height: 100%;
  border-radius: 99px;
}

.pair-bar.is-air i b { background: var(--air); }
.pair-bar.is-metro i b { background: var(--metro); }

.pair-bar.is-off i b {
  background: repeating-linear-gradient(
    135deg,
    var(--metro) 0 7px,
    #8f82b5 7px 11px
  );
}

.bar-break {
  position: absolute;
  top: -4px;
  right: 14%;
  width: 9px;
  height: 17px;
  background: repeating-linear-gradient(
    -65deg,
    transparent 0 3px,
    #fff 3px 6px
  );
  pointer-events: none;
}

.pair-bar em {
  font-family: var(--mono);
  font-style: normal;
  font-size: 0.75rem;
  text-align: right;
}

.chart {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 1.4rem;
}

.chart-row {
  display: grid;
  grid-template-columns: 11rem 1fr 5.4rem;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.78rem;
}

.chart-row.is-metro .chart-row__fill { background: var(--metro); }
.chart-row.is-air .chart-row__fill { background: var(--air); }
.chart-row.is-land .chart-row__fill { background: var(--land); }
.chart-row.is-link .chart-row__fill { background: var(--link); }

.chart-row__track {
  height: 10px;
  border-radius: 99px;
  background: #e2e8ee;
  overflow: hidden;
}

.chart-row__fill {
  height: 100%;
  border-radius: 99px;
}

.chart-row__val {
  font-family: var(--mono);
  text-align: right;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.data-table th,
.data-table td {
  padding: 0.4rem 0.55rem;
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.data-table th {
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

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

.data-table--pair th:nth-child(2),
.data-table--pair td:nth-child(2) {
  text-align: right;
}

.data-table--pair th:nth-child(3),
.data-table--pair td:nth-child(3) {
  text-align: left;
}

.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover,
.data-table .is-on { background: #f6f9fb; }

.outliers { margin-top: 2rem; }

.city-compare,
.inventory,
.sources { margin-top: 2.2rem; }

.city-compare > p,
.inventory > p,
.sources > p {
  margin: 0.4rem 0 0.85rem;
  color: var(--muted);
  line-height: 1.45;
  max-width: 46rem;
}

.sources h3 {
  margin: 1.1rem 0 0.4rem;
  font-size: 0.92rem;
}

.source-files {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
  max-width: 46rem;
}

.source-files li { margin: 0.2rem 0; }

.data-table--sources td.source-cell {
  white-space: normal;
  text-align: left;
  max-width: 40rem;
  font-size: 0.75rem;
  line-height: 1.35;
}

.data-table--sources th:nth-child(3),
.data-table--sources td:nth-child(3) { text-align: left; }

.pair {
  line-height: 1.3;
}

.pair b {
  display: block;
  font-weight: 600;
  color: var(--ink);
}

.pair span {
  display: block;
  margin-top: 0.08rem;
  font-size: 0.72rem;
  color: var(--metro);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem;
  margin-top: 0.8rem;
}

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem 1rem 1rem;
}

.card__kicker {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.card h3 {
  margin: 0.25rem 0 0;
  font-size: 1.02rem;
  letter-spacing: -0.02em;
}

.card__stat {
  margin: 0.35rem 0 0.45rem;
  font-family: var(--mono);
  font-size: 1.35rem;
  color: var(--accent);
}

.card p:last-child {
  margin: 0;
  font-size: 0.86rem;
  color: var(--muted);
  line-height: 1.45;
}

.caveat {
  margin: 1.4rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
  max-width: 46rem;
}

@media (max-width: 820px) {
  .app {
    position: relative;
    grid-template-columns: 1fr;
  }

  .rail {
    position: absolute;
    inset: 0 auto 0 0;
    width: min(350px, 92vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.18);
    padding-top: 2.2rem;
  }

  .rail.is-open { transform: translateX(0); }

  .rail-toggle,
  .rail-close { display: block; }

  .chart-row { grid-template-columns: 7.5rem 1fr 4.6rem; }
  .pair-block { grid-template-columns: 7.8rem 1fr; }
  .pair-block .pair-bars { grid-column: 1 / -1; }
}

@media (max-width: 520px) {
  .pair-block { grid-template-columns: 1fr; }
}
