:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --link: #1c5cab;
  --marker-ring: #fcfcfb;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --line: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --link: #86b6ef;
    --marker-ring: #1a1a19;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #262624;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --line: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --link: #86b6ef;
  --marker-ring: #1a1a19;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--link); }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 15px; margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; }
button { font: inherit; color: inherit; }

/* ---------- panel ---------- */
#panel {
  width: 360px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  z-index: 2;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: 16px 16px 8px;
}
.panel-head p { margin: 2px 0 0; }
#panel-body { overflow-y: auto; padding: 0 16px 16px; flex: 1; }
#panel-toggle { display: none; }

#filters { display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
fieldset { border: 0; margin: 0; padding: 0; }
legend, .row { font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }
legend output { color: var(--ink); font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

input[type="search"], select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
}
select { width: auto; }

.range2 { position: relative; height: 22px; }
.range2 input {
  position: absolute; inset: 0; width: 100%; margin: 0;
  pointer-events: none; background: none; -webkit-appearance: none; appearance: none;
}
.range2 input::-webkit-slider-thumb { pointer-events: auto; }
.range2 input::-moz-range-thumb { pointer-events: auto; }
.range2::before {
  content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 4px;
  transform: translateY(-50%); border-radius: 2px; background: var(--line);
}
.range2 input::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface); cursor: pointer;
}
.range2 input::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface); cursor: pointer;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-size: 12px; user-select: none;
}
.chip input { display: none; }
.chip[hidden] { display: none; }
.chip:has(input:checked) { background: var(--surface-2); border-color: var(--ink-2); }
.chip:not(:has(input:checked)) { color: var(--muted); text-decoration: line-through; }
.chip .n { color: var(--muted); font-variant-numeric: tabular-nums; }

.swatch {
  width: 10px; height: 10px; border-radius: 50%; flex: none;
  box-shadow: 0 0 0 1px var(--border);
}
.swatch.line { width: 16px; height: 4px; border-radius: 2px; box-shadow: none; background: var(--ink-2); }
.swatch.hollow { background: transparent; box-shadow: inset 0 0 0 2px var(--ink-2); opacity: 0.55; }
#legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; }
#legend li { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }

/* ---------- network list ---------- */
.list-head { display: flex; justify-content: space-between; align-items: baseline; margin: 14px 0 6px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--link); cursor: pointer; text-decoration: underline; font-size: 13px; }
#network-list { list-style: none; margin: 0 0 12px; padding: 0; }
#network-list li {
  padding: 7px 8px; margin: 0 -8px; border-radius: 8px; cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 0 8px;
}
#network-list li:hover, #network-list li:focus-visible { background: var(--surface-2); outline: none; }
#network-list .id { font-weight: 600; font-variant-numeric: tabular-nums; }
#network-list .name { grid-column: 1 / -1; color: var(--ink-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#network-list .meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; }
.empty { color: var(--muted); padding: 12px 0; }

/* ---------- detail ---------- */
#detail-view { padding: 12px 0; }
#detail-view h2 { font-size: 17px; margin: 8px 0 2px; }
#detail-view dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 12px 0; font-size: 13px; }
#detail-view dt { color: var(--ink-2); }
#detail-view dd { margin: 0; overflow-wrap: anywhere; }
.stations { width: 100%; border-collapse: collapse; font-size: 12px; }
.stations th { text-align: left; color: var(--ink-2); font-weight: 500; border-bottom: 1px solid var(--line); padding: 4px 6px 4px 0; }
.stations td { padding: 4px 6px 4px 0; border-bottom: 1px solid var(--line); vertical-align: top; font-variant-numeric: tabular-nums; }
.stations tr { cursor: pointer; }
.stations tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; }

footer { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }

/* ---------- map ---------- */
#map { flex: 1; height: 100%; background: var(--surface-2); }
.leaflet-container { font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--ink); }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; }
.leaflet-popup-content h3 { margin: 0 0 2px; font-size: 14px; }
.leaflet-popup-content p { margin: 6px 0; }
.leaflet-tooltip { background: var(--surface); color: var(--ink); border-color: var(--border); }
.leaflet-control-layers, .leaflet-bar a { background: var(--surface); color: var(--ink); }

.view-switch { display: flex; background: var(--surface); overflow: hidden; }
.view-switch button {
  border: 0; border-right: 1px solid var(--border); background: var(--surface); color: var(--ink);
  padding: 5px 10px; font-size: 12px; cursor: pointer;
}
.view-switch button:last-child { border-right: 0; }
.view-switch button:hover { background: var(--surface-2); }
.view-switch button.active { background: var(--accent); color: #fff; }

/* ---------- table view ---------- */
#table-view {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--surface); display: flex; flex-direction: column;
}
#table-view[hidden] { display: none; }
.table-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.table-scroll { overflow: auto; flex: 1; }
#network-table { border-collapse: collapse; width: 100%; font-size: 13px; }
#network-table th {
  position: sticky; top: 0; background: var(--surface); text-align: left;
  font-weight: 500; color: var(--ink-2); padding: 8px 10px; border-bottom: 1px solid var(--line);
  cursor: pointer; white-space: nowrap;
}
#network-table th[aria-sort="ascending"]::after { content: " ▲"; }
#network-table th[aria-sort="descending"]::after { content: " ▼"; }
#network-table td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; font-variant-numeric: tabular-nums; }
#network-table tbody tr:hover { background: var(--surface-2); }

.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  width: 32px; height: 32px; cursor: pointer; flex: none;
}

/* ---------- mobile: panel becomes a bottom sheet ---------- */
@media (max-width: 760px) {
  body { flex-direction: column-reverse; }
  #panel { width: 100%; max-height: 55vh; border-right: 0; border-top: 1px solid var(--border); }
  #panel.collapsed { max-height: none; }
  #panel.collapsed #panel-body { display: none; }
  #panel-toggle { display: block; }
  #map { min-height: 45vh; }
}

/* ---------- page dédiée d'un réseau (network.html) ---------- */
body.page { display: block; height: auto; min-height: 100%; overflow-y: auto; }
.page-main { max-width: 1180px; margin: 0 auto; padding: 16px 16px 48px; }
.page-nav { margin-bottom: 12px; font-size: 13px; }
.page-header h1 { font-size: 24px; }
.page-header p { margin: 4px 0 0; font-size: 15px; }
.page-main section { margin-top: 28px; }
.page-main h2 { font-size: 17px; margin-bottom: 4px; }
.page-top { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(300px, 1.3fr); gap: 20px; align-items: start; }
.meta-grid { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.meta-grid dt { color: var(--ink-2); }
.meta-grid dd { margin: 0; overflow-wrap: anywhere; }
#mini-map { height: 320px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.section-tools { display: flex; gap: 10px; align-items: center; }
.section-tools input[type="search"] { width: 260px; }
.text-btn {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; font-size: 13px;
}
.text-btn:hover { border-color: var(--ink-2); }
.table-scroll-x { overflow-x: auto; margin-top: 8px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); }
.data-table th, .data-table td { padding: 6px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.data-table thead th { color: var(--ink-2); font-weight: 500; white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
.data-table tbody th { font-weight: 600; white-space: nowrap; }
.data-table tr.group-start > * { border-top: 1px solid var(--ink-2); }
.data-table tbody tr:first-child > * { border-top: 0; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; white-space: nowrap; }
#page-footer { margin-top: 32px; padding-top: 12px; border-top: 1px solid var(--line); }
@media (max-width: 760px) {
  .page-top { grid-template-columns: 1fr; }
  .section-tools input[type="search"] { width: 100%; }
  .section-tools { width: 100%; }
}
.primary-btn {
  display: inline-block; margin: 2px 0 12px; padding: 8px 14px; border-radius: 8px;
  background: var(--accent); color: #fff; text-decoration: none; font-weight: 500;
}
.primary-btn:hover { filter: brightness(1.1); }
