:root {
  --bg: #0e1116;
  --bg-2: #161b22;
  --bg-3: #1c2230;
  --line: #262d3a;
  --text: #e6e9ef;
  --muted: #8b95a7;
  --accent: #4f8cff;
  --accent-2: #2f6bd6;
  --green: #3fb37f;
  --red: #e5534b;
  --amber: #d6a23a;
  --radius: 12px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--red); min-height: 18px; font-size: 13px; margin: 6px 0 0; }

button { font: inherit; cursor: pointer; border: none; border-radius: 8px; padding: 9px 14px; color: var(--text); background: var(--bg-3); transition: background .15s, transform .05s; }
button:hover { background: #232b3a; }
button:active { transform: translateY(1px); }
button.primary, button[type="submit"] { background: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover, button[type="submit"]:hover { background: var(--accent-2); }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.danger { background: transparent; border: 1px solid var(--red); color: var(--red); }
button.danger:hover { background: rgba(229,83,75,.12); }
input, select, textarea {
  font: inherit; background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 11px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

/* Login */
.login-screen { height: 100%; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2440 0%, var(--bg) 60%); }
.login-card { width: 320px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.login-card .brand { font-size: 20px; }

/* Brand */
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; }
.brand-mark { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #8a5cff); color: #fff; font-weight: 800; font-size: 14px; }

/* App layout */
.app { display: grid; grid-template-columns: 232px 1fr; height: 100vh; }
.sidebar { background: var(--bg-2); border-right: 1px solid var(--line); padding: 20px 16px;
  display: flex; flex-direction: column; gap: 22px; }
.sidebar nav { display: grid; gap: 4px; }
.nav-item { text-align: left; background: transparent; color: var(--muted); padding: 9px 11px; }
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: var(--bg-3); color: var(--text); font-weight: 600; }
.sidebar-foot { margin-top: auto; display: grid; gap: 10px; }
.warn-pill { font-size: 11px; color: var(--amber); border: 1px solid var(--amber); border-radius: 6px; padding: 4px 8px; text-align: center; }

.content { overflow: auto; }
.topbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px;
  padding: 24px 28px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 5; }
.topbar h1 { margin: 0 0 2px; font-size: 20px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.topbar-actions input { width: 260px; }

/* Table */
.table-wrap { padding: 8px 16px 40px; }
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--line); }
tbody td { padding: 13px 14px; border-bottom: 1px solid var(--bg-3); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--bg-2); }
.acct-cell { display: flex; flex-direction: column; }
.acct-cell .email { font-weight: 600; }
.acct-cell .name { color: var(--muted); font-size: 12px; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--bg-3); border: 1px solid var(--line); }
.badge.dash { color: var(--muted); }
.credits-val { font-variant-numeric: tabular-nums; font-weight: 600; }

/* Drawer */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 460px; max-width: 92vw;
  background: var(--bg-2); border-left: 1px solid var(--line); z-index: 21; box-shadow: var(--shadow);
  overflow: auto; animation: slidein .18s ease; }
@keyframes slidein { from { transform: translateX(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-inner { padding: 24px; display: grid; gap: 18px; }
.drawer h2 { margin: 0; font-size: 18px; word-break: break-all; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; }
.card h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; }
.close-x { position: absolute; }
.drawer-head { display: flex; justify-content: space-between; align-items: start; gap: 10px; }
.big-credit { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tx-list { display: grid; gap: 6px; max-height: 220px; overflow: auto; margin-top: 4px; }
.tx { display: grid; grid-template-columns: 60px 1fr auto; gap: 8px; align-items: center; font-size: 12px;
  padding: 6px 8px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 6px; }
.tx .pos { color: var(--green); font-weight: 700; font-variant-numeric: tabular-nums; }
.tx .neg { color: var(--red); font-weight: 700; font-variant-numeric: tabular-nums; }
.card select { width: auto; min-width: 140px; }
.card > button { width: 100%; }
.badge.ban { color: var(--red); border-color: var(--red); background: rgba(229, 83, 75, 0.12); }
.confirm-overlay { z-index: 49; }
.confirm-box { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 50;
  width: 380px; max-width: 92vw; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.confirm-box p { margin: 0 0 18px; line-height: 1.5; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }
.confirm-actions button { width: auto; padding: 9px 16px; }
.health { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }
.health.bad { background: var(--red); box-shadow: 0 0 0 3px rgba(229, 83, 75, 0.18); }
.err-row { display: grid; grid-template-columns: 130px 90px minmax(160px, 1fr) 2fr; gap: 10px; align-items: baseline;
  padding: 10px 14px; border-bottom: 1px solid var(--bg-3); cursor: pointer; font-size: 13px; }
.err-row:hover { background: var(--bg-2); }
.err-email { font-weight: 600; }
.err-det { word-break: break-word; }
.note-row { display: flex; justify-content: space-between; gap: 8px; align-items: start;
  padding: 8px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; margin-bottom: 6px; }
.note-row button { width: auto; padding: 2px 8px; }
.audit-list { display: grid; gap: 4px; max-height: 200px; overflow: auto; }
.audit-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; }
#notes-list { margin-top: 8px; }

/* Hamburger + Scrim: nur mobil sichtbar */
.menu-toggle { display: none; }
.nav-scrim { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center;
    position: fixed; top: 10px; left: 10px; z-index: 45; width: 42px; height: 42px;
    font-size: 20px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; color: var(--text); }
  .app { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .content { width: 100%; }

  /* Sidebar als einklappbares Off-Canvas-Panel */
  .sidebar { position: fixed; top: 0; left: 0; height: 100vh; width: 240px;
    transform: translateX(-100%); transition: transform .2s ease; z-index: 50; }
  body.nav-open .sidebar { transform: none; }
  .nav-scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 44; }
  .nav-scrim.hidden { display: none; }

  .topbar { flex-direction: column; align-items: stretch; gap: 12px; position: static; padding: 16px 16px 16px 64px; }
  .topbar-actions { flex-direction: column; }
  .topbar-actions input { width: 100%; }
  .table-wrap { padding: 8px 10px 40px; }

  /* Account-Tabelle -> Karten */
  #accounts-table thead { display: none; }
  #accounts-table, #accounts-table tbody, #accounts-table tr, #accounts-table td { display: block; width: 100%; }
  #accounts-table tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; padding: 4px 2px; background: var(--bg-2); }
  #accounts-table tr:hover { background: var(--bg-2); }
  #accounts-table td { border: none; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 14px; }
  #accounts-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; }
  #accounts-table td:first-child { display: block; padding-top: 10px; }
  #accounts-table td:first-child::before { content: ""; display: none; }

  /* Drawer -> Vollbild; Fehlerzeilen gestapelt */
  .drawer { width: 100vw; max-width: 100vw; }
  .err-row { grid-template-columns: 1fr; gap: 2px; }
  .err-row .log-time { order: -1; }
}
.log-out { display: grid; gap: 4px; max-height: 320px; overflow: auto; margin-top: 6px; }
.log-row { display: grid; grid-template-columns: 96px 78px 1fr; gap: 8px; align-items: baseline;
  font-size: 12px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.log-row.err { border-color: var(--red); background: rgba(229, 83, 75, 0.08); }
.log-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.log-src { justify-self: start; font-size: 11px; padding: 2px 7px; }
.log-act { font-weight: 600; }
.log-detail { grid-column: 2 / -1; word-break: break-word; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--bg-3);
  border: 1px solid var(--line); padding: 11px 18px; border-radius: 10px; z-index: 40; box-shadow: var(--shadow); }
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }

/* Setup */
.setup-body { padding: 24px 28px; display: grid; gap: 18px; max-width: 880px; }
.map-grid { display: grid; grid-template-columns: 140px 1fr; gap: 10px 14px; align-items: center; }
details.tbl { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
details.tbl summary { cursor: pointer; font-weight: 600; }
details.tbl .cols { color: var(--muted); font-size: 12px; margin-top: 8px; line-height: 1.7; }

/* Dashboard */
.dash-wrap { padding: 24px 28px; display: grid; gap: 20px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); gap: 14px; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.stat-num { font-size: 30px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; margin-top: 4px; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 8px; }
.stat-accent .stat-num { color: var(--accent); }
.stat-green .stat-num { color: var(--green); }
.dash-cols { display: grid; grid-template-columns: 1.25fr 1fr; gap: 16px; }
@media (max-width: 880px) { .dash-cols { grid-template-columns: 1fr; } }
.dash-cols .card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.dash-cols .card h3 { margin: 0 0 14px; font-size: 14px; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 168px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 5px; height: 100%; }
.bar { width: 100%; max-width: 40px; background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-radius: 6px 6px 0 0; min-height: 2px; }
.bar-val { font-size: 11px; color: var(--muted); }
.bar-label { font-size: 11px; color: var(--muted); }
.recent-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.recent-row:last-child { border-bottom: none; }
.recent-email { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-badges { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
