:root {
  --vert: #4f7f33;
  --vert-clair: #eaf2e3;
  --jaune: #f7ea4a;
  --texte: #1f2a1a;
  --gris: #6b7566;
  --bord: #d9dfd3;
  --fond: #f6f8f3;
  --rouge: #b3261e;
  --orange: #b45309;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--fond); color: var(--texte);
  font: 16px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--vert); }
header.top {
  background: #fff; border-bottom: 3px solid var(--jaune);
  display: flex; align-items: center; gap: 16px; padding: 10px 20px; flex-wrap: wrap;
}
header.top img { height: 44px; display: block; }
header.top nav { display: flex; gap: 14px; flex: 1; flex-wrap: wrap; }
header.top nav a { text-decoration: none; font-weight: 600; padding: 4px 0; }
header.top .qui { color: var(--gris); font-size: 14px; }
header.top form { margin: 0; }
main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 28px 0 10px; }
.sous { color: var(--gris); margin: 0 0 16px; }
.carte {
  background: #fff; border: 1px solid var(--bord); border-radius: 10px;
  padding: 16px; margin-bottom: 16px;
}
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 10px; font-size: 15px; }
.flash.ok { background: #e3f3dc; border: 1px solid #b9dcab; }
.flash.error { background: #fbe5e3; border: 1px solid #efb7b2; color: #7a1a14; }
button, .btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; padding: 9px 16px;
  border: 1px solid var(--vert); background: var(--vert); color: #fff; text-decoration: none;
  display: inline-block;
}
button.sec, .btn.sec { background: #fff; color: var(--vert); }
button.lien { background: none; border: none; color: var(--vert); padding: 4px 6px; text-decoration: underline; font-weight: 500; }
button.danger { background: #fff; color: var(--rouge); border-color: var(--rouge); }
label { display: block; font-weight: 600; margin: 12px 0 4px; font-size: 14px; }
input[type=text], input[type=password], input[type=time], input[type=number] {
  font: inherit; padding: 9px 10px; border: 1px solid var(--bord); border-radius: 8px;
  background: #fff; width: 100%;
}
input:focus { outline: 2px solid var(--jaune); border-color: var(--vert); }
input:disabled { background: #f0f1ee; color: #999; }
.login { max-width: 380px; margin: 40px auto; }
.login img { width: 220px; display: block; margin: 0 auto 16px; }

.navsemaine { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.navsemaine .titre { font-weight: 700; text-align: center; flex: 1; min-width: 200px; }
.navsemaine .btn { padding: 7px 12px; }
.navsemaine .vide { width: 90px; }

table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--bord); }
th { font-size: 13px; color: var(--gris); font-weight: 600; background: #fafbf8; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total td { font-weight: 700; background: var(--vert-clair); border-top: 2px solid var(--vert); }
td.maj { background: #fff9d6; font-weight: 700; }
th.maj { background: #fff3a8; color: var(--texte); }
.scroll { overflow-x: auto; }

table.saisie td { vertical-align: middle; }
table.saisie input { min-width: 90px; }
table.saisie input.f-pause { min-width: 70px; max-width: 90px; }
table.saisie tr.futur td { opacity: .5; }
.day-total { font-weight: 700; text-align: right; white-space: nowrap; }
.day-total.warn { color: var(--orange); }

.resume { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.resume > div { background: var(--fond); border: 1px solid var(--bord); border-radius: 8px; padding: 10px 12px; }
.resume > div.maj { background: #fff9d6; border-color: #e6d86a; }
.resume .v { font-size: 22px; font-weight: 700; }
.resume .l { font-size: 13px; color: var(--gris); }
.regle { font-size: 13px; color: var(--gris); margin: 10px 0 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--vert-clair); color: var(--vert); font-weight: 600; }
.badge.off { background: #eee; color: #777; }
form.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
form.inline input { width: 150px; padding: 6px 8px; }

@media (max-width: 640px) {
  main { padding: 14px 10px 50px; }
  header.top { padding: 8px 12px; gap: 10px; }
  .navsemaine .titre { order: -1; flex-basis: 100%; }
  table.saisie, table.saisie tbody { display: block; }
  table.saisie thead { display: none; }
  table.saisie tr {
    display: grid; gap: 6px 8px; padding: 10px 0; border-bottom: 1px solid var(--bord);
    grid-template-columns: 1fr 1fr 78px;
    grid-template-areas: "jour jour total" "debut fin pause";
  }
  table.saisie td { display: block; padding: 0; border: none; min-width: 0; }
  table.saisie td.c-jour { grid-area: jour; font-weight: 700; align-self: center; }
  table.saisie td.c-total { grid-area: total; align-self: center; }
  table.saisie td.c-debut { grid-area: debut; }
  table.saisie td.c-fin { grid-area: fin; }
  table.saisie td.c-pause { grid-area: pause; }
  table.saisie td[data-l]::before { content: attr(data-l); display: block; font-size: 12px; color: var(--gris); }
  table.saisie input, table.saisie input.f-pause { min-width: 0; max-width: none; width: 100%; padding: 8px 6px; }
  .resume { grid-template-columns: 1fr 1fr; }
}
@media print {
  header.top, .actions, .navsemaine .btn, .noprint { display: none !important; }
  body { background: #fff; }
  .carte { border: none; padding: 0; }
}

.centre { text-align: center; }
.etroit { max-width: 420px; }
h2.sans-marge { margin-top: 0; }

input.invalide { border-color: var(--rouge); background: #fdeceb; }

/* --- journées automatiques, absences, sélecteurs --- */
select, input[type=date] {
  font: inherit; padding: 9px 10px; border: 1px solid var(--bord); border-radius: 8px;
  background: #fff; width: 100%; color: var(--texte);
}
select:focus, input[type=date]:focus { outline: 2px solid var(--jaune); border-color: var(--vert); }
select:disabled, input[type=date]:disabled { background: #f0f1ee; color: #999; }
form.inline input[type=date] { width: 150px; padding: 6px 8px; }
.deux { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label.case { display: flex; gap: 8px; align-items: center; font-weight: 500; margin-top: 14px; }
label.case input { width: auto; }
.badge.auto-badge { background: #fff3a8; color: #6b5d00; }
.badge.abs-badge { background: #e7eefb; color: #254a8f; }
.badge.ferie-badge { background: #efe7fb; color: #5a2a91; }
table.saisie tr.auto td { background: #fffbe0; }
table.saisie tr.auto .day-total { color: #7a6a00; }
table.saisie tr.absence td { background: #eef3fc; }
table.saisie tr.ferie td { background: #f6f0fc; }
table.saisie tr.ferie.auto td { background: #fffbe0; }
table.saisie td.c-statut select { min-width: 150px; padding: 8px; }
.day-total { font-size: 14px; }

@media (max-width: 640px) {
  table.saisie tr.admin-row {
    grid-template-areas: "jour jour total" "statut statut statut" "debut fin pause";
  }
  table.saisie td.c-statut { grid-area: statut; }
  table.saisie td.c-statut select { min-width: 0; width: 100%; }
  .deux { grid-template-columns: 1fr; }
}

table.recap { font-size: 14px; }
table.recap th, table.recap td { padding: 8px 7px; }
table.recap td:first-child, table.recap td:nth-child(9) { white-space: nowrap; }

@media (max-width: 640px) {
  table.saisie tr.auto { background: #fffbe0; }
  table.saisie tr.absence { background: #eef3fc; }
  table.saisie tr.ferie { background: #f6f0fc; }
  table.saisie tr.auto td, table.saisie tr.absence td, table.saisie tr.ferie td { background: transparent; }
  table.saisie tr { padding-left: 4px; padding-right: 4px; }
}

.badge.lock-badge { background: #eceeea; color: #5b6657; }
table.saisie tr.futur .c-jour { opacity: 1; }
table.saisie tr.verrouille td { opacity: .85; }

/* ===== Gestion : devis, factures, planning ===== */
textarea {
  font: inherit; padding: 9px 10px; border: 1px solid var(--bord); border-radius: 8px;
  background: #fff; width: 100%; resize: vertical; color: var(--texte);
}
textarea:focus { outline: 2px solid var(--jaune); border-color: var(--vert); }
textarea:disabled { background: #f0f1ee; color: #777; }
input[type=text], input[type=email], input[type=password], input[type=time], input[type=number] { max-width: 100%; }
.trois { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.quatre { display: grid; grid-template-columns: 1fr 1fr 1fr 1.4fr; gap: 12px; }
.petit { font-size: 13px; color: var(--gris); }
.pre { white-space: pre-line; }
.nw { white-space: nowrap; }
.rouge { color: var(--rouge); }
input.court { width: 70px; }
header.top nav { gap: 12px; }
header.top nav a { font-size: 15px; }

.badge.st-brouillon { background: #eee; color: #555; }
.badge.st-envoye { background: #e7eefb; color: #254a8f; }
.badge.st-accepte, .badge.et-payee { background: #dff3d6; color: #2f6b1b; }
.badge.st-refuse, .badge.et-annulee { background: #eee; color: #777; }
.badge.et-attente, .badge.et-partielle { background: #fff3a8; color: #6b5d00; }
.badge.et-retard { background: #fbe5e3; color: #9b1c14; }
.badge.et-brouillon { background: #eee; color: #555; }
.badge.et-emise { background: #efe7fb; color: #5a2a91; }

.kpi { margin-bottom: 16px; }
.kpi .alerte { background: #fbe5e3; border-color: #efb7b2; }
.kpi .alerte .v { color: #9b1c14; }

/* éditeur de lignes */
table.lignes { min-width: 720px; }
table.lignes td { vertical-align: top; padding: 6px 6px; }
table.lignes td.c-d { min-width: 260px; }
table.lignes td.c-q, table.lignes th.c-q { width: 80px; }
table.lignes td.c-u, table.lignes th.c-u { width: 90px; }
table.lignes td.c-p, table.lignes th.c-p { width: 110px; }
table.lignes td.c-t, table.lignes th.c-t { width: 120px; }
table.lignes .l-total { padding-top: 14px; font-weight: 600; }
table.lignes textarea { min-height: 44px; }
.tot-live { display: flex; gap: 22px; justify-content: flex-end; flex-wrap: wrap; margin-top: 14px; font-size: 15px; }
.tot-live b { margin-left: 6px; font-variant-numeric: tabular-nums; }
.tot-live .g { font-size: 18px; }
.tot-live.fixe { margin-top: 10px; }
select.auto { width: auto; min-width: 220px; }

form.ligne-cat { display: grid; grid-template-columns: 3fr 1fr 1fr 1fr auto auto; gap: 8px; align-items: center; }
form.filtre { margin-bottom: 12px; flex-wrap: wrap; }
form.filtre select { width: auto; }

/* planning */
.grille-planning { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.jour-plan { background: #fff; border: 1px solid var(--bord); border-radius: 10px; padding: 10px 12px; min-height: 90px; }
.jour-plan h2 { font-size: 15px; margin: 0 0 8px; text-transform: capitalize; display: flex; justify-content: space-between; align-items: center; }
.jour-plan.aujourdhui { border: 2px solid var(--vert); }
.jour-plan.week-end { background: #f2f3ef; }
.jour-plan .plus { text-decoration: none; font-weight: 700; border: 1px solid var(--vert); border-radius: 50%; width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; }
.inter { border-left: 4px solid var(--vert); background: var(--vert-clair); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; }
.inter.faite { border-left-color: #999; background: #f0f1ee; }
.inter .h { font-weight: 700; font-size: 14px; }
.inter .actions { margin-top: 8px; }
.inter .btn { padding: 6px 10px; font-size: 14px; }
.cases { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 12px; }

@media (max-width: 640px) {
  .trois, .quatre { grid-template-columns: 1fr; }
  form.ligne-cat { grid-template-columns: 1fr 1fr; }
  form.ligne-cat input:first-child, form.ligne-cat input[name=designation] { grid-column: 1 / -1; }
  .tot-live { justify-content: flex-start; }
  .grille-planning { grid-template-columns: 1fr; }
  header.top nav { gap: 8px 12px; }
}
@media print {
  .grille-planning { grid-template-columns: repeat(2, 1fr); }
  .jour-plan { break-inside: avoid; }
}

@media (max-width: 640px) {
  table.lignes, table.lignes tbody { display: block; min-width: 0; }
  table.lignes thead { display: none; }
  table.lignes tr.ligne {
    display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px 8px; padding: 10px 0;
    border-bottom: 1px solid var(--bord);
    grid-template-areas: "d d d" "q u p" "t tot x";
  }
  table.lignes td { display: block; padding: 0; border: none; width: auto !important; min-width: 0 !important; }
  table.lignes td.c-d { grid-area: d; }
  table.lignes td.c-q { grid-area: q; }
  table.lignes td.c-u { grid-area: u; }
  table.lignes td.c-p { grid-area: p; }
  table.lignes td.c-t { grid-area: t; }
  table.lignes td.l-total { grid-area: tot; padding-top: 8px; text-align: right; }
  table.lignes td:last-child { grid-area: x; text-align: right; }
  table.lignes td.c-q::before { content: "Qté"; }
  table.lignes td.c-u::before { content: "Unité"; }
  table.lignes td.c-p::before { content: "PU HT (€)"; }
  table.lignes td.c-t::before { content: "TVA"; }
  table.lignes td.c-q::before, table.lignes td.c-u::before, table.lignes td.c-p::before, table.lignes td.c-t::before {
    display: block; font-size: 12px; color: var(--gris);
  }
  .devis-form .scroll { overflow-x: visible; }
  header.top { flex-direction: column; align-items: flex-start; }
  header.top nav { gap: 6px 14px; }
}

.gros { font-size: 20px; font-weight: 700; margin: 6px 0 0; }
h3 { font-size: 16px; margin: 18px 0 6px; }
form.ligne-mat { display: grid; grid-template-columns: 1fr 1.5fr auto auto; gap: 8px; align-items: center; }
@media (max-width: 640px) { form.ligne-mat { grid-template-columns: 1fr 1fr; } form.ligne-mat input { grid-column: 1 / -1; } }
.kpi { margin-top: 16px; }

/* espace client / signature */
canvas.zone-signature { width: 100%; height: 180px; background: #fff; border: 2px dashed var(--vert); border-radius: 10px; touch-action: none; display: block; cursor: crosshair; }
.espace-tete { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.espace-tete img { height: 70px; }
.bandeau-signe { background: #e3f3dc; border: 1px solid #b9dcab; border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; }
input.copie { font-family: monospace; font-size: 13px; }
.carte.cadre-info { background: #fafbf8; }
@media print { canvas.zone-signature { border: 1px solid #000; } }

@media (max-width: 640px) { .m-cache { display: none; } }

.carte.alerte { border-left: 4px solid #c0392b; background: #fdf1ef; }
