/* Plume — feuille de style */
:root {
  --bg: #f6f1e7; --paper: #fffdf8; --panel: #efe8da; --panel-2: #e8dfcd; --line: #ddd2bd;
  --ink: #2b2622; --ink-2: #5a5048; --muted: #8a7f72; --accent: #9a4632; --accent-2: #c0613f; --accent-soft: #f1ddd2;
  --ok: #4e7a4a; --warn: #b8862b; --danger: #a33b32;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --radius: 8px; --shadow: 0 1px 2px rgba(60,40,20,.06), 0 4px 14px rgba(60,40,20,.07);
  --editor-size: 19px; --editor-width: 40em;
  color-scheme: light;
}
[data-theme='dark'] {
  --bg: #1a1816; --paper: #211e1b; --panel: #24211e; --panel-2: #2c2824; --line: #3a342e;
  --ink: #ebe4d8; --ink-2: #c3b9ab; --muted: #8f8577; --accent: #e0957a; --accent-2: #eba489; --accent-soft: #3d2a22;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
#app { height: 100%; display: flex; flex-direction: column; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }

/* Boutons et champs */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--paper); border-radius: 6px; padding: 6px 11px; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
[data-theme='dark'] .btn.primary { color: #1a1816; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 8px; font-size: 12.5px; }
.btn.icon { padding: 5px 7px; }
.btn svg, .ico { width: 16px; height: 16px; flex: none; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: var(--paper); border-radius: 6px; padding: 6px 9px; outline: none; }
.input:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 64px; line-height: 1.5; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
label.field > .input, label.field > textarea, label.field > select { font-weight: 400; font-size: 14px; color: var(--ink); letter-spacing: 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--panel-2); border-radius: 999px; padding: 2px 9px; font-size: 12.5px; cursor: pointer; border: 1px solid transparent; }
.chip:hover { border-color: var(--line); }
.chip .x { opacity: .55; margin-left: 2px; } .chip .x:hover { opacity: 1; }
.chip.suggest { background: transparent; border: 1px dashed var(--line); color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

/* Barre du haut */
.topbar { height: 48px; flex: none; display: flex; align-items: center; gap: 6px; padding: 0 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-family: var(--serif); font-size: 19px; font-weight: 600; color: var(--accent); display: flex; align-items: center; gap: 7px; cursor: pointer; padding-right: 6px; }
.brand img { width: 22px; height: 22px; }
.project-title { font-family: var(--serif); font-size: 15px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.tabs { display: flex; gap: 2px; margin-left: 10px; overflow-x: auto; scrollbar-width: none; }
.tab { border: 0; background: transparent; padding: 6px 11px; border-radius: 6px; cursor: pointer; color: var(--ink-2); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tab:hover { background: var(--panel-2); }
.tab.active { background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }
.search-box { position: relative; width: 220px; }
.search-box .input { padding-left: 28px; height: 32px; }
.search-box svg { position: absolute; left: 8px; top: 8px; width: 15px; height: 15px; color: var(--muted); }
.search-results { position: absolute; right: 0; top: 38px; width: 420px; max-height: 70vh; overflow: auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 50; padding: 6px; }
.search-results h4 { margin: 8px 8px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.search-item { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.search-item:hover { background: var(--panel); }
.search-item small { display: block; color: var(--muted); }
.save-state { font-size: 12px; color: var(--muted); min-width: 80px; text-align: right; }

/* Disposition principale */
.main { flex: 1; display: flex; min-height: 0; }
.pane { overflow: auto; min-height: 0; }
.sidebar { width: 270px; flex: none; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
.inspector { width: 300px; flex: none; border-left: 1px solid var(--line); background: var(--panel); padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.side-head { display: flex; align-items: center; gap: 4px; padding: 10px 10px 6px; }
.side-head h3 { margin: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); flex: 1; }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin: 0 0 6px; display: flex; align-items: center; justify-content: space-between; }

/* Classeur */
.tree { padding: 2px 6px 40px; flex: 1; overflow: auto; }
.tree-row { display: flex; align-items: center; gap: 4px; padding: 3px 6px; border-radius: 6px; cursor: pointer; user-select: none; position: relative; border: 1px solid transparent; }
.tree-row:hover { background: var(--panel-2); }
.tree-row.selected { background: var(--paper); box-shadow: var(--shadow); }
.tree-row .twisty { width: 14px; height: 14px; display: grid; place-items: center; color: var(--muted); flex: none; transition: transform .12s; }
.tree-row .twisty.open { transform: rotate(90deg); }
.tree-row .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .wc { font-size: 11px; color: var(--muted); }
.tree-row .ico { color: var(--muted); }
.tree-row[data-type='chapter'] .title { font-weight: 600; }
.tree-row[data-type='folder'] .title { font-weight: 600; color: var(--ink-2); }
.tree-row.drop-before::before, .tree-row.drop-after::after { content: ''; position: absolute; left: 6px; right: 6px; height: 2px; background: var(--accent-2); }
.tree-row.drop-before::before { top: -1px; } .tree-row.drop-after::after { bottom: -1px; }
.tree-row.drop-inside { border-color: var(--accent-2); background: var(--accent-soft); }
.tree-row input { border: 1px solid var(--accent-2); border-radius: 4px; padding: 1px 4px; width: 100%; background: var(--paper); }
.status-dot[data-s='todo'] { background: #b8ada0; } .status-dot[data-s='draft'] { background: var(--warn); }
.status-dot[data-s='revised'] { background: #4f7fa6; } .status-dot[data-s='final'] { background: var(--ok); }

/* Menu contextuel */
.menu { position: fixed; z-index: 100; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px; min-width: 190px; }
.menu button { display: flex; width: 100%; align-items: center; gap: 8px; border: 0; background: none; padding: 6px 10px; border-radius: 5px; cursor: pointer; text-align: left; }
.menu button:hover { background: var(--panel); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu .danger { color: var(--danger); }

/* Éditeur */
.editor-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--paper); }
.editor-toolbar { display: flex; align-items: center; gap: 2px; padding: 6px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.editor-toolbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }
.editor-toolbar .tb { border: 0; background: none; border-radius: 5px; padding: 4px 8px; cursor: pointer; min-width: 30px; color: var(--ink-2); }
.editor-toolbar .tb:hover { background: var(--panel); color: var(--ink); }
.editor-scroll { flex: 1; overflow: auto; }
.page { max-width: var(--editor-width); margin: 0 auto; padding: 0 24px; font-size: var(--editor-size); }
.editor-title { display: block; width: 100%; margin: 2.4em 0 .3em; padding: 0; border: 0; background: transparent; font: 600 1.55em/1.2 var(--serif); outline: none; color: var(--ink); }
.editor-meta { margin: 0 0 1.6em; font-size: 12.5px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }
.editor { padding: 0 0 40vh; font: 1em/1.75 var(--serif); outline: none; min-height: 50vh; caret-color: var(--accent); }
.editor p { margin: 0 0 .1em; text-indent: 1.4em; }
.editor p:first-child, .editor h2 + p, .editor h3 + p, .editor hr + p, .editor blockquote + p { text-indent: 0; }
.editor h2, .editor h3 { font-family: var(--serif); margin: 1.2em 0 .5em; }
.editor blockquote { margin: 1em 2em; font-style: italic; color: var(--ink-2); }
.editor hr { border: 0; text-align: center; margin: 1.4em 0; height: 1.5em; }
.editor hr::after { content: '✦  ✦  ✦'; color: var(--muted); font-size: 14px; letter-spacing: .3em; }
.editor:empty::before { content: 'Il était une fois…'; color: var(--muted); font-style: italic; }
.editor .find-hl { background: #f3d36b88; border-radius: 2px; }
.editor-footer { display: flex; align-items: center; gap: 14px; padding: 6px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); background: var(--paper); }
.progress { height: 5px; border-radius: 3px; background: var(--panel-2); overflow: hidden; width: 120px; }
.progress > div { height: 100%; background: var(--accent-2); transition: width .3s; }
body.focus .topbar, body.focus .sidebar, body.focus .inspector, body.focus .editor-toolbar { display: none; }
body.focus .editor-footer { opacity: .25; transition: opacity .2s; } body.focus .editor-footer:hover { opacity: 1; }
body.typewriter .editor { padding-bottom: 50vh; }

/* Tableau de liège */
.cork { flex: 1; padding: 20px 24px 60px; overflow: auto; background: var(--bg); background-image: radial-gradient(var(--line) 1px, transparent 1px); background-size: 18px 18px; }
.cork-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.cork-head h2 { margin: 0; font: 600 22px var(--serif); }
.crumbs { font-size: 12.5px; color: var(--muted); display: flex; gap: 4px; flex-wrap: wrap; }
.crumbs span { cursor: pointer; } .crumbs span:hover { color: var(--accent); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.card { background: var(--paper); border-radius: 4px; box-shadow: var(--shadow); min-height: 170px; display: flex; flex-direction: column; border-top: 4px solid var(--line); position: relative; transition: transform .1s; }
.card.dragging { opacity: .4; } .card.drop-target { outline: 2px dashed var(--accent-2); outline-offset: 3px; }
.card-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px 4px; cursor: grab; }
.card-head .t { flex: 1; font: 600 15px var(--serif); border: 0; background: transparent; outline: none; padding: 0; min-width: 0; }
.card textarea { flex: 1; border: 0; background: repeating-linear-gradient(transparent 0 21px, var(--line) 21px 22px); line-height: 22px; padding: 0 10px; resize: none; outline: none; font-size: 13.5px; color: var(--ink-2); min-height: 100px; }
.card-foot { display: flex; align-items: center; gap: 8px; padding: 5px 10px; font-size: 11.5px; color: var(--muted); }
.card-add { border: 2px dashed var(--line); background: transparent; border-radius: 6px; min-height: 170px; cursor: pointer; color: var(--muted); font-size: 15px; }
.card-add:hover { border-color: var(--accent-2); color: var(--accent); }

/* Fiches */
.entity-list { flex: 1; overflow: auto; padding: 0 6px 30px; }
.entity-item { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.entity-item:hover { background: var(--panel-2); }
.entity-item.selected { background: var(--paper); box-shadow: var(--shadow); }
.entity-item small { display: block; color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font: 600 14px var(--serif); flex: none; overflow: hidden; background-size: cover; background-position: center; }
.avatar.lg { width: 92px; height: 92px; font-size: 34px; border-radius: 14px; }
.group-label { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 10px 8px 3px; font-weight: 600; }
.sheet { flex: 1; overflow: auto; background: var(--paper); }
.sheet-inner { max-width: 880px; margin: 0 auto; padding: 32px 32px 80px; }
.sheet-head { display: flex; gap: 20px; align-items: flex-start; margin-bottom: 22px; }
.sheet-name { font: 600 30px var(--serif); border: 0; background: transparent; outline: none; width: 100%; padding: 0; }
.sheet-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.sheet-grid .full { grid-column: 1 / -1; }
.sheet h3 .btn { font: 12.5px var(--sans); }
.sheet h3 { font: 600 17px var(--serif); margin: 30px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.rich { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; min-height: 120px; outline: none; font: 16px/1.6 var(--serif); background: var(--paper); }
.rich:focus { border-color: var(--accent-2); }
.rich:empty::before { content: attr(data-placeholder); color: var(--muted); font-style: italic; }
.link-list { display: flex; flex-direction: column; gap: 4px; }
.link-row { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; background: var(--panel); }
.link-row .grow { cursor: pointer; } .link-row .grow:hover { color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty h2 { font: 600 22px var(--serif); color: var(--ink-2); margin: 0 0 8px; }

/* Chronologie */
.timeline-wrap { flex: 1; overflow: auto; padding: 24px 24px 80px; }
.timeline { max-width: 860px; margin: 0 auto; position: relative; padding-left: 150px; }
.timeline::before { content: ''; position: absolute; left: 128px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.tl-event { position: relative; margin-bottom: 14px; background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 14px; border-left: 4px solid var(--ev-color, var(--accent-2)); }
.tl-event::before { content: ''; position: absolute; left: -28px; top: 15px; width: 12px; height: 12px; border-radius: 50%; background: var(--ev-color, var(--accent-2)); box-shadow: 0 0 0 4px var(--bg); }
.tl-date { position: absolute; left: -150px; width: 108px; text-align: right; top: 10px; font: 600 13px var(--serif); color: var(--ink-2); }
.tl-event .t { font: 600 16px var(--serif); }
.tl-event .d { color: var(--ink-2); margin-top: 3px; white-space: pre-wrap; }
.tl-event .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; align-items: center; }
.tl-event .handle { position: absolute; right: 8px; top: 8px; cursor: grab; color: var(--muted); opacity: 0; }
.tl-event:hover .handle { opacity: 1; }
.tl-event.dragging { opacity: .4; } .tl-event.drop-target { outline: 2px dashed var(--accent-2); }
.tl-edit { display: grid; grid-template-columns: 150px 1fr; gap: 8px; }

/* Stats */
.stats-wrap { flex: 1; overflow: auto; padding: 28px; }
.stats-grid { max-width: 980px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stat .n { font: 600 30px var(--serif); } .stat .l { color: var(--muted); font-size: 12.5px; }
.stat.wide { grid-column: span 4; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: 10px; }
.bars .bar { flex: 1; background: var(--accent-2); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars .bar:hover::after { content: attr(data-tip); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 3px 6px; border-radius: 4px; font-size: 11px; white-space: nowrap; margin-bottom: 4px; }

/* Projets & connexion */
.center-page { flex: 1; overflow: auto; padding: 48px 24px; }
.projects { max-width: 980px; margin: 0 auto; }
.projects h1 { font: 600 34px var(--serif); margin: 0 0 4px; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; margin-top: 26px; }
.project-card { background: var(--paper); border-radius: 6px; box-shadow: var(--shadow); padding: 20px; cursor: pointer; min-height: 150px; display: flex; flex-direction: column; border-left: 5px solid var(--accent); transition: transform .12s; }
.project-card:hover { transform: translateY(-2px); }
.project-card h2 { font: 600 21px var(--serif); margin: 0 0 6px; }
.project-card p { color: var(--ink-2); margin: 0; flex: 1; }
.login { max-width: 340px; margin: 14vh auto 0; background: var(--paper); padding: 32px; border-radius: 12px; box-shadow: var(--shadow); text-align: center; }
.login h1 { font: 600 32px var(--serif); color: var(--accent); margin: 6px 0 4px; }

/* Modales & toasts */
.overlay { position: fixed; inset: 0; background: rgba(30,20,10,.35); display: grid; place-items: center; z-index: 200; padding: 20px; }
.modal { background: var(--paper); border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.25); width: min(560px, 100%); max-height: 85vh; overflow: auto; padding: 22px; }
.modal h2 { margin: 0 0 14px; font: 600 21px var(--serif); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 300; }
.toast { background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; animation: pop .18s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }
.snap-row { display: flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.peek { position: fixed; z-index: 150; width: 340px; max-height: 60vh; overflow: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 14px; }
.peek h4 { margin: 0 0 4px; font: 600 18px var(--serif); }
.peek dl { margin: 8px 0 0; font-size: 13px; } .peek dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; margin-top: 7px; } .peek dd { margin: 1px 0 0; white-space: pre-wrap; }

/* Mobile */
.mobile-only { display: none; }
@media (max-width: 900px) {
  .inspector { position: fixed; right: 0; top: 48px; bottom: 0; z-index: 60; box-shadow: var(--shadow); transform: translateX(105%); transition: transform .2s; }
  .inspector.open { transform: none; }
  .sidebar { position: fixed; left: 0; top: 48px; bottom: 0; z-index: 60; box-shadow: var(--shadow); transform: translateX(-105%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .mobile-only { display: inline-flex; }
  .search-box, .save-state, .topbar > .grow { display: none; } .project-title { display: none; }
  .brand { font-size: 0; gap: 0; padding-right: 0; } .tabs { flex: 1; margin-left: 2px; }
  .editor-footer { flex-wrap: wrap; gap: 4px 12px; } .editor-footer .progress, .editor-footer .grow { display: none; }
  .editor-toolbar .tb-desk { display: none; }
  .tab span { display: none; }
  .sheet-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; } .stat.wide { grid-column: span 2; }
  .timeline { padding-left: 24px; } .timeline::before { left: 6px; } .tl-event::before { left: -24px; }
  .tl-date { position: static; text-align: left; width: auto; margin-bottom: 2px; }
  :root { --editor-size: 17px; }
}
