/* ── Design Tokens ────────────────────────────────────────────── */
:root {
  /* Brand */
  --accent:           #0d6efd;
  --accent-hover:     #0b5ed7;
  --accent-subtle:    rgba(13, 110, 253, 0.15);

  /* Surfaces */
  --bg:               #111316;
  --surface:          #1a1d21;
  --surface-2:        #212529;
  --surface-3:        #2d3035;

  /* Borders */
  --border:           #2d3035;
  --border-subtle:    #383d44;

  /* Text */
  --text-primary:     #dee2e6;
  --text-secondary:   #adb5bd;
  --text-muted:       #6c757d;

  /* Sidebar */
  --sidebar-w:        210px;
  --sidebar-w-sm:     56px;

  /* Spacing (4 / 8 px rhythm) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  /* Typography */
  --fs-xs:   0.75rem;
  --fs-sm:   0.875rem;
  --fs-base: 1rem;
  --fs-lg:   1.125rem;
  --lh-body: 1.6;
  --lh-head: 1.3;

  /* Radius */
  --r-sm:   6px;
  --r-md:   10px;
  --r-lg:   14px;
  --r-full: 50px;

  /* Transitions */
  --t-fast:   150ms ease;
  --t-normal: 200ms ease;
  --t-slow:   300ms ease;

  /* Shadows */
  --shadow-sm:     0 1px 3px rgba(0,0,0,.35);
  --shadow-md:     0 4px 14px rgba(0,0,0,.45);
  --shadow-accent: 0 0 0 1px var(--accent), 0 4px 16px rgba(13,110,253,.18);
  --shadow-focus:  0 0 0 3px rgba(13,110,253,.4);
}

/* ── Reset / Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  height: 100%;
  overflow: hidden;
}

body {
  background-color: var(--bg);
  color: var(--text-primary);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  margin: 0;
  height: 100%;
  overflow: hidden;
}

/* ── Skip to content (accessibility) ─────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--sp-4);
  z-index: 9999;
  padding: var(--sp-2) var(--sp-4);
  background: var(--accent);
  color: #fff;
  border-radius: 0 0 var(--r-sm) var(--r-sm);
  font-weight: 600;
  text-decoration: none;
  transition: top var(--t-fast);
}
.skip-link:focus {
  top: 0;
}

/* ── Focus-visible (accessible ring, dark-mode-friendly) ─────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}
/* Remove default outline when focus-visible is set */
:focus:not(:focus-visible) {
  outline: none;
}

/* ── App layout (sidebar + main) ─────────────────────────────── */
.app-layout {
  display: flex;
  position: fixed;
  inset: 0;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--t-normal);
  z-index: 100;
}

.sidebar.collapsed {
  width: var(--sidebar-w-sm);
}

/* Brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  padding: var(--sp-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  color: var(--text-primary);
  text-decoration: none;
  flex-shrink: 0;
  gap: 0;
  min-height: 56px;
  transition: color var(--t-fast);
}
.sidebar-brand:hover { color: #fff; }
.sidebar-brand i { font-size: 1.25rem; flex-shrink: 0; }

/* Nav area */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-2) 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  margin: 2px 6px;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  transition: background var(--t-fast), color var(--t-fast);
  min-height: 44px;
}

.sidebar-link:hover {
  background: var(--surface-3);
  color: #fff;
}

.sidebar-link.active {
  background: var(--accent-subtle);
  color: #6ea8fe;
}

.sidebar-link i {
  font-size: 1.1rem;
  flex-shrink: 0;
  width: 1.25rem;
  text-align: center;
}

/* Nav group labels (now buttons) */
.nav-group-label {
  display: flex;
  align-items: center;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: var(--sp-4) var(--sp-3) var(--sp-1) var(--sp-4);
  white-space: nowrap;
  overflow: hidden;
  transition: color var(--t-fast), opacity var(--t-normal), height var(--t-normal), padding var(--t-normal);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  gap: var(--sp-1);
}
.nav-group-label:hover { color: var(--text-secondary); }

.nav-group-chevron {
  margin-left: auto;
  font-size: 0.6rem;
  transition: transform var(--t-normal);
  flex-shrink: 0;
}

/* Collapsed group: chevron rotates, items hidden */
.nav-group-label.collapsed .nav-group-chevron {
  transform: rotate(-90deg);
}

.nav-group-items {
  overflow: hidden;
  transition: max-height var(--t-slow) ease;
  max-height: 500px; /* large enough for any group */
}
.nav-group-items.collapsed {
  max-height: 0;
}

/* Hide group labels + items when sidebar is icon-only */
.sidebar.collapsed .nav-group-label {
  opacity: 0;
  height: 0;
  padding-top: 0;
  padding-bottom: 0;
  pointer-events: none;
  overflow: hidden;
}
.sidebar.collapsed .nav-group-items {
  max-height: 500px !important; /* always show items in collapsed sidebar */
}

/* First group label gets less top padding */
.sidebar-nav .nav-group-label:first-child {
  padding-top: var(--sp-2);
}

/* User info at bottom */
.sidebar-user {
  flex-shrink: 0;
}

/* Toggle button at bottom */
.sidebar-toggle {
  flex-shrink: 0;
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.65rem var(--sp-4);
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-size: var(--fs-base);
  transition: color var(--t-fast), background var(--t-fast);
  min-height: 44px;
}

.sidebar-toggle:hover {
  color: var(--text-primary);
  background: var(--surface-3);
}

/* Hide labels when collapsed */
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-brand .nav-label {
  opacity: 0;
  width: 0;
  overflow: hidden;
  display: inline-block;
}

.sidebar.collapsed .sidebar-toggle { text-align: center; }
.sidebar.collapsed .sidebar-link   { justify-content: center; gap: 0; }
.sidebar.collapsed .sidebar-brand  { justify-content: center; }

/* ── Main content area ───────────────────────────────────────── */
.app-main {
  flex: 1;
  min-width: 0;
  padding: var(--sp-6) 1.75rem;
  overflow-y: auto;
  min-height: 0;
}

/* ── Page entrance animation ─────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0.4; transform: translateY(4px); }
  to   { opacity: 1;   transform: translateY(0); }
}

.app-main > * {
  animation: fadeUp 150ms ease both;
}

.app-main > .modal {
  animation: none;
}

.modal-backdrop {
  z-index: 1050 !important;
  display: none !important;
  pointer-events: none !important;
}

.modal {
  z-index: 1055 !important;
  pointer-events: auto;
}

/* Disable motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background-color: var(--surface);
  border-color: var(--border);
  border-radius: var(--r-md);
  transition: box-shadow var(--t-normal), border-color var(--t-normal);
}

/* All interactive cards (project, filament, printer roll, etc.) */
.card-interactive:hover,
.card-project:hover {
  box-shadow: var(--shadow-accent);
  border-color: var(--accent);
}

/* Subtle hover for non-primary cards */
.card:not(.card-interactive):not(.card-project):hover {
  box-shadow: var(--shadow-sm);
}

.card-footer {
  background-color: transparent;
  border-color: var(--border);
}

.card-header {
  border-color: var(--border);
}

/* ── Project thumbnails ──────────────────────────────────────── */
.project-thumb-link {
  color: inherit;
  display: block;
  text-decoration: none;
}

.project-card-thumb {
  aspect-ratio: 16 / 9;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  border-radius: var(--r-md) var(--r-md) 0 0;
  display: block;
  object-fit: cover;
  width: 100%;
}

.project-card-thumb-empty,
.project-detail-thumb-empty {
  align-items: center;
  color: var(--text-muted);
  display: flex;
  font-size: 2rem;
  justify-content: center;
}

.project-detail-thumb {
  aspect-ratio: 16 / 9;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  border-radius: var(--r-md) var(--r-md) 0 0;
  display: block;
  object-fit: cover;
  width: 100%;
}

/* ── Tables ──────────────────────────────────────────────────── */
.table-dark {
  --bs-table-bg: var(--surface);
  --bs-table-hover-bg: #22262b;
  --bs-table-striped-bg: #1e2126;
  border-color: var(--border);
}

.table-secondary {
  --bs-table-bg: #1e2126;
  color: var(--text-secondary);
}

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
  font-size: var(--fs-xs);
  letter-spacing: .03em;
  font-weight: 500;
}

/* ── Progress bar ────────────────────────────────────────────── */
.progress {
  background-color: var(--surface-3);
  border-radius: var(--r-full);
}

.progress-bar {
  transition: width var(--t-slow);
}

/* ── Buttons — touch targets & states ────────────────────────── */
.btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  transition: background-color var(--t-fast), border-color var(--t-fast),
              color var(--t-fast), box-shadow var(--t-fast),
              transform var(--t-fast);
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

/* Smaller variants keep touch targets via padding, not min-height override */
.btn-sm {
  min-height: 36px;
}

/* Loading state: spinner replaces icon, disables interaction */
.btn-loading {
  pointer-events: none;
  opacity: 0.75;
  position: relative;
}
.btn-loading::after {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: var(--sp-2);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Forms ───────────────────────────────────────────────────── */
.form-control,
.form-select {
  background-color: #1e2126;
  border-color: #3a3f46;
  color: var(--text-primary);
  color-scheme: dark;
  min-height: 44px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.form-control:focus,
.form-select:focus {
  background-color: #1e2126;
  border-color: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-focus);
}

.form-select option {
  background-color: #1e2126;
  color: var(--text-primary);
}

.form-control::placeholder { color: var(--text-muted); }

input[type="file"].form-control { padding: .45rem .75rem; }

/* Textarea doesn't need min-height */
textarea.form-control { min-height: unset; }

/* Form label spacing */
.form-label {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--sp-1);
}

/* Validation states */
.form-control.is-invalid,
.form-select.is-invalid {
  border-color: #dc3545;
  box-shadow: 0 0 0 3px rgba(220,53,69,.25);
}

.form-control.is-valid,
.form-select.is-valid {
  border-color: #198754;
  box-shadow: 0 0 0 3px rgba(25,135,84,.25);
}

/* ── Alerts ──────────────────────────────────────────────────── */
.alert {
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
}

/* ── QR preview ─────────────────────────────────────────── */
.qr-preview {
  background: #fff;
  border-radius: var(--r-sm);
  display: inline-flex;
  padding: 12px;
}

.qr-preview img {
  display: block;
  height: 180px;
  width: 180px;
}

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  padding: var(--sp-7) var(--sp-5);
  color: var(--text-muted);
  text-align: center;
}

.empty-state i {
  font-size: 3rem;
  opacity: 0.4;
}

.empty-state-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0;
}

.empty-state-desc {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin: 0;
  max-width: 320px;
  line-height: 1.5;
}

/* ── Skeleton loading ─────────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -600px 0; }
  100% { background-position:  600px 0; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-3) 25%,
    var(--border-subtle) 50%,
    var(--surface-3) 75%
  );
  background-size: 600px 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--r-sm);
}

.skeleton-text  { height: 1em; margin-bottom: var(--sp-2); }
.skeleton-title { height: 1.4em; width: 60%; margin-bottom: var(--sp-3); }
.skeleton-btn   { height: 44px; width: 120px; border-radius: var(--r-sm); }

/* ── BambuLab Dashboard ──────────────────────────────────────── */
#bambuDashboard {
  will-change: transform;
  transform: translateZ(0);
  contain: paint;
}

.bambu-stat-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: none !important;
  box-shadow: none !important;
}

.bambu-live {
  will-change: contents;
  transform: translateZ(0);
  display: block;
}

/* ── Utilities ───────────────────────────────────────────────── */
.btn-xs { padding: .1rem .35rem; font-size: .7rem; line-height: 1.4; border-radius: .2rem; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .4; }
}

/* ── Project detail: Mobile execution view (legacy, kept for safety) ── */
.mob-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 0.5px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}
.mob-header-title {
  flex: 1;
  min-width: 0;
}
.mob-header-title h1 {
  font-size: var(--fs-lg);
  font-weight: 500;
  margin: 0;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mob-header-title .mob-proj-id {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

/* Progress ring */
.mob-ring-card {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5);
  margin: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--r-md);
}
.mob-ring-wrap {
  position: relative;
  flex-shrink: 0;
}
.mob-ring {
  transform: rotate(-90deg);
  display: block;
}
.mob-ring-bg    { fill: none; stroke: var(--surface-3); stroke-width: 5; }
.mob-ring-fill  { fill: none; stroke: #198754; stroke-width: 5;
                  stroke-linecap: round; transition: stroke-dashoffset var(--t-slow); }
.mob-ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-primary);
}

/* Section headers */
.mob-section-head {
  padding: var(--sp-3) var(--sp-4) var(--sp-2);
  font-size: var(--fs-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.mob-section-count {
  background: var(--surface-3);
  border-radius: var(--r-full);
  padding: 1px 7px;
  font-size: .65rem;
}

/* Part rows */
.mob-part-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  min-height: 60px;
  cursor: pointer;
  border-bottom: 0.5px solid var(--border);
  transition: background var(--t-fast);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}
.mob-part-row:active,
.mob-part-row.mob-tapping { background: var(--surface-3); }

.mob-part-row.mob-selected { background: rgba(13,110,253,.12); }

.mob-part-info { flex: 1; min-width: 0; }
.mob-part-name {
  font-size: var(--fs-base);
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mob-part-sub {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 2px;
}
.mob-part-circle {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.mob-part-row:active .mob-part-circle,
.mob-part-row.mob-tapping .mob-part-circle {
  border-color: #198754;
}
.mob-part-row.mob-selected .mob-part-circle {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

/* Done rows */
.mob-part-row.mob-done {
  opacity: .55;
  cursor: default;
}
.mob-part-row.mob-done .mob-part-name {
  text-decoration: line-through;
  color: var(--text-muted);
}
.mob-part-row.mob-done .mob-part-circle {
  border-color: #198754;
  background: rgba(25,135,84,.15);
}

/* Flying-to-done animation */
@keyframes rowDone {
  0%   { transform: translateX(0);    opacity: 1; }
  60%  { transform: translateX(12px); opacity: 0.7; }
  100% { transform: translateX(0);    opacity: 0.55; }
}
.mob-part-row.mob-animating { animation: rowDone 300ms ease forwards; }

/* Bottom action bar */
.mob-action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 0.5px solid var(--border);
  display: flex;
  gap: var(--sp-3);
  z-index: 50;
}
.mob-action-bar .btn { flex: 1; }

/* Bottom bar spacer */
.mob-bottom-spacer { height: calc(80px + env(safe-area-inset-bottom)); }

/* Project done banner */
.mob-done-banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-7) var(--sp-5);
  text-align: center;
}

/* Long-press weight modal footer note */
.mob-longpress-note {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: var(--sp-2);
}

/* Multi-select confirm button (hidden by default) */
.mob-bulk-confirm { display: none; }
.mob-multi-mode .mob-bulk-confirm { display: flex; }
.mob-multi-mode .mob-multi-btn    { display: none; }

/* Breakpoint guard: only render mobile layout on narrow screens */
@media (min-width: 768px) {
  .d-project-mobile { display: none !important; }
}
@media (max-width: 767.98px) {
  .d-project-desktop { display: none !important; }
  /* On mobile, suppress top-header offset – mob-header is sticky instead */
  .app-main { padding-top: 0 !important; }
}

/* ── Bibliothek: Stepper ─────────────────────────────────────── */
.step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: 600;
  flex-shrink: 0;
  transition: background var(--t-normal), border-color var(--t-normal);
}
.step-dot.active { background: var(--accent);  border-color: var(--accent);  color: #fff; }
.step-dot.done   { background: #198754;         border-color: #198754;        color: #fff; }

/* ── Bibliothek: Drag & Drop ─────────────────────────────────── */
.lib-pair-card {
  cursor: grab;
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.lib-pair-card:active { cursor: grabbing; }
.lib-pair-card:hover  {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.lib-pair-assigned              { border-color: #198754 !important; }
.lib-pair-assigned .bi-grip-vertical { color: #198754 !important; }

.drop-target {
  transition: border-color var(--t-fast), background var(--t-fast);
  border: 1px solid var(--border);
}
.drop-target.lib-drop-over {
  border-color: var(--accent) !important;
  background: rgba(99,102,241,.12) !important;
  box-shadow: 0 0 0 2px var(--accent);
}

.unpaired-list .unpaired-item {
  font-size: var(--fs-xs);
  line-height: 1.3;
  border-radius: var(--r-sm);
}
.unpaired-list .unpaired-item:not(.active) {
  color: var(--text-primary);
  border: 1px solid var(--border);
  background: transparent;
}

/* ── Touch / Mobile globals ───────────────────────────────────── */
/* Remove 300 ms tap delay on all interactive elements */
a, button, [role="button"], input, select, textarea, label {
  touch-action: manipulation;
}

/* Suppress iOS blue tap flash */
a, button, [role="button"] {
  -webkit-tap-highlight-color: transparent;
}

/* Momentum scrolling on iOS */
.app-main {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* ── Responsive ──────────────────────────────────────────────── */
/* Auto-collapse sidebar on narrow screens */
@media (max-width: 860px) {
  .sidebar:not(.collapsed) { width: var(--sidebar-w-sm); }
  .sidebar:not(.collapsed) .nav-label,
  .sidebar:not(.collapsed) .sidebar-brand .nav-label {
    opacity: 0; width: 0; overflow: hidden; display: inline-block;
  }
  .sidebar:not(.collapsed) .nav-group-label {
    opacity: 0; height: 0; padding-top: 0; padding-bottom: 0; pointer-events: none;
  }
  .sidebar:not(.collapsed) .sidebar-link   { justify-content: center; gap: 0; }
  .sidebar:not(.collapsed) .sidebar-brand  { justify-content: center; }
  .sidebar:not(.collapsed) .sidebar-toggle { text-align: center; }
}

/* ── Mobile: Drawer + Top-Header ─────────────────────────────── */
@media (max-width: 575px) {

  /* Top header bar */
  .mobile-header {
    display: flex !important;
    align-items: center;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: calc(52px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    padding-left: var(--sp-4);
    padding-right: var(--sp-4);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 30;   /* above sidebar (20) and backdrop (10) */
    gap: var(--sp-3);
  }
  .mobile-header-title {
    flex: 1;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mobile-header-title i { color: var(--accent); margin-right: 6px; }
  .mobile-menu-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: var(--sp-2);
    font-size: 1.35rem;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-sm);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .mobile-menu-btn:active { background: var(--surface-3); }

  /* Backdrop — now inside app-layout (same stacking context as sidebar) */
  .mobile-drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 10;   /* above main content (auto/0), below sidebar (20) */
    pointer-events: none;
  }
  .mobile-drawer-backdrop.open { display: block; pointer-events: auto; }

  /* Sidebar becomes a left drawer */
  .sidebar,
  .sidebar.collapsed {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 260px !important;
    height: 100% !important;
    flex-direction: column !important;
    border-right: 1px solid var(--border) !important;
    border-top: none !important;
    z-index: 20 !important;  /* above backdrop (10), within same stacking context */
    transform: translateX(-100%);
    transition: transform 200ms ease !important;
    padding-bottom: env(safe-area-inset-bottom);
    padding-top: env(safe-area-inset-top);
  }
  .sidebar.mobile-open {
    transform: translateX(0) !important;
  }

  /* Restore full labels inside drawer */
  .sidebar .nav-label,
  .sidebar.collapsed .nav-label {
    display: inline-block !important;
    opacity: 1 !important;
    width: auto !important;
    overflow: visible !important;
    font-size: var(--fs-sm) !important;
    line-height: 1.4 !important;
  }
  .sidebar-link,
  .sidebar.collapsed .sidebar-link {
    flex-direction: row !important;
    justify-content: flex-start !important;
    align-items: center !important;
    gap: 0.75rem !important;
    min-width: unset !important;
    min-height: 44px !important;
    padding: 0.55rem 0.75rem !important;
    margin: 2px 6px !important;
    border-radius: var(--r-sm) !important;
    font-size: var(--fs-sm) !important;
    overflow: visible !important;
    white-space: normal !important;
  }
  .sidebar-link i,
  .sidebar.collapsed .sidebar-link i {
    font-size: 1.1rem !important;
    width: 1.25rem !important;
  }
  .sidebar-brand { display: flex !important; }
  .sidebar-user  { display: flex !important; }
  .sidebar-toggle { display: none !important; }

  /* Wenn Sidebar als Drawer offen ist: collapsed-Styles für Gruppen-Labels zurücksetzen */
  .sidebar.collapsed .nav-group-label {
    opacity: 1 !important;
    height: auto !important;
    padding: var(--sp-4) var(--sp-3) var(--sp-1) var(--sp-4) !important;
    pointer-events: auto !important;
    overflow: visible !important;
    color: var(--text-muted);
  }
  .sidebar.collapsed .nav-group-label .nav-label {
    display: inline !important;
    opacity: 1 !important;
    width: auto !important;
  }
  .sidebar.collapsed .nav-group-chevron {
    display: inline-block !important;
  }
  /* Gruppen-Items immer sichtbar im Drawer */
  .sidebar.collapsed .nav-group-items {
    max-height: 500px !important;
  }
  /* Brand-Label im Drawer sichtbar */
  .sidebar.collapsed .sidebar-brand .nav-label {
    display: inline-block !important;
    opacity: 1 !important;
    width: auto !important;
  }

  /* Main content: offset by top header, full width */
  .app-layout { padding-bottom: 0; }
  .app-main {
    padding: calc(52px + env(safe-area-inset-top) + var(--sp-4)) 0.9rem var(--sp-6) !important;
  }

  /* Tables on mobile */
  .table-responsive td,
  .table-responsive th { font-size: var(--fs-xs); padding: 0.35rem 0.5rem; }

  /* Reduce h2 on mobile */
  h2 { font-size: 1.25rem; }
}
