:root {
  --bg: #f6f7f9; --surface: #fff; --text: #1d2330; --muted: #6b7385; --border: #e2e5ea;
  --primary: #3b5bdb; --primary-text: #fff; --hover: #eef1f6; --danger: #c92a2a;
  --ok-bg: #e6f6ec; --ok: #1f7a3d; --err-bg: #fdecec; --radius: 10px;
  color-scheme: light;
}
/* Thème sombre : préférence du système (« system ») ou choix forcé de l'utilisateur. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171c; --surface: #1c2027; --text: #e6e8ec; --muted: #9aa2b1; --border: #2c323c;
    --primary: #6f8cff; --primary-text: #0b0e14; --hover: #252a33; --danger: #ff6b6b;
    --ok-bg: #16301f; --ok: #6fdc8c; --err-bg: #3a1b1b; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14171c; --surface: #1c2027; --text: #e6e8ec; --muted: #9aa2b1; --border: #2c323c;
    --primary: #6f8cff; --primary-text: #0b0e14; --hover: #252a33; --danger: #ff6b6b;
    --ok-bg: #16301f; --ok: #6fdc8c; --err-bg: #3a1b1b; color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
.muted { color: var(--muted); }
small { font-size: .8rem; }
.right { text-align: right; }

/* barre du haut */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); }
.search { flex: 1; max-width: 640px; }
.search input { width: 100%; }
.usermenu { display: flex; align-items: center; gap: 14px; white-space: nowrap; }
.usermenu form { margin: 0; }
.menu-toggle { display: none; }

.shell { display: flex; min-height: calc(100vh - 54px); }
.sidebar { width: 260px; flex-shrink: 0; padding: 16px; border-right: 1px solid var(--border);
  background: var(--surface); display: flex; flex-direction: column; gap: 12px; }
.channels { display: flex; flex-direction: column; gap: 2px; }
.channels a { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px;
  border-radius: 8px; color: var(--text); }
.channels a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channels a:hover { background: var(--hover); text-decoration: none; }
.channels a.active { background: var(--primary); color: var(--primary-text); }
.channels small { opacity: .7; }
.content { flex: 1; min-width: 0; padding: 20px 28px; max-width: 1100px; }
.center { max-width: 400px; margin: 10vh auto; padding: 0 16px; }

/* formulaires */
input, select, textarea { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
textarea { resize: vertical; min-height: 200px; }
label { display: block; margin-bottom: 12px; font-weight: 500; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
label.check input { width: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.row input { flex: 1; min-width: 180px; width: auto; }
.row select { width: auto; }
form.inline { margin: 0; }
form.inline select { width: auto; padding: 4px 8px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.btn.block { width: 100%; }
.link, .icon-btn { background: none; border: 0; color: var(--primary); font: inherit; cursor: pointer; padding: 0; }
.icon-btn { font-size: 1.3rem; color: var(--text); }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 16px; }
.panel.login h1 { text-align: center; }
.danger-zone { display: flex; flex-direction: column; gap: 12px; }
.danger-zone form { margin: 0; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--danger); }

/* liste de notes */
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 16px; }
.filters a { padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border); color: var(--text); font-size: .9rem; }
.filters a.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.filters a:hover { text-decoration: none; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; color: var(--text); transition: transform .08s, box-shadow .08s; }
.card:hover { text-decoration: none; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.card .thumb { width: 100%; height: 150px; object-fit: cover; background: var(--hover); }
.card-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card h3 { margin: 0; font-size: 1rem; }
.card p { margin: 0; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.meta { margin-top: auto; display: flex; flex-wrap: wrap; gap: 6px 10px; color: var(--muted); font-size: .8rem; align-items: center; }
.badges { display: flex; gap: 4px; }
.badge { background: var(--hover); border-radius: 6px; padding: 1px 6px; font-size: .8rem; }
.badge.on { color: var(--ok); } .badge.off { color: var(--danger); }
.chan { background: var(--hover); padding: 1px 6px; border-radius: 6px; }
.more { grid-column: 1 / -1; }
.empty { padding: 50px 20px; text-align: center; color: var(--muted); border: 2px dashed var(--border); border-radius: var(--radius); }

/* note */
.note { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; }
.note-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.note h1 { font-size: 1.7rem; margin-top: 10px; }
.body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1rem; line-height: 1.6; margin: 14px 0; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; margin: 16px 0; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; }
.media-list { display: flex; flex-direction: column; gap: 12px; }
.media { display: flex; flex-direction: column; gap: 6px; }
.media audio { width: 100%; max-width: 480px; }
.media video { width: 100%; max-height: 70vh; border-radius: 8px; background: #000; }
.att-edit ul { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 6px; }
.att-edit li { display: flex; align-items: center; gap: 10px; }
.att-edit li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-edit img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.conflict { border: 1px solid var(--danger); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; }

/* tableaux, admin */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.tabs a { padding: 8px 14px; color: var(--text); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stats div { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.stats b { display: block; font-size: 1.3rem; }
.stats span { color: var(--muted); font-size: .85rem; }

/* mobile */
@media (max-width: 760px) {
  .menu-toggle { display: block; }
  .brand { display: none; }
  .usermenu a:not(:last-of-type) { display: none; }
  .sidebar { position: fixed; top: 54px; bottom: 0; left: 0; z-index: 9; transform: translateX(-100%);
    transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.15); overflow-y: auto; }
  .sidebar.open { transform: none; }
  .content { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .table { font-size: .9rem; }
}

/* markdown */
.markdown { font-size: 1rem; line-height: 1.6; margin: 14px 0; overflow-wrap: anywhere; }
.markdown > :first-child { margin-top: 0; }
.markdown h1, .markdown h2, .markdown h3 { margin: 1.1em 0 .4em; }
.markdown h1 { font-size: 1.4rem; } .markdown h2 { font-size: 1.2rem; } .markdown h3 { font-size: 1.05rem; }
.markdown code { background: var(--hover); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.markdown pre { background: var(--hover); padding: 12px; border-radius: 8px; overflow-x: auto; }
.markdown pre code { background: none; padding: 0; }
.markdown blockquote { margin: 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.markdown table { border-collapse: collapse; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 4px 10px; }
.markdown img { max-width: 100%; }
.markdown ul.contains-task-list { list-style: none; padding-left: 4px; }

/* checklist */
.checklist { margin: 18px 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); }
.check-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.items { list-style: none; margin: 0; padding: 0; }
.items li { display: flex; align-items: center; gap: 10px; padding: 6px 2px; border-bottom: 1px solid var(--border); }
.items li:last-child { border-bottom: 0; }
.items .tick { background: none; border: 0; font-size: 1.35rem; line-height: 1; cursor: pointer; color: var(--primary); padding: 0; }
.items .text { flex: 1; overflow-wrap: anywhere; }
.items li.done .text { text-decoration: line-through; color: var(--muted); }
.items .x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: .9rem; opacity: .6; }
.items .x:hover { color: var(--danger); opacity: 1; }
.add-item { margin-top: 10px; }

/* tri, statut « faite » */
.list-tools { display: flex; gap: 8px; align-items: center; }
.sort-form { margin: 0; }
.sort-form select { width: auto; padding: 5px 8px; font-size: .9rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.filters .sep { width: 1px; background: var(--border); margin: 0 4px; }
.card { position: relative; }
.card-title { display: flex; align-items: flex-start; gap: 8px; }
.card-title h3 { flex: 1; }
.card-title h3 a { color: inherit; }
.card-title h3 a:hover { text-decoration: none; }
.stretched::after { content: ""; position: absolute; inset: 0; }
.todo { position: relative; z-index: 1; flex-shrink: 0; width: 22px; height: 22px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--muted); background: var(--surface); color: var(--primary-text); font-size: .75rem; line-height: 1;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.todo:hover { border-color: var(--primary); }
.todo.on { background: var(--primary); border-color: var(--primary); }
.card.done h3, .card.done p { text-decoration: line-through; color: var(--muted); }
.card.done .thumb { opacity: .5; }
.card.done { background: var(--bg); }
.is-done h1, .is-done .markdown { text-decoration: line-through; color: var(--muted); }
.done-mark { color: var(--primary); display: inline-block; }
.move-form select { width: auto; padding: 4px 8px; font-size: .85rem; }
.notify-form { margin-top: 0; }
.grow { flex: 1; }

/* notifications en direct */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px;
  max-width: min(380px, calc(100vw - 32px)); }
.toast { display: block; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,.2); transition: opacity .5s, transform .5s; font-size: .9rem; }
.toast:hover { text-decoration: none; opacity: .92; }
.toast.hide { opacity: 0; transform: translateY(8px); }

/* impersonation, jetons, archives */
.impersonation { position: sticky; top: 0; z-index: 20; display: flex; gap: 12px; align-items: center; justify-content: center;
  flex-wrap: wrap; padding: 8px 16px; background: #f59f00; color: #1d2330; font-size: .9rem; }
.impersonation form { margin: 0; }
.impersonation .btn { background: #fff; color: #1d2330; }
.token-new code.token { display: block; padding: 10px; margin: 8px 0; background: var(--surface); color: var(--text);
  border: 1px dashed var(--ok); border-radius: 8px; word-break: break-all; font-size: .95rem; cursor: copy; }
.token-form { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.token-form fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0 0 12px; padding: 8px 12px; }
.token-form legend { font-size: .85rem; color: var(--muted); padding: 0 4px; }
.token-form label.check { margin-bottom: 4px; }
.lock-panel { border-color: var(--danger); }
.card.archived { opacity: .75; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .85em; }
