:root {
  --bg: #f7f7fb; --fg: #1c1b29; --muted: #6b6a80; --card: #fff; --line: #e3e2ee;
  --accent: #6d28d9; --accent-fg: #fff; --danger: #dc2626; --ok: #16a34a;
}
:root[data-theme="dark"] { color-scheme: dark; --bg: #14131c; --fg: #ececf5; --muted: #9b9ab3; --card: #1e1d2b; --line: #2e2d42; --accent: #8b5cf6; }
:root[data-theme="light"] { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) { --bg: #14131c; --fg: #ececf5; --muted: #9b9ab3; --card: #1e1d2b; --line: #2e2d42; --accent: #8b5cf6; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.5 system-ui, sans-serif; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.top { display: flex; flex-wrap: wrap; gap: .3rem 1rem; align-items: center; justify-content: space-between; padding: .6rem 1.2rem;
  background: var(--card); border-bottom: 1px solid var(--line); }
.top nav { display: flex; flex-wrap: wrap; gap: .3rem 1rem; align-items: center; }
.brand { font-weight: 700; text-decoration: none; font-size: 1.15rem; }
.inline { display: inline; margin: 0; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
.wrap { max-width: 64rem; margin: 2rem auto; padding: 0 1rem; }
.wrap.narrow { max-width: 26rem; }
.hero { text-align: center; padding: 3rem 0; }
.hero h1 { font-size: 2.4rem; margin: 0 0 .5rem; }
.btn { display: inline-block; background: var(--accent); color: var(--accent-fg); border: 1px solid var(--accent);
  padding: .55rem 1.1rem; border-radius: 8px; cursor: pointer; font: inherit; text-decoration: none; }
.btn.small { padding: .25rem .65rem; font-size: .85rem; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.publish { background: var(--ok); border-color: var(--ok); }
.btn:disabled { opacity: .45; cursor: default; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem; }
.card { display: flex; flex-direction: column; gap: .2rem; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 1rem; text-decoration: none; color: inherit; transition: transform .1s; }
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card p { margin: .3rem 0; overflow-wrap: anywhere; }
.search { display: flex; gap: .5rem; margin-bottom: .5rem; }
.search input { flex: 1; }
.pager { display: flex; gap: 1rem; justify-content: center; margin: 2rem 0; }
input, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--fg); width: 100%; }
.form { display: flex; flex-direction: column; gap: 1rem; }
.form label, dialog label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; }
.flash { margin: 1rem auto; max-width: 64rem; padding: .7rem 1rem; border-radius: 8px; background: var(--card);
  border: 1px solid var(--line); }
.flash.error { border-color: var(--danger); color: var(--danger); }

/* IDE */
body.dash { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.ide { flex: 1; display: grid; grid-template-columns: 240px minmax(0, 1fr) minmax(0, 1fr); min-height: 0; }
.ide > * { min-height: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.files { background: var(--card); }
.files-bar { display: flex; flex-wrap: wrap; gap: .3rem; padding: .5rem; border-bottom: 1px solid var(--line); }
.tree { list-style: none; margin: 0; padding: 0; flex: 1; overflow: auto; font-size: .9rem; }
.tree li { display: flex; justify-content: space-between; align-items: center; padding: .2rem .5rem; cursor: pointer; }
.tree li:hover { background: var(--bg); }
.tree li.active { background: var(--accent); color: #fff; }
.tree li.sel .name { font-weight: 700; }
.tree .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree .acts { display: none; gap: .2rem; }
.tree li:hover .acts { display: flex; }
.tree .acts button { background: none; border: 0; cursor: pointer; color: inherit; padding: 0 .2rem; }
.quota { padding: .5rem; border-top: 1px solid var(--line); }
.quota > div { height: 5px; background: var(--accent); border-radius: 3px; width: 0; margin-bottom: .2rem; }
.danger-zone { padding: .5rem; font-size: .8rem; border-top: 1px solid var(--line); }
.danger-zone form { display: flex; flex-direction: column; gap: .4rem; margin-top: .4rem; }
.editor-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .4rem .6rem; background: var(--card);
  border-bottom: 1px solid var(--line); font-size: .85rem; }
.spacer { flex: 1; }
.editor { position: relative; }
#cm-host { flex: 1; min-height: 0; }
#cm-host .CodeMirror { height: 100%; font: 14px/1.5 ui-monospace, Consolas, monospace; }
.media-note { padding: 2rem; color: var(--muted); }
.preview iframe { flex: 1; border: 0; background: #fff; width: 100%; }
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--fg);
  width: min(28rem, 92vw); }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog form { display: flex; flex-direction: column; gap: .8rem; }
dialog h3 { margin: 0; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; }
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--ok); color: #fff;
  padding: .6rem 1rem; border-radius: 8px; z-index: 10; max-width: 90vw; }
.toast.bad { background: var(--danger); }
@media (max-width: 900px) {
  body.dash { height: auto; overflow: auto; }
  .ide { grid-template-columns: minmax(0, 1fr); }
  .ide > * { height: 50vh; }
}

/* Aide débutants */
.snippets-wrap { display: flex; align-items: center; gap: .5rem; padding: .3rem .6rem; background: var(--bg);
  border-bottom: 1px solid var(--line); font-size: .8rem; }
.snippets { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; flex: 1; }
.snippets[hidden] { display: none; }
.snippets-wrap .help-toggle { margin-left: auto; white-space: nowrap; display: flex; align-items: center; gap: .3rem; cursor: pointer; }
.help-toggle input { width: auto; }
.chip { background: var(--card); color: var(--fg); border: 1px solid var(--line); border-radius: 999px;
  padding: .1rem .6rem; cursor: pointer; font: inherit; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.help-tip { position: fixed; z-index: 100; max-width: 22rem; background: #1f1b3a; color: #f1efff; padding: .6rem .8rem;
  border-radius: 8px; font-size: .85rem; box-shadow: 0 6px 24px #0006; pointer-events: none; }
.help-tip strong { display: block; color: #c4b5fd; font-family: ui-monospace, Consolas, monospace; margin-bottom: .2rem; }
.help-tip code { display: block; margin-top: .4rem; padding: .3rem .5rem; background: #0006; border-radius: 4px;
  font-size: .8rem; white-space: pre-wrap; }
.CodeMirror-hints { z-index: 50; max-width: 36rem; font-size: .85rem; }
.CodeMirror-hint span { color: #666; }
.CodeMirror-hint-active span { color: #ddd; }

/* Annuaire : cartes avec miniature, auteur, mots-clés */
.cards { grid-template-columns: 1fr; }
@media (min-width: 560px) { .cards { grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); } }
.card { padding: 0; overflow: hidden; }
.card-link { display: flex; flex-direction: column; gap: .3rem; color: inherit; text-decoration: none; padding-bottom: .5rem; }
.thumb { aspect-ratio: 16 / 10; background: linear-gradient(135deg, var(--accent), #c084fc); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.thumb-ph { display: grid; place-items: center; height: 100%; font-size: 3rem; font-weight: 700; color: #fff8; }
.card-link > strong, .card-link > .by, .card-link > p { padding: 0 1rem; }
.card-link > strong { margin-top: .4rem; overflow-wrap: anywhere; }
.by { display: flex; align-items: center; gap: .3rem; color: var(--muted); font-size: .85rem; }
.by svg { fill: currentColor; flex: none; }
.tags { display: flex; flex-wrap: wrap; gap: .3rem; padding: 0 1rem 1rem; }
.tag { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: .05rem .6rem; font-size: .8rem;
  color: var(--accent); text-decoration: none; }
.tag:hover, .tag.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.count { margin-top: 0; }
/* Sur mobile, ni « Connexion » ni « Créer mon site » */
@media (max-width: 700px) { .auth-link { display: none; } }

/* Page Bibliothèques */
.lib { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0 1rem 1rem; margin: 1rem 0; }
.lib pre { background: #1f1b3a; color: #f1efff; padding: .8rem 1rem; border-radius: 8px; overflow-x: auto; font-size: .85rem; }

/* Documentation des bibliothèques (/libs/doc/) */
.doc-layout { display: block; }
.doc-nav { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .6rem 1rem; margin-bottom: 1rem; font-size: .92rem; }
.doc-nav ul { list-style: none; margin: .3rem 0; padding-left: 0; }
.doc-nav ul ul { padding-left: 1rem; }
.doc-nav a.on { font-weight: 700; }
.doc-body { min-width: 0; }
.doc-body pre { background: #1f1b3a; color: #f1efff; padding: .8rem 1rem; border-radius: 8px; overflow-x: auto; font-size: .85rem; }
.doc-body code { font-size: .9em; }
.doc-body table { border-collapse: collapse; display: block; overflow-x: auto; }
.doc-body th, .doc-body td { border: 1px solid var(--line); padding: .3rem .6rem; text-align: left; }
.doc-body blockquote { margin: 1rem 0; padding: .1rem 1rem; border-left: 4px solid var(--line); background: var(--card); border-radius: 0 8px 8px 0; }
@media (min-width: 900px) {
  .doc-layout { display: grid; grid-template-columns: 250px 1fr; gap: 1.5rem; align-items: start; }
  .doc-nav { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; margin-bottom: 0; }
}

/* Sélecteur de sites du tableau de bord */
.sitebar { display: flex; align-items: center; gap: .5rem; padding: .4rem .6rem; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.sitebar-label { font-weight: 600; font-size: .85rem; }
.site-tabs { display: flex; gap: .3rem; overflow-x: auto; flex: 1; min-width: 0; padding: 2px; }
.site-tab { display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; background: var(--bg, #fff); color: var(--fg); border: 1px solid var(--line); border-radius: 999px; padding: .25rem .75rem; cursor: pointer; font: inherit; font-size: .88rem; }
.site-tab:hover { border-color: var(--accent); }
.site-tab[aria-selected="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; font-weight: 600; }
.site-tab .st { font-size: .72rem; padding: 0 .45rem; border-radius: 999px; border: 1px solid var(--line); }
.site-tab .st.pub { color: #15803d; border-color: #15803d; }
.site-tab .st.dev { color: #b45309; border-color: #b45309; }
@media (max-width: 700px) {
  .sitebar { gap: .4rem; }
  .sitebar-label { flex: 1 1 100%; }
  .site-tabs { order: 1; flex: 1 1 100%; }
  .sitebar .btn { order: 2; }
}

/* Code ouvert */
.tag.code { border-color: var(--accent); color: var(--accent); font-family: ui-monospace, Consolas, monospace; }
.check { display: flex; gap: .5rem; align-items: flex-start; margin: .6rem 0; font-size: .92rem; }
.check input { margin-top: .25rem; }
.code-head { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between; margin: .5rem 0 1rem; }
.code-head h1 { margin: 0; font-size: 1.4rem; overflow-wrap: anywhere; }
.copy-form { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.copy-form input[type=text] { min-width: 0; flex: 1 1 10rem; }
.code-layout { display: block; }
.code-files { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .5rem; margin-bottom: 1rem; max-height: 40vh; overflow: auto; font-size: .9rem; }
.code-files ul { list-style: none; margin: 0; padding: 0; }
.code-files a { display: block; padding: .15rem .4rem; border-radius: 6px; overflow-wrap: anywhere; }
.code-files a.on { background: var(--accent); color: #fff; text-decoration: none; }
.code-view { min-width: 0; }
.code-view pre { background: #1f1b3a; color: #f1efff; padding: .8rem 1rem; border-radius: 8px; overflow: auto; font-size: .85rem; max-height: 75vh; margin: 0; tab-size: 2; }
.code-view img { max-width: 100%; height: auto; background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0 / 16px 16px; border-radius: 6px; }
@media (min-width: 900px) {
  .code-layout { display: grid; grid-template-columns: 260px 1fr; gap: 1.5rem; align-items: start; }
  .code-files { margin-bottom: 0; max-height: 75vh; }
}

/* Statistiques de visites */
dialog.wide { width: min(46rem, calc(100vw - 2rem)); }
.stats-legend { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; }
.stats-legend button { display: inline-flex; align-items: center; gap: .4rem; background: var(--card); color: var(--fg); border: 1px solid var(--line); border-radius: 999px; padding: .2rem .7rem; font: inherit; font-size: .85rem; cursor: pointer; }
.stats-legend button[aria-pressed="false"] { opacity: .45; text-decoration: line-through; }
.stats-legend .sw { width: .8rem; height: .8rem; border-radius: 50%; display: inline-block; }
.stats-chart svg { width: 100%; height: auto; display: block; }
.stats-chart .grid { stroke: var(--line); stroke-width: 1; }
.stats-chart .axis { fill: var(--muted, #666); font-size: 11px; }
.stats-chart .ln { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.stats-chart .pt { stroke: var(--bg, #fff); stroke-width: 1.5; }
.stats-table table { border-collapse: collapse; width: 100%; font-size: .85rem; }
.stats-table th, .stats-table td { border: 1px solid var(--line); padding: .2rem .5rem; text-align: right; }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }

/* Administration */
.admin-user { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem; margin: 1rem 0; }
.admin-user > header { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; }
.admin-user form { margin: 0; }
.quota { display: flex; align-items: center; gap: .6rem; margin: .5rem 0; }
.quota .bar { flex: 0 1 14rem; width: 14rem; height: .6rem; background: var(--line); border-radius: 999px; overflow: hidden; }
.quota .bar span { display: block; height: 100%; background: var(--accent); }
.quota .bar.full span { background: var(--danger); }
.admin-sites { width: 100%; border-collapse: collapse; font-size: .9rem; }
.admin-sites th, .admin-sites td { text-align: left; padding: .3rem .4rem; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.admin-sites th { color: var(--muted); font-weight: 600; border-top: 0; }
@media (max-width: 560px) { .admin-sites th:nth-child(3), .admin-sites td:nth-child(3), .admin-sites th:nth-child(4), .admin-sites td:nth-child(4) { display: none; } }
.admin-sites { table-layout: fixed; }
.admin-sites th:nth-child(1) { width: 34%; }
.admin-sites th:nth-child(3), .admin-sites th:nth-child(4) { width: 5.5rem; }
.admin-sites th:nth-child(5) { width: 6.5rem; }

/* Médiathèque */
.assets-filter { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 1rem 0; }
.assets-filter .chips { display: flex; flex-wrap: wrap; gap: .4rem; flex: 1 1 100%; }
.assets-filter input[type=search] { flex: 1 1 12rem; min-width: 0; width: auto; }
.assets-filter select, .assets-site select { width: auto; }
.chip.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
a.chip { text-decoration: none; display: inline-block; }
.assets-site { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 0 0 1rem; }
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); gap: 1rem; margin: 1rem 0; }
.asset { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .7rem; display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.asset h3 { margin: .2rem 0 0; font-size: 1rem; }
.asset p { margin: 0; font-size: .8rem; overflow-wrap: anywhere; }
.asset .thumb { display: flex; align-items: center; justify-content: center; background: var(--bg); border-radius: 8px; aspect-ratio: 16 / 10; overflow: hidden; }
.asset .thumb img { width: 100%; height: 100%; object-fit: cover; }
.asset.icons .thumb { background: #fff; }
.asset.icons .thumb img { width: 3.5rem; height: 3.5rem; object-fit: contain; }
.asset .thumb audio { width: 100%; }
.asset .row { margin-top: auto; padding-top: .4rem; }
.asset form { margin: 0; }
.asset.images .thumb { aspect-ratio: auto; height: 14rem; }
.asset.images .thumb img { object-fit: contain; }

/* À propos */
.about { max-width: 46rem; }
.about .lead { font-size: 1.1rem; }
.about section { margin: 2rem 0; scroll-margin-top: 1rem; }
.about h2 { margin-bottom: .5rem; }
.about-nav { display: flex; flex-wrap: wrap; gap: .4rem; margin: 1rem 0; }
.about-nav a { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: .2rem .8rem; text-decoration: none; font-size: .9rem; }
.about ul, .about ol { padding-left: 1.3rem; }
.about li { margin: .5rem 0; }
.about code { overflow-wrap: anywhere; }
.rules { counter-reset: r; list-style: none; padding-left: 0 !important; }
.rules li { counter-increment: r; position: relative; padding: .6rem .8rem .6rem 3rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.rules li::before { content: counter(r); position: absolute; left: .8rem; top: .55rem; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
