:root {
  color-scheme: dark;
  --bg: #111111;
  --panel: #1b1b1b;
  --panel-2: #222222;
  --panel-3: #2a2a2a;
  --line: #333333;
  --line-soft: #2a2a2a;
  --text: #ececec;
  --text-soft: #c5c5c5;
  --muted: #9a9a9a;
  --accent: #f0c040;
  --accent-strong: #ffd45e;
  --accent-contrast: #171717;
  --accent-soft: rgba(240, 192, 64, 0.14);
  --accent-soft-strong: rgba(240, 192, 64, 0.32);
  --accent-outline: rgba(240, 192, 64, 0.45);
  --danger: #e5534b;
  --danger-soft: rgba(229, 83, 75, 0.12);
  --danger-outline: rgba(229, 83, 75, 0.45);
  --success: #4fb477;
  --warning: #d9a441;
  --destructive: #d9534f;
  --sidebar-bg: #161616;
  --rail-bg: #0d0d0d;
  --chat-bg: #141414;
  --header-bg: #161616;
  --footer-bg: #131313;
  --input-bg: #161616;
  --settings-sidebar: #171717;
  --voice-bg: #171717;
  --message-hover: rgba(255, 255, 255, 0.025);
  --quote-border: #555555;
  --quote-bg: rgba(255, 255, 255, 0.035);
  --reply-bg: #1d1a12;
  --reply-border: #3a3320;
  --rail-button: #1b1b1b;
  --rail-button-hover: #242424;
  --presence-ring: #161616;
  --mention-text: #f5d67a;
  --mention-me-text: #ffffff;
  --overlay: rgba(0, 0, 0, 0.65);
  --radius: 8px;
  --radius-lg: 12px;
  --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --panel-3: #eceef2;
  --line: #d5d9e0;
  --line-soft: #e5e8ed;
  --text: #1f2430;
  --text-soft: #4b5563;
  --muted: #667085;
  --accent: #8a6200;
  --accent-strong: #6f4f00;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(138, 98, 0, 0.12);
  --accent-soft-strong: rgba(138, 98, 0, 0.24);
  --accent-outline: rgba(138, 98, 0, 0.42);
  --danger: #c0392b;
  --danger-soft: rgba(192, 57, 43, 0.1);
  --danger-outline: rgba(192, 57, 43, 0.4);
  --success: #2f855a;
  --warning: #b7791f;
  --destructive: #c0392b;
  --sidebar-bg: #f7f8fa;
  --rail-bg: #e9ebef;
  --chat-bg: #ffffff;
  --header-bg: #ffffff;
  --footer-bg: #f3f4f6;
  --input-bg: #ffffff;
  --settings-sidebar: #f7f8fa;
  --voice-bg: #f7f8fa;
  --message-hover: rgba(15, 23, 42, 0.04);
  --quote-border: #c7ccd5;
  --quote-bg: rgba(15, 23, 42, 0.04);
  --reply-bg: #fff8e6;
  --reply-border: #e8d49a;
  --rail-button: #ffffff;
  --rail-button-hover: #eef0f4;
  --presence-ring: #ffffff;
  --mention-text: #7a5200;
  --mention-me-text: #563900;
  --overlay: rgba(16, 24, 40, 0.35);
  --shadow: 0 18px 50px rgba(31, 35, 48, 0.18);
}

:root[data-theme="forest"] {
  color-scheme: dark;
  --bg: #0c1511;
  --panel: #12211a;
  --panel-2: #182b21;
  --panel-3: #20382b;
  --line: #315040;
  --line-soft: #263d30;
  --text: #e8f1e9;
  --text-soft: #c0d1c2;
  --muted: #8fa894;
  --accent: #80d99a;
  --accent-strong: #a8ecb9;
  --accent-contrast: #07130c;
  --accent-soft: rgba(128, 217, 154, 0.14);
  --accent-soft-strong: rgba(128, 217, 154, 0.30);
  --accent-outline: rgba(128, 217, 154, 0.45);
  --danger: #e06c75;
  --danger-soft: rgba(224, 108, 117, 0.12);
  --danger-outline: rgba(224, 108, 117, 0.45);
  --success: #63d69a;
  --warning: #e4b86a;
  --destructive: #d9534f;
  --sidebar-bg: #0f1d16;
  --rail-bg: #08110c;
  --chat-bg: #0a130f;
  --header-bg: #0f1d16;
  --footer-bg: #09120d;
  --input-bg: #12231a;
  --settings-sidebar: #102018;
  --voice-bg: #102018;
  --message-hover: rgba(170, 235, 190, 0.04);
  --quote-border: #4d745b;
  --quote-bg: rgba(170, 235, 190, 0.045);
  --reply-bg: #14261b;
  --reply-border: #2f513c;
  --rail-button: #15271d;
  --rail-button-hover: #1e3628;
  --presence-ring: #0f1d16;
  --mention-text: #b9efc7;
  --mention-me-text: #061008;
  --overlay: rgba(0, 0, 0, 0.7);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.52);
}

:root[data-theme="sunset"] {
  color-scheme: dark;
  --bg: #1a1014;
  --panel: #24161c;
  --panel-2: #2d1b22;
  --panel-3: #3a242c;
  --line: #4e303a;
  --line-soft: #3a242c;
  --text: #f7eae3;
  --text-soft: #e0c6b9;
  --muted: #b28f82;
  --accent: #ff9e6d;
  --accent-strong: #ffbe95;
  --accent-contrast: #251009;
  --accent-soft: rgba(255, 158, 109, 0.14);
  --accent-soft-strong: rgba(255, 158, 109, 0.30);
  --accent-outline: rgba(255, 158, 109, 0.45);
  --danger: #e06c75;
  --danger-soft: rgba(224, 108, 117, 0.12);
  --danger-outline: rgba(224, 108, 117, 0.45);
  --success: #67d39a;
  --warning: #e8b46b;
  --destructive: #d9534f;
  --sidebar-bg: #201319;
  --rail-bg: #140b10;
  --chat-bg: #190f13;
  --header-bg: #201319;
  --footer-bg: #170d12;
  --input-bg: #26171d;
  --settings-sidebar: #21141a;
  --voice-bg: #21141a;
  --message-hover: rgba(255, 210, 180, 0.045);
  --quote-border: #7d564a;
  --quote-bg: rgba(255, 190, 150, 0.05);
  --reply-bg: #2c1b17;
  --reply-border: #59372e;
  --rail-button: #291820;
  --rail-button-hover: #38212b;
  --presence-ring: #201319;
  --mention-text: #ffd2b1;
  --mention-me-text: #2b1209;
  --overlay: rgba(10, 4, 8, 0.7);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

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

[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: 650; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.error { color: var(--danger); font-size: 0.88rem; }
.hint { color: var(--muted); font-size: 0.82rem; }

button, input, select, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 12px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
button:hover:not(:disabled) { background: var(--panel-3); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button:disabled { opacity: 0.55; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}
button.primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
button.ghost { background: transparent; border-color: var(--line); }
button.danger { color: var(--danger); border-color: var(--danger-outline); background: transparent; }
button.danger:hover:not(:disabled) { background: var(--danger-soft); }
button.small { padding: 3px 8px; font-size: 0.8rem; }

button.icon-button {
  padding: 4px 8px;
  background: transparent;
  border-color: transparent;
  font-size: 1rem;
  line-height: 1;
}
button.icon-button:hover:not(:disabled) { background: var(--panel-3); }
button.icon-button.active { color: var(--accent); }

input, select, textarea {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
textarea { resize: vertical; min-height: 44px; }
label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 2px; }

.stack { display: grid; gap: 10px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { flex: 1; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.inline-actions { display: inline-flex; gap: 6px; }
.check-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.check-row input { width: auto; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.check input { width: auto; }

.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--panel-2);
  flex: none;
}
.avatar.large { width: 80px; height: 80px; }

.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.person { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 0; }
.person-link { display: flex; align-items: center; gap: 8px; color: var(--text); min-width: 0; }
.person-link:hover { text-decoration: none; color: var(--accent); }
.person-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-actions { display: flex; gap: 6px; }

.role-chip {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.76rem;
  margin: 2px 4px 2px 0;
}

dialog.modal {
  position: relative;
  width: min(540px, 94vw);
  max-height: 88vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--text);
  padding: 22px;
  box-shadow: var(--shadow);
}
dialog.modal.wide { width: min(780px, 96vw); }
dialog.modal::backdrop { background: var(--overlay); }
dialog.modal > h2 { padding-right: 36px; margin-bottom: 12px; }
dialog.modal form.modal-close { position: absolute; top: 10px; right: 10px; margin: 0; }
dialog.modal form.modal-close button {
  border: none; background: transparent; font-size: 1.2rem; line-height: 1; padding: 4px 8px;
}

.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.profile-head h2 { margin-bottom: 2px; }

.toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  z-index: 1000;
  max-width: min(380px, 90vw);
}
.toast {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
}
.toast-error { border-left-color: var(--danger); }
.toast-success { border-left-color: var(--success); }
.toast-out { opacity: 0; transform: translateY(6px); transition: opacity 0.3s ease, transform 0.3s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
