/* ══════════════════════════════════════════════════════
   THÈME CLAIR (défaut) — issu du style institutionnel
   ══════════════════════════════════════════════════════ */
:root {
  --bg:           #f4f2ed;
  --surface:      #ffffff;
  --surface2:     #f0ede6;
  --border:       #d8d4cb;
  --border2:      #c5c0b5;
  --accent:       #1a3a5c;
  --accent2:      #2d6a4f;
  --accent-light: #e8eff7;
  --accent-dim:   rgba(26,58,92,0.08);
  --text:         #1c1a17;
  --text-dim:     #7a7669;
  --text-mid:     #4a4740;
  --danger:       #8b2020;
  --danger-dim:   rgba(139,32,32,0.08);
  --scratch:      #c76b00;
  --scratch-dim:  rgba(199,107,0,0.08);
  --pdf:          #2d6a4f;
  --pdf-dim:      rgba(45,106,79,0.08);
  --pdf-light:    #edf7f0;
  --radius:       4px;
  --gap:          14px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
  --mono: 'Menlo','Consolas','DejaVu Sans Mono','Liberation Mono','Courier New',monospace;
  --sans: 'Segoe UI',system-ui,-apple-system,'Helvetica Neue','Arial',sans-serif;
}

/* ══════════════════════════════════════════════════════
   THÈME SOMBRE
   ══════════════════════════════════════════════════════ */
html.dark {
  --bg:           #141820;
  --surface:      #1c2230;
  --surface2:     #222a3a;
  --border:       #2e3850;
  --border2:      #3a4660;
  --accent:       #7bafd4;
  --accent2:      #5aaa7e;
  --accent-light: rgba(123,175,212,0.10);
  --accent-dim:   rgba(123,175,212,0.10);
  --text:         #dde3ec;
  --text-dim:     #6e7e99;
  --text-mid:     #a0aec0;
  --danger:       #e07070;
  --danger-dim:   rgba(224,112,112,0.10);
  --scratch:      #ffab19;
  --scratch-dim:  rgba(255,171,25,0.10);
  --pdf:          #6ebd96;
  --pdf-dim:      rgba(110,189,150,0.10);
  --pdf-light:    rgba(110,189,150,0.10);
  --shadow:       0 2px 8px rgba(0,0,0,.3);
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--sans); background: var(--bg); color: var(--text); overflow: hidden; font-size: 21px; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── HEADER ── */
header {
  position: relative; z-index: 10; height: 78px; padding: 0 30px;
  display: flex; align-items: center; gap: 18px;
  background: var(--accent); color: white; flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
html.dark header { background: #0f1520; border-bottom: 1px solid var(--border); }

.logo-icon {
  width: 52px; height: 52px; background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius); display: grid; place-items: center; flex-shrink: 0;
}
.logo-icon img { width: 44px; height: 44px; object-fit: contain; }

h1 { font-family: var(--mono); font-size: 20px; font-weight: 400;
     color: rgba(255,255,255,.92); letter-spacing: .01em; }
h1 span { color: rgba(255,255,255,.45); }

/* Bouton bascule thème */
.btn-theme {
  margin-left: auto;
  font-family: var(--mono); font-size: 15px; font-weight: 500;
  letter-spacing: .07em; text-transform: uppercase;
  color: rgba(255,255,255,.85); background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.28); border-radius: var(--radius);
  cursor: pointer; padding: 7px 15px;
  display: flex; align-items: center; gap: 9px;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn-theme:hover { background: rgba(255,255,255,.24); border-color: rgba(255,255,255,.5); }

.header-badge {
  font-family: var(--mono); font-size: 14px; letter-spacing: .09em;
  text-transform: uppercase; color: rgba(255,255,255,.55);
  border: 1px solid rgba(255,255,255,.22); padding: 3px 10px;
  border-radius: var(--radius); background: rgba(255,255,255,.08);
}

/* ── WORKSPACE ── */
.workspace { display: grid; grid-template-columns: 1fr 1fr; height: calc(100vh - 78px); overflow: hidden; }
.col-left  { display: flex; flex-direction: column; padding: var(--gap); gap: var(--gap); overflow-y: auto; border-right: 1px solid var(--border); padding-bottom: 36px; }
.col-right { display: flex; flex-direction: column; overflow: hidden; }

/* ── CARDS ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.card-header { padding: 9px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; background: var(--surface2); }
.card-title { font-family: var(--mono); font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: .10em; color: var(--text-dim); flex: 1; }
.card-title.scratch { color: var(--scratch); }
.card-title.latex   { color: var(--accent); }
.card-title.pdf-lbl { color: var(--pdf); }
.card-meta { font-family: var(--mono); font-size: 14px; color: var(--text-dim); }

/* ── BOUTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 9px 18px; border-radius: var(--radius);
  font-family: var(--mono); font-size: 15px; letter-spacing: .06em;
  text-transform: uppercase; cursor: pointer; border: none;
  transition: all .13s; font-weight: 500; white-space: nowrap;
}
.btn:disabled { opacity: .38; cursor: not-allowed; transform: none !important; }

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.12); box-shadow: 0 2px 8px var(--accent-dim); }

.btn-ghost { background: var(--surface2); color: var(--text-mid); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.btn-success { background: var(--pdf); color: white; }
.btn-success:hover:not(:disabled) { filter: brightness(1.1); }

.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: white; }

/* ── MODE TOGGLE ── */
.mode-row { padding: 10px 14px 0; }
.mode-toggle { display: inline-flex; gap: 0; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.mode-btn {
  font-family: var(--mono); font-size: 14px; font-weight: 500; letter-spacing: .06em;
  text-transform: uppercase; padding: 7px 16px; border: none;
  background: transparent; color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; gap: 7px; transition: all .13s;
  border-right: 1px solid var(--border);
}
.mode-btn:last-child { border-right: none; }
.mode-btn.active { background: var(--accent); color: white; }
.mode-btn:not(.active):hover { background: var(--accent-light); color: var(--accent); }

/* ── ZONE D'ENTRÉE ── */
.input-area { padding: 10px 14px; }

.drop-zone {
  border: 1.5px dashed var(--border2); border-radius: var(--radius);
  padding: 26px 20px; display: flex; flex-direction: column;
  align-items: center; gap: 8px; text-align: center;
  background: var(--surface2); transition: all .15s;
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--accent); background: var(--accent-light); }
.drop-icon { color: var(--text-dim); transition: color .15s; font-size: 22px; }
.drag-over .drop-icon { color: var(--accent); }
.drop-label { font-size: 20px; color: var(--text-mid); }
.drop-label strong { color: var(--text); }
.drop-or { font-family: var(--mono); font-size: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; }
.drop-hint { font-family: var(--mono); font-size: 14px; color: var(--text-dim); opacity: .55; margin-top: 2px; }
.btn-browse {
  font-family: var(--mono); font-size: 15px; font-weight: 500;
  letter-spacing: .06em; text-transform: uppercase;
  padding: 7px 18px; border-radius: var(--radius);
  background: var(--surface); color: var(--text-mid);
  border: 1px solid var(--border2); cursor: pointer; transition: all .13s;
}
.btn-browse:hover { border-color: var(--accent); color: var(--accent); }

/* Succès drop */
.drop-success {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; display: flex; flex-direction: row;
  align-items: center; gap: 10px;
  background: var(--surface2);
}
@keyframes popIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.success-icon { color: var(--accent2); flex-shrink: 0; }
.success-icon svg { animation: popIn 0.3s cubic-bezier(0.34,1.56,0.64,1); width: 20px; height: 20px; display: block; }
.drop-success .filename { font-family: var(--mono); font-size: 15px; color: var(--text); font-weight: 500; flex: 1; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drop-success .fileinfo { font-family: var(--mono); font-size: 13px; color: var(--text-dim); white-space: nowrap; margin: 0; }
.btn-reset {
  font-family: var(--mono); font-size: 13px; color: var(--text-dim);
  background: none; border: 1px solid var(--border); padding: 4px 10px;
  border-radius: var(--radius); cursor: pointer; flex-shrink: 0; transition: all .13s;
}
.btn-reset:hover { color: var(--accent); border-color: var(--accent); }

/* ── TEXTAREA JSON ── */
textarea {
  width: 100%; height: 190px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  outline: none; resize: vertical;
  font-family: var(--mono); font-size: 17px; line-height: 1.65;
  color: var(--text); padding: 10px; caret-color: var(--accent);
  transition: border-color .13s;
}
textarea::placeholder { color: var(--border2); }
textarea:focus { border-color: var(--accent); background: var(--surface); }

/* ── ACTION ROW ── */
.action-row { padding: 0 14px 12px; display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ── OPTIONS ROW ── */
.options-row { padding: 8px 14px; display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.options-label { font-family: var(--mono); font-size: 13px; letter-spacing: .07em; text-transform: uppercase; color: var(--text-dim); flex-shrink: 0; }
.opt-toggle {
  font-family: var(--mono); font-size: 13px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase;
  padding: 6px 13px; border-radius: var(--radius);
  background: var(--surface2); color: var(--text-dim);
  border: 1px solid var(--border); cursor: pointer;
  display: flex; align-items: center; gap: 7px; transition: all .13s;
}
.opt-toggle:hover { border-color: var(--accent); color: var(--accent); }
.opt-toggle.active { background: var(--accent); color: white; border-color: var(--accent); }
.opt-select {
  font-family: var(--mono); font-size: 13px; color: var(--text-mid);
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 5px 8px;
  cursor: pointer; outline: none; transition: border-color .13s;
}
.opt-select:hover, .opt-select:focus { border-color: var(--accent); color: var(--accent); }

/* ── ÉDITEUR LATEX (CodeMirror) ── */
.latex-block { padding: 10px 12px 12px; }

/* Conteneur principal */
.latex-block .CodeMirror {
  width: 100%; height: calc(100vh - 400px); min-height: 300px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono); font-size: 17px; line-height: 1.68;
  color: var(--text);
  transition: border-color .13s, background .13s;
}
.latex-block .CodeMirror-focused { border-color: var(--accent); background: var(--surface); }
.latex-block .CodeMirror.modified { border-color: var(--scratch); }

/* Numéros de lignes */
.latex-block .CodeMirror-gutters  { background: var(--surface2); border-right: 1px solid var(--border); border-radius: var(--radius) 0 0 var(--radius); }
.latex-block .CodeMirror-linenumber { color: var(--text-dim); }

/* Curseur */
.latex-block .CodeMirror-cursor { border-left-color: var(--text); }

/* Sélection */
.latex-block .CodeMirror-selected { background: var(--accent-dim); }
.latex-block .CodeMirror-focused .CodeMirror-selected { background: rgba(26,58,92,0.18); }
html.dark .latex-block .CodeMirror-focused .CodeMirror-selected { background: rgba(123,175,212,0.22); }

/* ── Coloration syntaxique LaTeX (mode stex) ── */
/* \commandes */
.latex-block .cm-keyword  { color: var(--accent); font-weight: 600; }
/* % commentaires */
.latex-block .cm-comment  { color: var(--text-dim); font-style: italic; }
/* \begin \end et commandes structurelles */
.latex-block .cm-tag      { color: var(--accent2); font-weight: 600; }
/* Chaînes de caractères / arguments textuels */
.latex-block .cm-string   { color: var(--text-mid); }
/* Accolades et crochets */
.latex-block .cm-bracket  { color: var(--text-dim); }
/* Nombres */
.latex-block .cm-number   { color: var(--scratch); }

/* Scrollbar interne */
.latex-block .CodeMirror-scroll::-webkit-scrollbar { width: 5px; height: 5px; }
.latex-block .CodeMirror-scroll::-webkit-scrollbar-track { background: transparent; }
.latex-block .CodeMirror-scroll::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

.badge-modified {
  font-family: var(--mono); font-size: 13px; letter-spacing: .07em;
  text-transform: uppercase; color: var(--scratch);
  border: 1px solid var(--scratch); padding: 1px 6px;
  border-radius: var(--radius); background: var(--scratch-dim);
}

/* ── COLONNE DROITE PDF ── */
.pdf-col-header {
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface2); display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.pdf-viewer-wrap { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.pdf-canvas-scroll {
  flex: 1; overflow-y: auto;
  background: #5a5d60;
  display: flex; flex-direction: column; align-items: center;
  padding: 14px; gap: 10px;
}
html.dark .pdf-canvas-scroll { background: #1a1e26; }
.pdf-canvas-scroll canvas { display: block; box-shadow: 0 2px 12px rgba(0,0,0,.4); max-width: 100%; }
.pdf-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: var(--text-dim); padding: 32px; text-align: center;
}
.pdf-empty svg { opacity: .2; color: var(--accent); }
.pdf-empty p { font-family: var(--mono); font-size: 15px; opacity: .6; max-width: 300px; line-height: 1.6; letter-spacing: .04em; }

/* ── OVERLAY COMPILATION ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; border-top-color: transparent; animation: spin .65s linear infinite; display: inline-block; vertical-align: middle; }
.compile-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45); backdrop-filter: blur(3px);
  z-index: 100; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.compile-overlay.active { opacity: 1; pointer-events: all; }
.compile-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 28px 40px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,.25);
  animation: modalIn .2s cubic-bezier(.34,1.56,.64,1);
}
@keyframes modalIn { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.compile-card .big-spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
.compile-card p { font-family: var(--mono); font-size: 17px; color: var(--text-mid); }
.compile-card small { font-family: var(--mono); font-size: 14px; color: var(--text-dim); }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 26px; right: 20px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-family: var(--mono); font-size: 17px;
  padding: 9px 16px; border-radius: var(--radius);
  opacity: 0; transform: translateY(12px);
  transition: all .22s cubic-bezier(.4,0,.2,1);
  z-index: 200; pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,.12); max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok    { border-color: #b7dfc6; color: var(--accent2); }
.toast.error { border-color: #e8b8b8; color: var(--danger); }

/* ── STATUS BAR ── */
.status-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  height: 22px; padding: 0 16px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface2); border-top: 1px solid var(--border);
  font-family: var(--mono); font-size: 14px; color: var(--text-dim);
}
.status-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--border2); }
.status-dot.ok  { background: var(--accent2); }
.status-dot.err { background: var(--danger); }

/* ── BOUTON À PROPOS (header) ── */
.btn-header-about {
  font-family: var(--mono); font-size: 15px; font-weight: 500;
  letter-spacing: .07em; text-transform: uppercase;
  color: rgba(255,255,255,.85); background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.28); border-radius: var(--radius);
  cursor: pointer; padding: 7px 15px;
  display: flex; align-items: center; gap: 9px;
  transition: background .15s, border-color .15s; white-space: nowrap;
}
.btn-header-about:hover { background: rgba(255,255,255,.24); border-color: rgba(255,255,255,.5); }

/* ── MODALE ── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); backdrop-filter: blur(3px);
  z-index: 500; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 40px rgba(0,0,0,.2);
  max-width: 800px; width: 92%; max-height: 88vh; overflow-y: auto;
  position: relative;
  animation: modalIn .2s cubic-bezier(.34,1.56,.64,1);
}

.modal-close-btn {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 4px; border-radius: var(--radius);
  display: grid; place-items: center; transition: color .13s, background .13s;
}
.modal-close-btn:hover { color: var(--text); background: var(--surface2); }

.modal-header {
  display: flex; align-items: center; gap: 14px;
  padding: 22px 24px 18px; border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.modal-logo {
  width: 40px; height: 40px; background: var(--accent); color: white;
  border-radius: var(--radius); display: grid; place-items: center; flex-shrink: 0;
}
.modal-app-name {
  font-family: var(--mono); font-size: 21px; font-weight: 600;
  color: var(--text); letter-spacing: .02em;
}
.modal-app-version {
  font-family: var(--mono); font-size: 15px; color: var(--text-dim);
  margin-top: 3px; letter-spacing: .04em;
}
.modal-app-version code { background: var(--accent-light); color: var(--accent); padding: 1px 5px; border-radius: 3px; }

.modal-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 18px; }

.modal-section { display: flex; flex-direction: column; gap: 7px; }
.modal-section-title {
  font-family: var(--mono); font-size: 14px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .12em; color: var(--accent);
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.modal-section p { font-size: 20px; line-height: 1.65; color: var(--text-mid); }
.modal-section strong { color: var(--text); font-weight: 600; }
.modal-section a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.modal-section a:hover { color: var(--accent2); }

.modal-rgpd {
  background: var(--pdf-light); border: 1px solid var(--pdf);
  border-radius: var(--radius); padding: 12px 14px;
  font-size: 19px; line-height: 1.65; color: var(--text-mid);
}
.modal-rgpd strong { color: var(--text); }
.modal-rgpd a { color: var(--pdf); }

.hidden { display: none !important; }
