/* ═══════════════════════════════════════════════
   GRIMOIRE KIT — Documentation surface
   Live-rendered markdown from github/Grimoire-kit
   Hérite des tokens forge-tokens.css. Aucune couleur
   hors tokens.
   ═══════════════════════════════════════════════ */

#documentation { padding: 120px 0; }
#documentation > .container { position: relative; z-index: 1; }

/* ── Shell (frame cockpit) ── */
.docs-shell {
  --docs-h: 660px;
  margin-top: 52px;
  background: var(--elev-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  position: relative;
}
.docs-shell::before {
  content: ''; position: absolute; inset: 0; z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64'%3E%3Cpath d='M64,0 L0,0 0,64' fill='none' stroke='%23FF6B3D' stroke-width='0.5' opacity='0.05'/%3E%3C/svg%3E");
  pointer-events: none;
}

/* ── Title bar ── */
.docs-bar {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 14px;
  background: var(--elev-2);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 2;
}
.docs-bar .cockpit-label { flex: 0 0 auto; }
.docs-bar .docs-source {
  margin-left: auto;
  font-family: var(--font-mono); font-size: 0.6rem;
  color: var(--ink-muted); letter-spacing: 0.04em;
  text-decoration: none; display: flex; align-items: center; gap: 6px;
  transition: color 200ms;
}
.docs-bar .docs-source:hover { color: var(--accent); }
.docs-bar .docs-source .sync {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--data-green); box-shadow: 0 0 5px var(--data-green);
}

/* ── Focus-mode doc picker (hidden unless layout=focus) ── */
.docs-focus-pick { display: none; }
.docs-focus-pick select {
  background: var(--elev-2); border: 1px solid var(--line); color: var(--ink);
  font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.04em;
  padding: 5px 10px; border-radius: var(--r-sm); outline: none; max-width: 260px;
}

/* ── Body grid ── */
.docs-body {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr) 196px;
  height: var(--docs-h);
  position: relative; z-index: 1;
}

/* ── Sidebar nav ── */
.docs-nav {
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0; background: var(--elev-1);
}
.docs-search {
  padding: 14px 14px 10px; border-bottom: 1px solid var(--line);
  position: relative; flex: 0 0 auto;
}
.docs-search input {
  width: 100%;
  background: var(--elev-2); border: 1px solid var(--line);
  border-radius: var(--r-sm); color: var(--ink);
  font-family: var(--font-mono); font-size: 0.68rem;
  padding: 7px 10px 7px 28px; outline: none;
  transition: border-color 200ms;
}
.docs-search input:focus { border-color: var(--accent); }
.docs-search input::placeholder { color: var(--ink-muted); }
.docs-search .ico {
  position: absolute; left: 23px; top: 50%; transform: translateY(-50%);
  width: 12px; height: 12px; color: var(--ink-muted); pointer-events: none;
}

.docs-tree {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 10px 8px 18px;
}
.docs-group { margin-bottom: 6px; }
.docs-group-label {
  font-family: var(--font-mono); font-size: 0.56rem;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-muted); padding: 12px 10px 6px;
}
.docs-link {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  font-family: var(--font-mono); font-size: 0.7rem;
  color: var(--ink-soft); background: none; border: none;
  padding: 6px 10px; border-radius: var(--r-sm);
  cursor: pointer; letter-spacing: 0.01em; line-height: 1.35;
  border-left: 2px solid transparent; margin-left: -2px;
  transition: background 160ms, color 160ms, border-color 160ms;
}
.docs-link:hover { background: var(--elev-2); color: var(--ink); }
.docs-link.active {
  color: var(--accent); background: var(--accent-soft);
  border-left-color: var(--accent);
}
.docs-link .bullet {
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--ink-muted); flex: 0 0 auto;
  transition: background 160ms;
}
.docs-link:hover .bullet { background: var(--ink-soft); }
.docs-link.active .bullet { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.docs-empty {
  font-family: var(--font-mono); font-size: 0.64rem; color: var(--ink-muted);
  padding: 18px 12px; text-align: center;
}

/* ── Main reading pane ── */
.docs-main {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -8%, rgba(255,107,61,0.04), transparent 70%),
    var(--bg);
}
.docs-crumb {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 32px; border-bottom: 1px solid var(--line);
  font-family: var(--font-mono); font-size: 0.62rem; color: var(--ink-muted);
  letter-spacing: 0.04em;
}
.docs-crumb .cr {
  background: none; border: none; padding: 0; cursor: default;
  font: inherit; color: var(--ink-muted); letter-spacing: inherit;
}
.docs-crumb button.cr { cursor: pointer; transition: color 160ms; }
.docs-crumb button.cr:hover { color: var(--ink-soft); }
.docs-crumb .cr.now { color: var(--accent); }
.docs-crumb .sep { color: var(--line-strong); }

.docs-article {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 30px 40px 60px;
  position: relative;
  scroll-behavior: smooth;
}
.docs-article.is-wide { max-width: 860px; margin: 0 auto; width: 100%; }

/* ── Loading / error states ── */
.docs-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; height: 100%;
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-muted);
}
.docs-state .spin {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: docs-spin 700ms linear infinite;
}
@keyframes docs-spin { to { transform: rotate(360deg); } }
.docs-state .retry {
  margin-top: 4px; font-family: var(--font-mono); font-size: 0.66rem;
  color: var(--accent); background: none; border: 1px solid var(--accent-dim);
  padding: 6px 14px; border-radius: var(--r-sm); cursor: pointer;
  transition: background 160ms;
}
.docs-state .retry:hover { background: var(--accent-soft); }

/* ── TOC rail ── */
.docs-toc {
  border-left: 1px solid var(--line);
  padding: 18px 16px; overflow-y: auto; min-height: 0;
  background: var(--elev-1);
}
.docs-toc-label {
  font-family: var(--font-mono); font-size: 0.56rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-muted); margin-bottom: 12px;
}
.docs-toc nav { display: flex; flex-direction: column; gap: 1px; }
.docs-toc a {
  font-family: var(--font-mono); font-size: 0.64rem; line-height: 1.45;
  color: var(--ink-muted); text-decoration: none;
  padding: 4px 8px; border-left: 2px solid transparent;
  transition: color 160ms, border-color 160ms;
}
.docs-toc a.lvl-3 { padding-left: 18px; font-size: 0.6rem; }
.docs-toc a:hover { color: var(--ink-soft); }
.docs-toc a.active { color: var(--accent); border-left-color: var(--accent); }
.docs-toc .toc-empty { font-family: var(--font-mono); font-size: 0.6rem; color: var(--ink-muted); }

/* ════════════════════════════════════════════
   Markdown body — typeset in Forge DA
   ════════════════════════════════════════════ */
.md-body { color: var(--ink-soft); font-size: 0.9rem; line-height: 1.75; }
.md-body > *:first-child { margin-top: 0 !important; }

.md-body h1, .md-body h2, .md-body h3, .md-body h4, .md-body h5 {
  font-family: var(--font-sans); color: var(--ink);
  letter-spacing: -0.02em; line-height: 1.25; scroll-margin-top: 20px;
}
.md-body h1 { font-size: 1.9rem; font-weight: 700; margin: 0 0 8px; }
.md-body h1 + p { color: var(--ink-soft); }
.md-body h2 {
  font-size: 1.3rem; font-weight: 700; margin: 40px 0 14px;
  padding-top: 18px; border-top: 1px solid var(--line);
}
.md-body h3 { font-size: 1.04rem; font-weight: 600; margin: 28px 0 10px; }
.md-body h4 {
  font-size: 0.78rem; font-weight: 600; margin: 22px 0 8px;
  font-family: var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-soft);
}
/* Anchor markers on hover */
.md-body h2, .md-body h3 { position: relative; }
.md-body h2 .anchor, .md-body h3 .anchor {
  position: absolute; left: -20px; top: auto; bottom: 0;
  color: var(--accent); opacity: 0; text-decoration: none;
  font-weight: 400; transition: opacity 160ms;
}
.md-body h2:hover .anchor, .md-body h3:hover .anchor { opacity: 0.7; }

.md-body p { margin: 0 0 16px; }
.md-body a {
  color: var(--accent); text-decoration: none;
  border-bottom: 1px solid var(--accent-dim); transition: border-color 160ms;
}
.md-body a:hover { border-bottom-color: var(--accent); }

.md-body ul, .md-body ol { margin: 0 0 16px; padding-left: 22px; }
.md-body li { margin: 4px 0; }
.md-body li::marker { color: var(--accent); }
.md-body ul ul, .md-body ol ol, .md-body ul ol, .md-body ol ul { margin: 4px 0; }

.md-body strong { color: var(--ink); font-weight: 600; }
.md-body em { color: var(--ink-soft); }

.md-body hr { border: none; border-top: 1px solid var(--line); margin: 28px 0; }

.md-body blockquote {
  border-left: 2px solid var(--accent); margin: 0 0 16px;
  padding: 4px 0 4px 18px; color: var(--ink-soft); font-style: italic;
  background: linear-gradient(90deg, var(--accent-soft), transparent 60%);
}
.md-body blockquote p:last-child { margin-bottom: 0; }

/* Inline code */
.md-body :not(pre) > code {
  font-family: var(--font-mono); font-size: 0.82em;
  background: var(--elev-2); border: 1px solid var(--line);
  color: var(--accent); padding: 1px 6px; border-radius: 3px;
  word-break: break-word;
}

/* Code blocks */
.md-body pre {
  position: relative; margin: 0 0 18px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--r-sm); overflow: hidden;
}
.md-body pre code {
  display: block; font-family: var(--font-mono); font-size: 0.76rem;
  line-height: 1.65; color: var(--ink-soft);
  padding: 30px 16px 16px; overflow-x: auto; white-space: pre;
  background: transparent;
}
.md-pre-lang {
  position: absolute; top: 9px; left: 14px;
  font-family: var(--font-mono); font-size: 0.54rem; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-muted); pointer-events: none;
}
.md-copy {
  position: absolute; top: 8px; right: 8px;
  font-family: var(--font-mono); font-size: 0.56rem; letter-spacing: 0.08em;
  color: var(--ink-muted); background: var(--elev-2);
  border: 1px solid var(--line); border-radius: 3px;
  padding: 4px 9px; cursor: pointer; opacity: 0;
  transition: opacity 160ms, color 160ms, border-color 160ms;
}
.md-body pre:hover .md-copy { opacity: 1; }
.md-copy:hover { color: var(--ink); border-color: var(--line-strong); }
.md-copy.done { color: var(--data-green); border-color: rgba(52,211,153,0.4); opacity: 1; }

/* Tables */
.md-body table {
  width: 100%; border-collapse: collapse; margin: 0 0 18px;
  font-size: 0.8rem; display: block; overflow-x: auto;
}
.md-body th, .md-body td {
  border: 1px solid var(--line); padding: 8px 12px; text-align: left;
}
.md-body th {
  font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--ink-muted);
  background: var(--elev-1); font-weight: 500;
}
.md-body tr:nth-child(even) td { background: rgba(255,255,255,0.012); }

.md-body img {
  max-width: 100%; height: auto; border-radius: var(--r-sm);
  border: 1px solid var(--line); margin: 6px 0 18px; display: block;
}

/* ── Mermaid diagrams + viewer (zoom / pan / plein écran) ── */
.md-body .mermaid-diagram {
  background: var(--elev-1); border: 1px solid var(--line);
  border-radius: var(--r-sm); margin: 0 0 18px;
  padding: 0; position: relative; overflow: hidden;
  font-family: var(--font-mono);
}
.md-body .mermaid-diagram > svg { display: block; max-width: 100%; height: auto; margin: 18px auto; }

.mmd-stage {
  position: relative; overflow: hidden;
  height: clamp(220px, 46vh, 460px);
  cursor: grab; touch-action: none;
}
.mmd-stage.grabbing { cursor: grabbing; }
.mmd-pan { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.mmd-pan svg { display: block; max-width: none; }

.mmd-toolbar {
  position: absolute; top: 10px; right: 10px; z-index: 3;
  display: flex; gap: 4px; opacity: 0; transition: opacity 160ms;
}
.mermaid-diagram:hover .mmd-toolbar { opacity: 1; }
.mmd-btn {
  width: 26px; height: 26px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--elev-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  color: var(--ink-soft); cursor: pointer; padding: 0; transition: all 160ms;
}
.mmd-btn:hover { color: var(--accent); border-color: var(--accent-dim); background: var(--elev-3); }
.mmd-btn svg { width: 13px; height: 13px; }
.mmd-hint {
  position: absolute; bottom: 8px; left: 12px; z-index: 3;
  font-family: var(--font-mono); font-size: 0.52rem; letter-spacing: 0.05em;
  color: var(--ink-muted); opacity: 0; transition: opacity 160ms; pointer-events: none;
}
.mermaid-diagram:hover .mmd-hint { opacity: 0.75; }

/* Fullscreen overlay */
.mmd-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(8,9,11,0.93); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  display: flex; flex-direction: column;
  animation: mmd-fade 160ms var(--ease-out, ease);
}
@keyframes mmd-fade { from { opacity: 0; } to { opacity: 1; } }
.mmd-overlay-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
  font-family: var(--font-mono); font-size: 0.62rem; color: var(--ink-muted); letter-spacing: 0.08em;
}
.mmd-overlay-bar .sp { flex: 1; }
.mmd-overlay-stage { flex: 1; position: relative; overflow: hidden; cursor: grab; touch-action: none; }
.mmd-overlay-stage.grabbing { cursor: grabbing; }
.mmd-zoomlabel { font-family: var(--font-mono); font-size: 0.62rem; color: var(--ink-soft); min-width: 46px; text-align: center; }
.mmd-close {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 0.6rem; color: var(--ink-soft);
  background: var(--elev-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 5px 11px; cursor: pointer; letter-spacing: 0.08em; transition: all 160ms;
}
.mmd-close:hover { color: var(--accent); border-color: var(--accent-dim); }
.mmd-close svg { width: 11px; height: 11px; }

/* ── highlight.js → tokens Forge ── */
.md-body .hljs { color: var(--ink-soft); background: transparent; }
.md-body .hljs-comment, .md-body .hljs-quote { color: var(--ink-muted); font-style: italic; }
.md-body .hljs-keyword, .md-body .hljs-selector-tag, .md-body .hljs-built_in,
.md-body .hljs-name, .md-body .hljs-tag { color: var(--accent); }
.md-body .hljs-string, .md-body .hljs-attr, .md-body .hljs-meta .hljs-string,
.md-body .hljs-addition, .md-body .hljs-regexp { color: var(--data-green); }
.md-body .hljs-number, .md-body .hljs-literal, .md-body .hljs-bullet { color: var(--data-amber); }
.md-body .hljs-title, .md-body .hljs-section, .md-body .hljs-selector-id,
.md-body .hljs-function .hljs-title, .md-body .hljs-symbol, .md-body .hljs-link { color: var(--data-cyan); }
.md-body .hljs-type, .md-body .hljs-class .hljs-title, .md-body .hljs-selector-class,
.md-body .hljs-params, .md-body .hljs-template-variable { color: var(--data-violet); }
.md-body .hljs-variable, .md-body .hljs-attribute, .md-body .hljs-meta { color: var(--ink); }
.md-body .hljs-deletion { color: var(--data-red); }
.md-body .hljs-emphasis { font-style: italic; }
.md-body .hljs-strong { font-weight: 600; }

/* ════════════════════════════════════════════
   Layout variants (Tweak: Disposition doc)
   ════════════════════════════════════════════ */
/* cockpit (default) = 3 colonnes, déjà défini */

/* large = nav + article, pas de TOC, lecture élargie */
.docs-shell[data-doc-layout="large"] .docs-body { grid-template-columns: 236px minmax(0, 1fr); }
.docs-shell[data-doc-layout="large"] .docs-toc { display: none; }

/* focus = colonne de lecture centrée, nav via menu déroulant */
.docs-shell[data-doc-layout="focus"] .docs-body { grid-template-columns: minmax(0, 1fr); }
.docs-shell[data-doc-layout="focus"] .docs-nav,
.docs-shell[data-doc-layout="focus"] .docs-toc { display: none; }
.docs-shell[data-doc-layout="focus"] .docs-focus-pick {
  display: flex; align-items: center; gap: 8px; margin-left: 16px;
}
.docs-shell[data-doc-layout="focus"] .docs-article { max-width: 760px; margin: 0 auto; width: 100%; }

/* ── Responsive ── */
@media (max-width: 1040px) {
  .docs-body { grid-template-columns: 220px minmax(0, 1fr); }
  .docs-shell .docs-toc { display: none; }
}
@media (max-width: 720px) {
  .docs-shell { --docs-h: 560px; }
  .docs-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .docs-nav {
    border-right: none; border-bottom: 1px solid var(--line);
    max-height: 168px;
  }
  .docs-tree { display: flex; flex-wrap: wrap; gap: 2px; }
  .docs-group { margin-bottom: 0; }
  .docs-article { padding: 22px 22px 48px; }
  .docs-crumb { padding: 10px 22px; }
}

/* ════════════════════════════════════════════
   FULL-PAGE MODE — page dédiée, bord à bord
   La surface remplit le viewport sous la nav ;
   chaque colonne défile indépendamment.
   ════════════════════════════════════════════ */
.docs-shell.is-fullpage {
  margin: 0; border: none; border-radius: 0;
  height: 100%; display: flex; flex-direction: column;
  background: var(--bg);
}
.docs-shell.is-fullpage .docs-bar {
  flex: 0 0 auto; padding: 11px 24px;
  background: var(--elev-1);
}
.docs-shell.is-fullpage .docs-body {
  flex: 1 1 auto; height: auto; min-height: 0;
  grid-template-columns: 288px minmax(0, 1fr) 244px;
}
.docs-shell.is-fullpage .docs-nav { background: var(--elev-1); }
.docs-shell.is-fullpage .docs-article { padding: 40px 48px 90px; }
.docs-shell.is-fullpage[data-doc-layout="cockpit"] .docs-article,
.docs-shell.is-fullpage[data-doc-layout="large"] .docs-article {
  max-width: 824px; margin: 0 auto; width: 100%;
}
.docs-shell.is-fullpage[data-doc-layout="focus"] .docs-article { max-width: 820px; }
.docs-shell.is-fullpage .docs-crumb { padding: 15px 48px; }

/* Sidebar identity header (remplace le hero) */
.docs-nav-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 2px; flex: 0 0 auto;
}
.docs-nav-title {
  font-family: var(--font-mono); font-size: 0.6rem;
  letter-spacing: 0.18em; color: var(--ink-soft);
}
.docs-nav-sync {
  display: flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: 0.52rem; letter-spacing: 0.1em;
  color: var(--data-green);
}
.docs-nav-sync .sync {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--data-green); box-shadow: 0 0 5px var(--data-green);
}

@media (max-width: 1180px) {
  .docs-shell.is-fullpage .docs-body { grid-template-columns: 264px minmax(0, 1fr); }
  .docs-shell.is-fullpage .docs-toc { display: none; }
  .docs-shell.is-fullpage .docs-article { padding: 34px 36px 80px; }
}
@media (max-width: 760px) {
  .docs-shell.is-fullpage .docs-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .docs-shell.is-fullpage .docs-nav { border-right: none; border-bottom: 1px solid var(--line); max-height: 200px; }
  .docs-shell.is-fullpage .docs-article { padding: 24px 22px 70px; }
  .docs-shell.is-fullpage .docs-crumb { padding: 12px 22px; }
}
