/* PV Builder — feuille de style commune. Thème clair par défaut, basculé
   manuellement (voir theme.js) via [data-theme="sombre"]. Base reprise de
   rundown-builder pour rester cohérent avec le reste du parc LA PROD TV. */

:root {
  --bg: #f4f5f7;
  --bg-1: #ffffff;
  --bg-2: #eceef1;
  --line: #dcdfe4;
  --texte: #1c2128;
  --texte-2: #6a7280;
  --accent: #2471a3;
  --accent-2: #1b5a80;
  --danger: #c0392b;
  --danger-bg: #fbeae8;
  --ok: #1e8449;
  --radius: 8px;
  --pad: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

[data-theme="sombre"] {
  --bg: #14161b;
  --bg-1: #1b1f26;
  --bg-2: #232830;
  --line: #333a45;
  --texte: #e8eaf0;
  --texte-2: #8a92a0;
  --accent: #4a9fd8;
  --accent-2: #6fb6e6;
  --danger: #e05a4a;
  --danger-bg: #3a2222;
  --ok: #35c26f;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--texte);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 650; }
a { color: var(--accent); }
.hint { color: var(--texte-2); font-size: 12.5px; }

/* --- Layout --- */
.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--bg-1); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar .titre { font-size: 16px; font-weight: 700; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.topbar .titre a { color: var(--texte); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.titre-logo { width: 22px; height: 22px; flex: none; border-radius: 5px; }
.topbar .spacer { flex: 1; }
.topbar .qui { color: var(--texte-2); font-size: 12.5px; white-space: nowrap; }
main { padding: 18px 16px 60px; max-width: 1400px; margin: 0 auto; }

.card {
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; margin-bottom: 16px;
}
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--texte-2); margin-bottom: 12px; }

/* --- Boutons / champs --- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--bg-2); color: var(--texte);
  font: 600 13px/1 inherit; padding: 9px 14px; border-radius: 7px; cursor: pointer;
  transition: filter .1s, transform .05s;
}
.btn:hover { filter: brightness(0.96); }
[data-theme="sombre"] .btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn.primaire { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

input[type=text], input[type=time], input[type=date], input[type=datetime-local], input[type=email], input[type=password],
input[type=number], select, textarea {
  background: var(--bg); border: 1px solid var(--line); color: var(--texte);
  border-radius: 6px; padding: 7px 9px; font: inherit; font-size: 13px; width: 100%;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { font-size: 12.5px; color: var(--texte-2); }
.champ { display: flex; flex-direction: column; gap: 4px; }
.rangee { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }

.theme-toggle {
  border: 1px solid var(--line); background: var(--bg-2); border-radius: 20px;
  width: 40px; height: 24px; position: relative; cursor: pointer; flex: none;
}
.theme-toggle::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: var(--accent); transition: left .15s;
}
[data-theme="sombre"] .theme-toggle::after { left: 18px; }

/* --- Listes / tuiles --- */
.grille-cartes { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.tuile {
  display: block; background: var(--bg-1); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; text-decoration: none; color: var(--texte); cursor: pointer;
}
.tuile:hover { border-color: var(--accent); }
.tuile .nom { font-weight: 650; margin-bottom: 4px; }
.tuile .meta { color: var(--texte-2); font-size: 12px; }

.liste-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px;
  border-bottom: 1px solid var(--line);
}
.liste-item:last-child { border-bottom: none; }
.liste-item .principal { flex: 1; min-width: 0; }
.liste-item .principal .nom { font-weight: 600; }
.liste-item .principal .meta { color: var(--texte-2); font-size: 12px; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600;
  background: var(--bg-2); color: var(--texte-2); text-transform: uppercase; letter-spacing: .03em;
}
.badge.role-admin { background: #fbeae8; color: var(--danger); }
.badge.role-editor { background: #d6f5e0; color: #0f6b33; }
.badge.role-viewer { background: var(--bg-2); color: var(--texte-2); }
[data-theme="sombre"] .badge.role-admin { background: #3a2222; color: #e05a4a; }
[data-theme="sombre"] .badge.role-editor { background: #16452a; color: #7fe6a8; }
.badge.courante { background: #d6f5e0; color: #0f6b33; }
[data-theme="sombre"] .badge.courante { background: #16452a; color: #7fe6a8; }

.onglets { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.onglet {
  border: none; background: none; color: var(--texte-2); font: 600 13px inherit;
  padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent;
}
.onglet.actif { color: var(--accent); border-bottom-color: var(--accent); }
.panneau { display: none; }
.panneau.actif { display: block; }

.vide { color: var(--texte-2); font-style: italic; padding: 20px 0; text-align: center; }
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--texte); color: var(--bg-1); padding: 9px 16px; border-radius: 8px;
  font-size: 13px; z-index: 200; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.visible { opacity: 1; }
.toast.erreur { background: var(--danger); color: #fff; }

/* --- Modale --- */
dialog {
  border: none; border-radius: 12px; padding: 0; background: var(--bg-1); color: var(--texte);
  width: min(560px, 92vw); max-height: 88vh;
}
dialog::backdrop { background: rgba(0,0,0,.4); }
.dlg-corps { padding: 18px; overflow-y: auto; max-height: calc(88vh - 60px); }
.dlg-titre { font-size: 15px; font-weight: 700; padding: 16px 18px 0; }
.dlg-pied { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 18px; }

/* --- Responsive --- */
@media (max-width: 640px) {
  .topbar { padding: 8px 10px; }
  .topbar .titre { font-size: 14px; }
  main { padding: 12px 10px 50px; }
  .card { padding: 12px; }
  .rangee { flex-direction: column; align-items: stretch; }
}

/* ============================================================== PV ÉDITEUR */

.pv-entete-ligne { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.pv-entete-ligne .bloc { min-width: 220px; flex: 1; }

/* Chips présents/excusés : nom + croix de retrait, saisie libre (datalist
   des comptes existants pour l'auto-complétion). */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; min-height: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--bg-2);
  border-radius: 20px; padding: 4px 6px 4px 10px; font-size: 12.5px;
}
.chip button {
  appearance: none; border: none; background: none; color: var(--texte-2); cursor: pointer;
  width: 16px; height: 16px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; line-height: 1;
}
.chip button:hover { background: var(--danger-bg); color: var(--danger); }
.chip.excuse { opacity: .65; }

/* Sections du PV : une bande de titre + un tableau 4 colonnes. */
.pv-section { margin-bottom: 20px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.pv-section-tete {
  display: flex; align-items: center; gap: 8px; background: var(--accent); color: #fff;
  padding: 8px 12px;
}
.pv-section-tete input {
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.3); color: #fff;
  font-weight: 650; flex: 1; min-width: 120px; max-width: 360px;
}
.pv-section-tete input::placeholder { color: rgba(255,255,255,.7); }
.pv-section-tete .btn { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.3); color: #fff; }
.pv-section-tete .btn:hover { background: rgba(255,255,255,.25); }

.pv-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.pv-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--texte-2); padding: 7px 10px; border-bottom: 1px solid var(--line); background: var(--bg-2);
}
/* Largeur des colonnes de contenu : données en ligne par public/pv.js selon
   les colonnes réellement configurées pour ce PV (voir creerSectionDom). */
.pv-table col.col-act { width: 36px; }
.pv-table td { padding: 2px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.pv-table tr:last-child td { border-bottom: none; }

/* Cellule éditable (contenteditable) : grandit avec le contenu tout seule
   (pas de JS de redimensionnement nécessaire, contrairement à un textarea).
   Mise en forme via la barre flottante (voir .barre-riche ci-dessous) —
   jouable ici sans le risque qui avait fait abandonner le contenteditable
   ailleurs dans le parc (rundown-builder) : là-bas, la sauvegarde
   reconstruisait toute la table et coupait le focus en pleine frappe ; ici
   sauvegarder() ne touche jamais le DOM après coup (voir le commentaire en
   tête de pv.js). */
.champ-adaptatif {
  border: 1px solid transparent; background: transparent; width: 100%; padding: 6px;
  font: inherit; font-size: 13px; color: inherit; line-height: 1.4;
  white-space: pre-wrap; word-break: break-word; min-height: 1.4em;
}
.champ-adaptatif:hover { border-color: var(--line); }
.champ-adaptatif:focus { background: var(--bg); border-color: var(--accent); outline: none; }
.champ-adaptatif div { min-height: 1em; } /* <div> par ligne créée par Entrée (defaultParagraphSeparator) */
.champ-adaptatif:empty::before { content: attr(data-placeholder); color: var(--texte-2); pointer-events: none; }

/* Barre d'outils flottante de mise en forme — une seule instance partagée,
   positionnée au-dessus de la cellule en cours d'édition, visible seulement
   pendant l'édition. display:none par défaut (jamais [hidden], pour éviter
   le piège de spécificité CSS déjà rencontré sur ce principe ailleurs dans
   le parc : une règle plus spécifique que [hidden] l'emportait et la barre
   ne se cachait jamais). */
.barre-riche {
  position: fixed; z-index: 500; display: none;
  align-items: center; gap: 2px; padding: 4px; background: var(--bg-1);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
.barre-riche.visible { display: flex; }
.barre-riche .boutons-base { display: flex; align-items: center; gap: 2px; }
.barre-riche button {
  appearance: none; border: 1px solid transparent; background: none; color: var(--texte);
  width: 26px; height: 26px; border-radius: 5px; cursor: pointer; font: 600 13px inherit;
  display: inline-flex; align-items: center; justify-content: center;
}
.barre-riche button:hover { background: var(--bg-2); }
.barre-riche .sep { width: 1px; align-self: stretch; margin: 2px 3px; background: var(--line); }

/* Bouton couleur (texte/surlignage) : ouvre une petite palette de presets
   plutôt que le sélecteur natif de l'OS directement — cliquer une couleur
   l'applique tout de suite, sans quitter la barre. */
.groupe-couleur { position: relative; }
.popover-couleur {
  position: absolute; top: 100%; left: 0; margin-top: 4px; z-index: 1;
  display: none; flex-direction: column; gap: 6px; padding: 8px;
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,.25); width: 132px;
}
.popover-couleur.visible { display: flex; }
.grille-couleurs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.grille-couleurs button {
  width: 100%; height: 22px; border-radius: 5px; border: 1px solid rgba(0,0,0,.15);
  cursor: pointer; padding: 0;
}
.grille-couleurs button:hover { outline: 2px solid var(--accent); outline-offset: 1px; }
.popover-couleur .personnalise {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  font-size: 11.5px; color: var(--texte-2); border-top: 1px solid var(--line); padding-top: 6px;
}
.popover-couleur .personnalise input[type=color] { width: 28px; height: 20px; padding: 0; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; }

.pv-table td.col-act { text-align: center; }
.pv-table .bouton-suppr-ligne {
  appearance: none; border: none; background: none; color: var(--texte-2); cursor: pointer;
  font-size: 13px; padding: 4px; border-radius: 4px;
}
.pv-table .bouton-suppr-ligne:hover { color: var(--danger); background: var(--danger-bg); }

.pv-section-pied { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; background: var(--bg-1); }

/* Liste à cocher (sociétés liées à un compte). */
.cases-liste { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.cases-liste label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--texte); cursor: pointer; }
.cases-liste input { width: auto; margin: 0; }

/* Historique des versions. */
.historique-item.courant { border-left: 3px solid var(--ok); padding-left: 10px; }

/* Gestion des colonnes d'un PV (dialogue pv.html). */
.liste-colonnes { display: flex; flex-direction: column; gap: 6px; }
.ligne-colonne { display: flex; align-items: center; gap: 8px; }
.ligne-colonne input[type=text] { flex: 1; }
.ligne-colonne label.case-visible { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--texte-2); white-space: nowrap; cursor: pointer; }
.ligne-colonne label.case-visible input { width: auto; margin: 0; }
.ligne-colonne .btn { padding: 5px 8px; font-size: 11px; }
