:root {
  --bg: #f0f2f5;
  --panel: #fff;
  --line: #dcdfe6;
  --text: #222;
  --muted: #5f6573;
  --btn: #f4f5f7;
  --btnh: #e4e7eb;
  --on: #d6e4ff;
  --paper: #fff;
  --paper-text: #222;
  --accent: #f1c40f;
  --accent-blue: #026fae;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

#app-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}
#app-screen > .work {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#14151b; --panel:#1f2029; --line:#34364a; --text:#e6e6ef; --muted:#9a9cb5;
    --btn:#2a2c3b; --btnh:#363950; --on:#3a4a78; --paper:#1a1b22; --paper-text:#e6e6ef;
  }
}
:root[data-theme="dark"] {
  --bg:#14151b; --panel:#1f2029; --line:#34364a; --text:#e6e6ef; --muted:#9a9cb5;
  --btn:#2a2c3b; --btnh:#363950; --on:#3a4a78; --paper:#1a1b22; --paper-text:#e6e6ef;
}

html { scroll-padding-top: env(safe-area-inset-top, 0px); }
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', Tahoma, Verdana, sans-serif; }
html, body { height: 100%; }
body { display: flex; flex-direction: column; background: var(--bg); color: var(--text); }
button, select { color: var(--text); }
button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent-blue); outline-offset: 1px;
}

.nav {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; background: #1e1e2d; color: #fff;
  transition: transform .25s;
}
.nav b { white-space: nowrap; }
.nb {
  background: #3f3f5a; color: #fff; border: 0; border-radius: 4px;
  padding: 7px 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.nb:hover { background: #52527a; }
.nb:disabled { opacity: .4; cursor: default; }
.nb.icon { padding: 6px 10px; font-size: 1rem; }

#crumb {
  flex: 1; min-width: 0; overflow: hidden; white-space: nowrap;
  text-overflow: ellipsis; color: #a2a2c2; font-size: .95rem;
}
#crumb strong { color: #fff; }
#crumb button { background: none; border: 0; color: #a2a2c2; cursor: pointer; font-size: inherit; }
#crumb button:hover { color: #fff; text-decoration: underline; }
#crumb i { margin: 0 6px; font-style: normal; color: #5c5c7a; }
#st { font-size: .8rem; color: #8ad8a0; white-space: nowrap; }

.work { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.bar {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; overflow-x: auto;
  background: var(--panel); border-bottom: 1px solid var(--line);
  transition: transform .25s;
}
.g { display: flex; align-items: center; gap: 4px; padding-right: 8px; border-right: 1px solid var(--line); flex: none; }
.g:last-child { border-right: 0; }
.bar button, .bar select, .col, .row button {
  background: var(--btn); border: 1px solid var(--line); border-radius: 4px;
  min-height: 34px; min-width: 34px; padding: 4px 9px; font-size: .88rem; cursor: pointer;
}
.bar button:hover, .bar select:hover, .col:hover, .row button:hover { background: var(--btnh); }
.bar button.on { background: var(--on); border-color: #7aa7f7; }
.col { position: relative; display: inline-flex; align-items: center; justify-content: center; overflow: hidden; }
.col input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.col span { font-weight: 700; border-bottom: 3px solid currentColor; line-height: 1; }
.bar .mn { background: var(--accent); color: #2c3e50; border: 0; font-weight: 700; }
.bar .mz { background: var(--accent-blue); color: #fff; border: 0; font-weight: 700; }
.bar .mx { font-weight: 600; }

.row {
  flex: none; display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.row[hidden] { display: none; }
.row input {
  flex: 1; min-width: 160px; font-size: 16px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 4px; background: var(--bg); color: var(--text);
}
#pal button { width: 38px; height: 38px; font-size: 1.15rem; padding: 0; }

.scroll {
  flex: 1; min-height: 0; overflow-y: auto; padding: 30px 16px;
  display: flex; flex-direction: column; align-items: center;
}

#page {
  width: 100%; 
  max-width: 820px;
  min-height: 600px; /* Taille minimum normale, plus de 1000px géant */
  padding: 56px 64px;
  background: var(--paper); color: var(--paper-text);
  border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
  font-size: 16px; line-height: 1.7;
  outline: 0; overflow-wrap: anywhere; flex-shrink: 0;
  transition: max-width .25s;
  margin-bottom: 50px; /* Laisse un peu d'espace en bas */
}
#page * { font-family: inherit; }
#page p, #page h1, #page h2, #page h3, #page blockquote, #page div { text-align: inherit; }
#page:empty::before { content: attr(data-ph); color: #999; pointer-events: none; }
#page h1 { font-size: 2rem; margin: .8em 0 .4em; line-height: 1.25; }
#page h2 { font-size: 1.5rem; margin: .8em 0 .4em; line-height: 1.3; }
#page h3 { font-size: 1.2rem; margin: .8em 0 .3em; }
#page p { margin: 0 0 .6em; }
#page ul, #page ol { margin: 0 0 .6em 1.6em; }
#page blockquote { margin: .8em 0; padding: 4px 16px; border-left: 4px solid #c9ccd3; color: #888; font-style: italic; }
#page hr { border: 0; border-top: 2px solid var(--line); margin: 1.2em 0; }
#page a { color: var(--accent-blue); }

/* Images dans le document */
#page figure.doc-img {
  margin: 1.2em 0; text-align: center;
  background: var(--bg); border-radius: 6px; padding: 8px;
}
#page figure.doc-img img {
  max-width: 100%; height: auto; border-radius: 4px; display: block; margin: 0 auto;
}
#page figure.doc-img figcaption {
  font-size: .85em; color: var(--muted); font-style: italic; margin-top: 6px;
}

.text-mode-note {
  background: #fff2ac; border-bottom: 2px solid var(--accent);
  color: #222; cursor: pointer; padding: 2px 4px; border-radius: 3px; font-weight: 600;
}
.text-mode-note:hover { background: #ffe97a; }
.text-mode-zone {
  background: #e1f5fe; border-bottom: 2px solid var(--accent-blue);
  color: var(--accent-blue); cursor: pointer; padding: 2px 4px; border-radius: 3px; font-weight: 700;
}
.text-mode-zone::after { content: " 🚪"; }
.text-mode-zone:hover { background: #b3e5fc; }

#stats {
  display: flex; gap: 18px; padding: 16px 4px 30px;
  font-size: .85rem; color: var(--muted); flex-shrink: 0; flex-wrap: wrap;
}

/* Panneaux génériques (lib, toc, search, drawer) */
#lib, #toc, #search {
  position: fixed; top: 0; bottom: 0; z-index: 25;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 0 25px rgba(0,0,0,.15);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transition: transform .25s, visibility .25s;
  visibility: hidden;
}
#lib { left: 0; width: 300px; transform: translateX(-100%); }
#toc { right: 0; width: 320px; transform: translateX(100%); }
#search { right: 0; width: 380px; transform: translateX(100%); }
#lib.open, #toc.open, #search.open { transform: none; visibility: visible; }

#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 340px; z-index: 20;
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: -4px 0 15px rgba(0,0,0,.15);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transform: translateX(100%); visibility: hidden;
  transition: transform .25s, visibility .25s;
}
#drawer.open { transform: none; visibility: visible; }

.dh {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.dh h3 { font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dh > button, .dh div button { border: 0; background: var(--btn); border-radius: 6px; padding: 7px 11px; cursor: pointer; font-weight: 700; }
#ds { background: #2ecc71; color: #fff; }

/* Bibliothèque */
.lib-list { flex: 1; overflow-y: auto; padding: 8px 0; }
.lib-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; cursor: pointer; font-size: .9rem;
  border-left: 3px solid transparent;
}
.lib-item:hover { background: var(--btnh); }
.lib-item.active { background: var(--on); border-left-color: var(--accent); }
.lib-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.lib-actions { display: none; gap: 2px; }
.lib-item:hover .lib-actions { display: flex; }
.lib-actions button { background: transparent; border: 0; cursor: pointer; padding: 2px 4px; font-size: .85rem; border-radius: 3px; }
.lib-actions button:hover { background: var(--btn); }
.lib-foot { padding: 12px; border-top: 1px solid var(--line); }
.lib-foot button { width: 100%; padding: 9px; background: var(--accent); color: #2c3e50; border: 0; border-radius: 6px; font-weight: 700; cursor: pointer; }

/* Drawer */
.drawer-title-row { padding: 10px 16px 0; }
.drawer-title-row[hidden] { display: none; }
.drawer-title-row input {
  width: 100%; padding: 8px 10px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text);
}
#drawer textarea {
  flex: 1; margin: 14px 16px; padding: 12px;
  border: 1px solid var(--line); border-radius: 6px; resize: none;
  font-size: 16px; line-height: 1.5; background: var(--bg); color: var(--text);
}
#dd {
  margin: 0 16px 14px; align-self: flex-start;
  background: none; border: 1px solid #e0b4b0; color: #c0392b;
  padding: 7px 12px; border-radius: 6px; cursor: pointer;
}

/* Sommaire */
.toc-body { flex: 1; overflow-y: auto; padding: 12px 0; }
.toc-section { margin-bottom: 14px; padding: 0 12px; }
.toc-page {
  font-weight: 700; padding: 6px 8px; cursor: pointer; border-radius: 4px;
  color: var(--text);
}
.toc-page:hover { background: var(--btnh); }
.toc-h {
  padding: 4px 8px; cursor: pointer; font-size: .88rem; color: var(--muted);
  border-left: 2px solid var(--line); margin-left: 12px; border-radius: 0 4px 4px 0;
}
.toc-h:hover { background: var(--btnh); color: var(--text); }
.toc-h1 { font-weight: 600; margin-left: 8px; }
.toc-h2 { margin-left: 20px; }
.toc-h3 { margin-left: 32px; font-size: .82rem; }
.empty { padding: 20px; color: var(--muted); font-size: .9rem; text-align: center; }

/* Recherche */
.search-body { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }
#searchInput {
  width: 100%; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text);
}
.search-results { flex: 1; overflow-y: auto; }
.search-card { margin-bottom: 12px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.sc-title {
  padding: 8px 12px; background: var(--btnh); font-weight: 700; font-size: .9rem;
  display: flex; justify-content: space-between; align-items: center;
}
.sc-count { background: var(--accent-blue); color: #fff; font-size: .75rem; padding: 1px 7px; border-radius: 10px; }
.sc-excerpt {
  padding: 8px 12px; font-size: .85rem; color: var(--text);
  border-top: 1px solid var(--line); cursor: pointer; line-height: 1.5;
}
.sc-excerpt:hover { background: var(--btnh); }
.sc-excerpt mark { background: #ffe066; color: #222; padding: 0 2px; border-radius: 2px; }

/* Menu export */
.menu {
  position: fixed; top: 56px; right: 16px; z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.15); overflow: hidden; min-width: 220px;
}
.menu[hidden] { display: none; }
.menu button {
  display: block; width: 100%; text-align: left;
  padding: 11px 16px; background: none; border: 0;
  cursor: pointer; font-size: .92rem; color: var(--text);
}
.menu button:hover { background: var(--btnh); }

#toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: #1e1e2d; color: #fff;
  padding: 9px 16px; border-radius: 6px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s;
  z-index: 40; max-width: 90%;
}
#toast.on { opacity: 1; }

/* ================= MODE FOCUS ================= */
body.focus-mode .nav,
body.focus-mode .bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 15;
  transform: translateY(-100%); opacity: 0;
  transition: transform .3s, opacity .3s;
}
body.focus-mode .nav { top: 0; }
body.focus-mode .bar { top: 52px; }

/* Zone sensible en haut : si on passe la souris là, la barre revient */
body.focus-mode::before {
  content: ''; position: fixed; top: 0; left: 0; right: 0; height: 40px; z-index: 14;
}

body.focus-mode .nav:hover,
body.focus-mode .bar:hover,
body.focus-mode .nav:focus-within,
body.focus-mode .bar:focus-within {
  transform: none; opacity: 1;
}

body.focus-mode .work { padding-top: 0; }
body.focus-mode #page {
  max-width: 720px;
  box-shadow: 0 8px 30px rgba(0,0,0,.12);
  margin-top: 40px;
}
body.focus-mode .scroll { padding-top: 20px; }

/* Le bouton flottant pour quitter */
#exitFocus {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e1e2d;
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 10px 20px;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  display: none;
  z-index: 20;
  opacity: 0.6;
  transition: opacity 0.2s;
}
#exitFocus:hover {
  opacity: 1;
}
body.focus-mode #exitFocus {
  display: block;
}

@media print {
  .nav, .bar, .row, #lib, #drawer, #toc, #search, #stats, #toast, .menu { display: none !important; }
  body { background: #fff; }
  .scroll { padding: 0; }
  #page {
    box-shadow: none; border: 0; margin: 0; padding: 0;
    min-height: 0; max-width: 100%; background: #fff; color: #000;
  }
}

/* État actif pour les boutons de mode */
.bar .mn.active {
  background: #e6b800 !important;
  box-shadow: 0 0 0 3px rgba(241, 196, 15, 0.4);
  transform: scale(0.95);
}

.bar .mz.active {
  background: #01579b !important;
  color: #fff;
  box-shadow: 0 0 0 3px rgba(2, 136, 209, 0.4);
  transform: scale(0.95);
}

/* Empêcher la page de grandir de façon bizarre */

#loadProjectInput { display: none; }

/* Mode Lecture */
body.read-only #page {
  cursor: default;
  background-color: var(--bg); /* Légèrement différent du blanc pour montrer qu'on ne peut pas écrire */
}
body.read-only #bar button:not(#mode-toggle):not(#logout-btn):not(#themeBtn):not(#expBtn):not(#libBtn):not(#searchBtn):not(#tocBtn):not(#focusBtn):not(#saveProjectBtn):not(#loadProjectBtn) {
  opacity: 0.4;
  pointer-events: none;
}
body.read-only #bar select {
  opacity: 0.4;
  pointer-events: none;
}
body.read-only .text-mode-note, 
body.read-only .text-mode-zone {
  cursor: pointer; /* On peut quand même cliquer pour lire */
}

/* Panneau de partage */
#share-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px; z-index: 35;
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: -4px 0 15px rgba(0,0,0,.15);
  transform: translateX(100%); visibility: hidden;
  transition: transform .25s, visibility .25s;
}
#share-panel.open { transform: none; visibility: visible; }
.share-body { padding: 20px; flex: 1; overflow-y: auto; }
.share-link-row {
  display: flex; gap: 6px;
  background: var(--bg); padding: 8px; border-radius: 6px;
}
.share-link-row input {
  flex: 1; padding: 8px; border: 1px solid var(--line); border-radius: 4px;
  font-size: 0.85rem; background: white; color: #333;
}
.share-link-row button {
  background: var(--accent); color: #1e1e2d; border: none;
  padding: 8px 12px; border-radius: 4px; font-weight: bold; cursor: pointer;
  white-space: nowrap;
}
.share-list { margin-top: 10px; }
.share-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 0.9rem;
}
.share-item .email { flex: 1; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.share-item .role-badge { font-size: 0.75rem; padding: 2px 8px; border-radius: 10px; background: var(--bg); color: var(--muted); margin-right: 10px; }
.share-item button { background: none; border: none; color: #e74c3c; cursor: pointer; }
.share-add { display: flex; flex-direction: column; gap: 8px; }
.share-add input, .share-add select { padding: 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 0.9rem; }
.share-add button { padding: 9px; background: var(--accent); color: #1e1e2d; border: none; border-radius: 6px; font-weight: bold; cursor: pointer; }

/* Mode Lecture */
body.read-only #page {
  cursor: default;
  background-color: var(--bg);
}
body.read-only #bar button:not(#mode-toggle):not(#logout-btn):not(#themeBtn):not(#expBtn):not(#libBtn):not(#searchBtn):not(#tocBtn):not(#focusBtn):not(#saveProjectBtn):not(#loadProjectBtn):not(#shareBtn) {
  opacity: 0.4; pointer-events: none;
}
body.read-only #bar select { opacity: 0.4; pointer-events: none; }
body.read-only .text-mode-note, body.read-only .text-mode-zone { cursor: pointer; }

/* ================= DASHBOARD ================= */
.doc-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  display: flex;
  flex-direction: column;
  height: 180px;
}
.doc-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.1);
  border-color: var(--accent);
}
.doc-card .doc-icon {
  font-size: 2rem;
  margin-bottom: 12px;
}
.doc-card .doc-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.doc-card .doc-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: auto;
}
.doc-card .doc-role-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--muted);
  font-weight: 600;
}
.doc-card .doc-role-badge.owner { background: #f1c40f; color: #1e1e2d; }
.doc-card .doc-role-badge.editor { background: #2ecc71; color: white; }
.doc-card .doc-role-badge.reader { background: #95a5a6; color: white; }
.doc-card .doc-role-badge.reader_notes { background: #3498db; color: white; }

.doc-card .doc-menu {
  position: absolute;
  top: 8px;
  right: 8px;
  display: none;
  gap: 4px;
}
.doc-card:hover .doc-menu {
  display: flex;
}

/* Menu contextuel des cartes */
.doc-menu-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 4px;
  z-index: 2;
  display: none;
}
.doc-card:hover .doc-menu-btn {
  display: block;
}
.doc-menu-btn:hover {
  background: var(--btn);
  color: var(--text);
}

.doc-context-menu {
  position: absolute;
  top: 40px;
  right: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  overflow: hidden;
  z-index: 10;
  min-width: 150px;
}
.doc-context-menu button {
  display: block;
  width: 100%;
  padding: 8px 12px;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
}
.doc-context-menu button:hover {
  background: var(--btnh);
}
.doc-context-menu button.danger {
  color: #e74c3c;
}

/* ================= CHAT ================= */
#chat-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px; z-index: 30;
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: -4px 0 15px rgba(0,0,0,.15);
  transform: translateX(100%); visibility: hidden;
  transition: transform .25s, visibility .25s;
}
#chat-panel.open { transform: none; visibility: visible; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 90%;
}

.chat-message.mine {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-message-meta {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0 4px;
}

.chat-message-meta strong {
  color: var(--text);
}

.chat-message-bubble {
  background: var(--bg);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chat-message.mine .chat-message-bubble {
  background: var(--accent);
  color: #1e1e2d;
}

.chat-message.system {
  align-self: center;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

.chat-input-area {
  border-top: 1px solid var(--line);
  padding: 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
}

#chat-input:focus {
  border-color: var(--accent);
}

#chat-send {
  background: var(--accent);
  color: #1e1e2d;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  font-size: 0.9rem;
}

#chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 0.9rem;
  font-style: italic;
}

/* Bouton "Lien vers..." */
.bar .ml { background: #9b59b6; color: white; border: 0; font-weight: 700; }

/* Fenêtre modale générique */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-content {
  background: var(--panel);
  border-radius: 12px;
  width: 100%;
  max-width: 500px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-header h3 { font-size: 1.1rem; }
.modal-header button {
  background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--muted);
}
.modal-body { padding: 20px; }

/* Liste des éléments dans le picker */
.link-picker-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.link-picker-item:hover { background: var(--btnh); border-color: var(--accent); }
.link-picker-item .lp-icon { font-size: 1.2rem; }
.link-picker-item .lp-info { flex: 1; }
.link-picker-item .lp-title { font-weight: 600; color: var(--text); font-size: 0.9rem; }
.link-picker-item .lp-path { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

/* Lien vers zone (dans le texte) */
.text-link-zone {
  background: #f3e5f5;
  color: #8e44ad;
  border-bottom: 2px dotted #9b59b6;
  cursor: pointer;
  padding: 1px 3px;
  border-radius: 3px;
  font-weight: 600;
}
.text-link-zone:hover { background: #e1bee7; }

/* Lien vers note (dans le texte) */
.text-link-note {
  background: #e8f4f8;
  color: #2980b9;
  border-bottom: 2px dotted #3498db;
  cursor: pointer;
  padding: 1px 3px;
  border-radius: 3px;
  font-weight: 600;
}
.text-link-note:hover { background: #d1ecf1; }

.bar .ml.active {
  background: #6a1b9a !important;
  box-shadow: 0 0 0 3px rgba(155, 89, 182, 0.4);
  transform: scale(0.95);
}

.text-link-temp {
  background: #f3e5f5;
  color: #8e44ad;
  border-bottom: 2px dotted #9b59b6;
  padding: 1px 3px;
  border-radius: 3px;
  font-weight: 600;
}

#history-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px; z-index: 35;
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: -4px 0 15px rgba(0,0,0,.15);
  transform: translateX(100%); visibility: hidden;
  transition: transform .25s, visibility .25s;
}
#history-panel.open { transform: none; visibility: visible; }

/* ================= COMPTEUR D'OBJECTIF ================= */
#goal-widget {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: 820px;
  width: 100%;
  margin-top: 10px;
}

.goal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.goal-label {
  font-weight: 600;
}

.goal-edit-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
}

.goal-edit-btn:hover { background: var(--btnh); }

.goal-bar {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.goal-fill {
  height: 100%;
  background: linear-gradient(90deg, #2ecc71, #27ae60);
  width: 0%;
  transition: width 0.3s, background 0.3s;
}

.goal-fill.warning { background: linear-gradient(90deg, #f39c12, #e67e22); }
.goal-fill.over { background: linear-gradient(90deg, #e74c3c, #c0392b); }

.goal-stats {
  font-size: 0.8rem;
  color: var(--text);
  font-weight: 600;
}

.goal-stats.warning { color: #e67e22; }
.goal-stats.over { color: #e74c3c; }

.goal-hidden { display: none; }

/* ================= TÂCHES ================= */
#tasks-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 420px; max-width: 100vw; z-index: 30;
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: -4px 0 15px rgba(0,0,0,.15);
  transform: translateX(100%); visibility: hidden;
  transition: transform .25s, visibility .25s;
}
#tasks-panel.open { transform: none; visibility: visible; }

.tasks-toolbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.task-primary {
  background: var(--accent); color: #1e1e2d; border: 0; border-radius: 8px;
  padding: 8px 14px; font-weight: 700; cursor: pointer; font-size: .9rem;
}
.tasks-filter { margin-left: auto; display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tasks-filter button {
  background: var(--btn); color: var(--text); border: 0; padding: 7px 10px;
  cursor: pointer; font-size: .8rem;
}
.tasks-filter button.active { background: var(--accent); color: #1e1e2d; font-weight: 700; }

.task-form {
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.task-form[hidden] { display: none; }
.task-form label { font-size: .75rem; color: var(--muted); font-weight: 700; margin-top: 4px; }
.task-form input, .task-form textarea, .task-form select {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px;
  font-family: inherit; font-size: .9rem; background: var(--panel); color: var(--text); outline: none;
}
.task-form input:focus, .task-form textarea:focus, .task-form select:focus { border-color: var(--accent); }
.task-form textarea { resize: vertical; }
.task-form-actions { display: flex; gap: 8px; margin-top: 8px; }
.task-form-actions button:not(.task-primary) {
  background: var(--btn); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: .9rem;
}

.tasks-list { flex: 1; overflow-y: auto; padding: 10px 14px 20px; }
.task-col { margin-bottom: 16px; border-radius: 10px; padding: 4px; transition: background .15s; }
.task-col.drop { background: color-mix(in srgb, var(--accent) 18%, transparent); outline: 2px dashed var(--accent); }
.task-col-head {
  display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: .85rem;
  margin: 4px 2px 8px; color: var(--text);
}
.task-col-head .count {
  background: var(--btn); border: 1px solid var(--line); border-radius: 10px;
  padding: 0 7px; font-size: .75rem; color: var(--muted); font-weight: 600;
}
.task-empty { color: var(--muted); font-size: .8rem; font-style: italic; padding: 6px 4px; }

.task-card {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px; cursor: grab;
}
.task-card.dragging { opacity: .4; }
.task-card.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-title { font-weight: 700; font-size: .92rem; word-wrap: break-word; }
.task-desc { font-size: .82rem; color: var(--muted); margin-top: 4px; white-space: pre-wrap; word-wrap: break-word; }
.task-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.task-chip {
  font-size: .72rem; padding: 2px 8px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.task-chip.me { background: var(--accent); color: #1e1e2d; border-color: var(--accent); font-weight: 700; }
.task-chip.link { cursor: pointer; color: #026fae; }
.task-chip.link:hover { background: var(--btnh); }
.task-chip.missing { color: var(--muted); text-decoration: line-through; }
.task-actions { display: flex; gap: 4px; margin-top: 8px; justify-content: flex-end; }
.task-actions button {
  background: var(--btn); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 3px 8px; cursor: pointer; font-size: .8rem;
}
.task-actions button:hover:not(:disabled) { background: var(--btnh); }
.task-actions button:disabled { opacity: .35; cursor: default; }
@media print { #tasks-panel { display: none !important; } }

/* ================= BIBLES ================= */
.text-link-entry {
  background: #e8f5e9; color: #2e7d32; border-bottom: 2px dotted #43a047;
  cursor: pointer; padding: 1px 3px; border-radius: 3px; font-weight: 600;
}
.text-link-entry:hover { background: #c8e6c9; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .text-link-entry { background: #1f3a26; color: #81c784; }
  :root:not([data-theme="light"]) .text-link-entry:hover { background: #2a4d33; }
}
:root[data-theme="dark"] .text-link-entry { background: #1f3a26; color: #81c784; }
:root[data-theme="dark"] .text-link-entry:hover { background: #2a4d33; }

.bar .mb { background: #2e7d32; color: #fff; border: 0; font-weight: 700; }

#bible-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 460px; max-width: 100vw; z-index: 30;
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: -4px 0 15px rgba(0,0,0,.15);
  transform: translateX(100%); visibility: hidden;
  transition: transform .25s, visibility .25s;
}
#bible-panel.open { transform: none; visibility: visible; }
.bible-nav { display: flex; align-items: center; gap: 8px; padding: 10px 14px 6px; }
.bible-nav #bible-back {
  background: var(--btn); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; cursor: pointer; font-size: .85rem;
}
.bible-nav #bible-back[hidden] { display: none; }
.bible-search { padding: 4px 14px 10px; border-bottom: 1px solid var(--line); }
.bible-search input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  background: var(--bg); color: var(--text); font-size: .9rem; outline: none;
}
.bible-search input:focus { border-color: var(--accent); }
.bible-body { flex: 1; overflow-y: auto; padding: 12px 14px 24px; }
.bible-actions { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.bible-actions h4 { flex: 1; font-size: 1.05rem; word-break: break-word; }
.bible-actions button:not(.task-primary) {
  background: var(--btn); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: .85rem;
}
.bible-card {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; margin-bottom: 8px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.bible-card:hover { border-color: var(--accent); background: var(--btnh); }
.bible-card .bc-name { flex: 1; font-weight: 700; word-break: break-word; }
.bible-card .bc-count {
  font-size: .75rem; color: var(--muted); border: 1px solid var(--line);
  border-radius: 10px; padding: 0 8px; background: var(--panel);
}
.bible-empty { color: var(--muted); font-size: .9rem; font-style: italic; text-align: center; padding: 30px 14px; line-height: 1.5; }

.entry-card {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; margin-bottom: 12px;
}
.entry-name {
  width: 100%; border: 0; border-bottom: 1px solid transparent; background: transparent;
  color: var(--text); font-size: 1.05rem; font-weight: 700; padding: 2px 0; outline: none; font-family: inherit;
}
.entry-name:focus { border-bottom-color: var(--accent); }
.entry-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; align-items: center; }
.entry-chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; padding: 2px 8px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer;
}
.entry-chip:hover { border-color: var(--accent); }
.entry-chip .x { color: var(--muted); font-weight: 700; padding-left: 2px; }
.entry-chip .x:hover { color: #e74c3c; }
.entry-add {
  font-size: .75rem; border: 1px dashed var(--line); border-radius: 10px;
  background: transparent; color: var(--muted); padding: 2px 6px; cursor: pointer;
}
.entry-desc {
  width: 100%; min-height: 90px; resize: none; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; background: var(--panel); color: var(--text); font-family: inherit;
  font-size: .9rem; line-height: 1.5; outline: none;
}
.entry-desc:focus { border-color: var(--accent); }
.entry-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: .72rem; color: var(--muted); }
.entry-foot .sp { flex: 1; }
.entry-foot button {
  background: var(--btn); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 3px 8px; cursor: pointer; font-size: .8rem;
}
.entry-foot button:hover { background: var(--btnh); }

.bl-label { display: block; font-size: .75rem; color: var(--muted); font-weight: 700; margin: 10px 0 4px; }
.bl-input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  background: var(--bg); color: var(--text); font-size: .9rem; outline: none; font-family: inherit;
}
.bl-input:focus { border-color: var(--accent); }
#bl-list { margin-top: 8px; }
.bl-sep {
  margin: 16px 0 4px; padding-top: 12px; border-top: 1px solid var(--line);
  font-size: .8rem; color: var(--muted); text-align: center;
}
.bl-bibles { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 8px; }
.bl-bibles label { font-size: .85rem; display: flex; align-items: center; gap: 4px; cursor: pointer; }
@media print { #bible-panel, #bible-linker { display: none !important; } }

/* Mot lié dont la fiche n'a plus de bible : plus de démarcation */
.text-link-entry.entry-orphan {
  background: none !important; color: inherit !important; border-bottom: 0 !important;
  padding: 0 !important; font-weight: inherit !important; cursor: text !important;
}
.entry-desc-wrap { margin-top: 8px; }
.entry-desc-label { font-size: .8rem; font-weight: 700; color: var(--accent-blue, #026fae); margin-bottom: 4px; cursor: pointer; }
.entry-desc-label:hover { text-decoration: underline; }
.entry-hint { font-size: .8rem; color: var(--muted); font-style: italic; margin: 8px 0; line-height: 1.4; }

/* ================= VERROUILLAGE, ASSEMBLAGE, COMMENTAIRES ================= */
.lock-banner {
  width: 100%; max-width: 820px; box-sizing: border-box; margin-bottom: 10px;
  padding: 10px 16px; border-radius: 8px; font-size: .9rem;
  background: var(--panel); border: 1px solid var(--accent); color: var(--text);
}
.lock-banner[hidden] { display: none; }
.task-lock-row { display: flex; gap: 8px; align-items: flex-start; margin-top: 6px; font-size: .85rem; color: var(--text); }
.task-lock-row[hidden] { display: none; }
.task-lock-row input { width: auto; margin-top: 3px; }
.task-lock-row small { color: var(--muted); }
.task-chip.lock { background: var(--panel); border-color: var(--accent); }
.lib-lock { margin-left: 6px; font-size: .8rem; opacity: .8; }

#asm-panel, #cmt-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 400px; max-width: 100vw; z-index: 30;
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: -4px 0 15px rgba(0,0,0,.15);
  transform: translateX(100%); visibility: hidden;
  transition: transform .25s, visibility .25s;
}
#asm-panel.open, #cmt-panel.open { transform: none; visibility: visible; }
.asm-body { flex: 1; overflow-y: auto; padding: 14px; }
.asm-body h4 { margin: 16px 0 8px; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.asm-help { font-size: .82rem; color: var(--muted); line-height: 1.5; margin: 0 0 10px; }
.asm-mode { display: flex; gap: 6px; }
.asm-mode button { flex: 1; padding: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 6px; cursor: pointer; }
.asm-mode button.active { background: var(--accent); color: #1e1e2d; border-color: var(--accent); font-weight: 700; }
.asm-list { display: flex; flex-direction: column; gap: 6px; }
.asm-item { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.asm-item .asm-pos { font-size: .7rem; font-weight: 700; color: var(--muted); min-width: 22px; }
.asm-item .asm-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; color: var(--text); }
.asm-item .asm-who { font-size: .7rem; color: var(--muted); }
.asm-item button { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 6px; cursor: pointer; padding: 3px 7px; }
.asm-item button:disabled { opacity: .35; cursor: default; }
.asm-empty { font-size: .82rem; color: var(--muted); padding: 6px 2px; }

.asm-preview { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; background: var(--bg); }
.asm-preview[hidden] { display: none; }
.asm-preview-bar { display: flex; gap: 12px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); color: var(--text); }
.asm-preview-bar span { flex: 1; font-size: .8rem; color: var(--muted); }
.asm-preview-bar button:not(.task-primary) { padding: 8px 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 6px; cursor: pointer; }
.asm-preview-scroll { flex: 1; overflow-y: auto; padding: 24px 12px; display: flex; justify-content: center; }
.asm-sheet {
  width: 100%; max-width: 820px; box-sizing: border-box; height: max-content;
  padding: 56px 64px; background: var(--paper); color: var(--paper-text);
  border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,.08);
  font-size: 16px; line-height: 1.7; overflow-wrap: anywhere;
}
.asm-sheet * { font-family: inherit; }
.asm-sheet h1 { font-size: 2rem; margin: .8em 0 .4em; line-height: 1.25; }
.asm-sheet h2 { font-size: 1.5rem; margin: .8em 0 .4em; line-height: 1.3; }
.asm-sheet h3 { font-size: 1.2rem; margin: .8em 0 .3em; }
.asm-sheet p { margin: 0 0 .6em; }
.asm-sheet ul, .asm-sheet ol { margin: 0 0 .6em 1.6em; }
.asm-sheet blockquote { margin: .8em 0; padding: 4px 16px; border-left: 4px solid #c9ccd3; color: #888; font-style: italic; }
.asm-sheet figure.doc-img { margin: 1em 0; text-align: center; }
.asm-sheet figure.doc-img img { max-width: 100%; height: auto; }
.asm-section + .asm-section.structured { margin-top: 2.5em; padding-top: 1.5em; border-top: 2px solid #c9ccd3; }
.asm-section-head { margin-bottom: 1em; }
.asm-section-head .asm-section-title { font-size: 1.6rem; font-weight: 700; line-height: 1.25; }
.asm-section-head .asm-section-author { font-size: .85rem; color: #888; }

.cmt-compose { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.cmt-compose textarea { width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; resize: vertical; }
.cmt-quote { font-size: .82rem; padding: 6px 10px; border-left: 3px solid var(--accent); background: var(--bg); color: var(--text); font-style: italic; border-radius: 0 6px 6px 0; }
.cmt-quote[hidden] { display: none; }
.cmt-list { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.cmt-card { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--bg); color: var(--text); }
.cmt-card.resolved { opacity: .55; }
.cmt-card .cmt-q { font-size: .78rem; font-style: italic; border-left: 3px solid var(--accent); padding-left: 8px; margin-bottom: 6px; cursor: pointer; }
.cmt-card .cmt-meta { font-size: .72rem; color: var(--muted); margin-bottom: 4px; }
.cmt-card .cmt-text { font-size: .9rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.cmt-card .cmt-actions { margin-top: 8px; display: flex; gap: 6px; }
.cmt-card .cmt-actions button { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 6px; cursor: pointer; padding: 3px 8px; font-size: .78rem; }

@media print {
  #asm-panel, #cmt-panel, .lock-banner { display: none !important; }
  body.printing-assembly #app-screen > *:not(#asm-preview) { display: none !important; }
  body.printing-assembly #asm-preview { position: static; display: block; background: #fff; }
  body.printing-assembly .asm-preview-bar { display: none !important; }
  body.printing-assembly .asm-preview-scroll { display: block; overflow: visible; padding: 0; }
  body.printing-assembly .asm-sheet { max-width: 100%; padding: 0; border: 0; box-shadow: none; background: #fff; color: #000; }
  body.printing-assembly .asm-section.structured + .asm-section.structured { page-break-before: always; border-top: 0; margin-top: 0; padding-top: 0; }
}

/* Impression de l'assemblage : l'écran de l'éditeur est figé à 100vh, on le libère pour que le PDF fasse plusieurs pages */
@media print {
  html:has(body.printing-assembly), body.printing-assembly { height: auto !important; overflow: visible !important; }
  body.printing-assembly { display: block; }
  body.printing-assembly #app-screen { height: auto !important; overflow: visible !important; display: block !important; }
} 

/* ===================== Relations entre fiches ===================== */
.bible-nav { flex-wrap: wrap; }
#bv-map {
  background: var(--btn); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; cursor: pointer; font-size: .85rem;
}
#bv-map:hover { background: var(--btnh); border-color: var(--accent); }

.entry-head { display: flex; align-items: center; gap: 8px; }
.entry-head .entry-name { flex: 1; width: auto; min-width: 0; }
.rel-add {
  flex: none; width: 28px; height: 28px; border-radius: 50%; padding: 0;
  border: 1px solid var(--line); background: var(--btn); color: var(--text);
  font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.rel-add:hover { background: var(--accent); border-color: var(--accent); color: #1e1e2d; }

.entry-rels { margin: 4px 0 10px; padding-top: 8px; border-top: 1px dashed var(--line); }
.entry-rels-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: .75rem; color: var(--muted); font-weight: 700; margin-bottom: 4px;
}
.rel-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: .85rem; }
.rel-arrow { flex: none; width: 1.3em; text-align: center; color: var(--muted); }
.rel-who { font-weight: 700; cursor: pointer; word-break: break-word; }
.rel-who:hover { text-decoration: underline; }
.rel-label { flex: 1; color: var(--muted); font-style: italic; word-break: break-word; }
.rel-btn { background: none; border: 0; padding: 2px 5px; cursor: pointer; color: var(--muted); font-size: .8rem; }
.rel-btn:hover { color: var(--text); }

#rel-list { margin-top: 8px; max-height: 220px; overflow-y: auto; }
.link-picker-item.sel { border-color: var(--accent); background: var(--on); }
.rel-dir { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; }
.rel-dir label { display: flex; align-items: center; gap: 6px; font-size: .9rem; cursor: pointer; }
.rel-dir small { color: var(--muted); }
.rel-swap {
  margin-left: auto; background: var(--btn); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: .8rem;
}
.rel-swap[hidden] { display: none; }
#rel-preview {
  margin-top: 10px; padding: 8px 10px; border-radius: 8px; word-break: break-word;
  background: var(--bg); border: 1px solid var(--line); font-size: .9rem; font-weight: 600;
}

/* Carte */
.relmap { position: fixed; inset: 0; z-index: 90; display: flex; flex-direction: column; background: var(--bg); }
.relmap[hidden] { display: none; }
.relmap-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.relmap-bar h3 { margin-right: auto; font-size: 1.05rem; }
.relmap-bar select, .relmap-bar button {
  background: var(--btn); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; font-size: .85rem; cursor: pointer;
}
.relmap-bar button:hover { background: var(--btnh); }
.relmap-chk { display: flex; align-items: center; gap: 4px; font-size: .85rem; cursor: pointer; }
.relmap-stage { position: relative; flex: 1; min-height: 0; }
#relmap-svg { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; user-select: none; }
#relmap-svg:active { cursor: grabbing; }
.rm-edge { stroke: var(--muted); stroke-width: 1.8; }
.rm-hit { stroke: transparent; stroke-width: 16; cursor: pointer; }
.rm-link:hover .rm-edge { stroke: var(--accent-blue); stroke-width: 2.8; }
.rm-arrow-path { fill: var(--muted); }
.rm-elabel {
  font-size: 12px; font-style: italic; fill: var(--text); cursor: pointer;
  paint-order: stroke; stroke: var(--bg); stroke-width: 4px; stroke-linejoin: round;
}
.rm-node { cursor: pointer; }
.rm-node circle { stroke: var(--panel); stroke-width: 3; }
.rm-node.focus circle { stroke: var(--accent); stroke-width: 4; }
.rm-nlabel {
  font-size: 13px; font-weight: 700; fill: var(--text);
  paint-order: stroke; stroke: var(--bg); stroke-width: 4px; stroke-linejoin: round;
}
.rm-ini { font-size: 15px; font-weight: 700; fill: #fff; pointer-events: none; }
#relmap-svg.dim .rm-node:not(.on) { opacity: .25; }
#relmap-svg.dim .rm-link:not(.on) { opacity: .12; }
#relmap-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 24px; text-align: center; color: var(--muted); font-style: italic; pointer-events: none;
}
#relmap-empty[hidden] { display: none; }
#relmap-legend {
  position: absolute; left: 12px; bottom: 12px; display: flex; flex-wrap: wrap; gap: 6px 12px;
  max-width: calc(100% - 24px); padding: 6px 10px; font-size: .75rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
}
#relmap-legend:empty { display: none; }
#relmap-legend .rm-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }
.relmap-hint { position: absolute; right: 12px; bottom: 12px; max-width: 260px; font-size: .72rem; color: var(--muted); text-align: right; pointer-events: none; }
@media (max-width: 700px) { .relmap-hint { display: none; } }
@media print { .relmap, #relation-modal { display: none !important; } }

/* ---- Carte : focus, options, sélection, jumeaux, noms masqués ---- */
.relmap-bar select { max-width: 170px; }
.relmap-focusbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .85rem; }
.relmap-focusbar[hidden] { display: none; }
.relmap-focusbar b { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.relmap-focusbar #relmap-depth { color: var(--muted); }
.relmap-bar button:disabled { opacity: .4; cursor: default; }
.relmap-more { position: relative; }
.relmap-more summary {
  list-style: none; cursor: pointer; font-size: .85rem; padding: 6px 10px; border-radius: 8px;
  background: var(--btn); color: var(--text); border: 1px solid var(--line);
}
.relmap-more summary::-webkit-details-marker { display: none; }
.relmap-more-body {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 5; min-width: 270px;
  display: flex; flex-direction: column; gap: 10px; padding: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
.relmap-more-body button[hidden] { display: none; }

.relmap-sel {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 3;
  display: flex; align-items: center; flex-wrap: wrap; justify-content: center; gap: 8px;
  max-width: calc(100% - 24px); padding: 8px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 18px rgba(0, 0, 0, .3);
}
.relmap-sel[hidden] { display: none; }
.relmap-sel-info { display: flex; flex-direction: column; margin-right: 6px; min-width: 0; }
.relmap-sel-info b { word-break: break-word; }
.relmap-sel-info small { color: var(--muted); }
.relmap-sel button {
  background: var(--btn); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; font-size: .8rem; cursor: pointer;
}
.relmap-sel button:hover { background: var(--btnh); border-color: var(--accent); }

.rm-node.twin circle { stroke-dasharray: 5 3; fill-opacity: .6; }
.rm-node.sel circle { stroke: var(--accent); stroke-width: 4; }

/* Noms des relations masqués quand la carte est chargée et dézoomée */
#relmap-svg.lbl-off .rm-elabel { opacity: 0; pointer-events: none; }
#relmap-svg.lbl-off .rm-link:hover .rm-elabel,
#relmap-svg.lbl-off .rm-link.on .rm-elabel { opacity: 1; pointer-events: auto; }

/* ===================== Fichiers .storyforge, lecteur, ePub ===================== */
.sf-choice {
  display: flex; flex-direction: column; gap: 4px; width: 100%; text-align: left; margin-bottom: 10px;
  padding: 12px 14px; background: var(--btn); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; cursor: pointer; font-size: .95rem;
}
.sf-choice span { color: var(--muted); font-size: .85rem; line-height: 1.4; }
.sf-choice:hover { background: var(--btnh); border-color: var(--accent); }
.sf-hint { color: var(--muted); font-size: .8rem; margin: 8px 0 0; }

.sfv { position: fixed; inset: 0; z-index: 10000; display: flex; flex-direction: column; background: var(--bg); color: var(--text); }
.sfv[hidden] { display: none; }
.sfv-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.sfv-title { display: flex; flex-direction: column; margin-right: auto; min-width: 0; }
.sfv-title b { word-break: break-word; }
.sfv-title small { color: var(--muted); }
.sfv-bar button {
  background: var(--btn); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 12px; font-size: .85rem; cursor: pointer;
}
.sfv-bar button:hover { background: var(--btnh); }
.sfv-bar button[hidden] { display: none; }
#sfv-notes-btn { display: none; }
.sfv-body { flex: 1; min-height: 0; display: flex; position: relative; }
.sfv-scroll { flex: 1; overflow-y: auto; padding: 24px 16px; display: flex; justify-content: center; }
.sfv-page {
  width: 100%; max-width: 820px; align-self: flex-start; margin-bottom: 40px; padding: 48px 56px;
  background: var(--paper); color: var(--paper-text); border: 1px solid var(--line); border-radius: 6px;
  font-size: 16px; line-height: 1.7; overflow-wrap: anywhere; box-shadow: 0 4px 12px rgba(0, 0, 0, .08);
}
.sfv-page h1 { font-size: 2rem; margin: .8em 0 .4em; line-height: 1.25; }
.sfv-page h2 { font-size: 1.5rem; margin: .8em 0 .4em; line-height: 1.3; }
.sfv-page h3 { font-size: 1.2rem; margin: .8em 0 .3em; }
.sfv-page p { margin: 0 0 .6em; }
.sfv-page img { max-width: 100%; height: auto; }
.sfv-page .text-mode-note {
  background: #fff2ac; border-bottom: 2px solid var(--accent); color: #222; cursor: pointer;
  padding: 2px 4px; border-radius: 3px; font-weight: 600;
}
.sfv-page .text-mode-zone {
  background: #e1f5fe; border-bottom: 2px solid var(--accent-blue); color: var(--accent-blue); cursor: pointer;
  padding: 2px 4px; border-radius: 3px; font-weight: 700;
}
.sfv-page .text-mode-zone::after { content: " 🚪"; }
.sfv-page .sfv-dead { opacity: .55; cursor: default; }
.sfv-page.sfv-hl-off .text-mode-note { background: none; border-bottom: 0; padding: 0; font-weight: inherit; cursor: default; }
.sfv-flash { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.sfv-side { width: 320px; flex: none; overflow-y: auto; padding: 14px; background: var(--panel); border-left: 1px solid var(--line); }
.sfv-side h4 { font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
.sfv-note-item { padding: 10px 12px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; background: var(--bg); }
.sfv-note-item:hover { border-color: var(--accent); }
.sfv-note-q { font-size: .8rem; color: var(--muted); margin-bottom: 4px; word-break: break-word; }
.sfv-note-t { white-space: pre-wrap; word-break: break-word; font-size: .92rem; }
@media (max-width: 800px) {
  #sfv-notes-btn { display: inline-block; }
  .sfv-page { padding: 28px 20px; }
  .sfv-side { display: none; position: absolute; right: 0; top: 0; bottom: 0; width: 88%; max-width: 360px; z-index: 2; box-shadow: -8px 0 24px rgba(0, 0, 0, .35); }
  .sfv.sfv-notes-open .sfv-side { display: block; }
}
@media print {
  body.printing-sfv > *:not(#sfv) { display: none !important; }
  body.printing-sfv .sfv { position: static; display: block; background: #fff; }
  body.printing-sfv .sfv-bar, body.printing-sfv .sfv-side { display: none !important; }
  body.printing-sfv .sfv-scroll { overflow: visible; padding: 0; display: block; }
  body.printing-sfv .sfv-page { border: 0; box-shadow: none; padding: 0; max-width: none; }
  body.printing-sfv .sfv-page .text-mode-note, body.printing-sfv .sfv-page .text-mode-zone { background: none; border: 0; padding: 0; }
}

/* ================= CHAT : non-lus et réponses ================= */
#chatBtn { position: relative; }
.nb-badge {
  position: absolute; top: -5px; right: -5px;
  min-width: 17px; height: 17px; padding: 0 4px; box-sizing: border-box;
  border-radius: 9px; background: #e74c3c; color: #fff;
  font-size: .68rem; font-weight: bold; line-height: 17px; text-align: center;
}
.nb-badge[hidden] { display: none; }
.chat-reply-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: .85rem; padding: 0 4px; opacity: 0; transition: opacity .15s;
}
.chat-message:hover .chat-reply-btn, .chat-reply-btn:focus { opacity: 1; }
@media (hover: none) { .chat-reply-btn { opacity: 1; } }
.chat-quote {
  border-left: 3px solid var(--accent); background: var(--bg); color: var(--muted);
  font-size: .78rem; padding: 4px 8px; border-radius: 6px;
  max-width: 100%; box-sizing: border-box;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer;
}
.chat-quote strong { color: var(--text); }
.chat-message.flash .chat-message-bubble { outline: 2px solid var(--accent); }
#chat-reply {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  border-top: 1px solid var(--line); background: var(--bg);
  font-size: .8rem; color: var(--muted);
}
#chat-reply[hidden] { display: none; }
#chat-reply-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chat-reply button { background: none; border: none; color: var(--muted); cursor: pointer; }

/* ================= ACCESSIBILITÉ ================= */
/* Anneau de focus visible au clavier (sauf dans l'éditeur, où le curseur suffit) */
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible,
summary:focus-visible, [tabindex]:focus-visible:not([contenteditable]) {
  outline: 3px solid #026fae !important;
  outline-offset: 2px;
}
:root[data-theme="dark"] button:focus-visible, :root[data-theme="dark"] a:focus-visible,
:root[data-theme="dark"] input:focus-visible, :root[data-theme="dark"] select:focus-visible,
:root[data-theme="dark"] textarea:focus-visible, :root[data-theme="dark"] [tabindex]:focus-visible:not([contenteditable]) {
  outline-color: #7cc4f5 !important;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) button:focus-visible, :root:not([data-theme="light"]) a:focus-visible,
  :root:not([data-theme="light"]) input:focus-visible, :root:not([data-theme="light"]) select:focus-visible,
  :root:not([data-theme="light"]) textarea:focus-visible, :root:not([data-theme="light"]) [tabindex]:focus-visible:not([contenteditable]) {
    outline-color: #7cc4f5 !important;
  }
}
/* Respect du réglage « réduire les animations » du système */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important; scroll-behavior: auto !important;
  }
}

/* ================= FORMULES GUIDÉES (math.js) ================= */
.mx { display: inline-flex; align-items: center; gap: .15em; vertical-align: middle; margin: 0 .12em; white-space: nowrap; line-height: 1.2; }
.mx [data-slot] { display: inline-block; min-width: .6em; padding: 0 .1em; border-radius: 3px; text-align: center; }
.mx-glyph, .mx-arrow { user-select: none; }
.mx [data-slot]:empty, .mx [data-slot].mx-empty { outline: 1px dashed var(--muted); outline-offset: 1px; }
.mx [data-slot]:empty::after, .mx [data-slot].mx-empty::after { content: attr(data-ph); color: var(--muted); font-style: italic; font-size: .8em; opacity: .85; }
.mx [data-slot].mx-active { background: rgba(241, 196, 15, .25); outline: 1px solid var(--accent); outline-offset: 1px; }
.mx-body { text-align: left; }

/* intégrale : bornes empilées à droite du signe (haute en haut, basse en bas) */
.mx-int > .mx-glyph { font-size: 2.1em; font-weight: 200; line-height: 1; transform: scaleX(.9); }
.mx-int > .mx-lims { display: inline-flex; flex-direction: column-reverse; justify-content: space-between; align-self: stretch; font-size: .72em; margin-left: -.2em; }

/* somme, produit : bornes au-dessus et au-dessous du signe */
.mx-over { display: inline-flex; align-items: center; }
.mx-sum > .mx-over, .mx-prod > .mx-over { flex-direction: column-reverse; }
.mx-sum .mx-glyph, .mx-prod .mx-glyph { font-size: 1.7em; line-height: 1; }
.mx-sum .mx-lo, .mx-sum .mx-hi, .mx-prod .mx-lo, .mx-prod .mx-hi { font-size: .7em; line-height: 1.1; }

/* limite : la variable, la flèche et la valeur visée sous « lim » */
.mx-lim > .mx-over { flex-direction: column; }
.mx-under { display: inline-flex; align-items: baseline; gap: .15em; font-size: .72em; }

/* racines : indice relevé et barre au-dessus du contenu */
.mx-nroot, .mx-sqrt { align-items: flex-end; }
.mx-index { font-size: .62em; align-self: flex-start; margin-right: -.2em; margin-bottom: .1em; }
.mx-nroot > .mx-glyph, .mx-sqrt > .mx-glyph { font-size: 1.25em; line-height: 1; margin-right: -.12em; }
.mx-rad { border-top: .09em solid currentColor; padding: .08em .25em 0 .2em; text-align: left; }
