/* ---------- Design-Tokens ---------- */
:root {
  --bg: #0e1014;
  --surface: #171a20;
  --surface-2: #1e222a;
  --surface-3: #262b35;
  --line: #2b313c;
  --line-soft: #21262e;

  --text: #e8eaed;
  --muted: #939aa6;
  --dim: #6b7280;

  --accent: #5b74f5;
  --accent-hover: #6d84ff;
  --accent-soft: rgba(91, 116, 245, .14);

  --green: #3fb950;
  --green-soft: rgba(63, 185, 80, .14);
  --red: #f85149;
  --red-soft: rgba(248, 81, 73, .13);
  --amber: #d29922;
  --amber-soft: rgba(210, 153, 34, .14);

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .18);

  --sidebar-w: 232px;
  --header-h: 56px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.55 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; color: var(--muted); }

/* ---------- Kopfzeile ---------- */
.topbar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -.01em; }
.brand-dot {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(140deg, var(--accent), #9b6bf5);
  display: grid; place-items: center; font-size: 13px;
}
.brand-dot::after { content: "◆"; color: #fff; }

.user-slot { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--muted); }
.user-slot img { width: 26px; height: 26px; border-radius: 50%; }

/* ---------- Grundlayout ---------- */
.app { display: block; }

.shell { display: flex; align-items: flex-start; min-height: calc(100vh - var(--header-h)); }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  position: sticky;
  top: var(--header-h);
  align-self: flex-start;
  max-height: calc(100vh - var(--header-h));
  overflow-y: auto;
}

.guild-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; margin-bottom: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.guild-card img, .guild-card .fallback {
  width: 34px; height: 34px; border-radius: 9px; object-fit: cover;
  background: var(--surface-3); display: grid; place-items: center; font-weight: 600;
}
.guild-card .meta { min-width: 0; flex: 1; }
.guild-card b { display: block; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guild-card span { font-size: 11.5px; color: var(--dim); }

.nav-label {
  font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--dim); padding: 0 10px; margin: 14px 0 6px; display: block;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--muted); font-size: 13.5px;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: #b9c4ff; font-weight: 500; }
.nav a .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .55; }

.content { flex: 1; min-width: 0; padding: 26px 30px 80px; max-width: 1100px; }

/* ---------- Typografie ---------- */
h1 { font-size: 21px; margin: 0 0 3px; letter-spacing: -.015em; }
h2 { font-size: 15px; margin: 0 0 12px; letter-spacing: -.005em; }
h3 { font-size: 13.5px; margin: 0; color: var(--muted); font-weight: 600; }
.sub { color: var(--muted); margin: 0 0 22px; font-size: 13.5px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 5px 0 0; line-height: 1.5; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }

/* ---------- Karten & Raster ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.card.accent { border-color: var(--accent); }
.card.danger { border-color: var(--red); }
.card.ok { border-color: var(--green); }

.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); }

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
}
.stat b { display: block; font-size: 25px; font-weight: 650; line-height: 1.25; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: 12px; }
.stat.good b { color: var(--green); }
.stat.warn b { color: var(--red); }

/* ---------- Server-Auswahl ---------- */
.server-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); }
.server {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; cursor: pointer;
  transition: border-color .12s, transform .12s;
}
.server:hover { border-color: var(--accent); transform: translateY(-1px); }
.server .avatar {
  width: 40px; height: 40px; border-radius: 11px; object-fit: cover;
  background: var(--surface-3); display: grid; place-items: center; font-weight: 600;
}
.server .meta { flex: 1; min-width: 0; }
.server .meta b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server .meta span { font-size: 12px; color: var(--dim); }

/* ---------- Formulare ---------- */
label { display: block; font-size: 12.5px; color: var(--muted); margin: 0 0 5px; font-weight: 500; }
.field { margin-bottom: 14px; }

input[type="text"], input[type="number"], input[type="color"], textarea, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 11px;
  font: inherit;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder { color: var(--dim); }
textarea { min-height: 76px; resize: vertical; }
input[type="color"] { height: 38px; padding: 3px; cursor: pointer; }
select[multiple] { min-height: 112px; padding: 6px; }
select[multiple] option { padding: 4px 6px; border-radius: 4px; }

/* ---------- Buttons ---------- */
button {
  font: inherit; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 15px; background: var(--accent); color: #fff;
  transition: background .12s, border-color .12s;
}
button:hover { background: var(--accent-hover); }
button.ghost { background: transparent; border-color: var(--line); color: var(--text); }
button.ghost:hover { background: var(--surface-2); border-color: var(--surface-3); }
button.danger { background: transparent; border-color: var(--red); color: var(--red); }
button.danger:hover { background: var(--red); color: #fff; }
button.small { padding: 6px 11px; font-size: 12.5px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 14px; }

/* ---------- Pills & Status ---------- */
.pill {
  font-size: 11.5px; font-weight: 500; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-3); color: var(--muted); white-space: nowrap;
}
.pill.open, .pill.ok { background: var(--green-soft); color: var(--green); }
.pill.closed, .pill.err { background: var(--red-soft); color: var(--red); }
.pill.warn { background: var(--amber-soft); color: var(--amber); }

.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 8px; }
.status-dot.on { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.status-dot.off { background: var(--dim); }
.status-dot.err { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }

/* ---------- Online-Liste ---------- */
.player-list { display: flex; flex-direction: column; gap: 7px; }
.player {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}
.player .name { font-weight: 550; }
.player .who { flex: 1; min-width: 0; }
.player .who div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .since { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }

/* ---------- Details / Akkordeon ---------- */
details.option {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 9px;
}
details.option > summary {
  cursor: pointer; font-weight: 550; list-style: none;
  display: flex; align-items: center; gap: 8px;
}
details.option > summary::-webkit-details-marker { display: none; }
details.option > summary::before { content: "›"; color: var(--dim); font-size: 17px; line-height: 1; }
details.option[open] > summary::before { content: "⌄"; }
details.option .body { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line-soft); }
th {
  color: var(--dim); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .05em;
  border-bottom-color: var(--line);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }

pre {
  background: #0a0c0f; border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 14px;
  overflow-x: auto; font-size: 12.5px; line-height: 1.5;
  font-family: ui-monospace, Consolas, monospace;
}
code {
  background: var(--surface-3); padding: 1px 5px; border-radius: 4px;
  font-family: ui-monospace, Consolas, monospace; font-size: 12.5px;
}

.empty { color: var(--dim); text-align: center; padding: 26px 0; font-size: 13.5px; }
.loading { color: var(--muted); padding: 46px 0; text-align: center; }

/* ---------- Toolbar & Suche ---------- */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.search {
  position: relative; flex: 1; min-width: 200px;
}
.search input {
  width: 100%; padding-left: 34px;
}
.search::before {
  content: "⌕"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--dim); font-size: 17px; pointer-events: none;
}
.count-badge {
  font-size: 12.5px; color: var(--muted); white-space: nowrap;
  padding: 4px 10px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px;
}

/* Sticky Tabellenkopf innerhalb scrollbarer Bereiche */
.table-wrap.tall { max-height: 62vh; overflow-y: auto; }
.table-wrap.tall thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface); backdrop-filter: blur(4px);
}

.row-hidden { display: none !important; }
.no-result { color: var(--dim); text-align: center; padding: 22px 0; font-size: 13.5px; }

/* Online-Punkt kompakt in Zeilen */
td .dot-online, .dot-online {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 8px;
  background: var(--green); box-shadow: 0 0 0 3px var(--green-soft);
}
.dot-offline {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 8px;
  background: var(--line);
}

/* ---------- Detail-Overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, .55);
  display: flex; justify-content: flex-end;
  animation: fade .12s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer {
  width: min(560px, 100%);
  height: 100%;
  background: var(--bg);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px rgba(0, 0, 0, .35);
  overflow-y: auto;
  animation: slide .16s ease;
}
@keyframes slide { from { transform: translateX(24px); } to { transform: translateX(0); } }
.drawer-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.drawer-head .avatar {
  width: 40px; height: 40px; border-radius: 11px;
  background: var(--surface-3); display: grid; place-items: center; font-weight: 600;
}
.drawer-head .meta { flex: 1; min-width: 0; }
.drawer-head .meta b { display: block; font-size: 15px; }
.drawer-head .meta span { font-size: 12px; color: var(--muted); }
.drawer-head button.close {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  width: 30px; height: 30px; padding: 0; border-radius: 8px; font-size: 16px; line-height: 1;
}
.drawer-head button.close:hover { border-color: var(--red); color: var(--red); }
.drawer-body { padding: 18px 20px 40px; }

/* Balkendiagramm Spielzeit/Tag */
.bars { display: flex; flex-direction: column; gap: 5px; }
.bar-row { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.bar-row .day { width: 62px; color: var(--muted); flex: 0 0 62px; }
.bar-row .track { flex: 1; height: 16px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--accent); border-radius: 4px; min-width: 2px; }
.bar-row .fill.zero { background: var(--line); }
.bar-row .val { width: 58px; text-align: right; color: var(--muted); flex: 0 0 58px; }

.event-log { display: flex; flex-direction: column; gap: 4px; }
.event-log .ev {
  display: flex; gap: 8px; align-items: baseline; font-size: 12.5px;
  padding: 6px 8px; background: var(--surface-2); border-radius: 6px;
}
.event-log .ev time { color: var(--dim); flex: 0 0 42px; font-variant-numeric: tabular-nums; }
.event-log .ev .txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.clickable { cursor: pointer; }
.clickable:hover { background: var(--surface-2); }
tr.clickable:hover td { background: var(--surface-2); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--surface-3); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 11px 17px; font-size: 13.5px;
  box-shadow: var(--shadow); z-index: 60;
}
.toast.error { border-color: var(--red); color: #ffb4b0; }

/* ---------- Startseite ---------- */
.hero { text-align: center; padding: 90px 20px; }
.hero h1 { font-size: 27px; }
.hero p { color: var(--muted); max-width: 460px; margin: 10px auto 26px; }
.hero button { padding: 11px 22px; font-size: 15px; }

/* ---------- Schmale Fenster ---------- */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; position: static; max-height: none;
    border-right: none; border-bottom: 1px solid var(--line);
    display: flex; gap: 14px; align-items: center; overflow-x: auto; padding: 12px;
  }
  .guild-card { margin: 0; flex: 0 0 auto; }
  .nav-label { display: none; }
  .nav { flex-direction: row; }
  .content { padding: 20px 16px 60px; }
}
