@import url('tokens.css');

/* =====================================================================
   Techni-Pierre — base + composants communs + éditeur complet + documents A4
   Toutes les valeurs viennent de tokens.css (voir DESIGN.md).
   Les composants partagés (bouton, champ, carte, badge, modale…) sont définis
   ICI une seule fois, pour toutes les pages ; simple.css, entreprise.css,
   nav.css et admin.css n'ajoutent que la mise en page propre à chaque écran.
   ===================================================================== */

/* ---------- 0. Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: var(--fw-regular) var(--fs-md) / var(--lh-normal) var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, a, select, summary, label { touch-action: manipulation; }
h1, h2, h3 { font-family: var(--font-sans); font-weight: var(--fw-semibold); line-height: var(--lh-tight); letter-spacing: var(--tracking-tight); margin: 0; }
::placeholder { color: var(--text-faint); opacity: 1; }
::selection { background: var(--ring); }

/* focus clavier visible partout */
:focus-visible { outline: 2px solid var(--accent-500); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }
:focus:not(:focus-visible) { outline: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* =====================================================================
   1. COMPOSANTS COMMUNS
   ===================================================================== */

/* ---------- Bouton ----------
   secondaire (défaut) : .btn .e-btn .tp-prev-btn
   principal (accent)  : .btn-primary .e-btn.ok .tp-prev-btn.main .s-cta
   fantôme             : .btn.ghost .e-btn.ghost .s-ghost
   danger              : .btn-danger .e-btn.danger */
.btn, .e-btn, .tp-prev-btn, .s-cta, .s-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-1-5); min-height: var(--h-md); padding: 0 var(--space-3);
  border: var(--border-w) solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs);
  font: var(--fw-medium) var(--fs-md) / 1 var(--font-sans); text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast), opacity var(--dur-fast);
}
.btn:hover, .e-btn:hover, .tp-prev-btn:hover { background: var(--surface-3); }
.btn:disabled, .e-btn:disabled, .tp-prev-btn:disabled, .s-cta:disabled, .s-ghost:disabled { opacity: 0.5; pointer-events: none; }
.btn-primary, .e-btn.ok, .tp-prev-btn.main, .s-cta { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); box-shadow: none; }
.btn-primary:hover, .e-btn.ok:hover, .tp-prev-btn.main:hover, .s-cta:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost, .e-btn.ghost, .s-ghost { background: none; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn.ghost:hover, .e-btn.ghost:hover, .s-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-danger, .e-btn.danger { background: var(--danger); border-color: var(--danger); color: var(--primary-fg); box-shadow: none; }
.btn.ok { color: var(--success-text); }
.btn.sm { min-height: var(--h-sm); padding: 0 var(--space-3); font-size: var(--fs-sm); }
.e-btn.big { min-height: var(--h-lg); padding: 0 var(--space-4); }
.link { background: none; border: 0; color: var(--text-2); cursor: pointer; padding: var(--space-1) 0; text-decoration: underline; text-underline-offset: 3px; font-size: var(--fs-sm); }
.link:hover { color: var(--text); }

/* ---------- Champ (texte, liste, zone de texte) ---------- */
.field input, .field select, .field textarea, .search, .e-search, .e-form input, .e-form select, .e-date-in, .e-note-add textarea,
.s-field input, .s-note, .key-row input, .key-model select, .ad-in, .ad-model select, .ad-link, .tp-login-card input, .add-line input, .toolbar select {
  min-height: var(--h-md); padding: 0 var(--space-3); border: var(--border-w) solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text);
  font: var(--fw-regular) var(--fs-md) / var(--lh-normal) var(--font-sans); letter-spacing: var(--tracking-normal); text-transform: none; box-shadow: var(--shadow-xs); min-width: 0;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.field input, .field select, .field textarea, .search { width: 100%; }
.field textarea, .e-note-add textarea, .s-note { padding: var(--space-2) var(--space-3); }
.field input:focus, .field select:focus, .field textarea:focus, .search:focus, .e-search:focus, .e-form input:focus, .e-form select:focus, .e-date-in:focus, .e-note-add textarea:focus,
.s-field input:focus, .s-note:focus, .key-row input:focus, .key-model select:focus, .ad-in:focus, .ad-model select:focus, .tp-login-card input:focus, .add-line input:focus, .toolbar select:focus {
  outline: none; border-color: var(--accent-500); box-shadow: var(--focus-ring);
}
input:disabled, select:disabled, textarea:disabled { opacity: 0.5; cursor: not-allowed; }
select { cursor: pointer; }
.field select, .e-form select, .key-model select, .ad-model select, select.ad-in, .toolbar select, .t-row select, .st, .e-statut {
  -webkit-appearance: none; appearance: none; background-image: var(--icon-chevron); background-repeat: no-repeat; background-position: right var(--space-3) center; padding-right: var(--space-8);
}
/* label de champ : 13 px, gris moyen, pas de majuscules */
.field .lbl, .e-form label, .s-field, .tp-login-card label, .key-model, .ad-model, .tech-grid label {
  font: var(--fw-medium) var(--fs-sm) / var(--lh-snug) var(--font-sans); color: var(--text-2); text-transform: none; letter-spacing: var(--tracking-normal);
}
.field { display: flex; flex-direction: column; gap: var(--space-1-5); }
.check { display: flex; gap: var(--space-2); align-items: center; margin: var(--space-3) 0 var(--space-1); font-size: var(--fs-md); cursor: pointer; min-height: var(--h-sm); }
.check input, .ad-actif input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- Carte ---------- */
.card, .e-card, .s-card, .key-card, .kpi {
  background: var(--surface); border: var(--border-w) solid var(--border); border-radius: var(--radius-lg);
}
.card, .e-card { padding: var(--card-pad); margin-bottom: var(--section-gap); }
.card-h { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.card-h h2, .e-card h2 { font-size: var(--fs-lg); font-weight: var(--fw-semibold); letter-spacing: var(--tracking-tight); }
.hint, .e-muted { color: var(--text-muted); font-size: var(--fs-sm); }
.empty, .e-empty { color: var(--text-muted); font-size: var(--fs-md); margin: var(--space-2) 0; }
.empty { text-align: center; padding: var(--space-6); margin: 0; }

/* ---------- Titre de page ---------- */
.pg-title, .e-head h1, .e-hello h1, .e-fiche-id h1 { font-size: var(--fs-title); font-weight: var(--fw-semibold); letter-spacing: var(--tracking-tight); line-height: var(--lh-tight); margin: 0; }

/* ---------- Badge (pastille + texte) ---------- */
.badge, .e-badge, .key-badge, .e-count {
  display: inline-flex; align-items: center; gap: var(--space-1-5); min-height: 22px; padding: 0 var(--space-2); border-radius: var(--radius-full);
  border: var(--border-w) solid var(--border); background: var(--surface); color: var(--text-2);
  font: var(--fw-medium) var(--fs-xs) / 1 var(--font-sans); letter-spacing: var(--tracking-normal); white-space: nowrap; vertical-align: middle; flex: none;
}
.e-badge { background: color-mix(in srgb, var(--c, var(--text-muted)) 7%, var(--surface)); border-color: color-mix(in srgb, var(--c, var(--text-muted)) 22%, var(--surface)); }
.e-badge::before, .key-badge.ok::before, .key-badge.err::before { content: ''; width: 6px; height: 6px; border-radius: var(--radius-full); background: var(--c, var(--text-muted)); flex: none; }
.e-count { background: var(--surface-3); border-color: transparent; font-variant-numeric: tabular-nums; }
.key-badge.ok { --c: var(--success); }
.key-badge.err { --c: var(--danger); color: var(--danger-text); }

/* ---------- Pastille de filtre ---------- */
.chips, .e-chips, .quick { display: flex; flex-wrap: wrap; gap: var(--space-1-5); align-items: center; }
.chip, .e-chip, .chip-q {
  display: inline-flex; align-items: center; gap: var(--space-1-5); min-height: var(--h-sm); padding: 0 var(--space-3); border: var(--border-w) solid var(--border); border-radius: var(--radius-full);
  background: var(--surface); color: var(--text-2); font: var(--fw-medium) var(--fs-sm) / 1 var(--font-sans); cursor: pointer; white-space: nowrap;
  transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}
button.chip:hover, .e-chip:hover, .chip-q:hover { background: var(--surface-3); color: var(--text); }
.chip.on, button.chip.on:hover, .e-chip.on, .e-chip.on:hover { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.e-chip i { width: 6px; height: 6px; border-radius: var(--radius-full); background: var(--c); flex: none; }
.e-chip b { font-weight: var(--fw-regular); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.e-chip.on b { color: inherit; opacity: 0.7; }
.chip.ok, .chip.warn, .chip.ia { cursor: default; min-height: 24px; padding: 0 var(--space-2); font-size: var(--fs-xs); }
.chip.ok { background: var(--surface-3); border-color: transparent; }
.chip.ia { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.chip.warn { background: var(--danger-soft); border-color: transparent; color: var(--danger-text); white-space: normal; padding: var(--space-1) var(--space-2); line-height: var(--lh-snug); }
.chips { margin-top: var(--space-3); }
.chips-lbl { color: var(--text-muted); font-size: var(--fs-sm); margin-right: var(--space-1); }
.chips-break { flex-basis: 100%; height: 0; }

/* ---------- Modale / feuille ---------- */
.s-modal, .tp-prev {
  position: fixed; inset: 0; z-index: var(--z-modal); background: var(--overlay); display: grid; place-items: center; padding: var(--space-4);
  animation: fade var(--dur) both;
}
.s-modal[hidden], .tp-prev[hidden] { display: none; }
.s-modal-card {
  background: var(--surface); border: var(--border-w) solid var(--border); border-radius: var(--radius-lg); width: 100%; max-width: var(--modal-w); max-height: 90vh; max-height: 90dvh; overflow-y: auto;
  padding: var(--space-6); box-shadow: var(--shadow-lg); animation: rise var(--dur-slow) var(--ease-out) both;
}
.s-modal-h { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.s-modal-h h2 { font-size: var(--fs-xl); font-weight: var(--fw-semibold); }
.s-x, .tp-prev-x {
  display: inline-grid; place-items: center; flex: none; width: var(--h-sm); height: var(--h-sm); border: 0; border-radius: var(--radius-md); background: none; color: var(--text-muted);
  font-size: var(--fs-md); cursor: pointer; transition: background var(--dur-fast), color var(--dur-fast);
}
.s-x:hover, .tp-prev-x:hover { background: var(--surface-3); color: var(--text); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pulse { 50% { opacity: 0.3; } }
/* téléphone : la modale devient une feuille qui monte du bas */
@media (max-width: 640px) {
  .s-modal, .tp-prev { padding: 0; place-items: end stretch; }
  .s-modal-card { max-width: none; max-height: 92vh; max-height: 92dvh; border-width: var(--border-w) 0 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: var(--space-5) var(--space-4) calc(var(--space-5) + env(safe-area-inset-bottom)); }
}

/* ---------- Aperçu d'un document (éditeur : .tp-prev ; autres pages : .e-prev-wrap) ---------- */
.tp-prev-box, .e-prev-wrap {
  width: min(var(--preview-w), 100%); max-height: 94vh; max-height: 94dvh; display: flex; flex-direction: column; background: var(--surface);
  border: var(--border-w) solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-lg); animation: rise var(--dur-slow) var(--ease-out) both;
}
.tp-prev-bar, .e-prev-bar { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4); border-bottom: var(--border-w) solid var(--border); background: var(--surface); }
.tp-prev-bar strong, .e-prev-bar strong { font-size: var(--fs-md); font-weight: var(--fw-semibold); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-prev-bar .spacer, .e-prev-bar .spacer { flex: 1; }
.tp-paper, .e-paper { background: var(--surface-3); padding: var(--space-6); overflow: auto; -webkit-overflow-scrolling: touch; }
/* la feuille garde toujours sa vraie largeur A4 ; sur petit écran elle est réduite en entier (zoom posé par app.js) */
.tp-paper .doc, .e-paper .doc { box-sizing: border-box; width: var(--a4-w); max-width: none; margin: 0 auto; padding: 40px 44px; background: var(--paper); color: var(--paper-text); border: var(--border-w) solid var(--border); box-shadow: var(--shadow-md); }
.pdf-page .doc { padding: 0; }
@media (max-width: 640px) {
  .tp-prev-box, .e-prev-wrap { width: 100%; max-height: 96vh; max-height: 96dvh; border-width: var(--border-w) 0 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .tp-prev-bar strong, .e-prev-bar strong { flex: 1; }
  .tp-prev-bar .spacer, .e-prev-bar .spacer { display: none; }
  .tp-prev-bar .tp-prev-btn { order: 3; flex: 1; }
  .tp-paper, .e-paper { padding: var(--space-2) var(--space-2) calc(var(--space-2) + env(safe-area-inset-bottom)); }
}
@media print { .tp-prev { display: none !important; } }

/* ---------- Message bref ---------- */
#toast, #tp-sync {
  position: fixed; left: 50%; z-index: var(--z-toast); max-width: calc(100vw - var(--space-8)); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  background: var(--primary); color: var(--primary-fg); font: var(--fw-medium) var(--fs-md) / var(--lh-snug) var(--font-sans); text-align: center; box-shadow: var(--shadow-lg);
}
#toast { bottom: var(--space-6); transform: translate(-50%, 12px); opacity: 0; pointer-events: none; transition: opacity var(--dur), transform var(--dur) var(--ease-out); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#tp-sync { bottom: var(--space-4); transform: translateX(-50%); font-size: var(--fs-sm); }

/* ---------- Vignette d'appareil : illustration en fond, photo réelle par-dessus si elle existe ---------- */
.visual { position: relative; display: block; background: var(--paper); border-radius: var(--radius-md); overflow: hidden; }
.visual:not(:has(img)) { background: var(--surface-3); }
.visual svg { position: absolute; inset: 14% 18%; width: 64%; height: 72%; }
/* images normalisées en carré (fond blanc ou photo plein cadre) : on remplit la vignette */
.visual img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--paper); }
.visual::after { content: ''; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--neutral-950) 8%, transparent); pointer-events: none; }
.q-img { width: 56px; height: 56px; flex: none; }
.q-id { flex: 1; min-width: 0; }
.l-img { width: 32px; height: 32px; border-radius: var(--radius-sm); }
.v-ico svg { inset: 14%; width: 72%; height: 72%; }

/* ---------- Utilitaires ---------- */
.row { display: flex; align-items: center; }
.gap { gap: var(--space-2); margin-top: var(--space-3); flex-wrap: wrap; }
.gap0 { gap: var(--space-2); }
.mt { margin-top: var(--space-4); }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.grid3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-3); }
.span2 { grid-column: span 2; }
.warn-t { color: var(--warning-text); font-weight: var(--fw-medium); }
.ok-t { color: var(--success-text); font-weight: var(--fw-medium); }
/* iOS : pas de zoom automatique quand on touche un champ (16 px minimum) */
@media (pointer: coarse) {
  input:not([type='checkbox']):not([type='radio']):not([type='file']), select, textarea { font-size: max(16px, 1em) !important; }
}

/* =====================================================================
   2. ÉDITEUR COMPLET (index.html)
   ===================================================================== */
/* Barre du haut d'origine (masquée dès que le menu commun est chargé) */
.topbar { background: var(--surface); border-bottom: var(--border-w) solid var(--border); position: sticky; top: 0; z-index: var(--z-sticky); }
.topbar-inner { max-width: var(--content-wide); margin: 0 auto; display: flex; align-items: center; gap: var(--space-6); padding: var(--space-2) var(--page-pad); }
.logo { height: 36px; width: auto; }
.tabs { display: flex; gap: var(--space-1); overflow-x: auto; }
.tabs button { background: none; border: 0; color: var(--text-muted); padding: 0 var(--space-3); min-height: var(--h-md); border-radius: var(--radius-md); cursor: pointer; font: var(--fw-medium) var(--fs-md) var(--font-sans); white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--surface-3); color: var(--text); }
.mode-switch { margin-left: auto; color: var(--text-2); text-decoration: none; font: var(--fw-medium) var(--fs-sm) var(--font-sans); border: var(--border-w) solid var(--border); padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); white-space: nowrap; }
.mode-switch + .mode-switch { margin-left: var(--space-1-5); }
.mode-switch:hover { background: var(--surface-3); color: var(--text); }
.topbar-inner .tp-admin-link { color: var(--text-muted); text-decoration: none; font: var(--fw-medium) var(--fs-sm) var(--font-sans); }

main { max-width: var(--content-wide); margin: 0 auto; padding: var(--space-6) var(--page-pad) var(--space-20); }
.tab { display: none; }
.tab.active { display: block; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: var(--section-gap); align-items: start; }
.col-right { position: sticky; top: var(--space-6); }
@media (max-width: 1100px) {
  .editor { grid-template-columns: 1fr; }
  .col-right { position: static; }
}

/* Dictée express : carte en retrait, sans fond sombre */
.card-dictee { background: var(--surface-2); }
.card-dictee textarea {
  width: 100%; border: var(--border-w) solid var(--border); background: var(--surface); color: var(--text); border-radius: var(--radius-md); padding: var(--space-3);
  resize: vertical; font-size: var(--fs-md); box-shadow: var(--shadow-xs); transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.card-dictee textarea:focus { outline: none; border-color: var(--accent-500); box-shadow: var(--focus-ring); }
.btn-mic { gap: var(--space-2); }
.btn-mic .dot { width: 8px; height: 8px; border-radius: var(--radius-full); background: var(--danger); }
.btn-mic.rec { background: var(--danger); border-color: var(--danger); color: var(--primary-fg); }
.btn-mic.rec .dot { background: currentColor; animation: pulse 1s infinite; }

/* Choix segmenté, pas à pas, cases */
.seg { display: flex; flex-wrap: wrap; gap: var(--space-1-5); }
.seg button {
  border: var(--border-w) solid var(--border); background: var(--surface); color: var(--text-2); border-radius: var(--radius-md); padding: 0 var(--space-3); min-height: var(--h-md); cursor: pointer;
  font-size: var(--fs-md); font-weight: var(--fw-medium); box-shadow: var(--shadow-xs); transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}
.seg button:hover { background: var(--surface-3); color: var(--text); }
.seg button.on { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }

.stepper { display: flex; border: var(--border-w) solid var(--border); border-radius: var(--radius-md); overflow: hidden; background: var(--surface); min-height: var(--h-md); box-shadow: var(--shadow-xs); transition: border-color var(--dur-fast), box-shadow var(--dur-fast); }
.stepper:focus-within { border-color: var(--accent-500); box-shadow: var(--focus-ring); }
.stepper button { border: 0; background: var(--surface-2); width: var(--h-md); flex: none; font-size: var(--fs-lg); cursor: pointer; color: var(--text-2); transition: background var(--dur-fast); }
.stepper button:hover { background: var(--surface-3); }
.stepper input { border: 0; text-align: center; width: 100%; min-width: 0; padding: 0 var(--space-1); background: none; font-weight: var(--fw-medium); font-variant-numeric: tabular-nums; }
.stepper input:focus { outline: none; }

.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.tog {
  display: flex; align-items: center; gap: var(--space-2); text-align: left; border: var(--border-w) solid var(--border); background: var(--surface); border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3); min-height: var(--h-md); cursor: pointer; font-size: var(--fs-md); box-shadow: var(--shadow-xs); transition: background var(--dur-fast), border-color var(--dur-fast);
}
.tog:hover { background: var(--surface-2); }
.tog .box { width: 16px; height: 16px; border-radius: 4px; border: var(--border-w) solid var(--border-strong); background: var(--surface); flex: none; position: relative; }
.tog.on { border-color: var(--border-strong); }
.tog.on .box { background: var(--accent); border-color: var(--accent); }
.tog.on .box::after { content: ''; position: absolute; inset: 1px; background: var(--accent-fg); -webkit-mask: var(--icon-check) center / contain no-repeat; mask: var(--icon-check) center / contain no-repeat; }

/* Choix de l'appareil */
.search { margin-bottom: var(--space-1); }
.brands { margin: var(--space-3) 0; }
.app-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-3); max-height: 620px; overflow-y: auto; padding: var(--space-0-5); }
.app {
  text-align: left; border: var(--border-w) solid var(--border); background: var(--surface); border-radius: var(--radius-lg); padding: var(--space-2) var(--space-2) var(--space-3); cursor: pointer;
  display: flex; flex-direction: column; gap: var(--space-0-5); transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.app:hover { border-color: var(--border-strong); }
.app.on { border-color: var(--accent-500); box-shadow: 0 0 0 1px var(--accent-500); }
.app-img { aspect-ratio: 1 / 1; margin-bottom: var(--space-2); border-radius: var(--radius-md); }
.app-brand { font-size: var(--fs-xs); color: var(--text-muted); padding: 0 var(--space-1); }
.app-name { font-weight: var(--fw-medium); font-size: var(--fs-md); padding: 0 var(--space-1); }
.app-meta { font-size: var(--fs-xs); color: var(--text-muted); padding: 0 var(--space-1); }
.app-price { font-size: var(--fs-sm); font-weight: var(--fw-medium); margin-top: var(--space-0-5); padding: 0 var(--space-1); font-variant-numeric: tabular-nums; }
.ph { display: flex; flex-direction: column; align-items: center; gap: var(--space-0-5); }
.ph-btn { border: 0; background: none; padding: 0; cursor: pointer; }
.ph-img { width: 48px; height: 48px; }
.ph-btn:hover .ph-img { box-shadow: 0 0 0 2px var(--accent-500); }
.ph-acts { display: flex; gap: var(--space-1-5); }
.ph-acts .link { padding: 0; font-size: var(--fs-xs); }

/* Distance automatique */
.geo-hint { margin-top: var(--space-2); font-size: var(--fs-sm); color: var(--text-muted); display: flex; align-items: center; gap: var(--space-1-5); flex-wrap: wrap; min-height: 20px; }
.geo-dot { width: 6px; height: 6px; border-radius: var(--radius-full); background: var(--text-faint); flex: none; }
.geo-dot.ok { background: var(--success); }
.geo-dot.warn { background: var(--warning); }
.geo-dot.pulse { background: var(--accent-500); animation: pulse 1s infinite; }

/* Panneau devis */
.quote-h { display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); padding-bottom: var(--space-4); border-bottom: var(--border-w) solid var(--border); }
.q-num { font-weight: var(--fw-semibold); font-size: var(--fs-lg); letter-spacing: var(--tracking-tight); }
.q-client { color: var(--text-muted); font-size: var(--fs-sm); }
.q-ttc { text-align: right; }
.q-ttc span { display: block; font-size: var(--fs-xs); color: var(--text-muted); }
.q-ttc strong { font-size: var(--fs-2xl); font-weight: var(--fw-semibold); letter-spacing: var(--tracking-tight); font-variant-numeric: tabular-nums; white-space: nowrap; }

.alerts { list-style: none; padding: 0; margin: var(--space-3) 0 0; display: flex; flex-direction: column; gap: var(--space-1-5); }
.alerts li { font-size: var(--fs-sm); padding: var(--space-2) var(--space-3) var(--space-2) var(--space-8); border-radius: var(--radius-md); border: var(--border-w) solid var(--border); position: relative; color: var(--text-2); }
.alerts li::before { position: absolute; left: var(--space-3); top: var(--space-2); font-weight: var(--fw-bold); }
.alerts li.info::before { content: 'i'; color: var(--text-muted); }
.alerts li.warn { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 25%, transparent); }
.alerts li.warn::before { content: '!'; color: var(--warning-text); }

.lines { margin-top: var(--space-4); }
.sec { margin-bottom: var(--space-4); }
.sec-h { display: flex; justify-content: space-between; font-weight: var(--fw-medium); font-size: var(--fs-sm); color: var(--text-muted); padding: var(--space-2) 0 var(--space-1-5); border-bottom: var(--border-w) solid var(--border); font-variant-numeric: tabular-nums; }
.line { display: grid; grid-template-columns: 32px minmax(0, 1fr) 54px 46px 78px 86px 26px; gap: var(--space-1-5); align-items: center; padding: var(--space-1) 0; border-bottom: var(--border-w) solid var(--border); font-size: var(--fs-md); font-variant-numeric: tabular-nums; }
.sec .line:last-child { border-bottom: 0; }
.line input { border: var(--border-w) solid transparent; background: none; padding: var(--space-1) var(--space-1-5); border-radius: var(--radius-sm); min-width: 0; width: 100%; transition: border-color var(--dur-fast); }
.line input:hover { border-color: var(--border); }
.line input:focus { border-color: var(--accent-500); background: var(--surface); outline: none; }
.l-qty, .l-pu { text-align: right; }
.l-u { color: var(--text-muted); font-size: var(--fs-xs); }
.l-tot { text-align: right; font-weight: var(--fw-medium); white-space: nowrap; }
.l-del { border: 0; background: none; color: var(--text-faint); font-size: var(--fs-lg); cursor: pointer; border-radius: var(--radius-sm); width: 26px; height: 26px; transition: background var(--dur-fast), color var(--dur-fast); }
.l-del:hover { background: var(--danger-soft); color: var(--danger-text); }
.line.edited { box-shadow: inset 2px 0 0 var(--accent-500); padding-left: var(--space-1-5); }
.line.manual .l-des { font-style: italic; }
@media (max-width: 560px) {
  .line { grid-template-columns: 30px minmax(0, 1fr) 48px 76px 26px; }
  .l-u, .l-tot { display: none; }
}

.add-line { display: flex; gap: var(--space-2); margin-top: var(--space-3); }
.add-line input { flex: 1; border-style: dashed; box-shadow: none; }
.add-line input:focus { border-style: solid; }

.totals { margin-top: var(--space-4); border-top: var(--border-w) solid var(--border); padding-top: var(--space-3); font-variant-numeric: tabular-nums; }
.t-row { display: flex; justify-content: space-between; align-items: center; padding: var(--space-1) 0; font-size: var(--fs-md); gap: var(--space-3); }
.t-row em { color: var(--text-muted); font-style: normal; font-size: var(--fs-xs); }
.t-row.big { font-weight: var(--fw-semibold); font-size: var(--fs-xl); letter-spacing: var(--tracking-tight); border-top: var(--border-w) solid var(--border); margin-top: var(--space-2); padding-top: var(--space-3); }
.t-row.muted { color: var(--text-muted); }
.mini { width: 56px; border: var(--border-w) solid var(--border); border-radius: var(--radius-sm); padding: var(--space-0-5) var(--space-1-5); text-align: right; background: var(--surface); }
.mini:focus { outline: none; border-color: var(--accent-500); box-shadow: var(--focus-ring); }
.t-row select { border: var(--border-w) solid var(--border); border-radius: var(--radius-sm); padding: var(--space-0-5) var(--space-6) var(--space-0-5) var(--space-1-5); background-color: var(--surface); background-position: right var(--space-1-5) center; }
.marge { margin-top: var(--space-3); font-size: var(--fs-xs); color: var(--success-text); border-top: var(--border-w) dashed var(--border); padding-top: var(--space-3); }
.marge.low { color: var(--danger-text); }
.actions { display: flex; gap: var(--space-2); justify-content: flex-end; margin-top: var(--space-4); flex-wrap: wrap; }

/* Pages liste / catalogue / réglages */
.page { max-width: var(--content-max); margin: 0 auto; }
.page.narrow { max-width: var(--content-narrow); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--space-3); margin-bottom: var(--section-gap); }
.kpi { padding: var(--space-4); }
.kpi span { display: block; font-size: var(--fs-sm); color: var(--text-muted); }
.kpi strong { display: block; font-size: var(--fs-xl); font-weight: var(--fw-semibold); letter-spacing: var(--tracking-tight); margin-top: var(--space-1); font-variant-numeric: tabular-nums; }
.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-md); font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-muted); padding: var(--space-2); border-bottom: var(--border-w) solid var(--border); white-space: nowrap; }
.tbl td { padding: var(--space-2); border-bottom: var(--border-w) solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl .r { text-align: right; }
.tbl .sub { font-size: var(--fs-xs); color: var(--text-muted); }
.tbl .acts { display: flex; gap: var(--space-1-5); justify-content: flex-end; flex-wrap: wrap; }
.tbl input { border: var(--border-w) solid transparent; background: none; border-radius: var(--radius-sm); padding: var(--space-1) var(--space-1-5); width: 100%; min-width: 0; transition: border-color var(--dur-fast); }
.tbl input:hover { border-color: var(--border); }
.tbl input:focus { border-color: var(--accent-500); outline: none; background: var(--surface); }
.tbl .w-num { width: 80px; text-align: right; }
.tbl .w-ref { width: 110px; }
.card:has(.tbl) { overflow-x: auto; }
.count { font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: var(--space-2); }
/* statut d'un devis : même pastille que les badges d'étape */
.st, .e-statut {
  min-height: var(--h-sm); border: var(--border-w) solid var(--border); border-radius: var(--radius-md); background-color: var(--surface); color: var(--text);
  padding-left: var(--space-3); font: var(--fw-medium) var(--fs-sm) var(--font-sans); box-shadow: var(--shadow-xs);
}
.st-accepté { color: var(--success-text); }
.st-refusé { color: var(--danger-text); }
.st-envoyé { color: var(--accent-text); }
.e-statut { box-shadow: var(--shadow-xs), inset 3px 0 0 var(--c, var(--border)); }
.banner { background: var(--surface-2); border: var(--border-w) solid var(--border); border-radius: var(--radius-lg); padding: var(--space-3) var(--space-4); font-size: var(--fs-sm); color: var(--text-2); margin-bottom: var(--space-4); }
.banner code { background: var(--surface-3); padding: var(--space-px) var(--space-1); border-radius: 4px; font: var(--fs-xs) var(--font-mono); }
.toolbar { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-3); align-items: center; }
.toolbar .search { width: 260px; margin: 0; }
.tech-row td { padding-top: 0; }
.tech-row summary { cursor: pointer; font-size: var(--fs-xs); color: var(--text-muted); padding: var(--space-0-5) 0 var(--space-2); }
.tech-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--space-2); padding-bottom: var(--space-3); }
.tech-grid label { display: flex; flex-direction: column; font-size: var(--fs-xs); gap: var(--space-1); }
.tech-grid input { border: var(--border-w) solid var(--border) !important; background: var(--surface) !important; }
.key-link-inline { margin-left: var(--space-2); color: var(--text-muted); font-weight: var(--fw-regular); text-underline-offset: 3px; }
.key-link-inline:hover { color: var(--text); }

@media (max-width: 900px) { .tech-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) {
  main { padding: var(--space-4) var(--page-pad) var(--space-10); }
  .logo { height: 30px; }
  .grid2, .toggles { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .quote-h { flex-wrap: wrap; }
  .actions .btn { flex: 1; }
  .toolbar .search { width: 100%; }
}

/* =====================================================================
   3. CONNEXION (mode en ligne) et bandeaux
   ===================================================================== */
#tp-login { position: fixed; inset: 0; z-index: var(--z-login); background: var(--surface-2); display: grid; place-items: center; padding: var(--space-4); overflow-y: auto; }
#tp-login[hidden] { display: none; }
.tp-login-card { width: min(380px, 100%); background: var(--surface); border: var(--border-w) solid var(--border); border-radius: var(--radius-lg); padding: var(--space-8) var(--space-6) var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); }
.tp-login-card img { height: 56px; align-self: center; margin-bottom: var(--space-1); }
.tp-login-card h1 { font-size: var(--fs-2xl); text-align: center; }
.tp-login-card label, .tp-f { display: flex; flex-direction: column; }
.tp-login-card label { gap: var(--space-1-5); }
.tp-f { gap: var(--space-4); }
.tp-login-card input { min-height: var(--h-lg); font-size: var(--fs-lg); }
.tp-login-card button[type=submit], .tp-f button[type=submit] {
  border: 0; border-radius: var(--radius-md); background: var(--accent); color: var(--accent-fg); font: var(--fw-medium) var(--fs-lg) var(--font-sans); min-height: var(--h-lg); padding: 0 var(--space-4); cursor: pointer;
  transition: background var(--dur-fast), opacity var(--dur-fast);
}
.tp-login-card button[type=submit]:hover, .tp-f button[type=submit]:hover { background: var(--accent-hover); }
.tp-f button[type=submit]:disabled { opacity: 0.5; }
.tp-login-card .lien { border: 0; background: none; color: var(--text-muted); font: var(--fw-medium) var(--fs-sm) var(--font-sans); cursor: pointer; min-height: var(--h-md); border-radius: var(--radius-md); text-decoration: underline; text-underline-offset: 3px; }
.tp-login-card .lien:hover { color: var(--text); }
.tp-login-msg { background: var(--danger-soft); color: var(--danger-text); border-radius: var(--radius-md); padding: var(--space-2) var(--space-3); margin: 0; font-size: var(--fs-sm); }
.tp-login-sub { text-align: center; color: var(--text-muted); margin: 0; font-size: var(--fs-md); }
.tp-code { text-align: center; font: var(--fw-semibold) var(--fs-2xl) var(--font-mono) !important; letter-spacing: 0.3em; }
#tp-assist { position: sticky; top: 0; z-index: var(--z-banner); background: var(--info); color: var(--primary-fg); font: var(--fw-medium) var(--fs-sm) var(--font-sans); padding: var(--space-2) var(--space-4); display: flex; gap: var(--space-3); align-items: center; justify-content: center; flex-wrap: wrap; }
#tp-assist button { border: 0; background: var(--surface); color: var(--text); font: var(--fw-medium) var(--fs-xs) var(--font-sans); padding: 0 var(--space-3); min-height: 28px; border-radius: var(--radius-md); cursor: pointer; }

/* =====================================================================
   4. DOCUMENTS IMPRIMÉS (devis, bon de commande, factures) — A4
   Exception assumée aux jetons : un document papier a ses propres valeurs
   fixes (points typographiques, encres) et ne suit ni le thème ni l'écran.
   html2canvas (PDF) ne comprend pas color-mix() : rester en couleurs simples.
   ===================================================================== */
#print { display: none; }
@page { size: A4; margin: 12mm 12mm 14mm; }
@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #1f1a16; font-size: 10pt; }
  #app, #toast { display: none !important; }
  #print { display: block; }
}
.doc { color: #1f1a16; font-family: var(--font-sans); font-size: 9.5pt; line-height: 1.4; letter-spacing: 0; }
.doc h1 { letter-spacing: 0; font-weight: 700; }
.d-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.d-brand { display: flex; gap: 14px; align-items: flex-start; }
.d-logo img { height: 64px; display: block; }
.d-soc { font-size: 8.5pt; color: #4a423b; }
.d-soc strong { color: #1f1a16; font-size: 10pt; }
.d-certif { margin-top: 4px; color: #b9650f; font-weight: 700; }
.d-title { text-align: right; }
.d-title h1 { font-size: 26pt; letter-spacing: 0.04em; text-transform: uppercase; color: #de801d; line-height: 1; margin-bottom: 6px; }
.d-title table { margin-left: auto; font-size: 9pt; border-collapse: collapse; }
.d-title td { padding: 1px 0 1px 12px; }
.d-title td:first-child { color: #8a8178; }
.d-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0 10px; }
.d-box { border: 1px solid #e3d9c8; border-radius: 6px; padding: 8px 10px; min-height: 64px; }
.d-lbl { font-size: 7.5pt; text-transform: uppercase; letter-spacing: 0.06em; color: #8a8178; font-weight: 700; margin-bottom: 3px; }
.d-objet { margin: 8px 0 10px; display: flex; align-items: center; gap: 12px; }
.d-objet p { margin: 0; }
.d-photo { width: 70px; height: 70px; object-fit: contain; border: 1px solid #e3d9c8; border-radius: 6px; }
.d-lines { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.d-lines th { background: #1f1a16; color: #fff; font-weight: 600; font-size: 8pt; text-transform: uppercase; letter-spacing: 0.04em; padding: 5px 6px; text-align: left; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.d-lines td { padding: 4px 6px; border-bottom: 1px solid #efe7da; vertical-align: top; }
.d-lines .r { text-align: right; white-space: nowrap; }
.d-lines tr { break-inside: avoid; }
.d-sec td { background: #f6f0e6; font-weight: 700; color: #b9650f; text-transform: uppercase; font-size: 8pt; letter-spacing: 0.05em; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.d-sub td { font-size: 8.5pt; color: #4a423b; text-align: right; border-bottom: 1px solid #e3d9c8; }
.d-sub td.r { font-weight: 700; }
.d-ref { color: #8a8178; font-size: 8pt; }
.d-bottom { display: grid; grid-template-columns: 1fr 285px; gap: 18px; margin-top: 14px; break-inside: avoid; }
.d-cond { font-size: 8pt; color: #4a423b; }
.d-cond p { margin: 0 0 6px; }
.d-totals { width: 100%; border-collapse: collapse; font-size: 9.5pt; font-variant-numeric: tabular-nums; }
.d-totals td { padding: 4px 6px; }
.d-totals .r { text-align: right; }
.d-totals td.r { white-space: nowrap; vertical-align: bottom; }
.d-totals .ttc td { background: #de801d; color: #fff; font-weight: 700; font-size: 11pt; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.d-totals .d-acompte td { font-weight: 700; color: #b9650f; }
.d-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; break-inside: avoid; font-size: 9pt; }
.d-sign-box { border: 1px solid #e3d9c8; border-radius: 6px; padding: 8px 10px; height: 90px; font-weight: 700; }
.d-sign-box span { font-weight: 400; font-size: 8pt; color: #8a8178; }
.d-foot { margin-top: 18px; padding-top: 6px; border-top: 1px solid #e3d9c8; font-size: 7.5pt; color: #8a8178; text-align: center; }
/* Caractéristiques techniques sur le devis */
.d-tech { margin: 4px 0 2px; padding: 5px 8px; background: #faf6ef; border-left: 2px solid #de801d; font-size: 7.6pt; line-height: 1.45; color: #4a423b; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.d-tech b { color: #1f1a16; font-weight: 700; }
.d-tech-t { display: block; font-weight: 700; color: #b9650f; text-transform: uppercase; letter-spacing: 0.04em; font-size: 7pt; }
.d-tech-src { display: block; color: #8a8178; font-size: 6.8pt; margin-top: 1px; }
/* Bon de commande / factures */
.d-cert { margin-top: 12px; border: 1px solid #e3d9c8; border-radius: 6px; padding: 8px 10px; font-size: 8.2pt; line-height: 1.45; break-inside: avoid; }
.d-cert b { font-weight: 700; }
.d-cert-note { display: block; margin-top: 4px; color: #8a8178; font-size: 7.2pt; }
.doc-facture .d-title h1, .doc-acompte .d-title h1 { color: #1f1a16; }
.doc-bc .d-title h1 { color: #2f6db5; }
.doc-bc .d-title h1, .doc-acompte .d-title h1 { font-size: 17pt; white-space: nowrap; }
.doc-facture .d-title h1 { font-size: 22pt; }

/* ---------- Fenêtre d'envoi d'e-mail (PDF joint, envoyé par le serveur) ---------- */
.tp-mail { position: fixed; inset: 0; z-index: var(--z-modal); display: grid; place-items: center; padding: var(--space-4); background: var(--overlay); }
.tp-mail[hidden] { display: none; }
.tp-mail-card { width: 100%; max-width: var(--modal-w); max-height: 92vh; overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-5); background: var(--surface); border: var(--border-w) solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.tp-mail-h { display: flex; align-items: center; justify-content: space-between; }
.tp-mail-h h2 { margin: 0; font: var(--fw-semibold) var(--fs-xl) / var(--lh-tight) var(--font-sans); }
.tp-mail-f { display: flex; flex-direction: column; gap: var(--space-1-5); font: var(--fw-medium) var(--fs-sm) / 1 var(--font-sans); color: var(--text-2); }
.tp-mail-f input, .tp-mail-f textarea { width: 100%; box-sizing: border-box; padding: var(--space-2) var(--space-3); border: var(--border-w) solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text); font: var(--fs-md) / var(--lh-normal) var(--font-sans); }
.tp-mail-f input { height: var(--h-lg); }
.tp-mail-f textarea { resize: vertical; }
.tp-mail-f input:focus, .tp-mail-f textarea:focus { outline: none; border-color: var(--border-strong); box-shadow: var(--focus-ring); }
.tp-mail-pj { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border: var(--border-w) solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); font-size: var(--fs-sm); }
.tp-mail-pj span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-mail-pj small { color: var(--text-muted); }
.tp-mail-pj .ic { width: 16px; height: 16px; color: var(--text-muted); }
.tp-mail-act { display: flex; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap; }
@media (max-width: 640px) { .tp-mail { padding: 0; place-items: end stretch; } .tp-mail-card { border-radius: var(--radius-lg) var(--radius-lg) 0 0; } .tp-mail-act > * { flex: 1; } }

/* ---------- logo de l'entreprise (Réglages) ---------- */
.logo-reglage { display: flex; align-items: center; gap: var(--space-4); margin-bottom: var(--space-4); padding-bottom: var(--space-4); border-bottom: var(--border-w) solid var(--border); }
.logo-reglage .hint { margin: var(--space-1) 0 var(--space-2); }
.logo-reglage .btn { margin-right: var(--space-2); }
.logo-apercu { flex: none; width: 160px; height: 80px; display: grid; place-items: center; padding: var(--space-2); border: var(--border-w) dashed var(--border-strong); border-radius: var(--radius-md); background: var(--paper); color: var(--text-muted); font-size: var(--fs-sm); }
.logo-apercu img { max-width: 100%; max-height: 100%; object-fit: contain; }
.d-logo-txt { font: 700 16pt var(--font-sans); color: #1f1a16; max-width: 180px; }
@media (max-width: 640px) { .logo-reglage { flex-direction: column; align-items: flex-start; } }
.tp-mail-ok { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); padding: var(--space-6) var(--space-4); text-align: center; animation: rise var(--dur-slow) var(--ease-out) both; }
.tp-mail-ok h2 { margin: 0; font: var(--fw-semibold) var(--fs-2xl) / 1.2 var(--font-sans); }
.tp-mail-ok p { margin: 0; color: var(--text-muted); font-size: var(--fs-md); }
.tp-mail-ok-ic { width: 56px; height: 56px; display: grid; place-items: center; border-radius: var(--radius-full); background: var(--success-soft); color: var(--success); }
.tp-mail-ok-ic .ic { width: 28px; height: 28px; }
/* bandeau « mode démo » (localhost uniquement) */
.tp-demo-bandeau { position: sticky; top: 0; z-index: var(--z-banner); padding: var(--space-1-5) var(--space-4); background: var(--warning-soft); color: var(--warning-text); border-bottom: var(--border-w) solid color-mix(in srgb, var(--warning) 30%, transparent); font: var(--fw-medium) var(--fs-xs) / 1.4 var(--font-sans); text-align: center; }
.tp-demo-bandeau a { color: inherit; font-weight: var(--fw-semibold); margin-left: var(--space-2); }
/* pas de barre de défilement de la page (on défile toujours au trackpad / à la molette / au doigt) */
html { scrollbar-width: none; }
html::-webkit-scrollbar { display: none; }
