:root {
  --color-primary:    #0D9488;
  --color-primary-lt: #CCFBF1;
  --color-bg:         #F8FAFC;
  --color-surface:    #ffffff;
  --color-surface2:   #F1F5F9;
  --color-text:       #0F172A;
  --color-muted:      #64748B;
  --color-border:     #CBD5E1;
  --color-error:      #c62828;
  --color-live:       #F43F5E;
  --radius:           12px;
  --shadow:           0 1px 3px rgba(0,0,0,.10), 0 4px 16px rgba(0,0,0,.12);
}

/* ── Mode sombre ── */
html.dark {
  --color-primary:    #2DD4BF;
  --color-primary-lt: #0D9488;
  --color-bg:         #0F172A;
  --color-surface:    #1e293b;
  --color-surface2:   #334155;
  --color-text:       #F1F5F9;
  --color-muted:      #94A3B8;
  --color-border:     #334155;
  --color-error:      #ef5350;
  --color-live:       #FB7185;
  --shadow:           0 2px 8px rgba(0,0,0,.4);
}

/* Suit le système si aucune préférence n'est enregistrée */
@media (prefers-color-scheme: dark) {
  html:not(.light) {
    --color-primary:    #2DD4BF;
    --color-primary-lt: #0D9488;
    --color-bg:         #0F172A;
    --color-surface:    #1e293b;
    --color-surface2:   #334155;
    --color-text:       #F1F5F9;
    --color-muted:      #94A3B8;
    --color-border:     #334155;
    --color-error:      #ef5350;
    --color-live:       #FB7185;
    --shadow:           0 2px 8px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
}

/* ── Map full screen ── */
#map {
  position: fixed;
  inset: 0;
  z-index: 0;
}

/* Décale les contrôles Leaflet du haut sous l'en-tête fixe */
.leaflet-top {
  margin-top: 60px;
}

/* ── Header overlay ── */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  background: var(--color-surface);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.header h1 {
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Status badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-live   { background: color-mix(in srgb, var(--color-live) 15%, var(--color-surface)); color: var(--color-live); }
.badge-done   { background: color-mix(in srgb, var(--color-primary) 15%, var(--color-surface)); color: var(--color-primary); }
.badge-draft  { background: var(--color-surface2); color: var(--color-muted); }

.badge-live::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--color-live);
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .5; transform: scale(1.4); }
}

/* ── Info panel (bottom) ── */
.info-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 1000;
  background: var(--color-surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -2px 12px rgba(0,0,0,.12);
  padding: 16px;
  max-height: 50vh;
  overflow-y: auto;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.stat-card {
  background: var(--color-bg);
  border-radius: var(--radius);
  padding: 10px;
  text-align: center;
}
.stat-card .value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-primary);
}
.stat-card .label {
  font-size: 0.72rem;
  color: var(--color-muted);
  margin-top: 2px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 80px; left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 2000;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ── Layer switcher ── */
.layer-btn {
  position: fixed;
  top: 70px; right: 12px;
  z-index: 1000;
  background: var(--color-surface);
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-primary);
}

/* ════════════════════════════════════════════════════════════════
   NAV COMMUNE (header + barre d'onglets)
   ════════════════════════════════════════════════════════════════ */

#app-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  height: 52px;
  background: var(--color-surface);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.nav-logo {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-primary);
  text-decoration: none;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-actions { display: flex; align-items: center; gap: 8px; }

.nav-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
}

.nav-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: .85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Menu déroulant ── */
.user-menu-wrap { position: relative; }

.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 210px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  z-index: 500;
  overflow: hidden;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  font-size: .9rem;
  color: var(--color-text);
  text-decoration: none;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background .12s;
}
.menu-item:hover { background: var(--color-surface2); }

.menu-toggle { cursor: pointer; justify-content: space-between; }

/* Toggle switch */
.toggle-switch {
  width: 38px; height: 22px;
  border-radius: 999px;
  background: var(--color-border);
  position: relative;
  flex-shrink: 0;
  transition: background .2s;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
}
.toggle-switch.on { background: var(--color-primary); }
.toggle-switch.on::after { transform: translateX(16px); }

.menu-divider { border: none; border-top: 1px solid var(--color-border); margin: 4px 0; }
.menu-logout { color: var(--color-error); }
.menu-logout:hover { background: color-mix(in srgb, var(--color-error) 8%, var(--color-surface)); }

/* ── Barre d'onglets ── */
#tab-bar {
  position: fixed;
  top: 52px; left: 0; right: 0;
  z-index: 190;
  height: 44px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
}
#tab-bar::-webkit-scrollbar { display: none; }

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 80px;
  padding: 0 12px;
  font-size: .82rem;
  font-weight: 500;
  color: var(--color-muted);
  text-decoration: none;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--color-primary); }
.tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 700; }

.tab-icon { font-size: 1rem; }
.tab-label { }

/* ── Card list (index) ── */
.page { max-width: 640px; margin: 0 auto; padding: 16px; }

/* ── Décalage du contenu sous header + tabs ── */
/* Sélecteur combiné (.page.app-content) pour surcharger padding: 16px de .page */
.page.app-content {
  padding-top: calc(52px + 44px + 16px);
  padding-bottom: 24px;
}
.page-header { padding: 16px 0 8px; display: flex; justify-content: space-between; align-items: center; }
.page-header h1 { font-size: 1.3rem; }

.hike-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-border);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: box-shadow .2s, border-color .2s;
  text-decoration: none;
  color: inherit;
  display: block;
}
.hike-card:hover { box-shadow: 0 6px 20px rgba(0,0,0,.14); }
.hike-card.status-active    { border-left-color: var(--color-live); }
.hike-card.status-completed { border-left-color: var(--color-primary); }
.hike-card.status-draft     { border-left-color: var(--color-muted); }
.hike-card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 4px; }
.hike-card .meta { font-size: 0.8rem; color: var(--color-muted); }
.copy-link-btn {
  background: none; border: 1px solid var(--color-border); border-radius: 6px;
  padding: 2px 6px; font-size: .85rem; cursor: pointer; line-height: 1.4;
  color: var(--color-muted); transition: background .15s, color .15s;
}
.copy-link-btn:hover, .copy-link-btn.copied { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: opacity .2s;
}
.btn:hover { opacity: .85; }
.btn-primary  { background: var(--color-primary);    color: #fff; border-radius: 999px; }
.btn-outline  { background: transparent; border: 2px solid var(--color-primary); color: var(--color-primary); border-radius: 999px; }
.btn-danger   { background: var(--color-error);      color: #fff; }

/* ── Login ── */
.login-box {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  max-width: 360px;
  margin: 80px auto 0;
}
.login-box h1 { font-size: 1.4rem; margin-bottom: 24px; text-align: center; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.85rem; margin-bottom: 4px; color: var(--color-muted); }
.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  outline: none;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color .2s;
}
.field input:focus { border-color: var(--color-primary); }
.error-msg { color: var(--color-error); font-size: 0.85rem; margin-top: 8px; }

/* ── Spinner ── */
.spinner {
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  width: 36px; height: 36px;
  animation: spin .7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }