:root {
  --citea: #0055A4;
  --citea-dark: #00407c;
  --alert: #E8730C;
  --ok: #1a8a3a;
  --late: #d4380d;
  --early: #0a7ea4;
  --ink: #1a1a1a;
  --muted: #5a6573;
  --line: #e2e6ea;
  --bg: #ffffff;
}

* { box-sizing: border-box; }

/* L'attribut HTML `hidden` doit toujours l'emporter sur les display:flex/block ci-dessous */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

body { overflow: hidden; }

/* Header */
#app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--citea);
  color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 17px; }
.brand-name strong { font-weight: 700; }
.brand-name { font-weight: 400; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.3);
}
.status { display: flex; align-items: center; gap: 6px; font-size: 13px; opacity: .95; }
.conn-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #b8c4d0; transition: background .3s;
}
.conn-dot.ok { background: #5dff9c; }
.conn-dot.error { background: #ff6b6b; }

/* Carte */
#map {
  position: absolute;
  top: 52px; left: 0; right: 0; bottom: 0;
  z-index: 1;
}

/* Marqueurs bus */
.bus-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 6px;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.me-marker {
  width: 16px; height: 16px;
  background: var(--citea);
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(0,85,164,.25);
}

/* Bandeau alertes */
.alert-banner {
  position: fixed;
  top: 52px; left: 0; right: 0;
  z-index: 1090;
  background: var(--alert);
  color: #fff;
  padding: 9px 16px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}
.alert-banner-more { font-size: 12px; text-decoration: underline; white-space: nowrap; }

/* Panneau arrêt */
.stop-panel {
  position: fixed;
  z-index: 1095;
  background: #fff;
  display: flex;
  flex-direction: column;
  box-shadow: -2px 0 12px rgba(0,0,0,.18);
}
@media (min-width: 769px) {
  .stop-panel { top: 52px; right: 0; bottom: 0; width: 360px; }
}
@media (max-width: 768px) {
  .stop-panel {
    left: 0; right: 0; bottom: 0;
    max-height: 55vh;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
  }
}
.stop-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.stop-panel-head h2 { margin: 0; font-size: 17px; color: var(--citea-dark); }
.stop-body { overflow-y: auto; padding: 8px 0; }

.dep-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
}
.dep-line {
  min-width: 34px;
  text-align: center;
  font-weight: 700;
  color: #fff;
  background: var(--citea);
  border-radius: 5px;
  padding: 4px 6px;
  font-size: 13px;
}
.dep-mid { min-width: 0; }
.dep-dir { font-size: 14px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dep-sched { font-size: 12px; color: var(--muted); }
.dep-time { text-align: right; font-weight: 600; font-size: 15px; }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  color: #fff;
}
.badge.on_time { background: var(--ok); }
.badge.delayed { background: var(--late); }
.badge.early { background: var(--early); }

/* Overlay alertes */
.overlay {
  position: fixed; inset: 0;
  z-index: 1200;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.overlay-card {
  background: #fff;
  width: 100%; max-width: 520px;
  max-height: 80vh;
  border-radius: 8px;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.overlay-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--alert);
  color: #fff;
}
.overlay-head h2 { margin: 0; font-size: 17px; }
.alerts-list { overflow-y: auto; padding: 8px 0; }
.alert-item { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.alert-item h3 { margin: 0 0 4px; font-size: 15px; }
.alert-item p { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.alert-routes { display: flex; flex-wrap: wrap; gap: 5px; }
.alert-route-chip {
  font-size: 11px; font-weight: 700; color: #fff;
  background: var(--citea); padding: 2px 7px; border-radius: 4px;
}

/* Boutons */
.icon-btn {
  background: none; border: none; cursor: pointer;
  font-size: 26px; line-height: 1; color: inherit;
  padding: 0 4px;
}
.locate-btn {
  position: fixed;
  bottom: 20px; right: 16px;
  z-index: 1080;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: var(--citea);
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.muted { color: var(--muted); font-size: 14px; padding: 0 16px; }

/* Recherche d'arrêt */
.search-bar {
  position: fixed;
  top: 62px; left: 10px; right: 10px;
  z-index: 1086;
  display: flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 8px 0 12px;
  background: #fff;
  border-radius: 9px;
  box-shadow: 0 2px 10px rgba(0,0,0,.2);
}
@media (min-width: 769px) { .search-bar { max-width: 420px; } }
body.has-alert .search-bar { top: 98px; }
.search-icon { color: var(--muted); font-size: 19px; line-height: 1; }
.search-input {
  flex: 1; min-width: 0; height: 100%;
  border: none; outline: none; background: transparent;
  font-size: 16px; color: var(--ink);
}
.search-clear {
  background: none; border: none; cursor: pointer;
  font-size: 24px; line-height: 1; color: var(--muted); padding: 0 4px;
}
.search-results {
  list-style: none; margin: 6px 0 0; padding: 4px 0;
  position: absolute; top: 100%; left: 0; right: 0;
  background: #fff; border-radius: 9px;
  box-shadow: 0 6px 18px rgba(0,0,0,.22);
  max-height: 52vh; overflow-y: auto;
}
.search-results li {
  padding: 12px 14px; cursor: pointer;
  font-size: 15px; border-bottom: 1px solid var(--line);
}
.search-results li:last-child { border-bottom: none; }
.search-results li.active, .search-results li:hover { background: #eef4fb; }
.search-results .sr-sub { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.search-results .sr-empty { padding: 12px 14px; color: var(--muted); font-size: 14px; }

/* Arrêts sur la carte (visibles à fort zoom) */
.stop-dot {
  width: 11px; height: 11px;
  background: #fff; border: 3px solid var(--citea);
  border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,.35);
}
/* Marqueur de l'arrêt recherché / "ton arrêt" */
.stop-pin {
  width: 20px; height: 20px;
  background: var(--alert); border: 3px solid #fff;
  border-radius: 50%; box-shadow: 0 0 0 4px rgba(232,115,12,.3), 0 1px 4px rgba(0,0,0,.4);
}
.term-pin {
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  background: var(--citea-dark); border: 3px solid #fff;
  border-radius: 4px; color: #fff; font-size: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}

/* Marqueur bus orienté selon le cap */
.bus-wrap { position: relative; width: 34px; height: 34px; }
.bus-dir { position: absolute; inset: 0; pointer-events: none; }
.bus-arrow {
  position: absolute; left: 50%; top: -2px; margin-left: -5px;
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 8px solid var(--citea-dark);
}
.bus-wrap .bus-marker { position: absolute; left: 3px; top: 3px; }

/* Lien "suivre le bus" dans la fiche arrêt */
.dep-row.live { cursor: pointer; }
.dep-row.live:active { background: #eef4fb; }
.dep-follow { display: block; font-size: 11px; font-weight: 600; color: var(--citea); margin-top: 3px; }

/* Barre de tracé d'une course */
.trip-bar {
  position: fixed;
  bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 1082;
  display: flex; align-items: center; gap: 10px;
  max-width: 88vw;
  padding: 8px 8px 8px 16px;
  background: var(--citea-dark); color: #fff;
  border-radius: 24px;
  box-shadow: 0 3px 14px rgba(0,0,0,.32);
}
.trip-bar-label { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trip-close {
  flex: none; width: 30px; height: 30px;
  background: rgba(255,255,255,.22); border: none; color: #fff;
  border-radius: 50%; font-size: 20px; line-height: 1; cursor: pointer;
}
