/*
 * Onglizy — comportements mobiles du SOCLE (chargé après app.css et les feuilles d'écran)
 *
 * SOMMAIRE
 *  1. Barre d'onglets basse publique ... .mobile-bottom-nav .mobile-tab .mobile-tab-icon .mobile-tab-label .mobile-tab-badge
 *  2. Barre d'onglets de l'espace pro .. .pro-tabbar (mêmes .mobile-tab)
 *  3. Menu mobile plein écran .......... dialog.mobile-menu .mobile-menu-inner .mobile-menu-head .mobile-menu-body
 *                                        .mobile-menu-list .mobile-menu-link .mobile-menu-icon .mobile-menu-title
 *                                        .mobile-menu-hint .mobile-menu-card .mobile-menu-user .mobile-menu-row .mobile-menu-info
 *  4. Barres d'action basses ........... .mobile-contact-bar .mobile-back .mobile-action-bar .mobile-save-bar (.is-dirty)
 *  5. Feuilles basses .................. tout .dialog devient une feuille basse sous 861 px (poignée dessinée en CSS)
 *  6. Ajustements < 861 px ............. en-tête compact, coquilles pro/admin empilées, sections resserrées
 *  7. Paysage bas, safe-area
 * États pilotés par public/mobile.js sur <body> : .mobile-editor-active, .mobile-keyboard-open
 */

:root {
  --dock-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* 1. BARRE D'ONGLETS BASSE (PUBLIC) -------------------------------------- */
.mobile-bottom-nav, .pro-tabbar { display: none; }
.mobile-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}
.mobile-tab:hover { color: var(--plum-700); }
.mobile-tab-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 56px;
  height: 28px;
  border-radius: var(--radius-pill);
  transition: background-color var(--transition);
}
.mobile-tab-label { max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mobile-tab[aria-current="page"] { color: var(--plum-700); font-weight: 600; }
.mobile-tab[aria-current="page"] .mobile-tab-icon, .mobile-tab[aria-expanded="true"] .mobile-tab-icon { background: var(--blush-100); }
.mobile-tab:focus-visible { outline-offset: -3px; border-radius: var(--radius-sm); }
.mobile-tab-badge {
  position: absolute;
  top: -4px;
  right: 8px;
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border: 2px solid var(--white);
  border-radius: var(--radius-pill);
  box-sizing: content-box;
  background: var(--plum-700);
  color: var(--white);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

@media (max-width: 860px) {
  .mobile-bottom-nav, .pro-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-dock);
    display: grid;
    grid-auto-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    height: calc(var(--dock-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--white);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 22px rgba(86, 60, 73, .04);
  }
  body:has(.mobile-bottom-nav), body.layout-pro { padding-bottom: calc(var(--dock-h) + var(--safe-bottom)); }

  /* La barre de contact d'une fiche, l'éditeur actif ou le clavier ouvert remplacent la barre d'onglets. */
  body:has(.mobile-contact-bar) .mobile-bottom-nav,
  body.mobile-editor-active .mobile-bottom-nav,
  body.mobile-editor-active .pro-tabbar,
  body.mobile-keyboard-open .mobile-bottom-nav,
  body.mobile-keyboard-open .pro-tabbar { display: none; }
  body.mobile-keyboard-open { padding-bottom: 0; }
}

/* 3. MENU MOBILE PLEIN ÉCRAN -------------------------------------------- */
dialog.mobile-menu {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--ivory);
  color: var(--plum-900);
}
dialog.mobile-menu::backdrop { background: var(--ivory); }
.mobile-menu-inner { display: flex; flex-direction: column; min-height: 100%; }
.mobile-menu-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: none;
  height: 56px;
  padding: 0 12px 0 16px;
  padding-top: env(safe-area-inset-top, 0px);
  box-sizing: content-box;
  background: var(--ivory);
  border-bottom: 1px solid var(--line);
}
.mobile-menu-head .brand-name { font-size: 24px; }
.mobile-menu-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 12px 16px calc(24px + var(--safe-bottom));
  overscroll-behavior: contain;
}
.mobile-menu-list { display: flex; flex-direction: column; gap: 4px; }
.mobile-menu-link {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  margin: 0 -12px;
  padding: 8px 12px;
  border-radius: 16px;
  color: var(--plum-900);
  text-decoration: none;
}
.mobile-menu-link:hover, .mobile-menu-link[aria-current="page"] { background: var(--blush-100); color: var(--plum-900); }
.mobile-menu-icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--white);
  color: var(--plum-700);
}
.mobile-menu-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.mobile-menu-title { font-size: 19px; font-weight: 600; line-height: 1.3; }
.mobile-menu-hint { font-size: 14px; line-height: 1.4; color: var(--muted); }
.mobile-menu-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--blush-50);
}
.mobile-menu-card-title { font-family: var(--font-ui); font-size: 18px; font-weight: 600; line-height: 1.3; letter-spacing: 0; }
.mobile-menu-card form { margin: 0; }
.mobile-menu-user { display: flex; align-items: center; gap: 12px; }
.mobile-menu-user-name { font-size: 16px; font-weight: 600; }
.mobile-menu-row { display: flex; flex-wrap: wrap; gap: 4px 8px; }
.mobile-menu-row > * { flex: 1 1 auto; }
.mobile-menu-info { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-left: -12px; }

/* 4. BARRES D'ACTION BASSES --------------------------------------------- */
.mobile-contact-bar, .mobile-action-bar, .mobile-save-bar { display: none; }
@media (max-width: 860px) {
  .mobile-contact-bar, .mobile-action-bar, .mobile-save-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-bar);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px calc(10px + var(--safe-bottom));
    background: var(--white);
    border-top: 1px solid var(--line);
    box-shadow: 0 -5px 25px rgba(86, 60, 73, .06);
  }
  .mobile-save-bar[hidden] { display: none; }
  .mobile-contact-bar > .button, .mobile-action-bar > .button, .mobile-save-bar > .button { flex: 1 1 0; min-width: 0; padding: 0 14px; }
  .mobile-back {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: 48px;
    height: 48px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-pill);
    background: var(--white);
    color: var(--plum-700);
    font-size: 20px;
    text-decoration: none;
  }
  .mobile-back:hover { background: var(--blush-100); color: var(--plum-700); }
  body:has(.mobile-contact-bar), body:has(.mobile-action-bar) { padding-bottom: calc(72px + var(--safe-bottom)); }
  .mobile-save-bar [data-save-status] { flex: 1 1 auto; min-width: 0; font-size: 14px; color: var(--muted); }
  .mobile-save-bar > .button { flex: 0 0 auto; }
  .mobile-save-bar.is-dirty [data-save-status] { color: var(--amber-700); font-weight: 600; }
  body.mobile-editor-active { padding-bottom: calc(72px + var(--safe-bottom)); }
  body.mobile-keyboard-open .mobile-contact-bar,
  body.mobile-keyboard-open .mobile-action-bar { display: none; }
}

/* 5. FEUILLES BASSES ----------------------------------------------------- */
@media (max-width: 860px) {
  .dialog {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    margin: auto 0 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .dialog .dialog-inner { padding: 12px 16px calc(24px + var(--safe-bottom)); }
  .dialog .dialog-inner::before {
    content: "";
    align-self: center;
    width: 40px;
    height: 4px;
    border-radius: var(--radius-pill);
    background: var(--line-strong);
  }
  .dialog-title { font-size: 26px; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions > .button { width: 100%; }
  .toast-region { bottom: calc(var(--dock-h) + 16px + var(--safe-bottom)); }
}

/* 6. AJUSTEMENTS < 861 PX ------------------------------------------------ */
@media (max-width: 860px) {
  :root { --header-h: 56px; --section-y: 48px; }
  .site-header-inner { gap: 8px; padding-right: 12px; }
  .site-header .brand-name { font-size: 24px; }
  .site-header .brand-mark { width: 28px; height: 28px; }
  .header-account { width: 44px; padding: 0; justify-content: center; }
  .section-heading { margin-bottom: 24px; }
  .lead { font-size: 16px; }
  .page-title { font-size: 32px; }
  .panel { padding: 20px 16px; }
  .card-pad, .card-pad-lg { padding: 20px 16px; }
  .empty-state { padding: 32px 16px; }
  .faq-answer { padding-right: 0; }
  .footer-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px 20px; }
  .footer-brand { grid-column: 1 / -1; }
  .site-footer-inner { padding-top: 48px; }
  .stepper .step-label { font-size: 13px; }
  .split { gap: 32px; }

  /* Coquille pro : la sidebar se réduit au sélecteur de fiche ; le menu passe dans la barre basse et la feuille « Plus ». */
  .shell { flex-direction: column; flex-wrap: nowrap; }
  .shell-sidebar, .side-sticky { flex: none; gap: 12px; }
  .shell-sidebar { padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .shell-pro .shell-sidebar > .side-nav, .shell-pro .shell-sidebar > .side-footer { display: none; }
  .shell-pro .side-head .brand-name { font-size: 24px; }
  .shell-pro .side-head .brand-mark { width: 28px; height: 28px; }
  .shell-main { flex: 1 0 auto; padding: 20px 16px 28px; }
  .shell-content { gap: 20px; }
  .dialog .side-nav ul { gap: 0; }
  .dialog .side-link { min-height: 52px; margin: 0 -12px; font-size: 16px; }

  /* Coquille admin : sidebar sombre empilée, menus en rangées défilantes. */
  .shell-admin .shell-sidebar { padding: 12px 16px 8px; border-bottom: 0; }
  .shell-admin .side-nav ul, .shell-admin .side-footer {
    position: relative;
    flex-direction: row;
    gap: 4px;
    margin: 0 -16px;
    padding: 0 16px 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .shell-admin .side-nav ul::-webkit-scrollbar, .shell-admin .side-footer::-webkit-scrollbar { display: none; }
  .shell-admin .side-link { width: auto; flex: none; white-space: nowrap; }
  .shell-admin .side-footer { flex-direction: row; align-items: center; padding-top: 8px; }
  .shell-admin .side-user { margin: 0 0 0 auto; padding: 0; border-top: 0; flex: none; }
  .shell-admin .side-user-name { display: none; }
  .shell-admin .shell-content { gap: 24px; }

  .table { font-size: 14px; }
  .bulk-bar { border-radius: var(--radius-sm); }
  .pagination { justify-content: center; }
  .pagination-summary { width: 100%; text-align: center; }
}
@media (max-width: 360px) {
  :root { --gutter: 12px; }
  .footer-grid { grid-template-columns: minmax(0, 1fr); }
}

/* 7. PAYSAGE BAS --------------------------------------------------------- */
/* La barre publique cède la place (le menu du header reste disponible) ; la barre pro reste :
   c'est la seule navigation de l'espace pro sous 861 px. */
@media (max-width: 860px) and (max-height: 500px) {
  .mobile-bottom-nav { display: none; }
  body:has(.mobile-bottom-nav) { padding-bottom: 0; }
  .site-header { position: static; }
  .dir-anchors { top: 0; }
}
