/* =========================================================================
   VéloTrack — socle
   Reconstitué : l'archive ne contenait que le complément v2/v3, qui utilise
   sept variables sans jamais les définir. Ce fichier pose le thème, la mise
   en page et la typographie ; le complément v2 le suit et le surcharge.

   Parti pris : un tableau de bord d'instrument, lu de nuit, souvent d'un
   coup d'œil sur un téléphone. Fond sombre, chiffres à chasse fixe pour
   qu'ils ne dansent pas d'un rafraîchissement à l'autre.
   ========================================================================= */

:root {
  --bg:     #12151a;   /* fond général, bleu-gris très sombre */
  --panel:  #1b2027;   /* cartes et surfaces surélevées */
  --border: #2b323c;   /* filets de séparation */
  --text:   #e6e9ee;   /* texte courant */
  --muted:  #8b95a3;   /* libellés, aides, métadonnées */

  --low:    #ef4444;   /* rouge — alerte, batterie critique */
  --mid:    #f59e0b;   /* ambre — vigilance, batterie faible */
  --high:   #22c55e;   /* vert — nominal */
  --accent: #2563eb;   /* bleu — actions */
}

*, *::before, *::after { box-sizing: border-box; }

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

/* La page de connexion se centre sur toute la hauteur : pas de marge. */
body:has(.login-page) { padding: 0; }

/* --- Titres ------------------------------------------------------------ */

h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h2 {
  margin: 0 0 0.9rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

/* --- En-tête et navigation --------------------------------------------- */

header {
  max-width: 1100px;
  margin: 0 auto 1.25rem;
}

header p { margin: 0.5rem 0 0; }

.top-nav, header nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  font-size: 0.9rem;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* --- Panneaux ----------------------------------------------------------- */

.panel {
  max-width: 1100px;
  margin: 0 auto 1rem;
  padding: 1.1rem 1.25rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* --- Bandeau de chiffres ------------------------------------------------ */

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 2.5rem;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* --- Textes secondaires -------------------------------------------------- */

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
}

h2 .hint { font-size: 0.8rem; }

.error {
  color: var(--low);
  font-size: 0.88rem;
}
.error:empty { display: none; }

code {
  padding: 0.1rem 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 0.85em;
}

/* --- Tableaux ------------------------------------------------------------ */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

th {
  padding: 0 0.7rem 0.5rem 0;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 0.45rem 0.7rem 0.45rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

tbody tr:last-child td { border-bottom: none; }

/* --- Réglages ------------------------------------------------------------ */

.setting {
  padding: 0.9rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.setting:last-child { border-bottom: none; }

.setting label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.setting .val {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--accent);
}

.setting .hint { margin: 0.45rem 0 0; }

input[type="range"] {
  width: 100%;
  height: 4px;
  margin: 0;
  border-radius: 2px;
  background: var(--border);
  accent-color: var(--accent);
  appearance: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
}

/* --- Accessibilité -------------------------------------------------------- */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Écrans étroits (WebView de l'application) ---------------------------- */

@media (max-width: 640px) {
  body { padding: 0.9rem; }

  .header-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
  }

  .stats { gap: 1.5rem; }

  .panel {
    padding: 0.9rem 1rem;
    border-radius: 6px;
  }

  /* Le tableau déborde plutôt que de se compresser illisiblement. */
  .panel:has(table) { overflow-x: auto; }
}

/* v2 : login, alertes, carte OSM */
.header-row { display: flex; justify-content: space-between; align-items: center; }
.logout { font-size: 0.85rem; color: var(--muted); }

.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-box { background: var(--panel); padding: 2rem; border-radius: 8px; border: 1px solid var(--border); width: 320px; }
.login-box h1 { margin-top: 0; text-align: center; }
.login-box label { display: block; margin: 1rem 0 0.3rem; color: var(--muted); font-size: 0.85rem; }
.login-box input { width: 100%; padding: 0.5rem; border-radius: 4px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.login-box button { width: 100%; margin-top: 1.4rem; padding: 0.6rem; border: none; border-radius: 4px; background: #2563eb; color: white; font-size: 1rem; cursor: pointer; }

.alerts { background: #3b1f1f; border-left: 4px solid var(--low); }
.alerts h2 { display: flex; justify-content: space-between; align-items: center; margin-top: 0; }
.alerts ul { list-style: none; padding: 0; margin: 0; }
.alerts li { padding: 0.4rem 0; border-bottom: 1px solid rgba(255,255,255,0.08); font-size: 0.9rem; }
.alerts li em { color: var(--muted); font-size: 0.8rem; }
.alerts li button, .alerts h2 button { margin-left: 0.6rem; padding: 0.15rem 0.6rem; border: 1px solid var(--border); border-radius: 4px; background: var(--panel); color: var(--text); cursor: pointer; }
.alert-type { font-weight: 700; margin-right: 0.4rem; }
.alert-motion { color: var(--low); }
.alert-battery_low, .alert-battery_crit { color: var(--mid); }
.alert-silence { color: #f97316; }

#osm-map { position: relative; height: 500px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
#osm-map canvas { display: block; cursor: grab; }
#osm-map canvas:active { cursor: grabbing; }
.osm-zoom { position: absolute; top: 10px; left: 10px; display: flex; flex-direction: column; gap: 4px; }
.osm-zoom button { width: 34px; height: 34px; font-size: 1.2rem; border: 1px solid var(--border); border-radius: 4px; background: var(--panel); color: var(--text); cursor: pointer; }
.hidden { display: none; }

/* --- Réglages --- */
.setting { margin: 1.1rem 0; }
.setting label { display: flex; justify-content: space-between; color: var(--text); font-size: 0.95rem; margin-bottom: 0.3rem; }
.setting .val { color: #60a5fa; font-weight: 600; }
.setting input[type=range] { width: 100%; accent-color: #2563eb; height: 28px; }
.setting .hint { margin: 0.25rem 0 0; }
.top-nav { display: flex; gap: 1rem; align-items: center; }
nav a { font-size: 0.9rem; }
code { background: var(--bg); padding: 0.1rem 0.35rem; border-radius: 3px; font-size: 0.85em; }

/* --- Mobile (WebView S23 et petits écrans) --- */
@media (max-width: 640px) {
  header, .panel { padding: 0.8rem 0.9rem; }
  header h1 { font-size: 1.15rem; }
  .stats { flex-wrap: wrap; gap: 1rem 1.6rem; }
  .stat-value { font-size: 1.15rem; }
  #osm-map, #map { height: 42vh; }
  table { font-size: 0.75rem; }
  th, td { padding: 0.35rem 0.4rem; }
  /* colonnes lat/lon masquées sur mobile : illisibles et redondantes avec la carte */
  table th:nth-child(2), table td:nth-child(2),
  table th:nth-child(3), table td:nth-child(3) { display: none; }
  .alerts li button, .alerts h2 button { padding: 0.4rem 0.9rem; }  /* cibles tactiles */
  .osm-zoom button { width: 42px; height: 42px; }
}

/* Suivi et historique */
#d-map { position: relative; height: 420px; border: 1px solid var(--border);
         border-radius: 6px; overflow: hidden; margin-bottom: 1rem; }
#d-map canvas { display: block; cursor: grab; }
h3 { font-size: 1rem; color: var(--muted); margin: 1.2rem 0 0.4rem; }
tbody tr:hover { background: rgba(96,165,250,0.07); }
#close-detail { float: right; padding: 0.2rem 0.7rem; border: 1px solid var(--border);
                border-radius: 4px; background: var(--panel); color: var(--text);
                cursor: pointer; font-size: 0.8rem; }