/* Socle : fond, barre latérale repliable, en-tête, barre d'onglets mobile, zone de contenu. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: var(--t-base); line-height: 1.5;
  -webkit-font-smoothing: antialiased; font-feature-settings: "cv11", "ss01";
  transition: background var(--dur), color var(--dur);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -0.015em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { flex: none; }

/* ---------- Fond : lueurs douces + trame de points ---------- */
.aurora { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
  background:
    radial-gradient(55% 45% at 15% 0%, var(--glow-1), transparent 70%),
    radial-gradient(40% 35% at 95% 8%, var(--glow-2), transparent 70%),
    radial-gradient(45% 40% at 60% 100%, var(--glow-3), transparent 70%),
    var(--bg);
}
.aurora::after {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(var(--dots) 1px, transparent 1px); background-size: 22px 22px;
  mask-image: radial-gradient(85% 75% at 50% 15%, #000 30%, transparent 100%);
}
.aurora__blob { position: absolute; border-radius: 50%; filter: blur(90px); opacity: var(--blob-opacity); will-change: transform; }
.aurora__blob--a { width: 40vmax; height: 40vmax; left: -12vmax; top: -16vmax; background: var(--blob-a); animation: drift-a 30s ease-in-out infinite alternate; }
.aurora__blob--b { width: 28vmax; height: 28vmax; right: -10vmax; top: 4vmax; background: var(--blob-b); opacity: calc(var(--blob-opacity) * 0.7); animation: drift-b 36s ease-in-out infinite alternate; }
.aurora__blob--c { width: 26vmax; height: 26vmax; left: 40vw; bottom: -16vmax; background: var(--blob-c); opacity: calc(var(--blob-opacity) * 0.7); animation: drift-c 40s ease-in-out infinite alternate; }
@keyframes drift-a { to { transform: translate3d(6vw, 4vh, 0) scale(1.06); } }
@keyframes drift-b { to { transform: translate3d(-5vw, 8vh, 0) scale(0.94); } }
@keyframes drift-c { to { transform: translate3d(-8vw, -6vh, 0) scale(1.1); } }

/* ---------- Mise en page ---------- */
#app { position: relative; z-index: 1; }
.layout { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100dvh; transition: grid-template-columns var(--dur) var(--ease); }
.layout.is-collapsed { --sidebar: 78px; }
.tabbar { display: none; }

/* ---------- Barre latérale « widget » ---------- */
.side {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-3); overflow: hidden;
  background: var(--panel); border-right: 1px solid var(--line);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
}
.side__top { display: flex; align-items: center; gap: var(--sp-2); }
/* Lockup Carbone (brand.css) puis l'espace dessous, aligné sur le nom. */
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; min-width: 0; flex: 1; padding: 6px 4px; border-radius: var(--r-sm); }
.brand:hover { background: var(--hover); }
.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Barre latérale : marque agrandie (≈ 2 × la hauteur des capitales) pour que l'étoile animée se voie. */
.brand .cb-lockup { gap: 7px; }
.brand .cb-mark { width: 34px; height: 34px; }
/* Retrait = marque (34 px) + écart (7 px) ; remonté pour se ranger sous le nom, à côté de la marque. */
.brand__txt { display: block; min-width: 0; margin-top: -11px; padding-left: 41px; color: var(--muted); font-size: var(--t-xs); line-height: 1.3; white-space: nowrap; }
.side__toggle { flex: none; }

.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; overflow-x: hidden; }
.nav::-webkit-scrollbar { width: 0; }
.nav__label { margin: var(--sp-3) 0 4px; padding: 0 10px; color: var(--faint); font-size: var(--t-2xs); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; }
.nav__label:first-child { margin-top: 0; }
.nav__link {
  position: relative; display: flex; align-items: center; gap: 11px; height: 38px; padding: 0 10px; border-radius: var(--r-sm);
  color: var(--ink-2); font-size: var(--t-base); font-weight: 500; white-space: nowrap;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.nav__link svg { width: 18px; height: 18px; flex: none; color: var(--muted); }
.nav__txt { min-width: 0; overflow: hidden; }
.nav__link:hover { background: var(--hover); color: var(--ink); }
.nav__link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.nav__link[aria-current="page"] svg { color: var(--accent); }
.nav__link[aria-current="page"]::before { content: ""; position: absolute; left: 0; top: 50%; translate: 0 -50%; width: 3px; height: 18px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav__count { margin-left: auto; padding: 1px 7px; border-radius: var(--r-pill); background: var(--accent-soft); color: var(--accent-ink); font-size: var(--t-2xs); font-style: normal; font-weight: 700; }

.side__foot { margin-top: auto; display: flex; align-items: center; gap: var(--sp-2); }
.user { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--card); text-align: left; transition: background var(--dur-fast), border-color var(--dur-fast); }
.user:hover, .user.is-active { background: var(--card-hover); border-color: var(--line-strong); }
.user__avatar { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--avatar-bg); color: var(--avatar-ink); font-size: var(--t-2xs); font-weight: 700; }
.user__who { min-width: 0; flex: 1; line-height: 1.3; }
.user__who strong { display: block; overflow: hidden; font-size: var(--t-sm); text-overflow: ellipsis; white-space: nowrap; }
.user__who span { display: block; overflow: hidden; color: var(--muted); font-size: var(--t-xs); text-overflow: ellipsis; white-space: nowrap; }
.user__gear { color: var(--muted); }
.user__gear svg { width: 16px; height: 16px; }

.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: var(--r-sm); border: 1px solid transparent;
  background: transparent; color: var(--muted); transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.icon-btn:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
.icon-btn:disabled { opacity: 0.35; }
.icon-btn--framed { border-color: var(--line-strong); background: var(--card); }
.icon-btn svg { width: 16px; height: 16px; }
.header__toggle { display: none; }
.side__theme, .drawer-scrim { display: none; }

/* --- Barre repliée : icônes seules, centrées --- */
.is-collapsed .brand { align-items: center; padding: 4px 0; }
/* Barre repliée : la marque seule, agrandie (≈ 30 px). */
.is-collapsed .brand .cb-word { display: none; }
.is-collapsed .brand .cb-mark { width: 30px; height: 30px; }
.is-collapsed .brand__txt, .is-collapsed .nav__txt, .is-collapsed .nav__count, .is-collapsed .user__who, .is-collapsed .user__gear { display: none; }
.is-collapsed .side__top { flex-direction: column-reverse; gap: var(--sp-3); }
.is-collapsed .nav__label { text-align: center; padding: 0; font-size: 0; margin: var(--sp-3) 0 2px; }
.is-collapsed .nav__label::after { content: ""; display: block; height: 1px; background: var(--line); margin: 0 6px; }
.is-collapsed .nav__link { justify-content: center; padding: 0; gap: 0; }
.is-collapsed .side__foot { flex-direction: column; }
.is-collapsed .user { justify-content: center; padding: 6px; }
.is-collapsed .user__logout { display: none; }

/* ---------- En-tête ---------- */
.main { min-width: 0; }
.header {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: var(--sp-3); height: var(--header);
  padding: 0 var(--sp-7); background: var(--header-bg); border-bottom: 1px solid var(--line);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
}
.crumbs { font-size: var(--t-base); font-weight: 600; }
.header__right { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); }
.search {
  display: flex; align-items: center; gap: 8px; width: 260px; height: 34px; padding: 0 6px 0 10px; border-radius: var(--r-sm);
  background: var(--card); border: 1px solid var(--line-strong); color: var(--muted); transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 15px; height: 15px; }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; outline: none; font-size: var(--t-sm); color: var(--ink); }
.search input::placeholder { color: var(--muted); }
.kbd { padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line-strong); color: var(--muted); font-size: var(--t-2xs); font-weight: 600; }

.content { width: 100%; max-width: 1400px; margin: 0 auto; padding: var(--sp-6) var(--sp-7) var(--sp-7); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-5); }
.page-head h1 { margin: 0; font-size: var(--t-xl); font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: var(--t-base); }
.view { animation: view-in var(--dur) var(--ease) both; }
/* Rendu dû à un rafraîchissement des données (main.js) : l'entrée de page ne se rejoue pas. */
#app[data-refresh] .view { animation: none; }
/* Idem pour les entrées des widgets (barres qui poussent, jauges, ligne fraîche) : seules les données changent. */
#app[data-refresh] :is(.split__bar span, .xp__fill, .rank-live__bar span, .climb__fill, .rank-hero__emblem .medal, .level-bar__track span, .table--conn tr.is-fresh, .set-pane) { animation: none; }
#app[data-refresh] .nearmiss__arc { transition: none; }
/* Bandeau discret au-dessus d'une page dont une relecture a échoué (les données affichées restent les précédentes). */
.notice { display: flex; align-items: center; gap: 10px; margin: 0 0 var(--sp-4); padding: 10px 14px; border-radius: 12px; color: var(--warn); background: var(--warn-soft); font-size: var(--t-xs); font-weight: 600; }
.notice svg { width: 16px; height: 16px; flex: none; }
.notice span { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.notice .btn { flex: none; }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Mobile : barre d'onglets en bas ---------- */
@media (max-width: 860px) {
  .layout, .layout.is-collapsed { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  .header { padding: 0 max(var(--sp-4), env(safe-area-inset-right)) 0 max(var(--sp-4), env(safe-area-inset-left)); }
  .header__toggle { display: none; }
  .crumbs { font-size: var(--t-lg); font-weight: 700; }
  .search { width: auto; flex: 1; max-width: 220px; }
  .search .kbd { display: none; }
  .content { padding: var(--sp-5) max(var(--sp-4), env(safe-area-inset-right)) var(--sp-6) max(var(--sp-4), env(safe-area-inset-left)); }
  .tabbar {
    position: fixed; z-index: 30; inset: auto max(10px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); display: flex; align-items: stretch; justify-content: space-around;
    height: 60px; padding: 0 var(--sp-1); border: 1px solid var(--line-strong); border-radius: 18px;
    background: var(--panel); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); box-shadow: var(--shadow-pop);
  }
  .tabbar__link { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; flex: 1; border-radius: 12px; color: var(--muted); font-size: 10px; font-weight: 600; }
  .tabbar__link svg { width: 20px; height: 20px; }
  .tabbar__link[aria-current="page"] { color: var(--accent); }
}

/* ---------- Mobile : en-tête qui tient à 320 px, menu en tiroir, cibles de 40 px (hors Banque) ---------- */
@media (max-width: 860px) {
  :root:not([data-brand="rivabank"]) .crumbs { flex: none; white-space: nowrap; }
  :root:not([data-brand="rivabank"]) .header__right { flex: 1; min-width: 0; justify-content: flex-end; }
  :root:not([data-brand="rivabank"]) .search { min-width: 0; height: 40px; }
  /* 16 px : en dessous, iOS zoome sur le champ. width: 0 laisse le champ rétrécir (le flex lui rend la place). */
  :root:not([data-brand="rivabank"]) .search input { width: 0; font-size: 16px; text-overflow: ellipsis; }
  :root:not([data-brand="rivabank"]) .header .icon-btn { width: 40px; height: 40px; }
  /* Le bouton menu ouvre la barre latérale en tiroir ; le bouton thème passe dans le tiroir. */
  :root:not([data-brand="rivabank"]) .header__toggle { display: grid; order: 3; }
  /* Le bouton clair/sombre reste dans l'en-tête sur téléphone : visible sans ouvrir le menu. */
  .layout.is-drawer .side {
    display: flex; position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(300px, 86vw); height: 100dvh;
    padding-bottom: calc(var(--sp-4) + env(safe-area-inset-bottom)); border-right: 1px solid var(--line-strong); box-shadow: var(--shadow-pop);
    animation: drawer-in var(--dur) var(--ease);
  }
  .layout.is-drawer .side__toggle { display: none; }
  .layout.is-drawer .side__theme { display: grid; width: 40px; height: 40px; }
  .layout.is-drawer .nav__link { height: 44px; }
  .layout.is-drawer .user__logout { width: 40px; height: 40px; }
  .layout.is-drawer .drawer-scrim { display: block; position: fixed; inset: 0; z-index: 35; padding: 0; border: 0; background: rgba(6, 10, 19, 0.35); }
}
/* Libellés de la barre d'onglets à 11 px dès qu'ils tiennent (« Connexions » déborderait à 320 px). */
@media (min-width: 360px) and (max-width: 860px) { :root:not([data-brand="rivabank"]) .tabbar__link { font-size: 11px; } }
@keyframes drawer-in { from { transform: translateX(-100%); } }

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