/* ============================================================
   PortalRez — admin.css · Shell de l'interface gestionnaire
   Porté de la maquette admin.html (fidèle au pixel)
   ============================================================ */

body { background: var(--bg-2); }
.app { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 246px; flex-shrink: 0; background: var(--white); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
}
.sb-head { padding: 20px 20px 16px; border-bottom: 1px solid var(--border-soft); }
.sb-head img { height: 28px; display: block; }
.campaign {
  margin: 14px 16px 8px; background: var(--bg-2); border-radius: 10px; padding: 10px 12px;
  display: flex; align-items: center; gap: 10px; border: 1px solid transparent;
  font-weight: 600; font-size: 13px; color: var(--title);
}
.sb-nav { flex: 1; padding: 8px 12px; display: flex; flex-direction: column; gap: 3px; overflow: auto; }
.nav {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px;
  cursor: pointer; color: var(--muted); font-size: 13.5px; font-weight: 500; border: none; background: none;
  font-family: inherit; text-align: left; width: 100%; transition: background .14s, color .14s; position: relative;
  text-decoration: none;
}
.nav:hover { background: var(--bg-2); color: var(--title); }
.nav.active { background: var(--green-pale); color: var(--green-dark); font-weight: 600; }
.nav.active::before { content: ''; position: absolute; left: -12px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: var(--green); }
.nav .nav-badge { margin-left: auto; }
.nav.soon { opacity: .45; cursor: default; }
.nav.soon:hover { background: none; color: var(--muted); }
.sb-foot { padding: 14px 16px; border-top: 1px solid var(--border-soft); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--green); color: #1f3a06; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }

/* ---------- main / topbar ---------- */
.main { flex: 1; margin-left: 246px; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px; background: rgba(255,255,255,.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-soft); display: flex; align-items: center; gap: 16px;
  padding: 0 30px; position: sticky; top: 0; z-index: 30;
}
.topbar .tb-search { flex: 1; max-width: 340px; display: flex; align-items: center; gap: 9px; background: var(--bg-2); border-radius: 9px; padding: 9px 13px; }
.topbar .tb-search input { border: none; background: none; font-family: inherit; font-size: 13.5px; outline: none; flex: 1; color: var(--title); }
.icon-btn { width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--border); background: var(--white); display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); position: relative; text-decoration: none; }
.icon-btn:hover { border-color: var(--green); color: var(--green-dark); }
.content { padding: 30px; max-width: 1280px; width: 100%; min-width: 0; }

/* ---------- Débordement horizontal : jamais toute la page ----------
   Les rangées d'actions (Ajouter, Exporter, Importer CAF, Tickets…)
   passent à la ligne dès qu'elles ne tiennent plus, à TOUTE largeur —
   sinon elles poussaient la page entière en défilement latéral (visible
   par exemple sous Arc, dont la barre latérale réduit la fenêtre).
   Le retour à la ligne ne s'active que s'il manque de la place : les
   écrans larges sont inchangés. */
.row { flex-wrap: wrap; }
.row > * { min-width: 0; }
.row.between { row-gap: 10px; }
.row.nowrap { flex-wrap: nowrap; }          /* échappatoire ponctuelle */
.content .row.between > .row { justify-content: flex-end; }
/* Les tableaux, eux, défilent DANS leur carte (déjà le cas en mobile) */
.tbl-wrap, .card > div[style*="overflow-x"] { max-width: 100%; }

/* ---------- toast ---------- */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--title); color: #fff; padding: 12px 18px; border-radius: 11px; font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px; animation: toastIn .3s var(--ease); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- grilles ---------- */
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.grid-dash { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 18px; }
.grid-detail { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1080px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-dash, .grid-detail { grid-template-columns: 1fr; }
  .grid-detail .card[style*="sticky"] { position: static !important; }
}
@media (max-width: 700px) {
  .choice-grid.cols-2 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .detail-head { flex-wrap: wrap; gap: 14px; }
  .field-row { flex-direction: column; gap: 16px; }
}
@media (max-width: 640px)  { .grid-4 { grid-template-columns: 1fr; } }
.wrap { flex-wrap: wrap; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; background: var(--white); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 34px 32px; }

/* ---------- responsive : sidebar en tiroir ---------- */
.hamb { display: none; }
.scrim { display: none; }
@media (max-width: 880px){
  .sidebar { transform: translateX(-100%); transition: transform .25s var(--ease); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .hamb { display: flex; }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(45,52,54,.3); z-index: 39; }
  .content { padding: 20px; }
  .topbar { padding: 0 18px; }
}

/* ---------- cartes de choix (B3) : pas de débordement sur petits écrans ---------- */
.choice-card .cc-body { min-width: 0; }
.choice-card .cc-title, .choice-card .cc-sub { overflow-wrap: anywhere; }

/* ---------- B4 : carte de remplissage ---------- */
.grid-fill { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,2fr); gap: 28px; align-items: center; }
@media (max-width: 700px) { .grid-fill { grid-template-columns: 1fr; gap: 16px; } }

/* ---- Lot D : sous-menus dépliables de la sidebar ---- */
.nav-grp summary { list-style: none; cursor: pointer; }
.nav-grp summary::-webkit-details-marker { display: none; }
.nav-grp .nav-caret { margin-left: auto; display: flex; color: var(--faint); transition: transform .18s ease; }
.nav-grp[open] .nav-caret { transform: rotate(90deg); }
.nav-grp .nav.grp-active { color: var(--title); font-weight: 600; }
.nav-sous { display: flex; flex-direction: column; gap: 1px; margin: 1px 0 4px; }
.nav.nav-sub { padding-left: 38px; font-size: 13px; }
.nav.nav-sub.active::before { left: 14px; }

/* Lignes de tableau cliquables (résidents, dossiers) */
.tbl tbody tr[onclick] { cursor: pointer; transition: background .12s ease; }
.tbl tbody tr[onclick]:hover { background: var(--bg-2); }

/* ============================================================
   RESPONSIVE MOBILE — consolidation (PWA)
   Objectif : AUCUN débordement latéral, quel que soit l'écran
   (fiches résident/dossier, échéancier, paramètres, audit…).
   ============================================================ */
@media (max-width: 760px) {
  html, body { overflow-x: hidden; }
  .content { padding: 16px 12px 40px; min-width: 0; }
  .main { min-width: 0; }

  /* Toutes les grilles de mise en page passent en 1 colonne */
  .grid-2, .grid-3 { grid-template-columns: 1fr !important; }
  .grid-2 > *, .grid-3 > * { min-width: 0; }

  /* Cartes : jamais plus larges que l'écran */
  .card { max-width: 100%; min-width: 0; }
  .card-pad { padding: 16px 14px; }

  /* Tableaux : défilement horizontal INTERNE à la carte
     (le reste de la page ne bouge pas) */
  .tbl { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  .tbl thead, .tbl tbody, .tbl tr { display: table; width: 100%; table-layout: auto; }
  .tbl td, .tbl th { white-space: nowrap; }

  /* Rangées d'infos et de champs : retour à la ligne */
  .row { flex-wrap: wrap; }
  .row > * { min-width: 0; }
  .field-row { flex-direction: column; }
  .field-row .field { width: 100%; }

  /* En-têtes de page : titre + actions empilés proprement */
  .row.between { row-gap: 10px; }

  /* Valeurs longues (e-mails, IBAN…) : coupure propre */
  .t-small strong, .row.between strong { overflow-wrap: anywhere; }

  /* Modales : pleine largeur confortable */
  dialog { max-width: 94vw !important; }

  /* Éditeur de textes : page moins haute, padding réduit */
  .txt-page { padding: 16px 14px; max-height: 60vh; }

  /* Grilles auto-fill (permissions, logements) : cases plus étroites */
  [style*="grid-template-columns:repeat(auto-fill,minmax(215px"] { grid-template-columns: 1fr 1fr !important; }
}

@media (max-width: 430px) {
  .content { padding: 12px 10px 36px; }
  .t-h1 { font-size: 20px; }
  [style*="grid-template-columns:repeat(auto-fill,minmax(215px"] { grid-template-columns: 1fr !important; }
}

/* ---------- Recherche instantanée (barre du haut) ---------- */
.tb-resultats {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0; z-index: 60;
  background: #fff; border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 14px 40px rgba(20, 35, 10, .14);
  max-height: min(65vh, 520px); overflow-y: auto; padding: 6px;
}
.tbr-titre { font-size: 10.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: var(--faint); padding: 9px 12px 4px; }
.tbr-item { display: flex; flex-direction: column; gap: 1px; padding: 8px 12px; border-radius: 9px;
  text-decoration: none; color: inherit; }
.tbr-item:hover { background: var(--green-pale); }
.tbr-l { font-size: 13.5px; font-weight: 600; }
.tbr-s { font-size: 12px; color: var(--faint); }
.tbr-tout { display: block; text-align: center; padding: 10px; margin-top: 4px; border-top: 1px solid var(--border-soft);
  font-size: 12.5px; font-weight: 600; color: var(--green-dark); text-decoration: none; border-radius: 0 0 10px 10px; }
.tbr-tout:hover { background: var(--green-pale); }
.tbr-vide { padding: 16px; text-align: center; font-size: 12.5px; color: var(--faint); }
@media (max-width: 760px) { .tb-resultats { max-height: 55vh; } }

/* ============================================================
   Comportement « application » (PWA installée)
   Ne s'applique QU'À l'app installée (display-mode: standalone) :
   dans un onglet de navigateur classique, tout reste normal.
   ============================================================ */
@media all and (display-mode: standalone) {
  /* Le double-tap ne zoome plus : le geste est interprété comme un
     simple appui, comme dans une application native. */
  * { touch-action: manipulation; }

  /* Pas de sélection de texte accidentelle sur les éléments d'interface
     (le texte des tableaux et des documents reste sélectionnable). */
  body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  input, textarea, select, .tbl, .card p, .t-small, .doc-texte, [data-selectable] {
    -webkit-user-select: text; user-select: text; -webkit-touch-callout: default;
  }

  /* Pas de surbrillance grise au toucher : on garde nos propres états :hover/:active */
  * { -webkit-tap-highlight-color: transparent; }

  /* Rebond élastique désactivé sur la page, conservé dans les zones défilantes */
  html, body { overscroll-behavior-y: none; }

  /* Respect des encoches et de la barre de gestes (iPhone) */
  .content { padding-bottom: calc(30px + env(safe-area-inset-bottom)); }
  .topbar  { padding-top: env(safe-area-inset-top); height: calc(60px + env(safe-area-inset-top)); }
}

/* Champs de saisie : 16 px minimum sur mobile, sinon iOS zoome
   automatiquement à la mise au point (et ne dézoome jamais). */
@media (max-width: 820px) {
  input, select, textarea, .input { font-size: 16px; }
}

/* Éléments interactifs : appui immédiat, pas de zoom au double-tap
   (valable aussi dans un onglet de navigateur — sans toucher au zoom
   volontaire de la page, qui reste possible au pincement hors PWA). */
.btn, button, a, label, .tr-clic, .choice-card, .radio-opt, .tab, .nav-item {
  touch-action: manipulation;
}

/* ---------- Visionneuse de documents (PWA) ---------- */
.pr-visionneuse {
  position: fixed; inset: 0; z-index: 900; background: #fff;
  display: none; flex-direction: column;
}
.pr-visionneuse.ouverte { display: flex; }
body.pv-actif { overflow: hidden; }
.pv-barre {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  border-bottom: 1px solid var(--border); background: var(--white);
}
.pv-btn {
  display: inline-flex; align-items: center; gap: 6px; border: none; background: none;
  color: var(--green-dark); font: inherit; font-size: 15px; font-weight: 600;
  padding: 8px 6px; cursor: pointer; border-radius: 8px; touch-action: manipulation;
}
.pv-btn:active { background: var(--green-pale); }
.pv-partage { margin-left: auto; font-size: 17px; }
.pv-titre {
  flex: 1; min-width: 0; text-align: center; font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text);
}
.pv-corps { flex: 1; min-height: 0; background: #f2f2f2; }
.pv-corps iframe { width: 100%; height: 100%; border: none; display: block; }
.pv-repli { display: none; height: 100%; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 30px; text-align: center; background: #fff; }
.pv-repli i { font-size: 40px; color: var(--faint); }
.pv-repli p { margin: 0; font-size: 14px; color: var(--muted); }
.pr-visionneuse.pv-non-affichable iframe { display: none; }
.pr-visionneuse.pv-non-affichable .pv-repli { display: flex; }

/* ---------- Ouverture du menu au glissement (PWA) ----------
   Courbe de sortie douce (démarrage franc, arrivée amortie) et voile
   qui s'estompe. Pendant le geste, le JS coupe la transition pour que
   le tiroir colle au doigt ; il la rétablit à la fin, si bien que
   l'animation repart de la position atteinte, sans à-coup. */
@media (max-width: 880px) {
  .sidebar {
    transition: transform .28s cubic-bezier(.32, .72, 0, 1);
    will-change: transform;
  }
  .scrim.show {
    opacity: 1;
    transition: opacity .28s cubic-bezier(.32, .72, 0, 1);
  }
  .scrim.ferme { opacity: 0; }
  /* Pendant le glissement : pas de sélection ni de défilement parasite */
  body.menu-glisse { overflow: hidden; -webkit-user-select: none; user-select: none; }
  body.menu-glisse .sidebar { box-shadow: 0 0 40px rgba(20, 35, 10, .18); }
}
/* Respect du réglage système « réduire les animations » */
@media (prefers-reduced-motion: reduce) {
  .sidebar, .scrim.show { transition: none; }
}

/* ============================================================
   Montserrat (police de la charte ADLINP) — hébergée dans
   l'application, aucun appel à un service extérieur.
   ============================================================ */
@font-face { font-family: 'Montserrat'; src: url('../fonts/Montserrat-Regular.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Montserrat'; src: url('../fonts/Montserrat-Italic.woff2') format('woff2');
  font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: 'Montserrat'; src: url('../fonts/Montserrat-SemiBold.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Montserrat'; src: url('../fonts/Montserrat-SemiBoldItalic.woff2') format('woff2');
  font-weight: 600; font-style: italic; font-display: swap; }
@font-face { font-family: 'Montserrat'; src: url('../fonts/Montserrat-ExtraBold.woff2') format('woff2');
  font-weight: 800; font-style: normal; font-display: swap; }
@font-face { font-family: 'Montserrat'; src: url('../fonts/Montserrat-ExtraBoldItalic.woff2') format('woff2');
  font-weight: 800; font-style: italic; font-display: swap; }

/* ---------- Éditeur de textes : aperçu fidèle au document produit ----------
   Mêmes règles que le PDF (Montserrat, titres verts gras-italique, bloc
   d'identité en gras) : ce que l'on voit à l'écran est ce qui sera imprimé. */
.txt-page {
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 13px; line-height: 1.6; color: #2d3436; text-align: justify;
  background: #fff;
}
.txt-page h1 {
  font-weight: 800; font-size: 24px; line-height: 1.2; color: #14181a;
  text-transform: uppercase; letter-spacing: -.2px; margin: 0 0 4px;
}
.txt-page h2 {
  font-weight: 800; font-style: italic; font-size: 15px; color: #89BD2B;
  text-transform: uppercase; margin: 22px 0 8px; text-align: left;
}
.txt-page h3 {
  font-weight: 600; font-size: 12.5px; color: #3c4244;
  text-transform: uppercase; margin: 14px 0 6px; text-align: left;
}
/* Intertitres courts en majuscules (PRÉAMBULE, ET…) : verts, comme au rendu */
.txt-page h3.court { color: #89BD2B; font-weight: 800; font-style: italic; font-size: 15px; }
.txt-page p { margin: 0 0 7px; }
/* Bloc d'identification des parties : gras, comme sur le document */
.txt-page p.identite { font-weight: 600; }

/* ---------- Barres d'actions sur mobile ----------
   En dessous de 760 px, les boutons d'en-tête ne s'empilent plus en
   escalier aligné à droite (peu lisible et disgracieux) : le bouton
   principal occupe toute la largeur, les actions secondaires se rangent
   sur deux colonnes égales. */
@media (max-width: 760px) {
  .content .row.between {
    flex-direction: column;
    align-items: stretch !important;
    gap: 14px;
  }
  .content .row.between > .row {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    justify-content: stretch;
  }
  .content .row.between > .row > .btn,
  .content .row.between > .row > form,
  .content .row.between > .row > .btn-primary {
    width: 100%;
    justify-content: center;
    margin: 0;
  }
  /* Le bouton principal (action mise en avant) prend toute la largeur */
  .content .row.between > .row > .btn-primary,
  .content .row.between > .row > .btn:first-child {
    grid-column: 1 / -1;
  }
  /* Un bouton seul en fin de rangée s'étire plutôt que de rester à moitié */
  .content .row.between > .row > .btn:last-child:nth-child(even) {
    grid-column: 1 / -1;
  }
  .content .row.between > .row > form > .btn { width: 100%; justify-content: center; }
  /* Titre et compteur restent alignés à gauche */
  .content .row.between > div:first-child { text-align: left; }
}

/* ---------- Visionneuse : rendu page par page (PDF multi-pages) ---------- */
.pv-corps { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pv-pages { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 10px 4px 28px; }
.pv-page {
  display: block; max-width: 100%; background: #fff; border-radius: 4px;
  box-shadow: 0 2px 10px rgba(20, 35, 10, .16);
}
.pv-chargement, .pv-fin {
  padding: 26px 12px; font-size: 13px; color: var(--faint); text-align: center;
}
.pv-fin { padding: 12px; font-size: 11.5px; }
