:root {
  --app-bg: #0d1117;
  --panel-bg: #161b22;
  --panel-border: #30363d;
  --editor-bg: #0d1117;
  --header-bg: #161b22;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --btn-primary-bg: #238636;
  --btn-primary-hover: #2ea043;
  --btn-secondary-bg: #21262d;
  --btn-secondary-hover: #30363d;
  --input-bg: #0d1117;
  --input-border: #30363d;
  --radius: 6px;
  --font-ui: system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-ui);
  background: var(--app-bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── HEADER ── */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 52px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
}
.app-logo { display: flex; align-items: center; gap: 8px; font-size: 1.1rem; }
.logo-icon { font-size: 1.3rem; }
.logo-text strong { color: var(--accent); }
.header-actions { display: flex; gap: 8px; }

/* ── LAYOUT ── */
.app-layout { display: flex; flex: 1; overflow: hidden; }

/* ── OPTIONS PANEL ── */
.options-panel {
  width: 280px;
  min-width: 280px;
  background: var(--panel-bg);
  border-right: none;
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease, min-width 0.2s ease;
  overflow: hidden;
  /* Crucial : contraint la hauteur au parent */
  min-height: 0;
  max-height: 100%;
}
.options-panel.collapsed {
  width: 25px;
  min-width: 25px;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
  /* Assure que le scroll fonctionne en contraignant la hauteur */
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--panel-border) transparent;
}
.options-panel.collapsed .panel-body { display: none; }


.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0px 8px 0px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
  /* Pas d'overflow:hidden ici — le bouton doit rester visible */
  min-height: 41px;
}

.panel-header-label {
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.15s ease, width 0.2s ease;
  flex: 1;
}
.options-panel.collapsed .panel-header-label {
  opacity: 0;
  width: 0;
  pointer-events: none;
}

.panel-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s, transform 0.2s;
  flex-shrink: 0;
  /*width: 26px;*/
  text-align: center;
  /* Toujours accessible, même replié */
  position: relative;
  z-index: 1;
}
.panel-toggle:hover { color: var(--text); }
.options-panel.collapsed .panel-toggle {
  transform: rotate(180deg);
}


.opt-section {
  background: #0d1117;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  margin-bottom: 8px; overflow: hidden;
}
.opt-section h3 {
  font-size: 0.75rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 8px 12px; border-bottom: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.02);
}
.opt-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 7px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  flex-wrap: wrap;
}
.opt-row:last-child { border-bottom: none; }
.opt-row.full { flex-direction: column; align-items: flex-start; }
.opt-row label { font-size: 0.78rem; color: var(--text-muted); flex-shrink: 0; }
.opt-row input[type="color"] {
  width: 36px; height: 24px; border: 1px solid var(--input-border);
  border-radius: 4px; padding: 2px; background: var(--input-bg); cursor: pointer;
}
.opt-row select,
.opt-row input[type="text"] {
  background: var(--input-bg); border: 1px solid var(--input-border);
  color: var(--text); border-radius: 4px; padding: 4px 6px;
  font-size: 0.78rem; max-width: 130px;
}
.opt-row input[type="range"] { flex: 1; accent-color: var(--accent); max-width: 80px; }
.opt-row span { font-size: 0.72rem; color: var(--text-muted); min-width: 32px; text-align: right; }
.opt-row input[type="checkbox"] {
  appearance: auto; accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer;
}
.opt-row input[type="file"] { font-size: 0.72rem; color: var(--text-muted); width: 100%; }
.opt-row small { font-size: 0.72rem; color: var(--accent); width: 100%; }
.panel-footer { padding: 10px; border-top: 1px solid var(--panel-border); }

/* ── EDITOR AREA ── */
.editor-area { flex: 1; display: flex; overflow: hidden; }
.editor-pane, .preview-pane { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.divider {
  width: 5px; background: var(--panel-border);
  cursor: col-resize; transition: background 0.15s; flex-shrink: 0;
}
.divider:hover, .divider.dragging { background: var(--accent); }

.pane-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; font-size: 0.8rem; color: var(--text-muted);
  background: var(--panel-bg); border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
}
.pane-actions { display: flex; gap: 4px; }

#markdown {
  flex: 1; background: var(--editor-bg); color: var(--text);
  border: none; padding: 20px;
  font-family: 'Fira Code', 'JetBrains Mono', monospace;
  font-size: 0.9rem; line-height: 1.7; resize: none; outline: none; tab-size: 2;
}
.pane-footer {
  padding: 5px 14px; background: var(--panel-bg);
  border-top: 1px solid var(--panel-border);
  font-size: 0.72rem; color: var(--text-muted);
}

#preview-container {
  flex: 1; overflow-y: auto; background: #fff;
  scrollbar-width: thin; position: relative;
}
#output {
  padding: var(--preview-padding, 40px);
  max-width: var(--preview-max-width, 800px);
  margin: 0 auto;
  font-family: var(--preview-font-body, system-ui, sans-serif);
  font-size: var(--preview-font-size, 16px);
  line-height: var(--preview-line-height, 1.7);
  color: var(--preview-text-color, #1a1a1a);
  background: var(--preview-bg-color, #ffffff);
  min-height: 100%;
}

#html-source { flex: 1; overflow-y: auto; background: #1e1e1e; padding: 20px; display: flex; }
#html-source pre {
  color: #d4d4d4; font-family: monospace; font-size: 0.82rem;
  white-space: pre-wrap; word-break: break-all; flex: 1;
}
.hidden { display: none !important; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius);
  border: 1px solid transparent; font-size: 0.82rem;
  font-weight: 500; cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.btn-primary { background: var(--btn-primary-bg); color: #fff; }
.btn-primary:hover { background: var(--btn-primary-hover); }
.btn-secondary { background: var(--btn-secondary-bg); color: var(--text); border-color: var(--panel-border); }
.btn-secondary:hover { background: var(--btn-secondary-hover); }
.btn-ghost {
  background: transparent; color: var(--text-muted);
  border-color: var(--panel-border); font-size: 0.78rem;
  padding: 5px 10px; width: 100%; justify-content: center;
}
.btn-ghost:hover { color: var(--text); background: var(--btn-secondary-bg); }
.btn-sm {
  background: transparent; border: 1px solid var(--panel-border);
  color: var(--text-muted); border-radius: 4px;
  padding: 3px 8px; cursor: pointer; font-size: 0.78rem; transition: all 0.15s;
}
.btn-sm:hover { color: var(--text); border-color: var(--text-muted); }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: #238636; color: #fff; padding: 10px 18px;
  border-radius: var(--radius); font-size: 0.85rem; z-index: 9999;
  animation: fadeIn 0.2s ease;
}
.toast.error { background: #da3633; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

/* ══════════════════════════════════════
   PREVIEW STYLES
══════════════════════════════════════ */
#output h1, #output h2, #output h3,
#output h4, #output h5, #output h6 {
  font-family: var(--preview-font-heading, inherit);
  color: var(--preview-heading-color, #111);
  margin: 1.4em 0 0.5em; line-height: 1.3;
}
#output h1 {
  font-size: 2em; padding-bottom: 0.3em;
  border-bottom: var(--preview-h1-border-width, 1px) solid var(--preview-h1-border-color, #e0e0e0);
}
#output h2 { font-size: 1.5em; }
#output h3 { font-size: 1.25em; }
#output p { margin: 0.0em 0; }
#output a {
  color: var(--preview-link-color, #0969da);
  text-decoration: var(--preview-link-underline, underline);
}
#output a:hover { text-decoration: underline; }

/* ── Code inline ── */
#output code {
  font-family: var(--preview-font-mono, 'Fira Code', monospace);
  background: var(--preview-code-inline-bg, #eaeef2);
  color: var(--preview-code-color, #1f2328);
  padding: 2px 6px; border-radius: 4px; font-size: 0.88em;
}

/* ── Blocs de code ── */
#output pre {
  background: var(--preview-code-bg, #f6f8fa);
  border: 1px solid var(--preview-code-border, #d0d7de);
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 1em 0;
  padding: 0; /* géré par code ou .code-line */
}
#output pre code {
  background: none;
  border: none;
  padding: 16px;
  display: block;
  font-size: 0.9em;
  color: var(--preview-code-color, #1f2328);
  font-family: var(--preview-font-mono, 'Fira Code', monospace);
  line-height: 1.6;
  white-space: pre;
}

/* ── Numéros de lignes ── */
#output pre.line-numbers code {
  padding: 0;
  counter-reset: line-number;
}
#output pre.line-numbers code .code-line {
  display: block;
  counter-increment: line-number;
  padding: 0 16px 0 0;
  line-height: 1.6;
  white-space: pre;
}
#output pre.line-numbers code .code-line::before {
  content: counter(line-number);
  display: inline-block;
  width: 2.4em;
  margin-right: 1.2em;
  text-align: right;
  color: var(--preview-code-color, #1f2328);
  opacity: 0.35;
  border-right: 1px solid var(--preview-code-border, #d0d7de);
  padding-right: 0.8em;
  user-select: none;
  font-size: 0.85em;
}

/* ── Blockquote ── */
#output blockquote {
  border-left: 4px solid var(--preview-quote-border, #0969da);
  background: var(--preview-quote-bg, #f6f8fa);
  padding: 12px 16px 12px 20px; margin: 1em 0;
  border-radius: 0 4px 4px 0; color: #555; position: relative;
}
#output blockquote::before {
  content: '\201C';
  font-size: 2.5em; font-family: Georgia;
  color: var(--preview-quote-border, #0969da);
  opacity: 0.3; position: absolute; top: -6px; left: 10px;
}
#output blockquote.no-marks::before { display: none; }

/* ── Tables ── */
#output table { width: 100%; border-collapse: collapse; margin: 1em 0; }
#output th, #output td {
  border: 1px solid var(--preview-table-border, #d0d7de);
  padding: 8px 12px; text-align: left;
}
#output thead { background: var(--preview-table-head-bg, #f6f8fa); font-weight: 600; }
#output tbody tr.striped { background: var(--preview-table-stripe, #f6f8fa); }

/* ── Images ── */
#output img {
  max-width: 100%;
  border-radius: var(--preview-img-radius, 4px);
  display: var(--preview-img-display, block);
  margin: var(--preview-img-margin, 1em auto);
  box-shadow: var(--preview-img-shadow, none);
}

/* ── Misc ── */
#output hr { border: 0; border-top: 1px solid #e0e0e0; margin: 1.5em 0; }
#output ul, #output ol { padding-left: 1.5em; margin: 0.75em 0; }
#output li { margin: 0.3em 0; }
.task-item { display: flex; align-items: center; margin: 0.3em 0; }
.task-item input { margin-right: 8px; accent-color: #27ae60; }

/* ── Numérotation titres ── */
#output.numbered-headings { counter-reset: h2 h3; }
#output.numbered-headings h2::before { counter-increment: h2; content: counter(h2) '. '; }
#output.numbered-headings h3::before { counter-increment: h3; content: counter(h2) '.' counter(h3) ' '; }

/* ── TOC flottante ── */
.md-toc {
  position: fixed; top: 68px; right: 12px;
  width: 230px; max-height: calc(100vh - 90px);
  background: var(--panel-bg, #161b22);
  border: 1px solid var(--panel-border, #30363d);
  border-radius: 8px; z-index: 200; font-size: 0.78rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  overflow: hidden; transition: max-height 0.25s ease;
}
.md-toc.collapsed { max-height: 38px; }
.md-toc-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; cursor: pointer;
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid var(--panel-border, #30363d);
  user-select: none;
}
.md-toc.collapsed .md-toc-header { border-bottom: none; }
.md-toc-title { font-weight: 600; color: var(--text-muted, #8b949e); font-size: 0.78rem; }
.md-toc-toggle { color: var(--text-muted, #8b949e); transition: transform 0.25s; font-size: 0.9rem; }
.md-toc.collapsed .md-toc-toggle { transform: rotate(-90deg); }
.md-toc-body {
  overflow-y: auto; max-height: calc(100vh - 130px); padding: 6px 0;
  scrollbar-width: thin; scrollbar-color: var(--panel-border) transparent;
}
.md-toc a {
  display: block; padding: 4px 12px;
  color: var(--accent, #58a6ff) !important;
  text-decoration: none !important; line-height: 1.4;
  transition: background 0.1s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.md-toc a:hover { background: rgba(255,255,255,0.07); }
.md-toc .toc-h3 { padding-left: 22px; font-size: 0.75rem; opacity: 0.85; }
.md-toc .toc-h4 { padding-left: 34px; font-size: 0.72rem; opacity: 0.7; }

/* ── Panel footer ── */
.panel-footer {
  padding: 10px;
  border-top: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.panel-footer-row {
  display: flex;
  gap: 6px;
}
.panel-footer-row .btn-ghost {
  flex: 1;
  font-size: 0.73rem;
  padding: 5px 6px;
  gap: 4px;
  white-space: nowrap;
}
.btn-accent {
  color: var(--accent) !important;
  border-color: rgba(88, 166, 255, 0.25) !important;
}
.btn-accent:hover {
  background: rgba(88, 166, 255, 0.08) !important;
  border-color: var(--accent) !important;
}

/* ── Admonitions ── */
.admonition {
  border-radius: 6px;
  margin: 1.2em 0;
  overflow: hidden;
  border: 1px solid transparent;
}
.admonition details {
  font-size: 0.95em;
}
.admonition summary {
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88em;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.admonition summary::-webkit-details-marker { display: none; }
.admonition summary::before {
  content: '▶';
  font-size: 0.7em;
  transition: transform 0.2s;
  opacity: 0.7;
}
.admonition[open] summary::before,
.admonition details[open] summary::before { transform: rotate(90deg); }
.admonition details > p,
.admonition details > ul,
.admonition details > ol,
.admonition details > pre,
.admonition details > blockquote {
  padding: 8px 14px;
  margin: 0;
}

.admonition-info    { border-color: #bce8f1; }
.admonition-info    summary { background: #d9edf7; color: #31708f; }
.admonition-info    details { background: rgba(56,139,253,0.06); color: var(--preview-text-color, #1a1a1a); }

.admonition-success { border-color: #dff0d8; }
.admonition-success summary { background: #dff0d8; color: #3c763d; }
.admonition-success details { background: rgba(63,185,80,0.06); color: var(--preview-text-color, #1a1a1a); }

.admonition-warning { border-color: #faebcc; }
.admonition-warning summary { background: #fcf8e3; color: #8a6d3b; }
.admonition-warning details { background: rgba(210,153,34,0.06); color: var(--preview-text-color, #1a1a1a); }

.admonition-danger  { border-color: #ebccd1; }
.admonition-danger  summary { background: #f2dede; color: #a94442; }
.admonition-danger  details { background: rgba(248,81,73,0.06); color: var(--preview-text-color, #1a1a1a); }

/* ── Spoiler standalone (hors admonition) ── */
.spoiler {
  border: 1px solid var(--preview-code-border, #d0d7de);
  border-radius: 6px;
  margin: 1em 0;
  overflow: hidden;
}
.spoiler > summary {
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88em;
  background: var(--preview-code-bg, #f6f8fa);
  color: var(--preview-text-color, #1a1a1a);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.spoiler > summary::-webkit-details-marker { display: none; }
.spoiler > summary::before {
  content: '▶';
  font-size: 0.7em;
  transition: transform 0.2s;
  opacity: 0.6;
}
.spoiler[open] > summary::before { transform: rotate(90deg); }
.spoiler-body { padding: 10px 14px; font-size: 0.95em; }

/* ── Drag & Drop ── */
#markdown.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
  background: rgba(88, 166, 255, 0.05);
}
