/* FTB Workspace — feuille de style unique, aucun framework. */

:root {
  --bg: #ffffff;
  --bg-sidebar: #f7f7f5;
  --bg-hover: #ecebe9;
  --bg-active: #e3e2df;
  --bg-inset: #f4f4f2;
  --text: #32302c;
  --text-soft: #6b6862;
  --text-faint: #9a968e;
  --border: #e6e4e0;
  --accent: #2f6db5;
  --accent-soft: #e8f0f9;
  --danger: #c0392b;
  --shadow: 0 8px 28px rgba(15, 15, 15, .14);
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #1f1f1f;
  --bg-sidebar: #191919;
  --bg-hover: #2c2c2c;
  --bg-active: #363636;
  --bg-inset: #262626;
  --text: #e9e7e4;
  --text-soft: #a8a49e;
  --text-faint: #74706a;
  --border: #333130;
  --accent: #6ea8e8;
  --accent-soft: #24354a;
  --danger: #e08074;
  --shadow: 0 8px 28px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }

/* Une regle d'id (#app{display:flex}) l'emporte sur [hidden] de la feuille
   du navigateur : il faut donc reaffirmer explicitement le masquage. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; font-size: inherit; color: inherit; }

#app { display: flex; height: 100vh; overflow: hidden; }

/* ---------------------------------------------------------------- sidebar */

#sidebar {
  width: 268px;
  flex: 0 0 268px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: margin-left .18s ease;
}

#sidebar.collapsed { margin-left: -268px; }

.side-head {
  padding: 12px 12px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.side-title {
  font-weight: 650;
  font-size: 14px;
  letter-spacing: .2px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 4px;
  padding: 4px 6px;
  line-height: 1;
  color: var(--text-soft);
  font-size: 14px;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.side-search {
  margin: 0 10px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: var(--radius);
  background: var(--bg-hover);
  color: var(--text-soft);
  font-size: 13.5px;
  cursor: pointer;
  border: 0;
  width: calc(100% - 20px);
  text-align: left;
}
.side-search:hover { background: var(--bg-active); }
.side-search kbd {
  margin-left: auto;
  font-family: var(--font);
  font-size: 11px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 4px;
}

#tree { flex: 1; overflow-y: auto; padding: 4px 8px 40px; }

.tree-row {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 4px;
  padding: 3px 4px;
  cursor: pointer;
  color: var(--text-soft);
  font-size: 14px;
  user-select: none;
}
.tree-row:hover { background: var(--bg-hover); color: var(--text); }
.tree-row.active { background: var(--bg-active); color: var(--text); font-weight: 550; }
.tree-row.drop-into { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.tree-row.dragging { opacity: .4; }

.twisty {
  width: 18px;
  flex: 0 0 18px;
  text-align: center;
  font-size: 10px;
  color: var(--text-faint);
  transition: transform .12s ease;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
}
.twisty.open { transform: rotate(90deg); }
.twisty.leaf { visibility: hidden; }

.tree-icon { width: 18px; flex: 0 0 18px; text-align: center; font-size: 14px; }

.tree-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-add {
  opacity: 0;
  border: 0;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0 4px;
  font-size: 15px;
  border-radius: 3px;
}
.tree-row:hover .tree-add { opacity: 1; }
.tree-add:hover { background: var(--bg-active); color: var(--text); }

.side-foot {
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-faint);
}
.side-foot button { flex: 0 0 auto; }
.new-page-btn {
  flex: 1;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 13.5px;
}
.new-page-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ------------------------------------------------------------------ main */

#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: 44px;
  flex: 0 0 44px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  font-size: 13.5px;
  color: var(--text-soft);
}

.crumbs { display: flex; align-items: center; gap: 4px; flex: 1; overflow: hidden; white-space: nowrap; }
.crumbs a { color: var(--text-soft); text-decoration: none; cursor: pointer; padding: 2px 4px; border-radius: 3px; }
.crumbs a:hover { background: var(--bg-hover); color: var(--text); }
.crumbs span.sep { color: var(--text-faint); }

#status { font-size: 12px; color: var(--text-faint); min-width: 90px; text-align: right; }

#scroll { flex: 1; overflow-y: auto; }

.doc { max-width: 780px; margin: 0 auto; padding: 48px 60px 45vh; }

.page-icon-btn {
  border: 0;
  background: transparent;
  font-size: 46px;
  line-height: 1;
  cursor: pointer;
  padding: 0 0 6px;
  border-radius: 6px;
}
.page-icon-btn:hover { background: var(--bg-hover); }

#title {
  font-size: 38px;
  font-weight: 700;
  line-height: 1.2;
  outline: none;
  margin: 0 0 10px;
  letter-spacing: -.5px;
}
#title:empty::before { content: "Sans titre"; color: var(--text-faint); }

/* ---------------------------------------------------------------- blocks */

.block {
  position: relative;
  display: flex;
  align-items: flex-start;
  margin: 1px 0;
  border-radius: 3px;
}
.block.drag-over-top { box-shadow: 0 -2px 0 var(--accent); }
.block.drag-over-bottom { box-shadow: 0 2px 0 var(--accent); }
.block.dragging { opacity: .35; }

.gutter {
  position: absolute;
  left: -46px;
  top: 2px;
  display: flex;
  gap: 1px;
  opacity: 0;
  transition: opacity .12s;
}
.block:hover .gutter { opacity: 1; }

.gutter button {
  border: 0;
  background: transparent;
  color: var(--text-faint);
  cursor: grab;
  border-radius: 3px;
  padding: 2px 3px;
  font-size: 13px;
  line-height: 1.3;
}
.gutter button:hover { background: var(--bg-hover); color: var(--text); }

.content {
  flex: 1;
  outline: none;
  min-height: 1.55em;
  padding: 2px 2px;
  white-space: pre-wrap;
  word-break: break-word;
}
.content:empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint);
  pointer-events: none;
}

.block[data-type="h1"] .content { font-size: 29px; font-weight: 680; line-height: 1.3; margin-top: 22px; letter-spacing: -.3px; }
.block[data-type="h2"] .content { font-size: 23px; font-weight: 660; line-height: 1.3; margin-top: 18px; }
.block[data-type="h3"] .content { font-size: 18.5px; font-weight: 640; line-height: 1.35; margin-top: 12px; }

.block[data-type="quote"] { padding-left: 0; }
.block[data-type="quote"] .content {
  border-left: 3px solid var(--text);
  padding-left: 12px;
  color: var(--text-soft);
}

.block[data-type="code"] .content {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  line-height: 1.5;
  overflow-x: auto;
}

.marker {
  flex: 0 0 auto;
  user-select: none;
  padding: 2px 6px 0 2px;
  color: var(--text-soft);
  min-width: 20px;
}
.block[data-type="bullet"] .marker { font-size: 17px; line-height: 1.35; }

.marker input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 4px 2px 0 0;
  cursor: pointer;
  accent-color: var(--accent);
}
.block[data-type="todo"].done .content { color: var(--text-faint); text-decoration: line-through; }

.block[data-type="divider"] { padding: 8px 0; }
.divider-line { flex: 1; height: 1px; background: var(--border); }

.block[data-type="image"] .content { padding: 0; }
.block[data-type="image"] img { max-width: 100%; border-radius: var(--radius); display: block; }

.content a { color: var(--accent); text-decoration: none; border-bottom: 1px solid rgba(47,109,181,.35); cursor: pointer; }
.content a:hover { background: var(--accent-soft); }
.content a.wl-missing { color: var(--text-faint); border-bottom-style: dashed; }
.content code {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--bg-inset);
  padding: 1px 5px;
  border-radius: 3px;
  color: #c0392b;
}
:root[data-theme="dark"] .content code { color: #e5928a; }

/* ------------------------------------------------------------- backlinks */

#backlinks { max-width: 780px; margin: 40px auto 0; padding: 0 60px; }
.bl-head {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-bottom: 8px;
}
.bl-item {
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 2px;
}
.bl-item:hover { background: var(--bg-hover); }
.bl-item .t { font-weight: 560; font-size: 14px; }
.bl-item .e { font-size: 12.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------------------------------------------------------------- popups */

.menu {
  position: absolute;
  z-index: 60;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 260px;
  max-height: 320px;
  overflow-y: auto;
}
.menu-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-faint);
  padding: 4px 8px;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
}
.menu-item .mi-icon {
  width: 26px; height: 26px;
  flex: 0 0 26px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  background: var(--bg-inset);
}
.menu-item .mi-sub { font-size: 12px; color: var(--text-faint); }
.menu-item.sel, .menu-item:hover { background: var(--bg-hover); }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 15, .35);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  z-index: 80;
}
.palette {
  width: min(640px, 92vw);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.palette input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  font-size: 16px;
  background: transparent;
  color: var(--text);
  outline: none;
  font-family: inherit;
}
.palette-results { max-height: 52vh; overflow-y: auto; padding: 6px; }
.pal-item { padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.pal-item.sel, .pal-item:hover { background: var(--bg-hover); }
.pal-item .t { font-size: 14.5px; font-weight: 550; }
.pal-item .e { font-size: 12.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-empty { padding: 18px; text-align: center; color: var(--text-faint); font-size: 14px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 13.5px;
  z-index: 200;
  box-shadow: var(--shadow);
}

@media (max-width: 820px) {
  #sidebar { position: absolute; z-index: 50; height: 100%; box-shadow: var(--shadow); }
  .doc { padding: 32px 22px 45vh; }
  #backlinks { padding: 0 22px; }
  .gutter { left: -30px; }
}

/* ------------------------------------------------------------------ tables */

/* Pages de registres : la page s'élargit pour que les colonnes respirent. */
.doc.doc-large { max-width: 1240px; }

.block[data-type="table"] .content { min-width: 0; padding: 2px 0; white-space: normal; word-break: normal; overflow-wrap: normal; }
.table-wrap {
  overflow: auto;
  max-height: 78vh;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.md-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 13.8px;
}
.md-table th, .md-table td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
  line-height: 1.45;
}
.md-table th:last-child, .md-table td:last-child { border-right: 0; }
.md-table tbody tr:last-child td { border-bottom: 0; }
.md-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-inset);
  font-weight: 600;
  font-size: 12.5px;
  white-space: nowrap;
}
.md-table tr:hover td { background: var(--bg-hover); }

/* colonnes courtes : sur une seule ligne */
.md-table [data-col="id"], .md-table [data-col="chantier"], .md-table [data-col="pilote"],
.md-table [data-col="echeance"], .md-table [data-col="date"], .md-table [data-col="statut"],
.md-table [data-col="j_moins"], .md-table [data-col="jour"], .md-table [data-col="qui"],
.md-table [data-col="responsable"], .md-table [data-col="sens"], .md-table [data-col="palier_vise"],
.md-table [data-col="probabilite"], .md-table [data-col="impact"] { white-space: nowrap; }
/* colonnes de texte : assez larges pour se lire */
.md-table [data-col="action"], .md-table [data-col="decision"], .md-table [data-col="risque"],
.md-table [data-col="parade"], .md-table [data-col="jalon"], .md-table [data-col="engagement"] { min-width: 22em; }
.md-table [data-col="prochaine_etape"], .md-table [data-col="critere_de_reussite"], .md-table [data-col="commentaire"],
.md-table [data-col="contreparties_livrees"], .md-table [data-col="poste"], .md-table [data-col="preuve_attendue"],
.md-table [data-col="organisation"] { min-width: 14em; }
/* colonnes techniques : discrètes */
.md-table td[data-col="source"], .md-table td[data-col="depend_de"] { font-size: 11.5px; color: var(--text-faint); max-width: 16em; word-break: break-word; }
.md-table th[data-col="source"], .md-table th[data-col="depend_de"] { color: var(--text-faint); font-weight: 500; }
@media (max-width: 900px) {
  .md-table [data-col="source"], .md-table [data-col="depend_de"] { display: none; }
}

.block[data-type="table"] .content[data-raw="1"] {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  white-space: pre;
  overflow-x: auto;
}

/* pastilles de statut */
.pastille {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  color: #fff;
  background: #8a8780;
}
.pastille-gris { background: #8a8780; }
.pastille-bleu { background: #0062FF; }
.pastille-vert { background: #2e7d4f; }
.pastille-rouge { background: #E62A45; }
.pastille-neutre { background: var(--bg-active); color: var(--text); font-weight: 500; }

/* registres d'actions et de décisions : vue en cartes */
.block.registre-bloc { display: block; }
.registre { flex: 1; min-width: 0; }
.vue-barre { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: 2px 0 10px; }
.vue-info { font-size: 13px; color: var(--text-soft); }
.vue-bouton {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.vue-bouton:hover { background: var(--bg-hover); }
.vue-bouton.principal { background: var(--accent); border-color: var(--accent); color: #fff; }
.cartes-groupe { margin: 0 0 18px; }
.cartes-titre { display: flex; align-items: baseline; gap: 8px; font-size: 16px; font-weight: 650; margin: 14px 0 8px; }
.cartes-nombre { font-size: 12px; font-weight: 500; color: var(--text-faint); }
.cartes { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 8px; }
.carte {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  min-width: 0;
}
.carte:hover { background: var(--bg-hover); }
.carte:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.carte-texte { font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.carte-pied { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.carte-date { font-family: var(--mono); font-size: 12.5px; color: var(--text-soft); }
.carte-date.retard { color: #E62A45; font-weight: 600; }
.carte-ref { font-size: 11.5px; color: var(--text-faint); }

/* formulaire de modification d'une ligne */
.palette.fiche { padding: 18px 20px; max-height: 80vh; overflow-y: auto; }
.fiche-titre { font-size: 16px; font-weight: 600; margin-bottom: 10px; }
.fiche-champ { display: block; margin: 0 0 10px; }
.fiche-nom { display: block; font-size: 12px; color: var(--text-soft); margin-bottom: 3px; }
.fiche-champ input, .fiche-champ select, .fiche-champ textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  font: inherit;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}
.fiche-champ textarea { resize: vertical; }
.fiche-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* Lot J2 : double authentification */
.totp-cle { display: block; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 17px; letter-spacing: 1px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; user-select: all; word-break: break-all; }
.totp-uri { margin: 8px 0 4px; font-size: 12.5px; color: var(--text-soft); }
.totp-uri code { display: block; margin-top: 6px; word-break: break-all; user-select: all; }
.totp-etapes { margin: 4px 0 12px 18px; padding: 0; font-size: 14px; }
.totp-secours { list-style: none; padding: 0; columns: 2; margin: 8px 0 16px; }
.totp-secours code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; }

/* Lot J1 : pages liées au cerveau */
.bandeau-lecture, .bandeau-source { font-size: 12.5px; color: var(--text-soft); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px; margin: 0 0 14px; }
.bandeau-lecture { border-style: dashed; }
