:root {
  --bg: #ffffff;
  --bg2: #f3f4f6;
  --fg: #1a1d21;
  --muted: #5b6370;
  --border: #d9dce1;
  --accent: #0b5cad;
  --panel-w: 360px;
  --radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1e23;
    --bg2: #262a31;
    --fg: #eceef1;
    --muted: #a0a8b4;
    --border: #3a3f48;
    --accent: #6cb2ff;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--fg); }
#map { position: fixed; inset: 0; z-index: 0; }
button { font: inherit; color: inherit; cursor: pointer; }

.banner {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 1200;
  background: #fff3cd; color: #5c4400; border: 1px solid #e0c36a; border-radius: var(--radius);
  padding: 6px 12px; font-size: 13px; max-width: calc(100vw - 24px); text-align: center;
}

/* Panneau */
#panel {
  position: fixed; z-index: 1100; top: 10px; left: 10px; bottom: 10px; width: var(--panel-w);
  background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.18); display: flex; flex-direction: column; overflow: hidden;
}
#panel.collapsed { bottom: auto; }
#panel.collapsed .panel-body { display: none; }
.panel-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 12px;
  background: var(--bg); border: 0; border-bottom: 1px solid var(--border); text-align: left; font-weight: 700; font-size: 15px;
}
.panel-toggle .toggle-label { flex: 1; }
.panel-toggle .grip { display: none; }
.chev { width: 8px; height: 8px; border-left: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin-right: 4px; }
#panel.collapsed .chev { transform: rotate(-135deg); }
.panel-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.view[hidden] { display: none; }
.sources { border-top: 1px solid var(--border); padding: 8px 12px; font-size: 12px; color: var(--muted); max-height: 22%; overflow-y: auto; }
.sources a { color: var(--accent); }
.sources ul { margin: 4px 0 0; padding-left: 16px; }

/* Recherche */
.search { padding: 10px 12px 4px; position: relative; }
.search input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg2); color: var(--fg); font: inherit;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.results { list-style: none; margin: 6px 0 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); max-height: 240px; overflow-y: auto; background: var(--bg); }
.results li { padding: 7px 10px; cursor: pointer; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.results li:last-child { border-bottom: 0; }
.results li:hover, .results li:focus { background: var(--bg2); }
.results .empty { color: var(--muted); cursor: default; }

/* Groupes */
.group { padding: 8px 12px 4px; }
.group-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.group-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0; }
.mini-btns { display: flex; gap: 4px; }
.mini-btns button { border: 1px solid var(--border); background: var(--bg2); border-radius: 4px; padding: 2px 8px; font-size: 12px; }
.mini-btns button:hover { border-color: var(--accent); }
.line-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.line-row input[type=checkbox] { width: 16px; height: 16px; margin: 0; flex: none; accent-color: var(--accent); }
.line-row .line-btn { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 2px 0; text-align: left; }
.line-row .line-btn:hover .line-name { text-decoration: underline; }
.line-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Pastille */
.badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 24px; padding: 0 6px;
  border-radius: 5px; font-weight: 700; font-size: 13px; line-height: 1; flex: none; border: 0;
}
button.badge:hover { filter: brightness(.92); }
.badges { display: inline-flex; flex-wrap: wrap; gap: 4px; }

/* Fiche ligne */
.line-head { padding: 12px; border-bottom: 1px solid var(--border); }
.line-head .top { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.line-head .close { margin-left: auto; border: 1px solid var(--border); background: var(--bg2); border-radius: var(--radius); padding: 4px 10px; }
.line-head .close:hover { border-color: var(--accent); }
.line-head h3 { margin: 0; font-size: 15px; }
.meta { margin: 4px 0; color: var(--muted); font-size: 13px; }
.meta b { color: var(--fg); font-weight: 600; }
.detail-block { padding: 8px 12px 0; }
.detail-block h4 { margin: 4px 0; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.detail-block ul { margin: 0; padding-left: 18px; }
.detail-block li { margin: 2px 0; }
.dir-select { padding: 10px 12px 0; display: flex; flex-direction: column; gap: 4px; }
.dir-select button { text-align: left; padding: 6px 10px; border: 1px solid var(--border); background: var(--bg); border-radius: var(--radius); }
.dir-select button[aria-pressed=true] { background: var(--bg2); border-color: var(--accent); font-weight: 600; }

/* Schéma de ligne */
.schema { list-style: none; margin: 10px 12px 14px; padding: 0; }
.schema li { position: relative; padding: 0 0 0 30px; min-height: 36px; }
.schema li::before { /* trait vertical */
  content: ""; position: absolute; left: 10px; top: 0; bottom: 0; width: 6px; background: var(--lc, #888);
}
.schema li:first-child::before { top: 50%; }
.schema li:last-child::before { bottom: 50%; }
.schema li:only-child::before { display: none; }
.schema li::after { /* point d'arrêt */
  content: ""; position: absolute; left: 6px; top: 50%; width: 10px; height: 10px; margin-top: -7px;
  background: #fff; border: 3px solid var(--lc, #888); border-radius: 50%; box-sizing: content-box; left: 5px;
}
.schema li.terminus::after { width: 12px; height: 12px; margin-top: -9px; left: 4px; border-width: 3px; }
.schema .stop-btn {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; width: 100%; background: none; border: 0; text-align: left;
  padding: 7px 4px; min-height: 36px;
}
.schema .stop-btn:hover .sname { text-decoration: underline; }
.schema .sname { font-weight: 500; }
.schema li.terminus .sname { font-weight: 700; }
.schema .badge { height: 20px; min-width: 24px; font-size: 11px; padding: 0 4px; }
.approx-tag { font-size: 11px; color: var(--muted); font-style: italic; }

/* Popup et infobulles */
.stop-pop h3 { margin: 0 0 4px; font-size: 14px; }
.stop-pop .code { color: #5b6370; font-size: 12px; margin-bottom: 6px; }
.stop-pop .approx { color: #8a5a00; font-size: 12px; margin: 4px 0; }
.stop-pop .badges { margin: 6px 0; }
.stop-pop .links { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; font-size: 13px; }
.stop-pop a { color: #0b5cad; }
.chevron-icon { background: none; border: 0; pointer-events: none; }
.chevron-icon svg { display: block; }
.line-tip { font-weight: 600; }

/* Contrôle de localisation */
.locate-btn {
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; background: #fff;
  border: 0; cursor: pointer; padding: 0;
}
.locate-btn svg { width: 18px; height: 18px; stroke: #333; fill: none; stroke-width: 2; }

/* Mobile : tiroir en bas */
@media (max-width: 767px) {
  #panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 62vh; border-radius: 14px 14px 0 0; border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #panel.collapsed { height: auto; bottom: 0; top: auto; }
  .panel-toggle { padding: 8px 12px 10px; flex-wrap: wrap; }
  .panel-toggle .grip { display: block; width: 100%; height: 4px; max-width: 40px; margin: 0 auto 4px; background: var(--border); border-radius: 2px; flex-basis: 100%; }
  .chev { transform: rotate(-135deg); }
  #panel.collapsed .chev { transform: rotate(45deg); }
  .leaflet-bottom { bottom: 0; }
  .banner { top: 6px; }
}
