/* ── Thème ─────────────────────────────────────────────────────────────── */
:root {
  --accent: #0f6e56;
  --accent-hover: #0b5844;
  --accent-soft: #e3f2ec;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --border: #dde1e4;
  --text: #1f2933;
  --muted: #6b7680;
  --danger: #c0392b;
  --warn: #c88a04;
  --ok: #1e8a4c;
  --bar: #1d2a33;
  --bar-text: #e8edf0;
  --radius: 6px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 1.6rem 0 .6rem; }
code { font-size: .9em; background: #eef1f3; padding: 0 .25em; border-radius: 3px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pad { padding: .6rem; }
[hidden] { display: none !important; }

/* ── Boutons & formulaires ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
  padding: .45rem .9rem; border: 1px solid transparent; border-radius: var(--radius);
  font: inherit; font-size: .92rem; font-weight: 500; cursor: pointer; text-decoration: none;
  background: #e9ecef; color: var(--text); white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: #dde1e4; }
.btn:disabled { opacity: .65; cursor: progress; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bar); color: #fff; }
.btn-secondary:hover { background: #2c3d49; }
.btn-ghost { background: transparent; border-color: var(--border); color: inherit; }
.btn-ghost:hover { background: rgba(127,127,127,.12); }
.btn-danger { background: transparent; border-color: #e6b8b2; color: var(--danger); }
.btn-danger:hover { background: #fbeceb; }
.btn-sm { padding: .25rem .6rem; font-size: .82rem; }
.btn-block { display: flex; width: 100%; white-space: normal; text-align: center; padding-top: .6rem; padding-bottom: .6rem; }

input, select, textarea {
  font: inherit; font-size: .92rem; color: var(--text);
  padding: .45rem .65rem; border: 1px solid var(--border); border-radius: var(--radius); background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; }
.form-group input:not([type=radio]):not([type=checkbox]), .form-group select { width: 100%; }
.form-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.form-row input[type=email] { flex: 1 1 220px; }
.input-sm { padding: .25rem .5rem; font-size: .82rem; width: 170px; }
form.inline { display: inline-flex; gap: .3rem; align-items: center; }

.alert { padding: .65rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.alert-error { background: #fdecea; color: #8a1c12; border: 1px solid #f5c2bc; }
.alert-success { background: #e6f4ea; color: #145c32; border: 1px solid #b7dfc3; }
.badge { display: inline-block; font-size: .72rem; padding: .05rem .45rem; border-radius: 10px; background: #e8ecef; color: var(--muted); margin-left: .4rem; vertical-align: middle; }
.dot { display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; margin-right: .25rem; }
.dot.ok { background: var(--ok); } .dot.err { background: var(--danger); }

/* ── Barre supérieure ──────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: 0 1rem; height: 52px;
  background: var(--bar); color: var(--bar-text);
}
.topbar a { color: var(--bar-text); text-decoration: none; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 600; font-size: 1.05rem; }
.brand-mark {
  display: inline-grid; place-items: center; background: var(--accent); color: #fff;
  font-family: Georgia, "Times New Roman", serif; font-weight: 700; font-size: .8rem;
  width: 34px; height: 26px; border-radius: 5px; letter-spacing: -.02em;
}
.brand-mark.big { width: 64px; height: 48px; font-size: 1.4rem; border-radius: 10px; }
.topnav { margin-left: auto; display: flex; align-items: center; gap: .9rem; font-size: .9rem; }
.topnav a:hover { text-decoration: underline; }
.topbar .btn-ghost { border-color: rgba(255,255,255,.25); color: var(--bar-text); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.1); text-decoration: none; }
.who { opacity: .75; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Pages ─────────────────────────────────────────────────────────────── */
.container { max-width: 1150px; margin: 0 auto; padding: 1.6rem 1rem 3rem; }
.container.narrow { max-width: 560px; }
.center { text-align: center; padding-top: 4rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: .4rem 0 1.2rem; }
.page-head .actions { display: flex; gap: .5rem; }
.empty { text-align: center; padding: 3rem 1rem; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.filter { width: 100%; max-width: 340px; margin-bottom: .8rem; }

.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; font-size: .9rem; }
.table th, .table td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid #eef0f2; vertical-align: middle; }
.table th { background: #fafbfc; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafcfb; }
.pname { font-weight: 600; text-decoration: none; color: var(--text); }
.pname:hover { color: var(--accent); }
.row-actions { display: flex; gap: .3rem; justify-content: flex-end; flex-wrap: wrap; }
.row-actions form { display: inline-flex; gap: .3rem; }

/* ── Dialogues ─────────────────────────────────────────────────────────── */
.dialog { border: 0; border-radius: 10px; padding: 1.4rem 1.5rem; width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.25); color: var(--text); }
.dialog::backdrop { background: rgba(20,30,38,.45); }
.dialog h2 { margin-top: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.2rem; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .5rem; }
.tpl { display: block; cursor: pointer; }
.tpl input { position: absolute; opacity: 0; }
.tpl span { display: block; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: .88rem; font-weight: 500; }
.tpl input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-hover); }
.tpl input:focus-visible + span { outline: 2px solid var(--accent); }
.members { list-style: none; padding: 0; margin: 1rem 0 0; }
.members li { display: flex; align-items: center; gap: .5rem; padding: .45rem 0; border-top: 1px solid #eef0f2; font-size: .9rem; }
.members .m-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* ── Connexion ─────────────────────────────────────────────────────────── */
.page-login { background: linear-gradient(160deg, #1d2a33 0%, #0f6e56 130%); min-height: 100vh; }
.login-wrap { max-width: 420px; margin: 0 auto; padding: 8vh 1rem 3rem; }
.login-card { background: var(--surface); border-radius: 12px; padding: 2rem 2rem 1.6rem; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-logo { text-align: center; margin-bottom: .6rem; }
.login-title { text-align: center; font-size: 1.5rem; }
.login-subtitle { text-align: center; color: var(--muted); margin: .2rem 0 1.6rem; }
.login-sep { display: flex; align-items: center; gap: .75rem; margin: 1.4rem 0; color: var(--muted); font-size: .8rem; }
.login-sep::before, .login-sep::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.captcha altcha-widget { display: block; --altcha-max-width: 100%; }

/* ── Éditeur : structure ───────────────────────────────────────────────── */
.page-editor { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.editor-bar { height: 48px; flex: none; gap: .75rem; }
.project-name { font-weight: 600; max-width: 26vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-group { display: flex; align-items: center; gap: .75rem; margin-left: .5rem; }
.editor-bar .topnav { gap: .45rem; }
.save-state { font-size: .8rem; opacity: .7; }
.save-state.err { color: #ff9b8f; opacity: 1; }
.count { display: inline-block; min-width: 1.3em; padding: 0 .3em; border-radius: 9px; font-size: .72rem; font-weight: 700; color: #fff; }
.count.err { background: var(--danger); } .count.warn { background: var(--warn); }

.split-btn { position: relative; display: inline-flex; }
.split-btn > .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); min-width: 120px; }
.btn-caret { border-radius: 0 var(--radius) var(--radius) 0; padding: .45rem .5rem; border-left: 1px solid rgba(255,255,255,.25); }
.menu { position: absolute; top: calc(100% + 4px); left: 0; z-index: 50; background: #fff; color: var(--text); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.2); padding: .3rem; min-width: 270px; }
.menu-item { display: flex; gap: .5rem; align-items: center; width: 100%; text-align: left; padding: .45rem .6rem; border: 0; background: none; font: inherit; font-size: .88rem; cursor: pointer; border-radius: 4px; }
.menu-item:hover { background: var(--bg); }
.spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.workspace {
  --files-w: 220px; --pdf-w: 45%;
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: var(--files-w) 5px minmax(200px, 1fr) 5px var(--pdf-w);
}
.workspace.resizing { user-select: none; cursor: col-resize; }
.workspace.resizing iframe, .workspace.resizing .pdf-scroll { pointer-events: none; }
.gutter { background: var(--border); cursor: col-resize; }
.gutter:hover { background: var(--accent); }

.icon-btn { border: 0; background: none; cursor: pointer; font: inherit; font-size: .9rem; color: inherit; padding: .2rem .4rem; border-radius: 4px; text-decoration: none; line-height: 1.2; }
.icon-btn:hover { background: rgba(127,127,127,.18); }

/* Arborescence */
.files { background: #f0f2f4; display: flex; flex-direction: column; min-height: 0; position: relative; }
.files.dragging { outline: 2px dashed var(--accent); outline-offset: -4px; background: var(--accent-soft); }
.files-head { display: flex; justify-content: space-between; align-items: center; padding: .45rem .5rem .45rem .75rem; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--border); }
.files-tools { display: flex; gap: 1px; }
.tree { list-style: none; margin: 0; padding: .3rem 0; overflow: auto; flex: 1; font-size: .88rem; }
.node { display: flex; align-items: center; gap: .3rem; padding: .22rem .5rem .22rem calc(.5rem + var(--depth) * 14px); cursor: pointer; white-space: nowrap; position: relative; }
.node:hover { background: #e2e6e9; }
.node.active { background: var(--accent-soft); color: var(--accent-hover); font-weight: 600; }
.node .tw { width: .8rem; font-size: .7rem; color: var(--muted); flex: none; }
.node .fname { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.node.dirty .fname::after { content: ' •'; color: var(--warn); }
.ficon { font-size: .58rem; font-weight: 700; width: 24px; text-align: center; border-radius: 3px; padding: 1px 0; color: #fff; background: #8795a1; flex: none; }
.i-tex { background: var(--accent); } .i-bib { background: #8e5ea2; } .i-img { background: #d07a28; } .i-pdf { background: #c0392b; } .i-sty { background: #3d6fa8; }
.main-star { color: var(--warn); font-size: .8rem; }
.node-tools { display: none; gap: 0; }
.node:hover .node-tools { display: flex; }
.node-tools button { border: 0; background: none; cursor: pointer; font-size: .78rem; padding: 0 .2rem; opacity: .6; }
.node-tools button:hover { opacity: 1; }
.drop-hint { font-size: .72rem; color: var(--muted); text-align: center; padding: .5rem; border-top: 1px solid var(--border); }

/* Éditeur */
.editor-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #fff; position: relative; }
.tabs { display: flex; overflow-x: auto; background: #f0f2f4; border-bottom: 1px solid var(--border); flex: none; min-height: 33px; }
.tab { display: flex; align-items: center; gap: .3rem; padding: .35rem .4rem .35rem .8rem; font-size: .84rem; cursor: pointer; border-right: 1px solid var(--border); white-space: nowrap; color: var(--muted); }
.tab:hover { background: #e6e9ec; }
.tab.active { background: #fff; color: var(--text); box-shadow: inset 0 2px 0 var(--accent); }
.tab.dirty .tab-name::after { content: ' •'; color: var(--warn); }
.tab-close { border: 0; background: none; cursor: pointer; font-size: 1rem; line-height: 1; color: var(--muted); padding: 0 .2rem; border-radius: 3px; }
.tab-close:hover { background: #dde1e4; color: var(--text); }
.cm-host { flex: 1; min-height: 0; }
.cm-host .CodeMirror { height: 100%; font-family: ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace; font-size: 14px; line-height: 1.5; }
.CodeMirror-activeline-background { background: #f3f8f6; }
.CodeMirror-matchingbracket { background: #d7efe5; color: inherit !important; outline: 1px solid #9fd2bd; }
.cm-s-default .cm-tag { color: #0f6e56; }
.cm-s-default .cm-keyword { color: #7a3e9d; }
.cm-s-default .cm-bracket { color: #3d6fa8; }
.cm-s-default .cm-comment { color: #8a949c; font-style: italic; }
.flash-line { background: #fff4c2 !important; transition: background .6s; }
.issue-gutter { width: 14px; }
.issue-marker { font-size: 11px; cursor: help; padding-left: 2px; }
.issue-marker.error { color: var(--danger); } .issue-marker.warning { color: var(--warn); }
.editor-empty { position: absolute; inset: 33px 0 0; display: grid; place-items: center; color: var(--muted); }
.binary-view { flex: 1; overflow: auto; padding: 1.5rem; display: flex; flex-direction: column; align-items: center; gap: 1rem; background: repeating-conic-gradient(#f3f3f3 0% 25%, #fff 0% 50%) 50% / 20px 20px; }
.binary-view img { max-width: 100%; box-shadow: 0 2px 10px rgba(0,0,0,.15); background: #fff; }

/* PDF */
.pdf-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #525a61; position: relative; }
.pdf-toolbar { display: flex; align-items: center; gap: .3rem; padding: .25rem .5rem; background: #3a4248; color: #e8edf0; font-size: .82rem; flex: none; min-height: 33px; }
.pdf-toolbar select { padding: .1rem .3rem; font-size: .8rem; background: #4b545b; color: #fff; border-color: #5d676f; }
.pdf-toolbar .sep { width: 1px; height: 18px; background: #5d676f; margin: 0 .3rem; }
.pdf-toolbar .grow { flex: 1; }
.page-info { opacity: .8; font-variant-numeric: tabular-nums; }
.pdf-scroll { flex: 1; overflow: auto; position: relative; }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px 14px; }
.pdf-page { position: relative; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); flex: none; }
.pdf-page canvas { display: block; }
.pdf-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #d5dade; font-size: .95rem; padding: 2rem; text-align: center; }
.sync-hl { position: absolute; background: rgba(255, 213, 0, .35); border: 1px solid rgba(220, 160, 0, .9); border-radius: 2px; pointer-events: none; animation: fadeout 2.5s forwards; }
@keyframes fadeout { 70% { opacity: 1; } 100% { opacity: 0; } }

/* Journal */
.issues { position: absolute; inset: 33px 0 0; background: #fff; display: flex; flex-direction: column; z-index: 5; }
.issues-head { display: flex; align-items: center; gap: .8rem; padding: .5rem .8rem; border-bottom: 1px solid var(--border); font-size: .85rem; flex-wrap: wrap; }
.issues-head strong { flex: 1; }
.issues-filter { display: flex; gap: .7rem; }
.issues-filter label { display: flex; gap: .25rem; align-items: center; cursor: pointer; }
.issues-msg:not(:empty) { padding: .6rem .8rem; color: var(--muted); font-size: .88rem; }
.issues-list { list-style: none; margin: 0; padding: .4rem; overflow: auto; flex: 1; }
.issue { border-left: 4px solid var(--border); background: #fafbfc; border-radius: 4px; padding: .45rem .7rem; margin-bottom: .4rem; font-size: .86rem; cursor: pointer; }
.issue:hover { background: #f1f4f6; }
.issue.error { border-color: var(--danger); background: #fdf3f2; }
.issue.warning { border-color: var(--warn); background: #fffaf0; }
.issue-head { display: flex; justify-content: space-between; gap: .5rem; font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.issue.error .lvl { color: var(--danger); } .issue.warning .lvl { color: var(--warn); } .issue.typesetting .lvl { color: var(--muted); }
.issue .loc { font-family: ui-monospace, monospace; text-transform: none; color: var(--muted); font-weight: 500; }
.issue-msg { margin-top: .15rem; word-break: break-word; }
.issue-ctx:empty { display: none; }
.issue-ctx { display: block; margin-top: .25rem; background: none; color: var(--muted); white-space: pre-wrap; font-size: .8rem; }
.raw-output { border-top: 1px solid var(--border); font-size: .82rem; max-height: 40%; overflow: auto; flex: none; }
.raw-output summary { padding: .4rem .8rem; cursor: pointer; color: var(--muted); }
.raw-output pre { margin: 0; padding: .5rem .8rem; font-size: .75rem; white-space: pre-wrap; word-break: break-all; }

/* Notifications */
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 100; background: var(--bar); color: #fff; padding: .55rem 1rem; border-radius: var(--radius); font-size: .88rem; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: min(680px, calc(100vw - 32px)); }
.toast.ok { background: var(--ok); }
.toast.error { background: var(--danger); }

/* Petits écrans : empilement */
@media (max-width: 860px) {
  .page-editor { height: auto; overflow: auto; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: auto 60vh 70vh; }
  .gutter { display: none; }
  .files { max-height: 30vh; }
  .project-name { max-width: 40vw; }
  .editor-bar { height: auto; flex-wrap: wrap; padding: .4rem 1rem; }
  .who { display: none; }
  .table .muted { display: none; }
}
