/* Gravité : styles de base et composants partagés. Mobile d'abord, thème sombre. */

:root {
  color-scheme: dark;
  --bg: #0f1114;
  --surface: #171a1f;
  --surface-2: #1f232a;
  --surface-3: #282d35;
  --line: #2b3038;
  --text: #f2f4f7;
  --muted: #9aa3ae;
  --faint: #6b7480;
  --accent: #ff6b4a;
  --accent-2: #ff8e6e;
  --accent-soft: rgba(255, 107, 74, 0.14);
  --ok: #3ddc97;
  --ok-soft: rgba(61, 220, 151, 0.14);
  --warn: #ffc857;
  --warn-soft: rgba(255, 200, 87, 0.14);
  --danger: #ff4d5e;
  --danger-soft: rgba(255, 77, 94, 0.14);
  --level-1: var(--ok);
  --level-2: var(--warn);
  --level-3: var(--accent);
  --radius: 18px;
  --radius-sm: 12px;
  --gap: 16px;
  --tabbar-h: 64px;
  --topbar-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
img, svg { display: block; }
.icon { display: inline-flex; align-items: center; justify-content: center; flex: none; }

/* ───────── Coquille ───────── */

#app { min-height: 100dvh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 8px 0 16px;
  background: rgba(15, 17, 20, 0.88);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  backdrop-filter: saturate(160%) blur(16px);
  border-bottom: 1px solid transparent;
}
.topbar-title { flex: 1; font-size: 17px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-flex { flex: 1; }
.brand { display: flex; align-items: center; gap: 10px; flex: 1; }
.brand-name { font-family: var(--font-display); font-weight: 750; font-size: 20px; letter-spacing: -0.02em; }

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(19, 21, 25, 0.94);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--faint);
  touch-action: manipulation;
}
.tab.active { color: var(--accent); }

body.is-fullscreen .topbar,
body.is-fullscreen .tabbar { display: none; }
body.is-fullscreen .view { max-width: none; padding: 0; }

/* Écran large (PC) : contenu centré, barre d'onglets compacte. */
@media (min-width: 900px) {
  .view { max-width: 720px; padding-top: 16px; }
  .tabbar { justify-content: center; }
  .tab { flex: 0 0 120px; }
}

/* ───────── Boutons ───────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 14px;
  font-weight: 650;
  font-size: 16px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn-primary { background: var(--accent); color: #1a0d08; }
.btn-primary:active { background: var(--accent-2); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-ok { background: var(--ok); color: #062015; }
.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 58px; font-size: 18px; border-radius: 16px; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 14px; border-radius: 10px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn-spacer { width: 44px; height: 44px; flex: none; }

/* ───────── Cartes et listes ───────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.card-hero {
  background: linear-gradient(145deg, #2a1712 0%, #1b1513 45%, var(--surface) 100%);
  border-color: rgba(255, 107, 74, 0.28);
}
.card-link { display: block; cursor: pointer; }
.card-link:active { background: var(--surface-2); }

.section { margin-top: 24px; }
.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.section-title a, .section-title button { text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: 0; }
a.list-item:active, button.list-item:active { background: var(--surface-2); }
button.list-item { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.list-item .sub { font-size: 14px; color: var(--muted); }
.list-item .chev { color: var(--faint); }

.row { display: flex; align-items: center; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack > * + * { margin-top: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grow { flex: 1; min-width: 0; }

/* ───────── Texte ───────── */

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
.strong { font-weight: 700; }
.accent { color: var(--accent); }
.ok { color: var(--ok); }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

.page-title { font-size: 28px; font-weight: 780; letter-spacing: -0.02em; margin: 8px 0 4px; }
.page-sub { color: var(--muted); margin-bottom: 16px; }

/* ───────── Statistiques ───────── */

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; }
.stat-value { font-family: var(--font-display); font-size: 26px; font-weight: 760; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ───────── Badges et puces ───────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-3);
  color: var(--muted);
  white-space: nowrap;
}
.badge.level-1 { background: var(--ok-soft); color: var(--level-1); }
.badge.level-2 { background: var(--warn-soft); color: var(--level-2); }
.badge.level-3 { background: var(--accent-soft); color: var(--level-3); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ───────── Formulaires ───────── */

.input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* évite le zoom automatique sur iPhone */
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.search { position: relative; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search .input { padding-left: 42px; }

.toggle { position: relative; width: 52px; height: 32px; flex: none; }
.toggle input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.toggle span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); transition: background 0.2s; }
.toggle span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.toggle input:checked + span { background: var(--ok); }
.toggle input:checked + span::after { transform: translateX(20px); }

.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.segmented button { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 650; font-size: 14px; cursor: pointer; touch-action: manipulation; }
.segmented button.active { background: var(--surface-3); color: var(--text); }

/* ───────── Barre de progression ───────── */

.progress { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width 0.3s ease; }
.progress.ok > span { background: var(--ok); }

/* ───────── États vides ───────── */

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .icon { margin: 0 auto 12px; color: var(--faint); }
.empty p + .btn, .empty p + a.btn { margin-top: 16px; }

/* ───────── Toast et dialogues ───────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  z-index: 100;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--surface-3);
  color: var(--text);
  font-weight: 600;
  font-size: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: #14382a; color: var(--ok); }
.toast.error { background: #3a1419; color: #ff8a95; }
body.is-fullscreen .toast { bottom: calc(var(--safe-bottom) + 24px); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  background: rgba(0, 0, 0, 0.6);
  animation: fade 0.15s ease;
}
.dialog {
  width: 100%;
  max-width: 420px;
  padding: 22px 20px 16px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  animation: rise 0.2s ease;
}
.dialog h3 { margin-bottom: 8px; }
.dialog p { margin-bottom: 16px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.dialog-actions .btn { flex: 1; }
.dialog-stack { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
@media (min-width: 600px) { .overlay { align-items: center; } }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

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

/* Focus clavier visible (PC). */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
