:root {
  --bg: #141414;
  --surface: #1d1d1d;
  --surface-2: #252525;
  --border: #2c2c2c;
  --border-strong: #3a3a3a;
  --text: #e8e8e8;
  --text-muted: #9a9a9a;
  --text-faint: #6e6e6e;
  --primary: #1473e6;
  --primary-hover: #0d66d0;
  --primary-soft: rgba(20, 115, 230, 0.16);
  --danger: #e34850;
  --danger-soft: rgba(227, 72, 80, 0.14);
  --success: #2d9d78;
  --success-soft: rgba(45, 157, 120, 0.16);
  --warning: #e68619;
  --warning-soft: rgba(230, 134, 25, 0.16);
  --radius: 4px;
  --radius-lg: 6px;
  --font: Inter, "Segoe UI", -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
p { margin: 0; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- Formulare ---------- */
.field { display: grid; gap: 6px; }
.field > span { font-size: 12px; color: var(--text-muted); font-weight: 500; }

input, select {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:hover, select:hover { border-color: #4a4a4a; }
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}
input[readonly] { color: var(--text-muted); font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 16px;
  font: 600 13px var(--font);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: #4a4a4a; }
.btn-danger { background: transparent; color: var(--danger); border-color: transparent; }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-block { width: 100%; height: 36px; border-radius: 18px; }
.btn-small { height: 28px; padding: 0 12px; font-size: 12px; }

.form-error {
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--danger-soft);
  border: 1px solid rgba(227, 72, 80, 0.35);
  color: #ff8a8f;
  font-size: 13px;
}

/* ---------- Anmeldeseiten ---------- */
body.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  display: grid;
  gap: 24px;
}
.auth-card form { display: grid; gap: 16px; }
.auth-card > [id^="state-"] { display: grid; gap: 24px; }
.auth-card .lead { color: var(--text-muted); font-size: 13px; margin-top: 6px; }
.auth-card code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}

@media (max-width: 420px) {
  .auth-card { padding: 24px 20px; }
}

/* ---------- Marke ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: #fa0f00;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ---------- App-Rahmen ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 52px;
  padding: 0 24px;
  background: rgba(20, 20, 20, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar nav { display: flex; gap: 4px; margin-left: 12px; }
.topbar nav a {
  padding: 6px 10px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
}
.topbar nav a:hover { color: var(--text); background: var(--surface-2); }
.topbar nav a[aria-current="page"] { color: var(--text); }
.topbar .spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 10px; color: var(--text-muted); }
.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.page { max-width: 1200px; margin: 0 auto; padding: 32px 24px 64px; display: grid; gap: 32px; }
.page-head { display: grid; gap: 6px; }
.page-head p { color: var(--text-muted); }

.section { display: grid; gap: 14px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.section-head .count { color: var(--text-faint); font-size: 12px; }

@media (max-width: 640px) {
  .topbar { padding: 0 16px; gap: 10px; }
  .topbar nav { margin-left: 0; }
  .brand-text, .user-name { display: none; }
  .page { padding: 24px 16px 48px; gap: 24px; }
}

/* ---------- Dashboard ---------- */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.app-tile {
  --app-fg: #fff;
  --app-bg: #333;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: start;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  transition: border-color 0.12s, background 0.12s, transform 0.12s;
}
a.app-tile:hover { border-color: var(--border-strong); background: #212121; }
a.app-tile:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
a.app-tile:active { transform: scale(0.99); }
.app-tile.unavailable { opacity: 0.55; }

.app-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--app-bg);
  border: 2px solid var(--app-fg);
  color: var(--app-fg);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.app-body { display: grid; gap: 4px; min-width: 0; }
.app-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.app-desc { color: var(--text-muted); font-size: 13px; line-height: 1.4; }
.app-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; color: var(--text-faint); font-size: 11px; }

.badge {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 7px;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: var(--surface-2);
  color: var(--text-muted);
}
.badge-alpha { background: var(--primary-soft); color: #6aa8f5; }
.badge-dev { background: var(--warning-soft); color: #f0a54a; }

.notice {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------- Admin ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: grid;
  gap: 16px;
}

.create-form { display: grid; grid-template-columns: 1fr 160px auto; gap: 12px; align-items: end; }
.create-form .btn { height: 36px; border-radius: 18px; }
.create-form .form-error { grid-column: 1 / -1; }
@media (max-width: 640px) {
  .create-form { grid-template-columns: 1fr; }
}

.link-box {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--primary-soft);
  border: 1px solid rgba(20, 115, 230, 0.4);
}
.link-box p { font-size: 13px; }
.link-box .hint { color: var(--text-muted); font-size: 12px; }
.link-row { display: flex; gap: 8px; }
.link-row input { flex: 1; min-width: 0; }

.user-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.user-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  gap: 14px;
  align-items: center;
  padding: 12px 16px;
}
.user-row + .user-row { border-top: 1px solid var(--border); }
.user-name-cell { display: grid; min-width: 0; }
.user-name-cell strong { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-name-cell small { color: var(--text-faint); font-size: 12px; }
.user-actions { display: flex; gap: 4px; justify-content: flex-end; min-width: 190px; }
.role { color: var(--text-muted); font-size: 12px; min-width: 70px; }
.you { color: var(--text-faint); font-weight: 400; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; min-width: 120px; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-active { color: var(--success); }
.status-pending, .status-reset { color: var(--warning); }
.status-expired { color: var(--text-faint); }

.empty { padding: 24px 16px; color: var(--text-muted); text-align: center; }

@media (max-width: 720px) {
  .user-row { grid-template-columns: auto 1fr; row-gap: 8px; }
  .user-row .role, .user-row .status { grid-column: 2; }
  .user-actions { grid-column: 1 / -1; justify-content: flex-start; min-width: 0; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: var(--radius);
  background: #2f2f2f;
  border: 1px solid var(--border-strong);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-size: 13px;
  z-index: 100;
}
