:root {
  --bg: #f5f3ee; --paper: #fff; --line: #e2ded5; --ink: #1c1b19; --muted: #77726a;
  --accent: #b3261e; --accent-soft: #fbecea; --radius: 8px;
  --nc: #b3261e; --dx: #c86b00; --av: #7d6f00; --ok: #2e7d4f;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); }
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--paper); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button:hover { background: #f0ede6; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #961f18; }
button.ghost { border: none; background: none; color: var(--muted); padding: 3px 6px; }
button.ghost:hover { color: var(--ink); background: #0000000a; }
button.small { padding: 3px 8px; font-size: 12px; }
input, textarea, select { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 100%; background: #fff; }
input:focus, textarea:focus, select:focus { outline: 2px solid #b3261e33; border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 3px; text-transform: uppercase; letter-spacing: .03em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; }
.sp { flex: 1; }
.hidden { display: none !important; }

/* --- en-tête */
header.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px; padding: 0 18px; height: 52px; background: var(--ink); color: #fff; }
header.top .brand { font-weight: 700; letter-spacing: .02em; margin-right: 18px; }
header.top nav a { text-decoration: none; padding: 6px 12px; border-radius: 6px; color: #d8d4cc; }
header.top nav a.on, header.top nav a:hover { background: #ffffff1a; color: #fff; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; text-align: center; margin-left: 4px; }
header.top .me { color: #d8d4cc; font-size: 13px; }
header.top button { background: transparent; color: #d8d4cc; border-color: #ffffff33; }

main.page { max-width: 1180px; margin: 0 auto; padding: 22px 18px 60px; }
main.full { padding: 0; height: calc(100vh - 52px); display: grid; grid-template-columns: 1fr 400px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 24px 0 10px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* --- puces */
.chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 1px 9px; font-size: 12px; color: #fff; background: var(--c, #555); white-space: nowrap; text-decoration: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.kind { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); background: #faf9f6; }
.as { font-size: 11px; padding: 1px 7px; border-radius: 4px; border: 1px solid currentColor; white-space: nowrap; }
.as-non_conforme { color: #fff; background: var(--nc); border-color: var(--nc); }
.as-douteux { color: var(--dx); } .as-a_verifier { color: var(--av); } .as-conforme { color: var(--ok); }
.st { font-size: 11px; padding: 1px 7px; border-radius: 4px; background: #eee; }
.st-a_discuter { background: #fff1d6; color: #8a5a00; } .st-valide { background: #e2f3e8; color: var(--ok); }

/* --- liste des sources */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); background: var(--paper); cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
table.list { width: 100%; border-collapse: collapse; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--line); background: #faf9f6; }
table.list td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr.click { cursor: pointer; } table.list tr.click:hover td { background: #faf8f3; }
.dots { display: flex; gap: 3px; flex-wrap: wrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); display: inline-block; }

/* --- lecteur */
.reader { overflow: auto; background: var(--bg); }
.reader .bar button { white-space: nowrap; }
.reader .bar { position: sticky; top: 0; z-index: 2; display: flex; gap: 8px; align-items: center; padding: 10px 22px; background: #f5f3eeee; backdrop-filter: blur(4px); border-bottom: 1px solid var(--line); }
.reader .bar input.title { font-size: 16px; font-weight: 600; border-color: transparent; background: transparent; }
.reader .bar input.title:hover, .reader .bar input.title:focus { border-color: var(--line); background: #fff; }
.text { max-width: 820px; margin: 22px auto 80px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 40px 54px; white-space: pre-wrap; word-wrap: break-word; font: 15px/1.7 Georgia, "Times New Roman", serif; }
.text mark { background: color-mix(in srgb, var(--c) 22%, transparent); border-bottom: 2px solid var(--c); color: inherit; cursor: pointer; border-radius: 2px; }
.text mark.multi { background: color-mix(in srgb, var(--c) 38%, transparent); border-bottom-style: double; border-bottom-width: 3px; }
.text mark.flash, .lnk.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px #b3261e66; } 100% { box-shadow: 0 0 0 0 transparent; } }
.text .pb { display: block; font-size: 0; margin: 26px -54px; border-top: 1px dashed var(--line); text-align: center; }
.text .pb::before { content: "page " attr(data-p); font: 11px system-ui, sans-serif; color: var(--muted); background: var(--paper); padding: 0 10px; position: relative; top: -9px; }
.text::selection, .text *::selection { background: #b3261e40; }
.orig { height: calc(100vh - 52px - 57px); }
.orig iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.empty { padding: 60px 20px; text-align: center; color: var(--muted); }
#selbtn { position: absolute; z-index: 20; box-shadow: 0 4px 14px #0003; }

/* --- panneau latéral */
.side { overflow: auto; background: var(--paper); border-left: 1px solid var(--line); padding: 0 16px 30px; }
.side h2:first-child { margin-top: 16px; }
.lnk { border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; background: #fff; }
.lnk .head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.lnk .quote { font: 13px/1.5 Georgia, serif; color: #3d3a35; margin: 6px 0 0; padding-left: 8px; border-left: 2px solid var(--line); max-height: 7.5em; overflow: hidden; white-space: pre-wrap; }
.lnk .comment { margin-top: 6px; font-size: 13px; }
.lnk .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.lnk.absence { border-left-style: dashed; background: repeating-linear-gradient(135deg, #fff, #fff 8px, #faf8f3 8px, #faf8f3 16px); }
.tabs { display: flex; gap: 4px; margin: 14px 0 8px; border-bottom: 1px solid var(--line); }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 6px 10px; color: var(--muted); }
.tabs button.on { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }

/* --- principes */
.plist { display: grid; gap: 10px; }
.pcard { display: grid; grid-template-columns: 6px 1fr auto; gap: 14px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 14px 0; cursor: pointer; text-decoration: none; }
.pcard:hover { border-color: #cfc9bd; box-shadow: 0 2px 8px #0000000d; }
.pcard .bar { background: var(--c); border-radius: 0 4px 4px 0; }
.pcard .t { font-weight: 600; font-size: 16px; }
.pcard .s { color: #4a4640; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pcard .n { text-align: right; font-size: 12px; color: var(--muted); white-space: nowrap; }
.code { font: 600 12px ui-monospace, monospace; color: var(--muted); }

.demo { display: grid; grid-template-columns: 1fr 380px; gap: 22px; align-items: start; }
.demo .titlein { font-size: 22px; font-weight: 700; border-color: transparent; padding: 4px 6px; margin-left: -6px; background: transparent; }
.demo .titlein:hover, .demo .titlein:focus { border-color: var(--line); background: #fff; }
.prose { font: 15px/1.7 Georgia, serif; }
.prose h3, .prose h4 { font-family: system-ui, sans-serif; margin: 18px 0 6px; }
.prose blockquote { margin: 8px 0; padding: 2px 12px; border-left: 3px solid var(--line); color: #4a4640; }
.prose p { margin: 0 0 10px; }
a.ref { text-decoration: none; background: var(--accent-soft); color: var(--accent); padding: 0 5px; border-radius: 4px; font: 600 12px ui-monospace, monospace; }
.sticky { position: sticky; top: 70px; }

/* --- échanges */
.thread { display: flex; flex-direction: column; gap: 8px; }
.msg { background: #faf9f6; border: 1px solid var(--line); border-radius: 10px; padding: 8px 11px; }
.msg.mine { background: #f3f6fb; border-color: #dbe3ee; }
.msg.new { border-color: var(--accent); }
.msg .who { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.msg .who b { color: var(--ink); }
.msg .body { margin-top: 3px; white-space: normal; }
.msg .body p { margin: 0 0 6px; } .msg .body p:last-child { margin: 0; }
.composer textarea { min-height: 64px; }
.ctx { font-size: 11px; text-decoration: none; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }

/* --- modale */
dialog { border: none; border-radius: 12px; padding: 0; width: min(620px, 94vw); box-shadow: 0 20px 60px #0004; }
dialog::backdrop { background: #1c1b1966; }
dialog form { padding: 18px 20px; }
dialog h3 { margin: 0 0 6px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
dialog blockquote { margin: 6px 0; padding: 6px 12px; border-left: 3px solid var(--accent); background: #faf9f6; max-height: 160px; overflow: auto; white-space: pre-wrap; font: 13px/1.5 Georgia, serif; }

/* --- connexion */
.login { max-width: 360px; margin: 12vh auto; }
.login h1 { margin-bottom: 14px; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 8px; display: none; z-index: 50; max-width: 90vw; }

@media (max-width: 980px) {
  main.full { grid-template-columns: 1fr; height: auto; }
  .demo, .grid2 { grid-template-columns: 1fr; }
  .text { padding: 24px 20px; }
  .text .pb { margin: 20px -20px; }
}
