:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1b1e23;
  --muted: #5f6772;
  --border: #dde1e6;
  --primary: #3c7a36;
  --primary-text: #ffffff;
  --ok: #2b8a3e;
  --warn: #a8670f;
  --bad: #c53030;
  --ok-bg: #e5f4e8;
  --warn-bg: #fdf1dc;
  --bad-bg: #fde7e7;
  --c1: #2f6fdb;
  --c2: #9aa3ad;
  --grid: #e7eaee;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #232830;
    --text: #e7eaee;
    --muted: #9aa3ad;
    --border: #2c323b;
    --primary: #4f9a48;
    --ok: #5cc06a;
    --warn: #e5a54b;
    --bad: #f06b6b;
    --ok-bg: #15301a;
    --warn-bg: #33270f;
    --bad-bg: #3a1717;
    --c1: #6aa2ff;
    --c2: #6b7480;
    --grid: #262c34;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2 { margin: 0 0 12px; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* --- Kopfzeile --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; }
.user { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user #me-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.container { max-width: 1100px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }

/* --- Karten --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.count { font-variant-numeric: tabular-nums; color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.big { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; }
.sub { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.state { font-size: 22px; font-weight: 700; margin: 4px 0; }
.state-online { color: var(--ok); }
.state-offline, .state-error { color: var(--bad); }
.state-starting, .state-stopping, .state-unreachable { color: var(--warn); }
.state-unknown { color: var(--muted); }
.screen-line { margin-top: 4px; }
.pill {
  display: inline-block;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
}
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-bad { background: var(--bad-bg); color: var(--bad); }
h3 { font-size: 15px; margin: 18px 0 4px; }
.tps-good { color: var(--ok); }
.tps-mid { color: var(--warn); }
.tps-bad { color: var(--bad); }

/* --- Banner & Toast --- */
.banner {
  border-radius: var(--radius);
  padding: 12px 16px;
  font-weight: 600;
  border: 1px solid transparent;
}
.banner-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.banner-bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  z-index: 20;
}
.toast-bad { background: var(--bad); color: #fff; }
.toast-ok { background: var(--ok); color: #fff; }

/* --- Spieler & Whitelist --- */
.avatar {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  image-rendering: pixelated;
  background: var(--surface-2);
  flex: none;
}
.avatar-missing { visibility: hidden; }
.players, .wl-list { list-style: none; margin: 0; padding: 0; }
.players { display: flex; flex-wrap: wrap; gap: 8px; }
.players li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  background: var(--surface-2);
  border-radius: 8px;
}
.wl-list { margin-top: 12px; max-height: 360px; overflow-y: auto; }
.wl-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
}
.wl-name { display: flex; align-items: center; gap: 8px; min-width: 0; overflow-wrap: anywhere; }
.wl-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.wl-perm { display: inline-flex; align-items: center; gap: 4px; margin: 0; font-size: 13px; font-weight: 400; cursor: pointer; }
.wl-perm input { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }
.wl-perm:has(input:disabled) { cursor: default; color: var(--muted); }
.tag {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--ok-bg);
  color: var(--ok);
}

/* --- Diagramme --- */
.chart-block + .chart-block { margin-top: 12px; }
.chart-title { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.chart-title .small { margin-left: auto; font-weight: 400; }
.legend { display: inline-flex; align-items: center; gap: 4px; font-weight: 400; font-size: 13px; color: var(--muted); }
.sw { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-left: 4px; }
.sw-1 { background: var(--c1); }
.sw-2 { background: var(--c2); }
.chart {
  display: block;
  width: 100%;
  height: 80px;
  background: var(--surface-2);
  border-radius: 8px;
}
.chart .grid { stroke: var(--grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.chart .s1 { stroke: var(--c1); }
.chart .s2 { stroke: var(--c2); }

/* --- Formulare & Buttons --- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
}
.btn:hover:not(:disabled) { filter: brightness(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-ghost { background: transparent; }
.btn-small { padding: 4px 10px; min-height: 32px; font-size: 13px; }
.btn-block { width: 100%; margin-top: 12px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

input[type="text"] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  min-height: 40px;
}
input[type="text"]:focus { outline: 2px solid var(--c1); outline-offset: 1px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; }
label { display: block; font-weight: 600; margin: 12px 0 6px; }
.link {
  display: block;
  margin: 10px auto 0;
  background: none;
  border: 0;
  color: var(--c1);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

/* --- Login --- */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login { width: 100%; max-width: 400px; padding: 16px; }
.login-card h1 { text-align: center; }
.msg { min-height: 1.4em; margin: 12px 0 0; font-weight: 600; }
.msg-bad { color: var(--bad); }
.msg-ok { color: var(--ok); }
#code { font-size: 22px; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }

/* --- Responsiv --- */
@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 420px) {
  .tiles { gap: 10px; }
  .card { padding: 12px; }
  .big { font-size: 22px; }
  .brand { font-size: 14px; }
}
