/* vault-viewer — registre visuel proche d'Obsidian, lecture au telephone d'abord.

   Deux themes. Le clair est defini sur :root, donc c'est le defaut ; le sombre
   arrive par la preference systeme, sauf si le lecteur a explicitement choisi
   clair, et par data-theme quand il bascule a la main. Les trois cas sont
   necessaires : sans le premier une preference systeme sombre est ignoree, sans
   le troisieme la bascule manuelle ne peut plus revenir en arriere. */

:root {
  --fond:    #ffffff;
  --surface: #f6f6f7;
  --eleve:   #ececed;
  --bord:    #e0e0e2;
  --texte:   #232326;
  --doux:    #55555c;
  --pale:    #8a8a92;
  --accent:  #6c53d4;
  --titre2:  #5a43b8;
  --or:      #b8860b;
  --mort:    #a99a80;
  --coche:   #4c9a3f;
  --code:    #9a4f2c;
  --voile:   rgba(20, 20, 24, .35);
  --ombre:   rgba(0, 0, 0, .14);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond:    #1a1a1e;
    --surface: #222227;
    --eleve:   #2a2a31;
    --bord:    #33333c;
    --texte:   #dcddde;
    --doux:    #a8aab0;
    --pale:    #74767e;
    --accent:  #a98cf0;
    --titre2:  #cfc2f5;
    --or:      #d2a24c;
    --mort:    #7a6a55;
    --coche:   #7bb86f;
    --code:    #e3c9a8;
    --voile:   rgba(0, 0, 0, .55);
    --ombre:   rgba(0, 0, 0, .5);
  }
}

:root[data-theme="dark"] {
  --fond:    #1a1a1e;
  --surface: #222227;
  --eleve:   #2a2a31;
  --bord:    #33333c;
  --texte:   #dcddde;
  --doux:    #a8aab0;
  --pale:    #74767e;
  --accent:  #a98cf0;
  --titre2:  #cfc2f5;
  --or:      #d2a24c;
  --mort:    #7a6a55;
  --coche:   #7bb86f;
  --code:    #e3c9a8;
  --voile:   rgba(0, 0, 0, .55);
  --ombre:   rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 17px/1.7 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- barre ---------- */
.barre {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  padding-top: calc(9px + env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--bord);
}
.marque, .icone {
  flex: none; color: var(--doux); font-size: 19px; line-height: 1;
  padding: 6px 9px; border-radius: 7px;
  background: none; border: 0; font-family: inherit; cursor: pointer;
}
.marque:hover, .icone:hover { background: var(--eleve); text-decoration: none; }
.ouvrir-switch {
  flex: 1; min-width: 0; text-align: left;
  padding: 8px 12px; font-size: 15px; font-family: inherit;
  background: var(--fond); color: var(--pale);
  border: 1px solid var(--bord); border-radius: 8px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ouvrir-switch:hover { border-color: var(--accent); color: var(--doux); }

/* ---------- explorateur ---------- */
.voile {
  position: fixed; inset: 0; z-index: 25; background: var(--voile);
}
.voile[hidden] { display: none; }

.explorateur {
  position: fixed; z-index: 28;
  top: 0; left: 0; bottom: 0; width: min(300px, 84vw);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--bord);
  padding-top: env(safe-area-inset-top, 0);
  box-shadow: 4px 0 24px var(--ombre);
}
.explorateur[hidden] { display: none; }
.explo-titre {
  padding: 13px 14px; font-size: 12px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--pale);
  border-bottom: 1px solid var(--bord); flex: none;
}
.explo-arbre { overflow-y: auto; padding: 6px 6px 24px; flex: 1; }
.explo-arbre .rien { color: var(--pale); font-size: 14px; padding: 12px; }

.noeud {
  display: block; width: 100%;
  padding: 6px 8px 6px calc(8px + var(--p) * 13px);
  font-size: 14.5px; line-height: 1.35; border-radius: 6px;
  cursor: pointer; color: var(--texte);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.noeud:hover { background: var(--eleve); text-decoration: none; }
.noeud.dossier { font-weight: 550; }
.noeud.feuille { color: var(--doux); }
.noeud.feuille.autre { font-style: italic; }
.noeud.actif { background: var(--eleve); color: var(--accent); font-weight: 600; }
.fleche {
  display: inline-block; width: 14px; color: var(--pale);
  font-size: 11px; transition: transform .12s;
}
.dossier.ouvert .fleche { transform: rotate(90deg); }
.enfants[hidden] { display: none; }

/* ---------- fil d'ariane ---------- */
.fil {
  padding: 9px 14px; font-size: 13.5px; color: var(--pale);
  border-bottom: 1px solid var(--bord);
  overflow-x: auto; white-space: nowrap;
}
.fil a { color: var(--doux); }
.fil .sep { margin: 0 7px; color: var(--pale); }

main { padding: 18px 16px 8px; max-width: 760px; margin: 0 auto; }

/* ---------- listes ---------- */
.liste { list-style: none; margin: 0; padding: 0; }
.entree {
  border-bottom: 1px solid var(--bord);
  padding: 12px 0 12px 24px; position: relative;
}
.entree::before {
  position: absolute; left: 2px; top: 12px; font-size: 13px; color: var(--pale);
}
/* Scopees a .entree : sans cela, <article class="note"> heriterait de la puce. */
.entree.dossier::before { content: "▸"; color: var(--or); }
.entree.note::before    { content: "▪"; color: var(--accent); }
.entree.fichier::before { content: "▫"; }
.entree a { font-size: 16px; }
.entree.dossier { font-weight: 400; }
.entree.dossier a { color: var(--texte); font-weight: 550; }

.chemin { display: block; font-size: 12px; color: var(--pale); margin-top: 2px; }
.extrait { margin: 6px 0 0; font-size: 14px; line-height: 1.5; color: var(--doux); }
.compte, .meta-fichier { color: var(--pale); font-size: 13.5px; margin: 0 0 16px; }
.vide { color: var(--pale); }
.avis { color: var(--or); font-size: 14px; }

.bouton {
  display: inline-block; padding: 10px 16px; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.bouton:hover { text-decoration: none; filter: brightness(1.08); }

/* ---------- note ---------- */
article.note { overflow-wrap: anywhere; }
.titre-note { font-size: 27px; line-height: 1.22; margin: 0 0 16px; font-weight: 600; }
article.note h1, article.note h2, article.note h3,
article.note h4, article.note h5 {
  line-height: 1.3; margin: 1.8em 0 .55em; font-weight: 600; scroll-margin-top: 70px;
}
article.note h1 { font-size: 24px; }
article.note h2 { font-size: 21px; color: var(--titre2); }
article.note h3 { font-size: 18.5px; }
article.note h4, article.note h5 { font-size: 16.5px; color: var(--doux); }
article.note p { margin: 0 0 1.05em; }
article.note ul, article.note ol { padding-left: 1.35em; margin: 0 0 1.05em; }
article.note li { margin-bottom: .4em; }
article.note blockquote {
  margin: 1.1em 0; padding: 3px 0 3px 15px;
  border-left: 3px solid var(--accent); color: var(--doux);
}
article.note code {
  background: var(--eleve); padding: 2px 6px; border-radius: 4px;
  font-size: .87em; font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--code);
}
article.note pre {
  background: var(--surface); border: 1px solid var(--bord);
  padding: 13px; border-radius: 8px; overflow-x: auto;
}
article.note pre code { background: none; padding: 0; color: var(--texte); }
article.note img, article.note .embed { max-width: 100%; height: auto; border-radius: 8px; }
article.note hr { border: 0; border-top: 1px solid var(--bord); margin: 2.2em 0; }

/* taches : inertes, le viewer est en lecture seule */
li.tache { list-style: none; margin-left: -1.35em; }
li.tache input { margin-right: 8px; accent-color: var(--coche); }
li.tache.faite { color: var(--pale); text-decoration: line-through; }

/* tableaux : defilables, sinon une colonne etroite coupe les mots */
article.note table, table.csv {
  display: block; overflow-x: auto; max-width: 100%;
  border-collapse: collapse; font-size: 14px;
}
article.note th, article.note td, table.csv th, table.csv td {
  border: 1px solid var(--bord); padding: 7px 10px;
  text-align: left; vertical-align: top; white-space: normal; min-width: 90px;
}
article.note th, table.csv th {
  background: var(--eleve); font-weight: 600; position: sticky; top: 0;
}
.defile { overflow-x: auto; }
table.csv td { max-width: 320px; }

.wikilink { border-bottom: 1px solid color-mix(in srgb, var(--accent) 38%, transparent); }
.lien-mort { color: var(--mort); border-bottom: 1px dashed var(--mort); cursor: help; }

/* ---------- replis ---------- */
.repli { margin: 0 0 16px; border: 1px solid var(--bord); border-radius: 8px; background: var(--surface); }
.repli summary {
  cursor: pointer; padding: 10px 13px; color: var(--doux); font-size: 13.5px;
}
.repli[open] summary { border-bottom: 1px solid var(--bord); }
.propr, .source {
  margin: 0; padding: 13px; font-size: 13px; overflow-x: auto; color: var(--doux);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word;
}
.source {
  background: var(--surface); border: 1px solid var(--bord); border-radius: 8px;
  white-space: pre;
}
.sommaire ul { list-style: none; margin: 0; padding: 10px 13px; }
.sommaire li { margin: 0; padding: 3px 0; font-size: 14.5px; }
.sommaire .n2 { padding-left: 14px; }
.sommaire .n3 { padding-left: 28px; font-size: 14px; }
.sommaire .n4 { padding-left: 42px; font-size: 13.5px; }

/* ---------- mentions liees ---------- */
.entrants { margin-top: 40px; padding-top: 6px; border-top: 1px solid var(--bord); }
.entrants h2 {
  font-size: 13.5px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--pale); font-weight: 600; margin: 16px 0 6px;
}

/* ---------- acces rapide ---------- */
.switch {
  position: fixed; inset: 0; z-index: 40; background: var(--voile);
  display: flex; justify-content: center; padding: 12vh 14px 14px;
}
.switch[hidden] { display: none; }
.switch-boite {
  width: 100%; max-width: 560px; max-height: 70vh;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--bord);
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 18px 50px var(--ombre);
}
#switch-champ {
  padding: 14px 16px; font-size: 16px; font-family: inherit;
  background: var(--eleve); color: var(--texte); border: 0;
  border-bottom: 1px solid var(--bord);
}
#switch-champ:focus { outline: none; }
#switch-liste { list-style: none; margin: 0; padding: 6px; overflow-y: auto; }
#switch-liste li a {
  display: block; padding: 9px 11px; border-radius: 7px;
  color: var(--texte); font-size: 15.5px;
}
#switch-liste li a:hover { background: var(--eleve); text-decoration: none; }
#switch-liste .rien { padding: 14px; color: var(--pale); font-size: 14.5px; }

/* ---------- pied ---------- */
footer {
  display: flex; justify-content: space-between;
  padding: 26px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  max-width: 760px; margin: 0 auto;
  border-top: 1px solid var(--bord); font-size: 13px; color: var(--pale);
}

/* ---------- login ---------- */
.page-login {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh; padding: 16px;
}
.carte-login {
  width: 100%; max-width: 340px;
  background: var(--surface); border: 1px solid var(--bord);
  border-radius: 12px; padding: 28px 24px;
  display: flex; flex-direction: column; gap: 14px;
}
.carte-login h1 {
  margin: 0 0 4px; font-size: 21px; font-weight: 600;
  letter-spacing: .04em; text-align: center;
}
.carte-login input {
  padding: 11px 13px; font-size: 16px;
  background: var(--fond); color: var(--texte);
  border: 1px solid var(--bord); border-radius: 8px;
}
.carte-login button {
  padding: 11px; font-size: 16px; font-weight: 600;
  background: var(--accent); color: #fff;
  border: 0; border-radius: 8px; cursor: pointer;
}
.erreur { margin: 0; color: #c0392b; font-size: 14px; text-align: center; }
:root[data-theme="dark"] .erreur { color: #e88a7d; }

/* ---------- grand ecran : explorateur permanent, comme dans Obsidian ---------- */
@media (min-width: 1000px) {
  body.avec-explo .barre,
  body.avec-explo .fil,
  body.avec-explo main,
  body.avec-explo footer { margin-left: 300px; }
  body.avec-explo .explorateur { box-shadow: none; }
  body.avec-explo .voile { display: none; }
  main { padding: 28px 16px 8px; }
}
