/* =============================================
   ESPACE — structure commune (post-connexion)
   Mobile/tablette : navbar bas
   Desktop (≥1024px) : sidebar droite + topbar
   Chargé en premier ; les feuilles de chaque domaine suivent (base_espace.html.twig).
   ============================================= */

/* === Layout racine === */

/*
 * Sur iOS PWA, la zone du home indicator (sous le viewport CSS) affiche
 * le fond de l'élément <html>. On le cale sur --clr-surface pour qu'il
 * soit invisible sous la nav-bottom (même couleur).
 */
html { background: var(--clr-surface); }

.app-layout {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* En mode PWA standalone, 100dvh démarre à la "small viewport" (sans home indicator).
   100lvh = large viewport = plein écran dès le premier rendu, sans attendre le scroll.
   body overflow:hidden en fait le containing block pour les position:fixed,
   ancré à la hauteur physique complète de l'écran. */
@media (display-mode: standalone) {
  body       { height: 100lvh; overflow: hidden; }
  .app-layout { height: 100lvh; }
}

.app-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--sp-2);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + var(--sp-6));
  max-width: var(--page-max);
  width: 100%;
  margin-inline: auto;
  view-transition-name: app-content;
}

/* ── View Transitions — navigation Turbo ── */
::view-transition-old(root),
::view-transition-new(root) { animation: none; }

@keyframes vt-slide-out {
  0%   { transform: translateX(0);       opacity: 1; }
  100% { transform: translateX(-120px);  opacity: 0; }
}
@keyframes vt-slide-in {
  from { transform: translateX(100px); opacity: 0; }
  to   { transform: translateX(0);     opacity: 1; }
}
::view-transition-old(app-content) { animation: vt-slide-out 220ms ease-in-out both; }
::view-transition-new(app-content) { animation: vt-slide-in  200ms ease-out 100ms both; }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(app-content),
  ::view-transition-new(app-content) { animation: none; }
}

/* === Topbar — visible sur tous les breakpoints === */
.topbar {
  view-transition-name: topbar;
  display: flex;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--sp-6) 0;
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  gap: var(--sp-4);
  z-index: 90;
}

.topbar-title {
  font-weight: 600;
  font-size: var(--text-lg);
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  letter-spacing: -.01em;
}

.topbar-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 4px;
  flex-shrink: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

/* === Nav basse (mobile / tablette) === */
/* Wrapper Alpine du profil — aligne le bouton avec les autres items */
.nav-bottom > div {
  flex: 1;
  display: flex;
}

.nav-bottom {
  view-transition-name: nav-bottom;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  background: var(--clr-surface);
  border-top: 1px solid var(--clr-border);
  display: flex;
  align-items: flex-start;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-bottom .nav-item {
  flex: 1;
  height: var(--nav-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--sp-2) 0;
  color: var(--clr-text-muted);
  font-size: var(--text-xs);
  transition: color .15s;
  cursor: pointer;
  touch-action: manipulation;
}

.nav-bottom .nav-item:hover,
.nav-bottom .nav-item.active { color: var(--clr-accent-text); font-weight: 600; }
/* Pastille derrière l'icône de l'onglet actif */
.nav-bottom .nav-icon { width: 56px; height: 28px; border-radius: var(--radius-full); transition: background .15s; }
.nav-bottom .nav-item.active .nav-icon { background: var(--clr-accent-soft); }

.nav-icon {
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.app-layout {
  padding-top: calc(var(--topbar-h) + env(safe-area-inset-top));
}

.demo-banner {
  flex-shrink: 0;
  background: var(--clr-warning-fill);
  color: #fff;
  text-align: center;
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: .01em;
}

/* === Sidebar — masquée sur mobile === */
.nav-sidebar { display: none; }

/* =============================================
   DESKTOP ≥ 1024px
   ============================================= */
@media (min-width: 1024px) {

  .app-layout {
    padding-right: var(--sidebar-w);
  }

  /* Topbar */
  .topbar {
    right: var(--sidebar-w);
  }

  /* Sidebar droite */
  .nav-sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--clr-surface);
    border-left: 1px solid var(--clr-border);
    z-index: 100;
    padding: var(--sp-3) 0;
  }

  .sidebar-logo {
    padding: 0 var(--sp-6) var(--sp-3);
    margin-bottom: var(--sp-4);
    font-weight: 700;
    font-size: var(--text-xl);
    letter-spacing: .06em;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
  }

  .sidebar-logo__img {
    width: 44px;
    height: 44px;
    object-fit: contain;
    border-radius: var(--radius-sm);
  }

  .sidebar-links {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 var(--sp-3);
    gap: 2px;
    overflow-y: auto;
  }

  .nav-sidebar .nav-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3);
    border-radius: var(--radius-md);
    color: var(--clr-text-muted);
    font-size: var(--text-sm);
    font-weight: 500;
    transition: background .15s, color .15s;
  }

  .nav-sidebar .nav-item:hover { background: var(--clr-surface-2); color: var(--clr-text); }
  .nav-sidebar .nav-item.active { background: var(--clr-accent-soft); color: var(--clr-accent-text); font-weight: 600; }

  .nav-sidebar .nav-icon { width: 18px; height: 18px; }

  /* Section toggles (bouton collapsible) */
  button.nav-item {
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
  }

  .nav-chevron {
    margin-left: auto;
    flex-shrink: 0;
    transition: transform .2s;
  }
  .nav-chevron.open { transform: rotate(180deg); }

  /* Sous-items indentés */
  .nav-sub {
    display: flex;
    flex-direction: column;
    padding-left: calc(var(--sp-3) + 18px + var(--sp-3));
    gap: 2px;
    margin-top: 2px;
    margin-bottom: var(--sp-1);
  }

  .nav-sub .nav-item {
    font-size: var(--text-xs);
    padding: var(--sp-2) var(--sp-3);
  }

  /* Sous-items de second niveau (ex: sections stats dans Administration) */
  .nav-sub--nested {
    padding-left: var(--sp-3);
    border-left: 1px solid var(--clr-border);
    margin-left: var(--sp-2);
    margin-top: 2px;
    margin-bottom: var(--sp-1);
  }

  .sidebar-footer {
    padding: var(--sp-4) var(--sp-3) 0;
    border-top: 1px solid var(--clr-border);
    margin-top: auto;
  }

  /* Masquer la nav basse */
  .nav-bottom { display: none; }

  .app-content {
    padding-bottom: var(--sp-6);
  }

  /* Utilisateur en pied de sidebar */
  .sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 0 var(--sp-3) var(--sp-3);
  }

  .sidebar-user-avatar {
    width: 34px; height: 34px;
    border-radius: var(--radius-sm);
    background: var(--clr-accent);
    color: #fff;
    font-size: var(--text-xs);
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    letter-spacing: .04em;
  }

  .sidebar-user-info {
    display: flex; flex-direction: column;
    overflow: hidden;
  }

  .sidebar-user-name {
    font-size: var(--text-sm); font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  .sidebar-user-role {
    font-size: var(--text-xs); color: var(--clr-text-muted);
  }
}

/* =============================================
   Avatar nav mobile
   ============================================= */
.nav-avatar {
  width: 26px; height: 26px;
  border-radius: var(--radius-sm);
  background: var(--clr-accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: .04em;
}

/* =============================================
   Profile sheet — mobile (Alpine overlay)
   ============================================= */
[x-cloak] { display: none !important; }

.profile-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

.profile-sheet {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  padding: var(--sp-6);
  box-shadow: var(--shadow-lg);
  max-height: calc(100dvh - var(--nav-h) - env(safe-area-inset-bottom) - var(--sp-4));
  overflow-y: auto;
}

/* Slide-up transition (Alpine x-transition:enter/leave) applied on .profile-sheet
   while x-show lives on the parent .profile-sheet-overlay */
.sheet-slide {
  transition: transform .28s cubic-bezier(.32, .72, 0, 1), opacity .28s ease;
}
.sheet-slide-off {
  transform: translateY(100%);
  opacity: 0;
}
.sheet-slide-on {
  transform: translateY(0);
  opacity: 1;
}

.profile-sheet-user {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

.profile-sheet-avatar {
  width: 44px; height: 44px;
  border-radius: var(--radius-md);
  background: var(--clr-accent);
  color: #fff;
  font-size: var(--text-sm);
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  letter-spacing: .04em;
}

.profile-sheet-action,
.profile-sheet-logout {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background .15s;
}

.profile-sheet-action { color: var(--clr-text-muted); }
.profile-sheet-action:hover { background: var(--clr-surface-2); color: var(--clr-text); }
.profile-sheet-action.active { color: var(--clr-accent-text); }

.profile-sheet-logout { color: var(--clr-danger); }
.profile-sheet-logout:hover { background: var(--clr-danger-soft); }

.sheet-section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--clr-text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: var(--sp-3) var(--sp-3) var(--sp-1);
}

/* =============================================
   EN-TÊTE DE PAGE
   ============================================= */
.page-header {
  margin-bottom: var(--sp-5);
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: 1.1;
  margin: 0 0 var(--sp-1);
}

