/* 08 · MOBILE (< 768 px) — application installée sur l'écran d'accueil (PWA)
   Pas un desktop réduit : la structure change réellement. Plus de sidebar, une
   navigation flottante en bas, des feuilles qui montent du bas, des zones
   tactiles de 44 px, et toutes les marges tiennent compte des zones sûres
   (Dynamic Island, indicateur d'accueil, orientation paysage). */

@media (max-width:767px){
  input:not([type=checkbox]):not([type=radio]),textarea,select{font-size:16px;}
  :root{
    --control-h:var(--control-h-touch);
    --radius-md:12px;
    --radius-lg:16px;
    --radius-xl:22px;
    --tabbar-height:64px;
    --safe-t:env(safe-area-inset-top,0px);
    --safe-b:env(safe-area-inset-bottom,0px);
    --safe-l:env(safe-area-inset-left,0px);
    --safe-r:env(safe-area-inset-right,0px);
    /* Espace à réserver sous le contenu pour la navigation flottante */
    --tabbar-clear:calc(var(--tabbar-height) + var(--safe-b) + var(--space-8));
    /* Hauteur du haut de l'écran où rien d'important ne doit se trouver : la barre d'état + la bande floue qu'iOS
       dessine lui-même en dessous (voir le @supports en fin de fichier). */
    --bande-ios:0px;
    --haut-libre:calc(var(--safe-t) + var(--bande-ios));
  }
  html,body{font-size:var(--fs-md);}
  body{
    padding-bottom:var(--tabbar-clear);
    padding-left:var(--safe-l);padding-right:var(--safe-r);
    background:var(--background);
  }

  /* ---- Page : contenu plein écran ---- */
  .app{max-width:none;padding:0 var(--space-4);margin:0 auto;}
  .view{padding:var(--space-1) 0 var(--space-6);}
  #view-add{margin-top:0;}

  /* ---- Barre du haut : gros titre, profil à droite, sous l'îlot ---- */
  header.top{
    position:sticky;top:0;z-index:var(--z-sticky);
    padding:calc(var(--safe-t) + max(var(--space-3), calc(var(--bande-ios) + var(--space-1)))) var(--space-4) var(--space-3);
    margin:0 calc(var(--space-4) * -1);
    background:var(--background);
  }
  header.top .brand{font-size:var(--fs-3xl);font-weight:var(--fw-semibold);letter-spacing:var(--ls-tight);}
  .profile-chip{
    height:40px;padding:0 var(--space-3) 0 var(--space-1);border-radius:var(--radius-pill);
    background:var(--surface-hover);
  }
  .profile-chip .avatar{width:32px;height:32px;font-size:var(--fs-sm);}

  /* ---- Navigation flottante : 5 destinations, au-dessus du contenu ---- */
  .tabbar-row{
    position:fixed;left:calc(var(--safe-l) + var(--space-3));right:calc(var(--safe-r) + var(--space-3));
    bottom:calc(var(--safe-b) + var(--space-2));transform:none;z-index:var(--z-nav);
    display:flex;justify-content:center;
    transition:opacity var(--dur-base) var(--ease-out),transform var(--dur-base) var(--ease-out);
  }
  nav.tabs{
    flex:1;max-width:520px;height:var(--tabbar-height);padding:var(--space-1);gap:0;
    border-radius:var(--radius-2xl);align-items:stretch;
  }
  nav.tabs button{
    flex:1;min-width:0;padding:var(--space-2) var(--space-1);gap:3px;
    border-radius:calc(var(--radius-2xl) - var(--space-1));
    font-size:var(--fs-2xs);font-weight:var(--fw-medium);
  }
  nav.tabs button .ic svg{width:22px;height:22px;}
  nav.tabs button.active{color:var(--accent);}
  .tab-indicator{top:var(--space-1);bottom:var(--space-1);border-radius:calc(var(--radius-2xl) - var(--space-1));}
  /* Clavier ouvert : la navigation s'efface pour laisser tout l'espace au champ */
  :root.kb-open .tabbar-row{opacity:0;pointer-events:none;transform:translateY(12px);}
  :root.kb-open body{padding-bottom:var(--space-4);}

  /* ---- Onglets Vinted : piste arrondie qui défile au doigt ---- */
  .segmented,.segmented.glass{
    padding:3px;gap:2px;border-radius:var(--radius-pill);
    background:var(--background-secondary) !important;
  }
  .segmented button{flex:1 0 auto;height:38px;padding:0 var(--space-3);border-radius:var(--radius-pill);font-size:var(--fs-md);}
  .segmented button.active{background:var(--surface);color:var(--text-primary);box-shadow:var(--shadow-sm);}
  #vt-segmented{
    overflow-x:auto;-webkit-overflow-scrolling:touch;scrollbar-width:none;justify-content:flex-start;margin-bottom:var(--space-4);
    mask-image:linear-gradient(to right,#000 calc(100% - 28px),transparent);
    -webkit-mask-image:linear-gradient(to right,#000 calc(100% - 28px),transparent);
  }
  #vt-segmented::-webkit-scrollbar{display:none;}
  #vt-segmented button{flex:1 0 auto;white-space:nowrap;}
  /* Petits iPhone : les quatre onglets doivent tenir sans être coupés */
  @media (max-width:389px){
    .segmented button{padding:0 var(--space-2);font-size:var(--fs-sm);}
  }

  /* ---- Champs et boutons : zones tactiles ≥ 44 px, texte ≥ 16 px (pas de zoom iOS) ---- */
  input[type=text],input[type=email],input[type=password],input[type=number],input[type=date],input[type=datetime-local],input[type=search],
  textarea,.carrier-filter,.search{font-size:var(--fs-md);font-size:16px;border-radius:var(--radius-lg) !important;}
  input[type=text],input[type=email],input[type=password],input[type=number],input[type=date],input[type=datetime-local],input[type=search]{height:var(--control-h-touch);padding:0 var(--space-4);}
  .carrier-filter{height:var(--control-h-touch);padding:0 var(--space-4);}
  textarea{padding:var(--space-3) var(--space-4);}
  button.primary,a.primary,button.ghost,a.ghost,button.danger-ghost{
    height:var(--control-h-touch);padding:0 var(--space-5);
    font-size:var(--fs-base);border-radius:var(--radius-lg);
  }
  .icon-btn,.contact-remove-btn,.list-search-btn,.vt-drawer-close{width:var(--control-h-touch);height:var(--control-h-touch);}
  .detail-close{width:40px;height:40px;top:var(--space-3);right:var(--space-3);}
  .vt-row-actions .ghost,.vt-colis-actions .ghost{height:36px;}
  .vt-radio-row label{height:var(--control-h-touch);border-radius:var(--radius-lg);}
  .switch{width:48px;height:30px;}
  .switch .track::before{width:26px;height:26px;}
  .switch input:checked + .track::before{transform:translateX(18px);}

  /* ---- Listes : pleine largeur, respirantes ---- */
  .article-item,.article-item.surface{padding:var(--space-3) 0;}
  .vt-row{padding:var(--space-3) 0;gap:var(--space-3);}
  .vt-colis-row{padding:var(--space-3) 0;}
  .article-item .meta .n,.vt-row .titre,.vt-colis-row .titre{font-size:var(--fs-base);}
  .article-item img,.vt-row img{width:48px;height:48px;border-radius:var(--radius-md);}
  .vt-conv-avatar{width:44px;height:44px;}
  .list-filter-row{display:flex;align-items:center;gap:var(--space-2);margin-bottom:var(--space-3);}
  .list-filter-row .carrier-filter{flex:1;margin-bottom:0;}

  /* ---- Indicateurs : 2 colonnes lisibles ---- */
  .metrics-bar,.metrics-bar.surface{display:grid;grid-template-columns:repeat(2,1fr);padding:0;margin-bottom:var(--space-4);}
  .metric-chip{padding:var(--space-4);}
  .metric-chip + .metric-chip{border-left:none;}
  .metric-chip:nth-child(even){border-left:1px solid var(--border-subtle);}
  .metric-chip:nth-child(n+3){border-top:1px solid var(--border-subtle);}
  .metric-chip:last-child:nth-child(odd){grid-column:1 / -1;}
  .metric-value{font-size:var(--fs-xl);}
  .vt-stats-bar{display:grid;grid-template-columns:repeat(2,1fr);gap:0;margin-bottom:var(--space-4);}
  .vt-stat{padding:var(--space-4);}
  .vt-stat + .vt-stat{border-left:none;}
  .vt-stat:nth-child(even){border-left:1px solid var(--border-subtle);}
  .vt-stat:nth-child(n+3){border-top:1px solid var(--border-subtle);}
  .kpi-row{display:flex;overflow-x:auto;scrollbar-width:none;}
  .kpi-card{flex:0 0 132px;padding:var(--space-4);}
  .csv-mobile-row{display:flex;justify-content:center;margin:var(--space-2) 0 var(--space-4);}

  /* ---- Feuilles : elles montent du bas, coins généreux, poignée discrète ---- */
  .detail-modal{align-items:flex-end;justify-content:center;}
  .detail-sheet,.detail-sheet.glass{
    width:100%;max-width:none;max-height:min(90dvh, calc(100dvh - var(--haut-libre) - var(--space-2)));overflow-y:auto;
    border:none;border-radius:var(--radius-2xl) var(--radius-2xl) 0 0;
    padding:var(--space-6) var(--space-5) calc(var(--space-6) + var(--safe-b));
  }
  .detail-sheet::before{
    display:block;content:'';position:absolute;top:var(--space-2);left:50%;transform:translateX(-50%);
    width:36px;height:5px;border-radius:var(--radius-pill);background:var(--border-default);
  }
  #confirm-modal .detail-sheet,#prompt-modal .detail-sheet{max-width:none !important;}
  #confirm-modal .detail-sheet > div:last-child,#prompt-modal .detail-sheet > div:last-child,#crop-modal .detail-sheet > div:last-child{
    flex-direction:column-reverse;
  }
  #confirm-modal .detail-sheet > div:last-child button,#prompt-modal .detail-sheet > div:last-child button,#crop-modal .detail-sheet > div:last-child button{
    width:100% !important;
  }

  /* ---- Conversation : plein écran, composer arrondi au-dessus de la navigation ---- */
  .vt-composer{
    margin-top:var(--space-4);min-height:52px;border-radius:var(--radius-xl);
    padding:var(--space-1) var(--space-1) var(--space-1) var(--space-4);
  }
  .vt-composer button{width:var(--control-h-touch);height:var(--control-h-touch);}
  .vt-msg-row > div{max-width:84%;}
  .vt-msg-bubble{font-size:var(--fs-md);}
  /* Heure façon WhatsApp, nichée dans le coin bas-droit de la bulle. L'espaceur
     invisible réserve sa place en fin de texte : la dernière ligne s'arrête avant
     l'heure, ou l'heure passe sur une ligne à elle si elle ne tient pas. */
  .vt-msg-bubble{position:relative;}
  .vt-msg-time-spacer{display:inline;visibility:hidden;margin-left:10px;font-size:11px;}
  .vt-msg-time-tail{
    display:block;position:absolute;right:12px;bottom:6px;
    font-size:11px;line-height:1;color:var(--text-tertiary);white-space:nowrap;pointer-events:none;
  }
  .vt-msg-meta:not(:has(.pill-status)){display:none;}
  .vt-msg-meta:has(.pill-status){font-size:0;}
  .vt-msg-meta .pill-status{font-size:11px;}
  .vt-offer-bar{margin-bottom:var(--space-4);}

  /* ---- Recherche plein écran ---- */
  .search-overlay{background:var(--background);}
  .selection-bar{bottom:calc(var(--tabbar-height) + var(--safe-b) + var(--space-4));}

  /* ---- Notification : au-dessus de la navigation ---- */
  .app-toast{bottom:calc(var(--tabbar-height) + var(--safe-b) + var(--space-6));max-width:calc(100vw - var(--space-8));}

  /* ---- Divers ---- */
  .ext-actions{display:flex;flex-direction:column;gap:var(--space-2);margin:var(--space-4) 0 var(--space-1);}
  .ext-actions .primary,.ext-actions .ghost{width:100%;}
  .code-field{display:flex;align-items:center;gap:var(--space-2);padding:var(--space-1) var(--space-1) var(--space-1) var(--space-3);}
  .code-field code{flex:1;min-width:0;overflow-x:auto;white-space:nowrap;}
  .etapes{margin:var(--space-4) 0 0;padding-left:var(--space-5);display:flex;flex-direction:column;gap:var(--space-2);}
  .vt-set-title{font-size:var(--fs-lg);margin:var(--space-6) 0 var(--space-3);}
  .vt-settings{display:block;}
  .card{margin-bottom:var(--space-6);}
  .card.compact{margin-bottom:var(--space-5);}
}

/* Paysage sur téléphone : la navigation se fait plus basse, le titre plus discret */
@media (max-width:767px) and (orientation:landscape){
  :root{--tabbar-height:52px;}
  header.top .brand{font-size:var(--fs-2xl);}
}

/* ------------------------------------------------- Annonces : en-tête de la liste ; Créer est un onglet à part entière */
@media (max-width:767px){
  .vt-page-head{display:flex;align-items:center;justify-content:space-between;gap:var(--space-3);margin:0 0 var(--space-4);}
  .vt-page-head h2{display:none;}
  .vt-page-head button{width:auto;margin-left:auto;}
  .vt-creer .card-title{display:none;}
  .vt-creer #brouillon-mode-segmented{display:flex;overflow-x:auto;scrollbar-width:none;margin-bottom:var(--space-5) !important;}
  .vt-creer #brouillon-mode-segmented::-webkit-scrollbar{display:none;}
  .vt-creer #brouillon-mode-segmented button{flex:1 0 auto;white-space:nowrap;}
}

/* ------------------------------------------------- Formulaire de publication : rythme régulier */
.vt-creer .status-line{margin:var(--space-1) 0 var(--space-4);}
.vt-creer .status-line:empty{display:none;}
.vt-creer label.field{margin-bottom:var(--space-4);}
.vt-creer .lbl{margin-bottom:var(--space-2);}
.vt-creer .vt-radio-row{margin-bottom:var(--space-3);}

/* Ligne « prix + quand + Valider » d'un brouillon : prix et menu côte à côte, Valider en dessous, pleine largeur */
@media (max-width:767px){
  .vt-row-valider{display:grid !important;grid-template-columns:96px minmax(0,1fr);gap:var(--space-2) !important;align-items:center;}
  .vt-row-valider .vt-completer-quand{grid-column:1 / -1;}
  .vt-row-valider .field{flex:none !important;width:auto !important;}
  .vt-row-valider .vt-completer-quand{width:100%;}
  .vt-row-valider .vt-completer-date{grid-column:1 / -1;}
  .vt-row-valider .primary{grid-column:1 / -1;width:100%;padding:0 var(--space-4) !important;font-size:var(--fs-md) !important;}
}

/* ------------------------------------------------- Bande floue d'iOS en haut de l'écran
   Depuis iOS 27, dans une app ajoutée à l'écran d'accueil qui passe sous la barre d'état (black-translucent +
   viewport-fit=cover, notre cas), iPhone dessine LUI-MÊME un voile flou sous la barre d'état, qui déborde d'environ
   35-40 pt plus bas. Ce n'est pas notre CSS (il n'y a plus aucun flou dedans) et aucune propriété ni balise ne le
   désactive : la seule parade fiable est de ne rien mettre d'important dans cette bande. --haut-libre (barre d'état +
   bande) est donc la marge du haut du bandeau, de la caméra, de la recherche, de la visionneuse photo et des feuilles.
   min(..., inset × 1000) : vaut 40px dès que le contenu passe sous la barre d'état, 0 sinon (Safari en onglet,
   paysage). -webkit-touch-callout n'existe que sur iPhone/iPad : Android et ordinateur ne sont pas concernés. */
@supports (-webkit-touch-callout:none){
  @media (max-width:767px){
    :root{--bande-ios:min(40px, calc(env(safe-area-inset-top,0px) * 1000));}
  }
}

/* Scanner : Lucas préfère l'image de la caméra bord à bord (même si le tout haut de l'écran passe sous la bande
   floue d'iOS) plutôt qu'une bande noire qui mange de l'écran - pas de padding-top sur .view-camera/.video-wrap,
   contrairement au bandeau/à la recherche/aux feuilles plus haut dans ce fichier. Seul le bouton torche, lui, doit
   rester lisible : il descend sous la bande floue au lieu de rester dedans. */
@media (max-width:767px){
  .pi-apercu{padding-top:max(20px, calc(var(--haut-libre) + var(--space-2)));}
  .cam-round-btn{top:calc(var(--haut-libre) + var(--space-3));}
}

/* ------------------------------------------------- Messages : réponses toutes prêtes (js/reponses-rapides.js)
   Rangée de chips (aspect : 13-mobile-glass.css) qui défile à l'horizontale au-dessus du champ de message. */
@media (max-width:767px){
  .vt-reponses-rapides{display:flex;gap:var(--space-2);overflow-x:auto;padding:6px 12px 2px;scrollbar-width:none;}
  .vt-reponses-rapides::-webkit-scrollbar{display:none;}
  .vt-reponse-pastille{flex:none;white-space:nowrap;font:inherit;font-size:var(--fs-sm);color:var(--text-primary);cursor:pointer;}
}
