/* Calepin — interface d'écriture calme et lisible (§ 13). Une seule couleur d'accent, neuf gris. */

:root {
  --g0: #ffffff;
  --g1: #f8f9fa;
  --g2: #edeff2;
  --g3: #e3e6ea;
  --g4: #d3d7dd;
  --g5: #a9afb8;
  --g6: #7c838d;
  --g7: #5b616b;
  --g8: #1f2328;
  --accent: #1c64c8;
  --accent-soft: #e8f0fb;
  --on-accent: #ffffff;
  --danger: #c62828;
  --warn-bg: #fff6e0;
  --warn-fg: #7a5200;
  --info-bg: #eef3fb;
  --add-bg: #e6f4ea;
  --del-bg: #fdecea;
  --bg: var(--g0);
  --sb-bg: var(--g1);
  --hover: var(--g2);
  --active: var(--g3);
  --border: var(--g3);
  --text: var(--g8);
  --text-2: var(--g7);
  --text-3: var(--g6);
  --sb-w: 260px;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  --shadow: 0 1px 2px rgba(15, 20, 30, .06), 0 4px 16px rgba(15, 20, 30, .08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --g0: #1a1b1e; --g1: #25262b; --g2: #2c2e33; --g3: #373a40; --g4: #45484f; --g5: #5c5f66; --g6: #8b9099; --g7: #a9adb4; --g8: #e7e8ea;
    --accent: #6ea8fe; --accent-soft: #23324a; --on-accent: #0f1a2b; --danger: #ff8a80;
    --warn-bg: #3a3020; --warn-fg: #f0cf8a; --info-bg: #1f2a3a; --add-bg: #1f3326; --del-bg: #3d2224;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --g0: #1a1b1e; --g1: #25262b; --g2: #2c2e33; --g3: #373a40; --g4: #45484f; --g5: #5c5f66; --g6: #8b9099; --g7: #a9adb4; --g8: #e7e8ea;
  --accent: #6ea8fe; --accent-soft: #23324a; --on-accent: #0f1a2b; --danger: #ff8a80;
  --warn-bg: #3a3020; --warn-fg: #f0cf8a; --info-bg: #1f2a3a; --add-bg: #1f3326; --del-bg: #3d2224;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 4px; }
[hidden] { display: none !important; }
kbd { font: 11px var(--mono); color: var(--text-3); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; background: var(--bg); }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.block { display: block; }
.grow { flex: 1; min-width: 0; }
.col { display: flex; flex-direction: column; }
.mono { font-family: var(--mono); }
.strong { font-weight: 600; }
.pad { padding: 8px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.gap { gap: 8px; flex-wrap: wrap; }
.offscreen { position: fixed; left: -9999px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; z-index: 100; background: var(--bg); padding: 8px; }
.danger-text { color: var(--danger) !important; }

/* Icônes */
.ico { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
.ico.small { width: 14px; height: 14px; }
.ico.neutral { color: var(--text-3); }
.ico.flip { transform: scaleX(-1); }
.emoji { font-size: 15px; line-height: 1; width: 16px; text-align: center; flex: none; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: var(--radius);
  border: 1px solid transparent; background: transparent; cursor: pointer; white-space: nowrap; font-weight: 500; color: var(--text);
  transition: background .12s;
}
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: var(--danger); filter: brightness(1.08); }
.btn.ghost { color: var(--text-2); }
.btn.small { height: 28px; padding: 0 8px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; height: 38px; }
.btn.icon-only { width: 32px; padding: 0; justify-content: center; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.link:hover { text-decoration: underline; }

/* Champs */
.input, .select {
  height: 34px; padding: 0 10px; border: 1px solid var(--g4); border-radius: var(--radius); background: var(--bg); width: 100%; min-width: 0;
}
.input.small, .select.small { height: 30px; width: auto; font-size: 13px; }
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.input[readonly] { background: var(--sb-bg); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.field-error { color: var(--danger); font-size: 13px; margin: 4px 0; min-height: 0; }
.field-error:empty { display: none; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; margin: 6px 0; }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.switch { appearance: none; width: 34px !important; height: 20px !important; border-radius: 10px; background: var(--g4); position: relative; cursor: pointer; transition: background .12s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .12s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(14px); }

/* Mise en page */
.app { display: grid; grid-template-columns: var(--sb-w) 1fr; height: 100vh; height: 100dvh; }
.sb-collapsed .app { grid-template-columns: 0 1fr; }
.sb-collapsed .sidebar { visibility: hidden; }
.main { display: flex; flex-direction: column; min-width: 0; overflow: auto; position: relative; }
.scrim { display: none; }

/* Barre latérale */
.sidebar {
  background: var(--sb-bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0;
  position: relative; overflow: hidden;
}
.sb-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 4px 14px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; color: var(--text); }
.logo:hover { text-decoration: none; }
.logo-mark { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.account-btn { display: flex; align-items: center; gap: 8px; margin: 2px 8px 6px; padding: 4px 6px; border: 0; background: none; border-radius: var(--radius); cursor: pointer; text-align: left; min-height: 32px; }
.account-btn:hover { background: var(--hover); }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; background: var(--g3); color: var(--text-2); font-size: 10.5px; font-weight: 600; flex: none; }
.avatar.small { width: 20px; height: 20px; font-size: 9px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.sb-actions { padding: 0 8px 6px; display: flex; flex-direction: column; gap: 1px; }
.sb-action { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 4px 8px; border: 0; background: none; border-radius: var(--radius); cursor: pointer; color: var(--text-2); text-align: left; font-size: 14px; }
.sb-action:hover { background: var(--hover); text-decoration: none; }
.new-sub { font-size: 11.5px; color: var(--text-3); line-height: 1.2; }
.sb-scroll { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.sb-section { margin-top: 12px; }
.sb-title { font-size: 12px; font-weight: 500; color: var(--text-3); margin: 0; padding: 4px 8px; }
.sb-title-row { display: flex; align-items: center; justify-content: space-between; border-radius: var(--radius); }
.sb-title-row.drop { background: var(--accent-soft); }
.sb-title-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.sb-title-row:hover .sb-title-actions, .sb-title-row:focus-within .sb-title-actions { opacity: 1; }
.sb-foot { border-top: 1px solid var(--border); padding: 6px 8px; display: flex; gap: 2px; }
.sb-foot .sb-action { flex: 1; }
.sb-resizer { position: absolute; top: 0; right: -3px; width: 6px; height: 100%; cursor: col-resize; z-index: 2; }
.sb-resizer:hover { background: var(--g3); }
.shared-owner { display: flex; align-items: center; gap: 6px; padding: 6px 8px 2px; font-size: 12.5px; color: var(--text-2); }

/* Lignes de l'arbre */
.tree, .fav-list { list-style: none; margin: 0; padding: 0; }
.row.fav, .tree .row {
  display: flex; align-items: center; gap: 6px; height: 32px; padding-right: 4px; border-radius: var(--radius); cursor: pointer;
  color: var(--text); user-select: none; position: relative; outline-offset: -2px;
}
.row.fav { padding-left: 8px; }
.tree .row:hover, .row.fav:hover { background: var(--hover); }
.tree .row.active, .row.fav.active { background: var(--active); font-weight: 500; }
.tree .row.drop, .row.fav.drop { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.tree .row.dragging { opacity: .5; }
.row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev, .chev-space { width: 20px; height: 20px; flex: none; display: inline-flex; align-items: center; justify-content: center; border: 0; background: none; border-radius: 4px; color: var(--text-3); padding: 0; cursor: pointer; }
.chev:hover { background: var(--g3); }
.chev .ico { width: 14px; height: 14px; transition: transform .12s; }
.chev.open .ico { transform: rotate(90deg); }
.row-actions { display: flex; gap: 0; opacity: 0; }
.row:hover .row-actions, .row:focus-within .row-actions, .row.active .row-actions { opacity: 1; }
.row-btn { width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: none; border-radius: 4px; color: var(--text-3); cursor: pointer; padding: 0; }
.row-btn:hover { background: var(--g3); color: var(--text); }
.ico.lock { width: 13px; height: 13px; color: var(--text-3); }
.rename-input { flex: 1; min-width: 0; height: 24px; border: 1px solid var(--accent); border-radius: 4px; padding: 0 4px; background: var(--bg); }
.tree-empty { color: var(--text-3); font-size: 13px; padding: 4px 8px; margin: 0; }
.badge { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 10px; background: var(--g2); color: var(--text-2); margin-left: 6px; font-weight: 500; }
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); }

/* Barre du haut */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 8px 12px 8px 16px; background: var(--bg); border-bottom: 1px solid transparent; }
.main.scrolled .topbar { border-bottom-color: var(--border); }
.topbar-left { flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 4px; flex: none; }
.menu-btn, .expand-btn { display: none; }
.sb-collapsed .expand-btn { display: inline-flex; }
.breadcrumb { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; white-space: nowrap; font-size: 13.5px; }
.crumb { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; flex-shrink: 1; min-width: 0; }
.crumb:hover { color: var(--text); text-decoration: none; }
.crumb.current { color: var(--text); font-weight: 500; }
.breadcrumb .sep { color: var(--g5); flex: none; }
.status-label { font-size: 12.5px; color: var(--text-3); margin-right: 6px; white-space: nowrap; }
.ro-label { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--text-3); margin-right: 4px; }
.segmented { display: inline-flex; background: var(--g2); border-radius: var(--radius); padding: 2px; }
.seg { border: 0; background: none; height: 28px; padding: 0 10px; border-radius: 4px; cursor: pointer; color: var(--text-2); font-weight: 500; font-size: 13px; }
.seg[aria-pressed="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

/* Pages */
.page { width: 100%; max-width: 900px; margin: 0 auto; padding: 24px 32px 64px; }
.page.narrow { max-width: 760px; }
.page.wide { max-width: 1200px; }
.page-title { font-size: 28px; font-weight: 700; margin: 8px 0 16px; letter-spacing: -.01em; }
.section-title { font-size: 13px; color: var(--text-3); font-weight: 500; margin: 24px 0 8px; }
.center-msg { text-align: center; padding-top: 80px; }
.empty { padding: 24px 0; }

/* Note */
.note-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.reader { width: 100%; max-width: 784px; margin: 0 auto; padding: 16px 32px 96px; }
.note-head { margin: 24px 0 20px; }
.note-emoji { font-size: 48px; line-height: 1; border: 0; background: none; padding: 4px; margin: 0 0 8px -4px; border-radius: 8px; cursor: pointer; display: inline-flex; }
.note-emoji:hover:not(:disabled) { background: var(--hover); }
.note-emoji:disabled { cursor: default; }
.note-emoji .emoji { font-size: 48px; width: auto; }
.note-emoji.empty { font-size: 13px; color: var(--text-3); opacity: 0; transition: opacity .12s; }
.note-head:hover .note-emoji.empty, .note-emoji.empty:focus-visible { opacity: 1; }
.emoji-add { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px; }
.note-title { font-size: 40px; line-height: 1.2; font-weight: 700; margin: 0; letter-spacing: -.02em; word-break: break-word; }
.title-btn { font: inherit; letter-spacing: inherit; border: 0; background: none; padding: 0; text-align: left; cursor: text; color: inherit; border-radius: 4px; }
.title-btn:hover { background: var(--hover); }
.title-input { font: inherit; letter-spacing: inherit; width: 100%; border: 0; border-bottom: 2px solid var(--accent); background: none; padding: 0; outline: none; }
.note-meta { color: var(--text-3); font-size: 13px; margin: 8px 0 0; }
.banners:empty { display: none; }
.banner { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn-fg); margin: 8px 0; flex-wrap: wrap; }
.banner.info { background: var(--info-bg); color: var(--text); }
.banner .btn { color: inherit; }

/* Édition */
.note-view.editing { overflow: hidden; }
.main:has(.note-view.editing) { overflow: hidden; }
.editwrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.editwrap .note-top { padding: 0 24px; }
.editwrap .note-head { margin: 4px 0 8px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.editwrap .note-emoji, .editwrap .note-emoji .emoji { font-size: 26px; margin: 0; }
.editwrap .note-emoji.empty { display: none; }
.cm-editor :focus-visible, .cm-content:focus-visible { outline: none; }
.editwrap .note-title { font-size: 22px; flex: 1; min-width: 200px; }
.editwrap .note-meta { width: 100%; margin: 0; }
.edit-head { display: flex; align-items: center; gap: 8px; padding: 4px 16px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.toolbar { display: flex; align-items: center; gap: 2px; flex: 1; overflow-x: auto; }
.tool { width: 32px; height: 32px; flex: none; display: inline-flex; align-items: center; justify-content: center; border: 0; background: none; border-radius: var(--radius); color: var(--text-2); cursor: pointer; }
.tool:hover { background: var(--hover); color: var(--text); }
.tool.push { margin-left: auto; }
.tool[aria-pressed="true"] { color: var(--accent); }
.mobile-tabs { display: none; }
.split { --split: 50%; flex: 1; display: grid; grid-template-columns: var(--split) 6px 1fr; min-height: 0; }
.split.no-preview { grid-template-columns: 1fr 0 0; }
.split.no-preview .preview, .split.no-preview .split-divider { display: none; }
.pane { overflow: auto; min-height: 0; min-width: 0; }
.pane.source { display: flex; }
.pane.preview { border-left: 1px solid var(--border); padding: 16px 32px 64px; }
.split-divider { cursor: col-resize; background: transparent; }
.split-divider:hover, .split-divider:focus-visible { background: var(--g2); }

/* CodeMirror */
.cm-editor { flex: 1; height: 100%; background: var(--bg); color: var(--text); font-size: 15px; }
.cm-editor.cm-focused { outline: none; }
.cm-editor.font-mono .cm-content { font-family: var(--mono); font-size: 14px; }
.cm-editor.font-sans .cm-content { font-family: var(--font); font-size: 16px; }
.cm-scroller { line-height: 1.65 !important; font-family: inherit !important; }
.cm-content { padding: 16px 24px 50vh !important; max-width: 860px; caret-color: var(--text); }
.cm-gutters { background: var(--bg) !important; border-right: 1px solid var(--border) !important; color: var(--g5) !important; }
.cm-cursor { border-left-color: var(--text) !important; }
.cm-selectionBackground, .cm-focused .cm-selectionBackground { background: var(--accent-soft) !important; }
.cm-content ::selection { background: var(--accent-soft); }
.cm-h1 { font-weight: 700; font-size: 1.35em; }
.cm-h2 { font-weight: 700; font-size: 1.2em; }
.cm-h3 { font-weight: 700; font-size: 1.08em; }
.cm-h4 { font-weight: 700; }
.cm-strong { font-weight: 700; }
.cm-em { font-style: italic; }
.cm-strike { text-decoration: line-through; }
.cm-link { color: var(--accent); }
.cm-code { font-family: var(--mono); background: var(--g1); border-radius: 3px; }
.cm-quote { color: var(--text-2); font-style: italic; }
.cm-mark, .cm-list { color: var(--text-3); }
.cm-fm { display: block; width: 100%; text-align: left; border: 0; border-radius: 4px; background: var(--g1); color: var(--text-3); font: 12.5px var(--font); padding: 3px 8px; margin: 2px 0; cursor: pointer; }
.cm-fm:hover { background: var(--g2); }

/* Contenu Markdown */
.md { font-size: 16px; line-height: 1.6; word-wrap: break-word; color: var(--text); }
.md > :first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { line-height: 1.3; margin: 1.6em 0 .5em; font-weight: 700; letter-spacing: -.01em; }
.md h1 { font-size: 1.9em; }
.md h2 { font-size: 1.5em; }
.md h3 { font-size: 1.25em; }
.md h4 { font-size: 1.05em; }
.md h5, .md h6 { font-size: 1em; color: var(--text-2); }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 0 0 1em; }
.md ul, .md ol { padding-left: 1.6em; }
.md li + li { margin-top: .2em; }
.md li > ul, .md li > ol { margin: .2em 0 0; }
.md blockquote { border-left: 3px solid var(--g4); padding: 0 0 0 1em; color: var(--text-2); }
.md code { font-family: var(--mono); font-size: .88em; background: var(--g1); border: 1px solid var(--g2); border-radius: 4px; padding: .1em .35em; }
.md pre { background: var(--g1); border: 1px solid var(--g2); border-radius: var(--radius); padding: 12px 14px; overflow-x: auto; }
.md pre code { background: none; border: 0; padding: 0; font-size: 13.5px; line-height: 1.5; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.md img { max-width: 100%; height: auto; border-radius: 4px; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 12px; }
.md th { background: var(--g1); font-weight: 600; text-align: left; }
.md .al-center { text-align: center; }
.md .al-right { text-align: right; }
.md .task-list-item { list-style: none; margin-left: -1.4em; }
.md .task-list-item-checkbox { margin: 0 .5em 0 0; vertical-align: -2px; cursor: pointer; }
.md .task-list-item-checkbox:disabled { cursor: default; }
.md .footnotes { font-size: .9em; color: var(--text-2); }
.md .footnotes-sep { margin-top: 3em; }

/* Listes */
.list { width: 100%; border-collapse: collapse; margin: 12px 0; }
.list th { text-align: left; font-weight: 500; font-size: 12px; color: var(--text-3); padding: 6px 8px; border-bottom: 1px solid var(--border); }
.list td { padding: 6px 8px; border-bottom: 1px solid var(--g2); vertical-align: middle; }
.list-row { cursor: pointer; }
.list-row:hover { background: var(--g1); }
.list-name { display: flex; align-items: center; gap: 8px; min-height: 32px; }
.list td.actions { text-align: right; white-space: nowrap; }
.table-scroll { overflow-x: auto; }
.recent-list, .result-list, .plain-list, .share-list, .notif-list { list-style: none; margin: 0; padding: 0; }
.recent-item { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 6px 8px; border-radius: var(--radius); color: var(--text); }
.recent-item:hover { background: var(--g1); text-decoration: none; }
.search-field { display: flex; align-items: center; gap: 8px; width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--g4); border-radius: var(--radius); background: var(--bg); color: var(--text-3); cursor: text; margin: 16px 0 8px; text-align: left; }
.search-form { display: flex; gap: 8px; margin-bottom: 16px; }
.result { display: flex; flex-direction: column; gap: 2px; padding: 10px 8px; border-radius: var(--radius); color: var(--text); }
.result:hover { background: var(--g1); text-decoration: none; }
.result-title { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.snippet { color: var(--text-2); font-size: 13.5px; }
mark { background: var(--warn-bg); color: inherit; border-radius: 2px; padding: 0 1px; }
.plain-list li { padding: 6px 0; border-bottom: 1px solid var(--g2); }
.share-item { border-bottom: 1px solid var(--border); padding: 12px 0; }
.card-section { border-top: 1px solid var(--border); padding: 20px 0; }
.card-section h2 { font-size: 16px; margin: 0 0 12px; }
.card-section .field { max-width: 420px; }

/* Fenêtres */
.backdrop { position: fixed; inset: 0; background: rgba(15, 20, 30, .35); display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px; z-index: 50; animation: fade .12s; }
.modal { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); width: 100%; max-width: 460px; max-height: 80vh; display: flex; flex-direction: column; animation: pop .14s; }
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 4px 20px; }
.modal-head h2 { font-size: 16px; margin: 0; font-weight: 600; }
.modal-body { padding: 8px 20px 12px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; flex-wrap: wrap; }
.modal-text { margin: 0 0 12px; color: var(--text-2); }
.palette-modal { max-width: 600px; }
.palette-modal .modal-head { display: none; }
.palette-modal .modal-body { padding: 0; }
.palette-input { width: 100%; border: 0; border-bottom: 1px solid var(--border); padding: 14px 18px; font-size: 16px; background: none; outline: none; }
.palette-list { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow-y: auto; }
.palette-item { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 4px 10px; border-radius: var(--radius); cursor: pointer; }
.palette-item.selected, .palette-item:hover { background: var(--hover); }
.codes { font-family: var(--mono); background: var(--g1); padding: 12px; border-radius: var(--radius); white-space: pre-wrap; user-select: all; }
.totp { display: flex; flex-direction: column; }
.qr { width: 200px; height: 200px; margin: 4px auto 12px; display: block; border-radius: 4px; }
.input.code { font: 20px var(--mono); letter-spacing: .3em; text-align: center; max-width: 200px; }

/* Menus */
.menu { position: fixed; z-index: 60; min-width: 220px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; animation: pop .12s; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 32px; padding: 4px 10px; border: 0; background: none; border-radius: 4px; cursor: pointer; text-align: left; color: var(--text); font-size: 13.5px; }
.menu-item:hover:not(:disabled), .menu-item:focus { background: var(--hover); outline: none; }
.menu-item .ico { color: var(--text-3); }
.menu-item.danger, .menu-item.danger .ico { color: var(--danger); }
.menu-item span:nth-child(2) { flex: 1; }
.menu-hint { color: var(--text-3); font-size: 12px; }
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }
.menu-sep:first-child, .menu-sep + .menu-sep, .menu-sep:last-child { display: none; }

/* Notifications */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; background: var(--g8); color: var(--g0); padding: 8px 8px 8px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13.5px; max-width: min(560px, calc(100vw - 32px)); animation: pop .14s; }
.toast.error { background: var(--danger); color: #fff; }
.toast-action { border: 0; background: none; color: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; padding: 4px; }
.toast-close { border: 0; background: none; color: inherit; opacity: .7; cursor: pointer; display: inline-flex; padding: 4px; }

/* Emoji */
.emoji-picker { position: fixed; z-index: 60; width: 340px; max-width: calc(100vw - 16px); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 8px; animation: pop .12s; }
.emoji-head { display: flex; gap: 6px; }
.emoji-tabs { display: flex; gap: 2px; margin: 6px 0; overflow-x: auto; }
.emoji-tab { flex: none; width: 30px; height: 30px; border: 0; background: none; border-radius: 4px; cursor: pointer; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; color: var(--text-3); }
.emoji-tab.active, .emoji-tab:hover { background: var(--hover); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); height: 240px; overflow-y: auto; align-content: start; }
.emoji-cell { border: 0; background: none; font-size: 22px; height: 38px; border-radius: 6px; cursor: pointer; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
.emoji-cell:hover, .emoji-cell:focus { background: var(--hover); outline: none; }

/* Partage */
.share-add { display: flex; gap: 8px; }
.suggest { margin: 4px 0; }
.suggest-item { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 36px; padding: 4px 8px; border: 0; background: none; border-radius: var(--radius); cursor: pointer; text-align: left; }
.suggest-item:hover { background: var(--hover); }
.share-people { list-style: none; padding: 0; margin: 12px 0; }
.share-people li { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.share-public { border-top: 1px solid var(--border); padding-top: 12px; }
.share-public h3 { font-size: 14px; margin: 0; }
.share-public .row { margin: 8px 0; }
.share-opts { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 8px 0; font-size: 13px; color: var(--text-2); }
.share-opts label { display: flex; align-items: center; gap: 6px; }

/* Sélecteur de dossier */
.picker { max-height: 50vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: 4px; }
.picker-row { display: flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 8px; border-radius: 4px; cursor: pointer; }
.picker-row:hover { background: var(--hover); }
.picker-row.selected { background: var(--accent-soft); }
.picker-row.disabled { opacity: .5; cursor: default; }

/* Différences */
.diff-wrap { max-height: 50vh; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); margin-top: 12px; }
.diff { width: 100%; border-collapse: collapse; font: 12.5px/1.5 var(--mono); table-layout: fixed; }
.diff th { position: sticky; top: 0; background: var(--g1); text-align: left; font: 500 12px var(--font); padding: 6px 8px; color: var(--text-2); }
.diff td { padding: 0 8px; white-space: pre-wrap; word-break: break-word; vertical-align: top; border-left: 1px solid var(--g2); }
.d-add { background: var(--add-bg); }
.d-del { background: var(--del-bg); }
.d-empty { background: var(--g1); }

/* Administration */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 16px 0; overflow-x: auto; }
.tab { padding: 8px 12px; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }
.stats { display: flex; flex-wrap: wrap; gap: 24px; margin: 8px 0; }
.stat { display: flex; flex-direction: column; }
.stat-value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--text-3); }
.settings { max-width: 720px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--g2); }
.setting-row .select, .setting-row .input { max-width: 260px; }
.form .field { margin-bottom: 10px; }

/* Connexion */
.login { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 14vh 16px 16px; background: var(--sb-bg); }
.login-box { width: 100%; max-width: 360px; }
.login-logo { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 22px; font-weight: 700; margin-bottom: 24px; }
.login-logo .logo-mark { width: 26px; height: 26px; }
.login-form { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 24px; display: flex; flex-direction: column; gap: 4px; }
.login-form .btn { margin-top: 8px; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Écrans tactiles : le menu ⋯ est toujours visible */
@media (hover: none) {
  .row-actions, .sb-title-actions { opacity: 1; }
  .tree .row, .row.fav { height: 44px; }
  .row-btn { width: 36px; height: 36px; }
  .note-emoji.empty { opacity: 1; }
}

/* Téléphone et tablette */
@media (max-width: 899px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: min(320px, 85vw); transform: translateX(-100%); transition: transform .15s; visibility: visible !important; box-shadow: var(--shadow); }
  .drawer-open .sidebar { transform: none; }
  .drawer-open .scrim { display: block; position: fixed; inset: 0; background: rgba(15, 20, 30, .3); z-index: 30; }
  .sb-resizer, .collapse-btn, .expand-btn { display: none !important; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 6px 8px; gap: 4px; }
  .label-wide { display: none; }
  .btn { min-height: 40px; }
  .btn.icon-only { width: 40px; }
  .seg { height: 36px; }
  .page, .reader { padding: 12px 16px 64px; }
  .note-title { font-size: 30px; }
  .split { grid-template-columns: 1fr !important; }
  .split-divider { display: none; }
  .split[data-tab="write"] .preview { display: none; }
  .split[data-tab="preview"] .source { display: none; }
  .split[data-tab="preview"] .preview { display: block !important; border-left: 0; padding: 16px; }
  .mobile-tabs { display: inline-flex; }
  .tool.push { display: none; }
  .edit-head { padding: 4px 8px; order: 3; border-bottom: 0; }
  .editwrap .note-top { padding: 0 12px; }
  .cm-content { padding: 12px 12px 40vh !important; }
  .status-label { display: none; }
  .list th:nth-child(3), .list td:nth-child(3) { display: none; }
  .modal { max-height: 88vh; }
  .backdrop { padding-top: 6vh; }
  .menu-item { min-height: 44px; }
}
