/* Appli téléphone de LDK Atelier (app/js/telephone.js, telephone-appareils.js, signature-telephone.js, lier.js).
   - Mise en page téléphone (560 px de large et moins) : barre d'onglets en bas à la place de la barre latérale,
     barre du haut allégée, écrans clés utilisables au doigt à 375 px, sans défilement horizontal.
   - Feuille « Plus », écran de signature plein écran (toute largeur : un téléphone ou une tablette liés),
     page de liaison /lier.html.
   Uniquement des variables du thème (clair et sombre) ; la barre d'onglets reprend le bleu nuit de la barre latérale. */

/* ---------- Barre d'onglets du bas ---------- */
.tel-onglets { display: none; }

/* Hauteur prise par la barre d'onglets (0 au-dessus de 560 px et en plein écran). Toute barre collée en bas de page
   (position: sticky ou fixed, bottom: …) doit s'en écarter : `bottom: var(--tel-bas, 0px)`, sinon les onglets la
   recouvrent et reçoivent ses clics. Les barres des pages existantes sont décalées ci-dessous. */
:root { --tel-bas: 0px; }
@media (max-width: 560px) {
  :root { --tel-bas: calc(62px + env(safe-area-inset-bottom)); }
  body.plein-ecran { --tel-bas: 0px; }
  /* (body:not(.plein-ecran) : plus précis que le <style> de la page, qui est lu après cette feuille) */
  body:not(.plein-ecran) .rg-bar { bottom: calc(var(--tel-bas) + 10px); }          /* Réglages : Enregistrer */
  body:not(.plein-ecran) .rn-pied,                                                  /* nouvelle prise en charge */
  body:not(.plein-ecran) .ra-pied,                                                  /* rachat */
  body:not(.plein-ecran) .vp-barre { bottom: var(--tel-bas); }                      /* ventes (options, échéancier…) */
}

@media (max-width: 560px) {
  .tel-onglets {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    height: calc(62px + env(safe-area-inset-bottom)); padding: 0 4px env(safe-area-inset-bottom);
    background: var(--side-bg); border-top: 1px solid #1d2840; box-shadow: 0 -6px 20px rgba(2, 6, 23, .18);
  }
  .tel-onglets a, .tel-onglets button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0;
    color: #8b97ab; font: inherit; font-size: 11px; font-weight: 550; letter-spacing: .01em; text-decoration: none;
    border: 0; background: none; padding: 6px 2px 4px; position: relative; cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .tel-onglets a:hover { text-decoration: none; }
  .tel-onglets span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tel-onglets .on { color: #fff; }
  .tel-onglets .on svg { color: #2dd4bf; }
  .tel-onglets .on::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: #2dd4bf; }
  .marque-perso .tel-onglets .on svg { color: var(--marque-vive); }
  .marque-perso .tel-onglets .on::before { background: var(--marque-vive); }
  .tel-pastille {
    position: absolute; top: 5px; left: calc(50% + 5px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
    background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; line-height: 18px; text-align: center;
    box-shadow: 0 0 0 2px var(--side-bg);
  }
  .tel-pastille[hidden] { display: none; }
  body.plein-ecran .tel-onglets { display: none; }

  /* La barre latérale reste joignable par « Plus › Tout le menu » ; le bouton menu du haut laisse la place au titre. */
  .topbar .menu-btn { display: none; }
  .topbar { gap: 6px; padding: 0 10px 0 14px; }
  .topbar [data-aide], .topbar [data-theme] { display: none; } /* dans la feuille « Plus » */
  .topbar .top-actions { gap: 2px; }
  .topbar .top-actions .btn.primary { width: 40px; padding: 0; }
  .topbar .top-search { width: 40px; height: 40px; min-width: 40px; padding: 0; justify-content: center; }
  /* 16 px sur les côtés, comme sous 860 px : certaines rangées défilantes (filtres) comptent sur cette marge. */
  .content { padding: 14px 16px calc(88px + env(safe-area-inset-bottom)); }
  .toasts { left: 12px; right: 12px; bottom: calc(72px + env(safe-area-inset-bottom)); align-items: stretch; }

  /* Écrans clés au doigt : cibles de 40 px au moins, en-têtes qui passent à la ligne, rien qui dépasse. */
  /* Sur html seulement : sur body, overflow ferait de body la zone de défilement et casserait la barre du haut collante. */
  html { overflow-x: hidden; }
  .main, .content { max-width: 100vw; }
  .page-head { flex-wrap: wrap; gap: 10px; }
  .page-head .titles { min-width: 0; flex: 1 1 100%; }
  .page-head h1 { font-size: 21px; overflow-wrap: anywhere; }
  .page-head .btn-row { width: 100%; }
  .page-head .btn-row > .btn { flex: 1 1 auto; }
  .btn { min-height: 40px; }
  .btn.sm { min-height: 34px; }
  .btn.icon { min-width: 40px; }
  .btn.icon.sm { min-width: 34px; }
  .input, .select { height: 42px; font-size: 16px; } /* 16 px : pas de zoom automatique sur iPhone */
  .textarea { font-size: 16px; }
  .tabs { overflow-x: auto; scrollbar-width: none; flex-wrap: nowrap; }
  .tabs::-webkit-scrollbar { display: none; }
  .chips { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; padding-bottom: 2px; }
  .chips::-webkit-scrollbar { display: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .card { min-width: 0; }
  .kv { grid-template-columns: minmax(92px, 36%) minmax(0, 1fr); }
  .kv dd, .kv > * { overflow-wrap: anywhere; min-width: 0; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 auto; }
  .sig-pad { height: 200px; }
  .overlay { padding: 2vh 6px calc(6px + env(safe-area-inset-bottom)); }
}

/* ---------- Feuille « Plus » ---------- */
.tel-feuille-fond { position: fixed; inset: 0; z-index: 95; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-end; animation: fade .15s ease; }
.tel-feuille {
  width: 100%; background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: var(--shadow-l);
  padding: 8px 14px calc(76px + env(safe-area-inset-bottom)); max-height: 86vh; overflow-y: auto; animation: tel-monter .2s ease;
}
@keyframes tel-monter { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .tel-feuille { animation: none; } }
.tel-poignee { width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 2px auto 12px; }
.tel-grille { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tel-tuile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 78px; padding: 8px 4px;
  border: 1px solid var(--line-2); border-radius: 14px; background: var(--surface-2); color: var(--ink-2); font: inherit; font-size: 12px;
  font-weight: 550; text-align: center; cursor: pointer; position: relative; text-decoration: none !important;
}
.tel-tuile svg { color: var(--brand); }
.tel-tuile:active { background: var(--surface-3); }
.tel-nb { position: absolute; top: 6px; right: 8px; min-width: 18px; height: 18px; border-radius: 99px; background: var(--danger); color: #fff; font-size: 10.5px; line-height: 18px; padding: 0 5px; }
.tel-nb[hidden] { display: none; }
.tel-moi {
  display: flex; align-items: center; gap: 10px; width: 100%; margin-top: 12px; padding: 10px 12px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.tel-moi .grow { display: flex; flex-direction: column; min-width: 0; }
@media (min-width: 561px) { .tel-feuille { max-width: 480px; margin: 0 auto; padding-bottom: 20px; } }
/* Sur téléphone, la feuille s'arrête au-dessus de la barre d'onglets : « Plus » la referme. */
@media (max-width: 560px) {
  .tel-feuille-fond { bottom: calc(62px + env(safe-area-inset-bottom)); }
  .tel-feuille { padding-bottom: 14px; }
  .chips .chip { flex: none; white-space: nowrap; }
}

/* ---------- Écran de signature plein écran (téléphone lié) ---------- */
body.tel-plein-ouvert { overflow: hidden; }
.tel-plein { position: fixed; inset: 0; z-index: 400; background: var(--bg); display: flex; flex-direction: column; overscroll-behavior: contain; }
.ts-tete { display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px 16px; background: var(--side-bg); color: #fff; flex: none; }
.ts-marque { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; font-weight: 650; }
.ts-marque img { width: 30px; height: 30px; object-fit: contain; border-radius: 8px; background: #fff; flex: none; }
.ts-mono { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: #1f2a40; color: #5eead4; font-weight: 700; flex: none; }
.ts-tete .btn.ghost { color: #cbd5e1; }
.ts-tete .btn.ghost:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.ts-corps { flex: 1; min-height: 0; width: 100%; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; }
.ts-ref { font-size: 11.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.ts-intro h1 { font-size: 22px; margin-top: 2px; }
.ts-client { font-size: 17px; font-weight: 650; color: var(--brand); margin-top: 4px; overflow-wrap: anywhere; }
.ts-conditions { flex: none; max-height: 30vh; overflow-y: auto; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink-2); font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.ts-cadre { position: relative; flex: 1 1 auto; min-height: 190px; }
.ts-cadre .ts-pad { position: absolute; inset: 0; width: 100%; height: 100%; border-width: 2px; }
.ts-ligne { position: absolute; left: 22px; right: 22px; bottom: 30px; border-top: 1.5px solid #cbd5e1; color: #94a3b8; font-size: 12px; padding-top: 4px; pointer-events: none; }
.ts-msg { color: var(--danger); font-size: 13.5px; font-weight: 550; margin: 0; }
.ts-actions { display: flex; gap: 10px; flex: none; }
.ts-actions .btn { flex: 1 1 0; min-height: 50px; font-size: 15.5px; }
.ts-actions .btn.primary { flex-grow: 2; }
.ts-refus { align-self: center; border: 0; background: none; color: var(--muted); font: inherit; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; padding: 6px; cursor: pointer; }
.ts-fin { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px; padding: 24px 8px; }
.ts-fin h1 { font-size: 24px; }
.ts-fin p { color: var(--muted); max-width: 420px; }
.ts-fin-ic { width: 76px; height: 76px; border-radius: 24px; display: grid; place-items: center; background: var(--warn-soft); color: var(--warn); }
.ts-fin.ok .ts-fin-ic { background: var(--ok-soft); color: var(--ok); }
.ts-fin .btn { min-width: 200px; min-height: 50px; }
/* Téléphone à l'horizontale : conditions plus courtes, plus de place pour signer. */
@media (max-height: 500px) {
  .ts-corps { padding-top: 10px; gap: 8px; }
  .ts-intro h1 { font-size: 18px; }
  .ts-client { font-size: 15px; margin-top: 0; }
  .ts-conditions { max-height: 22vh; font-size: 13px; padding: 8px 12px; }
  .ts-cadre { min-height: 150px; }
  .ts-actions .btn { min-height: 44px; }
}

/* ---------- Page de liaison /lier.html ---------- */
.lier { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); background: var(--bg); }
.lier-boite { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 26px 22px; display: flex; flex-direction: column; gap: 16px; }
.lier-ic { width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.lier-ic.ok { background: var(--ok-soft); color: var(--ok); }
.lier-boite h1 { font-size: 22px; }
.lier-boite p { color: var(--ink-2); }
.lier-code { font: 650 24px/1 ui-monospace, "SF Mono", Menlo, monospace !important; letter-spacing: .18em; text-align: center; text-transform: uppercase; height: 56px !important; }
.lier-erreur { color: var(--danger); font-weight: 550; font-size: 14px; }
.lier-astuce { font-size: 13px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 12px; padding: 10px 12px; }
.lier-astuce b { color: var(--ink-2); }
