:root {
  --bg:       #f2efe8;
  --surface:  #fafaf6;
  --ink:      #1c1c1a;
  --muted:    #888070;
  --border:   #dbd6c8;
  --green:    #2a5c24;
  --green-lt: #4a8c42;
  --danger:   #b83232;
  --warn:     #a05c00;
  --mono:     'DM Mono', monospace;
  --sans:     'DM Sans', sans-serif;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans, sans-serif), serif;
  font-weight: 300;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
}

/* ── Topbar ── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.8rem;
  background: rgba(242,239,232,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}
.topbar-brand {
  font-family: var(--mono, monospace), serif;
  font-size: .78rem;
  font-weight: 500;
  letter-spacing: .06em;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.pulse {
  width: 8px; height: 8px;
  background: var(--green);
  border-radius: 50%;
  animation: blink 2s ease infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

.btn-sm {
  font-family: var(--mono, monospace), serif;
  font-size: .68rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: .28rem .65rem;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
}
.btn-sm:hover { color: var(--ink); border-color: var(--ink); }

/* ── Wrapper ── */
#mainContent { width: 100%; }
.wrap--auth { margin-top: 52px; padding-top: 2rem; }
.wrap {
  position: relative;
  z-index: 1;
  width: min(460px, 100%);
  margin: 0 auto;
  animation: up .4s ease both;
}
@keyframes up {
  from { opacity:0; transform:translateY(14px); }
  to   { opacity:1; transform:translateY(0); }
}

/* ── Card générique ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  box-shadow: 0 1px 0 var(--border), 0 6px 24px rgba(0,0,0,.07);
}

/* ── Login ── */
.login-label {
  font-family: var(--mono, monospace), serif;
  font-size: .65rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  margin-bottom: 1.8rem;
}
.login-inner { padding: 2.6rem 2.4rem; }
.card-h   { font-size: 1.35rem; font-weight: 600; margin-bottom: .3rem; }
.card-sub { font-size: .83rem; color: var(--muted); margin-bottom: 2rem; }

.field { display: flex; flex-direction: column; gap: .45rem; margin-bottom: 1.1rem; }
.field label {
  font-family: var(--mono, monospace), serif;
  font-size: .65rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: .7rem .95rem;
  font-family: var(--mono, monospace), serif;
  font-size: .92rem;
  color: var(--ink);
  outline: none;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(42,92,36,.1);
}
.alert-err {
  font-family: var(--mono, monospace), serif;
  font-size: .75rem;
  color: var(--danger);
  background: rgba(184,50,50,.07);
  border: 1px solid rgba(184,50,50,.18);
  border-radius: 3px;
  padding: .5rem .85rem;
  margin-bottom: 1rem;
}
.btn-main {
  width: 100%;
  padding: .8rem;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 3px;
  font-family: var(--mono, monospace), serif;
  font-size: .8rem;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn-main:hover  { background: var(--green-lt); }
.btn-main:active { transform: scale(.98); }

/* ── Contenu ── */
.eyebrow {
  font-family: var(--mono, monospace), serif;
  font-size: .65rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1.6rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.act-head {
  padding: 1.8rem 2rem 1.4rem;
  border-bottom: 1px solid var(--border);
}
.act-kicker {
  font-family: var(--mono, monospace), serif;
  font-size: .62rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .5rem;
}
.act-title {
  font-size: 1.3rem;
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: .3rem;
}
.act-meta {
  font-family: var(--mono, monospace), serif;
  font-size: .68rem;
  color: var(--muted);
}

.act-link {
  padding: 1.3rem 2rem;
  border-bottom: 1px solid var(--border);
}
.link-pill {
  display: flex;
  align-items: center;
  gap: .7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: .7rem .9rem;
}
.link-pill-icon {
  flex-shrink: 0;
  width: 28px; height: 28px;
  background: rgba(42,92,36,.1);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
}
.link-pill-icon svg { width: 14px; height: 14px; stroke: var(--green); fill: none; stroke-width: 2; }
.link-pill-url {
  flex: 1;
  font-family: var(--mono, monospace), serif;
  font-size: .7rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.act-actions {
  padding: 1.2rem 2rem;
  display: flex;
  gap: .7rem;
}
.btn-open {
  flex: 1;
  padding: .75rem;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 3px;
  font-family: var(--mono, monospace), serif;
  font-size: .75rem;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  transition: background .15s;
}
.btn-open:hover { background: var(--green-lt); }
.btn-copy {
  padding: .75rem 1rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--mono, monospace), serif;
  font-size: .75rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn-copy:hover { border-color: var(--ink); }
.btn-copy.ok    { color: var(--green); border-color: var(--green-lt); }

/* ── Vide / erreur ── */
.state-box {
  padding: 2.8rem 2rem;
  text-align: center;
}
.state-ico { font-size: 2rem; opacity: .25; margin-bottom: .9rem; }
.state-t   {
  font-family: var(--mono, monospace), serif; font-size: .82rem; color: var(--muted); margin-bottom: .35rem; }
.state-s   { font-size: .75rem; color: var(--muted); opacity: .65; }
.state-box.warn .state-t { color: var(--warn); opacity: 1; }

/* ── Stack de cartes ── */
.stack {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

/* ── Statusline ── */
.statusline {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
  font-family: var(--mono, monospace), serif;
  font-size: .62rem;
  color: var(--muted);
}
.reload-btn {
  background: none;
  border: none;
  font-family: var(--mono, monospace), serif;
  font-size: .62rem;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}
.reload-btn:hover { color: var(--ink); }

/* ── Topbar actions ── */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: .6rem;
}
.topbar-actions form { display: contents; }

/* ── Map view ── */
.map-view {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
}
.map-topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.8rem;
  background: rgba(242,239,232,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 1;
}
#liveMap { flex: 1; min-height: 0; }

/* ── Marqueur athlète ── */
.athlete-icon { background: transparent !important; border: none !important; }
.ai-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateX(-50%);
}
.ai-dot {
  width: 18px; height: 18px;
  background: var(--green);
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,.4);
}
.ai-name {
  font-family: var(--mono, monospace), serif;
  font-size: .72rem;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 7px;
  white-space: nowrap;
  margin-top: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.stale .ai-dot {
  background: var(--muted);
  box-shadow: none;
}
.stale .ai-name { color: var(--muted); }

/* ── Popup métriques ── */
.lp-name {
  font-family: var(--mono, monospace), serif;
  font-size: .8rem;
  font-weight: 600;
  margin-bottom: .55rem;
}
.lp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .4rem .8rem;
  margin-bottom: .5rem;
}
.lp-grid > div { display: flex; flex-direction: column; }
.lp-val {
  font-family: var(--mono, monospace), serif;
  font-size: .78rem;
  font-weight: 500;
}
.lp-lbl {
  font-size: .58rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .07em;
}
.lp-time {
  font-family: var(--mono, monospace), serif;
  font-size: .58rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: .35rem;
}
.lp-status {
  font-size: .58rem;
  font-weight: 500;
  margin-top: .3rem;
}
.lp-status.live  { color: var(--green); }
.lp-status.stale { color: var(--muted); }

/* ── Desktop layout ── */
@media (min-width: 820px) {
  .wrap { width: min(960px, 100%); }
  .stack {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  }
}

/* ── Dark mode ── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #1a1715;
    --surface:  #252220;
    --ink:      #f5f2ed;
    --muted:    #a09a8f;
    --border:   #3a3330;
  }
  .topbar, .map-topbar {
    background: rgba(26,23,21,.92);
  }
  .card {
    box-shadow: 0 1px 0 var(--border), 0 6px 24px rgba(0,0,0,.3);
  }
  .leaflet-popup-content-wrapper,
  .leaflet-popup-tip {
    background: var(--surface);
    color: var(--ink);
  }
  .leaflet-popup-content-wrapper {
    border: 1px solid var(--border);
    box-shadow: 0 3px 14px rgba(0,0,0,.5);
  }
  .ai-name {
    color: var(--ink);
  }
}

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