:root {
    --bg: #fafaf7;
    --fg: #1a1a1a;
    --muted: #888;
    --accent: #4a6fa5;
    --border: #e0e0dd;
    --error: #b33;
    --card: #fff;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1a1a1a;
        --fg: #eaeaea;
        --muted: #888;
        --accent: #7da2d4;
        --border: #333;
        --error: #e77;
        --card: #232323;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    color: var(--fg);
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--card);
}
.topbar .brand { font-weight: 600; text-decoration: none; color: var(--fg); }
.topbar nav { display: flex; gap: 1rem; align-items: center; }
.topbar nav a { color: var(--accent); text-decoration: none; }
.topbar .inline { display: inline; margin: 0; }
.topbar-search { flex: 1; margin: 0 1rem; max-width: 360px; }
.topbar-search input {
    width: 100%;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--bg);
    color: var(--fg);
    font: inherit;
}
.search-form { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
.search-mode {
    border: none;
    padding: 0;
    margin: 0 0 1rem 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}
.search-mode legend {
    padding: 0;
    font-size: 0.85em;
    color: var(--muted);
    margin-right: 0.5rem;
}
.search-mode .mode-option { margin: 0; }
.search-mode .mode-link {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 14px;
    border: 1px solid var(--border);
    font-size: 0.85em;
    text-decoration: none;
    color: var(--fg);
}
.search-mode .mode-link.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.search-mode .disabled .mode-link {
    color: var(--muted);
    opacity: 0.6;
    cursor: not-allowed;
}
.search-mode .small { flex-basis: 100%; font-size: 0.8em; margin: 0.5rem 0 0 0; }
.search-form input[type="search"] {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card);
    color: var(--fg);
    font: inherit;
}
.search-form button {
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
}
.search-results { list-style: none; padding: 0; }
.search-results li {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}
.search-results .snippet {
    margin-top: 0.25rem;
    color: var(--muted);
    font-size: 0.95em;
}
.search-results mark {
    background: #ffe680;
    color: inherit;
    padding: 0 0.15rem;
    border-radius: 2px;
}
@media (prefers-color-scheme: dark) {
    .search-results mark {
        background: #88651f;
        color: #fff;
    }
}
.topbar button {
    background: none;
    border: 1px solid var(--border);
    color: var(--fg);
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
}

main { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.5rem; }

h1 { margin-top: 0; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.error {
    background: #fee;
    color: var(--error);
    padding: 0.5rem 0.75rem;
    border-left: 3px solid var(--error);
    border-radius: 2px;
}

.note-list { list-style: none; padding: 0; }
.note-list li {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}
.note-list .meta {
    font-size: 0.85em;
    color: var(--muted);
    display: block;
    margin-top: 0.25rem;
}
.tag {
    display: inline-block;
    background: var(--border);
    padding: 0.1rem 0.5rem;
    border-radius: 10px;
    font-size: 0.85em;
    margin-left: 0.5rem;
    color: var(--fg);
    text-decoration: none;
}

.tag-cloud {
    list-style: none;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
}
.tag-cloud li { margin: 0; }
.tag-cloud .tag {
    margin-left: 0;
    padding: 0.3rem 0.75rem;
}
.tag-cloud .count {
    margin-left: 0.3rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.note-form label {
    display: block;
    margin-bottom: 0.75rem;
}
.note-form input[type="text"],
.note-form textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card);
    color: var(--fg);
    font: inherit;
}
.note-form textarea {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.95em;
    resize: vertical;
}
.note-form .actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 0.5rem;
}
.note-form button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
}
.note-form .cancel { color: var(--muted); text-decoration: none; }

.note header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
}
.note header .meta {
    font-size: 0.85em;
    color: var(--muted);
    margin: 0.25rem 0;
}
.note-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
    align-items: center;
}
.note-actions .danger {
    color: var(--error);
    background: none;
    border: 1px solid var(--error);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
}

.rendered pre {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 0.75rem;
    border-radius: 4px;
    overflow-x: auto;
}
.rendered code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.92em;
}
.rendered table {
    border-collapse: collapse;
}
.rendered th, .rendered td {
    border: 1px solid var(--border);
    padding: 0.25rem 0.5rem;
}
.rendered .broken-link {
    color: var(--error);
    text-decoration: line-through;
    cursor: help;
}

.backlinks {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.backlinks h2 {
    margin: 0 0 0.5rem 0;
    font-size: 0.95em;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.backlinks ul { list-style: none; padding: 0; margin: 0; }
.backlinks li { padding: 0.2rem 0; }

.history-list {
    list-style: none;
    padding: 0;
}
.history-list li {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    align-items: baseline;
}
.history-list .sha {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--muted);
    font-size: 0.9em;
}
.history-list .current-tag {
    background: var(--accent);
    color: white;
    padding: 0.1rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75em;
    margin-left: 0.5rem;
    text-transform: uppercase;
}
.history-list .date {
    font-size: 0.85em;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.sha-big {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.7em;
    color: var(--muted);
    background: var(--border);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    vertical-align: middle;
}

.restore-form {
    margin: 1rem 0;
}
.restore-form .danger {
    background: none;
    color: var(--error);
    border: 1px solid var(--error);
    padding: 0.4rem 0.9rem;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
}

pre.diff {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 0.75rem;
    border-radius: 4px;
    overflow-x: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.88em;
    line-height: 1.4;
}

/* Chat UI */
.chat-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 1.5rem;
    margin-top: 1rem;
}
.chat-sidebar {
    border-right: 1px solid var(--border);
    padding-right: 1rem;
}
.chat-sidebar h2 {
    font-size: 0.85em;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 0.5rem 0;
}
.chat-sidebar .new-chat {
    display: inline-block;
    padding: 0.3rem 0.7rem;
    background: var(--accent);
    color: white;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.9em;
}
.chat-list { list-style: none; padding: 0; margin: 1rem 0 0 0; }
.chat-list li {
    display: flex;
    align-items: stretch;
    gap: 0.3rem;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9em;
}
.chat-list li.active { background: var(--border); }
.chat-list li a { color: var(--fg); text-decoration: none; }
.chat-list-link {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}
.chat-list-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-list li .meta { font-size: 0.8em; color: var(--muted); }
.chat-list-delete { margin: 0; }
.chat-list-delete button {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0.1rem 0.4rem;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}
.chat-list li:hover .chat-list-delete button { opacity: 1; }
.chat-list-delete button:hover { color: #d04848; }

.chat-main h1 { margin-bottom: 0.2rem; }
.chat-hint {
    background: var(--card);
    border-left: 3px solid var(--accent);
    padding: 0.5rem 0.75rem;
    border-radius: 2px;
    color: var(--muted);
}

.chat-messages { margin: 1rem 0; display: flex; flex-direction: column; gap: 0.75rem; }
.msg {
    border-radius: 8px;
    padding: 0.6rem 0.85rem;
    max-width: 90%;
}
.msg header {
    font-size: 0.8em;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.3rem;
}
.msg.user {
    align-self: flex-end;
    background: var(--accent);
    color: white;
}
.msg.user header { color: rgba(255,255,255,0.8); }
.msg.assistant { background: var(--card); border: 1px solid var(--border); }
.msg.tool {
    font-size: 0.85em;
    color: var(--muted);
    align-self: flex-start;
    max-width: 100%;
}
.msg.tool pre {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 0.5rem;
    border-radius: 4px;
    overflow-x: auto;
    font-size: 0.85em;
    max-height: 300px;
}
.tool-call { margin-top: 0.4rem; font-size: 0.85em; color: var(--muted); }
.tool-call summary { cursor: pointer; }

.msg.timing {
    background: #f0f4f8;
    border: 1px dashed #b9c8d4;
    color: #2c3e50;
    font-size: 0.9em;
}
.msg.timing header { color: #4a6076; font-weight: 600; }
.msg.timing summary { cursor: pointer; padding: 0.3rem 0; }
.timing-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
    font-size: 0.85em;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.timing-table th,
.timing-table td {
    text-align: left;
    padding: 0.2rem 0.5rem;
    border-bottom: 1px solid #d5dde6;
    vertical-align: top;
}
.timing-table th { font-weight: 600; color: #4a6076; }
.timing-table td code { background: rgba(0,0,0,0.04); padding: 0 0.3rem; border-radius: 2px; }
@media (prefers-color-scheme: dark) {
    .msg.timing { background: #1e2a34; border-color: #3b4a56; color: #c5d3df; }
    .msg.timing header { color: #8fa6b9; }
    .timing-table th,
    .timing-table td { border-color: #2e3a44; }
    .timing-table th { color: #8fa6b9; }
    .timing-table td code { background: rgba(255,255,255,0.06); }
}

.msg.thinking .thinking-dots {
    display: inline-flex;
    gap: 0.3rem;
    padding: 0.2rem 0;
}
.msg.thinking .thinking-dots span {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--muted);
    animation: thinking-bounce 1.2s infinite ease-in-out;
}
.msg.thinking .thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.msg.thinking .thinking-dots span:nth-child(3) { animation-delay: 0.30s; }
@keyframes thinking-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40%           { transform: scale(1.0); opacity: 1; }
}

.msg.pending-write {
    background: #fff7e6;
    border: 1px solid #f5c36f;
    color: #533c00;
    align-self: stretch;
}
.msg.pending-write header {
    color: #7a5a00;
    font-weight: 600;
}
.msg.pending-write pre {
    background: #fffbf0;
    border: 1px solid #e8d7a1;
    padding: 0.5rem;
    border-radius: 4px;
    overflow-x: auto;
    font-size: 0.85em;
    max-height: 240px;
}
.msg.pending-write .pending-tool {
    margin: 0.3rem 0;
    font-size: 0.9em;
}
.msg.pending-write .pending-actions {
    margin-top: 0.6rem;
    display: flex;
    gap: 0.5rem;
}
.btn-accept,
.btn-decline {
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
}
.btn-accept { background: #2f8a3d; color: white; border-color: #266c30; }
.btn-accept:hover { background: #266c30; }
.btn-decline { background: var(--card); color: var(--fg); }
.btn-decline:hover { background: var(--border); }

.chat-input-actions {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    justify-content: flex-end;
}

.mic-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.4rem;
    height: 2.4rem;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--card);
    color: var(--fg);
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
}
.mic-btn:hover { background: var(--border); }
.mic-btn.recording {
    background: #d04848;
    color: white;
    border-color: #a33737;
    animation: mic-pulse 1.4s infinite;
}
.mic-btn.uploading {
    background: var(--accent);
    color: white;
    cursor: wait;
    opacity: 0.8;
}
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(208, 72, 72, 0.5); }
    50%       { box-shadow: 0 0 0 8px rgba(208, 72, 72, 0); }
}

.chat-mirror { margin: 0.5rem 0 1rem 0; }
.btn-mirror {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card);
    color: var(--fg);
    cursor: pointer;
    font-size: 0.9em;
}
.btn-mirror:hover { background: var(--border); }

/* EasyMDE — basis-integratie met project-theme */
.EasyMDEContainer .CodeMirror {
    min-height: 320px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.95em;
}
.editor-toolbar { border-radius: 4px 4px 0 0; }
.EasyMDEContainer .CodeMirror { border-radius: 0 0 4px 4px; }
.editor-toolbar button {
    color: var(--fg);
    opacity: 0.8;
}
.editor-toolbar button:hover,
.editor-toolbar button.active {
    opacity: 1;
}

@media (prefers-color-scheme: dark) {
    .editor-toolbar {
        background: var(--card);
        border-color: var(--border);
    }
    .editor-toolbar button {
        color: var(--fg) !important;
    }
    .editor-toolbar button:hover,
    .editor-toolbar button.active {
        background: var(--border) !important;
        border-color: var(--border) !important;
    }
    .editor-toolbar i.separator { border-color: var(--border); }
    .EasyMDEContainer .CodeMirror {
        background: var(--card);
        color: var(--fg);
        border-color: var(--border);
    }
    .EasyMDEContainer .CodeMirror-cursor { border-color: var(--fg); }
    .EasyMDEContainer .CodeMirror-selected { background: #3a3a3a; }
    .editor-preview, .editor-preview-side {
        background: var(--card);
        color: var(--fg);
    }
    .editor-statusbar { color: var(--muted); }
}

.chat-input {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}
.chat-input textarea {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card);
    color: var(--fg);
    font: inherit;
    resize: vertical;
}
.chat-input button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
    align-self: flex-end;
}

/* Login screen */
body.auth {
    display: grid;
    place-items: center;
    min-height: 100vh;
}
.login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2rem;
    min-width: 300px;
    text-align: center;
}
.login-card h1 { margin-top: 0; }
.login-card form { text-align: left; }
.login-card label { display: block; margin-bottom: 0.75rem; }
.login-card input[type="password"] {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--fg);
    font: inherit;
}
.login-card button {
    width: 100%;
    padding: 0.6rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
    font-weight: 500;
}
