:root {
  --bg: #0e0e10; --panel: #18181b; --panel-2: #1f1f23; --border: #2f2f35;
  --text: #efeff1; --muted: #adadb8; --accent: #9146ff; --accent-2: #772ce8;
  --ok: #2ecc71; --danger: #eb4d4b; --warn: #f1c40f; --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
a { color: #bf94ff; }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.25; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- Form ---------- */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; }
input, select, textarea {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 7px; padding: 8px 10px; font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
textarea { resize: vertical; min-height: 80px; }
input[type=color] { padding: 2px; height: 36px; width: 56px; }
input[type=checkbox] { width: auto; margin: 0 6px 0 0; accent-color: var(--accent); }
.check { display: flex; align-items: center; color: var(--text); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }
.row > .shrink { flex: 0 0 auto; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 7px 13px; border-radius: 7px; cursor: pointer; font: inherit; font-weight: 600; text-decoration: none;
}
.btn:hover { border-color: #4a4a52; }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: #ff8a89; }
.btn.danger:hover { background: #3a1d1d; border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.block { width: 100%; margin-top: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(circle at 30% 20%, #2a1650 0, transparent 45%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.login-logo { font-size: 42px; }
.code-input { font-size: 22px; letter-spacing: 4px; text-align: center; font-family: ui-monospace, monospace; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100%; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.guild { display: flex; gap: 10px; align-items: center; padding: 16px; border-bottom: 1px solid var(--border); }
.guild img { width: 40px; height: 40px; border-radius: 12px; background: var(--panel-2); }
.guild-name { font-weight: 700; }
nav { padding: 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
nav a { padding: 9px 12px; border-radius: 7px; color: var(--muted); text-decoration: none; cursor: pointer; font-weight: 600; }
nav a:hover { background: var(--panel-2); color: var(--text); }
nav a.active { background: #2a1650; color: #fff; }
.me { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.me img { width: 28px; height: 28px; border-radius: 50%; }
.me span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view { padding: 26px 30px; max-width: 1150px; width: 100%; }
.view-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 26px; font-weight: 800; }
.stat .l { color: var(--muted); font-size: 12px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 11px; font-weight: 700; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }
.badge.accent { background: #2a1650; border-color: #4b2b8a; color: #d7c4ff; }
.badge.warn { background: #3a3110; border-color: #6d5a12; color: #f7d96c; }
.badge.danger { background: #3a1d1d; border-color: #6b2b2b; color: #ff9c9b; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button { background: none; border: none; color: var(--muted); padding: 8px 12px; cursor: pointer; font: inherit; font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 600; }
tr:hover td { background: #1c1c20; }
.user { display: inline-flex; align-items: center; gap: 7px; }
.user img { width: 22px; height: 22px; border-radius: 50%; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1px solid #0004; vertical-align: middle; margin-right: 6px; }
.empty { color: var(--muted); padding: 22px; text-align: center; }

/* ---------- Discord-Vorschau ---------- */
.msg { padding: 10px 12px; border-radius: 8px; background: #313338; color: #dbdee1; margin-bottom: 10px; font-size: 15px; line-height: 1.375; }
.msg.ephemeral { background: #32353b; box-shadow: inset 2px 0 0 #5865f2; }
.msg-ctx { font-size: 12px; color: #949ba4; margin: 0 0 6px 52px; }
.msg-row { display: flex; gap: 12px; }
.msg .avatar { width: 40px; height: 40px; border-radius: 50%; flex: 0 0 40px; background: #1e1f22; }
.msg .body { flex: 1; min-width: 0; }
.msg .meta { font-size: 12px; color: #949ba4; margin-bottom: 2px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.msg .meta b { color: #f2f3f5; font-size: 15px; font-weight: 600; }
.msg .meta .botbadge { background: #5865f2; color: #fff; font-size: 10px; font-weight: 700; padding: 0 4px; border-radius: 3px; line-height: 15px; }
.msg .text { word-wrap: break-word; overflow-wrap: anywhere; }
.msg a { color: #00a8fc; text-decoration: none; }
.msg a:hover { text-decoration: underline; }
.msg a.btn { color: var(--text); }
.msg a.btn:hover { text-decoration: none; }
.msg code.inline { background: #2b2d31; border: 1px solid #1e1f22; padding: 0 3px; border-radius: 3px; font-size: 85%; font-family: ui-monospace, Consolas, monospace; }
.msg pre.codeblock { background: #2b2d31; border: 1px solid #1e1f22; border-radius: 4px; padding: 7px 9px; margin: 4px 0; font-size: 13px; white-space: pre-wrap; font-family: ui-monospace, Consolas, monospace; }
.msg .quote { border-left: 4px solid #4e5058; padding-left: 10px; margin: 2px 0; }
.msg .h1 { font-size: 1.5em; font-weight: 700; margin: 6px 0 2px; color: #f2f3f5; }
.msg .h2 { font-size: 1.25em; font-weight: 700; margin: 6px 0 2px; color: #f2f3f5; }
.msg .h3 { font-size: 1.05em; font-weight: 700; margin: 6px 0 2px; color: #f2f3f5; }
.msg .subtext { font-size: 12px; color: #949ba4; }
.msg .li { padding-left: 16px; position: relative; }
.msg .li::before { content: '•'; position: absolute; left: 4px; }
.msg .mention { background: #5865f24d; color: #c9cdfb; border-radius: 3px; padding: 0 2px; font-weight: 500; }
.msg .ts { background: #ffffff14; border-radius: 3px; padding: 0 2px; }
.msg .spoiler { background: #1e1f22; color: transparent; border-radius: 3px; cursor: pointer; }
.msg .spoiler.open { background: #ffffff1a; color: inherit; }
.msg .ph { background: #f1c40f26; color: #f7d96c; border: 1px dashed #f1c40f88; border-radius: 3px; padding: 0 3px; font-family: ui-monospace, monospace; font-size: 90%; }
.msg img.emoji { width: 1.375em; height: 1.375em; vertical-align: bottom; }
.msg .eph { font-size: 12px; color: #949ba4; margin-top: 6px; }
.embed { border-left: 4px solid var(--accent); background: #2b2d31; border-radius: 4px; padding: 8px 16px 12px 12px; margin-top: 4px; max-width: 520px; font-size: 14px; }
.embed-grid { display: flex; gap: 16px; }
.embed-main { flex: 1; min-width: 0; }
.embed .e-author { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: #f2f3f5; margin-top: 8px; }
.embed .e-author img { width: 24px; height: 24px; border-radius: 50%; }
.embed .e-author a { color: #f2f3f5; }
.embed .t { font-weight: 600; color: #f2f3f5; font-size: 16px; margin-top: 8px; }
.embed .t a { color: #00a8fc; }
.embed .d { margin-top: 8px; word-wrap: break-word; overflow-wrap: anywhere; }
.embed .e-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.embed .e-field { grid-column: 1 / -1; min-width: 0; }
.embed .e-field.inline { grid-column: auto; }
.embed .fn { font-weight: 600; color: #f2f3f5; margin-bottom: 2px; font-size: 14px; }
.embed .fv { font-size: 14px; overflow-wrap: anywhere; }
.embed img.thumb, .embed .img-ph.thumb { width: 80px; height: 80px; object-fit: cover; border-radius: 4px; margin-top: 8px; flex: 0 0 80px; }
.embed img.big, .embed .img-ph.big { max-width: 100%; max-height: 300px; border-radius: 4px; margin-top: 16px; display: block; }
.embed .img-ph { background: #1e1f22; border: 1px dashed #4e5058; color: #949ba4; font-size: 11px; display: grid; place-items: center; text-align: center; padding: 6px; overflow: hidden; word-break: break-all; }
.embed .img-ph.big { height: 120px; }
.embed .f { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #b5bac1; margin-top: 8px; }
.embed .f img { width: 20px; height: 20px; border-radius: 50%; }
.brow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.dbtn { display: inline-flex; align-items: center; padding: 2px 16px; min-height: 32px; border-radius: 8px; font-size: 14px; font-weight: 500; color: #fff; background: #4e5058; }
.dbtn.primary { background: #5865f2; } .dbtn.success { background: #00863a; } .dbtn.danger { background: #d22d39; }
.msg-tools { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Editor & Layout ---------- */
.view.wide { max-width: 1500px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.split > .card { margin-bottom: 16px; }
.sticky { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; }
.lbl { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.counter { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter.warn { color: var(--warn); }
.embed-edit { border-left: 3px solid var(--border); padding-left: 12px; margin: 6px 0 10px; }
.color-pick { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.color-pick .check { margin: 0; }
details > summary { cursor: pointer; color: var(--muted); margin: 6px 0 10px; font-size: 13px; }
.field-row { display: flex; gap: 8px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--panel-2); }
.field-row .grow { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.field-row textarea { min-height: 52px; }
.field-tools { display: flex; flex-direction: column; justify-content: space-between; align-items: flex-end; gap: 6px; }
.field-tools .check { margin: 0; }
.hint { background: #1b2a3a; border: 1px solid #27445f; color: #b9d6f2; padding: 8px 10px; border-radius: 7px; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.chip { background: #2a1650; border: 1px solid #4b2b8a; color: #d7c4ff; border-radius: 99px; padding: 2px 9px; font: 12px ui-monospace, monospace; cursor: pointer; }
.chip:hover { background: #3a1f6e; }
.chips-global summary { margin: 0 0 6px; }
.warn-text { color: var(--warn); }
.tpl-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
.tpl-side { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; padding: 12px; }
.tpl-side > input { margin-bottom: 10px; }
.tpl-group { margin-bottom: 10px; }
.tpl-group-h { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 6px 4px; font-weight: 700; }
.tpl-item { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 6px; cursor: pointer; color: var(--text); text-decoration: none; font-size: 13px; }
.tpl-item:hover { background: var(--panel-2); }
.tpl-item.active { background: #2a1650; }

/* ---------- Self-Roles ---------- */
.entry { display: grid; grid-template-columns: 1.4fr 1fr 70px 1.3fr 110px auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.entry input, .entry select { padding: 6px 8px; }
.perm-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; max-height: 45vh; overflow: auto; padding-right: 4px; }
.perm-groups h4 { margin: 0 0 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Tickets ---------- */
tr.clickable { cursor: pointer; }
.badge.ok { background: #13361f; border-color: #1f6b3a; color: #7ee2a0; }
dialog.wide { width: min(1000px, 96vw); }
.ticket-info { display: flex; flex-wrap: wrap; gap: 10px 28px; padding: 10px 0 14px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.transcript { background: #313338; border-radius: 8px; padding: 8px 0; max-height: 68vh; overflow: auto; }
.msg.flat { margin: 0; border-radius: 0; padding-top: 6px; padding-bottom: 2px; }
.msg.flat:not(.compact) { margin-top: 10px; }
.msg.flat:hover { background: #2e3035; }
.msg.compact { padding-top: 1px; }
.msg .avatar-sp { width: 40px; flex: 0 0 40px; font-size: 10px; color: transparent; text-align: right; padding-top: 4px; }
.msg.compact:hover .avatar-sp { color: #949ba4; }
.msg .attach-img { display: block; max-width: min(400px, 100%); max-height: 300px; border-radius: 6px; margin-top: 4px; }
.msg .file { display: inline-flex; align-items: center; gap: 4px; background: #2b2d31; border: 1px solid #1e1f22; border-radius: 6px; padding: 8px 12px; margin-top: 4px; }

/* ---------- Streamer ---------- */
.streamer-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.streamer { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.streamer.live { border-color: #e91916; box-shadow: 0 0 0 1px #e9191655; }
.streamer-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.streamer-head img { width: 40px; height: 40px; border-radius: 50%; }
.streamer-head .live-badge { margin-left: auto; background: #e91916; border-color: #e91916; color: #fff; }

/* ---------- Modal & Toasts ---------- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 14px; padding: 22px; width: min(720px, 94vw); }
dialog::backdrop { background: #000a; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--panel-2); border: 1px solid var(--border); border-left: 4px solid var(--ok); padding: 10px 14px; border-radius: 8px; max-width: 380px; box-shadow: 0 8px 24px #0008; }
.toast.error { border-left-color: var(--danger); }

@media (max-width: 1250px) {
  .split { grid-template-columns: 1fr; }
  .sticky { position: static; max-height: none; }
}
@media (max-width: 980px) {
  .tpl-layout { grid-template-columns: 1fr; }
  .tpl-side { position: static; max-height: 320px; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  nav { flex-direction: row; overflow-x: auto; }
  nav a span { display: none; }
  .view { padding: 16px; }
  .entry { grid-template-columns: 1fr 1fr; }
}
