:root {
  --primary:      #1d4ed8;
  --primary-dark: #1e40af;
  --sidebar-bg:   #0f172a;
  --sidebar-w:    240px;
  --topbar-h:     56px;
  --text:         #1e293b;
  --text-muted:   #64748b;
  --border:       #e2e8f0;
  --bg:           #f8fafc;
  --card-bg:      #ffffff;
  --radius:       8px;
  --danger:       #dc2626;
  --success:      #16a34a;
}

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

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ── Layout ──────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }
.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }
.content { padding: 24px; flex: 1; }

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex; flex-direction: column; z-index: 100;
  overflow: visible;
}
.sidebar-brand { padding: 20px 16px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-logo { max-height: 40px; max-width: 180px; display: block; }
.brand-text { color: #fff; font-weight: 700; font-size: 15px; }
.sidebar-nav { flex: 1; padding: 8px 8px; overflow-y: auto; }
.nav-section-label {
  font-size: 10px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: rgba(255,255,255,.35);
  padding: 8px 8px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 10px; border-radius: 6px;
  color: rgba(255,255,255,.7); text-decoration: none;
  font-size: 13px; transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item svg { flex-shrink: 0; opacity: .8; }
.sidebar-footer {
  padding: 12px 8px 0;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 6px;
}
.user-info {
  flex: 1; display: flex; align-items: center; gap: 10px;
  text-decoration: none; border-radius: 6px; padding: 6px 8px;
  transition: background .15s;
}
.user-info:hover { background: rgba(255,255,255,.08); }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-name { color: #fff; font-size: 13px; font-weight: 600; }
.user-role { color: rgba(255,255,255,.45); font-size: 11px; }
.logout-btn {
  color: rgba(255,255,255,.5); padding: 8px; border-radius: 6px;
  display: flex; align-items: center; text-decoration: none;
  transition: color .15s, background .15s;
}
.logout-btn:hover { color: #fff; background: rgba(255,255,255,.08); }

/* ── Sidebar Clock ───────────────────────────────────────────────── */
.sidebar-clock-box {
  text-align: center; padding: 8px 8px 12px;
  border-top: 1px solid rgba(255,255,255,.06);
  margin-top: 4px;
}
.sidebar-clock-label {
  font-size: 9px; font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase; color: rgba(255,255,255,.3); margin-bottom: 2px;
}
.sidebar-clock {
  font-size: 20px; font-weight: 700; color: rgba(255,255,255,.8);
  letter-spacing: .04em; font-variant-numeric: tabular-nums;
}

/* ── Topbar ──────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h); display: flex; align-items: center;
  padding: 0 24px; background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; margin-left: auto; }
.page-title { font-size: 17px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Cards ───────────────────────────────────────────────────────── */
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card-header { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.card-title { font-weight: 600; font-size: 14px; }
.card-body  { padding: 20px; }

/* ── Tables ──────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.table th { background: #f8fafc; font-weight: 600; font-size: 12px; color: var(--text-muted); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8fafc; }
.table.table-simple th, .table.table-simple td { padding: 10px 0; background: none; }
.table.table-simple th { width: 180px; }
.actions { white-space: nowrap; text-align: right; }

/* ── Badges ──────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-muted   { background: #f1f5f9; color: #64748b; }
.badge-warning { background: #fef9c3; color: #854d0e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-primary { background: #dbeafe; color: #1d4ed8; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--card-bg); color: var(--text);
  font-size: 13px; font-weight: 500; cursor: pointer;
  text-decoration: none; transition: background .15s, border-color .15s;
  white-space: nowrap; vertical-align: middle;
}
.btn:hover      { background: #f1f5f9; }
.btn-primary    { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger     { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm  { height: 30px; padding: 0 10px; font-size: 12px; }
.btn-full { width: 100%; height: 40px; }

/* ── Forms ───────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.required { color: var(--danger); }

.form-control {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 13.5px; color: var(--text); background: var(--card-bg);
  transition: border-color .15s, box-shadow .15s;
  height: 36px;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29,78,216,.1); }
textarea.form-control { height: auto; }
select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px;
}
.form-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; display: block; }
.form-row   { display: flex; gap: 16px; }
.form-row > .form-group { flex: 1; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
.toggle-label { display: flex !important; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; color: var(--text); font-weight: 500; }
.toggle-label input[type=checkbox] { width: 16px; height: 16px; flex-shrink: 0; }

/* ── Alerts ──────────────────────────────────────────────────────── */
.alert { padding: 10px 16px; border-radius: 6px; margin: 16px 24px 0; font-size: 13.5px; border: 1px solid transparent; }
.alert-success { background: #dcfce7; border-color: #86efac; color: #166534; }
.alert-error   { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.alert-info    { background: #dbeafe; border-color: #93c5fd; color: #1e40af; }
.alert-warning { background: #fef9c3; border-color: #fde047; color: #854d0e; }

/* ── Auth ────────────────────────────────────────────────────────── */
.auth-body  { background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.auth-wrap  { width: 100%; max-width: 400px; }
.auth-card  { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; }
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-logo  { max-height: 48px; max-width: 200px; }
.auth-brand-text { font-size: 20px; font-weight: 800; color: var(--text); }
.auth-title { font-size: 20px; font-weight: 700; margin-bottom: 20px; }
.auth-subtitle { color: var(--text-muted); font-size: 13.5px; margin-bottom: 16px; }
.auth-link  { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-muted); }
.auth-link a { color: var(--primary); text-decoration: none; }
.auth-footer { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 20px; }
.auth-card .alert { margin: 0 0 16px; }

/* ── Settings nav ────────────────────────────────────────────────── */
.settings-nav { display: flex; gap: 4px; margin-bottom: 20px; flex-wrap: wrap; }
.snav-item { padding: 7px 14px; border-radius: 6px; color: var(--text-muted); text-decoration: none; font-size: 13px; font-weight: 500; border: 1px solid transparent; }
.snav-item:hover { background: var(--card-bg); border-color: var(--border); color: var(--text); }
.snav-item.active { background: var(--card-bg); border-color: var(--border); color: var(--primary); font-weight: 600; }

/* ── Mail Cards nebeneinander ────────────────────────────────────── */
.mail-cards { display: flex; gap: 20px; align-items: flex-start; }
.mail-cards > .card { flex: 1; min-width: 0; }

/* ── Permissions ─────────────────────────────────────────────────── */
.perm-group { margin-bottom: 20px; }
.perm-group-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 10px; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.perm-item { display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500; }
.perm-item:hover { background: #f8fafc; }
.perm-item input { margin-top: 2px; flex-shrink: 0; }
.perm-key { font-size: 10px; color: var(--text-muted); font-weight: 400; margin-left: 4px; }

/* ── Stats ───────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.stat-card  { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stat-value { font-size: 32px; font-weight: 800; color: var(--text); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 6px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

/* ── Drop-Zone ───────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border); border-radius: 8px;
  padding: 32px 24px; text-align: center;
  transition: border-color .2s, background .2s; cursor: pointer;
}
.drop-zone.dragover { border-color: var(--primary); background: rgba(29,78,216,.04); }
.drop-icon   { font-size: 36px; margin-bottom: 8px; }
.drop-label  { font-size: 14px; font-weight: 500; color: var(--text); }
.drop-link   { color: var(--primary); cursor: pointer; text-decoration: underline; }
.drop-hint   { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.drop-filename { font-size: 13px; font-weight: 600; margin-top: 10px; }

/* ── Update log ──────────────────────────────────────────────────── */
.update-log { font-family: monospace; font-size: 12px; padding: 12px 16px; max-height: 300px; overflow-y: auto; background: #0f172a; color: #94a3b8; border-radius: 6px; }
.update-log .log-error { color: #f87171; }
.update-log .log-info  { color: #94a3b8; }

/* ── Misc ────────────────────────────────────────────────────────── */
.toolbar { display: flex; justify-content: flex-end; margin-bottom: 16px; gap: 8px; }
.text-muted  { color: var(--text-muted); }
.text-center { text-align: center; }
.empty-state { text-align: center; color: var(--text-muted); padding: 40px; }
code { font-family: monospace; font-size: 12px; background: #f1f5f9; padding: 1px 5px; border-radius: 3px; }

/* ── Plugin Accordion Nav ──────────────────────────────────── */
.nav-group { border: none; padding: 0; }
.nav-group summary { list-style: none; cursor: pointer; user-select: none; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group-summary { display: flex; align-items: center; gap: 10px; }
.nav-group-arrow { margin-left: auto; transition: transform .2s; flex-shrink: 0; opacity: .6; }
details[open] .nav-group-arrow { transform: rotate(180deg); }
.nav-child {
  padding-left: 32px !important;
  font-size: 12px !important;
  opacity: .85;
}
.nav-child.active { opacity: 1; }
.nav-child:hover { opacity: 1; }



/* ── Sidebar Toggle ──────────────────────────────────────────────────────── */
.sidebar        { transition: transform .22s ease; }
.main           { transition: margin-left .22s ease; }

.sidebar-collapsed .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
.sidebar-collapsed .main    { margin-left: 0; }

/* Button klebt am rechten Rand der Sidebar */
.sidebar-toggle {
  position: absolute;
  top: 50%;
  right: -28px;
  transform: translateY(-50%);
  width: 28px;
  height: 52px;
  background: var(--sidebar-bg);
  border: none;
  border-radius: 0 6px 6px 0;
  color: rgba(255,255,255,.6);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 101;
  transition: color .15s, background .15s;
  box-shadow: 2px 0 6px rgba(0,0,0,.15);
}
.sidebar-toggle:hover { color: #fff; background: #1e293b; }

/* Pfeil dreht sich beim Einklappen */
.sidebar-collapsed .sidebar-toggle {
  transform: translateY(-50%) rotate(180deg);
  border-radius: 6px 0 0 6px;
}

/* ── Sidebar Mobile Tools (Sprache + OPcache – nur auf Mobile sichtbar) ─── */
.sidebar-mobile-tools {
  display: none;
  gap: 4px;
  padding: 6px 8px 4px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex-wrap: wrap;
}

/* ── Mobile Overlay ──────────────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 99;
}

/* ── Hamburger (nur mobile sichtbar) ─────────────────────────────────────── */
.topbar-hamburger { display: none; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Sidebar: standardmäßig versteckt, als Overlay über Content */
  .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-w)));
    z-index: 200;
    transition: transform .22s ease;
  }

  /* Sidebar-Toggle-Pfeil im Sidebar-Rand: auf Mobile ausblenden */
  .sidebar-toggle { display: none; }

  /* Sidebar offen (via JS: body.sidebar-mobile-open) */
  .sidebar-mobile-open .sidebar  { transform: none !important; }
  .sidebar-mobile-open .sidebar-overlay { display: block; }

  /* Main: immer volle Breite auf Mobile */
  .main { margin-left: 0 !important; transition: none; }

  /* Desktop-Collapsed-Klasse auf Mobile überschreiben */
  .sidebar-collapsed .main { margin-left: 0; }

  /* Hamburger einblenden */
  .topbar-hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  /* Topbar kompakter */
  .topbar { padding: 0 12px; gap: 6px; }
  .page-title { font-size: 15px; }

  /* Topbar-Aktionen auf Mobile ausblenden (OPcache + Sprachumschalter) */
  .topbar-lang    { display: none !important; }
  .topbar-opcache { display: none !important; }

  /* Sprache + OPcache in Sidebar einblenden (als Ersatz) */
  .sidebar-mobile-tools { display: flex; }

  /* Content-Padding reduzieren */
  .content { padding: 12px; }
  .alert  { margin: 10px 12px 0; }

  /* Cards: Inhalt horizontal scrollbar */
  .card > .card-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Toolbar-Buttons wrappen */
  .toolbar { flex-wrap: wrap; }

  /* Form-Rows: untereinander */
  .form-row { flex-direction: column; gap: 0; }

  /* Stats: 2 Spalten */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-value { font-size: 24px; }

  /* Mail-Cards: stapeln */
  .mail-cards { flex-direction: column; }

  /* Berechtigungs-Grid: 1 Spalte */
  .perm-grid { grid-template-columns: 1fr; }

  /* Settings-Nav: kleiner */
  .settings-nav { gap: 2px; }
  .snav-item { padding: 5px 10px; font-size: 12px; }

  /* Footer-Grid: 2 Spalten → 1 Spalte */
  .footer-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 14px !important;
  }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .footer-grid { grid-template-columns: 1fr !important; }
}

/* ── cws-ticket Nachrichten-HTML ─────────────────────────────────────────── */
.cws-ticket-message { overflow-wrap: break-word; }
.cws-ticket-message p  { margin: 0 0 10px; }
.cws-ticket-message p:last-child { margin-bottom: 0; }
.cws-ticket-message ul, .cws-ticket-message ol { padding-left: 20px; margin: 0 0 10px; }
.cws-ticket-message blockquote {
  border-left: 3px solid var(--border);
  margin: 8px 0; padding: 6px 12px;
  color: var(--text-muted); font-style: italic;
}
.cws-ticket-message a { color: var(--primary); }
.cws-ticket-message img { max-width: 100%; height: auto; }
