/* =========================================================
   Variabelen. Thema's in themes/ overschrijven alleen deze.
   ========================================================= */
:root {
    color-scheme: light;
    --bg: #f4f5f7;
    --fg: #1c1e21;
    --muted: #6b6f76;
    --surface: #ffffff;
    --surface-2: #eceef2;
    --border: #d8dbe0;
    --accent: #3b6cf6;
    --accent-fg: #ffffff;
    --danger: #d64545;
    --mention: #e8870e;
    --link: #2f5bd8;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* =========================================================
   Basis
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.45;
}

a { color: var(--link); }
img { max-width: 100%; }
h2 { margin: 0 0 12px; font-size: 1.4rem; }
h3 { margin: 0; }

main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px;
}

/* Losse terug-links onderaan of bovenaan een pagina */
body > a {
    display: inline-block;
    margin: 12px 16px;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.empty { color: var(--muted); }

/* =========================================================
   Formulieren en knoppen
   ========================================================= */
input, textarea, select, button { font: inherit; color: inherit; }

input[type=text],
input[type=password],
textarea,
select {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
}

textarea {
    width: 100%;
    min-height: 90px;
    resize: vertical;
}

input[type=color] {
    width: 44px;
    height: 34px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
}

button,
input[type=submit] {
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
}

button:hover,
input[type=submit]:hover { filter: brightness(0.94); }

button:disabled { opacity: 0.6; cursor: not-allowed; }

/* Hoofdknoppen */
.chat-form > button[type=submit],
input[type=submit],
main > form > button[type=submit] {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-fg);
    font-weight: 600;
}

main > form:not(.chat-form) {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 520px;
}
main > form:not(.chat-form) br { display: none; }
main > form:not(.chat-form) > button[type=submit] { align-self: flex-start; }

/* =========================================================
   Navbar
   ========================================================= */
.navbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.navbar form { margin: 0; display: flex; }

.navbar a,
.navbar button {
    padding: 6px 14px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: none;
    color: var(--fg);
    font-weight: 500;
    text-decoration: none;
}

.navbar a:hover,
.navbar button:hover {
    background: var(--surface-2);
    filter: none;
}

.navbar a.active {
    background: var(--accent);
    color: var(--accent-fg);
}

.badge {
    display: inline-block;
    min-width: 1.3em;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 0.75em;
    font-weight: 700;
    line-height: 1.5;
    text-align: center;
}
.badge[hidden] { display: none; }
.badge.mention { background: var(--mention); }

/* =========================================================
   Posts
   ========================================================= */
.posts {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
    gap: 16px;
    align-items: start;
}

.post {
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.post-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 10px 12px;
}

.post-author {
    color: var(--fg);
    font-weight: 600;
    text-decoration: none;
}

.post-edited,
.post-time {
    color: var(--muted);
    font-size: 0.8em;
}
.post-time { margin-left: auto; white-space: nowrap; }

.post-image {
    display: block;
    background: var(--surface-2);
}
.post-image img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 460px;
    object-fit: cover;
}

.post-caption {
    margin: 0;
    padding: 10px 12px;
    overflow-wrap: anywhere;
}

.post-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    font-size: 0.9em;
}
.post-actions form { margin: 0; }
.post-actions button {
    padding: 0;
    border: none;
    background: none;
    color: var(--danger);
}

.profile + .posts { margin-top: 16px; }

.post img {
    width: 350px;
    height: 350px;
}

/* =========================================================
   Profiel
   ========================================================= */
.profile {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.profile img {
    display: block;
    width: clamp(72px, 20vw, 140px);
    height: clamp(72px, 20vw, 140px);
    border-radius: 50%;
    object-fit: cover;
}

.profile h2 { margin: 0; }
.profile > div:nth-child(2) { min-width: 0; }
.profile > div:nth-child(2) span { color: var(--muted); }

.profile > a {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--fg);
    text-decoration: none;
    white-space: nowrap;
}
.profile > div + div + a { margin-left: auto; }

/* =========================================================
   Ledenlijst
   ========================================================= */
.friends {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
    gap: 10px;
}

.member {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.member-link {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.member img {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 50%;
    object-fit: cover;
}

.member-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.member-user,
.member-status {
    overflow: hidden;
    color: var(--muted);
    font-size: 0.85em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.member > a:not(.member-link) {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--fg);
    text-decoration: none;
    white-space: nowrap;
}

/* =========================================================
   Instellingen
   ========================================================= */
.settings {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 640px;
    margin: 0 auto;
    padding: 16px;
}

.settings > div {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.settings > div input[type=text],
.settings > div input[type=password],
.settings > div select { flex: 1 1 220px; }

.settings > div > label:first-child { min-width: 140px; }

.settings section {
    display: flex;
    align-items: center;
    gap: 16px;
}

.settings img {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    object-fit: cover;
}

.settings textarea {
    min-height: 180px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9rem;
}

.settings input[type=submit] { align-self: flex-start; }

.swatch {
    display: inline-block;
    padding: 2px 8px;
    border: 1px solid #888;
    border-radius: 4px;
}
.swatch-light { background: #ffffff; }
.swatch-dark { background: #14161a; }

.css-preview {
    width: 100%;
    height: 400px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

/* =========================================================
   Chat: indeling
   ========================================================= */
body.chat-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.chat-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
}

.chat {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    max-width: none;
    margin: 0;
    padding: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.chat-title { margin: 0; font-size: 1.1rem; }

.rooms-toggle {
    display: none;
    padding: 4px 10px;
    font-size: 1.2rem;
    line-height: 1;
}
.rooms-backdrop { display: none; }

/* Zijbalk */
.chat-sidebar {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    gap: 2px;
    width: 230px;
    padding: 12px;
    overflow-y: auto;
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.chat-sidebar h3 {
    margin: 14px 8px 4px;
    color: var(--muted);
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
.chat-sidebar h3:first-child { margin-top: 0; }

.chat-sidebar a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    color: var(--fg);
    text-decoration: none;
}
.chat-sidebar a:hover { background: var(--surface-2); }
.chat-sidebar a.active {
    background: var(--surface-2);
    font-weight: 600;
}

.chat-sidebar select { width: 100%; margin-top: 8px; }

/* =========================================================
   Chat: berichten
   ========================================================= */
.messages {
    flex: 1;
    min-height: 0;
    padding: 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.message {
    display: flex;
    gap: 10px;
    margin-bottom: 4px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}
.message:hover { background: var(--surface-2); }

.message > img {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 50%;
    object-fit: cover;
}
.message > div { flex: 1; min-width: 0; }

.message-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
}
.message-head a {
    color: var(--fg);
    font-weight: 600;
    text-decoration: none;
}
.message-head time,
.message-edited {
    color: var(--muted);
    font-size: 0.75em;
}

.message p {
    margin: 2px 0 0;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.message-deleted { font-style: italic; opacity: 0.5; }

.message-image {
    display: block;
    max-width: min(100%, 400px);
    max-height: 300px;
    margin-top: 4px;
    border-radius: var(--radius-sm);
}

.message-actions {
    display: flex;
    gap: 2px;
    margin-left: auto;
    opacity: 0;
}
.message:hover .message-actions,
.message:focus-within .message-actions { opacity: 1; }
@media (hover: none) {
    .message-actions { opacity: 0.7; }
}
.message-actions button {
    padding: 0 3px;
    border: none;
    background: none;
}

.message-reply {
    margin: 2px 0;
    padding-left: 8px;
    overflow: hidden;
    border-left: 3px solid var(--border);
    color: var(--muted);
    font-size: 0.85em;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}
.message-reply.gone { font-style: italic; cursor: default; }

.message-edit { display: flex; gap: 6px; margin-top: 2px; }
.message-edit input { flex: 1; min-width: 0; }

.message.mentioned {
    padding-left: 6px;
    background: color-mix(in srgb, var(--mention) 12%, transparent);
    border-left: 3px solid var(--mention);
}
.mention {
    padding: 0 3px;
    border-radius: 4px;
    background: color-mix(in srgb, var(--accent) 22%, transparent);
    font-weight: 600;
}

.message.flash { animation: flash 1.5s; }
@keyframes flash {
    from { background: color-mix(in srgb, var(--mention) 40%, transparent); }
    to   { background: transparent; }
}

.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}
.reaction {
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font-size: 0.85em;
    line-height: 1.7;
}
.reaction.mine {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 18%, var(--surface));
    font-weight: 600;
}

/* =========================================================
   Chat: invoer
   ========================================================= */
.reply-bar {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 12px;
    background: var(--surface-2);
    border-top: 1px solid var(--border);
    font-size: 0.85em;
}
.reply-bar[hidden] { display: none; }
.reply-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reply-bar button { padding: 0 4px; border: none; background: none; }

.chat-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.chat-form input[type=text] { flex: 1; min-width: 0; }

.attach {
    font-size: 1.3em;
    cursor: pointer;
}

.attachment {
    display: flex;
    align-items: center;
    gap: 4px;
    max-width: 30%;
    font-size: 0.85em;
}
.attachment[hidden] { display: none; }
.attachment span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.attachment button { padding: 0 4px; border: none; background: none; }

.emoji-btn {
    padding: 0 4px;
    border: none;
    background: none;
    font-size: 1.3em;
}

.emoji-picker {
    position: fixed;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    max-width: calc(100vw - 16px);
    padding: 6px;
    background: var(--surface);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.emoji-picker[hidden] { display: none; }
.emoji-picker button {
    padding: 2px;
    border: none;
    background: none;
    font-size: 1.3em;
}

/* =========================================================
   Smalle schermen
   ========================================================= */
@media (max-width: 700px) {
    main { padding: 12px; }

    .navbar { justify-content: space-between; gap: 4px; padding: 6px 8px; }
    .navbar a,
    .navbar button { padding: 6px 10px; font-size: 0.95rem; }

    .rooms-toggle { display: inline-flex; }

    /* Zijbalk wordt een lade die over de pagina schuift */
    .chat-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 40;
        width: min(80vw, 300px);
        padding-top: 16px;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.25);
    }
    .chat-layout.menu-open .chat-sidebar { transform: none; }

    .chat-layout.menu-open .rooms-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 35;
        background: rgba(0, 0, 0, 0.45);
    }

    .messages { padding: 8px; }
    .message > img { width: 36px; height: 36px; }

    .profile > div + div + a { margin-left: 0; }
    .settings > div > label:first-child { min-width: 100%; }
}

/* Terugbalk */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar-title { margin: 0; font-size: 1.1rem; }

.back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--fg);
    font-size: 1.2rem;
    line-height: 1;
    text-decoration: none;
}
.back-btn:hover { filter: brightness(0.94); }

/* Dashboard */
.dashboard-title { margin-bottom: 16px; }

.dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr));
    gap: 12px;
}
.dashboard form { display: flex; margin: 0; }
.dashboard form .tile { flex: 1; }

.tile {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 120px;
    padding: 16px;
    background: var(--surface);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}
.tile:hover { background: var(--surface-2); filter: none; }
.tile-icon { font-size: 2rem; line-height: 1; }
.tile-label { font-weight: 600; }
.tile-desc { color: var(--muted); font-size: 0.85em; }
.tile .badge { position: absolute; top: 8px; right: 8px; }

.load-more {
    display: flex;
    justify-content: center;
    padding: 20px 0;
}