:root {
  --bg: #0a0a0a;
  --bg-elevated: #151515;
  --bg-input: #1c1c1c;
  --border: #2a2a2a;
  --green: #45f01f;
  --green-dim: #2a9012;
  --red: #ff3b30;
  --text: #f2f2f2;
  --text-dim: #8f8f8f;
  --radius: 10px;

  /* couleurs par type d'intervention */
  --c-tonte: #45f01f;
  --c-taille: #38bdf8;
  --c-elagage: #facc15;
  --c-debrous: #a3e635;
  --c-defrichage: #b45309;
  --c-entretien: #c084fc;
  --c-amenagement: #ff3b30;
  --c-plantation: #34d399;
  --c-arrosage: #22d3ee;
  --c-devis: #ff9f1c;
  --c-autre: #9ca3af;
  --jaune-valider: #facc15;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body { padding-bottom: env(safe-area-inset-bottom); }

.hidden { display: none !important; }

.screen { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- Marque ---------- */
.brand {
  font-family: 'Oswald', sans-serif;
  font-style: italic;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
  font-size: 2rem;
}
.brand-jardin { color: var(--text); }
.brand-974 { color: var(--green); }
.brand-small { font-size: 1.25rem; }

/* ---------- Connexion ---------- */
#login-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-sub { color: var(--text-dim); margin: 4px 0 28px; font-size: 0.95rem; }

/* ---------- Sélecteur d'agenda ---------- */
#selecteur-screen { align-items: center; justify-content: center; padding: 24px; }
.selecteur-box { width: 100%; max-width: 360px; text-align: center; }
.carte-agenda {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 16px;
  margin-top: 14px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.carte-agenda:active { border-color: var(--green); }
.carte-agenda-icone { font-size: 2rem; line-height: 1; }
.carte-agenda-texte { display: flex; flex-direction: column; gap: 3px; }
.carte-agenda-texte strong { color: var(--text); font-size: 1.05rem; }
.carte-agenda-texte span { color: var(--text-dim); font-size: 0.8rem; }
#brand-retour { cursor: pointer; }

.agenda-souslabel {
  color: var(--c-entretien);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0 18px 8px;
  margin-top: -6px;
}

/* ---------- Cartes de rappel Programmation (actions en un clic) ---------- */
.rdv-card.mode-programmation { align-items: center; }
.programmation-actions { display: flex; gap: 6px; }
.prog-btn {
  border: none;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
}
.prog-btn.ajouter { background: var(--green); color: #0a0a0a; }
.prog-btn.retirer { background: transparent; color: var(--red); border: 1px solid var(--red); }
#login-form { display: flex; flex-direction: column; gap: 12px; }
.error-msg { color: var(--red); font-size: 0.85rem; min-height: 1.1em; margin: 4px 0 0; }

/* ---------- Champs ---------- */
input, select, textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--green);
}
label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 14px;
}
label > input, label > select, label > textarea { margin-top: 6px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Boutons ---------- */
.btn {
  border: none;
  border-radius: var(--radius);
  padding: 13px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.btn-primary { background: var(--green); color: #0a0a0a; flex: 1; }
.btn-danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 6px 10px;
}

/* ---------- Barre du haut ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 8px;
}
.topbar-actions { display: flex; gap: 0px; }
.topbar-actions .icon-btn { font-size: 1.15rem; padding: 6px 6px; }
.btn-full { width: 100%; margin-top: 4px; }

/* ---------- Recherche ---------- */
#recherche-input { margin-bottom: 4px; }
.recherche-resultats { max-height: 55dvh; overflow-y: auto; margin-top: 10px; }
.recherche-compteur { color: var(--text-dim); font-size: 0.78rem; margin-bottom: 8px; }

/* ---------- Carnet clients ---------- */
.clients-liste { max-height: 45dvh; overflow-y: auto; margin-bottom: 4px; }
.client-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.client-card-info { min-width: 0; }
.client-card-nom { font-weight: 600; }
.client-card-detail { color: var(--text-dim); font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.import-details { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 14px; }
.import-details summary {
  cursor: pointer;
  color: var(--green);
  font-size: 0.85rem;
  font-weight: 600;
}
.import-aide { color: var(--text-dim); font-size: 0.75rem; margin: 8px 0; line-height: 1.4; }
.import-resultat { font-size: 0.8rem; color: var(--green); margin-top: 8px; min-height: 1.1em; }

/* ---------- Filtre d'impression ---------- */
.filtre-impression { margin: 4px 0 18px; }
.radio-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text);
  padding: 10px 0;
  cursor: pointer;
}
.radio-line input { width: auto; }

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  cursor: pointer;
}
.checkbox-line input { width: auto; flex-shrink: 0; }

/* ---------- Compte rendu d'intervention ---------- */
.cr-contexte {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.cr-contexte strong { color: var(--text); display: block; font-size: 1.05rem; margin-bottom: 2px; }
.cr-prestations { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 18px; }
.cr-chip {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.cr-chip.active { background: var(--green); color: #0a0a0a; border-color: var(--green); }

/* ---------- Zone imprimable ---------- */
#print-view { display: none; }

@media print {
  body * { visibility: hidden; }
  #print-view, #print-view * { visibility: visible; }
  #print-view {
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    background: #ffffff;
    color: #000000;
    padding: 10mm;
    font-family: Arial, sans-serif;
  }
  .print-titre { font-size: 1.4rem; font-weight: 700; margin-bottom: 2px; }
  .print-sous-titre { color: #444; margin-bottom: 22px; font-size: 0.9rem; }
  .print-jour { margin-top: 22px; page-break-inside: avoid; }
  .print-jour-titre {
    font-weight: 700;
    background: #000;
    color: #fff;
    padding: 6px 10px;
    margin-bottom: 0;
    text-transform: capitalize;
    font-size: 1rem;
  }
  .print-vide {
    color: #777;
    font-style: italic;
    font-size: 0.85rem;
    padding: 10px 4px;
    border: 1px solid #ccc;
    border-top: none;
  }

  .print-tableau {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
  }
  .print-tableau th, .print-tableau td {
    border: 1px solid #bbb;
    padding: 10px 12px;
    text-align: left;
    vertical-align: top;
    font-size: 0.85rem;
    word-wrap: break-word;
  }
  .print-tableau thead th {
    background: #eee;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #333;
    border-top: none;
  }
  .print-tableau .col-heure { width: 13%; white-space: nowrap; font-weight: 700; }
  .print-tableau .col-commentaire { width: 26%; }
  .print-tableau tbody td.col-commentaire {
    /* Lignes discrètes pour écrire à la main */
    background-image: repeating-linear-gradient(
      to bottom, transparent, transparent 20px, #ddd 21px
    );
  }
  .print-tableau tbody tr { page-break-inside: avoid; }
  .print-tableau tbody td { min-height: 42px; height: 42px; }
  .print-tableau tr.print-tache td { font-style: italic; color: #555; }
  .print-tableau tr.print-devis td:nth-child(3) { font-weight: 600; }
}

/* ---------- Bascule de vue ---------- */
.view-toggle {
  display: flex;
  gap: 8px;
  padding: 4px 18px 12px;
}
.toggle-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 18px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.toggle-btn.active { background: var(--green); color: #0a0a0a; border-color: var(--green); }

.view { flex: 1; padding: 0 18px 100px; overflow-y: auto; }

/* ---------- Vue Liste ---------- */
.liste-jour-titre {
  font-family: 'Oswald', sans-serif;
  font-style: italic;
  font-weight: 600;
  color: var(--green);
  font-size: 0.95rem;
  margin: 22px 0 8px;
  text-transform: capitalize;
}
.liste-jour-titre:first-child { margin-top: 4px; }

.rdv-card {
  display: flex;
  gap: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 4px solid var(--c-autre);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
}
.rdv-heure { font-weight: 700; font-size: 0.95rem; min-width: 48px; }
.rdv-heure small { display: block; font-weight: 400; color: var(--text-dim); font-size: 0.7rem; }
.rdv-info { flex: 1; min-width: 0; }
.rdv-client { font-weight: 600; }
.rdv-type { color: var(--text-dim); font-size: 0.85rem; }
.rdv-adresse { color: var(--text-dim); font-size: 0.8rem; margin-top: 2px; }
.rdv-badge {
  align-self: flex-start;
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-envoye { background: rgba(69,240,31,0.15); color: var(--green); }
.badge-attente { background: rgba(255,255,255,0.08); color: var(--text-dim); }

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 60px 20px;
  font-size: 0.9rem;
}

/* ---------- Vue Mois ---------- */
.mois-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 10px;
}
.mois-label {
  font-family: 'Oswald', sans-serif;
  font-style: italic;
  font-weight: 600;
  font-size: 1.1rem;
  text-transform: capitalize;
}
.grid-jours-entete {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-bottom: 6px;
}
.grid-mois {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.jour-case {
  min-height: 62px;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 4px 3px;
  gap: 2px;
  cursor: pointer;
  overflow: hidden;
}
.jour-case.autre-mois { opacity: 0.35; }
.jour-case.aujourdhui { border-color: var(--green); }
.jour-case.selectionne { background: rgba(69,240,31,0.12); border-color: var(--green); }
.jour-numero { font-size: 0.72rem; text-align: right; color: var(--text-dim); padding-right: 2px; }
.jour-case.aujourdhui .jour-numero { color: var(--green); font-weight: 700; }
.jour-case.selectionne .jour-numero { color: var(--green); font-weight: 700; }
.apercu-item {
  font-size: 0.58rem;
  line-height: 1.3;
  font-weight: 600;
  color: #0a0a0a;
  padding: 1px 4px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.apercu-item.apercu-tache {
  background: transparent;
  border: 1px dashed var(--c-autre);
  color: var(--text-dim);
  font-weight: 500;
  font-style: italic;
}
.apercu-plus { font-size: 0.56rem; color: var(--text-dim); padding: 0 4px; }

.jour-selection { margin-top: 18px; }
.jour-selection-titre {
  font-family: 'Oswald', sans-serif;
  font-style: italic;
  font-weight: 600;
  margin-bottom: 8px;
  text-transform: capitalize;
}

/* ---------- Bouton flottant ---------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  border: none;
  box-shadow: 0 4px 14px rgba(255,59,48,0.4);
  cursor: pointer;
}

/* ---------- Modale ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
.modal-sheet {
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
}
.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 4px auto 14px;
}
.modal-title {
  font-family: 'Oswald', sans-serif;
  font-style: italic;
  font-weight: 600;
  margin: 0 0 16px;
}
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.statut-email {
  font-size: 0.8rem;
  color: var(--text-dim);
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 14px;
}

/* ---------- Sélecteur Rendez-vous / Devis / Tâche ---------- */
.type-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}
.type-btn {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 10px 4px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.type-btn.active[data-type="rdv"] { background: var(--green); color: #0a0a0a; border-color: var(--green); }
.type-btn.active[data-type="devis"] { background: var(--c-devis); color: #0a0a0a; border-color: var(--c-devis); }
.type-btn.active[data-type="tache"] { background: var(--c-entretien); color: #0a0a0a; border-color: var(--c-entretien); }

/* ---------- Suggestions d'adresse (API Adresse nationale) ---------- */
.champ-adresse-wrap { position: relative; }
.adresse-suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 220px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 8px 20px rgba(0,0,0,0.4);
}
.adresse-suggestion-item {
  padding: 10px 12px;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.adresse-suggestion-item:last-child { border-bottom: none; }
.adresse-suggestion-item:hover, .adresse-suggestion-item.survol { background: rgba(69,240,31,0.1); }
.adresse-suggestion-item .contexte { display: block; color: var(--text-dim); font-size: 0.72rem; }

/* ---------- Bouton d'envoi manuel (dans la modale) ---------- */
.confirmation-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.btn-confirm { background: rgba(69,240,31,0.15); color: var(--green); border: 1px solid var(--green); flex: 1; }

/* ---------- Badges de statut d'envoi ---------- */
.badge-a-confirmer { background: rgba(250,204,21,0.15); color: #facc15; }
.badge-a-valider { background: rgba(250,204,21,0.25); color: #facc15; font-weight: 700; border: 1px solid rgba(250,204,21,0.5); }
.badge-devis { background: rgba(255,159,28,0.15); color: var(--c-devis); }

/* ---------- Carte "tâche" / "devis" ---------- */
.rdv-card.est-tache { border-left-style: dashed; }
.rdv-card.est-devis { border-left-style: dotted; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(90px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 100;
}

@media (min-width: 640px) {
  #app-screen { max-width: 480px; margin: 0 auto; }
  .modal-overlay { align-items: center; justify-content: center; }
  .modal-sheet { max-width: 440px; border-radius: 18px; }
}
