/**
 * Couche mobile Speecho — à charger EN DERNIER sur les pages app.
 *
 * Règle d'or : tout est enfermé dans @media (max-width: 768px).
 * Au-dessus de 768px ce fichier n'applique rien, donc la version
 * desktop et tablette reste strictement inchangée.
 */

@media (max-width: 768px) {
  /* ---- Confort de base ---- */
  html {
    -webkit-text-size-adjust: 100%;
  }

  body {
    overscroll-behavior-y: contain;
    -webkit-tap-highlight-color: transparent;
  }

  /* Pas de zoom automatique au focus : iOS zoome sous 16px. */
  input,
  select,
  textarea {
    font-size: 16px;
  }

  /* ---- Barre du haut : compacte et collante ---- */
  .side {
    position: sticky;
    top: 0;
    z-index: 40;
    padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
    background: var(--panel-bg, #f7f8fa);
    backdrop-filter: saturate(1.4) blur(8px);
  }

  .side .logo {
    padding: 2px 4px;
    font-size: 1.1rem;
  }

  .side .nav-toggle {
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
  }

  /* ---- Cibles tactiles : plancher à 44px ---- */
  button,
  .btn,
  a.btn,
  .nav-btn,
  select,
  .chips button,
  [role="button"] {
    min-height: 44px;
  }

  .chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .chips button {
    padding-inline: 14px;
  }

  /* ---- Marges latérales respirables, sans scroll horizontal ---- */
  .shell > .wrap,
  .main {
    padding-left: 16px;
    padding-right: 16px;
    /* Les rangees de filtres debordent volontairement jusqu'au bord ;
       « clip » borne ce debord sans creer de conteneur de defilement
       (contrairement a overflow:hidden, qui casserait les positions sticky). */
    overflow-x: clip;
  }

  /* ---- Barre d'onglets ---- */
  .tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 2px;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface, #fff) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(12px);
    border-top: 1px solid var(--line, #e2e6ec);
  }

  .tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 50px;
    padding: 4px 2px;
    border-radius: 12px;
    text-decoration: none;
    color: var(--muted, #667085);
    font-size: 0.66rem;
    font-weight: 650;
    letter-spacing: -0.01em;
    line-height: 1.1;
    text-align: center;
  }

  .tabbar a svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .tabbar a[aria-current="page"] {
    color: var(--accent, #2f5d8c);
    background: var(--accent-soft, #e8eef5);
  }

  .tabbar a:active {
    transform: scale(0.95);
  }

  /* La barre masquerait le bas de page : on rend la hauteur au contenu. */
  body.has-tabbar .main,
  body.has-tabbar .shell > .wrap {
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }

  /* Le menu hamburger ne sert plus qu'au compte : on retire les doublons. */
  body.has-tabbar .side-menu .side-label,
  body.has-tabbar .side-menu .nav-wrap {
    display: none;
  }

  body.has-tabbar .side.is-open .side-foot {
    display: block;
    margin-top: 0;
    padding-top: 10px;
  }

  /* ---- Statistiques du profil : 3 tuiles sur une ligne ---- */
  .stat-grid,
  .profile-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .stat-grid > *,
  .profile-stats > * {
    padding: 12px 10px;
    text-align: center;
  }

  /* ---- Titres : moins de hauteur perdue ---- */
  h1 {
    font-size: clamp(1.5rem, 7vw, 1.9rem);
    line-height: 1.15;
  }

  h2 {
    font-size: 1.2rem;
  }

  .lead {
    font-size: 0.95rem;
  }
}

/* En TWA/PWA plein écran, la barre d'adresse n'existe pas :
   on récupère la place et on neutralise le rebond élastique. */
@media (display-mode: standalone), (display-mode: fullscreen) {
  html,
  body {
    overscroll-behavior: none;
  }
}

/* Le portail d'auth masque .shell : la barre d'onglets doit suivre. */
body.auth-gate .tabbar {
  display: none;
}

/* =======================================================================
   Passe « app » — au-delà du responsive.
   Une app ne se présente pas à chaque ouverture : l'onglet actif dit déjà
   où on est. On rend l'espace au contenu et on met l'action sous le pouce.
   ======================================================================= */
@media (max-width: 768px) {
  /* ---- Barre du haut : logo + titre de l'écran + menu ---- */
  .side-head {
    gap: 10px;
  }

  .appbar-title {
    flex: 1;
    min-width: 0;
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: -0.02em;
    color: var(--ink, #1c2430);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
  }

  /* Le logo cède la place au titre : il reste cliquable mais discret. */
  body.has-tabbar .side .logo {
    font-size: 0.95rem;
    opacity: 0.55;
  }

  /* ---- Chrome marketing : hors de l'app ---- */
  body.has-tabbar .wrap > .badge,
  body.has-tabbar .wrap > .hero-title,
  body.has-tabbar .wrap > .lead,
  body.has-tabbar .main > .profile-header > .lead {
    display: none;
  }

  /* Le quota reste, mais en pastille compacte plutôt qu'en ligne perdue. */
  body.has-tabbar .wrap > .hint {
    display: inline-block;
    margin: 2px 0 12px;
    padding: 5px 11px;
    border-radius: 999px;
    background: var(--accent-soft, #e8eef5);
    color: var(--accent, #2f5d8c);
    font-size: 0.78rem;
    font-weight: 700;
  }

  /* ---- Filtres : une seule ligne, qu'on balaie au pouce ---- */
  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* Débord jusqu'aux bords : on voit qu'il y a une suite. */
    margin-inline: -16px;
    padding-inline: 16px;
    padding-bottom: 2px;
  }

  .chips::-webkit-scrollbar {
    display: none;
  }

  .chips button {
    flex: 0 0 auto;
    scroll-snap-align: start;
  }

  /* ---- Action principale sous le pouce ---- */
  .brief-actions {
    position: sticky;
    bottom: calc(80px + env(safe-area-inset-bottom));
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-inline: -16px;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom) / 2);
    background: color-mix(in srgb, var(--canvas, #eef1f4) 94%, transparent);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line, #e2e6ec);
  }

  .brief-actions .btn-coral {
    width: 100%;
    font-size: 1rem;
    min-height: 52px;
  }

  .brief-actions .btn-ghost {
    width: 100%;
  }

  /* ---- Panneaux : moins de boîte, plus de contenu ---- */
  .panel {
    border-radius: 16px;
    padding: 14px;
  }

  /* ---- Formulaires longs : repliés par défaut ---- */
  .m-fold > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 48px;
    padding: 4px 2px;
    cursor: pointer;
    list-style: none;
    font-weight: 750;
  }

  .m-fold > summary::-webkit-details-marker {
    display: none;
  }

  .m-fold > summary::after {
    content: "";
    width: 9px;
    height: 9px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    opacity: 0.5;
    transition: transform 0.15s ease;
  }

  .m-fold[open] > summary::after {
    transform: rotate(-135deg);
  }

  .m-fold + .m-fold {
    border-top: 1px solid var(--line, #e2e6ec);
  }
}
