html, body { height: 100%; }

:root {
  --wc-bg: #f5f7fb;
  --wc-text: #0f172a;
  --wc-border: rgba(15, 23, 42, 0.08);
  --wc-primary: #3b82f6;
  --wc-primary-2: #6366f1;
  --wc-muted: rgba(15, 23, 42, 0.62);
  --wc-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--wc-bg);
  color: var(--wc-text);
}

.sidebar {
  width: 280px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: #ffffff;
  border-right: 1px solid var(--wc-border);
  z-index: 1040;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 18px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(59,130,246,0.12), rgba(99,102,241,0.08));
  border: 1px solid rgba(59,130,246,0.16);
  margin-bottom: 16px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #1e40af;
  background: rgba(59,130,246,0.18);
}

.brand-title { font-weight: 800; line-height: 1.1; }
.brand-subtitle { font-size: 12px; opacity: 0.75; }

.sidebar-section {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(15, 23, 42, 0.55);
  padding: 10px 10px 6px;
}

.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  color: rgba(15, 23, 42, 0.82);
  font-weight: 600;
  text-decoration: none;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.sidebar .nav-link:hover {
  background: rgba(59, 130, 246, 0.08);
  color: #0b2a7a;
}

.sidebar .nav-link.active {
  background: rgba(59, 130, 246, 0.14);
  color: #0b2a7a;
  border: 1px solid rgba(59, 130, 246, 0.18);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
}

.user-pill {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid rgba(15, 23, 42, 0.06);
}

.user-name { font-weight: 750; }
.user-role { font-size: 12px; opacity: 0.7; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(245, 247, 251, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-title { font-weight: 800; }
.topbar-user { font-weight: 600; opacity: 0.85; }

.content { min-height: 0; }

.card { border-radius: 1rem; }
.card-header { border-top-left-radius: 1rem; border-top-right-radius: 1rem; }

.kpi-card {
  box-shadow: var(--wc-shadow);
}

.kpi-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

/* Charts */
.wc-chart {
  width: 100%;
  min-height: 220px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--wc-border);
  box-shadow: inset 0 1px 0 rgba(15, 23, 42, 0.03);
  padding: 14px;
}

.wc-chart.is-compact { min-height: 190px; }

.wc-chart .wc-chart-wrap {
  display: flex;
  gap: 14px;
  align-items: center;
}

.wc-chart .wc-chart-legend {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
}

.wc-chart .wc-chart-legend li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--wc-text);
}

.wc-chart .wc-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
  flex: 0 0 auto;
}

.wc-chart .wc-legend-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.wc-chart .wc-legend-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
  color: rgba(15, 23, 42, 0.86);
}

.wc-chart .wc-legend-value {
  font-variant-numeric: tabular-nums;
  color: rgba(15, 23, 42, 0.68);
}

.wc-chart .wc-empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: rgba(15, 23, 42, 0.6);
  font-size: 14px;
}

/* Mobile sidebar overlay/offcanvas */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 1030;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px !important;
    transform: translateX(-105%);
    transition: transform 160ms ease;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.18);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .sidebar-overlay { display: block; }
  .content { padding: 16px !important; }
}

@media (max-width: 992px) {
  .sidebar { width: 240px; }
}

/* ── Mobile & Responsive Improvements ───────────────────────── */

/* Tabellen horizontal scrollbar mit Fade-Indikator */
.table-responsive {
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 768px) {
  .table-responsive::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 32px;
    background: linear-gradient(to left, rgba(255,255,255,0.95), transparent);
    pointer-events: none;
    border-radius: 0 1rem 1rem 0;
  }
  .table-responsive { position: relative; }

  /* Kompaktere Tabellen auf Mobile */
  .table-sm td, .table-sm th { padding: 0.35rem 0.5rem; font-size: .82rem; }

  /* Karten */
  .card { border-radius: 0.75rem; }
  .card-header { padding: 0.65rem 1rem; }
  .card-body { padding: 0.875rem; }

  /* KPI-Karten */
  .kpi-value { font-size: 22px; }

  /* Topbar: Benutzername auf kleinen Schirmen ausblenden */
  .topbar-user { display: none; }

  /* Buttons touch-freundlicher */
  .btn { min-height: 38px; }
  .btn-sm { min-height: 32px; font-size: .82rem; }

  /* Formulare: volle Breite auf Mobile */
  .form-control, .form-select { font-size: 16px; } /* Verhindert Zoom auf iOS */

  /* Container: weniger Padding */
  .container-fluid { padding-left: 12px !important; padding-right: 12px !important; }

  /* Row mit negativem Margin anpassen */
  .row { --bs-gutter-x: 0.75rem; }

  /* Seitenabstand im Content-Bereich */
  .content { padding: 14px !important; }

  /* h3 Überschriften kleiner */
  .h3 { font-size: 1.15rem; }

  /* Alert kompakter */
  .alert { padding: 0.65rem 1rem; font-size: .88rem; }

  /* Accordion Buttons */
  .accordion-button { font-size: .88rem; padding: 0.65rem 1rem; }

  /* Modal auf Mobile fast vollbild */
  .modal-dialog { margin: 0.5rem; }

  /* Badges */
  .badge { font-size: .72rem; }

  /* Progress bars kleiner */
  .progress { height: 4px !important; }

  /* Flex-Wrap erzwingen in Action-Bereichen */
  .d-flex.gap-2 { flex-wrap: wrap; }

  /* Navtoggle besser sichtbar */
  #navToggle { padding: 6px 10px; font-size: 1.1rem; }
}

/* Tablet (768–992px) */
@media (min-width: 769px) and (max-width: 992px) {
  .sidebar { width: 220px; }
  .sidebar-inner { padding: 14px 12px; }
  .kpi-value { font-size: 24px; }
  .sidebar .nav-link { padding: 9px 10px; font-size: .9rem; }
}

/* Sidebar-Transition (smooth overlay) */
.sidebar { transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1); }
.sidebar-overlay { transition: opacity 200ms ease; opacity: 0; }
body.nav-open .sidebar-overlay { opacity: 1; display: block; }

/* Sticky Action-Buttons auf Mobile */
@media (max-width: 576px) {
  /* Stacked form buttons */
  .form-actions-row { flex-direction: column !important; }
  .form-actions-row .btn { width: 100% !important; }

  /* KPI-Cards in 2 Spalten erzwingen */
  .kpi-row > [class*="col-"] { flex: 0 0 50%; max-width: 50%; }
}

/* Print improvements */
@media print {
  .sidebar, #sidebarOverlay, .topbar, footer,
  #navToggle, .btn, .alert { display: none !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; }
  body { background: white !important; }
  .container-fluid { padding: 0 !important; }
  a[href]::after { content: none !important; }
}
