/* ============================================================
   mobile.css — version mobile de l'appli de gestion (10/11/2026)
   ------------------------------------------------------------
   Chargé APRÈS tout le reste, uniquement sur écran <= 780 px
   (attribut media du <link>) : le bureau n'est donc jamais
   touché. Ne redéfinit aucune couleur : mêmes variables que
   style.css. Aucune donnée, aucun secret.
   ============================================================ */

@media (max-width: 780px) {

  /* ---------- Base ---------- */
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { overflow-x: hidden; }
  img, video, canvas, svg, iframe { max-width: 100%; }
  img { height: auto; }
  pre, code { white-space: pre-wrap; word-break: break-word; }
  main.content, .main-v2 { overflow-wrap: break-word; }
  .main-v2 { padding-bottom: 72px; } /* place pour la barre du bas */

  /* ---------- Barre de navigation du haut (menu burger) ---------- */
  .sidebar { position: sticky; top: 0; z-index: 900; }
  .sidebar-brand {
    min-height: 56px;
    padding: 6px 66px 6px 14px;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    justify-content: flex-start;
  }
  .sidebar-brand img { max-height: 34px; width: auto; }
  .sidebar-brand span { margin-top: 0; font-size: 9.5px; }
  .sidebar-toggle { width: 44px; height: 44px; right: 8px; }
  .sidebar-scroll {
    max-height: calc(100vh - 130px);
    max-height: calc(100dvh - 130px);
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-link { padding: 13px 12px; font-size: 15px; }
  .sidebar-group-title { padding-top: 6px; }

  /* ---------- Barre de navigation du bas ---------- */
  .bottom-nav {
    display: flex !important;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 950;
    background: var(--surface);
    border-top: 1px solid var(--line-strong);
    padding: 4px 2px calc(4px + env(safe-area-inset-bottom, 0px));
  }
  .bottom-nav a, .bottom-nav button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 52px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 4px 2px;
    background: none;
    border: 0;
    border-radius: var(--radius);
    color: var(--ink-soft);
    font-family: var(--f-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-decoration: none;
    cursor: pointer;
  }
  .bottom-nav svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .bottom-nav .actif { color: var(--amber-bright); }
  .bottom-nav .bn-badge {
    position: absolute;
    top: 2px;
    left: calc(50% + 6px);
    min-width: 17px;
    padding: 1px 5px;
    border-radius: 20px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1.4;
    text-align: center;
  }
  /* L'assistant interne et la cloche remontent au-dessus de la barre du bas */
  #ai-bulle { bottom: 70px !important; }
  #ai-panneau { bottom: 134px !important; max-height: calc(100vh - 160px) !important; }

  /* ---------- Bandeau du haut de page ---------- */
  .topbar { padding: 10px 14px; min-height: 0; gap: 8px; }
  .topbar h1 { font-size: 18px !important; }
  .session-info { width: 100%; justify-content: space-between; flex-wrap: wrap; gap: 10px; }

  /* Panneaux de la cloche et de la messagerie : pleine largeur d'écran */
  #panneau-cloche-taches, #panneau-messagerie {
    position: fixed !important;
    left: 8px !important;
    right: 8px !important;
    top: 64px !important;
    width: auto !important;
    max-height: calc(100vh - 140px) !important;
    z-index: 960;
  }
  #panneau-menu-navigation { max-width: calc(100vw - 24px); }

  /* ---------- Contenu ---------- */
  main.content { padding: 14px 12px 24px; max-width: 100%; }
  .section-title { font-size: 14px; }
  .client-form, .contracts-panel, .panel { padding: 16px 14px; }
  .form-header { gap: 8px; }
  .form-header h1 { font-size: 18px; }
  .form-grid { gap: 12px; }
  .back-link { padding: 6px 0; }

  /* Cartes de chiffres : 2 par ligne pour limiter le défilement */
  .kpi-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
  .kpi-card { padding: 12px; }
  .kpi-value { font-size: 22px; }
  .kpi-label { font-size: 10px; line-height: 1.3; }

  /* ---------- Liste des clients ---------- */
  .filters-row { gap: 10px; }
  .tier-legend { gap: 8px; }
  .tier-legend + .tier-legend { padding-left: 0; border-left: none; }
  .search-row { gap: 8px; }
  .search-row input[type="search"] { min-height: 44px; }
  .client-tag { padding: 12px 14px; grid-template-columns: 1fr; gap: 4px; }
  .client-tag:hover { transform: none; }
  .badge-statut-client { position: static; justify-self: start; margin-bottom: 2px; }
  .client-tag .tag-name { font-size: 17px; }
  .client-tag .tag-meta { gap: 2px 12px; }

  /* ---------- Formulaires : pas de zoom automatique iOS, zones tactiles 44 px ---------- */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]),
  select, textarea { font-size: 16px !important; min-height: 44px; max-width: 100%; }
  textarea { min-height: 88px; }
  .checkbox-label input[type="checkbox"], .prepa-check-item input[type="checkbox"],
  input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; }
  .prepa-check-item { padding: 4px 0; font-size: 14.5px; }
  .btn-primary, .btn-danger, .btn-form-submit { min-height: 46px; }
  .btn-form-submit { width: 100%; }
  .btn-new-client { padding: 10px 16px; justify-content: center; }
  .btn-link { padding: 8px 2px; }
  .tab-btn, .tier-chip, .contract-btn { min-height: 40px; }
  .gammes-tabs, .tab-btn-row { gap: 8px; }
  .gamme-tab-btn { padding: 8px 14px; }
  .fiche-actions-row, .fiche-actions-left { flex-direction: column; align-items: stretch; }
  .fiche-actions-row .btn-primary, .fiche-actions-row .btn-danger,
  .fiche-actions-left .btn-primary, .fiche-actions-left .btn-danger { width: 100%; }
  .field-qrcode { grid-row: auto; }
  .qrcode-image { width: 120px; height: 120px; }
  .contract-qr-box { display: flex; width: 100%; }
  .champ-modifiable-en-ligne { gap: 6px; }
  .btn-check { width: 46px; min-height: 44px; }

  /* ---------- Modales : défilantes, pleine largeur, boutons empilés ---------- */
  .modal-overlay { padding: 10px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .modal-box { margin: auto; padding: 20px 16px; max-height: calc(100vh - 20px); max-height: calc(100dvh - 20px); overflow-y: auto; }
  .modal-actions { flex-direction: column-reverse; align-items: stretch; gap: 8px; }
  .modal-actions .btn-danger, .modal-actions .btn-primary { width: 100%; min-height: 46px; }
  .modal-actions > * { width: 100%; }
  .btn-croix { top: 6px; right: 8px; padding: 10px; }

  /* ---------- Tableaux ---------- */
  /* Tableaux sans en-tête reconnu : défilement horizontal plutôt qu'un débordement de la page */
  table:not(.tbl-cartes) { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* Tableaux avec en-têtes (classe ajoutée par mobile.js) : chaque ligne devient une carte */
  .tbl-cartes, .tbl-cartes tbody, .tbl-cartes tfoot, .tbl-cartes tr, .tbl-cartes td {
    display: block; width: 100%; max-width: none !important; box-sizing: border-box;
  }
  .tbl-cartes { border: 0; }
  .tbl-cartes thead { display: none; }
  .tbl-cartes tr {
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface-raised);
    margin-bottom: 10px;
    padding: 2px 0;
  }
  .tbl-cartes td {
    border: 0;
    border-bottom: 1px solid var(--line);
    padding: 8px 12px;
    white-space: normal !important;
    text-align: left;
  }
  .tbl-cartes td:last-child { border-bottom: 0; }
  .tbl-cartes td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-family: var(--f-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-soft);
    margin-bottom: 2px;
  }
  .tbl-cartes td input, .tbl-cartes td select { width: 100%; min-height: 40px; }
  .tbl-cartes tfoot tr { background: rgba(255, 255, 255, 0.03); }
  .recap-generation td:first-child { width: 45%; }

  /* ---------- Page Préinscriptions (liste + fiche) ---------- */
  .main-v2.pre-shell { height: auto; overflow: visible; }
  main.content.pre-page { overflow: visible; }
  .pre-tabs { gap: 14px; }
  .pre-split { gap: 12px; }
  .pre-toolbar { padding: 10px; gap: 6px; }
  .btn-pre { padding: 10px 12px; font-size: 13px; min-height: 40px; }
  .pre-outils { padding: 8px 10px; flex-wrap: wrap; }
  .pre-outils input[type=search] { font-size: 16px; min-height: 40px; }
  .pre-rows { max-height: 65vh; }
  .pre-head {
    grid-template-columns: 40px 1fr;
  }
  .pre-head span { display: none; }
  .pre-head::after { content: "Tout sélectionner"; }
  .pre-row {
    grid-template-columns: 40px minmax(0, 1fr) auto;
    grid-template-areas: "chk nom place" ". gam dat";
    row-gap: 4px;
    padding: 10px 12px;
  }
  .pre-row .pre-check-cell { grid-area: chk; align-self: start; padding: 6px 0; }
  .pre-row .pre-nom { grid-area: nom; }
  .pre-row .pre-place { grid-area: place; }
  .pre-row .pre-gamme { grid-area: gam; }
  .pre-row .pre-date { grid-area: dat; text-align: right; }
  .pre-nom strong, .pre-mail { white-space: normal; overflow-wrap: anywhere; }
  .pre-detail-corps { padding: 16px 14px; }
  #pre-statut { margin-left: 0; width: 100%; }

  /* ---------- Catalogue d'articles de la fiche client (client.php) ----------
     Son bloc de style est placé plus bas dans la page : « body » relève la priorité. */
  body .acc-catalogue .tbl-cartes tr.ligne-catalogue {
    display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; padding: 8px 10px;
  }
  body .acc-catalogue .tbl-cartes tr.ligne-catalogue > td { width: auto; border: 0; padding: 2px 0; }
  body .acc-catalogue td.cat-coche-cell { width: 36px; flex: 0 0 36px; }
  body .acc-catalogue .tbl-cartes tr.ligne-catalogue > td:nth-child(2) { flex: 1 1 calc(100% - 60px); font-weight: 600; }
  body .acc-catalogue .table-intervention input.cat-coche { width: 24px; height: 24px; }
  body .acc-catalogue .table-intervention input.cat-qte { width: 72px; }
  .acc-catalogue > summary, .acc-cat > summary { padding: 14px; }

  /* ---------- Divers ---------- */
  .membre-ligne { padding: 12px; }
  .membre-actions { gap: 10px; }
  .mdp-genere-box { padding: 14px; }
  .login-shell { padding: 14px; }
  .login-card { padding: 24px 18px; }
}

/* Très petits écrans : cartes de chiffres sur une colonne */
@media (max-width: 360px) {
  .kpi-grid { grid-template-columns: 1fr !important; }
  .sidebar-brand span { display: none; }
  .bottom-nav a, .bottom-nav button { font-size: 9px; }
}
