/* ----------------------------------------------------------------- Base */
:root {
  --bg: #0b1017;
  --surface: #141c26;
  --surface-2: #1c2735;
  --line: #27333f;
  --text: #e8eef6;
  --muted: #93a3b6;
  --accent: #f97316;
  --accent-soft: rgba(249, 115, 22, 0.15);
  --ok: #22c55e;
  --warn: #eab308;
  --danger: #ef4444;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { line-height: 1.25; margin: 0; }
a { color: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: #24313f; }
.btn:active { transform: scale(.98); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #1a0d02; }
.btn-primary:hover { background: #fb8c3a; }
.btn-small { padding: 6px 10px; font-size: .85rem; }
.btn-icon { padding: 9px; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn[disabled] { opacity: .4; cursor: not-allowed; }

/* ------------------------------------------------------- Page d'accueil */
.page-home { padding: 0 0 48px; }

.site-header {
  padding: calc(28px + var(--safe-top)) 20px 20px;
  max-width: 1100px;
  margin: 0 auto;
}
.site-header h1 { font-size: 1.8rem; letter-spacing: -.02em; }
.site-header p { color: var(--muted); margin: 6px 0 0; }

main { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

main section { margin-top: 32px; }
main h2 {
  font-size: 1.05rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 12px;
}
.count { color: #5f7186; font-weight: 400; }

.banner {
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: .92rem;
  border: 1px solid;
}
.banner-warn { background: rgba(234, 179, 8, .1); border-color: rgba(234, 179, 8, .4); }
.banner code { background: rgba(255, 255, 255, .08); padding: 1px 5px; border-radius: 5px; }

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}
.dropzone-icon { width: 34px; height: 34px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dropzone-main { margin: 10px 0 2px; font-weight: 600; }
.dropzone-sub { margin: 0; color: var(--muted); font-size: .9rem; }
.hint { color: var(--muted); font-size: .85rem; margin: 10px 2px 0; }

.import-status { margin: 8px 2px 0; font-size: .9rem; min-height: 1.2em; color: var(--muted); }
.import-status.ok { color: var(--ok); }
.import-status.warn { color: var(--warn); }
.import-status.error { color: var(--danger); }

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.empty { color: var(--muted); font-size: .92rem; grid-column: 1 / -1; margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color .15s, transform .1s;
}
.card:hover { border-color: #3a4a5c; }
.card-link { text-decoration: none; color: inherit; display: block; }
.card-sketch {
  background: linear-gradient(180deg, #101825, #16202d);
  color: var(--accent);
  border-bottom: 1px solid var(--line);
  display: block;
}
.card-sketch svg { display: block; width: 100%; height: 120px; }
.sketch-start { fill: var(--ok); }
.sketch-end { fill: var(--danger); }
.card-body { padding: 14px 14px 4px; }
.card-title { font-size: 1.05rem; }
.card-subtitle {
  margin: 2px 0 0;
  color: #5f7186;
  font-size: .78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-stats { display: flex; gap: 18px; margin: 12px 0 0; }
.card-stats dt { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.card-stats dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.card-actions { display: flex; gap: 8px; padding: 14px; margin-top: auto; }
.card-actions .btn-primary { flex: 1; }

/* --------------------------------------------------------- Page de suivi */
.page-follow { overflow: hidden; height: 100dvh; }
#map { position: fixed; inset: 0; background: #0f1720; }

/* Les contrôles Leaflet passent sous la barre de titre. */
.leaflet-top { top: calc(58px + var(--safe-top)); }
.leaflet-container { background: #0f1720; font-family: inherit; }
.leaflet-control-attribution { font-size: 10px; background: rgba(11, 16, 23, .7) !important; color: #7b8ba0 !important; }
.leaflet-control-attribution a { color: #9fb2c8 !important; }
.leaflet-bar a, .leaflet-control-layers-toggle {
  background-color: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--line) !important;
}
.leaflet-control-layers { background: var(--surface) !important; color: var(--text); border-radius: 10px !important; }

.hud { position: fixed; z-index: 500; }

.hud-top {
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + var(--safe-top)) 12px 8px;
  background: linear-gradient(180deg, rgba(11, 16, 23, .95), rgba(11, 16, 23, 0));
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.hud-top h1 {
  font-size: 1rem;
  font-weight: 650;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .8);
}
.btn-back { background: rgba(20, 28, 38, .85); backdrop-filter: blur(6px); }

.chip {
  font-size: .72rem;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(20, 28, 38, .85);
  backdrop-filter: blur(6px);
  white-space: nowrap;
}
.chip-ok { color: var(--ok); border-color: rgba(34, 197, 94, .45); }
.chip-warn { color: var(--warn); border-color: rgba(234, 179, 8, .45); }
.chip-error { color: var(--danger); border-color: rgba(239, 68, 68, .45); }
.chip-idle { color: var(--muted); }

.alert {
  top: calc(56px + var(--safe-top));
  left: 12px; right: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(28, 39, 53, .95);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: .9rem;
  box-shadow: var(--shadow);
}
.alert span { flex: 1; }
.alert-danger { background: rgba(69, 26, 26, .95); border-color: rgba(239, 68, 68, .6); }

.map-buttons {
  right: 12px;
  bottom: calc(var(--panel-height, 210px) + 14px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: bottom .25s ease;
}
.btn-round {
  width: 46px; height: 46px;
  border-radius: 50%;
  padding: 0;
  background: rgba(20, 28, 38, .92);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
}
.btn-round.is-active { color: var(--accent); border-color: var(--accent); }
.btn-round.is-muted { color: #64748b; }
.btn-round.is-muted::after {
  content: "";
  position: absolute;
  width: 30px; height: 2px;
  background: currentColor;
  transform: rotate(-45deg);
}
.btn-round { position: relative; overflow: hidden; }

.hud-bottom {
  left: 0; right: 0; bottom: 0;
  background: rgba(13, 19, 27, .94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 0 14px calc(12px + var(--safe-bottom));
  box-shadow: 0 -8px 24px rgba(0, 0, 0, .35);
}
.panel-toggle {
  display: block;
  width: 100%;
  background: none;
  border: 0;
  padding: 10px 0 6px;
  cursor: pointer;
}
.grabber { display: block; width: 44px; height: 4px; border-radius: 99px; background: #3a4a5c; margin: 0 auto; }

.progress {
  position: relative;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  border: 1px solid var(--line);
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #ea580c, var(--accent));
  transition: width .4s ease;
}
.progress-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
}

.stats { display: grid; gap: 10px; margin-top: 12px; }
.stats-primary { grid-template-columns: 1.4fr 1fr 1fr; align-items: end; }
.stats-secondary { grid-template-columns: repeat(3, 1fr); }
.stat { min-width: 0; }
.stat-label {
  display: block;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.stat-value {
  display: block;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-big .stat-value { font-size: 1.7rem; color: var(--accent); letter-spacing: -.02em; }
.stat-value.is-alert { color: var(--danger); }

.panel-body { overflow: hidden; transition: max-height .25s ease, opacity .2s ease; max-height: 260px; }
.is-collapsed .panel-body { max-height: 0; opacity: 0; }
.profile-wrap { margin-top: 12px; }
#profile { width: 100%; height: 90px; display: block; }
.profile-empty { color: var(--muted); font-size: .85rem; margin: 8px 0; }

/* Marqueur de position */
.me-icon { background: none; border: 0; }
.me-arrow {
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  transition: transform .3s linear;
}
.me-arrow svg { width: 26px; height: 26px; fill: #38bdf8; stroke: #fff; stroke-width: 1.2; filter: drop-shadow(0 1px 3px rgba(0, 0, 0, .6)); }
.me-arrow.no-heading svg { fill: #38bdf8; transform: scale(.62); }
.me-arrow.no-heading { border-radius: 50%; }

@media (max-width: 420px) {
  .stats-secondary { grid-template-columns: repeat(2, 1fr); }
  .stat-big .stat-value { font-size: 1.5rem; }
}
@media (min-width: 760px) {
  .hud-top { padding-inline: 16px; }
  .hud-bottom { padding-inline: 20px; }
  .stats-primary { grid-template-columns: 1.2fr repeat(2, 1fr); }
  .stats-secondary { grid-template-columns: repeat(6, 1fr); }
}
