:root {
  --bg: #0d1117;
  --bg2: #131a23;
  --panel: #18212c;
  --panel2: #1e2935;
  --line: #2a3644;
  --line2: #364556;
  --text: #e6edf3;
  --muted: #8b9aab;
  --dim: #5d6b7b;
  --accent: #4da3ff;
  --ok: #2ecc71;
  --p-avance: #ff4757;
  --p-heure: #4da3ff;
  --p-retard: #2ecc71;
  --p-fort: #ff6ec7;
  --leger: #f1c40f;
  --retard: #ff8c2e;
  --fort: #ff4757;
  --nd: #6b7a8c;
  --crit: #ff4757;
  --warn: #ffb02e;
  --info: #4da3ff;
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-variant-numeric: tabular-nums; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }

/* ---------- Connexion ---------- */
#login { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(1200px 600px at 30% 20%, #1a2a3d 0%, var(--bg) 60%); }
.login-card { width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px; box-shadow: 0 20px 60px #0008; }
.login-card h1 { margin: 12px 0 2px; font-size: 22px; letter-spacing: .02em; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .06em; }
.login-card input { width: 100%; }
.login-card .btn { width: 100%; margin-top: 22px; padding: 10px; }
.err { color: var(--fort); min-height: 20px; margin-top: 10px; font-size: 13px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .08em; }
.logo svg { flex: none; }

/* ---------- Champs ---------- */
input[type=text], input[type=password], input[type=number], input[type=search], input[type=date], select, textarea {
  background: var(--bg2); border: 1px solid var(--line2); border-radius: 6px; padding: 7px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #4da3ff22; }
.btn { background: var(--panel2); border: 1px solid var(--line2); border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--fort); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- Cadre ---------- */
#app { display: grid; grid-template-columns: 64px 1fr; grid-template-rows: 52px 1fr; height: 100vh; }
#top { grid-column: 1 / 3; display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--bg2); border-bottom: 1px solid var(--line); }
#top .logo { font-size: 15px; }
#top .net { color: var(--muted); font-size: 13px; }
#top .spacer { flex: 1; }
#clock { font: 600 22px var(--mono); letter-spacing: .04em; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 12px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--nd); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.warn { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.dot.crit { background: var(--crit); box-shadow: 0 0 8px var(--crit); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .35; } }
#alarmBtn { cursor: pointer; }
#alarmBtn.has { border-color: var(--crit); color: #ffd7db; background: #3a1820; }
#userBtn { cursor: pointer; }
#nav { background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 10px 0; gap: 4px; }
#nav a { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 10px; color: var(--muted); text-decoration: none; position: relative; }
#nav a:hover { background: var(--panel); color: var(--text); }
#nav a.active { background: var(--panel2); color: var(--accent); }
#nav a.active::before { content: ""; position: absolute; left: -8px; top: 12px; bottom: 12px; width: 3px; border-radius: 2px; background: var(--accent); }
#nav a span { position: absolute; left: 56px; background: var(--panel2); border: 1px solid var(--line2); padding: 4px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .1s; z-index: 50; color: var(--text); }
#nav a:hover span { opacity: 1; }
#nav .sep { flex: 1; }
#main { overflow: auto; padding: 18px 20px 30px; position: relative; }
#main.full { padding: 0; overflow: hidden; }

h2 { margin: 0 0 14px; font-size: 18px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
h2 small { color: var(--muted); font-weight: 400; font-size: 13px; }
h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.grid { display: grid; gap: 14px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; position: relative; overflow: hidden; }
.kpi .v { font: 700 28px/1.1 system-ui; margin-top: 4px; }
.kpi .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi .s { font-size: 12px; color: var(--dim); margin-top: 2px; }
.kpi.alert { border-color: #ff475766; background: linear-gradient(180deg, #2a141a, var(--panel)); }
.kpi.alert .v { color: #ff8a95; }
.kpi .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--ok); }

/* ---------- Tableaux ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line2); position: sticky; top: 0; background: var(--panel); z-index: 1; white-space: nowrap; }
td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #ffffff06; }
td.num, th.num { text-align: right; }
.tablewrap { overflow: auto; max-height: calc(100vh - 190px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }

/* ---------- Badges ---------- */
.lb { display: inline-grid; place-items: center; min-width: 28px; height: 22px; padding: 0 6px; border-radius: 5px; font-weight: 800; font-size: 13px; }
.lb.tram { border-radius: 50%; width: 26px; min-width: 26px; height: 26px; }
.st { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.st.EN_LIGNE { background: #2ecc7122; color: #6fe3a0; }
.st.PREVUE { background: #ffffff0d; color: var(--muted); }
.st.ATTENTE { background: #f1c40f1f; color: #f5d553; }
.st.TERMINEE { background: transparent; color: var(--dim); border: 1px solid var(--line2); }
.st.ANNULEE { background: #ff475733; color: #ff8a95; }
.st.NON_VUE { background: #ffb02e2a; color: #ffc766; }
.st.PERDUE { background: #ff8c2e2a; color: #ffad6b; }
.st.HORS_OBS { color: var(--dim); }
.dl { font-family: var(--mono); font-weight: 700; white-space: nowrap; }
.dl.avance { color: var(--p-avance); } .dl.heure { color: var(--p-heure); } .dl.retard { color: var(--p-retard); } .dl.fort { color: var(--p-fort); } .dl.nd { color: var(--dim); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--line2); border-radius: 999px; cursor: pointer; background: var(--bg2); user-select: none; font-size: 13px; }
.chip.on { border-color: var(--accent); background: #4da3ff1a; }
.chip .lb { height: 18px; min-width: 22px; font-size: 11px; }
.chip .lb.tram { width: 20px; min-width: 20px; height: 20px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Thermomètres ---------- */
.thermo { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; }
.thermo-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.thermo-head .t { font-weight: 700; }
.thermo-head .stats { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-left: auto; flex-wrap: wrap; }
.thermo-head .stats b { color: var(--text); }
.thermo-body { overflow-x: auto; padding: 4px 8px 8px; }
.thermo svg { display: block; }
.thermo svg .stopname { fill: var(--muted); font-size: 11px; }
.thermo svg .stopname.term { fill: var(--text); font-weight: 700; }
.thermo svg .veh { cursor: pointer; }
.thermo svg .veh:hover rect { stroke: #fff; stroke-width: 1.5; }
.thermo svg .vt { font: 700 10.5px var(--mono); fill: #0d1117; pointer-events: none; }
.thermo svg .dirlabel { fill: var(--dim); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }

/* ---------- Carte ---------- */
#map { position: absolute; inset: 0; }
.map-over { position: absolute; top: 12px; left: 12px; z-index: 2; background: #131a23ee; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; max-width: 420px; backdrop-filter: blur(6px); }
.map-over .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; max-height: 120px; overflow: auto; }
.maplibregl-popup-content { background: var(--panel2) !important; color: var(--text); border: 1px solid var(--line2); border-radius: 8px !important; padding: 10px 12px !important; font-size: 13px; box-shadow: 0 8px 30px #0008 !important; }
.maplibregl-popup-tip { border-top-color: var(--panel2) !important; border-bottom-color: var(--panel2) !important; }
.maplibregl-popup-close-button { color: var(--muted); }

/* ---------- Journal ---------- */
.ev { display: grid; grid-template-columns: 4px 72px 140px 38px 1fr auto; gap: 10px; align-items: center; padding: 8px 12px 8px 0; border-bottom: 1px solid var(--line); }
.ev .lv { align-self: stretch; border-radius: 2px; background: var(--info); }
.ev.crit .lv { background: var(--crit); } .ev.warn .lv { background: var(--warn); }
.ev.unack { background: #ffffff05; }
.ev.unack.crit { background: #ff47570d; }
.ev .tm { font-family: var(--mono); color: var(--muted); }
.ev .ty { font-size: 11px; font-weight: 700; letter-spacing: .04em; color: var(--muted); text-transform: uppercase; }
.ev .ack { font-size: 11px; color: var(--dim); text-align: right; white-space: nowrap; }
.ev .msg .by { color: var(--accent); font-size: 12px; margin-left: 6px; }
.evlist { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); max-height: calc(100vh - 260px); overflow: auto; }
.evlist.short { max-height: 420px; }
.empty { padding: 30px; text-align: center; color: var(--dim); }

/* ---------- Tiroir ---------- */
#drawer { position: fixed; top: 52px; right: 0; bottom: 0; width: min(720px, 100vw); background: var(--bg2); border-left: 1px solid var(--line2); box-shadow: -20px 0 50px #0008; z-index: 30; display: flex; flex-direction: column; transform: translateX(105%); transition: transform .18s ease; }
#drawer.open { transform: none; }
#drawer header { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
#drawer header .t { font-weight: 700; font-size: 16px; flex: 1; }
#drawer .body { overflow: auto; padding: 14px 16px; }
#drawer td { padding: 5px 8px; font-size: 13px; }
tr.skip td { text-decoration: line-through; color: var(--dim); }
tr.cur td { background: #4da3ff14; }
tr.passe td { color: var(--muted); }
.src { font-size: 10px; padding: 1px 5px; border-radius: 3px; background: var(--panel2); color: var(--muted); }
.src.rt { background: #2ecc7122; color: #6fe3a0; }
.src.alias { background: #ffb02e22; color: #ffc766; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------- Divers ---------- */
.bars .row { display: grid; grid-template-columns: 170px 1fr 80px; gap: 10px; align-items: center; margin: 6px 0; font-size: 13px; }
.bars .track { height: 8px; background: var(--bg2); border-radius: 4px; overflow: hidden; }
.bars .fill { height: 100%; background: var(--accent); }
.cols2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 14px; }
.form-row { display: grid; grid-template-columns: 220px 1fr; gap: 10px; align-items: center; margin: 8px 0; }
.form-row label { color: var(--muted); font-size: 13px; }
.form-row .hint { grid-column: 2; font-size: 12px; color: var(--dim); margin-top: -4px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--panel2); border: 1px solid var(--line2); border-left: 4px solid var(--info); padding: 10px 14px; border-radius: 6px; max-width: 420px; box-shadow: 0 10px 30px #0008; animation: tin .2s ease; font-size: 13px; cursor: pointer; }
.toast.crit { border-left-color: var(--crit); } .toast.warn { border-left-color: var(--warn); }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } }
.menu { position: absolute; top: 46px; right: 12px; background: var(--panel2); border: 1px solid var(--line2); border-radius: 8px; padding: 6px; z-index: 70; min-width: 200px; box-shadow: 0 10px 30px #0008; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 5px; cursor: pointer; }
.menu button:hover { background: var(--panel); }
.menu .who { padding: 8px 10px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line2); border-radius: 12px; padding: 20px; min-width: 360px; }
dialog::backdrop { background: #000a; }
.loading { padding: 60px; text-align: center; color: var(--muted); }
@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 52px 1fr 56px; }
  #nav { grid-row: 3; flex-direction: row; justify-content: space-around; border-right: 0; border-top: 1px solid var(--line); padding: 0; }
  #nav .sep, #nav a span { display: none; }
  #top .net, #top .hide-m { display: none; }
  .ev { grid-template-columns: 4px 56px 1fr auto; }
  .ev .ty, .ev .lbc { display: none; }
}
