/* Alpi — application (même palette que Wiski.pro) */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #0a0e18;
  --surface: #131a2e;
  --surface-2: #1a2340;
  --text: #eef1f8;
  --text-muted: #aab4d0;
  --primary: #4fb0ff;
  --primary-2: #7c5cff;
  --success: #37d399;
  --warn: #ffb547;
  --danger: #ff4d6d;
  --border: rgba(255,255,255,0.1);
  --border-strong: rgba(255,255,255,0.16);
  --radius: 18px;
  --tabbar-h: 64px;
  --topbar-h: 56px;
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
h1, h2, h3, b, strong { font-family: 'Poppins', 'Inter', sans-serif; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
a { color: var(--primary); }
.hidden { display: none !important; }
.icon { width: 1em; height: 1em; flex-shrink: 0; }

/* Top bar */
.topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 50;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(10,14,24,0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-family: 'Poppins', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  font-weight: 800;
  font-size: 0.95rem;
  color: #fff;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 100px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.chip.good .dot { background: var(--success); }
.chip.mid .dot { background: var(--warn); }
.chip.bad .dot { background: var(--danger); }
.chip.searching .dot { animation: blink 1s ease-in-out infinite; background: var(--warn); }
@keyframes blink { 50% { opacity: 0.2; } }

/* Views */
.views {
  position: fixed;
  inset: calc(var(--topbar-h) + var(--safe-top)) 0 calc(var(--tabbar-h) + var(--safe-bottom));
}
.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px 28px;
  display: none;
}
.view.active { display: block; animation: viewIn 0.25s ease; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } }
.view > * { max-width: 640px; margin-left: auto; margin-right: auto; }
.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.view-head h1 { font-size: 1.5rem; }
.block-title { font-size: 1rem; margin: 22px auto 10px; color: var(--text-muted); font-weight: 600; }

/* Live */
#view-live.active { display: flex; flex-direction: column; }
.live-head { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.state-chip {
  padding: 5px 14px;
  border-radius: 100px;
  background: rgba(79,176,255,0.14);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.state-chip.down { background: rgba(124,92,255,0.18); color: #b3a2ff; }
.state-chip.up { background: rgba(255,181,71,0.14); color: var(--warn); }
.state-chip.rec::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--danger);
  vertical-align: 1px;
  animation: blink 1.4s ease-in-out infinite;
}
.live-timer { font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.speedo {
  text-align: center;
  margin: clamp(12px, 5vh, 40px) auto clamp(10px, 4vh, 32px);
  line-height: 1;
}
.speedo strong {
  display: block;
  font-size: clamp(5rem, 28vw, 8.5rem);
  font-weight: 800;
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(135deg, #fff 30%, var(--primary));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.speedo span { color: var(--text-muted); font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; font-size: 0.85rem; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
}
.stat {
  padding: 12px 8px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
  min-width: 0;
}
.stat b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stat small { margin-left: 3px; color: var(--text-muted); font-size: 0.72rem; font-weight: 600; }
.stat em { display: block; font-style: normal; color: var(--text-muted); font-size: 0.72rem; margin-top: 2px; }

.live-hint { color: var(--text-muted); text-align: center; font-size: 0.85rem; margin: 16px auto 0; min-height: 2.6em; }
.live-controls {
  margin-top: auto;
  padding-top: 18px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 22px;
}
.round-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  transition: transform 0.15s ease;
}
.round-btn:active { transform: scale(0.93); }
.round-btn.primary {
  width: 88px;
  height: 88px;
  font-size: 2rem;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 14px 34px rgba(79,176,255,0.35);
}
.round-btn.secondary { background: var(--surface-2); border: 1px solid var(--border-strong); }
.round-btn.danger { background: rgba(255,77,109,0.15); color: var(--danger); border: 1px solid rgba(255,77,109,0.35); }

/* Maps */
.map { width: 100%; height: 100%; background: #1a2340; }
#view-map { padding: 0; }
#view-map > * { max-width: none; }
.map-wrap { position: absolute; inset: 0; }
.map-overlay {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 24px;
  z-index: 500;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}
.map-overlay > * { pointer-events: auto; }
.map-pill, .map-btn {
  background: rgba(10,14,24,0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-strong);
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.map-pill { padding: 8px 16px; border-radius: 100px; }
.map-pill b { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.map-pill span { color: var(--text-muted); font-size: 0.8rem; }
.map-btn { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 1.3rem; }
.map-btn.on { color: var(--primary); }
.map-card { height: 260px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); margin-bottom: 12px; }
.leaflet-container { font-family: 'Inter', sans-serif; }
.leaflet-control-attribution { font-size: 9px; }
.pos-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(79,176,255,0.3), 0 2px 8px rgba(0,0,0,0.5);
}

/* History */
.session-list { display: grid; gap: 10px; }
.session-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color 0.2s ease, transform 0.15s ease;
}
.session-card:active { transform: scale(0.98); }
.session-card:hover { border-color: var(--border-strong); }
.session-card h3 { font-size: 1rem; }
.session-card time { color: var(--text-muted); font-size: 0.8rem; }
.session-card .row { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: 0.85rem; }
.session-card .row span { color: var(--text-muted); }
.session-card .row b { color: var(--text); font-family: 'Inter', sans-serif; font-weight: 600; }
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.empty .icon { font-size: 2rem; color: var(--primary); margin-bottom: 8px; }
.text-btn { color: var(--primary); font-weight: 600; font-size: 0.9rem; cursor: pointer; }

/* Detail */
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem; background: var(--surface); border: 1px solid var(--border); flex-shrink: 0; }
.title-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  border-bottom: 1px dashed transparent;
  font-family: 'Poppins', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  padding: 2px 0;
}
.title-input:focus { outline: none; border-bottom-color: var(--primary); }
.detail-date { color: var(--text-muted); font-size: 0.85rem; margin: -8px auto 12px; }
.chart-card { margin-top: 12px; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.chart-head h3 { font-size: 0.95rem; }
.chart-head span { color: var(--text-muted); font-size: 0.78rem; }
.chart-card canvas { width: 100%; height: 130px; display: block; }
.run-list, .record-list { display: grid; gap: 8px; }
.run {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.run.active { border-color: var(--primary); }
.run-num {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-family: 'Poppins', sans-serif;
  font-weight: 700;
  color: #fff;
}
.run-main b { font-size: 0.95rem; display: block; }
.run-main span, .run-side { color: var(--text-muted); font-size: 0.78rem; }
.run-side { text-align: right; }
.run-side b { display: block; color: var(--text); font-size: 0.95rem; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.btn {
  flex: 1;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  font-weight: 600;
  white-space: nowrap;
}
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); border: 0; color: #fff; }
.btn-danger { color: var(--danger); border-color: rgba(255,77,109,0.35); background: rgba(255,77,109,0.1); }

/* Records */
.record { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.record .ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: rgba(79,176,255,0.14); color: var(--primary); font-size: 1.15rem; flex-shrink: 0; }
.record div { flex: 1; min-width: 0; }
.record small { display: block; color: var(--text-muted); font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.record strong { font-size: 1.05rem; }

/* Settings */
.settings { border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); overflow: hidden; }
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.setting:last-child { border-bottom: 0; }
.setting b { display: block; font-size: 0.95rem; font-weight: 600; }
.setting small { color: var(--text-muted); font-size: 0.78rem; }
.setting.danger b { color: var(--danger); }
.setting select {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 7px 10px;
  max-width: 50%;
}
.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 48px;
  height: 28px;
  border-radius: 100px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  position: relative;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.2s ease;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
}
.switch:checked { background: var(--primary); border-color: var(--primary); }
.switch:checked::after { transform: translateX(20px); }
.about-app { text-align: center; color: var(--text-muted); font-size: 0.78rem; margin-top: 24px; }

/* Tab bar */
.tabbar {
  position: fixed;
  inset: auto 0 0;
  z-index: 50;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0 6px var(--safe-bottom);
  display: flex;
  background: rgba(10,14,24,0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: color 0.2s ease;
}
.tab .icon { font-size: 1.35rem; }
.tab.active { color: var(--primary); }
.tab.rec-dot { position: relative; }
.tab.rec-dot::after {
  content: '';
  position: absolute;
  top: 10px;
  left: calc(50% + 10px);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

/* Modal + toast */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-card {
  width: 100%;
  max-width: 380px;
  padding: 22px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
}
.modal-card h2 { font-size: 1.2rem; margin-bottom: 6px; }
.modal-card p { color: var(--text-muted); font-size: 0.9rem; }
.modal-actions { display: grid; gap: 8px; margin-top: 18px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
  z-index: 1100;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  padding: 10px 18px;
  border-radius: 100px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Install (hors connexion) */
.install-fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
  z-index: 900;
  display: none;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 32px);
  padding: 12px 14px 12px 16px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  font-family: 'Poppins', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: left;
  box-shadow: 0 12px 30px rgba(0,0,0,0.45), 0 0 0 6px rgba(79,176,255,0.16);
  animation: installFloat 3.2s ease-in-out infinite;
}
.install-fab.visible { display: flex; }
body.map-open .install-fab { bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 84px); }
/* Leaves room for the button so it never covers the controls */
body.has-fab .view { padding-bottom: 90px; }
body.has-fab #view-map { padding-bottom: 0; }
.install-fab-icon { font-size: 1rem; line-height: 1; }
.install-fab-close {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  margin-left: 2px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  font-size: 0.75rem;
  line-height: 1;
}
.install-fab-close:hover { background: rgba(255,255,255,0.3); }
@keyframes installFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}
@media (prefers-reduced-motion: reduce) {
  .install-fab { animation: none; }
}
.install-help {
  position: fixed;
  inset: 0;
  z-index: 1050;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  background: rgba(0,0,0,0.6);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.install-help.visible { opacity: 1; visibility: visible; }
.install-help-card {
  width: 100%;
  max-width: 420px;
  padding: 22px 20px 18px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
}
.install-help-card h3 { font-size: 1.1rem; margin-bottom: 8px; }
.install-help-card p, .install-help-card li { color: var(--text-muted); font-size: 0.88rem; }
.install-help-card ol { margin: 12px 0 16px 20px; display: grid; gap: 6px; }
.install-help-card strong { color: var(--text); font-family: 'Inter', sans-serif; }
.install-help-ok { width: 100%; }
.install-help-ok + .install-help-ok { margin-top: 8px; }

@media (min-width: 900px) {
  .stat b { font-size: 1.5rem; }
  .map-card { height: 360px; }
}
@media (max-height: 640px) {
  .speedo strong { font-size: 4.5rem; }
  .stat { padding: 8px 6px; }
  .round-btn.primary { width: 72px; height: 72px; }
}
