/* Lythea Chat – Design-Tokens wie forum.lythea.de (aus dem Lythea-Dashboard) */
:root {
  color-scheme: dark;
  --surface-base: #09090c;
  --surface-raised: #0f0f14;
  --surface-elevated: #151519;
  --surface-overlay: #1c1c22;
  --border-subtle: rgba(255,255,255,0.05);
  --border-default: rgba(255,255,255,0.08);
  --border-emphasis: rgba(255,255,255,0.13);
  --text-primary: #ededf2;
  --text-secondary: #9898aa;
  --text-tertiary: #83839c;
  --accent: #7c6ef5;
  --accent-hover: #9585ff;
  --accent-strong: #6455e0;
  --accent-text: #9d93fa;
  --accent-muted: rgba(124,110,245,0.12);
  --accent-border: rgba(124,110,245,0.28);
  --mention-bg: rgba(245,158,11,0.09);
  --mention-bar: #f59e0b;
  --success: #22c55e;
  --warning-text: #fbbf24;
  --error: #ef4444;
  --error-text: #f87171;
  --error-muted: rgba(239,68,68,0.12);
  --role-admin: #f87171;
  --role-moderator: #4ade80;
  --code-bg: rgba(255,255,255,0.06);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w: 248px;
  --members-w: 232px;
}
[data-theme="light"] {
  color-scheme: light;
  --surface-base: #f7f7f8;
  --surface-raised: #f1f1f3;
  --surface-elevated: #ffffff;
  --surface-overlay: #ebebef;
  --border-subtle: rgba(0,0,0,0.06);
  --border-default: rgba(0,0,0,0.11);
  --border-emphasis: rgba(0,0,0,0.18);
  --text-primary: #17171c;
  --text-secondary: #62626e;
  --text-tertiary: #6b6b72;
  --accent-text: #5646cc;
  --accent-muted: rgba(124,110,245,0.10);
  --accent-border: rgba(124,110,245,0.25);
  --mention-bg: rgba(245,158,11,0.12);
  --warning-text: #b45309;
  --error-text: #b91c1c;
  --role-admin: #dc2626;
  --role-moderator: #15803d;
  --code-bg: rgba(0,0,0,0.06);
  --shadow: 0 10px 30px rgba(0,0,0,0.10);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--surface-base); color: var(--text-primary);
  font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent-text); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Grundgerüst ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr var(--members-w); height: 100dvh; overflow: hidden; }
.sidebar, .members { background: var(--surface-raised); border-right: 1px solid var(--border-subtle); display: flex; flex-direction: column; min-height: 0; }
.members { border-right: 0; border-left: 1px solid var(--border-subtle); }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.app.members-hidden { grid-template-columns: var(--sidebar-w) 1fr 0; }
.app.members-hidden .members { display: none; }

.brand { display: flex; gap: 10px; align-items: center; padding: 16px 16px 12px; }
.brand img { border-radius: 9px; }
.brand strong { display: block; font-size: 15px; }
.brand span { display: block; font-size: 12px; color: var(--text-tertiary); }

.channels { flex: 1; overflow-y: auto; padding: 6px 8px; }
.ch {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; margin: 1px 0;
  border: 0; border-radius: var(--radius-sm); background: none; text-align: left; cursor: pointer;
  color: var(--text-secondary); font-size: 14.5px; text-decoration: none;
}
.ch:hover { background: var(--surface-overlay); color: var(--text-primary); }
.ch.active { background: var(--accent-muted); color: var(--text-primary); box-shadow: inset 0 0 0 1px var(--accent-border); }
.ch.unread { color: var(--text-primary); font-weight: 600; }
.ch .ch-icon { width: 20px; text-align: center; color: var(--text-tertiary); flex: none; }
.ch .ch-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch .ch-lock { font-size: 11px; opacity: .6; }
.badge { min-width: 20px; padding: 0 6px; border-radius: 10px; font-size: 11.5px; font-weight: 700; line-height: 20px; text-align: center; background: var(--surface-overlay); color: var(--text-secondary); }
.badge.mention { background: var(--error); color: #fff; }
.sidebar-admin { padding: 4px 16px 10px; display: flex; flex-direction: column; gap: 2px; }
.link-btn { background: none; border: 0; padding: 4px 0; text-align: left; color: var(--text-tertiary); cursor: pointer; font-size: 13px; }
.link-btn:hover { color: var(--accent-text); }

.me { position: relative; display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--border-subtle); background: var(--surface-elevated); }
.me-text { flex: 1; min-width: 0; }
.me-text strong { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text span { display: block; font-size: 12px; color: var(--text-tertiary); }
.menu {
  position: absolute; bottom: calc(100% + 6px); left: 10px; right: 10px; z-index: 30;
  background: var(--surface-elevated); border: 1px solid var(--border-default); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column;
}
.menu a, .menu button { padding: 8px 10px; border-radius: 7px; text-decoration: none; color: var(--text-primary); background: none; border: 0; text-align: left; cursor: pointer; font-size: 14px; }
.menu a:hover, .menu button:hover { background: var(--surface-overlay); }
.menu .danger { color: var(--error-text); }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none; object-fit: cover; display: inline-grid; place-items: center;
  background: hsl(var(--hue, 250) 45% 42%); color: #fff; font-weight: 700; font-size: 15px; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }
.avatar.lg { width: 64px; height: 64px; font-size: 26px; }

.icon-btn {
  border: 0; background: none; cursor: pointer; color: var(--text-secondary); border-radius: 8px;
  min-width: 34px; height: 34px; padding: 0 8px; font-size: 17px; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
.icon-btn:hover { background: var(--surface-overlay); color: var(--text-primary); }
.icon-btn.small { min-width: 26px; height: 26px; font-size: 13px; }
#btnMembers { font-size: 14px; }

/* ---------- Kopfzeile ---------- */
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; min-height: 58px; border-bottom: 1px solid var(--border-subtle); background: var(--surface-base); }
.topbar-title { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 16px; font-weight: 700; }
.topbar p { margin: 0; font-size: 12.5px; color: var(--text-tertiary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.banner { padding: 7px 16px; font-size: 13px; background: var(--error-muted); color: var(--error-text); border-bottom: 1px solid var(--border-subtle); }
.banner.info { background: var(--accent-muted); color: var(--accent-text); }

/* ---------- Nachrichten ---------- */
.messages { flex: 1; overflow-y: auto; padding: 8px 0 12px; overscroll-behavior: contain; }
.history-hint { text-align: center; font-size: 12.5px; color: var(--text-tertiary); padding: 14px; }
.welcome { padding: 24px 20px 8px; text-align: left; }
.welcome .welcome-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-overlay); font-size: 26px; margin-bottom: 10px; }
.welcome h2 { margin: 0 0 4px; font-size: 22px; }
.welcome p { margin: 0; color: var(--text-secondary); }

.day { display: flex; align-items: center; gap: 12px; margin: 16px 16px 6px; font-size: 12px; font-weight: 600; color: var(--text-tertiary); }
.day::before, .day::after { content: ''; flex: 1; height: 1px; background: var(--border-default); }
.new-divider { display: flex; align-items: center; gap: 8px; margin: 6px 16px; font-size: 11.5px; font-weight: 700; color: var(--error-text); text-transform: uppercase; letter-spacing: .04em; }
.new-divider::before { content: ''; flex: 1; height: 1px; background: var(--error); opacity: .6; }

.msg { position: relative; display: grid; grid-template-columns: 40px 1fr; gap: 0 12px; padding: 3px 16px 3px 16px; }
.msg.first { margin-top: 10px; }
.msg:hover { background: var(--surface-raised); }
.msg.mentioned { background: var(--mention-bg); box-shadow: inset 3px 0 0 var(--mention-bar); }
.msg.pending { opacity: .55; }
.msg.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--accent-muted); } to { background: transparent; } }
.msg .avatar { margin-top: 2px; cursor: pointer; }
.msg .gutter { font-size: 10.5px; color: var(--text-tertiary); text-align: right; padding-top: 4px; opacity: 0; user-select: none; }
.msg:hover .gutter { opacity: 1; }
.msg-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.author { font-weight: 650; cursor: pointer; background: none; border: 0; padding: 0; font-size: 15px; }
.author:hover { text-decoration: underline; }
.role-admin { color: var(--role-admin); }
.role-moderator { color: var(--role-moderator); }
.tag { font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; text-transform: uppercase; letter-spacing: .03em; background: var(--accent-muted); color: var(--accent-text); }
.time { font-size: 11.5px; color: var(--text-tertiary); }
.edited { font-size: 11px; color: var(--text-tertiary); }
.body { overflow-wrap: anywhere; white-space: pre-wrap; }
.body.deleted { font-style: italic; color: var(--text-tertiary); }
.body.emoji-only { font-size: 34px; line-height: 1.2; }
.body code { font-family: var(--mono); font-size: 13px; background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.body pre { font-family: var(--mono); font-size: 13px; background: var(--code-bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; margin: 4px 0; white-space: pre; }
.body blockquote { margin: 2px 0; padding-left: 10px; border-left: 3px solid var(--border-emphasis); color: var(--text-secondary); }
.body .mention { background: var(--accent-muted); color: var(--accent-text); padding: 0 3px; border-radius: 4px; font-weight: 600; }
.body .mention.me { background: rgba(245,158,11,0.18); color: var(--warning-text); }
.body .spoiler { background: var(--text-primary); color: transparent; border-radius: 4px; cursor: pointer; transition: .15s; }
.body .spoiler.open { background: var(--code-bg); color: inherit; }
.reply-ref { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--text-tertiary); margin-bottom: 2px; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; grid-column: 2; }
.reply-ref::before { content: '↱'; }
.reply-ref b { color: var(--text-secondary); }
.img-wrap { margin-top: 6px; max-width: min(420px, 100%); }
.img-wrap img { display: block; max-width: 100%; max-height: 360px; width: auto; height: auto; border-radius: 10px; cursor: zoom-in; background: var(--surface-overlay); }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.reaction { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 12px; border: 1px solid var(--border-default); background: var(--surface-raised); cursor: pointer; font-size: 13px; }
.reaction.mine { border-color: var(--accent-border); background: var(--accent-muted); color: var(--accent-text); }
.reaction:hover { border-color: var(--border-emphasis); }

.actions { position: absolute; right: 14px; top: -14px; display: none; gap: 2px; padding: 2px; background: var(--surface-elevated); border: 1px solid var(--border-default); border-radius: 9px; box-shadow: var(--shadow); z-index: 5; }
.msg:hover .actions, .msg.menu-open .actions { display: flex; }
.actions button { border: 0; background: none; cursor: pointer; border-radius: 6px; width: 30px; height: 28px; font-size: 15px; }
.actions button:hover { background: var(--surface-overlay); }
.actions .danger:hover { color: var(--error-text); }

.edit-box textarea { width: 100%; }
.edit-hint { font-size: 12px; color: var(--text-tertiary); }

.jump { position: absolute; bottom: 120px; left: 50%; transform: translateX(-50%); z-index: 10; border: 0; border-radius: 16px; padding: 6px 14px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; box-shadow: var(--shadow); }
.typing { height: 20px; padding: 0 18px; font-size: 12.5px; color: var(--text-tertiary); }
.typing .dots::after { content: '…'; animation: dots 1.2s steps(4) infinite; display: inline-block; width: 1.2em; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0; } to { width: 1.2em; } }

/* ---------- Eingabe ---------- */
.composer { position: relative; margin: 0 16px 14px; background: var(--surface-elevated); border: 1px solid var(--border-default); border-radius: var(--radius); }
.composer:focus-within { border-color: var(--accent-border); }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 6px 14px; font-size: 13px; color: var(--text-secondary); border-bottom: 1px solid var(--border-subtle); background: var(--surface-raised); border-radius: var(--radius) var(--radius) 0 0; }
.composer-preview { padding: 10px 12px 0; display: flex; gap: 10px; align-items: flex-start; }
.composer-preview img { max-height: 90px; max-width: 160px; border-radius: 8px; }
.composer-row { display: flex; align-items: flex-end; gap: 4px; padding: 6px; }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: none; color: inherit; font: inherit;
  padding: 7px 4px; max-height: 40vh; min-height: 34px;
}
.composer textarea::placeholder { color: var(--text-tertiary); }
.send { border: 0; width: 38px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; cursor: pointer; font-size: 15px; }
.send:hover { background: var(--accent-hover); }
.send:disabled { opacity: .4; cursor: default; }
.composer-hint { margin: 0; padding: 0 14px 8px; font-size: 11.5px; color: var(--text-tertiary); }
.composer.readonly { opacity: .7; }
.suggest { position: absolute; left: 8px; bottom: calc(100% + 6px); min-width: 220px; max-height: 260px; overflow-y: auto; background: var(--surface-elevated); border: 1px solid var(--border-default); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 4px; z-index: 20; }
.suggest button { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; padding: 6px 8px; border-radius: 7px; cursor: pointer; text-align: left; }
.suggest button.active, .suggest button:hover { background: var(--accent-muted); }

/* ---------- Mitglieder ---------- */
.members header { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 6px; }
.members h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-tertiary); }
#memberList { overflow-y: auto; padding: 0 8px 12px; }
.group-title { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-tertiary); padding: 12px 8px 4px; }
.member { display: flex; align-items: center; gap: 10px; width: 100%; padding: 5px 8px; border: 0; border-radius: 8px; background: none; cursor: pointer; text-align: left; }
.member:hover { background: var(--surface-overlay); }
.member .avatar { position: relative; overflow: visible; width: 32px; height: 32px; font-size: 13px; }
.member .avatar img { border-radius: 50%; }
.member .avatar::after { content: ''; position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%; background: var(--success); border: 2px solid var(--surface-raised); }
.member span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }

/* ---------- Overlays ---------- */
.popover { position: fixed; z-index: 60; background: var(--surface-elevated); border: 1px solid var(--border-default); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; max-width: 300px; }
.emoji-grid { display: grid; grid-template-columns: repeat(6, 36px); gap: 4px; }
.emoji-grid button { border: 0; background: none; font-size: 21px; border-radius: 8px; height: 36px; cursor: pointer; }
.emoji-grid button:hover { background: var(--surface-overlay); }
.profile { display: flex; flex-direction: column; gap: 10px; min-width: 240px; }
.profile-head { display: flex; gap: 12px; align-items: center; }
.profile-head strong { font-size: 17px; display: block; }
.profile .btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border-default); background: var(--surface-overlay); color: var(--text-primary); padding: 7px 12px; border-radius: var(--radius-sm); cursor: pointer; text-decoration: none; font-size: 14px; font-weight: 600; }
.btn:hover { border-color: var(--border-emphasis); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--error-text); }
.btn.small { padding: 4px 9px; font-size: 13px; }

.modal { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; }
.modal-card { width: min(520px, 100%); max-height: 88dvh; overflow-y: auto; background: var(--surface-elevated); border: 1px solid var(--border-default); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.modal-card h2 { margin: 0 0 14px; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 13px; color: var(--text-secondary); }
.field input, .field select, .field textarea { font: inherit; color: var(--text-primary); background: var(--surface-base); border: 1px solid var(--border-default); border-radius: 8px; padding: 8px 10px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; }
.modal-actions > div { display: flex; gap: 8px; }
.log-entry { font-size: 13px; padding: 7px 0; border-bottom: 1px solid var(--border-subtle); }
.log-entry time { color: var(--text-tertiary); margin-right: 6px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80; background: var(--surface-overlay); border: 1px solid var(--border-default); padding: 9px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; max-width: calc(100vw - 32px); }
.toast.error { color: var(--error-text); border-color: rgba(239,68,68,.3); }
.lightbox { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.85); display: grid; place-items: center; cursor: zoom-out; padding: 20px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------- Anmeldung ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--accent-muted), transparent 60%), var(--surface-base); }
.login-card { width: min(420px, 100%); text-align: center; background: var(--surface-elevated); border: 1px solid var(--border-default); border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow); }
.login-card img { border-radius: 16px; }
.login-card h1 { margin: 12px 0 6px; font-size: 24px; }
.login-card p { color: var(--text-secondary); margin: 0 0 18px; }
.login-card .btn { width: 100%; padding: 11px; font-size: 15px; }
.login-small { font-size: 13px; margin-top: 16px !important; }
.login-error { color: var(--error-text) !important; background: var(--error-muted); padding: 8px; border-radius: 8px; }

/* ---------- Schmal / Handy ---------- */
.only-mobile, .only-narrow { display: none !important; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; }
@media (max-width: 1100px) {
  .app, .app.members-hidden { grid-template-columns: var(--sidebar-w) 1fr; }
  .members { position: fixed; right: 0; top: 0; bottom: 0; width: 260px; z-index: 50; transform: translateX(100%); transition: transform .2s; display: flex !important; }
  .app.members-open .members { transform: none; }
  .only-narrow { display: inline-flex !important; }
}
@media (max-width: 760px) {
  .app, .app.members-hidden { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 280px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .app.sidebar-open .sidebar { transform: none; }
  .only-mobile { display: inline-flex !important; }
  .composer { margin: 0 8px 8px; }
  .composer-hint { display: none; }
  .msg { padding-left: 10px; padding-right: 10px; grid-template-columns: 36px 1fr; gap: 0 10px; }
  .actions { right: 8px; }
  .jump { bottom: 100px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
