/* ── Reset & Variablen ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f1117;
  --bg-card:     #181c27;
  --bg-sidebar:  #13161f;
  --border:      #252a38;
  --accent:      #4f7cff;
  --accent-glow: rgba(79,124,255,0.18);
  --text:        #e8eaf0;
  --text-muted:  #6b7280;
  --success:     #22c55e;
  --warning:     #f59e0b;
  --error:       #ef4444;
  --radius:      12px;
  --sidebar-w:   240px;
}

body.light {
  --bg:          #f4f5f7;
  --bg-card:     #ffffff;
  --bg-sidebar:  #ffffff;
  --border:      #e2e5eb;
  --accent:      #3b6bef;
  --accent-glow: rgba(59,107,239,0.12);
  --text:        #111827;
  --text-muted:  #6b7280;
}

/* ── Theme Switch ─────────────────────────────────────────── */
.theme-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.theme-row:last-child { border-bottom: none; }
.theme-label { font-size: 14px; font-weight: 500; }
.theme-label span { display: block; font-size: 12px; color: var(--text-muted); font-weight: 400; margin-top: 2px; }

.switch { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.25s;
}
.switch-track::after {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.25s;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Layout ───────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 28px;
  border-bottom: 1px solid var(--border);
}
.logo-icon { font-size: 22px; color: var(--accent); }
.logo-text  { font-weight: 700; font-size: 15px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; padding: 20px 12px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover  { background: rgba(255,255,255,0.05); color: var(--text); }
.nav-item.active { background: var(--accent-glow); color: var(--accent); }
.nav-icon { font-size: 16px; }

.sidebar-footer {
  margin-top: auto;
  padding: 16px 12px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 8px;
}
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.user-name    { font-size: 13px; font-weight: 600; }
.user-role    { font-size: 11px; color: var(--text-muted); }

/* ── Main ─────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px 36px;
  max-width: 1100px;
}

/* ── Topbar ───────────────────────────────────────────────── */
.topbar { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 32px; }
.topbar h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.topbar-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ── Stats Grid ───────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
}
.stat-card.highlight {
  border-color: var(--accent);
  background: linear-gradient(135deg, var(--bg-card), rgba(79,124,255,0.07));
}
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.stat-value { font-size: 26px; font-weight: 700; }

/* ── Card ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 20px;
}
.card-header h2 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.card-header p  { font-size: 13px; color: var(--text-muted); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn-primary:hover    { opacity: 0.88; }
.btn-primary:active   { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}
.btn-ghost:hover { background: rgba(255,255,255,0.05); color: var(--text); }

/* ── Tabellen ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.02); }

/* ── Badge ────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-admin    { background: rgba(79,124,255,0.15); color: var(--accent); }
.badge-customer { background: rgba(34,197,94,0.12); color: var(--success); }

/* ── Verbindungstest ──────────────────────────────────────── */
.test-area { margin-top: 24px; display: flex; flex-direction: column; gap: 20px; }

.test-results { display: flex; flex-direction: column; gap: 12px; }
.test-results.hidden { display: none; }

.result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.3s;
}
.result-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; transition: background 0.3s; }
.result-dot.pending { background: var(--text-muted); }
.result-dot.running { background: var(--warning); animation: pulse 0.9s infinite; }
.result-dot.success { background: var(--success); }
.result-dot.error   { background: var(--error); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }
.result-label  { flex: 1; font-size: 13.5px; font-weight: 500; }
.result-status { font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.result-item.success { border-color: rgba(34,197,94,0.3); }
.result-item.error   { border-color: rgba(239,68,68,0.3); }

.test-summary { padding: 14px 18px; border-radius: 8px; font-size: 13.5px; font-weight: 500; }
.test-summary.hidden  { display: none; }
.test-summary.success { background: rgba(34,197,94,0.1); border:1px solid rgba(34,197,94,0.3); color: var(--success); }
.test-summary.error   { background: rgba(239,68,68,0.1); border:1px solid rgba(239,68,68,0.3); color: var(--error); }

/* ── Alert ────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  margin-bottom: 16px;
  display: none;
}
.alert.show   { display: block; }
.alert-error   { background: rgba(239,68,68,0.1); border:1px solid rgba(239,68,68,0.3); color: var(--error); }
.alert-success { background: rgba(34,197,94,0.1); border:1px solid rgba(34,197,94,0.3); color: var(--success); }

/* ── Formular ─────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text-muted); }
.form-group input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.form-group input:focus { border-color: var(--accent); }

/* ── Mobile Topbar ────────────────────────────────────────── */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 200;
}
.mobile-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
}
.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.25s, opacity 0.25s;
}
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Drawer Overlay ───────────────────────────────────────── */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 299;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.drawer-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2,1fr); }
}

@media (max-width: 700px) {
  /* Globales Overflow verhindern */
  html, body { overflow-x: hidden; max-width: 100%; }

  /* Mobile Topbar einblenden */
  .mobile-topbar { display: flex; }

  /* Drawer: Sidebar wird zum Slide-in Panel */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    z-index: 300;
    width: 260px;
    top: 0;
  }
  .sidebar.open { transform: translateX(0); }
  .drawer-overlay { display: block; }

  /* Main unter Mobile-Topbar schieben */
  .main {
    margin-left: 0;
    padding: 80px 16px 24px;
    max-width: 100%;
    width: 100%;
    overflow-x: hidden;
  }

  /* Topbar innen kompakter */
  .topbar { margin-bottom: 20px; }
  .topbar h1 { font-size: 18px; }

  /* Stats: 2 Spalten auf mittelgroß, 1 Spalte auf klein */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .stat-card { padding: 14px 16px; }
  .stat-value { font-size: 20px; }

  /* Cards kompakter */
  .card { padding: 18px 16px; }

  /* max-width Cards (Einstellungen etc.) auf 100% */
  .card[style*="max-width"] { max-width: 100% !important; }

  /* Result-Items schmaler */
  .result-item { padding: 12px 14px; gap: 10px; }
  .result-status { font-size: 11.5px; }

  /* Buttons volle Breite */
  .btn-primary { width: 100%; justify-content: center; }

  /* Formulare */
  .form-group input,
  textarea { font-size: 16px; } /* verhindert iOS zoom */
}

@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr; }
}
