:root {
  --paper: #fbf8f2;
  --bg: #f1ece3;
  --panel: #ffffff;
  --ink: #2b2622;
  --muted: #8a8078;
  --line: #e3dbcf;
  --accent: #9c4a3c;
  --accent-soft: #f4e4df;
  --radius: 10px;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  --sans: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--sans); }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.spacer { flex: 1; }

/* Boutons */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 14px; }
.btn:hover { border-color: #cfc3b3; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.danger { color: #b3261e; }
.btn.danger:not(.ghost) { border-color: #e7b9b5; }
.btn.wide { width: 100%; padding: 10px; }
.btn-sm { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 2px 9px; font-size: 12px; }
.btn-sm:hover { border-color: var(--accent); color: var(--accent); }
.link { border: 0; background: none; color: var(--accent); padding: 0; margin-top: 4px; }

/* Connexion */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at 20% 10%, #f7e6dc, transparent 50%), radial-gradient(circle at 90% 90%, #e3e8ef, transparent 50%), var(--bg); }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 16px; padding: 32px; box-shadow: 0 20px 50px rgba(60,40,20,.12); text-align: center; }
.auth-card .logo { font-size: 42px; }
.auth-card h1 { font-size: 30px; }
.auth-card .sub { color: var(--muted); margin: 4px 0 20px; }
.seg { display: flex; background: var(--bg); border-radius: 8px; padding: 3px; margin-bottom: 18px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px; border-radius: 6px; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.auth form { text-align: left; display: grid; gap: 12px; }
.auth label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.auth input { padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.auth input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.err { color: #b3261e; min-height: 1em; margin: 0; font-size: 13px; }

/* Barre du haut */
.topbar { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-family: var(--serif); font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.who { color: var(--muted); }
.total { color: var(--muted); font-size: 13px; background: var(--bg); padding: 3px 10px; border-radius: 99px; }

/* Bibliothèque */
.library { max-width: 1100px; margin: 0 auto; padding: 32px 20px; }
.library h2 { font-size: 28px; margin-bottom: 20px; }
.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px; }
.book { position: relative; background: var(--panel); border-radius: 4px 12px 12px 4px; padding: 20px 18px 16px 26px; min-height: 250px; display: flex; flex-direction: column;
  box-shadow: 0 2px 6px rgba(60,40,20,.08); cursor: pointer; transition: transform .15s, box-shadow .15s; border-left: 10px solid var(--c); }
.book:hover { transform: translateY(-3px); box-shadow: 0 12px 24px rgba(60,40,20,.14); }
.book h3 { font-size: 20px; }
.book .genre { color: var(--c); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin: 4px 0 0; }
.book .syn { color: var(--muted); flex: 1; font-family: var(--serif); }
.book footer { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }
.book.new { border: 2px dashed #cfc3b3; background: transparent; box-shadow: none; align-items: center; justify-content: center; color: var(--muted); font-size: 15px; }
.book.new span { font-size: 36px; }
.book.new:hover { color: var(--accent); border-color: var(--accent); }

/* Espace de travail */
.ws { display: grid; grid-template-columns: 270px 1fr 310px; height: calc(100vh - 52px); }
.ws.no-assist { grid-template-columns: 270px 1fr; }
.ws.no-assist .assist { display: none; }
.side { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px; }
.book-info { width: 100%; text-align: left; border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; }
.book-info.active, .book-info:hover { border-color: var(--accent); color: var(--accent); }
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 8px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 6px 2px; border-radius: 6px; font-size: 12px; color: var(--muted); }
.tabs button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.side-head { display: flex; align-items: center; justify-content: space-between; margin: 14px 2px 6px; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 7px; cursor: pointer; }
.item:hover { background: var(--bg); }
.item.active { background: var(--accent-soft); color: var(--accent); }
.it-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.it-meta { font-size: 11px; color: var(--muted); }
.mv { display: none; }
.item:hover .mv { display: flex; }
.item:hover .it-meta { display: none; }
.mv button { border: 0; background: none; padding: 0 3px; color: var(--muted); }
.mv button:hover { color: var(--accent); }
.group { font-size: 12px; color: var(--muted); margin: 10px 4px 2px; font-weight: 600; }
.empty { color: var(--muted); padding: 8px; font-style: italic; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: #c9bfb2; }
.st-en-cours { background: #e0a526; } .st-relecture { background: #3d7ec9; } .st-termine { background: #4f9a5a; }

.main { overflow-y: auto; }
.avatar { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: #fff; font-weight: 700; flex: none; font-family: var(--serif); }
.avatar.sm { width: 24px; height: 24px; font-size: 12px; }
.avatar.xs { width: 10px; height: 10px; }
.avatar.big { width: 48px; height: 48px; font-size: 22px; }

/* Éditeur */
.editor { max-width: 820px; margin: 0 auto; padding: 24px 28px 40px; display: flex; flex-direction: column; min-height: 100%; }
.ch-num { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--accent); }
.ch-title { width: 100%; border: 0; background: transparent; font: 600 30px var(--serif); padding: 2px 0 6px; outline: none; }
.ed-meta { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.ed-meta select { border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; background: var(--panel); }
.save { font-size: 12px; color: #4f9a5a; }
.save.saving { color: var(--muted); }
.save.err { color: #b3261e; }
.paper { flex: 1; min-height: 60vh; margin-top: 18px; width: 100%; resize: none; border: 0; outline: none; background: var(--paper);
  padding: 40px 48px; border-radius: 4px; box-shadow: 0 1px 3px rgba(60,40,20,.08), 0 8px 30px rgba(60,40,20,.06);
  font: 18px/1.85 var(--serif); color: #2f2924; }

/* Assistance */
.assist { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; background: var(--paper); }
.card h4 { margin: 0 0 8px; font-size: 13px; }
.card textarea, #lookup { width: 100%; border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; background: #fff; resize: vertical; }
#lookup { margin-bottom: 8px; }
.sg-word { font-family: var(--serif); font-size: 16px; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 3px 10px; font-size: 13px; }
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.chip.person { display: inline-flex; align-items: center; gap: 6px; }
.chip.rep b { color: var(--accent); font-weight: 600; }
.hints { margin-top: 12px; }
.hints h5 { margin: 0 0 4px; font-size: 12px; }
.hints ul { margin: 0; padding-left: 16px; font-family: var(--serif); font-style: italic; }
.hints li { cursor: pointer; padding: 2px 0; }
.hints li:hover { color: var(--accent); }
.pmini { display: flex; gap: 10px; margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 13px; }
.pmini p { margin: 3px 0; }

/* Pages (fiches) */
.page { max-width: 820px; margin: 0 auto; padding: 28px; }
.page.wide { max-width: 1100px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.page-head h2 { font-size: 26px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.form .full { grid-column: 1 / -1; }
.form input, .form select, .form textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--panel); font-size: 15px; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--ink); }
.form textarea { font-family: var(--serif); resize: vertical; line-height: 1.6; }
.form input[type=color] { padding: 2px; height: 38px; }
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.sub-h { margin: 24px 0 8px; }
.cat-h { margin: 22px 0 10px; font-size: 18px; }
.cgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.ccard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; cursor: pointer; transition: box-shadow .15s, border-color .15s; }
.ccard:hover { border-color: #cfc3b3; box-shadow: 0 6px 18px rgba(60,40,20,.08); }
.ccard header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.ccard h3 { font-size: 18px; }
.ccard .role { font-size: 12px; color: var(--muted); }
.ccard p { margin: 6px 0 0; font-size: 13.5px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 24px 0 12px; }
.stats div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-align: center; }
.stats b { display: block; font: 600 24px var(--serif); }
.stats span { color: var(--muted); font-size: 12px; }
.progress { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress div { height: 100%; background: var(--accent); }
.danger-zone { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line); }
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state > div { font-size: 48px; }
.empty-state h2 { color: var(--ink); margin: 8px 0; }

/* Menu d'export */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); min-width: 190px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 10px 30px rgba(60,40,20,.15); padding: 4px; display: flex; flex-direction: column; z-index: 10; }
.menu[hidden] { display: none; }
.menu button { border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 6px; }
.menu button:hover { background: var(--accent-soft); color: var(--accent); }

/* Dictionnaire */
.dict { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
.dict h5 { margin: 0 0 6px; font-size: 12px; }
.defs { margin: 0 0 8px; padding-left: 18px; font: 13px/1.45 var(--serif); }
.defs li { margin-bottom: 3px; }
.defs i { color: var(--muted); font: 11px var(--sans); margin-right: 3px; }
.dictchip { border-style: dashed; }
.dict-links { margin-top: 8px; font-size: 12px; color: var(--muted); }
.dict-links a { color: var(--accent); text-decoration: none; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 20; box-shadow: 0 8px 24px rgba(0,0,0,.2); }

@media (max-width: 1100px) {
  .ws, .ws.no-assist { grid-template-columns: 230px 1fr; }
  .assist { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  .ws { height: auto; min-height: calc(100vh - 52px); }
}
@media (max-width: 720px) {
  .ws, .ws.no-assist { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); max-height: 40vh; }
  .paper { padding: 22px; font-size: 17px; }
  .form, .stats { grid-template-columns: 1fr 1fr; }
  .who { display: none; }
}
