/* =============================================================================
   App shell — sidebar, workspace, panneau droit, observability
   ============================================================================= */

/**
 * `body` est en `display: flex; flex-direction: column` (styles.css).
 * Sans `flex-grow`, le host `<my-app>` ne fait que la hauteur de son contenu
 * → toute la chaîne (workspace, main) reste « courte » (~60 % du viewport).
 */
body.has-app-shell > my-app {
  display: flex;
  flex-direction: column;
  flex: 1 1 0%;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

.app-root {
  min-height: 100vh;
  min-height: 100dvh;
}

/** Overlay pendant `/api/auth/me` — le viewport reste monté en dessous (voir `my-app.html`). */
.app-boot-loading {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--surface);
}

body.has-app-shell .app-root {
  flex: 1 1 0%;
  min-height: 0;
  max-height: 100%;
  height: auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.app-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  max-height: 100%;
  height: 100%;
  overflow: hidden;
}

/** Auth / partage : pas de sidebar ni observability — le viewport occupe la colonne (même si `body.has-app-shell` est absent). */
.app-shell--minimal {
  flex: 1 1 auto;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-shell--minimal .app-shell-main {
  min-height: 100%;
}

.app-shell--minimal .app-workspace {
  flex: 1 1 auto;
  min-height: 0;
  align-self: stretch;
}

.app-shell--minimal main.app-main.auth-layout {
  flex: 1 1 auto;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-shell-main {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  flex: 1 1 0%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  max-height: 100%;
}

.app-shell > .app-sidebar {
  flex-shrink: 0;
}

/* Desktop : sidebar à gauche + colonne principale */
@media (min-width: 769px) {
  .app-shell {
    flex-direction: row;
  }

  /**
   * Desktop: on veut une barre de titre en haut, puis (main + panneau droit) en dessous.
   * On passe la zone workspace en grid pour éviter de casser l'alignement du panneau droit.
   */
  .app-workspace {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .app-desktop-chrome {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  main.app-main {
    grid-column: 1;
    grid-row: 2;
  }

  .app-right {
    grid-column: 2;
    grid-row: 2;
  }

  .app-sidebar {
    position: relative;
    transform: none !important;
    width: var(--app-sidebar-width, 212px);
    border-right: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .app-sidebar-drawer-head {
    display: none !important;
  }

  .app-mobile-chrome {
    display: none !important;
  }

  .app-desktop-chrome {
    display: flex !important;
  }

  /* Desktop: le menu utilisateur remonte dans la topbar (pas en bas de la sidebar). */
  .app-sidebar-footer {
    display: none;
  }

  .avatar-trigger--topbar {
    box-sizing: border-box;
    padding: 0 0.65rem;
    margin: 0;
    border-radius: 0;
    border-left: 1px solid transparent;
    border-right: 1px solid transparent;
    border-top: none;
    border-bottom: none;
    background: transparent;
    min-height: 100%;
    height: 100%;
    align-self: stretch;
    align-items: center;
  }

  .avatar-trigger--topbar:hover {
    background: var(--bg-secondary);
    border-left-color: var(--border);
    border-right-color: var(--border);
  }

  .avatar-trigger--topbar .avatar-name {
    max-width: 12rem;
  }

  /* Dropdown: aligné à droite dans la topbar */
  .app-desktop-chrome .avatar-dropdown {
    right: 0;
    left: auto;
  }

  .app-sidebar-backdrop {
    display: none !important;
  }

  .app-shell-main {
    flex: 1 1 0%;
    min-width: 0;
    min-height: 0;
    align-self: stretch;
  }
}

/**
 * Desktop “compact” : ≤1200px, la sidebar se collapse (icônes only)
 * et s’étend au survol (ou focus clavier) pour relire les libellés.
 *
 * Mobile ≤768px reste un drawer (voir media query plus bas).
 */
@media (min-width: 769px) and (max-width: 1200px) {
  body.has-app-shell {
    --app-sidebar-collapsed-width: 58px;
  }

  .app-sidebar {
    /* La sidebar reste dans le flux à largeur repliée (ne pousse jamais le main) */
    width: var(--app-sidebar-collapsed-width, 58px);
    background: transparent;
    border-right: none;
    overflow: visible;
    z-index: 40;
  }

  .app-sidebar:hover,
  .app-sidebar:focus-within {
    z-index: 200;
  }

  /**
   * Le contenu de la sidebar (nav + footer) s’étend en overlay au survol / focus clavier.
   * Comme `.app-sidebar-body` est en `position:absolute`, sa largeur n’affecte pas le layout.
   */
  .app-sidebar-body {
    position: absolute;
    inset: 0;
    width: var(--app-sidebar-collapsed-width, 58px);
    background: var(--surface);
    border-right: 1px solid var(--border);
    transition: width 0.18s ease;
  }

  .app-sidebar:hover .app-sidebar-body,
  .app-sidebar:focus-within .app-sidebar-body {
    width: var(--app-sidebar-width, 212px);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.12);
  }

  .app-sidebar-nav {
    padding-left: 0.25rem;
    padding-right: 0.25rem;
  }

  /**
   * Tout le bloc compact cible `#app-sidebar-nav` : `app-nav-rail-cell` / `app-nav-link-label`
   * existent aussi dans les paramètres — ne pas utiliser de sélecteurs globaux `.app-nav-*` ici.
   */
  #app-sidebar-nav .app-nav-section-title {
    /**
     * IMPORTANT: garder la hauteur pour aligner les items entre collapsed et expanded.
     * En collapsed, on affiche une version "compacte" (centrée + tronquée) pour éviter le trou.
     */
    /* Couleur discrète uniforme (collapsed & expanded) */
    opacity: 0.72;
    pointer-events: auto;
    /* Ne pas changer l’alignement/padding pendant la transition de width (évite le “glitch” visuel) */
    text-align: left;
    padding: 0.35rem 0.5rem 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #app-sidebar-nav .app-nav-link {
    justify-content: center;
    padding: 0.42rem 0.25rem;
    /* Même hauteur avec ou sans badge (puce vs compteur en flux) → pas de saut d’alignement au expand. */
    min-height: 2.5rem;
    box-sizing: border-box;
  }

  #app-sidebar-nav .app-nav-rail-cell {
    margin-right: 0;
    width: 34px;
  }

  #app-sidebar-nav .app-nav-link-label {
    width: 0;
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    white-space: nowrap;
    pointer-events: none;
  }

  /**
   * Sidebar repliée (sans hover / sans focus dedans) : petite puce sur l’icône.
   * Avec hover ou focus clavier dans la barre : compteur classique après le libellé (règles suivantes).
   */
  .app-sidebar:not(:hover):not(:focus-within) #app-sidebar-nav .app-nav-link .nav-unread-badge {
    position: absolute;
    left: calc(50% + 8px);
    right: auto;
    top: 50%;
    transform: translate(-35%, -50%);
    margin-left: 0;
    box-shadow: 0 0 0 2px var(--surface);
    min-width: 8px;
    width: 8px;
    height: 8px;
    padding: 0;
    font-size: 0;
    line-height: 0;
    overflow: hidden;
    text-indent: 101%;
    white-space: nowrap;
  }

  /* Expanded (hover/focus) */
  .app-sidebar:hover #app-sidebar-nav .app-nav-section-title,
  .app-sidebar:focus-within #app-sidebar-nav .app-nav-section-title {
    /* Garder la même apparence “discrète” que le mode collapsed */
    opacity: 0.72;
    pointer-events: auto;
  }

  .app-sidebar:hover #app-sidebar-nav .app-nav-link,
  .app-sidebar:focus-within #app-sidebar-nav .app-nav-link {
    justify-content: flex-start;
    padding: 0.38rem 0.45rem;
    min-height: 2.5rem;
    box-sizing: border-box;
  }

  .app-sidebar:hover #app-sidebar-nav .app-nav-rail-cell,
  .app-sidebar:focus-within #app-sidebar-nav .app-nav-rail-cell {
    width: 26px;
    margin-right: 0.35rem;
  }

  .app-sidebar:hover #app-sidebar-nav .app-nav-link-label,
  .app-sidebar:focus-within #app-sidebar-nav .app-nav-link-label {
    width: auto;
    max-width: 999px;
    opacity: 1;
    pointer-events: auto;
  }

  .app-sidebar:hover #app-sidebar-nav .app-nav-link .nav-unread-badge,
  .app-sidebar:focus-within #app-sidebar-nav .app-nav-link .nav-unread-badge {
    position: static;
    transform: none;
    inset: auto;
    left: auto;
    right: auto;
    top: auto;
    margin-left: 0.35rem;
    box-shadow: none;
    min-width: 14px;
    width: auto;
    height: 14px;
    padding: 0 0.22rem;
    font-size: 0.55rem;
    line-height: 1;
    overflow: visible;
    text-indent: 0;
    white-space: nowrap;
  }
}

/**
 * Barre supérieure mobile : le bouton menu doit rester **hors** du drawer (sinon il disparaît avec la sidebar).
 * En ≤768px elle est dans le flux (`flex-direction: column` sur `.app-workspace`) pour que `main`
 * ne s’étende pas sous la barre ; inutile d’ajouter sa hauteur à `.app-viewport-host`.
 */
.app-mobile-chrome {
  display: none;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  box-sizing: border-box;
  height: calc(44px + env(safe-area-inset-top, 0px));
  padding: 0 max(0.8rem, env(safe-area-inset-right, 0px)) 0 max(0.65rem, env(safe-area-inset-left, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.app-desktop-chrome {
  display: none;
  align-items: stretch;
  justify-content: space-between;
  gap: 1rem;
  flex-shrink: 0;
  height: 56px;
  padding: 0 calc(var(--main-padding) + 0.25rem);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.app-desktop-chrome-title {
  display: flex;
  align-items: center;
  font-size: 1.18rem;
  font-weight: 480;
  line-height: 1.2;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.app-desktop-chrome-actions {
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  gap: 0.5rem;
  flex: 0 0 auto;
  min-width: 0;
  height: 100%;
}

.app-desktop-chrome .avatar-menu-wrapper {
  display: flex;
  align-items: stretch;
  height: 100%;
}

.app-mobile-chrome-brand {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

.app-mobile-menu-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: 8px;
  outline: none;
  box-shadow: none;
  -webkit-tap-highlight-color: transparent;
}

.app-mobile-menu-btn:focus:not(:focus-visible) {
  outline: none;
}

.app-mobile-menu-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-sidebar-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.app-sidebar-drawer-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-sidebar-drawer-close {
  flex-shrink: 0;
}

/* Mobile : sidebar en drawer */
@media (max-width: 768px) {
  body.has-app-shell {
    --main-padding: 1rem;
    /** Alignement des overlays `position:fixed` (ex. réglages) sur la barre menu — même hauteur que `.app-mobile-chrome`. */
    --app-mobile-chrome-h: calc(44px + env(safe-area-inset-top, 0px));
  }

  /**
   * Barre menu : **dans le flux** (plus `position:fixed`) pour que la grille flex réserve
   * sa hauteur — sinon `main` occupe 100 % de la hauteur utile et le contenu passe sous la barre.
   */
  .app-workspace {
    flex-direction: column;
    align-items: stretch;
  }

  .app-mobile-chrome {
    display: flex;
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    width: 100%;
    flex-shrink: 0;
    z-index: 100;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
  }

  .app-desktop-chrome {
    display: none !important;
  }

  .app-main {
    width: 100%;
    min-width: 0;
  }

  .app-mobile-menu-btn {
    min-width: 44px;
    min-height: 44px;
  }

  .app-shell {
    flex-direction: row;
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 88vw);
    z-index: 400;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transform: translateX(-102%);
    transition: transform 0.25s ease;
  }

  .app-sidebar.app-sidebar--open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.12);
  }

  .app-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 399;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .app-sidebar-backdrop.visible {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .app-shell-main {
    flex: 1 1 0%;
    min-height: 0;
    width: 100%;
    align-self: stretch;
  }

  /**
   * Mobile: le titre de page remonte dans la barre mobile (app-mobile-chrome)
   * → éviter le doublon sous la navbar pour les pages "shell".
   */
  .shell-page__title,
  .shell-page__lead {
    display: none !important;
  }

  .shell-page__header {
    margin-bottom: 0.85rem;
  }
}

.app-sidebar-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.app-sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.35rem 0.4rem 0.75rem;
  min-height: 0;
}

.app-nav-section + .app-nav-section {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.app-nav-section-title {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.35rem 0.5rem 0.25rem;
  margin: 0;
  line-height: 1.2;
}

.app-nav-rail-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  flex-shrink: 0;
  margin-right: 0.35rem;
  color: var(--muted);
}

.app-nav-link.active .app-nav-rail-cell {
  color: var(--accent);
}

.app-nav-rail-icon {
  flex-shrink: 0;
  opacity: 0.92;
}

.app-nav-rail-placeholder {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.app-nav-link {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.25rem;
  padding: 0.38rem 0.45rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.875rem;
  position: relative;
}

/* .nav-unread-badge (styles.css) est en position:absolute pour .nav-link — hors flux ici sans parent positionné, le badge se plaçait en haut de la page. */
.app-nav-link .nav-unread-badge {
  position: static;
  transform: none;
  inset: auto;
  margin-left: 0.35rem;
  flex-shrink: 0;
  align-self: center;
  box-shadow: none;
}

.app-nav-link:hover {
  background: var(--bg-secondary);
  text-decoration: none;
}

.app-nav-link.active {
  background: var(--gradient-primary-subtle);
  color: var(--accent);
  font-weight: 600;
}

.app-sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 0.75rem;
}

.app-sidebar-footer .avatar-menu-wrapper {
  position: relative;
}

.app-sidebar-footer .avatar-dropdown {
  left: 0;
  right: auto;
}

.avatar-trigger--sidebar {
  width: 100%;
  justify-content: flex-start;
}

.app-workspace {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1 1 0%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  max-height: 100%;
}

.app-main {
  flex: 1 1 0%;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/**
 * Référence pour remplir toute la zone utile du `main` (flex seul ne suffit pas si
 * `au-viewport` n’expose pas d’enfant direct stylable — le routeur injecte le composant autrement).
 */
body.has-app-shell main.app-main {
  position: relative;
}

/**
 * Remplit le rectangle **intérieur au padding** du main (même inset que var(--main-padding)).
 */
body.has-app-shell .app-viewport-host {
  position: absolute;
  top: var(--main-padding);
  right: var(--main-padding);
  bottom: var(--main-padding);
  left: var(--main-padding);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

/**
 * Préférences : sous-menu gris collé à la sidebar app + hauteur pleine zone centrale
 * (sinon `top` / `bottom` du host restent à `var(--main-padding)` et le menu ne touche pas les bords).
 */
body.route-settings.has-app-shell .app-viewport-host {
  left: 0;
  top: 0;
  bottom: 0;
}

body.has-app-shell .app-viewport-host > au-viewport {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  width: 100%;
  height: 100%;
  max-height: 100%;
}

/** Enfant direct du viewport (quand il existe). */
body.has-app-shell .app-viewport-host > au-viewport > * {
  flex: 1 1 0%;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-self: stretch;
  width: 100%;
  box-sizing: border-box;
}

/**
 * Ciblage explicite des racines de pages (le sélecteur `> *` ne matche pas toujours selon l’hydratation Aurelia).
 */
body.has-app-shell .app-viewport-host .shell-page,
body.has-app-shell .app-viewport-host .activity-log-shell,
body.has-app-shell .app-viewport-host .settings-page,
body.has-app-shell .app-viewport-host .conv-layout {
  flex: 1 1 0%;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  width: 100%;
  align-self: stretch;
  box-sizing: border-box;
}

/**
 * Scroll sur `.app-workspace` (body.shell-workspace-scroll) : stats, finance, logs,
 * knowledge/events (détections), paramètres. Ascenseur au bord droit de la colonne centrale ;
 * le panneau d’observabilité reste hors scroll. `app-viewport-host` en flux pour propager
 * la hauteur du contenu.
 */
body.has-app-shell.shell-workspace-scroll .app-workspace {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/**
 * Un seul cadre de padding : celui de `main.app-main` (styles.css). Pas de second
 * `--main-padding` sur `.app-viewport-host` (évite le double marging avec l’ancien
 * mode absolute + inset).
 */
body.has-app-shell.shell-workspace-scroll main.app-main {
  overflow: visible;
  flex: 1 1 auto;
  min-height: min-content;
  max-height: none;
}

/** Préférences : pas de marge haut/bas sur `main` (menu latéral pleine hauteur ; contenu : `.settings-content`). */
body.route-settings.has-app-shell main.app-main {
  padding-top: 0;
  padding-bottom: 0;
}

/** Préférences : pas de marge gauche sur le main en mode scroll workspace. */
body.has-app-shell.shell-workspace-scroll.route-settings main.app-main {
  padding-left: 0;
}

body.has-app-shell.shell-workspace-scroll .app-viewport-host {
  position: static;
  inset: auto;
  flex: 0 0 auto;
  width: 100%;
  padding: 0;
  box-sizing: border-box;
  overflow: visible;
  height: auto;
  max-height: none;
}

body.has-app-shell.shell-workspace-scroll .app-viewport-host > au-viewport {
  flex: 0 0 auto;
  height: auto;
  max-height: none;
  min-height: 0;
}

body.has-app-shell.shell-workspace-scroll .app-viewport-host > au-viewport > * {
  flex: 0 0 auto;
  height: auto;
  max-height: none;
  min-height: 0;
}

body.has-app-shell.shell-workspace-scroll .app-viewport-host .shell-page,
body.has-app-shell.shell-workspace-scroll .app-viewport-host .settings-page,
body.has-app-shell.shell-workspace-scroll .app-viewport-host .activity-log-shell {
  flex: 0 0 auto;
  height: auto;
  max-height: none;
  overflow: visible;
}

body.has-app-shell.shell-workspace-scroll .app-viewport-host .shell-page .shell-page__body {
  flex: 0 0 auto;
  min-height: 0;
}

body.has-app-shell.shell-workspace-scroll .activity-log-shell .activity-log-full {
  flex: 0 0 auto;
  min-height: 0;
  overflow: visible;
}

body.has-app-shell.shell-workspace-scroll .activity-log-shell .activity-log-table-wrapper {
  flex: 0 0 auto;
  min-height: 0;
  overflow: visible;
}

/**
 * Paramètres : rétablir la même chaîne flex que hors `shell-workspace-scroll` (voir lignes 460–497).
 * Le routeur Aurelia monte d’abord l’élément du composant (`<settings>`), pas `.settings-page` :
 * le sélecteur `> au-viewport > .settings-page` ne matche donc jamais ; il faut styler `> *`
 * puis `.settings-page` en descendant.
 */
body.has-app-shell.shell-workspace-scroll.route-settings .app-viewport-host {
  flex: 1 1 auto;
  align-self: stretch;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.has-app-shell.shell-workspace-scroll.route-settings .app-viewport-host > au-viewport {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  width: 100%;
}

body.has-app-shell.shell-workspace-scroll.route-settings .app-viewport-host > au-viewport > * {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-self: stretch;
  width: 100%;
  box-sizing: border-box;
}

body.has-app-shell.shell-workspace-scroll.route-settings .app-viewport-host .settings-page {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  align-self: stretch;
  box-sizing: border-box;
}

.app-right {
  width: var(--app-right-width, 300px);
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/** Fiche réservation depuis le calendrier : ~2/3 de la largeur utile (desktop). */
.app-right.app-right--wide {
  --app-right-width: min(68vw, 960px);
  flex: 0 0 var(--app-right-width);
  max-width: min(68vw, 960px);
}

.app-right-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.app-right-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.app-right-empty,
.app-right-body {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}

/**
 * Fiche réservation (calendrier) : même enveloppe que la page Réservations (`bk-detail-panel`) +
 * `bookings-page` pour les sélecteurs `.bookings-page .bk-*` dans styles.css.
 * Double classe pour battre le `padding: 1rem` de `.app-right-body` (même spécificité à un seul segment).
 */
.app-right-body.app-right-body--booking-detail {
  padding: 0;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  background: var(--surface);
}

.app-right-body.app-right-body--booking-detail > .bk-detail-panel {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
}

.app-right-body.app-right-body--booking-detail .bk-detail-panel > booking-detail-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  align-self: stretch;
}

.app-right-body.app-right-body--booking-detail .booking-detail-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
}

.app-right-heading {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.app-right-meta {
  margin: 0.75rem 0 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  font-size: 0.85rem;
}

.app-right-meta dt {
  color: var(--muted);
  margin: 0;
}

.app-right-meta dd {
  margin: 0;
}

@media (max-width: 768px) {
  .app-right {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(100vw - 48px, 320px);
    z-index: 350;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
  }
}

/* --- Observability --- */
.obs-panel {
  flex-shrink: 0;
  background: var(--surface);
  position: relative;
  z-index: 25;
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Bordure haute sur la dragbar (premier enfant), pas sur tout le bloc — évite double trait */
}

/** Bandeau unique : visible réduit ou étendu (en-tête du panneau). */
.obs-panel-head {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.5rem 0.4rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  min-height: 40px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.obs-panel-head-brand {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  flex-shrink: 0;
}

.obs-panel-head-aux {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  flex-shrink: 0;
}

.obs-panel-icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
}

.obs-panel-icon-link:hover {
  background: var(--bg-secondary);
  color: var(--text);
}

.obs-panel-icon-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.obs-panel-spinner {
  animation: spin 1.2s linear infinite;
  color: var(--accent);
}

.obs-panel-status-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  flex-shrink: 0;
}

.obs-panel-status-dot--idle {
  color: var(--muted);
}

.obs-panel-status-dot--active {
  color: #22c55e;
}

.obs-panel-status-dot--active .obs-panel-spinner {
  color: #22c55e;
}

.obs-panel-status-dot--error {
  color: #ef4444;
}

.obs-panel-status-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.obs-panel-status-elapsed {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.obs-panel-dismiss {
  margin-left: 0;
}

/* Activity log en embed */
.activity-log-embed {
  padding: 0.5rem 0.75rem 0.75rem !important;
  max-width: none !important;
  margin: 0 !important;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.activity-log-embed .activity-log-header h2 {
  font-size: 1rem;
}

.activity-log-embed .activity-log-filters {
  padding: 0.5rem 0;
  flex-shrink: 0;
}

.activity-log-embed .activity-log-embed-inner {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.activity-log-embed .activity-log-table-wrapper {
  max-height: none;
  flex: 1 1 auto;
  overflow: auto;
  min-height: 0;
}

.activity-log-embed .activity-log-footer {
  flex-shrink: 0;
}

/* Logs plein écran : même gabarit shell que les autres pages */
.activity-log-shell {
  margin: 0;
  padding: 0;
  gap: 0.5rem;
}

.activity-log-shell .shell-page__header {
  margin-bottom: 0;
}

.activity-log-shell .shell-page__header.shell-page__header--split {
  justify-content: flex-end;
}

.activity-log-shell .activity-log-full {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.activity-log-shell .activity-log-table-wrapper {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

/* --- Pages « shell » (tout sauf conversations / training / personas) --- */
.shell-page {
  display: flex;
  flex-direction: column;
  flex: 1 1 0%;
  min-height: 0;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  align-self: stretch;
  box-sizing: border-box;
}

.shell-page--wide {
  max-width: none;
}

.shell-page__header {
  margin-bottom: 1.25rem;
  flex-shrink: 0;
}

.shell-page__header--split {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.shell-page__header--split .shell-page__title {
  margin-bottom: 0;
}

.shell-page__header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.shell-page__title {
  margin: 0 0 0.35rem;
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}

.shell-page__lead {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.45;
}

.shell-page__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/**
 * Pages longues : le défilement est sur `.shell-page` (zone déjà inset par `--main-padding`
 * sur `.app-viewport-host`), pas sur un panneau interne — évite le contenu coupé quand
 * `height: 100%` + ancêtre `overflow: hidden`.
 *
 * Le `shell-page__body` en `flex: 0 0 auto` évite que le corps vole tout le flex et force
 * un mini-scroll interne ; la colonne entière (en-tête + corps) défile ensemble.
 */
/** Pages encore sur scroll interne shell (hors shell-workspace-scroll). */
body.has-app-shell .app-viewport-host .shell-page.shell-page--viewport-scroll {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: 100%;
  overflow-x: visible;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body.has-app-shell .app-viewport-host .shell-page.shell-page--viewport-scroll .shell-page__body {
  flex: 0 0 auto;
  min-height: 0;
}

.shell-page__list {
  margin: 0;
  padding-left: 1.25rem;
  line-height: 1.6;
}

/** Blocs Connaissance (titres un peu plus compacts) */
.shell-page--dense .shell-page__header {
  margin-bottom: 1rem;
}

.shell-page--dense .shell-page__title {
  font-size: 1.2rem;
}

