/* Check-RSJU — design system : accent rouge + hiérarchie de gris.
   Voir _dev-template/DESIGN-SYSTEM.md pour les conventions. */

:root {
  --accent: #B3261E;
  --accent-strong: #8C1C13;
  --accent-soft: #F5D9D6;
  --on-accent: #FFFFFF;

  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --surface-2: #F2F2F2;
  --surface-3: #E6E6E6;
  --on-surface: #1C1B1B;
  --on-surface-var: #5B5B5B;
  --outline: #C9C5C4;
  --outline-soft: #E2DEDD;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.12);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.16);
  --shadow-3: 0 4px 12px rgba(0, 0, 0, 0.2);

  /* Intensité de gris pour statuts/scores, la plus forte tirant vers l'accent
     (voir DESIGN-SYSTEM.md — pas de couleur par catégorie). */
  --tone-0-bg: var(--surface-2); --tone-0-fg: var(--on-surface-var);
  --tone-1-bg: #E4E4E4; --tone-1-fg: var(--on-surface);
  --tone-2-bg: #D8D3D2; --tone-2-fg: var(--on-surface);
  --tone-3-bg: var(--accent-soft); --tone-3-fg: var(--accent-strong);

  --app-loaded: 1;
}

:root[data-theme="dark"] {
  --accent: #E5988F;
  --accent-strong: #F5D9D6;
  --accent-soft: #4A2420;
  --on-accent: #3A0A05;

  --bg: #141212;
  --surface: #1E1B1B;
  --surface-2: #272323;
  --surface-3: #322D2D;
  --on-surface: #EDE9E8;
  --on-surface-var: #B8B2B1;
  --outline: #4A4444;
  --outline-soft: #363131;

  --tone-0-bg: var(--surface-2); --tone-0-fg: var(--on-surface-var);
  --tone-1-bg: #362F2F; --tone-1-fg: var(--on-surface);
  --tone-2-bg: #423838; --tone-2-fg: var(--on-surface);
  --tone-3-bg: var(--accent-soft); --tone-3-fg: var(--accent-strong);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #E5988F; --accent-strong: #F5D9D6; --accent-soft: #4A2420; --on-accent: #3A0A05;
    --bg: #141212; --surface: #1E1B1B; --surface-2: #272323; --surface-3: #322D2D;
    --on-surface: #EDE9E8; --on-surface-var: #B8B2B1;
    --outline: #4A4444; --outline-soft: #363131;
    --tone-0-bg: var(--surface-2); --tone-0-fg: var(--on-surface-var);
    --tone-1-bg: #362F2F; --tone-1-fg: var(--on-surface);
    --tone-2-bg: #423838; --tone-2-fg: var(--on-surface);
    --tone-3-bg: var(--accent-soft); --tone-3-fg: var(--accent-strong);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--on-surface);
  min-height: 100vh;
}

.mi {
  font-family: "Material Icons";
  font-size: 20px;
  line-height: 1;
  vertical-align: middle;
  -webkit-font-smoothing: antialiased;
}
body.no-icons .mi { display: none; }

/* --- Splash --- */
#splash {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 1000; transition: opacity .4s ease;
}
#splash.hide { opacity: 0; pointer-events: none; }
.splash-mark {
  width: 64px; height: 64px; border-radius: 16px; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.splash-mark .mi { color: var(--on-accent); font-size: 32px; }
@media (prefers-reduced-motion: reduce) { #splash { transition: none; } }

#unzip-error {
  display: none; position: fixed; inset: 0; z-index: 2000; background: var(--bg);
  color: var(--on-surface); padding: 24px; font-family: system-ui, sans-serif;
}

/* --- Auth screen --- */
#auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow-2); padding: 32px; text-align: center;
}
.auth-card .brand-mark {
  width: 48px; height: 48px; border-radius: 12px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 12px;
}
.auth-card .brand-mark .mi { color: var(--on-accent); }
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card .sub { color: var(--on-surface-var); font-size: 14px; margin: 0 0 20px; }
.auth-tabs { display: flex; border-bottom: 1px solid var(--outline-soft); margin-bottom: 20px; }
.auth-tab {
  flex: 1; background: none; border: none; padding: 10px; font-size: 14px; cursor: pointer;
  color: var(--on-surface-var); border-bottom: 2px solid transparent;
}
.auth-tab.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.auth-form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.auth-error, .auth-info {
  font-size: 13px; padding: 8px 12px; border-radius: 8px; margin: 0 0 12px;
}
.auth-error { background: var(--accent-soft); color: var(--accent-strong); }
.auth-info { background: var(--surface-2); color: var(--on-surface-var); }

label { font-size: 13px; color: var(--on-surface-var); display: block; margin-bottom: 4px; }
input[type="text"], input[type="email"], input[type="password"], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--outline); border-radius: 8px;
  background: var(--surface); color: var(--on-surface); font: inherit; font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--on-surface-var); }

button { font: inherit; cursor: pointer; }
.btn {
  border: none; border-radius: 8px; padding: 10px 16px; font-size: 14px; font-weight: 600;
  background: var(--surface-2); color: var(--on-surface);
}
.btn:hover { background: var(--surface-3); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-text { background: none; padding: 4px 8px; color: var(--accent); font-weight: 500; }

/* --- App shell --- */
#app-shell { min-height: 100vh; }
.appbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--outline-soft);
  box-shadow: var(--shadow-1);
}
.appbar .brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; }
.appbar .brand-mark .mi { color: var(--on-accent); font-size: 18px; }
.appbar h1 { font-size: 16px; margin: 0; font-weight: 700; }
.appbar .spacer { flex: 1; }
.appbar-btn {
  background: none; border: none; border-radius: 8px; padding: 8px; color: var(--on-surface-var);
}
.appbar-btn:hover { background: var(--surface-2); color: var(--on-surface); }

main { max-width: 1300px; margin: 0 auto; padding: 24px 20px; }
.vue[hidden] { display: none; }

/* --- Navigation principale --- */
.main-nav {
  display: flex; align-items: center; gap: 4px; padding: 0 20px; background: var(--surface);
  border-bottom: 1px solid var(--outline-soft); overflow-x: auto;
}
.nav-btn {
  display: flex; align-items: center; gap: 6px; background: none; border: none;
  padding: 12px 14px; font-size: 13px; font-weight: 600; color: var(--on-surface-var);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.nav-btn .mi { font-size: 18px; }
.nav-btn:hover { color: var(--on-surface); }
.nav-btn.active { color: var(--accent); border-color: var(--accent); }
.main-nav .spacer { flex: 1; }

/* --- Arborescence --- */
.arbre-filtres { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
.arbre-filtres input[type="search"] { flex: 1; min-width: 220px; }
.arbre-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
.arbre-domaines {
  background: var(--surface); border-radius: 12px; padding: 8px; box-shadow: var(--shadow-1);
  max-height: 70vh; overflow: auto;
}
.domaine-item {
  display: flex; align-items: center; gap: 6px; width: 100%; background: none; border: none;
  text-align: left; padding: 7px 10px; border-radius: 8px; font-size: 13px; color: var(--on-surface);
  cursor: pointer;
}
.domaine-item:hover { background: var(--surface-2); }
.domaine-item.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.domaine-item .compte { margin-left: auto; color: var(--on-surface-var); font-size: 12px; }
.domaine-item.active .compte { color: var(--accent-strong); }

.arbre-liste { display: flex; flex-direction: column; gap: 8px; }
.loi-carte {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: 12px;
  padding: 12px 16px; box-shadow: var(--shadow-1); cursor: pointer; border: none; text-align: left; width: 100%;
}
.loi-carte:hover { box-shadow: var(--shadow-2); }
.loi-carte .loi-cote { font-family: "Roboto Mono", monospace; font-size: 12px; color: var(--on-surface-var); min-width: 80px; }
.loi-carte .loi-titre { flex: 1; font-size: 14px; }
.vide-liste { color: var(--on-surface-var); font-size: 14px; padding: 20px; text-align: center; }

/* --- Écran de travail --- */
.travail-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 8px; height: calc(100vh - 260px); min-height: 400px; }
@media (max-width: 900px) { .travail-layout { grid-template-columns: 1fr; height: auto; } }
.travail-pdf { background: var(--surface-3); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-1); }
.travail-pdf iframe { width: 100%; height: 100%; border: none; min-height: 400px; }
.travail-contenu { overflow: auto; display: flex; flex-direction: column; gap: 12px; padding-right: 4px; }

.article-carte { background: var(--surface); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow-1); }
.article-carte .article-tete { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.article-carte .article-numero { font-weight: 700; font-size: 14px; }
.article-carte .article-titre-marginal { font-style: italic; color: var(--on-surface-var); font-size: 13px; }
.article-carte .article-texte { white-space: pre-wrap; font-size: 14px; line-height: 1.6; }
.article-carte.abroge .article-texte { color: var(--on-surface-var); font-style: italic; }

.verrou-banner {
  display: flex; align-items: center; gap: 8px; background: var(--accent-soft); color: var(--accent-strong);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; margin: 0 0 12px;
}
.verrou-banner .btn-text { margin-left: auto; }

.article-carte .article-numero-input { width: 90px; font-weight: 700; font-size: 13px; padding: 4px 6px; }
.article-carte .article-titre-input { flex: 1; min-width: 160px; font-size: 13px; padding: 4px 6px; }
.article-carte textarea.article-texte-edit {
  white-space: pre-wrap; font-size: 14px; line-height: 1.6; min-height: 90px; resize: vertical;
  font-family: inherit;
}
.article-carte .article-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.article-carte .article-actions .btn-text { padding: 5px 8px; border-radius: 6px; }
.article-carte .article-actions .btn-text:hover { background: var(--surface-2); }
.article-carte .article-actions .btn-text.danger { color: var(--accent-strong); }

/* Actions utilitaires peu fréquentes (réordonner, diviser, fusionner,
   supprimer) : icône seule + info-bulle native (title), pour ne pas
   monopoliser l'espace au détriment de l'action de workflow principale. */
.article-carte .article-actions-icones { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.btn-icone {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0; border: none; border-radius: 6px;
  background: none; color: var(--on-surface-var);
}
.btn-icone .mi { font-size: 18px; }
.btn-icone:hover { background: var(--surface-2); color: var(--on-surface); }
.btn-icone:disabled { opacity: .35; cursor: default; }
.btn-icone:disabled:hover { background: none; }
.btn-icone.danger:hover { background: var(--accent-soft); color: var(--accent-strong); }
.article-carte .article-meta-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }

.commentaires-bloc { margin-top: 10px; border-top: 1px solid var(--outline-soft); padding-top: 8px; }
.commentaire-item { font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--outline-soft); }
.commentaire-item:last-child { border-bottom: none; }
.commentaire-item .commentaire-tete { display: flex; gap: 8px; align-items: baseline; color: var(--on-surface-var); font-size: 12px; }
.commentaire-item .commentaire-auteur { font-weight: 600; color: var(--on-surface); }
.commentaire-item .commentaire-texte { margin-top: 2px; white-space: pre-wrap; }
.commentaire-ajout { display: flex; gap: 6px; margin-top: 8px; }
.commentaire-ajout textarea { min-height: 40px; flex: 1; font-size: 13px; }

/* --- Dashboard tiles --- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.tile { background: var(--surface); border-radius: 12px; padding: 16px; box-shadow: var(--shadow-1); }
.tile .valeur { font-size: 28px; font-weight: 700; }
.tile .libelle { font-size: 13px; color: var(--on-surface-var); }

/* --- Tone badges --- */
.tone { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.tone-0 { background: var(--tone-0-bg); color: var(--tone-0-fg); }
.tone-1 { background: var(--tone-1-bg); color: var(--tone-1-fg); }
.tone-2 { background: var(--tone-2-bg); color: var(--tone-2-fg); }
.tone-3 { background: var(--tone-3-bg); color: var(--tone-3-fg); }

/* --- Table --- */
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-1); }
th, td { text-align: left; padding: 10px 14px; font-size: 14px; border-bottom: 1px solid var(--outline-soft); }
th { color: var(--on-surface-var); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:last-child td { border-bottom: none; }

/* --- Dialog --- */
dialog {
  border: none; border-radius: 16px; padding: 0; max-width: 480px; width: calc(100% - 48px);
  box-shadow: var(--shadow-3); color: var(--on-surface); background: var(--surface);
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
#dialog-journal, #dialog-historique, #dialog-admin, #dialog-structure { max-width: 900px; }
#dialog-admin .auth-tabs { margin: 0 20px; }
#import-sql-texte { width: 100%; font-family: "Roboto Mono", monospace; font-size: 12px; }

.structure-noeud {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; font-size: 14px;
}
.structure-noeud:hover { background: var(--surface-2); }
.structure-noeud .structure-libelle { flex: 1; }
.structure-noeud .structure-libelle-input { flex: 1; border: none; background: none; font: inherit; color: inherit; padding: 2px 4px; }
.structure-noeud .structure-libelle-input:focus { outline: 1px solid var(--accent); border-radius: 4px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--outline-soft); }
.dialog-head h2 { font-size: 16px; margin: 0; }
.dialog-body { padding: 20px; max-height: 60vh; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.dialog-foot { display: flex; align-items: center; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--outline-soft); }
.dialog-foot .spacer { flex: 1; }

/* --- Toast --- */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--on-surface); color: var(--surface); padding: 10px 18px; border-radius: 8px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
  z-index: 500;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* --- Aide contextuelle --- */
.help-btn { color: var(--on-surface-var); }
.help-content { font-size: 14px; line-height: 1.6; }
.help-content kbd {
  background: var(--surface-2); border: 1px solid var(--outline); border-radius: 4px;
  padding: 1px 6px; font-family: "Roboto Mono", monospace; font-size: 12px;
}
.help-content code {
  background: var(--surface-2); border-radius: 4px; padding: 1px 5px;
  font-family: "Roboto Mono", monospace; font-size: 12px;
}
.help-content p { margin: 0 0 10px; }
.help-content p:last-child { margin-bottom: 0; }

[hidden] { display: none !important; }
