:root {
  --bg: #1e1f22; --side: #2b2d31; --card: #313338; --card2: #383a40; --line: #3f4147;
  --text: #dbdee1; --muted: #949ba4; --head: #f2f3f5;
  --accent: #5865f2; --accent-h: #4752c4; --green: #23a559; --red: #f23f43; --yellow: #f0b232;
  --radius: 10px;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] { }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: #8ea1e1; }
h1, h2, h3 { color: var(--head); margin: 0; line-height: 1.25; }
h1 { font-size: 24px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.noscript { padding: 24px; }
.hidden { display: none !important; }

/* Buttons & Eingaben */
button, .btn { font: inherit; border: 0; border-radius: 6px; padding: 8px 16px; cursor: pointer; background: var(--card2); color: var(--head); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { filter: brightness(1.15); }
button:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn-primary { background: var(--accent); } .btn-primary:hover { background: var(--accent-h); filter: none; }
.btn-green { background: var(--green); } .btn-danger { background: var(--red); }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
input[type=text], input[type=number], input[type=search], select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; min-height: 90px; font-family: inherit; }
select { appearance: auto; }
input[type=number] { width: 140px; }
input[type=file] { color: var(--muted); max-width: 100%; }

/* Login */
.center { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login { text-align: center; max-width: 420px; }
.login .logo { width: 72px; height: 72px; margin-bottom: 16px; }
.login p { color: var(--muted); }

/* Kopfleiste */
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: var(--side); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .brand { font-weight: 700; color: var(--head); display: flex; align-items: center; gap: 8px; cursor: pointer; }
.topbar .brand img { width: 26px; height: 26px; }
.topbar .spacer { flex: 1; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--card2); object-fit: cover; flex: none; }
.avatar.sm { width: 28px; height: 28px; }

/* Serverauswahl */
.page { max-width: 1000px; margin: 0 auto; padding: 24px 16px 64px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin-top: 18px; }
.guild-card { background: var(--card); border-radius: var(--radius); padding: 16px; display: flex; align-items: center; gap: 14px; border: 1px solid transparent; }
.guild-card:hover { border-color: var(--line); }
.guild-icon { width: 52px; height: 52px; border-radius: 16px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px; flex: none; object-fit: cover; }
.guild-card .name { font-weight: 600; color: var(--head); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guild-card .info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

/* Server-Ansicht */
.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - 57px); }
.sidebar { background: var(--side); padding: 14px 10px; border-right: 1px solid var(--line); position: sticky; top: 57px; align-self: start; max-height: calc(100vh - 57px); overflow: auto; }
.side-head { display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px; }
.side-head .guild-icon { width: 38px; height: 38px; border-radius: 12px; font-size: 14px; }
.side-head .name { font-weight: 700; color: var(--head); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--muted); cursor: pointer; width: 100%; background: none; text-align: left; }
.nav-item:hover { background: var(--card); color: var(--text); filter: none; }
.nav-item.active { background: var(--card2); color: var(--head); }
.nav-item .ico { width: 22px; text-align: center; }
.content { padding: 24px; max-width: 920px; width: 100%; min-width: 0; }
.content > * + * { margin-top: 18px; }
.back { margin-bottom: 8px; }

/* Karten & Formulare */
.stack { display: grid; gap: 18px; }
.card { background: var(--card); border-radius: var(--radius); padding: 18px; }
.card > h2 + .muted { margin-top: 4px; }
.card > * + * { margin-top: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 22px; font-weight: 700; color: var(--head); }
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.module-card { background: var(--card); border-radius: var(--radius); padding: 16px; cursor: pointer; text-align: left; display: block; width: 100%; }
.module-card .t { font-weight: 600; color: var(--head); margin-bottom: 4px; }
.module-card:hover { background: var(--card2); filter: none; }
.field { display: grid; gap: 6px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.field label.lbl { font-weight: 600; color: var(--head); }
.help { color: var(--muted); font-size: 13px; }
.field + .field { border-top: 1px solid var(--line); padding-top: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > .grow { flex: 1; min-width: 160px; }
.row label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

/* Schalter */
.switch { position: relative; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch .track { position: absolute; inset: 0; background: #80848e; border-radius: 12px; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--card2); border-radius: 6px; padding: 3px 4px 3px 8px; font-size: 13px; }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, #80848e); flex: none; }
.chip button { padding: 0 6px; background: transparent; font-size: 16px; line-height: 1; color: var(--muted); }
.chip button:hover { color: var(--red); }
.chip.static { padding-right: 8px; }
.tag { display: inline-block; background: var(--card2); border-radius: 4px; padding: 1px 7px; font-size: 12px; margin: 2px 4px 2px 0; }

/* Tabellen */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
td.wrap { white-space: normal; min-width: 240px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.user { display: flex; align-items: center; gap: 10px; }
.user .nm { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; }
.empty { color: var(--muted); padding: 10px 0; }

/* Speichern-Leiste */
.savebar { position: sticky; bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: #111214; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.savebar.clean { display: none; }
.savebar .actions { display: flex; gap: 8px; }

/* Modal & Toasts */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { background: var(--card); border-radius: 12px; padding: 20px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; }
.modal > * + * { margin-top: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 14px; }
.perm-grid label { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.perm-grid input { margin-top: 4px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 30; max-width: calc(100vw - 32px); }
.toast { background: #111214; border-left: 4px solid var(--green); padding: 10px 14px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.5); max-width: 380px; }
.toast.err { border-color: var(--red); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.banner { background: #4a3b12; border: 1px solid var(--yellow); color: #f6dfa3; padding: 10px 14px; border-radius: 8px; }

/* Mobil */
@media (max-width: 800px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .topbar { padding: 10px 12px; }
  .topbar .brand { white-space: nowrap; }
  .sidebar { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); display: flex; flex-wrap: nowrap; gap: 4px; overflow-x: auto; padding: 8px; }
  .side-head { display: none; }
  .nav-item { width: auto; white-space: nowrap; flex: none; }
  .content { padding: 16px; }
  .field-row { align-items: flex-start; }
}
