:root {
  --bg-0: #1e1f22;   /* Server-Leiste */
  --bg-1: #2b2d31;   /* Kanal-Liste, Mitglieder */
  --bg-2: #313338;   /* Chat */
  --bg-3: #383a40;   /* Eingabe, Hover */
  --bg-4: #404249;   /* aktiv */
  --bg-modal: #313338;
  --text: #dbdee1;
  --text-strong: #f2f3f5;
  --muted: #949ba4;
  --faint: #6d6f78;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --danger: #da373c;
  --success: #23a55a;
  --warn: #f0b232;
  --radius: 8px;
  --font: "Segoe UI", "Noto Sans", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg-2); color: var(--text); font: 15px/1.4 var(--font); }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, textarea, select { font: inherit; color: var(--text); }
a { color: #00a8fc; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #1a1b1e; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
.hidden { display: none !important; }

/* ---------- Formulare & Buttons ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: .02em; }
.input, textarea.input, select.input {
  width: 100%; background: var(--bg-0); border: 1px solid transparent; border-radius: 4px;
  padding: 10px; outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 70px; }
.btn { background: var(--accent); color: #fff; padding: 8px 16px; border-radius: 4px; font-weight: 600; font-size: 14px; transition: background .15s; }
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: #4e5058; } .btn.secondary:hover { background: #6d6f78; }
.btn.danger { background: var(--danger); } .btn.danger:hover { background: #a12828; }
.btn.success { background: var(--success); } .btn.success:hover { background: #1a7f45; }
.btn.ghost { background: transparent; color: var(--text); } .btn.ghost:hover { text-decoration: underline; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.error-text { color: #fa777c; font-size: 13px; min-height: 18px; }
.color-input { width: 44px; height: 36px; padding: 0; border: 0; background: none; cursor: pointer; }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 20% 20%, #4752c4 0, transparent 40%), radial-gradient(circle at 80% 80%, #eb459e55 0, transparent 40%), var(--bg-0); }
.auth-card { width: 100%; max-width: 440px; background: var(--bg-2); border-radius: var(--radius); padding: 32px; box-shadow: 0 8px 32px #0008; }
.auth-card h1 { margin: 0 0 4px; text-align: center; color: var(--text-strong); font-size: 24px; }
.auth-card p.sub { margin: 0 0 20px; text-align: center; color: var(--muted); }
.auth-card .btn { width: 100%; padding: 11px; font-size: 15px; }
.auth-switch { margin-top: 12px; font-size: 14px; color: var(--muted); }
.auth-switch button { color: #00a8fc; padding: 0; }
.auth-switch button:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 72px 240px 1fr 240px; height: 100vh; height: 100dvh; overflow: hidden; }
.app.no-members { grid-template-columns: 72px 240px 1fr; }

/* Server-Leiste */
.rail { background: var(--bg-0); display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 0; overflow-y: auto; }
.rail-sep { width: 32px; height: 2px; background: var(--bg-3); border-radius: 1px; flex-shrink: 0; }
.rail-item { position: relative; flex-shrink: 0; }
.rail-btn { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--bg-2);
  color: var(--text-strong); font-weight: 600; font-size: 15px; transition: border-radius .15s, background .15s; overflow: hidden; }
.rail-btn:hover, .rail-item.active .rail-btn { border-radius: 16px; }
.rail-btn.green { color: var(--success); font-size: 24px; } .rail-btn.green:hover { background: var(--success); color: #fff; }
.rail-btn.red { color: #f23f43; font-size: 20px; } .rail-btn.red:hover { background: var(--danger); color: #fff; }
.rail-btn.home:hover, .rail-item.active .rail-btn.home { background: var(--accent); }
.rail-pill { position: absolute; left: -12px; top: 50%; width: 8px; height: 0; border-radius: 0 4px 4px 0; background: #fff;
  transform: translateY(-50%); transition: height .15s; }
.rail-item:hover .rail-pill { height: 20px; }
.rail-item.unread .rail-pill { height: 8px; }
.rail-item.active .rail-pill { height: 40px; }
.tooltip { position: fixed; background: #111214; color: var(--text-strong); padding: 6px 10px; border-radius: 6px; font-size: 14px; font-weight: 600;
  pointer-events: none; z-index: 1000; white-space: nowrap; box-shadow: 0 4px 12px #0006; }

/* Seitenleiste (Kanäle) */
.sidebar { background: var(--bg-1); display: flex; flex-direction: column; min-width: 0; }
.sidebar-header { height: 48px; padding: 0 16px; display: flex; align-items: center; font-weight: 700; color: var(--text-strong);
  border-bottom: 1px solid #1f2023; box-shadow: 0 1px 2px #0003; cursor: pointer; flex-shrink: 0; }
.sidebar-header:hover { background: var(--bg-3); }
.sidebar-header .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-list { flex: 1; overflow-y: auto; padding: 12px 8px; }
.cat-title { display: flex; align-items: center; padding: 6px 8px 4px; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.cat-title button { color: var(--muted); font-size: 18px; line-height: 1; padding: 0 2px; } .cat-title button:hover { color: var(--text-strong); }
.channel { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 4px; color: var(--muted); cursor: pointer; margin-bottom: 2px; }
.channel:hover { background: var(--bg-3); color: var(--text); }
.channel.active { background: var(--bg-4); color: var(--text-strong); }
.channel.unread { color: var(--text-strong); font-weight: 600; }
.channel .hash { font-size: 20px; line-height: 1; width: 20px; text-align: center; color: var(--faint); }
.channel .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel .gear { opacity: 0; font-size: 14px; color: var(--muted); } .channel:hover .gear { opacity: 1; }
.channel .gear:hover { color: var(--text-strong); }
.home-nav { padding: 8px; }
.user-panel { height: 52px; background: #232428; display: flex; align-items: center; gap: 8px; padding: 0 8px; flex-shrink: 0; }
.user-panel .who { flex: 1; min-width: 0; cursor: pointer; border-radius: 4px; padding: 2px 4px; }
.user-panel .who:hover { background: var(--bg-3); }
.user-panel .n { font-weight: 600; font-size: 14px; color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-panel .u { font-size: 12px; color: var(--muted); }
.icon-btn { width: 32px; height: 32px; border-radius: 4px; display: grid; place-items: center; color: var(--muted); font-size: 16px; }
.icon-btn:hover { background: var(--bg-3); color: var(--text-strong); }

/* Avatare */
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700;
  flex-shrink: 0; position: relative; user-select: none; }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; }
.avatar.lg { width: 80px; height: 80px; font-size: 32px; }
.avatar .status { position: absolute; right: -2px; bottom: -2px; width: 14px; height: 14px; border-radius: 50%;
  border: 3px solid var(--bg-1); background: #80848e; }
.avatar.lg .status { width: 24px; height: 24px; border-width: 5px; border-color: var(--bg-0); right: 0; bottom: 0; }
.avatar .status.on { background: var(--success); }

/* Chat */
.main { display: flex; flex-direction: column; min-width: 0; background: var(--bg-2); }
.chat-header { height: 48px; padding: 0 16px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid #1f2023;
  box-shadow: 0 1px 2px #0003; flex-shrink: 0; }
.chat-header .hash { font-size: 24px; color: var(--faint); }
.chat-header .cname { font-weight: 700; color: var(--text-strong); }
.chat-header .topic { color: var(--muted); font-size: 14px; border-left: 1px solid var(--bg-4); padding-left: 10px; margin-left: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.messages { flex: 1; overflow-y: auto; padding: 16px 0 8px; }
.msg { display: flex; gap: 16px; padding: 2px 48px 2px 16px; position: relative; }
.msg.first { margin-top: 16px; }
.msg:hover { background: #2e3035; }
.msg .gutter { width: 40px; flex-shrink: 0; }
.msg .gutter .time-sm { display: none; font-size: 11px; color: var(--faint); text-align: right; padding-top: 3px; }
.msg:hover .gutter .time-sm { display: block; }
.msg .body { min-width: 0; flex: 1; }
.msg .meta { display: flex; align-items: baseline; gap: 8px; }
.msg .author { font-weight: 600; color: var(--text-strong); cursor: pointer; }
.msg .author:hover { text-decoration: underline; }
.msg .time { font-size: 12px; color: var(--faint); }
.msg .content { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; color: var(--text); }
.msg .content code { background: var(--bg-0); padding: 1px 4px; border-radius: 3px; font-size: 13px; font-family: Consolas, monospace; }
.msg .content pre { background: var(--bg-0); border: 1px solid #1a1b1e; padding: 8px; border-radius: 4px; white-space: pre-wrap; margin: 4px 0; font-family: Consolas, monospace; font-size: 13px; }
.msg .edited { font-size: 11px; color: var(--faint); margin-left: 4px; }
.msg .actions { position: absolute; right: 16px; top: -14px; background: var(--bg-2); border: 1px solid #1f2023; border-radius: 6px;
  display: none; box-shadow: 0 2px 6px #0004; }
.msg:hover .actions { display: flex; }
.msg .actions button { padding: 4px 8px; color: var(--muted); font-size: 14px; } .msg .actions button:hover { color: var(--text-strong); background: var(--bg-3); }
.msg .actions button.del:hover { color: #f23f43; }
.msg .edit-box textarea { width: 100%; background: var(--bg-3); border: 0; border-radius: 6px; padding: 8px; outline: none; resize: none; }
.msg .edit-hint { font-size: 12px; color: var(--muted); }
.tag-admin { font-size: 12px; cursor: help; }
.day-sep { display: flex; align-items: center; margin: 20px 16px 4px; color: var(--faint); font-size: 12px; font-weight: 600; }
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--bg-4); }
.day-sep span { padding: 0 8px; }
.welcome { padding: 16px; }
.welcome .big-hash { width: 68px; height: 68px; border-radius: 50%; background: var(--bg-4); display: grid; place-items: center; font-size: 40px; color: var(--text-strong); }
.welcome h2 { color: var(--text-strong); margin: 8px 0 4px; font-size: 28px; }
.composer { padding: 0 16px 4px; flex-shrink: 0; }
.composer-box { background: var(--bg-3); border-radius: var(--radius); display: flex; align-items: flex-end; }
.composer textarea { flex: 1; background: transparent; border: 0; outline: none; resize: none; padding: 11px 16px; max-height: 200px; line-height: 1.375; }
.composer textarea:disabled { cursor: not-allowed; }
.typing { height: 22px; font-size: 13px; color: var(--muted); padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.typing b { color: var(--text); }
.empty-state { flex: 1; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted); }
.empty-state h2 { color: var(--text-strong); }
.home-cards { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }
.home-card { background: var(--bg-1); border-radius: var(--radius); padding: 20px; width: 220px; cursor: pointer; transition: transform .15s, background .15s; }
.home-card:hover { background: var(--bg-3); transform: translateY(-2px); }
.home-card .ic { font-size: 32px; } .home-card h3 { margin: 8px 0 4px; color: var(--text-strong); }

/* Mitgliederliste */
.members { background: var(--bg-1); overflow-y: auto; padding: 16px 8px; }
.member-group { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--muted); padding: 16px 8px 4px; }
.member-group:first-child { padding-top: 0; }
.member { display: flex; align-items: center; gap: 12px; padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.member:hover { background: var(--bg-3); }
.member.offline { opacity: .4; } .member.offline:hover { opacity: 1; }
.member .mn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }

/* Modals */
.modal-backdrop { position: fixed; inset: 0; background: #000b; display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .12s; }
@keyframes fade { from { opacity: 0 } }
.modal { background: var(--bg-modal); border-radius: var(--radius); width: 100%; max-width: 480px; max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: 0 8px 32px #0009; animation: pop .15s; }
@keyframes pop { from { transform: scale(.95) } }
.modal.wide { max-width: 920px; height: 86vh; }
.modal-head { padding: 16px 16px 8px; display: flex; align-items: center; }
.modal-head h2 { margin: 0; font-size: 20px; color: var(--text-strong); flex: 1; }
.modal-body { padding: 8px 16px 16px; overflow-y: auto; }
.modal-foot { padding: 16px; background: var(--bg-1); border-radius: 0 0 var(--radius) var(--radius); display: flex; justify-content: flex-end; gap: 8px; }
.settings { display: grid; grid-template-columns: 200px 1fr; height: 100%; min-height: 0; }
.settings-nav { background: var(--bg-1); padding: 16px 8px; overflow-y: auto; border-radius: var(--radius) 0 0 var(--radius); }
.settings-nav .label { padding: 6px 10px; display: block; }
.settings-nav button { display: block; width: 100%; text-align: left; padding: 6px 10px; border-radius: 4px; color: var(--muted); margin-bottom: 2px; }
.settings-nav button:hover { background: var(--bg-3); color: var(--text); }
.settings-nav button.active { background: var(--bg-4); color: var(--text-strong); }
.settings-nav button.danger-link { color: #f23f43; }
.settings-content { padding: 20px 24px; overflow-y: auto; position: relative; }
.settings-content h3 { margin: 0 0 16px; color: var(--text-strong); }
.close-x { position: absolute; top: 12px; right: 14px; font-size: 22px; color: var(--muted); z-index: 2; }
.close-x:hover { color: var(--text-strong); }

/* Rollen-Editor */
.role-editor { display: grid; grid-template-columns: 200px 1fr; gap: 20px; }
.role-list { display: flex; flex-direction: column; gap: 2px; }
.role-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 4px; cursor: pointer; color: var(--text); }
.role-item:hover { background: var(--bg-3); }
.role-item.active { background: var(--bg-4); }
.role-item .dot, .role-chip .dot { width: 12px; height: 12px; border-radius: 50%; background: #99aab5; flex-shrink: 0; }
.role-item .lock { margin-left: auto; font-size: 12px; opacity: .6; }
.perm-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--bg-4); }
.perm-row .txt { flex: 1; } .perm-row .t { color: var(--text-strong); font-weight: 600; } .perm-row .d { color: var(--muted); font-size: 13px; }
.switch { position: relative; width: 40px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #80848e; border-radius: 12px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::before { transform: translateX(16px); }
.switch input:disabled + span { opacity: .4; cursor: not-allowed; }
.tri { display: flex; border-radius: 4px; overflow: hidden; border: 1px solid var(--bg-4); flex-shrink: 0; }
.tri button { width: 34px; height: 28px; color: var(--muted); font-weight: 700; }
.tri button:hover { background: var(--bg-3); }
.tri button.on.deny { background: var(--danger); color: #fff; }
.tri button.on.neutral { background: #4e5058; color: #fff; }
.tri button.on.allow { background: var(--success); color: #fff; }
.role-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.role-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--bg-0); border-radius: 4px; padding: 2px 6px; font-size: 12px; }
.role-chip button { color: var(--muted); font-size: 12px; padding: 0 0 0 2px; } .role-chip button:hover { color: #f23f43; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-bottom: 1px solid var(--bg-4); }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .t { color: var(--text-strong); font-weight: 600; }
.list-row .s { color: var(--muted); font-size: 13px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--bg-1); border-radius: var(--radius); padding: 16px; }
.stat .v { font-size: 28px; font-weight: 700; color: var(--text-strong); }
.stat .k { color: var(--muted); font-size: 13px; }

/* Dropdown */
.dropdown { position: fixed; background: #111214; border-radius: 6px; padding: 6px; min-width: 200px; z-index: 200; box-shadow: 0 8px 24px #0008; }
.dropdown button { display: flex; width: 100%; padding: 8px; border-radius: 3px; font-size: 14px; color: var(--text); justify-content: space-between; }
.dropdown button:hover { background: var(--accent); color: #fff; }
.dropdown button.danger { color: #f23f43; } .dropdown button.danger:hover { background: var(--danger); color: #fff; }
.dropdown hr { border: 0; border-top: 1px solid var(--bg-4); margin: 4px; }

/* Profil */
.profile-card { width: 340px; background: var(--bg-0); border-radius: var(--radius); overflow: hidden; box-shadow: 0 8px 24px #000a; }
.profile-card .banner { height: 60px; }
.profile-card .top { padding: 0 16px; margin-top: -40px; display: flex; align-items: flex-end; justify-content: space-between; }
.profile-card .badges { display: flex; flex-wrap: wrap; gap: 4px; background: var(--bg-1); border-radius: 8px; padding: 4px 6px; margin-bottom: 4px; max-width: 220px; justify-content: flex-end; }
.badge { width: 26px; height: 26px; display: grid; place-items: center; font-size: 17px; border-radius: 6px; cursor: help; position: relative; }
.badge:hover { background: var(--bg-3); }
.profile-card .inner { margin: 12px; background: var(--bg-1); border-radius: 8px; padding: 12px; }
.profile-card .dn { font-size: 20px; font-weight: 700; color: var(--text-strong); }
.profile-card .un { color: var(--text); font-size: 14px; }
.profile-card .sec { border-top: 1px solid var(--bg-4); margin-top: 12px; padding-top: 10px; }
.profile-card .sec .label { margin-bottom: 6px; display: block; }
.badge-list { display: flex; flex-direction: column; gap: 6px; }
.badge-line { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.badge-line .bi { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; font-size: 15px; }
.badge-pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 12px; font-size: 12px; border: 1px solid var(--bg-4); background: var(--bg-1); cursor: pointer; user-select: none; }
.badge-pill.on { border-color: var(--accent); background: #5865f233; color: var(--text-strong); }

/* Toasts */
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #111214; color: var(--text-strong); padding: 10px 16px; border-radius: 6px; box-shadow: 0 4px 16px #0008; animation: pop .15s; max-width: 90vw; }
.toast.err { border-left: 4px solid var(--danger); }
.toast.ok { border-left: 4px solid var(--success); }

/* Mobil */
.mobile-toggle { display: none; }
@media (max-width: 900px) {
  .app, .app.no-members { grid-template-columns: 72px 1fr; }
  .members { display: none; }
  .sidebar { position: fixed; left: 72px; top: 0; bottom: 0; width: 240px; z-index: 50; transform: translateX(-120%); transition: transform .2s; }
  .app.show-sidebar .sidebar { transform: none; box-shadow: 8px 0 24px #0008; }
  .app.show-members .members { display: block; position: fixed; right: 0; top: 0; bottom: 0; width: 240px; z-index: 50; box-shadow: -8px 0 24px #0008; }
  .mobile-toggle { display: grid; }
  .settings { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .settings-nav { display: flex; overflow-x: auto; padding: 8px; border-radius: var(--radius) var(--radius) 0 0; }
  .settings-nav .label { display: none; }
  .settings-nav button { white-space: nowrap; width: auto; }
  .role-editor { grid-template-columns: 1fr; }
  .msg { padding-right: 16px; }
}
@media (max-width: 500px) {
  .app, .app.no-members { grid-template-columns: 60px 1fr; }
  .rail-btn { width: 42px; height: 42px; }
  .sidebar { left: 60px; }
  .msg { gap: 10px; }
  .profile-card { width: calc(100vw - 32px); }
}
