:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1c2330;
  --muted: #6b7686;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --out: #dbe8ff;
  --in: #ffffff;
  --ok: #1f8a4c;
  --warn-bg: #fff4d6;
  --warn-text: #7a5300;
  --err-bg: #fde7e7;
  --err-text: #a12626;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
/* Donker: volgt het systeem, tenzij in Instellingen → Weergave licht of donker is gekozen
   (data-theme op <html>; geforceerd wint). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c;
    --surface: #1a2029;
    --surface-2: #222a35;
    --border: #2e3846;
    --text: #e3e8ef;
    --muted: #8e9aab;
    --accent: #5b8ff0;
    --out: #233a5e;
    --in: #1f2732;
    --ok: #4cc283;
    --warn-bg: #3a2f12;
    --warn-text: #f1cf7a;
    --err-bg: #3d1d1d;
    --err-text: #f29a9a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c;
  --surface: #1a2029;
  --surface-2: #222a35;
  --border: #2e3846;
  --text: #e3e8ef;
  --muted: #8e9aab;
  --accent: #5b8ff0;
  --out: #233a5e;
  --in: #1f2732;
  --ok: #4cc283;
  --warn-bg: #3a2f12;
  --warn-text: #f1cf7a;
  --err-bg: #3d1d1d;
  --err-text: #f29a9a;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0 0 4px; }
h3 { font-size: 15px; margin: 0 0 10px; }
h4 { font-size: 13px; margin: 16px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

button {
  font: inherit; cursor: pointer;
  background: var(--accent); color: var(--accent-text);
  border: 1px solid transparent; border-radius: 8px; padding: 7px 14px;
}
button.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
button.danger { background: var(--err-bg); color: var(--err-text); border-color: transparent; }
button.small { padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
input {
  font: inherit; width: 100%;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
input:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; margin: 10px 0; font-weight: 500; }
label input { margin-top: 4px; font-weight: 400; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.tag {
  font-size: 11px; font-weight: 600; vertical-align: middle;
  background: var(--warn-bg); color: var(--warn-text);
  border-radius: 6px; padding: 2px 6px;
}
.ok { color: var(--ok); }
.error-text { color: var(--err-text); min-height: 1.2em; }
.banner { padding: 8px 14px; border-radius: 8px; margin: 8px; }
.banner.error { background: var(--err-bg); color: var(--err-text); }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }
.banner.warn button { margin-left: 8px; }

/* inloggen */
.login { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 24px; width: 100%; max-width: 380px;
}
#known-accounts { margin-top: 12px; }
#login-form[data-mode="login"] .reg-only { display: none; }
.seg { display: flex; gap: 4px; margin: 4px 0 12px; padding: 3px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.seg button { flex: 1; background: transparent; color: var(--muted); border: 0; }
.seg button.active { background: var(--surface); color: inherit; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
#known-accounts button { margin: 4px 4px 0 0; }

/* hoofdscherm */
.app {
  display: grid; height: 100vh;
  grid-template-columns: 270px 1fr 380px;
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top top" "side chat panel";
}
.topbar {
  grid-area: top; display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.me { display: flex; gap: 10px; align-items: center; }
.status::before { content: "●"; margin-right: 4px; color: var(--muted); }
.status.online::before { color: var(--ok); }
.status.verbinden::before { color: #d9a400; }
.status.auth-fout::before, .status.offline::before { color: var(--err-text); }

.sidebar, .panel {
  background: var(--surface); overflow: auto; min-height: 0;
}
.sidebar { grid-area: side; border-right: 1px solid var(--border); padding: 12px; }
.panel { grid-area: panel; border-left: 1px solid var(--border); display: flex; flex-direction: column; }

.me-card { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.user-list { list-style: none; margin: 10px 0 0; padding: 0; }
.user-list li {
  display: flex; gap: 10px; align-items: center;
  padding: 7px 8px; border-radius: 8px; cursor: pointer;
}
.user-list li:hover { background: var(--surface-2); }
.user-list li.active { background: var(--out); }
.user-list .name { font-weight: 600; }
.user-list .badge {
  margin-left: auto; background: var(--accent); color: var(--accent-text);
  border-radius: 10px; font-size: 11px; padding: 0 7px;
}

.sidebar-actions { margin-bottom: 4px; }
.sidebar h4 { margin-top: 12px; }
.badge {
  background: var(--accent); color: var(--accent-text);
  border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 600;
}
.secondary .badge { margin-left: 2px; }
.chat-header .actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }

/* dialogen (contact toevoegen, verzoeken) */
.modal-box.dialog { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 0; }
.dialog-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface);
}
.dialog-head h3 { margin: 0; }
.dialog-body { padding: 14px 16px 18px; }
.dialog-body form.row input { flex: 1; width: auto; min-width: 160px; margin: 0; }
.person { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.person-text { flex: 1; min-width: 0; }
.person .name { font-weight: 600; }
.invite-code { font-size: 26px; font-weight: 700; letter-spacing: .08em; margin: 4px 0 6px; word-break: normal; }
.invite-link { margin-bottom: 8px; }
.ok-box { border: 1px solid var(--ok); }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  background: var(--surface-2); color: var(--muted);
  display: grid; place-items: center; font-weight: 700; overflow: hidden;
}
.avatar.big { width: 96px; height: 96px; font-size: 32px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.chat { grid-area: chat; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-header {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.messages {
  flex: 1; overflow: auto; list-style: none; margin: 0; padding: 14px;
  display: flex; flex-direction: column; gap: 6px;
}
.msg {
  max-width: 72%; padding: 7px 11px; border-radius: 12px;
  background: var(--in); border: 1px solid var(--border);
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.out { align-self: flex-end; background: var(--out); border-color: transparent; }
.msg.error { background: var(--err-bg); color: var(--err-text); border-color: transparent; }
.msg.system { align-self: center; background: transparent; border: none; color: var(--muted); font-size: 12px; }
.msg .meta { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; text-align: right; }
.send-form {
  display: flex; gap: 8px; padding: 10px; background: var(--surface); border-top: 1px solid var(--border);
}

.tabs { display: flex; border-bottom: 1px solid var(--border); overflow-x: auto; flex: none; }
.tabs button {
  background: none; color: var(--muted); border: none; border-radius: 0;
  border-bottom: 2px solid transparent; padding: 10px 12px;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.panel-body { padding: 14px; overflow: auto; flex: 1; }

.kv { display: grid; grid-template-columns: 90px 1fr; gap: 4px 10px; margin: 6px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.box {
  background: var(--surface-2); border-radius: 8px; padding: 10px; margin: 8px 0;
}
.box.bad { background: var(--err-bg); color: var(--err-text); }
pre.json { white-space: pre-wrap; word-break: break-all; margin: 0; font-family: var(--mono); font-size: 11px; }
.safety {
  display: grid; grid-template-columns: repeat(4, auto); gap: 6px 14px; justify-content: start;
  font-family: var(--mono); font-size: 16px; letter-spacing: .04em; margin: 8px 0;
}

.log { list-style: none; margin: 0; padding: 0; font-family: var(--mono); font-size: 11px; }
.log li { border-bottom: 1px solid var(--border); padding: 6px 0; }
.log .dir-in { color: var(--ok); }
.log .dir-uit { color: var(--accent); }
.log .hexdump { color: var(--muted); word-break: break-all; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: grid; place-items: center; z-index: 10; padding: 16px;
}
.modal-box { background: var(--surface); border-radius: 14px; padding: 18px; max-width: 100%; }
.cropper canvas {
  display: block; touch-action: none; cursor: grab; border-radius: 8px;
  background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 20px 20px;
}
.cropper .zoom { display: flex; gap: 10px; align-items: center; }
.cropper .zoom input { padding: 0; }
.hint { font-size: 12px; color: var(--muted); max-width: 320px; }

/* instellingen */
.settings {
  position: fixed; inset: 0; z-index: 5;
  background: rgba(0,0,0,.45);
  display: grid; place-items: center; padding: 16px;
}
.settings-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 14px;
  width: min(920px, 100%); height: min(720px, 100%);
  display: flex; flex-direction: column; overflow: hidden;
}
.settings-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.settings-head h2 { margin: 0; font-size: 17px; }
.settings-main { display: flex; flex: 1; min-height: 0; }
.settings-nav {
  flex: none; width: 190px; padding: 10px; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; overflow: auto;
}
.settings-nav button {
  text-align: left; background: transparent; color: var(--text); border: 0;
}
.settings-nav button:hover { background: var(--surface-2); }
.settings-nav button.active { background: var(--out); font-weight: 600; }
.settings-body { flex: 1; overflow: auto; padding: 18px 22px; min-width: 0; }
.settings-body > h3 { font-size: 18px; margin-bottom: 12px; }
.settings-form { max-width: 420px; }
.profile-row { gap: 16px; margin-bottom: 8px; }

/* schakelaar: label links, toggle rechts */
.switch {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 12px 0; margin: 0; border-bottom: 1px solid var(--border);
  font-weight: 500; cursor: pointer; max-width: 620px;
}
.switch.disabled { cursor: default; }
.switch-text { display: flex; flex-direction: column; gap: 2px; }
.switch-text .small { font-weight: 400; }
.switch input {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 42px; height: 24px; margin: 0; padding: 0; border: 0;
  border-radius: 12px; background: var(--border); position: relative; cursor: pointer;
  transition: background .15s;
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }
.switch input:disabled { opacity: .55; cursor: default; }

/* keuzelijst (radio) */
.choices { display: flex; flex-direction: column; gap: 6px; max-width: 620px; }
.choice {
  display: flex; gap: 10px; align-items: flex-start; margin: 0;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); font-weight: 500; cursor: pointer;
}
.choice > span { display: flex; flex-direction: column; gap: 2px; }
.choice .small { font-weight: 400; }
.choice input { width: auto; margin: 3px 0 0; accent-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); }

.danger-zone {
  margin-top: 24px; padding: 4px 16px 16px; max-width: 620px;
  border: 1px solid var(--err-text); border-radius: 10px;
}
.danger-zone h4 { color: var(--err-text); }

/* smalle schermen: alles onder elkaar */
@media (max-width: 1000px) {
  .app {
    height: auto; min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 70vh auto;
    grid-template-areas: "top" "side" "chat" "panel";
  }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: 40vh; }
  .panel { border-left: none; border-top: 1px solid var(--border); }
  .msg { max-width: 88%; }
}
@media (max-width: 700px) {
  .settings { padding: 0; }
  .settings-box { border-radius: 0; height: 100%; }
  .settings-main { flex-direction: column; }
  .settings-nav {
    width: auto; flex-direction: row; overflow-x: auto;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .settings-nav button { white-space: nowrap; }
  .settings-body { padding: 14px 16px; }
}

/* verzoek via exacte naam in de contactenlijst */
.user-list li.lookup {
  flex-direction: column; align-items: stretch; gap: 10px;
  padding: 12px; margin-bottom: 8px; cursor: default;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
}
.user-list li.lookup:hover { background: var(--surface-2); }
.lookup-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.lookup-head .avatar { width: 44px; height: 44px; font-size: 18px; background: var(--accent); color: var(--accent-text); }
.lookup-names { min-width: 0; }
.lookup-names > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lookup-status { color: var(--muted); line-height: 1.4; }
.user-list li.lookup button { width: 100%; }

/* groepen */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; }
.section-head h4 { margin: 0; }
.avatar.group { border-radius: 10px; background: var(--accent); color: var(--accent-text); }
.msg .sender { font-size: 12px; font-weight: 700; margin-bottom: 2px; }
.checklist { list-style: none; margin: 6px 0 10px; padding: 0; max-height: 260px; overflow: auto; }
.checklist li label {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; cursor: pointer;
  font-weight: 400;
}
.checklist li label:hover { background: var(--surface-2); }
.checklist input[type="checkbox"] { width: auto; margin: 0; }
.checklist .avatar { width: 30px; height: 30px; font-size: 13px; }
.member-list { list-style: none; margin: 6px 0 12px; padding: 0; }
.member-list li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.member-list .grow { flex: 1; min-width: 120px; }
.member-list .name { font-weight: 600; }
.member-list .actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* typ-indicator: "X is aan het typen" + drie puntjes */
.typing { display: inline-flex; align-items: baseline; gap: 4px; font-size: 12px; color: var(--accent); font-style: italic; }
.typing .dots { display: inline-flex; gap: 2px; }
.typing .dots i {
  width: 4px; height: 4px; border-radius: 50%; background: currentColor; display: inline-block;
  animation: typing-dot 1.2s infinite ease-in-out;
}
.typing .dots i:nth-child(2) { animation-delay: .15s; }
.typing .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes typing-dot { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { .typing .dots i { animation: none; opacity: .7; } }

/* vinkjes: ✓ server, ✓✓ grijs afgeleverd, ✓✓ blauw gelezen */
.ticks { font-weight: 700; letter-spacing: -2px; cursor: help; }
.ticks.sent, .ticks.delivered { color: var(--muted); }
.ticks.read { color: #3b9cff; }

/* log: kort bewaarde frames (typ-signalen) */
.log li.ephemeral { opacity: .75; }

/* ---------- media ---------- */
#attach-btn { padding: 0 10px; font-size: 18px; }
.chat.drop { outline: 2px dashed var(--accent); outline-offset: -6px; }
.attach-bar {
  display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px;
  border-top: 1px solid var(--border); background: var(--surface);
}
.attach-item {
  display: flex; align-items: center; gap: 8px; flex: none; max-width: 260px;
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
}
.attach-item img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }
.attach-icon { font-size: 26px; line-height: 1; }
.attach-meta { min-width: 0; }
.attach-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 170px; }

.msg.has-media { padding: 4px; }
.msg.has-media .meta { padding: 0 6px 2px; }
.media { display: flex; flex-direction: column; gap: 6px; }
.media-img { display: block; max-width: min(320px, 100%); max-height: 420px; border-radius: 8px; cursor: zoom-in; background: var(--surface-2); }
.media-img.blur { filter: blur(6px); }
.media-video { display: block; max-width: min(320px, 100%); max-height: 420px; border-radius: 8px; background: #000; }
.media-video-thumb { position: relative; max-width: min(320px, 100%); min-height: 80px; border-radius: 8px; overflow: hidden; background: #000; }
.media-video-thumb .media-img { cursor: default; opacity: .8; }
.media-play {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: #fff; font-size: 34px; text-shadow: 0 1px 6px rgba(0,0,0,.6); pointer-events: none;
}
.media-dur {
  position: absolute; left: 6px; bottom: 6px; color: #fff; font-size: 12px;
  background: rgba(0,0,0,.55); padding: 1px 6px; border-radius: 6px;
}
.media-file {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; min-width: 220px;
  border-radius: 8px; background: var(--surface-2);
}
.media-file a.button { margin-left: auto; text-decoration: none; }
a.button {
  display: inline-block; padding: 4px 10px; border-radius: 8px; font-size: 13px;
  background: var(--accent); color: var(--accent-text);
}
.media-warn { color: var(--err-text); font-size: 12px; margin-top: 2px; }
.media-caption { padding: 0 6px; white-space: pre-wrap; }
.media-progress { display: flex; align-items: center; gap: 8px; padding: 0 6px; }
.media-progress .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; min-width: 80px; }
.media-progress .bar > div { height: 100%; background: var(--accent); transition: width .2s; }
.lightbox {
  position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.88);
  display: grid; place-items: center; cursor: zoom-out;
}
.lightbox img { max-width: 96vw; max-height: 94vh; object-fit: contain; }
.lightbox-close { position: fixed; top: 12px; right: 12px; }
.log li.note { color: var(--ok); }
