/* ═══════════════════════════════════════════════════════════════════════════
   NOTAIRE — couche mobile commune (téléphone : largeur ≤ 640 px) — charte mobile v2

   Chargée en tout dernier dans base.html (juste avant </body>) : elle passe donc
   après style.css, après le CSS propre à chaque page, après le bloc <style> de la
   barre latérale et après le bloc « OVERRIDE GLOBAL » de fin de base.html.

   Ce fichier porte la coquille (barre du haut, barre de navigation du bas, menu)
   et la charte commune des pages (jetons, titres, cartes, boutons, champs, puces,
   feuilles). Les règles propres à une page restent dans son gabarit, dans un bloc
   @media (max-width: 640px), et s'appuient sur les jetons ci-dessous.

   Jetons partagés (variables) :
     --mob-top        hauteur de la barre du haut — `top` des éléments collants d'une page
     --mob-nav        hauteur de la barre de navigation du bas
     --mob-gutter     marge latérale de la page (16 px)
     --mob-radius     rayon des cartes et des feuilles (16 px) ; --mob-radius-sm : contrôles (12 px)
     --mob-ctl        hauteur des contrôles (boutons, champs, puces larges) : 44 px
     --mob-shadow     ombre des cartes ; --mob-surface : fond des cartes ; --mob-bg : fond de page
     --mob-pill       fond de l'indicateur d'onglet actif / des puces actives douces
     --mob-title      taille des titres de page (1,6 rem)

   Échelle des z-index sur mobile :
     barre du haut 9998 · barre du bas 99999 · menu 100000 · palette de recherche 100001 ·
     fenêtres modales et dialogues de page 100010 (ils couvrent les deux barres) ·
     menus flottants (popovers) 100020.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --mob-top: calc(52px + env(safe-area-inset-top, 0px));   /* = hauteur exacte de .mob-topbar */
  --mob-nav: 64px;
  --mob-gutter: 16px;
  --mob-z-modal: 100010;
  --mob-z-popover: 100020;
  --mob-radius: 16px;
  --mob-radius-sm: 12px;
  --mob-ctl: 44px;
  --mob-shadow: 0 1px 2px rgba(41,33,32,.04), 0 6px 18px rgba(41,33,32,.06);
  --mob-surface: #fff;
  --mob-bg: var(--ja-parchment);
  --mob-pill: #E2EAE2;
  --mob-pill: color-mix(in srgb, var(--ja-accent) 18%, #fff);
  --mob-title: 1.6rem;
}

@media (max-width: 640px) {

  /* ── Bases ──────────────────────────────────────────────────────────── */
  html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--mob-top) + 8px); }
  body { overscroll-behavior-y: none; background: var(--mob-bg) !important; }
  /* base.html pose `html, body { overflow-x: hidden !important }` : <body> devient alors un conteneur
     de défilement (overflow-y calculé à auto) et AUCUN position: sticky ne colle plus à l'écran
     (barre du haut, en-têtes et recherches collantes des pages). Sur <html> la valeur est reportée
     sur la fenêtre (pas de conteneur créé) ; sur <body>, `clip` coupe le débordement horizontal sans
     créer de conteneur de défilement. */
  html { overflow-x: hidden !important; }
  body { overflow-x: clip !important; }
  img, video, iframe, canvas, svg:not(.lucide) { max-width: 100%; }
  iframe { width: 100%; }
  pre { white-space: pre-wrap; overflow-wrap: anywhere; }

  /* ── Barre du haut : claire et translucide, monogramme + recherche ────── */
  body .mob-topbar {
    margin: 0 !important;
    width: 100%;
    height: var(--mob-top);
    padding: env(safe-area-inset-top, 0px) var(--mob-gutter) 0 !important;
    box-sizing: border-box;
    gap: 12px;
    background: rgba(252,250,247,.86);
    -webkit-backdrop-filter: saturate(1.6) blur(14px); backdrop-filter: saturate(1.6) blur(14px);
    border-bottom: 1px solid var(--ja-line);
  }
  /* Monogramme JA (le texte « JA Notaire » reste lisible par les lecteurs d'écran) */
  body .mob-topbar-logo {
    flex-shrink: 0; width: 30px; height: 30px; font-size: 0; opacity: 1; color: transparent;
    background: url("../notaire_logo.png") center / contain no-repeat;
    filter: brightness(0) saturate(0); opacity: .86;
  }
  /* Recherche : bouton (palette) ou champ (recherche historique) — même pastille */
  body .mob-topbar-search {
    flex: 1; min-width: 0; height: 38px; min-height: 0; box-sizing: border-box;
    display: flex; align-items: center; gap: 8px;
    padding: 0 14px; border-radius: var(--mob-radius-sm);
    background: rgba(41,33,32,.055); border: 1px solid transparent;
    color: var(--ja-gray-400); font-size: .92rem; font-weight: 500; text-align: left;
  }
  body .mob-topbar-search:active { background: rgba(41,33,32,.09); }
  body .mob-topbar-search svg { width: 17px; height: 17px; color: var(--ja-stone); opacity: .7; }
  body .mob-topbar-search input {
    background: transparent !important; border: none !important; color: var(--ja-espresso) !important;
    padding: 0 0 0 1.5rem !important; height: 36px; font-size: 16px !important;
  }
  body .mob-topbar-search input::placeholder { color: var(--ja-gray-400) !important; }
  body .mob-topbar-search .mob-topbar-search-ic { left: 14px; opacity: .55; color: var(--ja-stone); }

  body .page-wrap {
    margin-left: 0 !important;
    padding: 14px var(--mob-gutter) calc(var(--mob-nav) + 22px + env(safe-area-inset-bottom)) !important;
    max-width: 100vw !important;
    overflow-x: clip;
  }
  .page-wrap > .flash-bar { margin-bottom: 12px; }
  .flash { font-size: .86rem; padding: 11px 14px; border-radius: var(--mob-radius-sm); }

  /* ── Barre de navigation du bas : claire, indicateur d'onglet actif ────── */
  body .mob-nav {
    height: calc(var(--mob-nav) + env(safe-area-inset-bottom));
    padding: 0 4px env(safe-area-inset-bottom);
    background: rgba(255,255,255,.94);
    -webkit-backdrop-filter: saturate(1.6) blur(16px); backdrop-filter: saturate(1.6) blur(16px);
    border-top: 1px solid var(--ja-line);
    box-shadow: 0 -8px 24px rgba(41,33,32,.05);
    align-items: stretch;
  }
  body .mob-nav-item {
    flex: 1; min-width: 0; justify-content: center; gap: 4px; padding: 0 2px;
    color: var(--ja-stone); text-transform: none; letter-spacing: 0;
    font-size: 11.5px; font-weight: 700; line-height: 1.1;
    background: none; border: none; font-family: inherit; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  body .mob-nav-item:hover { color: var(--ja-stone); }
  body .mob-nav-item .mob-nav-icon {
    position: relative; display: grid; place-items: center;
    width: 58px; height: 30px; border-radius: 15px; font-size: 0;
    transition: background .2s ease, color .2s ease;
  }
  body .mob-nav-item .mob-nav-icon svg { width: 22px; height: 22px; stroke-width: 1.9; }
  body .mob-nav-item.active { color: var(--ja-accent-dark); }
  body .mob-nav-item.active .mob-nav-icon { background: var(--mob-pill); filter: none; }
  body .mob-nav-item.active .mob-nav-lbl { font-weight: 800; }
  body .mob-nav-item:active .mob-nav-icon { background: rgba(41,33,32,.07); }
  body .mob-nav-item.active:active .mob-nav-icon { background: var(--mob-pill); }
  .mob-nav-lbl { white-space: nowrap; }
  /* Pastille du nombre de tâches urgentes, accrochée à l'icône */
  body .mob-taches-badge {
    position: absolute; top: -2px; left: 33px; right: auto;
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; box-sizing: border-box;
    font-size: 11px; font-weight: 800; line-height: 18px;
    border: 2px solid #fff; animation: none;
  }
  /* Page affichée dans un cadre (?embedded=1 : fiches client / partenaire ouvertes à côté d'une liste) :
     pas de seconde coquille mobile à l'intérieur du cadre. */
  body.embedded .mob-topbar, body.embedded .mob-nav, body.embedded .mob-sheet-ov { display: none !important; }

  /* ── Menu (bouton « Menu » de la barre du bas) : feuille claire, rubriques par thème ── */
  .mob-sheet-ov { background: rgba(41,33,32,.40); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
  body .mob-sheet {
    background: var(--ja-parchment); border-top: none;
    border-radius: 24px 24px 0 0; box-shadow: 0 -12px 40px rgba(41,33,32,.18);
    padding: 8px var(--mob-gutter) calc(18px + env(safe-area-inset-bottom));
    max-height: 88vh; max-height: 88dvh; overscroll-behavior: contain;
  }
  body .mob-sheet-pull { width: 40px; height: 5px; border-radius: 3px; background: rgba(41,33,32,.16); margin: 0 auto 10px; }
  .mob-sheet-top { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
  .mob-sheet-user {
    flex: 1; min-width: 0; display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: var(--mob-radius);
    background: var(--mob-surface); box-shadow: var(--mob-shadow);
  }
  .mob-sheet-av {
    flex-shrink: 0; width: 38px; height: 38px; border-radius: 12px;
    display: grid; place-items: center; font-size: .78rem; font-weight: 900; color: #fff; letter-spacing: .02em;
  }
  .mob-sheet-who { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
  .mob-sheet-who b { font-size: .95rem; font-weight: 800; color: var(--ja-espresso); letter-spacing: -.01em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mob-sheet-who small { font-size: .74rem; font-weight: 600; color: var(--ja-gray-400); }
  .mob-sheet-close {
    flex-shrink: 0; width: 42px; height: 42px; border-radius: 50%; border: none; cursor: pointer;
    display: grid; place-items: center; background: var(--mob-surface); color: var(--ja-stone);
    box-shadow: var(--mob-shadow);
  }
  .mob-sheet-close svg { width: 20px; height: 20px; }
  body .mob-sheet-hd {
    margin: 14px 4px 7px; text-align: left;
    font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; color: var(--ja-gray-400);
  }
  body .mob-sheet-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0; }
  body .mob-sheet-item {
    display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 6px;
    min-height: 78px; padding: 10px 2px 9px; box-sizing: border-box;
    border-radius: var(--mob-radius); background: var(--mob-surface); border: 1px solid var(--ja-line);
    color: var(--ja-espresso); text-decoration: none; text-align: center;
    font-size: clamp(10.5px, 2.95vw, 12px); font-weight: 700; line-height: 1.15; letter-spacing: -.005em;
    overflow-wrap: normal; word-break: keep-all; hyphens: manual;
    -webkit-tap-highlight-color: transparent; transition: background .15s, border-color .15s;
  }
  body .mob-sheet-item:active { background: var(--ja-bg-3); }
  .mob-sheet-ic {
    flex-shrink: 0; width: 38px; height: 38px; border-radius: 12px;
    display: grid; place-items: center;
    background: var(--ja-bg-3); color: var(--ja-stone);
  }
  .mob-sheet-ic svg { width: 20px; height: 20px; }
  .mob-sec-suivi .mob-sheet-ic      { background: var(--ja-resp-ja-pale); color: var(--ja-resp-ja-ink); }
  .mob-sec-finances .mob-sheet-ic   { background: var(--ja-accent-pale); color: var(--ja-accent-dark); }
  .mob-sec-ressources .mob-sheet-ic { background: var(--ja-amber-pale); color: var(--status-warning-fg); }
  .mob-sec-compte .mob-sheet-ic     { background: var(--ja-bg-3); color: var(--ja-stone); }
  body .mob-sheet-item.mob-sheet-item-active { background: var(--ja-accent-pale); border-color: var(--ja-accent-light); color: var(--ja-accent-dark); }
  body .mob-sheet-item.mob-sheet-item-active .mob-sheet-ic { background: var(--ja-accent); color: #fff; }
  body .mob-sheet-item.mob-sheet-danger { color: var(--status-danger-fg); }
  body .mob-sheet-item.mob-sheet-danger .mob-sheet-ic { background: var(--ja-red-pale); color: var(--ja-red); }

  /* ── Charte des pages : titres ─────────────────────────────────────── */
  body .page-wrap .pg-title,
  body .page-wrap .idx-title,
  body .page-wrap .off-hd-title,
  body .page-wrap .tk-hero-title,
  body .page-wrap .ct-title,
  body .page-wrap .ph-title,
  body .page-wrap .page-title { font-size: var(--mob-title) !important; font-weight: 900 !important; line-height: 1.1 !important; letter-spacing: -.04em !important; }
  .pg-sub, .ph-sub { font-size: .86rem; line-height: 1.4; }
  .pg-header, .ct-page-header { flex-direction: column; align-items: stretch; gap: .8rem; margin-bottom: 1.2rem; }
  .pg-actions, .ct-header-right { flex-wrap: wrap; gap: .5rem; }
  .pg-actions > * { flex: 0 1 auto; }

  /* Sous-onglets horizontaux : une ligne qui défile, jamais de retour à la ligne */
  body .page-wrap .sub-tabs {
    flex-wrap: nowrap !important; overflow-x: auto !important; overscroll-behavior-x: contain;
    scrollbar-width: none; -webkit-overflow-scrolling: touch; margin-bottom: 1rem !important;
  }
  body .page-wrap .sub-tabs::-webkit-scrollbar { display: none; }
  body .page-wrap .sub-tab { padding: 10px 12px !important; white-space: nowrap !important; flex-shrink: 0; min-height: 42px; display: inline-flex; align-items: center; }
  .dossier-tabs { overflow-x: auto; scrollbar-width: none; }
  .dossier-tabs::-webkit-scrollbar { display: none; }
  .dossier-tab { white-space: nowrap; flex-shrink: 0; min-height: 42px; }

  /* ── Boutons et cibles tactiles ────────────────────────────────────── */
  .btn { min-height: var(--mob-ctl); padding: 10px 18px; border-radius: var(--mob-radius-sm); font-size: .9rem; justify-content: center; }
  .btn-sm { min-height: 38px; padding: 7px 14px; font-size: .84rem; }
  .btn:active { transform: scale(.98); }
  .check-btn { width: 22px; height: 22px; }
  button, a, [role="button"] { -webkit-tap-highlight-color: rgba(107,138,109,.18); }

  /* ── Champs de saisie : 16 px minimum (sinon iOS zoome la page au focus) ─ */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]),
  select, textarea { font-size: 16px !important; }
  select { padding-right: 1.6rem; }
  input[type="checkbox"], input[type="radio"] { accent-color: var(--ja-accent); }
  .form-card { padding: 1.15rem 1.05rem 1.35rem; border-radius: var(--mob-radius); max-width: none; box-shadow: var(--mob-shadow); border-color: transparent; }
  .form-title { font-size: 1.05rem; margin-bottom: 16px; }
  .form-row { grid-template-columns: 1fr !important; gap: 12px; }
  .form-group label { font-size: .78rem; }
  .form-group input, .form-group select, .form-group textarea { padding: 11px 13px; min-height: var(--mob-ctl); border-radius: var(--mob-radius-sm); }
  .form-group textarea { min-height: 104px; }
  .form-actions { flex-wrap: wrap; gap: 8px; margin-top: 18px; }
  .form-actions .btn { flex: 1 1 auto; justify-content: center; }

  /* ── Fenêtres modales : feuille en bas d'écran, au-dessus des deux barres ─ */
  .modal-bg { z-index: var(--mob-z-modal); padding: 0; align-items: flex-end; }
  .modal-box {
    max-width: none; width: 100%; max-height: 92vh; max-height: 92dvh;
    border-radius: 22px 22px 0 0; padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-header { border-radius: 22px 22px 0 0; padding: 14px 16px; }
  .modal-header h3 { font-size: .98rem; }
  .modal-close-btn { font-size: 1.4rem; width: 40px; height: 40px; display: grid; place-items: center; padding: 0; }
  .modal-body { padding: 16px; }
  .mail-actions, .dest-choices { flex-wrap: wrap; }
  .mail-actions .btn { flex: 1 1 auto; justify-content: center; }
  .ssl-overlay { z-index: var(--mob-z-modal); align-items: flex-end; }
  .ssl-box { width: 100%; max-width: none; border-radius: 22px 22px 0 0; align-self: flex-end; max-height: 88vh; overflow-y: auto; padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); }

  /* ── Tableaux génériques : défilement horizontal dans leur cadre ────── */
  .table-wrap, .mob-scroll-x {
    overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
    scrollbar-width: thin; max-width: 100%;
  }
  .table-wrap { border-radius: var(--mob-radius); box-shadow: var(--mob-shadow); border-color: transparent; }
  .table-wrap table { min-width: 560px; }
  th, td { padding: 10px 12px; }
  th { white-space: nowrap; }

  /* ── Grilles ───────────────────────────────────────────────────────── */
  .two-col, .three-col { grid-template-columns: 1fr !important; gap: 12px; }
  .dossiers-grid { grid-template-columns: 1fr; gap: 10px; }
  .idx-stats { flex-wrap: wrap; }
  .idx-stat { min-width: calc(50% - 5px); }

  /* ── Composants de la charte (classes à poser dans les gabarits, sans effet sur ordinateur) ──
     .m-fab        bouton flottant de l'action principale d'une page (créer), au-dessus de la barre du bas
     .m-seg        sélecteur segmenté (2 à 4 vues exclusives) ; enfants .m-seg-btn, actif .on ou .active
     .m-chips      rangée de puces de filtre qui défile ; enfants .m-chip, active .on ou .active
     .m-card       carte blanche (rayon 16, ombre douce) ; .m-card-pad pour le rembourrage standard
     .m-list       liste dans une carte ; lignes .m-row (56 px mini, filet entre lignes, chevron .m-chev)
     .m-eyebrow    intertitre de section (capitales espacées)                                        */
  .m-fab {
    position: fixed; z-index: 9990; right: var(--mob-gutter);
    bottom: calc(var(--mob-nav) + 16px + env(safe-area-inset-bottom));
    min-width: 56px; height: 56px; padding: 0 20px 0 18px; border-radius: 18px; border: none;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--ja-accent); color: #fff; font: inherit; font-size: .95rem; font-weight: 800; letter-spacing: -.01em;
    box-shadow: 0 8px 22px rgba(74,84,69,.32), 0 2px 6px rgba(41,33,32,.12);
    text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .m-fab:active { transform: scale(.97); background: var(--ja-accent-dark); }
  /* Pendant la saisie (clavier ouvert), le bouton flottant s'efface pour ne pas couvrir le champ */
  body:has(:is(input:not([type="checkbox"]):not([type="radio"]), select, textarea):focus) .m-fab { display: none; }
  .m-fab svg { width: 22px; height: 22px; stroke-width: 2.2; }
  .m-fab.m-fab-rond { width: 56px; padding: 0; border-radius: 50%; }
  .m-seg {
    display: flex; gap: 2px; padding: 3px; border-radius: var(--mob-radius-sm);
    background: var(--ja-bg-3); border: 1px solid var(--ja-line);
  }
  .m-seg .m-seg-btn {
    flex: 1 1 0; min-width: 0; min-height: 38px; padding: 0 10px; border: none; border-radius: 9px;
    background: transparent; color: var(--ja-stone); font: inherit; font-size: .88rem; font-weight: 700;
    white-space: nowrap; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  }
  .m-seg .m-seg-btn.on, .m-seg .m-seg-btn.active {
    background: var(--mob-surface); color: var(--ja-espresso); font-weight: 800;
    box-shadow: 0 1px 2px rgba(41,33,32,.08), 0 2px 8px rgba(41,33,32,.06);
  }
  .m-chips {
    display: flex; gap: 8px; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none;
    margin: 0 calc(-1 * var(--mob-gutter)); padding: 2px var(--mob-gutter);
    overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
  }
  .m-chips::-webkit-scrollbar { display: none; }
  .m-chips .m-chip {
    flex-shrink: 0; height: 36px; padding: 0 14px; border-radius: 18px;
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--mob-surface); border: 1px solid var(--ja-line-strong); color: var(--ja-stone);
    font: inherit; font-size: .86rem; font-weight: 700; white-space: nowrap; cursor: pointer;
  }
  .m-chips .m-chip.on, .m-chips .m-chip.active { background: var(--ja-espresso); border-color: var(--ja-espresso); color: var(--ja-parchment); }
  .m-card { background: var(--mob-surface); border-radius: var(--mob-radius); box-shadow: var(--mob-shadow); border: 1px solid rgba(41,33,32,.04); }
  .m-card-pad { padding: 14px 16px; }
  .m-list { background: var(--mob-surface); border-radius: var(--mob-radius); box-shadow: var(--mob-shadow); overflow: hidden; }
  .m-list .m-row {
    display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 11px 14px;
    border-top: 1px solid var(--ja-line); color: var(--ja-espresso); text-decoration: none;
  }
  .m-list .m-row:first-child { border-top: none; }
  .m-list .m-row:active { background: var(--ja-bg-2); }
  .m-chev { flex-shrink: 0; width: 16px; height: 16px; color: var(--ja-gray-400); }
  .m-eyebrow { margin: 22px 4px 8px; font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; color: var(--ja-gray-400); }

  /* ── Utilitaires partagés (à poser dans les gabarits) ──────────────── */
  .mob-hide { display: none !important; }
  .mob-stack { display: flex !important; flex-direction: column !important; align-items: stretch !important; }
  .mob-wrap { flex-wrap: wrap !important; }
  .mob-full { width: 100% !important; max-width: none !important; flex: 1 1 100% !important; }
  .mob-scroll-x > * { flex-shrink: 0; }
  /* Menus flottants (popovers positionnés en fixed par JS) : au-dessus des barres,
     et jamais plus larges que l'écran */
  .mob-popover, .fourn-popover, .ct-mp, .ct-st { z-index: var(--mob-z-popover) !important; max-width: calc(100vw - 16px); }
}

/* Les composants de la charte n'existent que sur téléphone : masqués au-delà de 640 px */
@media (min-width: 641px) {
  .m-fab, .m-mobile-only { display: none !important; }
}

/* Écran tactile sans survol : afficher d'emblée ce qui n'apparaît qu'au survol */
@media (hover: none) and (pointer: coarse) {
  .ct-emol-reset { opacity: 1; }
}
