:root {
  --fond: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --bord: #e3e5e9;
  --texte: #1c2230;
  --texte-2: #5d6576;
  --accent: #2563eb;
  --accent-texte: #ffffff;
  --accent-doux: #e8efff;
  --danger: #c2372f;
  --succes: #1f9d55;
  --ombre: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --rayon: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #12151b;
    --surface: #1b1f27;
    --surface-2: #222733;
    --bord: #2f3542;
    --texte: #e7e9ee;
    --texte-2: #9aa3b5;
    --accent: #5b8cff;
    --accent-texte: #0b1020;
    --accent-doux: #1f2a44;
    --danger: #ff6b61;
    --succes: #4ade80;
    --ombre: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--fond);
  color: var(--texte);
}

h1, h2 { margin: 0; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }

/* --- Boutons --- */
.bouton {
  border: 1px solid var(--bord);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.bouton:hover:not(:disabled) { background: var(--surface-2); }
.bouton:disabled { opacity: .55; cursor: default; }
.bouton.principal { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); }
.bouton.principal:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.bouton.danger { color: var(--danger); }
.bouton.petit { padding: 3px 10px; font-size: 13px; }
.bouton.discret { border-color: transparent; background: transparent; color: var(--texte-2); }

input, select, textarea {
  border: 1px solid var(--bord);
  border-radius: 8px;
  background: var(--surface);
  padding: 7px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus, [contenteditable]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* --- Connexion --- */
.ecran-connexion { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.carte-connexion {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--ombre);
  display: grid;
  gap: 10px;
}
.carte-connexion h1 { font-size: 26px; }
.sous-titre { margin: 0 0 8px; color: var(--texte-2); }
.erreur { color: var(--danger); min-height: 1.5em; margin: 0; }

/* --- En-tête --- */
#application { display: flex; flex-direction: column; height: 100%; }
.entete {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--bord);
}
.logo { font-size: 19px; }
.onglets { display: flex; gap: 4px; }
.onglet {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--texte-2);
}
.onglet.actif { background: var(--accent-doux); color: var(--accent); font-weight: 600; }
.entete-droite { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.etat { color: var(--danger); font-size: 12px; }
.etat.connecte { color: var(--succes); }
.lien-discret { color: var(--texte-2); text-decoration: none; font-size: 14px; }
.lien-discret:hover { color: var(--accent); }

.bandeau {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  background: var(--accent-doux);
  color: var(--accent);
  font-weight: 500;
}
.spinner {
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: tourner .8s linear infinite;
}
@keyframes tourner { to { transform: rotate(360deg); } }

/* --- Vue documents --- */
.vue-documents {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  min-height: 0;
}
.liste {
  border-right: 1px solid var(--bord);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.liste > input { margin: 12px; width: auto; }
.liste-documents { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; }
.item-document {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
}
.item-document:hover { background: var(--surface-2); }
.item-document.choisi { background: var(--accent-doux); }
.item-titre { font-weight: 600; display: flex; gap: 6px; align-items: baseline; }
.item-meta { font-size: 12.5px; color: var(--texte-2); }
.item-apercu {
  font-size: 13px;
  color: var(--texte-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.pastille {
  font-size: 11px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-texte);
  border-radius: 999px;
  padding: 0 7px;
  flex-shrink: 0;
}
.vide { color: var(--texte-2); padding: 16px; margin: 0; }

.detail { overflow-y: auto; padding: 24px 32px 48px; min-width: 0; }
.detail-entete { margin-bottom: 18px; }
.titre-document { font-size: 24px; border-radius: 6px; padding: 2px 4px; margin-left: -4px; }
.titre-document:hover { background: var(--surface); }
.detail-meta { color: var(--texte-2); font-size: 13.5px; margin: 4px 0 14px; }
.barre-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.pages { display: grid; gap: 16px; max-width: 900px; }
.page {
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
}
.page-entete {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--bord);
  flex-wrap: wrap;
}
.page-numero { font-weight: 600; }
.page-date { font-size: 12.5px; color: var(--texte-2); }
.espace { flex: 1; }
.page-texte {
  padding: 16px 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  min-height: 3em;
  border-radius: 0 0 var(--rayon) var(--rayon);
}

/* --- Configuration --- */
.vue-configuration { flex: 1; overflow-y: auto; padding: 24px 32px 48px; display: grid; gap: 20px; align-content: start; }
.carte {
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 20px;
  max-width: 900px;
  display: grid;
  gap: 14px;
  justify-items: start;
}
.carte h2 { font-size: 18px; }
.aide { margin: 0; color: var(--texte-2); font-size: 14px; }
.profils { display: grid; gap: 12px; width: 100%; }
.profil {
  border: 1px solid var(--bord);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 8px;
  background: var(--surface-2);
}
.profil-ligne { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.profil-ligne input[name="nom"] { flex: 1; min-width: 180px; font-weight: 600; }
.profil-ligne select { width: auto; max-width: 100%; }
.case { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.case input { width: auto; }
.profil > .case { white-space: normal; font-size: 14px; }
.grille-champs { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; width: 100%; }
.grille-champs label, .champ-large { display: grid; gap: 4px; font-size: 14px; color: var(--texte-2); width: 100%; }

/* --- Toast --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--texte);
  color: var(--fond);
  padding: 10px 18px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100% - 32px);
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.erreur { background: var(--danger); color: #fff; }

/* --- Petits écrans --- */
@media (max-width: 760px) {
  .entete { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .entete-droite { margin-left: 0; width: 100%; justify-content: space-between; }
  .vue-documents { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .liste { border-right: 0; border-bottom: 1px solid var(--bord); max-height: 40vh; }
  .detail, .vue-configuration { padding: 16px; }
}
