:root {
  --fond: #f7f8f7;
  --surface: #ffffff;
  --texte: #16211f;
  --discret: #5b6a67;
  --bord: #dde3e1;
  --accent: #0f766e;
  --accent-fort: #0b5e58;
  --accent-doux: #e3f3f1;
  --alerte: #fff6db;
  --danger: #b42318;
  --ok: #067647;
  --rayon: 10px;
  --ombre: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 12px rgb(16 24 40 / 5%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #0f1514; --surface: #172120; --texte: #e6eeec; --discret: #9fb0ac; --bord: #2a3836;
    --accent: #2bb3a6; --accent-fort: #4fcfc2; --accent-doux: #173a37; --alerte: #3a3218; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fond: #0f1514; --surface: #172120; --texte: #e6eeec; --discret: #9fb0ac; --bord: #2a3836;
  --accent: #2bb3a6; --accent-fort: #4fcfc2; --accent-doux: #173a37; --alerte: #3a3218; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--fond); color: var(--texte); font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
a:hover { color: var(--accent-fort); }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0.4em 0; }
h2, .h2 { font-size: 1.45rem; margin: 1.6em 0 0.5em; }
h3, .h3 { font-size: 1.1rem; margin: 1.2em 0 0.3em; }
.lead { font-size: 1.15rem; color: var(--discret); }
.discret { color: var(--discret); }
.petit { font-size: 0.85rem; }
.centre { text-align: center; }
.centre-bloc { text-align: center; padding: 3rem 0; }

.conteneur { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.conteneur-large { max-width: 1440px; margin: 0 auto; padding: 0 16px; }
.etroit { max-width: 760px; margin-left: auto; margin-right: auto; }

.btn { display: inline-flex; align-items: center; gap: 0.4em; padding: 0.6em 1.1em; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: #fff; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; transition: background 0.15s; }
.btn:hover { background: var(--accent-fort); color: #fff; }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn-second { background: var(--surface); color: var(--accent); }
.btn-second:hover { background: var(--accent-doux); color: var(--accent-fort); }
.btn-grand { padding: 0.8em 1.4em; font-size: 1.05rem; }
.btn-petit { padding: 0.35em 0.8em; font-size: 0.9rem; }
.lien { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; padding: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }

.entete { background: var(--surface); border-bottom: 1px solid var(--bord); }
.entete-in { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 60px; flex-wrap: wrap; }
.entete nav { display: flex; gap: 1.1rem; align-items: center; flex-wrap: wrap; }
.entete nav a:not(.btn) { color: var(--texte); text-decoration: none; font-weight: 500; }
.logo { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.15rem; color: var(--texte); text-decoration: none; margin: 0; }
.logo-marque { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff; font-size: 1rem; }
@media (max-width: 640px) { .entete nav a:not(.btn) { display: none; } }

.heros { padding: 3rem 0 2rem; }
.heros-in { display: grid; grid-template-columns: 1.2fr 1fr; gap: 3rem; align-items: center; }
@media (max-width: 860px) { .heros-in { grid-template-columns: 1fr; } .apercu-heros { display: none; } }
.surtitre { color: var(--accent); font-weight: 600; margin: 0; }
.apercu-heros { margin: 0; }
.mini-facture { background: #fff; color: #1d2422; border-radius: 8px; box-shadow: 0 10px 40px rgb(16 24 40 / 14%); padding: 1.6rem; font-size: 0.85rem; transform: rotate(1.5deg); }
.mf-haut { display: flex; justify-content: space-between; border-bottom: 2px solid #0f766e; padding-bottom: 0.5rem; margin-bottom: 1rem; }
.mf-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; color: #4a5654; }
.mf-ligne, .mf-total { display: flex; justify-content: space-between; padding: 0.35rem 0; border-bottom: 1px solid #e6eae9; }
.mf-total { font-weight: 700; border: 0; font-size: 1rem; }
.mf-mention { font-size: 0.75rem; color: #5b6a67; margin: 0.8rem 0 0; }

.grille-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; margin-top: 1rem; }
.carte { display: block; background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 1.2rem 1.3rem; color: inherit; text-decoration: none; margin-bottom: 1rem; }
.carte .h3 { margin-top: 0; }
a.carte:hover { border-color: var(--accent); }
.bande { margin: 3rem auto; }
.pastilles { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.8rem 0; }
.pastilles a { background: var(--surface); border: 1px solid var(--bord); border-radius: 999px; padding: 0.35em 0.9em; text-decoration: none; color: var(--texte); font-size: 0.95rem; }
.pastilles a:hover { border-color: var(--accent); color: var(--accent); }

.fil { font-size: 0.85rem; color: var(--discret); margin-top: 1.5rem; }
.fil a { color: var(--discret); }
.tableau-defile { overflow-x: auto; }
.tableau { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--rayon); overflow: hidden; border: 1px solid var(--bord); font-size: 0.95rem; }
.tableau th, .tableau td { padding: 0.6rem 0.8rem; text-align: left; border-bottom: 1px solid var(--bord); }
.tableau td:nth-child(n+2), .tableau th:nth-child(n+2) { text-align: right; white-space: nowrap; }
.tableau tfoot td { font-weight: 700; }
.encart { background: var(--accent-doux); border-radius: var(--rayon); padding: 1.2rem 1.4rem; margin: 2rem 0; display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.encart p { margin: 0; }
.article blockquote { border-left: 3px solid var(--accent); margin: 1rem 0; padding: 0.5rem 1rem; background: var(--surface); }
.faq details { background: var(--surface); border: 1px solid var(--bord); border-radius: 8px; padding: 0.8rem 1rem; margin-bottom: 0.5rem; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq p { margin: 0.6rem 0 0; color: var(--discret); }
.alerte { background: var(--alerte); border-radius: 8px; padding: 0.7rem 1rem; }
.liste-guides .carte p { color: var(--discret); margin: 0; }

.offres { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.2rem; max-width: 820px; margin: 2rem auto; }
.offre { background: var(--surface); border: 1px solid var(--bord); border-radius: 14px; padding: 1.6rem; display: flex; flex-direction: column; gap: 0.6rem; }
.offre h2 { margin: 0; }
.offre-pro { border: 2px solid var(--accent); box-shadow: var(--ombre); }
.prix { font-size: 2.2rem; font-weight: 800; margin: 0; }
.prix small { font-size: 1rem; font-weight: 500; color: var(--discret); }
.coches { list-style: none; padding: 0; margin: 0.5rem 0 1rem; }
.coches li { padding-left: 1.6em; position: relative; margin: 0.35em 0; }
.coches li::before { content: "✓"; position: absolute; left: 0; color: var(--accent); font-weight: 700; }
.attente input, .ligne-form input { flex: 1; min-width: 0; }
.attente { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.attente p { flex-basis: 100%; margin: 0; }
.ligne-form { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.retour { min-height: 1.4em; color: var(--accent-fort); font-weight: 500; }
.cle { font: 700 1.4rem ui-monospace, monospace; background: var(--surface); border: 2px dashed var(--accent); border-radius: 8px; padding: 0.8rem; user-select: all; }

.pied { border-top: 1px solid var(--bord); background: var(--surface); margin-top: 4rem; padding: 2rem 0 1rem; }
.pied-in { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 1.5rem; }
.pied-in a { display: block; color: var(--discret); text-decoration: none; font-size: 0.92rem; margin: 0.25rem 0; }
.pied-in a:hover { color: var(--accent); }
.pied-titre { font-weight: 700; margin: 0 0 0.4rem; }
@media (max-width: 760px) { .pied-in { grid-template-columns: 1fr 1fr; } }

/* ---------- Formulaires ---------- */
input, select, textarea { font: inherit; color: var(--texte); background: var(--surface); border: 1px solid var(--bord); border-radius: 7px; padding: 0.45em 0.6em; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.88rem; font-weight: 500; color: var(--discret); }
label.case { flex-direction: row; align-items: center; gap: 0.5rem; color: var(--texte); }
label.case input { width: auto; }
[hidden] { display: none !important; }

/* ---------- Éditeur ---------- */
.page-app .pied { margin-top: 2rem; }
.barre-app { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--bord); }
.barre-in { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; padding-top: 0.5rem; padding-bottom: 0.5rem; flex-wrap: wrap; }
.barre-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.segments { display: inline-flex; border: 1px solid var(--bord); border-radius: 8px; overflow: hidden; }
.segments button { border: 0; background: var(--surface); color: var(--texte); padding: 0.4em 1em; font: inherit; cursor: pointer; }
.segments button[aria-selected="true"] { background: var(--accent); color: #fff; }
.compte { background: var(--accent-doux); border-radius: 999px; padding: 0 0.45em; font-size: 0.8rem; }
.compte:empty { display: none; }
.badge-pro, .badge-pro-petit { background: #111; color: #ffd166; border-radius: 5px; font-weight: 800; letter-spacing: 0.05em; }
.badge-pro { padding: 0.2em 0.5em; font-size: 0.8rem; }
.badge-pro-petit { padding: 0.05em 0.35em; font-size: 0.65rem; }
.est-pro .badge-pro-petit { display: none; }

.editeur { display: grid; grid-template-columns: minmax(340px, 1fr) minmax(0, 1.05fr); gap: 1.5rem; padding-top: 1rem; align-items: start; }
@media (max-width: 980px) { .editeur { grid-template-columns: 1fr; } }
.formulaire h1 { margin-top: 0.3rem; }
.bloc { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 0.8rem 1rem; margin-bottom: 0.8rem; }
.bloc > summary { font-weight: 700; cursor: pointer; padding: 0.2rem 0; }
.sous-bloc { grid-column: 1 / -1; }
.sous-bloc > summary { cursor: pointer; font-size: 0.9rem; color: var(--accent); }
.champs { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; margin-top: 0.7rem; }
.champs .large { grid-column: 1 / -1; }
@media (max-width: 520px) { .champs { grid-template-columns: 1fr; } }
.logo-zone { display: flex; align-items: center; gap: 0.6rem; font-size: 0.88rem; color: var(--discret); flex-wrap: wrap; }
.logo-zone img { max-height: 40px; }
.fichier { cursor: pointer; }
.statut { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.statut label[data-si-payee] { flex-direction: row; align-items: center; gap: 0.5rem; }
.statut input[type="date"] { width: auto; }

#lignes { margin-top: 0.6rem; }
.ligne-tete, .ligne { display: grid; grid-template-columns: minmax(0, 3fr) 70px 70px 95px 72px 28px; gap: 0.35rem; align-items: center; }
.ligne-tete { font-size: 0.78rem; color: var(--discret); font-weight: 600; }
.ligne { margin-bottom: 0.35rem; }
.ligne input, .ligne select { padding: 0.4em 0.45em; }
.ligne-tete .col-tva[hidden], .ligne .col-tva[hidden] { display: block !important; visibility: hidden; }
@media (max-width: 520px) {
  .ligne-tete { display: none; }
  .ligne { grid-template-columns: 1fr 1fr 1fr 28px; padding-bottom: 0.4rem; border-bottom: 1px dashed var(--bord); }
  .ligne [data-k="designation"] { grid-column: 1 / -1; }
  .ligne .col-tva[hidden] { display: none !important; }
}
.suppr { border: 0; background: none; color: var(--discret); font-size: 1.3rem; cursor: pointer; line-height: 1; }
.suppr:hover { color: var(--danger); }
.ligne-boutons { display: flex; gap: 1rem; align-items: center; margin-top: 0.4rem; }
.actions-bas { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0 0.5rem; }

.zone-apercu { position: sticky; top: 64px; }
@media (max-width: 980px) { .zone-apercu { position: static; overflow-x: auto; } }

/* La feuille reste claire même en thème sombre : c'est un document imprimable */
.feuille { background: #fff; color: #1d2422; aspect-ratio: 210 / 297; width: 100%; max-width: 760px; margin: 0 auto; padding: 6% 6.5%; box-shadow: var(--ombre); border-radius: 4px; font-size: clamp(8px, 1.1vw, 12.5px); line-height: 1.45; display: flex; flex-direction: column; overflow: hidden; }
.feuille p { margin: 0; }
.f-tete { display: flex; justify-content: space-between; gap: 2em; }
.f-logo { max-height: 5em; max-width: 14em; margin-bottom: 0.8em; object-fit: contain; }
.f-nom { font-weight: 700; font-size: 1.15em; }
.f-emetteur { color: #3b4644; }
.f-titre { text-align: right; }
.f-type { font-size: 2em; font-weight: 800; color: #0f766e; letter-spacing: -0.02em; line-height: 1.1; margin-bottom: 0.3em !important; }
.f-client { margin: 2.5em 0 1em auto; width: 45%; background: #f4f7f6; border-radius: 4px; padding: 1em 1.2em; }
.f-etiquette { font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.06em; color: #6b7775; }
.f-categorie { font-size: 0.9em; color: #4a5654; margin-bottom: 0.6em !important; }
.f-lignes { width: 100%; border-collapse: collapse; }
.f-lignes th { text-align: left; font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.04em; color: #6b7775; border-bottom: 2px solid #0f766e; padding: 0.5em 0.4em; }
.f-lignes td { padding: 0.55em 0.4em; border-bottom: 1px solid #e6eae9; vertical-align: top; }
.f-lignes th:nth-child(n+2), .f-lignes td:nth-child(n+2) { text-align: right; white-space: nowrap; }
.f-vide { color: #9aa5a3; text-align: center !important; font-style: italic; }
.f-totaux { margin: 1em 0 0 auto; width: 50%; }
.f-totaux p { display: flex; justify-content: space-between; padding: 0.3em 0.4em; }
.f-net { background: #0f766e; color: #fff; font-weight: 700; font-size: 1.15em; border-radius: 3px; margin-top: 0.3em !important; padding: 0.5em 0.6em !important; }
.f-paiement, .f-notes { margin-top: 1.5em !important; }
.f-signature { margin-top: 1.5em; }
.f-cadre { border: 1px solid #c9d1cf; height: 6em; width: 50%; margin-top: 0.5em; border-radius: 3px; }
.f-mentions { margin-top: auto; padding-top: 1.5em; font-size: 0.82em; color: #5b6765; border-top: 1px solid #e6eae9; }
.f-mentions p { margin-bottom: 0.25em; }
.f-credit { font-size: 0.75em; color: #9aa5a3; text-align: center; margin-top: 0.8em !important; }

/* ---------- Modales ---------- */
.modale { border: 0; border-radius: 14px; padding: 1.2rem 1.4rem; width: min(640px, calc(100vw - 32px)); background: var(--surface); color: var(--texte); box-shadow: 0 20px 60px rgb(0 0 0 / 25%); }
.modale::backdrop { background: rgb(10 20 18 / 45%); }
.modale-tete { display: flex; justify-content: space-between; align-items: center; }
.modale-tete h2 { margin: 0; }
.fermer { border: 0; background: none; font-size: 1.6rem; cursor: pointer; color: var(--discret); }
.modale label { margin: 0.6rem 0; }
.filtres { margin: 0.8rem 0; }
.liste-docs { max-height: 55vh; overflow-y: auto; }
.doc-item { display: flex; align-items: center; gap: 0.3rem; border-bottom: 1px solid var(--bord); }
.doc-ouvrir { flex: 1; display: grid; grid-template-columns: 1.2fr 1.5fr 1fr 0.9fr; gap: 0.5rem; align-items: center; text-align: left; background: none; border: 0; padding: 0.6rem 0.2rem; font: inherit; color: inherit; cursor: pointer; }
.doc-ouvrir:hover { background: var(--accent-doux); }
.doc-type { font-weight: 600; }
.doc-montant { text-align: right; }
.etat { font-size: 0.8rem; text-align: center; border-radius: 999px; padding: 0.1em 0.5em; background: var(--fond); }
.etat.ok { color: var(--ok); }
.etat.retard { color: var(--danger); font-weight: 600; }
@media (max-width: 520px) { .doc-ouvrir { grid-template-columns: 1fr 1fr; } }
.modale-pied { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---------- Impression : seule la feuille sort, en A4 ---------- */
@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; }
  body > *:not(main), main > *:not(.editeur), .formulaire, .barre-app, dialog { display: none !important; }
  .editeur { display: block; padding: 0; max-width: none; }
  .zone-apercu { position: static; }
  .feuille { box-shadow: none; border-radius: 0; width: 210mm; min-height: 297mm; max-width: none; aspect-ratio: auto; padding: 16mm 15mm; font-size: 10pt; overflow: visible; }
  .f-net { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .f-client { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
