:root {
    --bg: #2f3136;
    --bg2: #36393f;
    --bg3: #202225;
    --bg-msg-hover: rgba(255, 255, 255, 0.02);
    --surface: #40444b;
    --text: #dcddde;
    --text-hi: #ffffff;
    --muted: #96989d;
    --accent: #5865f2;
    --accent-hover: #4752c4;
    --red: #ed4245;
    --red-hover: #c03539;
    --green: #3ba55d;
    --yellow: #faa81a;
    --border: rgba(255, 255, 255, 0.06);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

* { box-sizing: border-box; }

/* Generische Utility-Klasse — mit !important, damit sie immer gegen display:flex/grid/etc gewinnt */
.hidden { display: none !important; }

html, body {
    margin: 0;
    height: 100%;
    font-family: "gg sans", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg2);
    color: var(--text);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ── Header ─────────────────────────────── */

header.top {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    background: var(--bg3);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.brand {
    font-weight: 700;
    color: var(--text-hi);
    font-size: 16px;
}

.channel {
    color: var(--muted);
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.channel .sep { margin: 0 6px; opacity: .5; }
.channel #voiceName { color: var(--text); }

.status {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--muted);
    flex-shrink: 0;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--red);
    transition: background .15s;
}
.dot.on { background: var(--green); box-shadow: 0 0 6px rgba(59, 165, 93, 0.5); }
.dot.warn { background: var(--yellow); }

/* ── Main Layout ────────────────────────── */

main {
    flex: 1;
    display: grid;
    grid-template-columns: 320px 1fr;
    overflow: hidden;
    min-height: 0;
}

@media (max-width: 700px) {
    main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
    section.members { max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
}

/* ── Member-List ────────────────────────── */

section.members {
    border-right: 1px solid var(--border);
    padding: 14px;
    overflow-y: auto;
    background: var(--bg);
}

section.members h2 {
    margin: 0 0 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 600;
}

.channel-actions:empty { display: none; }
.channel-actions h2 { margin-bottom: 8px; }
.channel-actions { margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }

.channel-actions-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ch-action {
    display: flex;
    flex-direction: column;
}

.ch-action-btn {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: var(--surface);
    color: var(--text-hi);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    transition: background .15s;
    position: relative;
}
.ch-action-btn::after {
    content: "›";
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%) rotate(90deg);
    font-size: 14px;
    opacity: .5;
    transition: transform .2s;
}
.ch-action-btn:hover { background: var(--accent); }
.ch-action.open .ch-action-btn {
    background: var(--accent);
    border-radius: 6px 6px 0 0;
}
.ch-action.open .ch-action-btn::after {
    transform: translateY(-50%) rotate(-90deg);
    opacity: 1;
}

.ch-action-panel-wrap {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows .22s ease-out;
}
.ch-action.open .ch-action-panel-wrap {
    grid-template-rows: 1fr;
}

.ch-action-panel {
    overflow: hidden;
    min-height: 0;
}
.ch-action.open .ch-action-panel {
    padding: 10px;
    background: var(--bg3);
    border-radius: 0 0 6px 6px;
    border-top: 1px solid rgba(0, 0, 0, 0.2);
    display: flex;
    gap: 6px;
    align-items: center;
    animation: panelFade .25s ease-out;
}

@keyframes panelFade {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.ch-panel-label {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
    flex-shrink: 0;
}

.ch-action-input {
    flex: 1;
    min-width: 0;
    padding: 7px 10px;
    border-radius: 5px;
    border: 1px solid transparent;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    text-align: center;
    transition: border-color .15s;
}
.ch-action-input:focus {
    outline: none;
    border-color: var(--accent);
}
.ch-action-input.shake {
    animation: shake .35s;
    border-color: var(--red);
}
@keyframes shake {
    10%, 90% { transform: translateX(-1px); }
    20%, 80% { transform: translateX(2px); }
    30%, 50%, 70% { transform: translateX(-3px); }
    40%, 60% { transform: translateX(3px); }
}

.ch-panel-confirm {
    padding: 6px 14px;
    border: none;
    border-radius: 5px;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s;
}
.ch-panel-confirm:hover { background: var(--accent-hover); }

.ch-panel-cancel {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    transition: background .15s, color .15s;
}
.ch-panel-cancel:hover { background: var(--surface); color: var(--text); }

#memberList {
    list-style: none;
    margin: 0;
    padding: 0;
}

.member {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    grid-template-rows: auto auto;
    gap: 6px 10px;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 8px;
    background: var(--bg2);
    align-items: center;
    transition: outline-color .1s;
    outline: 2px solid transparent;
}
.member.speaking { outline-color: var(--green); }

.member .avatar {
    grid-row: 1 / span 2;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--surface);
    background-size: cover;
    background-position: center;
}

.member .info { min-width: 0; }
.member .name {
    font-weight: 600;
    color: var(--text-hi);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}
.member .uid {
    font-size: 11px;
    color: var(--muted);
    cursor: pointer;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    transition: color .15s;
    user-select: all;
}
.member .uid:hover { color: var(--text); }
.member .uid.copied { color: var(--green); }
.member .uid.copied::after { content: " ✓ kopiert"; }

.member .flags {
    display: flex;
    gap: 4px;
    font-size: 14px;
    flex-shrink: 0;
}
.flag { opacity: .7; }

.member .actions {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding-top: 4px;
}
.act {
    font-size: 11px;
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-hi);
    cursor: pointer;
    font-weight: 500;
    transition: background .15s;
    font-family: inherit;
}
.act:hover { background: var(--red); }
.act:active { transform: translateY(1px); }

.empty {
    color: var(--muted);
    font-size: 13px;
    padding: 12px;
    text-align: center;
}

/* ── Chat ──────────────────────────────── */

section.chat {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg2);
}

.chat-log {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px 4px;
}

.msg-wrapper { margin-bottom: 2px; }
.msg-wrapper.has-reply { margin-top: 8px; }

.msg-reply {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px 0 62px;
    margin: 0 -8px 2px;
    font-size: 12px;
    color: var(--muted);
    position: relative;
    cursor: default;
    min-height: 18px;
}
.msg-reply::before {
    content: "";
    position: absolute;
    left: 27px;
    top: 10px;
    bottom: 0;
    width: 22px;
    height: 12px;
    border-left: 2px solid var(--border);
    border-top: 2px solid var(--border);
    border-top-left-radius: 6px;
}
.reply-avatar {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--surface);
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
}
.reply-author {
    color: var(--text-hi);
    font-weight: 500;
    flex-shrink: 0;
}
.reply-author.bot::after {
    content: "BOT";
    font-size: 9px;
    background: var(--accent);
    color: #fff;
    padding: 0 3px;
    border-radius: 2px;
    margin-left: 4px;
    font-weight: 500;
    letter-spacing: 0.03em;
    vertical-align: middle;
}
.reply-content {
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    transition: color .1s;
}
.msg-reply:hover .reply-content { color: var(--text); }
.reply-content .inline-emoji { width: 1em; height: 1em; vertical-align: -0.15em; }
.reply-content.muted { font-style: italic; }

.msg {
    display: flex;
    gap: 12px;
    padding: 4px 8px;
    margin: 0 -8px;
    border-radius: 4px;
}
.msg:hover { background: var(--bg-msg-hover); }

.msg-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background-color: var(--surface);
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.msg-body { flex: 1; min-width: 0; }

.msg-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}

.msg-author {
    font-weight: 600;
    color: var(--text-hi);
    font-size: 15px;
}
.msg.bot .msg-author::after {
    content: "BOT";
    font-size: 10px;
    background: var(--accent);
    color: #fff;
    padding: 1px 4px;
    border-radius: 3px;
    margin-left: 6px;
    font-weight: 500;
    letter-spacing: 0.03em;
    vertical-align: middle;
}

.msg-ts { font-size: 11px; color: var(--muted); }

.msg-content {
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.4;
    color: var(--text);
}

.inline-emoji {
    width: 1.375em;
    height: 1.375em;
    vertical-align: -0.25em;
    object-fit: contain;
    margin: 0 1px;
}

.mention {
    display: inline-block;
    padding: 0 3px;
    border-radius: 3px;
    color: #c9cdfb;
    background: rgba(88, 101, 242, 0.2);
    font-weight: 500;
    cursor: default;
    transition: background .1s, color .1s;
}
.mention:hover {
    background: var(--accent);
    color: #fff;
}
.mention-role { color: #c9cdfb; }
.mention-channel { color: #c9cdfb; }

.msg-attach {
    display: inline-block;
    font-size: 13px;
    color: var(--accent);
    text-decoration: none;
    margin-top: 4px;
    padding: 4px 8px;
    background: var(--bg3);
    border-radius: 4px;
}
.msg-attach:hover { text-decoration: underline; }

/* ── Chat-Input ────────────────────────── */

.chat-input {
    padding: 10px 16px 14px;
    display: flex;
    gap: 8px;
    background: var(--bg2);
    flex-shrink: 0;
}

.chat-input input {
    flex: 1;
    padding: 11px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color .15s;
}
.chat-input input:focus {
    outline: none;
    border-color: var(--accent);
}
.chat-input input:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.chat-input button {
    padding: 11px 20px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    transition: background .15s;
}
.chat-input button:hover:not(:disabled) { background: var(--accent-hover); }
.chat-input button:disabled {
    background: var(--surface);
    color: var(--muted);
    cursor: not-allowed;
}

/* ── Emoji-Button + Picker ───────────────── */

.chat-input .emoji-btn {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 8px;
    background: var(--bg);
    color: var(--muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, color .15s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 0;
    font-weight: normal;
}
.chat-input .emoji-btn svg { width: 22px; height: 22px; fill: currentColor; display: block; }
.chat-input .emoji-btn:hover { background: var(--surface); color: var(--text); }

.emoji-picker {
    position: absolute;
    bottom: 72px;
    right: 16px;
    width: 340px;
    max-width: calc(100vw - 32px);
    max-height: 400px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow: hidden;
    animation: pickerIn .15s ease-out;
}
.emoji-picker.hidden { display: none; }

@keyframes pickerIn {
    from { opacity: 0; transform: translateY(4px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.emoji-picker-head {
    padding: 10px;
    border-bottom: 1px solid var(--border);
}
.emoji-picker-head input {
    width: 100%;
    padding: 7px 10px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: var(--bg3);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
}
.emoji-picker-head input:focus {
    outline: none;
    border-color: var(--accent);
}

.emoji-grid {
    flex: 1;
    overflow-y: auto;
    padding: 0 10px 10px;
}

.emoji-group-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 4px 6px;
    margin: 0 -4px;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 2;
    box-shadow: 0 1px 0 var(--border);
}
.emoji-group-head::before {
    /* deckt 10px über der Sticky-Position ab, damit keine Emojis durchschimmern */
    content: "";
    position: absolute;
    left: -10px;
    right: -10px;
    top: -10px;
    height: 10px;
    background: var(--bg);
}
.emoji-guild-icon {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
}

.emoji-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, 36px);
    gap: 2px;
}

.emoji-item {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .1s, transform .1s;
    padding: 4px;
}
.emoji-item:hover { background: var(--surface); transform: scale(1.1); }
.emoji-item img { width: 100%; height: 100%; object-fit: contain; }

.emoji-empty {
    padding: 20px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}
.emoji-empty.hidden { display: none; }

/* ── Key-Entry-Form (Error-Screen) ──────── */

.key-entry-form {
    display: flex;
    gap: 8px;
    margin-top: 20px;
}
.key-entry-form input {
    flex: 1;
    padding: 11px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: var(--bg3);
    color: var(--text);
    font-size: 14px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.key-entry-form input:focus {
    outline: none;
    border-color: var(--accent);
}
.key-entry-form button {
    padding: 11px 18px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    transition: background .15s;
}
.key-entry-form button:hover { background: var(--accent-hover); }

.key-entry-error {
    margin-top: 10px;
    color: var(--red);
    font-size: 13px;
    min-height: 16px;
}

section.chat { position: relative; }

/* ── Error-Screen ──────────────────────── */

.error-screen {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}
.error-screen.hidden { display: none; }

.error-box {
    background: var(--bg2);
    padding: 40px 48px;
    border-radius: 10px;
    text-align: center;
    max-width: 440px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.error-box h1 {
    margin: 0 0 12px;
    color: var(--red);
    font-size: 22px;
}
.error-box p {
    color: var(--muted);
    margin: 0;
    line-height: 1.5;
}

/* ── Scrollbars ────────────────────────── */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--surface); }
