:root {
  --bg: #0b1020;
  --panel: rgba(18, 24, 42, 0.82);
  --panel-solid: #12182a;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf5;
  --text-dim: #9aa6c0;
  --accent: #38bdf8;
  --accent-2: #22d3ee;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --radius: 14px;
}
[data-theme="light"] {
  --bg: #eef2f8;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-solid: #ffffff;
  --border: rgba(0, 0, 0, 0.08);
  --text: #0f172a;
  --text-dim: #51607a;
  --accent: #0284c7;
  --accent-2: #0891b2;
  --shadow: 0 10px 40px rgba(30, 41, 59, 0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #app { height: 100%; width: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}
#map { position: absolute; inset: 0; top: 0; }

/* ── Barre supérieure ───────────────────────────────── */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 60px; z-index: 20;
  display: flex; align-items: center; gap: 18px; padding: 0 18px;
  background: var(--panel); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 19px; }
.brand .logo { font-size: 22px; }
.brand .accent { color: var(--accent); }

.search-wrap { position: relative; flex: 1; max-width: 420px; }
#search {
  width: 100%; height: 40px; padding: 0 16px; font-size: 14px;
  color: var(--text); background: var(--panel-solid);
  border: 1px solid var(--border); border-radius: 10px; outline: none;
}
#search:focus { border-color: var(--accent); }
#search-results {
  position: absolute; top: 46px; left: 0; right: 0; z-index: 30;
  background: var(--panel-solid); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; display: none;
}
#search-results.open { display: block; }
.sr-item { padding: 10px 14px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.sr-item:hover { background: rgba(56, 189, 248, 0.12); }
.sr-call { font-weight: 600; }
.sr-meta { color: var(--text-dim); font-size: 12px; }

.stats { display: flex; gap: 22px; margin-left: auto; }
.stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.stat-val { font-weight: 700; font-size: 16px; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim); }

#theme-toggle {
  width: 40px; height: 40px; border-radius: 10px; cursor: pointer; font-size: 18px;
  background: var(--panel-solid); color: var(--text); border: 1px solid var(--border);
}
#theme-toggle:hover { border-color: var(--accent); }

/* ── Panneaux ───────────────────────────────────────── */
.panel {
  background: var(--panel); backdrop-filter: blur(16px);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.panel-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-dim); margin-bottom: 8px; font-weight: 700; }

#legend { position: absolute; left: 14px; bottom: 14px; z-index: 15; padding: 12px 14px; }
#api-link { display: block; margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--accent); text-decoration: none; font-weight: 600; }
#api-link:hover { text-decoration: underline; }
.legend-item { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; cursor: pointer; user-select: none; }
.legend-item.off { opacity: 0.35; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }

#live-badge {
  position: absolute; top: 72px; right: 14px; z-index: 15;
  display: flex; align-items: center; gap: 7px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.5px; padding: 6px 11px; border-radius: 20px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text-dim);
}
#live-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34,197,94,0.6); animation: pulse 1.8s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34,197,94,0.6); }
  70% { box-shadow: 0 0 0 8px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

/* ── Détail station ─────────────────────────────────── */
#detail {
  position: absolute; top: 72px; right: 14px; bottom: 14px; width: 360px; z-index: 25;
  padding: 20px; overflow-y: auto; transition: transform 0.25s ease;
}
#detail.hidden { transform: translateX(420px); pointer-events: none; }
#detail-close {
  position: absolute; top: 14px; right: 14px; width: 30px; height: 30px; border-radius: 8px;
  cursor: pointer; background: var(--panel-solid); border: 1px solid var(--border); color: var(--text);
}
.d-call { font-size: 24px; font-weight: 800; letter-spacing: 0.5px; }
.d-type { display: inline-block; margin-top: 6px; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; color: #fff; }
.d-section { margin-top: 18px; }
.d-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.d-cell { background: var(--panel-solid); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.d-cell .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim); }
.d-cell .v { font-size: 16px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.d-comment { margin-top: 14px; padding: 10px 12px; background: var(--panel-solid);
  border: 1px solid var(--border); border-radius: 10px; font-size: 13px; color: var(--text-dim);
  word-break: break-word; }
.d-btn { display: inline-block; margin-top: 14px; padding: 8px 14px; border-radius: 9px;
  background: var(--accent); color: #001018; font-weight: 700; border: none; cursor: pointer; font-size: 13px; }
.d-btn:hover { filter: brightness(1.1); }
.hidden { display: none; }

/* ── Graphiques ─────────────────────────────────────── */
.chart-toolbar { display: flex; gap: 6px; margin: 14px 0 8px; }
.chart-range { flex: 1; padding: 6px 0; font-size: 12px; font-weight: 600; cursor: pointer;
  background: var(--panel-solid); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 8px; }
.chart-range.active { background: var(--accent); color: #001018; border-color: var(--accent); }
.chart-card { background: var(--panel-solid); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px 8px; margin-top: 10px; }
.chart-card .chart-h { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim); font-weight: 700; margin-bottom: 6px; display: flex; justify-content: space-between; }
.chart-card .chart-h .now { color: var(--accent); font-size: 13px; }
.chart-wrap { position: relative; height: 130px; }
.chart-empty { color: var(--text-dim); font-size: 12px; padding: 6px 0; }

/* ── Compte & favoris ───────────────────────────────── */
#account-panel { position: absolute; top: 72px; right: 14px; width: 320px; z-index: 28;
  padding: 20px; transition: transform 0.25s ease; }
#account-panel.hidden { transform: translateX(380px); pointer-events: none; }
#acc-close { position: absolute; top: 14px; right: 14px; width: 30px; height: 30px; border-radius: 8px;
  cursor: pointer; background: var(--panel-solid); border: 1px solid var(--border); color: var(--text); }
.acc-title { font-size: 18px; font-weight: 800; margin-bottom: 14px; }
.acc-form { display: flex; flex-direction: column; gap: 9px; }
.acc-form input { height: 40px; padding: 0 12px; font-size: 14px; color: var(--text);
  background: var(--panel-solid); border: 1px solid var(--border); border-radius: 9px; outline: none; }
.acc-form input:focus { border-color: var(--accent); }
.acc-btn { height: 42px; background: var(--accent); color: #001018; border: none; border-radius: 9px;
  font-weight: 700; cursor: pointer; font-size: 14px; }
.acc-btn:hover { filter: brightness(1.1); }
.acc-btn.alt { background: var(--panel-solid); color: var(--text); border: 1px solid var(--border); }
.acc-status { font-size: 12px; min-height: 15px; margin-top: 4px; }
.acc-status.err { color: #ef4444; } .acc-status.ok { color: #22c55e; }
.acc-user { display: flex; align-items: center; gap: 8px; font-size: 15px; margin-bottom: 4px; }
.acc-user .av { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #001018;
  display: flex; align-items: center; justify-content: center; font-weight: 800; }
.fav-list { margin-top: 6px; }
.fav-row { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.fav-row .fc { flex: 1; color: var(--accent); cursor: pointer; font-weight: 600; }
.fav-row .fc:hover { text-decoration: underline; }
.fav-row .fx { cursor: pointer; background: none; border: none; color: #ef4444; font-size: 15px; }

.fav-star { background: none; border: none; cursor: pointer; font-size: 22px; color: #fbbf24;
  vertical-align: middle; margin-left: 4px; line-height: 1; }
#account-btn.logged { color: var(--accent); }

/* ── Rejeu temporel ─────────────────────────────────── */
#replay-bar { position: absolute; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 24;
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; width: min(760px, calc(100% - 28px)); }
#replay-bar.hidden { display: none; }
#rp-play { width: 38px; height: 38px; flex: none; border-radius: 50%; cursor: pointer; font-size: 15px;
  background: var(--accent); color: #001018; border: none; }
#rp-play:hover { filter: brightness(1.1); }
#rp-time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 13px; min-width: 96px; }
#rp-slider { flex: 1; accent-color: var(--accent); cursor: pointer; }
#replay-bar select { height: 34px; padding: 0 8px; font-size: 12px; color: var(--text);
  background: var(--panel-solid); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
#rp-info { font-size: 11px; color: var(--text-dim); min-width: 70px; }
#rp-close { width: 32px; height: 32px; flex: none; border-radius: 8px; cursor: pointer;
  background: var(--panel-solid); color: var(--text); border: 1px solid var(--border); }
#replay-btn.active { color: var(--accent); }
@media (max-width: 640px) {
  #replay-bar { flex-wrap: wrap; bottom: 8px; }
  #rp-info { display: none; }
}

/* ── Alertes ────────────────────────────────────────── */
#alert-btn { position: relative; }
.badge { position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: #ef4444; color: #fff; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; }

#alerts-panel { position: absolute; top: 72px; right: 14px; bottom: 14px; width: 370px; z-index: 27;
  padding: 18px; overflow-y: auto; transition: transform 0.25s ease; }
#alerts-panel.hidden { transform: translateX(440px); pointer-events: none; }
#ap-close { position: absolute; top: 14px; right: 14px; width: 30px; height: 30px; border-radius: 8px;
  cursor: pointer; background: var(--panel-solid); border: 1px solid var(--border); color: var(--text); }
.ap-notif { width: 100%; margin-top: 10px; padding: 9px; border-radius: 9px; cursor: pointer; font-size: 13px;
  background: var(--panel-solid); color: var(--text); border: 1px solid var(--border); }
.ap-notif.on { border-color: #22c55e; color: #22c55e; }
.ap-form { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.ap-form select, .ap-form input { height: 38px; padding: 0 10px; font-size: 13px; color: var(--text);
  background: var(--panel-solid); border: 1px solid var(--border); border-radius: 8px; outline: none; width: 100%; }
.ap-form select:focus, .ap-form input:focus { border-color: var(--accent); }
#ap-geo-rows { display: flex; flex-direction: column; gap: 8px; }
#ap-pick { height: 38px; cursor: pointer; background: var(--panel-solid); color: var(--text);
  border: 1px dashed var(--border); border-radius: 8px; font-size: 13px; }
#ap-pick.armed { border-color: var(--accent); color: var(--accent); }
.ap-hint { font-size: 11px; color: var(--text-dim); }
#ap-add { height: 40px; background: var(--accent); color: #001018; border: none; border-radius: 9px;
  font-weight: 700; cursor: pointer; font-size: 14px; }
#ap-add:hover { filter: brightness(1.1); }
.ap-rule { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.ap-rule .ar-ico { font-size: 16px; }
.ap-rule .ar-txt { flex: 1; }
.ap-rule .ar-sub { font-size: 11px; color: var(--text-dim); }
.ap-rule .ar-del { cursor: pointer; background: none; border: none; color: #ef4444; font-size: 16px; }
.ap-event { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.ap-event .ae-time { font-size: 11px; color: var(--text-dim); }
.ap-event .ae-call { color: var(--accent); cursor: pointer; }

#toasts { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 40;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; cursor: pointer; max-width: 90vw; padding: 11px 16px; border-radius: 11px;
  background: var(--panel-solid); color: var(--text); border: 1px solid var(--accent);
  box-shadow: var(--shadow); font-size: 14px; font-weight: 600; animation: toastin 0.25s ease; }
.toast.hide { opacity: 0; transition: opacity 0.3s; }
@keyframes toastin { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Cercle de géorepérage sur la carte */
.geo-preview { }

/* ── Messagerie ─────────────────────────────────────── */
.msg-list { display: flex; flex-direction: column; margin-top: 8px; }
.msg { max-width: 88%; margin: 5px 0; padding: 7px 10px; border-radius: 11px; font-size: 13px; word-break: break-word; }
.msg.in { background: var(--panel-solid); border: 1px solid var(--border); align-self: flex-start; border-bottom-left-radius: 3px; }
.msg.out { background: var(--accent); color: #001018; align-self: flex-end; border-bottom-right-radius: 3px; }
.msg-meta { font-size: 10px; opacity: 0.75; margin-bottom: 2px; }
.msg.out .msg-meta { color: #00303d; }
.msg-compose { display: flex; gap: 6px; margin-top: 12px; }
.msg-compose input { flex: 1; height: 36px; padding: 0 10px; font-size: 13px; color: var(--text);
  background: var(--panel-solid); border: 1px solid var(--border); border-radius: 8px; outline: none; }
.msg-compose input:focus { border-color: var(--accent); }
.msg-compose button, .mp-compose button { padding: 0 14px; height: 36px; background: var(--accent); color: #001018;
  border: none; border-radius: 8px; font-weight: 700; cursor: pointer; font-size: 13px; }
.msg-compose button:hover, .mp-compose button:hover { filter: brightness(1.1); }
.msg-status { font-size: 12px; margin-top: 6px; min-height: 15px; }
.msg-status.err { color: #ef4444; }
.msg-status.ok { color: #22c55e; }
.msg-empty { color: var(--text-dim); font-size: 12px; padding: 6px 0; }

#messages-panel { position: absolute; top: 72px; left: 14px; bottom: 14px; width: 360px; z-index: 26;
  padding: 18px; overflow-y: auto; transition: transform 0.25s ease; }
#messages-panel.hidden { transform: translateX(-440px); pointer-events: none; }
#mp-close { position: absolute; top: 14px; right: 14px; width: 30px; height: 30px; border-radius: 8px;
  cursor: pointer; background: var(--panel-solid); border: 1px solid var(--border); color: var(--text); }
.mp-compose { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.mp-compose #mp-to { width: 90px; }
.mp-compose input { height: 36px; padding: 0 10px; font-size: 13px; color: var(--text); flex: 1;
  background: var(--panel-solid); border: 1px solid var(--border); border-radius: 8px; outline: none; }
.mp-compose #mp-text { flex-basis: 100%; }
.mp-list { margin-top: 14px; }
.mp-item { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.mp-item .mp-h { font-size: 11px; color: var(--text-dim); margin-bottom: 2px; }
.mp-item .mp-call { color: var(--accent); cursor: pointer; font-weight: 600; }
.mp-item .mp-call:hover { text-decoration: underline; }

.maplibregl-popup-content {
  background: var(--panel-solid); color: var(--text); border-radius: 10px;
  border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 13px; padding: 8px 12px;
}
.maplibregl-popup-tip { display: none; }

@media (max-width: 640px) {
  .stats { display: none; }
  #detail { width: auto; left: 14px; }
  #detail.hidden { transform: translateY(120%); }
}
