:root {
    --bg: #ffffff; --bg2: #f6f7f9; --tekst: #1f2328; --zacht: #656d76; --rand: #d8dee4;
    --accent: #2563eb; --accent-t: #ffffff; --gevaar: #c62828; --hover: #eaeef2; --actief: #dbeafe;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171a; --bg2: #1b1f24; --tekst: #e6edf3; --zacht: #8b949e; --rand: #30363d;
        --accent: #4c8dff; --accent-t: #0b0d10; --gevaar: #ff6b6b; --hover: #262c33; --actief: #1e3a5f;
    }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--tekst);
       font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbalk */
.topbalk { height: 52px; display: flex; align-items: center; gap: 16px; padding: 0 16px;
           border-bottom: 1px solid var(--rand); background: var(--bg2); position: sticky; top: 0; z-index: 50; }
.merk { font-weight: 700; color: var(--tekst); font-size: 1.1rem; }
.topnav { margin-left: auto; display: flex; gap: 14px; align-items: center; font-size: .9rem; }
.gebruiker { color: var(--zacht); }
.ikoon { display: none; background: none; border: 0; color: var(--tekst); font-size: 1.3rem; cursor: pointer; }

/* Zoeken */
.zoekveld { position: relative; flex: 0 1 380px; }
.zoekveld input { width: 100%; padding: 6px 12px; border: 1px solid var(--rand); border-radius: 6px;
                  background: var(--bg); color: var(--tekst); }
#zoek-uit { position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px; background: var(--bg);
            border: 1px solid var(--rand); border-radius: 6px; max-height: 60vh; overflow: auto;
            box-shadow: 0 8px 24px rgba(0,0,0,.15); }
#zoek-uit a { display: block; padding: 8px 12px; color: var(--tekst); border-bottom: 1px solid var(--rand); }
#zoek-uit a:hover { background: var(--hover); text-decoration: none; }
#zoek-uit small { display: block; color: var(--zacht); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zoek-leeg { padding: 10px 12px; color: var(--zacht); }

/* Meldingen */
.meldingen { padding: 8px 16px; }
.melding { padding: 8px 12px; border-radius: 6px; background: var(--hover); margin-bottom: 4px; }
.melding.success { background: var(--actief); }

/* Layout */
.layout { display: flex; min-height: calc(100vh - 52px); }
#zijbalk { width: 290px; flex: none; border-right: 1px solid var(--rand); background: var(--bg2);
           padding: 12px 8px; overflow: auto; position: sticky; top: 52px; height: calc(100vh - 52px); }
.zijbalk-kop { display: flex; justify-content: space-between; align-items: center; padding: 0 8px 8px; }
.inhoud { flex: 1; min-width: 0; padding: 24px 32px 64px; max-width: 1200px; }
body:not(.met-zijbalk) .inhoud { max-width: none; padding: 0; }

/* Boom */
.boom { list-style: none; margin: 0; padding: 0; }
.boom .boom { padding-left: 16px; }
.boom li:not(.open) > .boom { display: none; }
.rij { display: flex; align-items: center; gap: 2px; border-radius: 6px; padding: 1px 4px; position: relative; }
.rij:hover { background: var(--hover); }
.rij.actief { background: var(--actief); font-weight: 600; }
.rij a { flex: 1; color: var(--tekst); padding: 3px 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rij a:hover { text-decoration: none; }
.caret, .plus { background: none; border: 0; color: var(--zacht); cursor: pointer; width: 22px; height: 22px; padding: 0; border-radius: 4px; }
.caret::before { content: "▸"; display: inline-block; transition: transform .1s; }
li.open > .rij > .caret::before { transform: rotate(90deg); }
.plus { opacity: 0; }
.rij:hover .plus { opacity: 1; }
.plus:hover, .caret:hover { background: var(--rand); }
.rij.drop-before { box-shadow: 0 -2px 0 var(--accent); }
.rij.drop-after { box-shadow: 0 2px 0 var(--accent); }
.rij.drop-inside { outline: 2px solid var(--accent); }

/* Knoppen */
.knop { display: inline-block; padding: 6px 12px; border: 1px solid var(--rand); border-radius: 6px;
        background: var(--bg); color: var(--tekst); cursor: pointer; font: inherit; font-size: .9rem; }
.knop:hover { background: var(--hover); text-decoration: none; }
.knop.primair { background: var(--accent); border-color: var(--accent); color: var(--accent-t); }
.knop.primair:hover { filter: brightness(1.1); }
.knop.gevaar { color: var(--gevaar); }
.knop.klein { padding: 2px 8px; font-size: .8rem; }

/* Pagina */
.kruimel { color: var(--zacht); font-size: .85rem; margin-bottom: 8px; }
.kruimel span { margin: 0 6px; }
.paginakop, .editorkop { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.paginakop h1 { margin: 0; font-size: 2rem; }
.acties { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.meta { color: var(--zacht); font-size: .8rem; margin: 4px 0 24px; }
.paginagrid { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 32px; }
#inhoudsopgave { position: sticky; top: 76px; align-self: start; font-size: .85rem; }
#inhoudsopgave ul { list-style: none; padding: 0; margin: 6px 0 0; }
#inhoudsopgave li { padding: 2px 0; }
#inhoudsopgave .niv2 { padding-left: 12px; }
#inhoudsopgave .niv3 { padding-left: 24px; }
.subpaginas { margin-top: 48px; border-top: 1px solid var(--rand); }
.leeg { text-align: center; padding: 80px 0; }

/* Markdown */
.markdown h1, .markdown h2, .markdown h3 { line-height: 1.25; margin: 1.6em 0 .5em; }
.markdown img { max-width: 100%; height: auto; }
.markdown pre { background: var(--bg2); padding: 12px 16px; border-radius: 6px; overflow: auto; }
.markdown code { background: var(--bg2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.markdown pre code { background: none; padding: 0; }
.markdown blockquote { margin: 1em 0; padding: 0 16px; border-left: 4px solid var(--rand); color: var(--zacht); }
.markdown table { border-collapse: collapse; margin: 1em 0; }
.markdown th, .markdown td { border: 1px solid var(--rand); padding: 6px 12px; }
.markdown th { background: var(--bg2); }

/* Editor */
#titel { flex: 1; min-width: 200px; font-size: 1.8rem; font-weight: 700; border: 0; border-bottom: 1px solid var(--rand);
         background: none; color: var(--tekst); padding: 4px 0; }
#titel:focus { outline: none; border-color: var(--accent); }
.editorkop { margin-bottom: 16px; align-items: center; }
.status { color: var(--zacht); font-size: .85rem; max-width: 320px; }
.status.fout { color: var(--gevaar); }
.EasyMDEContainer .CodeMirror { background: var(--bg); color: var(--tekst); border-color: var(--rand); }
.EasyMDEContainer .CodeMirror-cursor { border-left-color: var(--tekst); }
.editor-toolbar { background: var(--bg2); border-color: var(--rand); }
.editor-toolbar button { color: var(--tekst) !important; }
.editor-toolbar button:hover, .editor-toolbar button.active { background: var(--hover); border-color: var(--rand); }
.editor-preview, .editor-preview-side { background: var(--bg); color: var(--tekst); }
.editor-preview img, .editor-preview-side img { max-width: 100%; }

/* Diagrammen: witte achtergrond zodat zwarte lijnen ook in dark mode leesbaar blijven */
.markdown img[src^="/diagrams/"], .editor-preview img[src^="/diagrams/"],
.editor-preview-side img[src^="/diagrams/"], .cm-diagram {
    background: #fff; border-radius: 6px; padding: 8px; max-width: 100%; height: auto;
}
.cm-diagram { display: block; max-height: 480px; margin: 6px 0; cursor: pointer; border: 1px solid var(--rand); }
.cm-diagram:hover { border-color: var(--accent); }

/* Dialoog nieuwe pagina */
.nieuw-dialoog { border: 1px solid var(--rand); border-radius: 10px; background: var(--bg); color: var(--tekst);
                 padding: 20px 24px; width: min(460px, 92vw); }
.nieuw-dialoog::backdrop { background: rgba(0,0,0,.45); }
.nieuw-dialoog h2 { margin: 0 0 12px; font-size: 1.2rem; }
.nieuw-dialoog label { display: block; margin-bottom: 14px; font-size: .9rem; }
.nieuw-dialoog input[type=text] { display: block; width: 100%; margin-top: 4px; padding: 7px 10px; font: inherit;
                                  border: 1px solid var(--rand); border-radius: 6px; background: var(--bg); color: var(--tekst); }
.nieuw-dialoog input[type=file] { display: block; margin-top: 6px; max-width: 100%; }
.nieuw-dialoog .acties { justify-content: flex-end; }
.nieuw-dialoog .fout { color: var(--gevaar); margin: 0 0 10px; }

/* draw.io */
.drawio-overlay { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.5); padding: 2vh 2vw; }
.drawio-overlay iframe { width: 100%; height: 100%; border: 0; border-radius: 8px; background: #fff; }

/* Mobiel */
@media (max-width: 800px) {
    .ikoon { display: inline-block; }
    #zijbalk { position: fixed; left: 0; top: 52px; z-index: 40; transform: translateX(-100%); transition: transform .15s; }
    body.menu-open #zijbalk { transform: none; }
    .inhoud { padding: 16px; }
    .paginagrid { grid-template-columns: 1fr; }
    #inhoudsopgave { display: none; }
    .zoekveld { flex: 1; }
    .gebruiker { display: none; }
}

/* Import */
.importform { display: grid; gap: 16px; max-width: 460px; margin: 20px 0 32px; }
.importform label { display: block; font-size: .9rem; }
.importform select { display: block; width: 100%; margin-top: 4px; padding: 7px 10px; font: inherit;
                     border: 1px solid var(--rand); border-radius: 6px; background: var(--bg); color: var(--tekst); }
.importform input[type=file] { display: block; margin-top: 6px; max-width: 100%; }
.importform button { justify-self: start; }
.uitleg { color: var(--zacht); font-size: .9rem; }
