:root {
  color-scheme: light dark;
  --surface-0: #0e0e11;
  --surface-1: #141418;
  --surface-2: #1a1a1f;
  --accent-color: #6366F1;
  --accent-soft: rgba(99, 102, 241, 0.16);
  --accent-muted: rgba(99, 102, 241, 0.35);
  --accent-contrast: #F9FAFB;
  /* Control bar dynamic spacing */
  --controls-offset: 200px; /* default viewer padding to clear controls */
  --controls-bottom-expanded: calc(env(safe-area-inset-bottom, 0px) + 32px);
  --controls-bottom-min: calc(env(safe-area-inset-bottom, 0px) + 72px);
}

/* Dynamic viewport height - works with iOS/iPad Safari toolbar */
html, body { 
  height: 100%; 
  height: 100dvh; /* Dynamic viewport height - shrinks when Safari shows toolbars */
}

body {
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent-color) 10%, var(--surface-0)) 0%, var(--surface-0) 55%, var(--surface-1) 100%);
  transition: background 0.4s ease;
  min-height: 0; /* Allow shrinking */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

main#app {
  flex: 1 1 0; /* Take all available space, can shrink */
  min-height: 0; /* Critical for flex children to shrink properly */
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.vh { height: 100vh; height: 100dvh; }

.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* iOS smoother programmatic scrolling */
#viewer { 
  -webkit-overflow-scrolling: touch;
}

.card:hover { transform: translateY(-2px); }

.tap-highlight-none { -webkit-tap-highlight-color: rgba(0,0,0,0); }

/* iOS/iPad safe-area handling + fullscreen fixes */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  /* Control bar sizing - single source of truth */
  --control-bar-height: 120px; /* Approximate height including padding */
  --control-bottom-spacing: 8px; /* Minimal aesthetic spacing from screen edge */
  --control-top-margin: 16px;    /* Space above control panel (scroll clearance) */
}

/* In fullscreen hide header and add top safe padding to viewer */
html.is-fs header { 
  display: none !important; 
}

html.is-fs #viewerPdfContainer {
  border-radius: 0;
  border: none;
}

html.is-fs #controls {
  background: transparent;
}

html.is-fs .control-panel {
  background: transparent;
  border: none;
  box-shadow: none;
}

/* Active accent color effect on header */
body[data-accent-active="true"] #mainHeader > div {
  border-color: var(--accent-muted) !important;
  background: linear-gradient(to bottom,
    color-mix(in srgb, var(--accent-color) 12%, rgba(12,12,15,0.95)),
    color-mix(in srgb, var(--accent-color) 8%, rgba(12,12,15,0.90)),
    color-mix(in srgb, var(--accent-color) 6%, rgba(12,12,15,0.85))
  ) !important;
}

.category-pill {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}

.category-pill:hover {
  transform: translateY(-1px) scale(1.02);
  box-shadow: 0 4px 12px -4px rgba(0,0,0,0.4);
}

.category-pill:active {
  transform: translateY(0) scale(0.98);
}

.category-pill.is-selected {
  box-shadow: 0 0 0 2px rgba(250, 250, 255, 0.25);
}

/* Manage Categories Button */
#btnManageCategories {
  min-width: 36px; /* Ensure icon-only button is square on mobile */
}

#btnManageCategories svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.category-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  text-shadow: 0 1px 1px rgba(0,0,0,0.25);
}

.badge-stack {
  max-height: 4.5rem;
  overflow: hidden;
  position: relative;
  padding-bottom: 0.35rem;
}

.badge-stack::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 28px;
  background: linear-gradient(to bottom, rgba(9,9,12,0) 0%, rgba(9,9,12,0.9) 100%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.badge-stack.is-overflowing::after {
  opacity: 1;
}

.glass-panel {
  backdrop-filter: blur(28px);
  background: rgba(15, 15, 21, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  box-shadow: 0 24px 48px -32px rgba(0, 0, 0, 0.65);
}

/* Music Card Collection */
.music-card {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  background: linear-gradient(160deg, var(--card-accent, var(--accent-color)) 0%, color-mix(in srgb, var(--card-accent, var(--accent-color)) 20%, #000) 100%);
  box-shadow: 0 12px 24px -12px rgba(0, 0, 0, 0.6);
  transition: transform 0.3s ease, box-shadow 0.3s ease, filter 0.3s ease;
  cursor: pointer;
}

.music-card:hover { 
  transform: translateY(-4px); 
  box-shadow: 0 18px 36px -12px rgba(0, 0, 0, 0.7); 
}

.music-card .card-bg {
  width: 100%;
  height: 220px;
  object-fit: cover;
  filter: brightness(0.9);
  display: block;
}

/* Lazy loading thumbnail styles for fast initial render */
.music-card .card-bg.lazy-thumb {
  background: linear-gradient(135deg, #1a1a1f 0%, #262630 50%, #1a1a1f 100%);
  background-size: 200% 200%;
  animation: shimmer 1.5s ease-in-out infinite;
}

.music-card .card-bg.thumb-loading {
  opacity: 0;
}

.music-card .card-bg.thumb-loaded {
  animation: fadeIn 0.3s ease-out forwards;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

@media (min-width: 640px) { 
  .music-card .card-bg { height: 240px; } 
}

.music-card:hover .card-bg { filter: brightness(1.03); }

.music-card .card-overlay {
  position: absolute; 
  inset: auto 0 0 0;
  padding: 1rem;
  background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.6) 100%);
  text-align: center;
}

.music-card .card-title { 
  font-weight: 600; 
  font-size: 1rem; 
  color: #fff; 
}

.music-card .card-subtitle { 
  font-size: 0.875rem; 
  color: rgba(255,255,255,0.82); 
}

.music-card .icon-btn {
  height: 36px; 
  width: 36px;
  display: grid; 
  place-items: center;
  border-radius: 9999px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  color: #e5e7eb;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
}

.music-card .icon-btn svg {
  display: block;
  margin: 0 auto;
}

.music-card .icon-btn:hover { 
  background: rgba(255,255,255,0.16); 
  border-color: rgba(255,255,255,0.26); 
}

.music-card .icon-btn:active { 
  transform: translateY(1px); 
}

.music-card .card-actions { 
  margin-top: 0.5rem; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  gap: 0.5rem; 
}

/* Ensure all SVGs in buttons with grid place-items-center are perfectly centered */
button.grid.place-items-center svg {
  display: block;
  margin: 0 auto;
}

/* Ensure favorite star on cards turns yellow when active */
.music-card .icon-btn.fav.text-yellow-400 { color: #facc15; }
.music-card .icon-btn.fav.text-neutral-300 { color: #d1d5db; }

.music-card .icon-btn.offline-active {
  background: rgba(34, 197, 94, 0.18);
  border-color: rgba(134, 239, 172, 0.55);
  color: #bbf7d0;
}

.music-card .icon-btn.offline-active:hover {
  background: rgba(34, 197, 94, 0.25);
  border-color: rgba(134, 239, 172, 0.8);
}

.badge-offline {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #22c55e;
  color: #0f172a;
  border-radius: 999px;
  padding: 0 0.4rem;
  font-size: 0.65rem;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.35);
}

.offline-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.18);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #bbf7d0;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Playlist Card Hover Effects - Glassmorphism */
.playlist-card {
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.playlist-card::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 0.75rem;
  padding: 1px;
  background: linear-gradient(135deg, 
    rgba(255, 255, 255, 0.1), 
    rgba(255, 255, 255, 0.05)
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.playlist-card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 
    0 20px 40px -16px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.playlist-card:hover::before {
  opacity: 1;
}

.playlist-card:hover .playlist-card-bg {
  backdrop-filter: blur(32px);
}

.playlist-card:active {
  transform: translateY(-2px) scale(1.01);
}

/* Enhance playlist card buttons on card hover */
.playlist-card:hover .playlist-play-btn,
.playlist-card:hover .playlist-edit-btn {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

.offline-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 999px;
  background: currentColor;
  display: inline-flex;
}

.btn-offline {
  position: relative;
}

.btn-offline[disabled] {
  opacity: 0.6;
}

.offline-spinner {
  width: 1.1rem;
  height: 1.1rem;
  animation: spin 0.9s linear infinite;
}

#libraryPager {
  padding: 1.5rem 0;
  min-height: 80px; /* Ensure minimum touchable height on iPad */
  padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px)); /* Account for iOS safe area */
}

@media (max-width: 540px) {
  #libraryPager { 
    padding: 1.25rem 0;
    padding-bottom: calc(1.75rem + env(safe-area-inset-bottom, 0px));
  }
  .filter-toggle {
    display: inline-flex;
  }
}

.filter-toggle {
  display: none;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(17,17,23,0.6);
  color: #e5e7eb;
  font-size: 0.85rem;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.filter-toggle:hover {
  background: rgba(24,24,32,0.75);
  border-color: rgba(255,255,255,0.2);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    rgba(8, 8, 12, 0.85) 0%,
    rgba(4, 4, 6, 0.92) 100%
  );
  backdrop-filter: blur(24px) saturate(120%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 1.25rem;
  animation: backdropFadeIn 0.3s ease-out;
}

@keyframes backdropFadeIn {
  from {
    opacity: 0;
    backdrop-filter: blur(0px);
  }
  to {
    opacity: 1;
    backdrop-filter: blur(24px) saturate(120%);
  }
}

.modal-backdrop.fade-out {
  animation: backdropFadeOut 0.2s ease-out forwards;
}

@keyframes backdropFadeOut {
  to {
    opacity: 0;
    backdrop-filter: blur(0px);
  }
}

.modal-backdrop.fade-out .share-dialog-container {
  animation: dialogExit 0.2s ease-out forwards;
}

@keyframes dialogExit {
  to {
    opacity: 0;
    transform: scale(0.95) translateY(20px);
  }
}

.list-row .row-more {
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

/* Lazy loading for list view thumbnails */
.list-row .lazy-thumb-row {
  background: linear-gradient(135deg, #1a1a1f 0%, #262630 50%, #1a1a1f 100%);
  background-size: 200% 200%;
  animation: shimmer 1.5s ease-in-out infinite;
}

.list-row .lazy-thumb-row.thumb-loaded {
  animation: none;
  background: none;
}

/* Compact list mode on phones */
@media (max-width: 720px) {
  .list-row {
    align-items: flex-start;
    gap: 0.75rem;
  }
  .list-row .row-title {
    white-space: normal;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-height: 1.25;
  }
  .list-row .row-subtitle {
    white-space: normal;
  }
  .list-row .row-actions {
    margin-left: auto;
    gap: 0.5rem;
  }
  .list-row .row-action-group {
    display: none;
  }
  .list-row .row-more {
    display: inline-flex;
  }
}

.mobile-action-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 20%, rgba(10, 10, 16, 0.92), rgba(5, 5, 10, 0.95));
  backdrop-filter: blur(18px) saturate(120%);
  -webkit-backdrop-filter: blur(18px) saturate(120%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0.6rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 110;
}

.mobile-action-sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.mobile-action-sheet-backdrop.closing {
  opacity: 0;
  pointer-events: none;
}

.mobile-action-sheet-backdrop.closing .mobile-action-sheet {
  transform: translateY(20px);
  opacity: 0;
}

.mobile-action-sheet {
  width: min(520px, 96vw);
  margin: 0 auto calc(env(safe-area-inset-bottom, 12px) + 0.35rem);
  background: linear-gradient(145deg, rgba(21, 21, 28, 0.97), rgba(12, 12, 18, 0.96));
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 22px 22px 14px 14px;
  box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.55), 0 -4px 14px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  padding: 0.5rem 0.75rem 0.8rem;
  transform: translateY(24px);
  opacity: 0.92;
  transition: transform 0.2s ease, opacity 0.2s ease;
  position: relative;
}

.mobile-action-sheet-backdrop.open .mobile-action-sheet {
  transform: translateY(0);
  opacity: 1;
}

.sheet-handle {
  width: 46px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0.25rem auto 0.5rem;
}

.sheet-meta {
  padding: 0.25rem 0.4rem 0.1rem;
}

.sheet-title {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.3;
  color: #f3f4f6;
}

.sheet-subtitle {
  color: #9ca3af;
  font-size: 0.9rem;
  margin-top: 0.1rem;
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.35rem;
}

.sheet-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.02);
  color: #e5e7eb;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease, box-shadow 0.18s ease;
  text-align: left;
}

.sheet-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 10px 24px -18px rgba(0, 0, 0, 0.6);
}

.sheet-btn:active {
  transform: translateY(1px);
}

.sheet-btn.destructive {
  border-color: rgba(244, 63, 94, 0.35);
  color: #fecdd3;
}

.sheet-btn.destructive .sheet-icon {
  color: #f43f5e;
  background: rgba(244, 63, 94, 0.12);
}

.sheet-btn.is-active {
  border-color: color-mix(in srgb, var(--accent-color) 60%, rgba(255, 255, 255, 0.08));
  background: linear-gradient(120deg, color-mix(in srgb, var(--accent-color) 16%, rgba(20, 20, 28, 0.92)), rgba(18, 18, 26, 0.94));
  box-shadow: 0 16px 38px -24px var(--accent-color);
}

.sheet-icon {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.04);
  color: #d1d5db;
  flex-shrink: 0;
}

.sheet-labels {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.sheet-label {
  font-weight: 600;
  color: #f8fafc;
}

.sheet-sublabel {
  font-size: 0.9rem;
  color: #a1a1aa;
}

/* ===== HEADER STYLES - Modern & Elegant ===== */

/* ===== FILTER BOX SCROLL-BEHAVIOR (stabilisiert) ===== */
#filterBlock,
#filterPanel {
  transition: transform 200ms ease-out, opacity 180ms ease-out, height 200ms ease-out, margin 200ms ease-out;
  will-change: transform, opacity, height, margin;
}

#filterBlock.is-collapsed,
#filterPanel.is-collapsed {
  transform: translateY(-8px);
  opacity: 0;
  height: 0 !important;
  margin: 0 !important;
  overflow: hidden;
  pointer-events: none;
}

#mainHeader {
  will-change: auto; /* No transform needed anymore */
}

/* ===== FILTER PANEL AUTO-COLLAPSE (smooth & elegant) ===== */
#filterPanel,
#filterBlock {
  transition: none; /* Transitions handled by JS for smooth scroll-linked animation */
  will-change: max-height, opacity, transform;
  overflow: hidden;
  /* Große Obergrenze, damit echte Höhe Platz hat; wird animiert */
  max-height: 1000px;
}

#filterContent {
  transition: max-height 300ms cubic-bezier(0.4, 0.0, 0.2, 1), 
              opacity 250ms cubic-bezier(0.4, 0.0, 0.2, 1), 
              transform 250ms cubic-bezier(0.4, 0.0, 0.2, 1);
  will-change: max-height, opacity, transform;
}

/* Zusammengeklappt: Platz freigeben + keine Klicks */
.filter-collapsed {
  max-height: 0 !important;
  opacity: 0 !important;
  transform: translateY(-6px);
  margin-bottom: 0 !important;
  pointer-events: none !important;
}

#headerSpacer {
  height: 64px; /* Default desktop height */
  flex-shrink: 0;
  overflow: hidden;
}

/* Safari-specific fixes - simplified for reliability */
@supports (-webkit-touch-callout: none) {
  #mainHeader {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
  
  #headerSpacer {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
  
  #app {
    -webkit-font-smoothing: antialiased;
  }
  
  /* Safari: use -webkit-fill-available but let content handle padding */
  body.in-viewer {
    height: -webkit-fill-available;
  }
}

#headerUploadBtn {
  display: inline-flex !important;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  height: 40px;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #ffffff;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.16) 0%, rgba(99, 102, 241, 0.12) 100%);
  border: 1px solid rgba(99, 102, 241, 0.35);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0.0, 0.2, 1);
  white-space: nowrap;
  box-shadow: 0 2px 8px -2px rgba(99, 102, 241, 0.2);
}

#headerUploadBtn:hover {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.28) 0%, rgba(99, 102, 241, 0.22) 100%);
  border-color: rgba(99, 102, 241, 0.55);
  transform: translateY(-1px) scale(1.02);
  box-shadow: 
    0 4px 12px -2px rgba(99, 102, 241, 0.35),
    0 0 0 1px rgba(99, 102, 241, 0.2);
}

#headerUploadBtn:active {
  transform: translateY(0) scale(0.98);
}

#headerUploadBtn svg {
  width: 16px;
  height: 16px;
  opacity: 0.9;
  flex-shrink: 0;
}

#headerUploadBtn:hover svg {
  opacity: 1;
}

/* Enhanced Mode Switcher */
#headerModeSwitch {
  background: rgba(255, 255, 255, 0.03) !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  border-radius: 0.75rem !important;
  padding: 0.25rem !important;
  box-shadow: 
    inset 0 1px 2px rgba(0, 0, 0, 0.2),
    0 2px 8px -2px rgba(0, 0, 0, 0.15);
}

#headerModeSwitch button {
  font-weight: 600 !important;
  letter-spacing: -0.01em;
  border-radius: 0.5rem !important;
  padding: 0.5rem 1rem !important;
  transition: all 0.25s cubic-bezier(0.4, 0.0, 0.2, 1) !important;
}

#headerModeSwitch button:hover:not([aria-pressed="true"]) {
  background: rgba(255, 255, 255, 0.05) !important;
}

#headerModeSwitch button[aria-pressed="true"] {
  box-shadow: 
    0 2px 8px -2px rgba(99, 102, 241, 0.4),
    0 0 0 1px rgba(99, 102, 241, 0.2) !important;
}

@media (max-width: 768px) {
  #app {
    padding-top: 0.5rem !important; /* 8px on tablets - tighter */
  }
  
  /* Smaller header on tablets */
  #mainHeader .mx-auto {
    height: 56px;
  }
  
  #headerSpacer {
    height: 56px !important;
  }
  
  .glass-panel { width: 92vw; }
}

/* ===== VIEWER MODE STYLES ===== */
body.in-viewer {
  background: #050506;
  overflow: hidden;
  /* Viewport-Höhe mit dvh für Safari Toolbar-Anpassung */
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  margin: 0;
  padding: 0;
}

body.in-viewer main#app {
  padding: 0 !important;
  max-width: none;
  width: 100%;
  /* Volle Höhe - Controls liegen darüber mit position: fixed */
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0;
}

/* Viewer container - transparent, nimmt verfügbaren Platz */
body.in-viewer #viewer {
  flex: 1 1 0;
  min-height: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  padding-bottom: var(--controls-offset, 180px);
  padding-top: 0;
}

/* Hide header completely in viewer mode for maximum space */
body.in-viewer #mainHeader {
  display: none !important;
}

body.in-viewer #headerSpacer {
  display: none !important;
}

#viewerShell {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  /* Volle Höhe - explizit für iPad Safari */
  height: 100%;
  width: 100%;
  position: relative;
}

#viewerContent {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

#viewerPdfContainer {
  flex: 1 1 0;
  min-height: 0;
  position: relative;
  border-radius: 0;
  overflow: hidden;
  background: transparent;
  backdrop-filter: none;
  border: none;
  box-shadow: none;
}

#viewer {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch; /* Wichtig für iOS smooth scrolling */
  /* Basis-Abstand, im Viewer-Modus per CSS-Variable erweitert */
  padding-bottom: 24px;
  padding-top: 16px;
  box-sizing: border-box;
}

#viewerTapHints {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 35;
}

.viewer-tap-hint {
  height: 100%;
  pointer-events: none;
  opacity: 0;
  border-radius: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* Große Flächen-Hintergrund für die Tap-Zones */
.viewer-tap-hint--left {
  background: linear-gradient(to right, rgba(99, 102, 241, 0.25) 0%, rgba(99, 102, 241, 0) 100%);
}

.viewer-tap-hint--right {
  background: linear-gradient(to left, rgba(99, 102, 241, 0.25) 0%, rgba(99, 102, 241, 0) 100%);
}

/* Pfeil-Icons in den Tap-Zones */
.viewer-tap-hint::before {
  content: '';
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.viewer-tap-hint--left::before {
  content: '‹';
  font-size: 36px;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.8);
  padding-right: 4px;
}

.viewer-tap-hint--right::before {
  content: '›';
  font-size: 36px;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.8);
  padding-left: 4px;
}

/* Initial sichtbar beim Laden - Intro-Animation */
.viewer-tap-hint.is-intro {
  opacity: 1;
  animation: tapZoneIntro 2.5s ease-out forwards;
}

.viewer-tap-hint.is-visible {
  opacity: 1;
}

.viewer-tap-hint.is-visible::before {
  background: rgba(99, 102, 241, 0.25);
  border-color: rgba(99, 102, 241, 0.5);
  color: rgba(255, 255, 255, 1);
  box-shadow: 
    0 4px 24px rgba(99, 102, 241, 0.4),
    0 0 0 1px rgba(99, 102, 241, 0.3) inset;
}

/* Magisches Aufleuchten beim Klicken */
.viewer-tap-hint.is-active {
  opacity: 1;
}

.viewer-tap-hint.is-active.viewer-tap-hint--left {
  background: linear-gradient(to right, rgba(99, 102, 241, 0.5) 0%, rgba(99, 102, 241, 0) 100%);
}

.viewer-tap-hint.is-active.viewer-tap-hint--right {
  background: linear-gradient(to left, rgba(99, 102, 241, 0.5) 0%, rgba(99, 102, 241, 0) 100%);
}

.viewer-tap-hint.is-active::before {
  transform: scale(1.2);
  background: rgba(99, 102, 241, 0.45);
  border-color: rgba(255, 255, 255, 0.6);
  color: #fff;
  box-shadow: 
    0 0 60px 20px rgba(99, 102, 241, 0.5),
    0 0 100px 40px rgba(99, 102, 241, 0.25),
    0 8px 32px rgba(99, 102, 241, 0.6),
    0 0 0 2px rgba(255, 255, 255, 0.4) inset;
  animation: tapZonePulse 0.5s ease-out;
}

@keyframes tapZoneIntro {
  0% {
    opacity: 0;
  }
  15% {
    opacity: 1;
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes tapZonePulse {
  0% {
    transform: scale(1);
    box-shadow: 
      0 0 0 0 rgba(99, 102, 241, 0.6),
      0 4px 20px rgba(0, 0, 0, 0.3);
  }
  50% {
    transform: scale(1.3);
    box-shadow: 
      0 0 80px 30px rgba(99, 102, 241, 0.6),
      0 0 120px 50px rgba(99, 102, 241, 0.3),
      0 8px 40px rgba(99, 102, 241, 0.7);
  }
  100% {
    transform: scale(1.2);
    box-shadow: 
      0 0 60px 20px rgba(99, 102, 241, 0.5),
      0 0 100px 40px rgba(99, 102, 241, 0.25),
      0 8px 32px rgba(99, 102, 241, 0.6);
  }
}

/* PDF Page Styling */
#viewer canvas {
  border-radius: 16px;
  box-shadow: 
    0 20px 40px -12px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.05);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#viewer canvas:hover {
  transform: translateY(-2px);
  box-shadow: 
    0 24px 48px -12px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.08);
}

[data-role="page-label"] {
  font-size: 0.75rem;
  color: #6b7280;
  margin-bottom: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.025em;
}

.viewer-page {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.viewer-page-stage {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}

.viewer-page-frame {
  position: relative;
  width: 100%;
  max-width: 1400px;
}

.viewer-page-frame canvas[data-role="pdf-canvas"] {
  display: block;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 
    0 20px 40px -12px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.05);
}

.annotation-layer,
.annotation-committed {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
}

.annotation-layer.is-active {
  pointer-events: auto;
  cursor: crosshair;
}

.annotation-tool-btn {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 9px;
  padding: 0.3rem 0.5rem;
  color: #e5e7eb;
  font-size: 0.88rem;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.annotation-tool-btn[aria-pressed="true"] {
  background: rgba(99, 102, 241, 0.18);
  border-color: rgba(99, 102, 241, 0.45);
  color: #f8fafc;
}

.annotation-tool-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.annotation-color-btn {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: var(--annotation-color, #f1f5f9);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25) inset;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.annotation-color-btn:hover {
  transform: translateY(-1px);
}

.annotation-color-btn[aria-pressed="true"] {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.4);
}

.annotation-size {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: #cbd5f5;
}

.annotation-size input[type="range"] {
  width: 118px;
  accent-color: var(--accent-color);
}

.annotation-size span {
  min-width: 1.5rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.annotation-toggle-active {
  background: linear-gradient(135deg, var(--accent-color) 0%, color-mix(in srgb, var(--accent-color) 80%, #000) 100%) !important;
  border-color: color-mix(in srgb, var(--accent-color) 80%, rgba(255, 255, 255, 0.35)) !important;
  color: #ffffff !important;
}

.annotation-layer.is-saving {
  cursor: progress;
}

.annotation-layer.is-disabled {
  opacity: 0.75;
}

[data-role="skeleton"] {
  border-radius: 16px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.02) 0%,
    rgba(255, 255, 255, 0.05) 50%,
    rgba(255, 255, 255, 0.02) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 2s ease-in-out infinite;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Loading State */
.viewer-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  gap: 1.5rem;
  padding: 3rem;
}

.viewer-loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(99, 102, 241, 0.2);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.animate-fade-in {
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.viewer-loading-text {
  font-size: 0.875rem;
  color: #9ca3af;
  font-weight: 500;
}

/* Smooth transitions */
#viewerPdfContainer,
.control-panel,
.btn {
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Focus states for accessibility */
.btn:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

#controlsInner:focus,
#controlsInner:focus-visible,
.control-panel:focus,
.control-panel:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}

.input-group input:focus {
  outline: none;
}

/* Toast Notifications - Glass Design */
#toastContainer {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  max-width: 360px;
}

.toast {
  backdrop-filter: blur(24px);
  background: linear-gradient(135deg, 
    color-mix(in srgb, var(--accent-color) 18%, rgba(15, 18, 26, 0.95)) 0%, 
    rgba(15, 18, 26, 0.92) 100%);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  box-shadow: 
    0 20px 40px -12px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  color: #e2e8f0;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  opacity: 0;
  transform: translateX(100px);
  animation: toast-in 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  pointer-events: auto;
}

.toast.toast-out {
  animation: toast-out 0.25s cubic-bezier(0.4, 0, 1, 1) forwards;
}

.toast::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-color);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent-color) 65%, transparent);
  flex-shrink: 0;
}

@keyframes toast-in {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(100px);
  }
}

@media (max-width: 640px) {
  #toastContainer {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }
  
  .toast {
    padding: 0.65rem 0.85rem;
    font-size: 0.8125rem;
  }
}

/* ============================================
   CONTROL BAR - Einheitlich expandierend (Liquid Glass)
   ============================================ */
#controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  background: transparent;
  pointer-events: none;
  box-sizing: border-box;
}

/* Im Library-Modus komplett versteckt */
#controls.hidden {
  display: none !important;
}

/* Im Viewer-Modus sichtbar */
body.in-viewer #controls:not(.hidden) {
  display: block !important;
}

/* Dual-Mode: Bestimmte Elemente verstecken */
#controls.dual-mode-active .dual-hide {
  display: none !important;
}

/* ============================================
   #controlsInner - Das expandierende Element
   ============================================ */
#controlsInner {
  position: fixed;
  z-index: 200;
  pointer-events: auto;
  overflow: visible; /* allow floating panels (annotations) to extend */
  max-height: calc(100dvh - var(--controls-bottom-expanded, 32px) - 12px);
  
  /* Liquid Glass Hintergrund */
  background: linear-gradient(120deg, 
    color-mix(in srgb, var(--accent-color, #6366f1) 16%, rgba(15, 18, 26, 0.94)) 0%, 
    rgba(15, 18, 26, 0.90) 100%);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: 
    0 20px 50px -15px rgba(0, 0, 0, 0.7),
    0 10px 30px -10px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  
  /* Smooth Animation - nur relevante Properties, kürzer für snappier feel */
  transition:
    transform 0.22s cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 0.28s cubic-bezier(0.4, 0, 0.2, 1),
    background 0.28s cubic-bezier(0.4, 0, 0.2, 1),
    width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
    height 0.25s cubic-bezier(0.4, 0, 0.2, 1),
    bottom 0.25s cubic-bezier(0.4, 0, 0.2, 1),
    left 0.25s cubic-bezier(0.4, 0, 0.2, 1),
    padding 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

/* ============================================
   MINIMIERTER ZUSTAND - Box mit zwei Buttons links
   ============================================ */
#controls.controls-minimized #controlsInner {
  width: fit-content;
  height: 52px;
  left: 16px;
  transform: translate(0, 0);
  bottom: var(--controls-bottom-min, calc(env(safe-area-inset-bottom, 0px) + 56px));
  border-radius: 14px;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  cursor: default;
}

#controls.controls-minimized #controlsInner:hover {
  box-shadow: 
    0 24px 60px -20px rgba(0, 0, 0, 0.8),
    0 12px 35px -12px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}

#controls.controls-minimized #controlsInner:active {
  transform: scale(0.98);
}

/* Icon Layer - Container für die Buttons */
.controls-icon-layer {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: relative;
}

/* Minimierte Buttons Container - horizontal nebeneinander */
.minimized-buttons {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  width: auto;
  height: 100%;
}

/* Einzelne Buttons im minimierten Zustand */
.minimized-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.minimized-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  transform: scale(1.05);
}

.minimized-btn:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.2);
}

.minimized-btn svg {
  width: 20px;
  height: 20px;
}

/* Im minimierten Zustand: Zeige nur die minimized-buttons */
#controls.controls-minimized .minimized-buttons {
  display: flex;
}

#controls.controls-minimized .expanded-buttons {
  display: none;
}

/* Im expandierten Zustand: Zeige nur expanded-buttons, verstecke minimized-buttons */
#controls:not(.controls-minimized) .minimized-buttons {
  display: none;
}

#controls:not(.controls-minimized) .expanded-buttons {
  display: flex;
}

/* Expandierte Buttons Container */
.expanded-buttons {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

/* Einzelne Buttons im expandierten Zustand */
.expanded-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.expanded-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  transform: scale(1.05);
}

.expanded-btn:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.2);
}

.expanded-btn svg {
  width: 20px;
  height: 20px;
}

/* Content verstecken wenn minimiert */
#controls.controls-minimized .controls-content {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* ============================================
   EXPANDIERTER ZUSTAND - Volle Controlbar
   ============================================ */
#controls:not(.controls-minimized) #controlsInner {
  left: 16px;
  right: 16px;
  transform: translate(0, 0);
  bottom: var(--controls-bottom-expanded, calc(env(safe-area-inset-bottom, 0px) + 24px));
  width: auto;
  max-width: min(1180px, calc(100% - 32px));
  height: auto;
  border-radius: 18px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: default;
  margin: 0 auto;
  transform-origin: center bottom;
}

@supports (-webkit-touch-callout: none) {
  /* Extra breathing room for iPad Safari where fixed elements can overlap home bar */
  body.in-viewer #controls:not(.controls-minimized) #controlsInner {
    bottom: var(--controls-bottom-expanded, calc(env(safe-area-inset-bottom, 0px) + 24px));
  }
}

/* Icon Layer im expandierten Zustand - enthält Zurück + X Buttons */
#controls:not(.controls-minimized) .controls-icon-layer {
  align-self: center;
  position: relative;
  flex-shrink: 0;
  width: auto;
  height: auto;
  border-radius: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: default;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

#controls:not(.controls-minimized) .controls-icon-layer:hover {
  background: transparent;
  transform: none;
}

#controls:not(.controls-minimized) .controls-icon-layer:active {
  transform: none;
}

/* Content anzeigen wenn expandiert */
#controls:not(.controls-minimized) .controls-content {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  position: relative;
  width: 100%;
  height: auto;
  overflow: visible;
  transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1) 0.1s;
  min-width: 0;
}

/* Annotation Controls und Control Panel direktes Styling */
#controls:not(.controls-minimized) #annotationControls,
#controls:not(.controls-minimized) .control-panel {
  opacity: 0;
  animation: fadeInContent 0.3s ease 0.2s forwards;
}

@keyframes fadeInContent {
  to {
    opacity: 1;
  }
}

/* Fullscreen mode */
html.is-fs #controls {
  background: transparent;
}

.control-panel {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
  display: flex;
  flex-wrap: nowrap;
  gap: 0.65rem;
  align-items: center;
  justify-content: space-between;
  min-height: 54px; /* leaner footprint */
  width: 100%;
}

.control-panel-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: nowrap;
}

/* Icon-Layer als erstes Element im expandierten Panel */
.control-panel-left .controls-icon-layer {
  margin-right: 0.25rem;
}

.control-panel-left,
.control-panel-center,
.control-panel-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: nowrap;
}

.control-panel-center {
  flex: 1;
  justify-content: center;
  max-width: 620px;
  min-width: 0;
}

.control-panel-right {
  margin-left: auto;
}

.control-module {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  align-items: center;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

.control-module-title {
  display: none;
}

.control-module-body {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  align-items: center;
}

.control-module-body .btn + .btn {
  margin-left: 0;
}

.control-module.status-module {
  justify-content: flex-start;
}

.status-module .control-module-body {
  padding: 0;
  flex-wrap: nowrap;
  justify-content: flex-start;
}

.control-group,
.annotation-actions-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#annotationToolbar {
  position: fixed;
  margin-bottom: 0;
  left: 50%;
  transform: translate(-50%, 0);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 190px);
  z-index: 400;
  pointer-events: auto;
}

.annotation-toolbar {
  position: relative;
  pointer-events: auto;
  z-index: 241;
  min-width: 540px;
  max-width: min(1024px, 92vw);
  backdrop-filter: blur(20px);
  background: linear-gradient(135deg, rgba(22, 25, 35, 0.96), rgba(12, 15, 24, 0.96));
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 16px;
  padding: 0.75rem 0.85rem;
  box-shadow:
    0 14px 28px -14px rgba(0, 0, 0, 0.55),
    0 8px 24px -10px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.02) inset;
  display: none;
  flex-direction: column;
  gap: 0.75rem;
}

.annotation-toolbar.is-open {
  display: flex;
  animation: fadeInUp 0.18s ease-out;
  transform-origin: bottom left;
  box-shadow:
    0 14px 28px -14px rgba(0, 0, 0, 0.6),
    0 10px 32px -10px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset;
}

html.is-fs #controlsInner,
html.is-fs #controlsInner *:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}

html.is-fs .control-panel,
html.is-fs .control-panel:focus,
html.is-fs .control-panel:focus-visible {
  outline: none !important;
  box-shadow: none !important;
  border: none !important;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.annotation-toolbar-header {
  display: none;
}

.annotation-toolbar-heading {
  display: none;
}

.annotation-toolbar-heading::before {
  display: none;
}

.annotation-toolbar-meta {
  display: none;
}

.annotation-panel {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.85rem;
}

.annotation-section {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  min-width: auto;
  white-space: nowrap;
}

.annotation-section .section-label {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.6);
  font-weight: 600;
  white-space: nowrap;
}

.annotation-tools-row,
.annotation-actions-row {
  display: inline-flex;
  gap: 0.35rem;
}

.annotation-colors {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.annotation-colors .annotation-color-btn {
  width: 26px;
  height: 26px;
  border-radius: 10px;
}

.annotation-size .range-wrapper {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.annotation-size input[type="range"] {
  width: 110px;
}

.annotation-actions-row .btn {
  min-width: auto;
  justify-content: center;
  padding: 0.35rem 0.6rem;
  font-size: 0.75rem;
}

@media (max-width: 900px) {
  .annotation-panel {
    flex-wrap: wrap;
    row-gap: 0.5rem;
  }
  
  .annotation-toolbar {
    min-width: calc(100vw - 28px);
    max-width: calc(100vw - 28px);
  }
}

.zoom-body {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.zoom-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  border: none;
  padding: 0;
}

.zoom-row .btn-icon {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #e5e7eb;
}

.zoom-row .btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
}

#zoomSlider {
  flex: 0 0 120px;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.35);
  outline: none;
}

#zoomSlider::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-color);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent-color) 30%, transparent);
  cursor: pointer;
}

#zoomSlider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-color);
  border: none;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent-color) 30%, transparent);
  cursor: pointer;
}

.zoom-readout {
  min-width: 44px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  color: #e2e8f0;
  font-weight: 500;
}

.control-divider {
  width: 1px;
  height: 32px;
  background: linear-gradient(to bottom, 
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.12) 50%,
    rgba(255, 255, 255, 0) 100%);
  flex-shrink: 0;
}

/* Button Styles - Consistent Design */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.48rem 0.95rem;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 500;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  border: none;
  outline: none;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.2s;
}

.btn:hover::before {
  opacity: 1;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #e5e7eb;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
  box-shadow: 0 8px 16px -4px rgba(0, 0, 0, 0.3);
}

.btn-secondary:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, 
    var(--accent-color) 0%, 
    color-mix(in srgb, var(--accent-color) 80%, #000) 100%);
  border: 1px solid color-mix(in srgb, var(--accent-color) 100%, rgba(255, 255, 255, 0.3));
  color: white;
  box-shadow: 0 4px 12px -2px color-mix(in srgb, var(--accent-color) 50%, transparent);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary.is-ready {
  opacity: 1;
}

.btn-primary:hover {
  background: linear-gradient(135deg, 
    color-mix(in srgb, var(--accent-color) 90%, #fff) 0%, 
    var(--accent-color) 100%);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px -4px color-mix(in srgb, var(--accent-color) 60%, transparent);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-icon {
  padding: 0.42rem;
  min-width: 2rem;
}

.btn-icon svg {
  width: 1.05rem;
  height: 1.05rem;
}

#btnEditMarkers svg {
  width: 1.25rem;
  height: 1.25rem;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #e5e7eb;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.08);
}

.btn-ghost:active {
  background: rgba(255, 255, 255, 0.06);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Input Styles */
.input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  transition: all 0.2s;
}

.input-group:focus-within {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-color) 15%, transparent);
}

.input-group label {
  font-size: 0.75rem;
  color: #9ca3af;
  white-space: nowrap;
  user-select: none;
}

.input-group input {
  background: transparent;
  border: none;
  color: #e5e7eb;
  font-size: 0.875rem;
  font-weight: 500;
  outline: none;
  width: 3.5rem;
  text-align: center;
}

.input-group input::-webkit-inner-spin-button,
.input-group input::-webkit-outer-spin-button {
  opacity: 0.5;
}

/* Status Display */
.status-display {
  margin: 0;
  font-size: 0.8rem;
  color: #9ca3af;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  width: 100%;
  justify-content: space-between;
}

.status-display::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-color);
  box-shadow: 0 0 8px color-mix(in srgb, var(--accent-color) 65%, transparent);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* iPad / Tablet specific styles (768px - 1024px) */
@media (min-width: 641px) and (max-width: 1024px) {
  .control-panel {
    padding: 0.6rem 0.95rem;
    border-radius: 15px;
    background: linear-gradient(120deg, 
      color-mix(in srgb, var(--accent-color) 20%, rgba(15, 18, 26, 0.95)) 0%, 
      rgba(15, 18, 26, 0.92) 100%);
    border: 1.5px solid rgba(148, 163, 184, 0.18);
    box-shadow: 
      0 24px 48px -20px rgba(0, 0, 0, 0.8),
      0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    backdrop-filter: blur(32px) saturate(180%);
    -webkit-backdrop-filter: blur(32px) saturate(180%);
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  
  .control-panel-left,
  .control-panel-center,
  .control-panel-right {
    gap: 0.5rem;
    flex-wrap: wrap;
  }
  
  /* Make buttons slightly larger for better touch targets */
  .btn {
    padding: 0.45rem 0.85rem;
    font-size: 0.8rem;
    min-height: 38px;
  }
  
  .btn-icon {
    padding: 0.45rem;
    min-width: 38px;
    min-height: 38px;
  }
  
  /* Ensure annotation toolbar is visible */
  #annotationToolbar {
    margin-bottom: 0;
  }
  
  .annotation-toolbar {
    left: 50%;
    transform: translateX(-50%);
    min-width: calc(100vw - 32px);
    max-width: calc(100vw - 32px);
  }
}

/* Mobile tweaks */
@media (max-width: 640px) {
  #app {
    padding-top: 0.375rem !important; /* 6px on mobile - very tight */
  }
  
  /* Smaller header on mobile */
  #mainHeader .mx-auto {
    height: 52px;
  }
  
  #headerSpacer {
    height: 52px !important;
  }
  
  #mainHeader .mx-auto {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  
  #mainHeader a span:last-child {
    font-size: 1rem;
  }
  
  #headerModeSwitch button {
    padding: 0.375rem 0.75rem !important;
    font-size: 0.8125rem !important;
  }
  
  #headerModeSwitch button span span:last-child {
    display: none; /* Hide text on mobile, keep icons */
  }
  
  #viewerPdfContainer {
    border-radius: 0;
  }

  #controlsInner {
    padding: 0.6rem 0.75rem;
    width: min(100%, calc(100% - 12px));
  }
  
  .control-panel {
    padding: 0.65rem 0.85rem;
    border-radius: 16px;
    flex-wrap: wrap;
    gap: 0.6rem;
    justify-content: center;
    min-height: 56px;
  }
  
  .control-panel-left,
  .control-panel-center,
  .control-panel-right {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .control-panel-center {
    max-width: 100%;
  }
  
  .control-panel-right {
    margin-left: 0;
  }
  
  .control-module {
    padding: 0;
  }
  
  #annotationToolbar {
    margin-bottom: 0.5rem;
  }
  
  .annotation-toolbar {
    padding: 0.65rem 0.85rem;
    gap: 0.6rem;
  }
  
  .annotation-toolbar-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }
  
  .annotation-panel {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .annotation-tools-row,
  .annotation-actions-row {
    flex-wrap: wrap;
  }
  
  .annotation-actions-row .btn {
    min-width: 100%;
  }
  
  .btn {
    padding: 0.42rem 0.8rem;
    font-size: 0.8rem;
  }

  .btn-icon {
    padding: 0.42rem;
    min-width: 2rem;
  }
  
  .status-display {
    width: 100%;
    justify-content: center;
  }
  
  .control-divider {
    display: none;
  }
}

/* Ultra-small phones (e.g., 320–380px) */
@media (max-width: 380px) {
  /* Compact header for tiny screens */
  #mainHeader .mx-auto {
    height: 48px !important;
  }
  
  #headerSpacer {
    height: 48px !important;
  }
  
  #app {
    padding-top: 0.25rem !important; /* 4px - minimal spacing */
  }
  
  #mainHeader a span:last-child { 
    display: none; /* Hide "Piano Sheets" text, keep emoji */
  }
  
  #header-actions { 
    gap: 0.375rem; 
  }
  
  #headerModeSwitch button { 
    padding: 0.375rem 0.625rem !important; 
    font-size: 0.8125rem !important; 
  }
  
  #headerUploadBtn { 
    padding: 0.5rem !important; 
  }
  
  #headerUploadBtn span { 
    display: none; 
  }
  
  #headerUploadBtn svg { 
    width: 18px; 
    height: 18px; 
  }
  
  .btn span:not(.sr-only) {
    display: none;
  }
  
  .btn-icon span {
    display: none;
  }
  
  .input-group label {
    font-size: 0.7rem;
  }
}

/* ===== Z-INDEX HIERARCHY - CENTRALIZED =====
   Base layers (0-10): Normal content
   UI layers (10-30): Panels, cards, filters
   Interactive (30-50): Dropdowns, tooltips, popovers  
   Overlays (50-80): Modals, drawers, viewer controls (70)
   System (80-100): Notifications, critical UI
*/

/* Category Bar - Must be below dropdowns */
#categoryBar {
  position: relative;
  z-index: 10;
}

/* Filter Panel - Must be below dropdowns */
#filterPanel {
  position: relative;
  z-index: 10;
}

/* Filter Block Container */
#filterBlock {
  position: relative;
  z-index: 10;
}

/* ===== SORT DROPDOWN - OPTIMIZED ===== */

/* Dropdown positioning container - ABOVE everything else */
.sort-dropdown-wrapper {
  position: relative;
  z-index: 60 !important; /* Above panels and category bar */
}

#sortMenuBtn {
  position: relative;
  z-index: 1;
}

/* Dropdown menu - fixed positioning to escape stacking contexts */
#sortMenu {
  position: fixed;
  min-width: 220px;
  max-width: 280px;
  z-index: 9999 !important; /* Top of everything */
  background: linear-gradient(135deg, 
    rgba(15, 18, 25, 0.98) 0%, 
    rgba(10, 13, 18, 0.98) 100%);
  border: 1px solid rgba(99, 102, 241, 0.35);
  border-radius: 12px;
  box-shadow: 
    0 24px 48px -12px rgba(0, 0, 0, 0.8),
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 0 32px -8px rgba(99, 102, 241, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  overflow: hidden;
  backdrop-filter: blur(24px) saturate(180%) brightness(1.1);
  -webkit-backdrop-filter: blur(24px) saturate(180%) brightness(1.1);
  transform-origin: top left;
  pointer-events: auto; /* Ensure clicks are captured */
  /* Initial position off-screen until calculated */
  top: -9999px;
  left: -9999px;
}

/* Animation when opening - NO translateY to avoid position conflicts */
#sortMenu:not(.hidden) {
  animation: dropdown-in 0.15s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes dropdown-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

#sortMenu.hidden {
  display: none !important;
  pointer-events: none !important;
}

/* Dropdown backdrop to block clicks below */
#sortMenu::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  pointer-events: none;
}

/* Menu items */
#sortMenu button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  color: #d1d5db;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.75rem 1rem;
  border: none;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.4, 0.0, 0.2, 1);
  position: relative;
  pointer-events: auto; /* Ensure button clicks work */
}

#sortMenu button::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent-color);
  opacity: 0;
  transition: opacity 0.15s ease;
}

#sortMenu button:hover {
  background: rgba(99, 102, 241, 0.12);
  color: #f3f4f6;
}

#sortMenu button:active {
  background: rgba(99, 102, 241, 0.18);
}

#sortMenu button.is-active {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.16) 0%, rgba(99, 102, 241, 0.08) 100%);
  color: #ffffff;
  font-weight: 600;
}

#sortMenu button.is-active::before {
  opacity: 1;
}

/* Checkmark */
#sortMenu button .sortMenuCheck {
  opacity: 0;
  font-size: 1rem;
  color: var(--accent-color);
  transition: opacity 0.15s ease, transform 0.15s ease;
  transform: scale(0.8);
}

#sortMenu button.is-active .sortMenuCheck {
  opacity: 1;
  transform: scale(1);
}

/* Responsive */
@media (max-width: 480px) {
  #sortMenu { 
    min-width: 200px;
    max-width: 92vw; 
  }
}

/* === GPU Performance Optimierungen === */
.music-card,
.playlist-card,
.glass-panel,
.control-panel,
.toast {
  will-change: transform, opacity;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Verhindert Repaints durch Box-Shadows bei Scrollbewegung */
.music-card,
.playlist-card {
  transition: transform 0.25s ease, filter 0.25s ease;
}

/* Vermeidet teures Redraw bei Scroll für überlagerte Filter */
#app, main, body:not(.in-viewer) {
  transform: translateZ(0);
}

/* Für iOS Safari: stabilisiert Layer bei blur() und backdrop-filter */
@supports (-webkit-backdrop-filter: blur(10px)) {
  .glass-panel,
  .control-panel {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
}

/* ===== SHARE DIALOG STYLES ===== */
.share-dialog-container {
  position: relative;
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  background: linear-gradient(135deg, 
    rgba(22, 22, 28, 0.98) 0%, 
    rgba(18, 18, 24, 0.96) 100%);
  border: 2px solid rgba(99, 102, 241, 0.4);
  border-radius: 24px;
  box-shadow: 
    0 0 0 1px rgba(99, 102, 241, 0.2) inset,
    0 40px 80px -20px rgba(0, 0, 0, 0.95),
    0 20px 60px -10px rgba(99, 102, 241, 0.3),
    0 10px 40px -5px rgba(0, 0, 0, 0.8);
  max-width: 560px;
  width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: dialogEnter 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: center;
  overflow: hidden;
  /* Ensure proper stacking and visibility */
  z-index: 1;
  isolation: isolate;
}

.share-dialog-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, 
    transparent 0%, 
    rgba(99, 102, 241, 0.6) 50%, 
    transparent 100%);
  opacity: 1;
  z-index: 1;
}

.share-dialog-container::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(
    circle at top center,
    rgba(99, 102, 241, 0.12) 0%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 0;
}

.share-dialog-close {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 10;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #9ca3af;
}

.share-dialog-close:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  color: #f3f4f6;
  transform: rotate(90deg);
}

.share-dialog-close:active {
  transform: rotate(90deg) scale(0.95);
}

@keyframes dialogEnter {
  0% {
    opacity: 0;
    transform: scale(0.92) translateY(30px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.share-dialog-header {
  position: relative;
  z-index: 2;
  padding: 28px 28px 20px 28px;
  background: linear-gradient(180deg, 
    rgba(99, 102, 241, 0.08) 0%,
    rgba(99, 102, 241, 0.03) 50%,
    transparent 100%);
  border-bottom: 1px solid rgba(99, 102, 241, 0.3);
}

.share-dialog-title {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 22px;
  font-weight: 700;
  color: #f9fafb;
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}

.share-dialog-title svg {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 4px rgba(99, 102, 241, 0.4));
}

.share-dialog-subtitle {
  font-size: 14px;
  color: #d1d5db;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 40px;
  opacity: 0.9;
}

.share-dialog-body {
  position: relative;
  z-index: 2;
  flex: 1;
  overflow-y: auto;
  padding: 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 240px;
  max-height: 480px;
  background: linear-gradient(180deg,
    rgba(0, 0, 0, 0.2) 0%,
    rgba(0, 0, 0, 0.25) 100%);
}

.share-dialog-body::-webkit-scrollbar {
  width: 10px;
}

.share-dialog-body::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
  border-radius: 5px;
  margin: 8px 0;
}

.share-dialog-body::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, 
    rgba(99, 102, 241, 0.4) 0%, 
    rgba(99, 102, 241, 0.25) 100%);
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.share-dialog-body::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, 
    rgba(99, 102, 241, 0.6) 0%, 
    rgba(99, 102, 241, 0.4) 100%);
  background-clip: padding-box;
}

.share-user-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  background: linear-gradient(135deg, 
    rgba(255, 255, 255, 0.08) 0%, 
    rgba(255, 255, 255, 0.04) 100%);
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.share-user-item::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 14px;
  padding: 1px;
  background: linear-gradient(135deg, 
    rgba(99, 102, 241, 0) 0%, 
    rgba(99, 102, 241, 0.3) 100%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.share-user-item:hover {
  background: linear-gradient(135deg, 
    rgba(99, 102, 241, 0.12) 0%, 
    rgba(99, 102, 241, 0.06) 100%);
  border-color: rgba(99, 102, 241, 0.5);
  transform: translateX(4px);
  box-shadow: 
    0 4px 16px -4px rgba(99, 102, 241, 0.3),
    0 0 0 1px rgba(99, 102, 241, 0.1) inset;
}

.share-user-item:hover::before {
  opacity: 1;
}

.share-user-item:active {
  transform: translateX(2px) scale(0.99);
}

.share-user-checkbox {
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  cursor: pointer;
  accent-color: #6366f1;
  border-radius: 6px;
  margin: 0;
  transition: all 0.2s ease;
  filter: drop-shadow(0 2px 4px rgba(99, 102, 241, 0.3));
}

.share-user-checkbox:checked {
  filter: drop-shadow(0 2px 8px rgba(99, 102, 241, 0.6));
}

.share-user-checkbox:focus {
  outline: 2px solid rgba(99, 102, 241, 0.6);
  outline-offset: 2px;
}

.share-user-checkbox:focus:not(:focus-visible) {
  outline: none;
}

.share-user-item.is-shared {
  background: linear-gradient(135deg, 
    rgba(99, 102, 241, 0.15) 0%, 
    rgba(99, 102, 241, 0.08) 100%);
  border-color: rgba(99, 102, 241, 0.4);
}

.share-user-label {
  flex: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.share-user-info {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}

.share-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.3);
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  color: #86efac;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

.share-user-email {
  font-size: 15px;
  font-weight: 600;
  color: #f3f4f6;
  letter-spacing: -0.01em;
}

.share-user-id {
  font-size: 12px;
  color: #9ca3af;
  font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
  opacity: 0.8;
}

.share-no-users {
  text-align: center;
  padding: 60px 20px;
  color: #9ca3af;
  font-size: 14px;
  font-weight: 500;
  opacity: 0.7;
}

.share-dialog-footer {
  position: relative;
  z-index: 2;
  padding: 20px 28px 24px 28px;
  background: linear-gradient(180deg, 
    transparent 0%, 
    rgba(0, 0, 0, 0.3) 100%);
  border-top: 1px solid rgba(99, 102, 241, 0.2);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.share-dialog-footer button {
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  letter-spacing: -0.01em;
}

.share-dialog-footer .btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #d1d5db;
}

.share-dialog-footer .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.share-dialog-footer .btn-primary {
  background: linear-gradient(135deg, 
    #6366f1 0%, 
    #4f46e5 100%);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  box-shadow: 
    0 4px 16px -4px rgba(99, 102, 241, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

.share-dialog-footer .btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, 
    #7c3aed 0%, 
    #6366f1 100%);
  transform: translateY(-2px);
  box-shadow: 
    0 8px 24px -6px rgba(99, 102, 241, 0.8),
    0 0 0 1px rgba(255, 255, 255, 0.15) inset;
}

.share-dialog-footer .btn-primary:active:not(:disabled) {
  transform: translateY(-1px);
}

.share-dialog-footer .btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== SHARED ITEM BADGE STYLES ===== */

/* Shared badge - positioned absolute like offline badge */
.badge-shared {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, 
    rgba(99, 102, 241, 0.95) 0%, 
    rgba(79, 70, 229, 0.95) 100%);
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 
    0 4px 12px rgba(99, 102, 241, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 10;
  cursor: pointer;
}

.badge-shared svg {
  width: 18px;
  height: 18px;
  color: #ffffff;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

.badge-shared:hover {
  transform: scale(1.15) translateY(-2px);
  box-shadow: 
    0 8px 20px rgba(99, 102, 241, 0.7),
    0 0 0 2px rgba(255, 255, 255, 0.2) inset;
  border-color: rgba(255, 255, 255, 0.5);
}

.badge-shared:active,
.badge-shared-row:active {
  transform: scale(1.05);
}

/* Tooltip for shared badge - simple indicator */
.badge-shared .shared-tooltip {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: linear-gradient(135deg, 
    rgba(15, 18, 26, 0.98) 0%, 
    rgba(10, 13, 18, 0.98) 100%);
  border: 1px solid rgba(99, 102, 241, 0.4);
  border-radius: 8px;
  padding: 8px 12px;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  color: #e2e8f0;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  box-shadow: 
    0 12px 24px -8px rgba(0, 0, 0, 0.8),
    0 0 0 1px rgba(99, 102, 241, 0.2) inset;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.badge-shared .shared-tooltip::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-bottom-color: rgba(99, 102, 241, 0.4);
}

.badge-shared .shared-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(1px);
  border: 5px solid transparent;
  border-bottom-color: rgba(15, 18, 26, 0.98);
}

.badge-shared:hover .shared-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(10px);
}

/* Hide label and email elements - show only "Geteilt" text via content */
.shared-tooltip-label,
.shared-tooltip-email {
  display: none;
}

/* Hide old inline badge container */
.shared-badge-container {
  display: none !important;
}

/* Shared badge for list view - inline style */
.badge-shared-row {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, 
    rgba(99, 102, 241, 0.95) 0%, 
    rgba(79, 70, 229, 0.95) 100%);
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 
    0 3px 10px rgba(99, 102, 241, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 5;
  cursor: pointer;
  margin-right: 380px; /* Space for action buttons */
}

.badge-shared-row svg {
  width: 14px;
  height: 14px;
  color: #ffffff;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

.badge-shared-row:hover {
  transform: translateY(-50%) scale(1.15);
  box-shadow: 
    0 6px 16px rgba(99, 102, 241, 0.7),
    0 0 0 2px rgba(255, 255, 255, 0.2) inset;
  border-color: rgba(255, 255, 255, 0.5);
}

.badge-shared-row .shared-tooltip {
  position: absolute;
  top: 100%;
  right: 0;
  transform: translateY(8px);
  background: linear-gradient(135deg, 
    rgba(15, 18, 26, 0.98) 0%, 
    rgba(10, 13, 18, 0.98) 100%);
  border: 1px solid rgba(99, 102, 241, 0.4);
  border-radius: 8px;
  padding: 8px 12px;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  color: #e2e8f0;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  box-shadow: 
    0 12px 24px -8px rgba(0, 0, 0, 0.8),
    0 0 0 1px rgba(99, 102, 241, 0.2) inset;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.badge-shared-row .shared-tooltip::before {
  content: 'Geteilt';
}

.badge-shared-row .shared-tooltip::after {
  content: none;
}

.badge-shared-row:hover .shared-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(10px);
}

@media (max-width: 640px) {
  .share-dialog-container {
    width: 95vw;
    max-height: 90vh;
    border-radius: 20px;
  }
  
  .share-dialog-header {
    padding: 24px 20px 18px 20px;
  }
  
  .share-dialog-title {
    font-size: 19px;
    gap: 12px;
  }
  
  .share-dialog-title svg {
    width: 24px;
    height: 24px;
  }
  
  .share-dialog-subtitle {
    padding-left: 36px;
  }
  
  .share-dialog-body {
    padding: 16px 20px;
    gap: 10px;
  }
  
  .share-user-item {
    padding: 14px 16px;
  }
  
  .share-dialog-footer {
    padding: 16px 20px 20px 20px;
    flex-direction: column-reverse;
    gap: 10px;
  }
  
  .share-dialog-footer button {
    width: 100%;
    padding: 14px 20px;
  }
  
  .badge-shared {
    width: 30px;
    height: 30px;
  }
  
  .badge-shared svg {
    width: 16px;
    height: 16px;
  }
  
  .badge-shared-row {
    width: 26px;
    height: 26px;
    margin-right: 0;
    position: relative;
    right: auto;
    top: auto;
    transform: none;
    margin-left: 8px;
  }
  
  .badge-shared-row:hover {
    transform: scale(1.1);
  }
  
  .badge-shared-row svg {
    width: 13px;
    height: 13px;
  }
}

/* Emoji Picker Buttons */
.emoji-btn {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  -webkit-user-select: none;
}

.emoji-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  transform: scale(1.1);
}

.emoji-btn:active {
  transform: scale(0.95);
}

.emoji-btn.selected {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(99, 102, 241, 0.3));
  border-color: rgba(99, 102, 241, 0.5);
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.3);
}

/* Dual Page Viewer */
#dualViewer {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  width: 100%;
  overflow: auto;
}

/* Dual Viewer Container - Fixed Fullscreen */
.dual-viewer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  display: none;
  overflow: hidden;
  z-index: 100;
  background: #0a0a0a;
}

.dual-viewer:not(.hidden) {
  display: flex;
}

.dual-viewer.hidden {
  display: none !important;
}

.dual-viewer-inner {
  display: flex;
  flex-direction: row;
  gap: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.dual-page {
  flex: 0 1 auto;
  min-width: 0;
  max-width: none;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
}

.dual-page[data-side="left"] .dual-page-stage {
  justify-content: flex-end;
}

.dual-page[data-side="right"] .dual-page-stage {
  justify-content: flex-start;
}

.dual-page-label {
  display: none;
}

.dual-page-stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  max-width: 100%;
  position: relative;
  overflow: visible; /* Changed from hidden to allow jump markers to be visible */
}

.dual-page-canvas {
  background: #0a0a0a;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.dual-canvas-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible; /* Ensure jump markers are visible */
}

.dual-tap-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  z-index: 15;
}

.dual-tap-hint {
  flex: 0 0 15%;
  max-width: 200px;
  min-width: 80px;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.dual-tap-hint--left {
  background: linear-gradient(to right, rgba(99, 102, 241, 0.25) 0%, rgba(99, 102, 241, 0) 100%);
}

.dual-tap-hint--right {
  background: linear-gradient(to left, rgba(99, 102, 241, 0.25) 0%, rgba(99, 102, 241, 0) 100%);
}

.dual-tap-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.8);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.dual-tap-hint--left .dual-tap-button {
  padding-right: 4px;
}

.dual-tap-hint--right .dual-tap-button {
  padding-left: 4px;
}

.dual-tap-hint.is-visible {
  opacity: 1;
}

.dual-tap-hint.is-visible .dual-tap-button {
  background: rgba(99, 102, 241, 0.25);
  border-color: rgba(99, 102, 241, 0.5);
  color: rgba(255, 255, 255, 1);
  box-shadow: 
    0 4px 24px rgba(99, 102, 241, 0.4),
    0 0 0 1px rgba(99, 102, 241, 0.3) inset;
}

.dual-tap-hint.is-active {
  opacity: 1;
}

.dual-tap-hint.is-active.dual-tap-hint--left {
  background: linear-gradient(to right, rgba(99, 102, 241, 0.5) 0%, rgba(99, 102, 241, 0) 100%);
}

.dual-tap-hint.is-active.dual-tap-hint--right {
  background: linear-gradient(to left, rgba(99, 102, 241, 0.5) 0%, rgba(99, 102, 241, 0) 100%);
}

.dual-tap-hint.is-active .dual-tap-button {
  transform: scale(1.2);
  background: rgba(99, 102, 241, 0.45);
  border-color: rgba(255, 255, 255, 0.6);
  color: #fff;
  box-shadow: 
    0 0 60px 20px rgba(99, 102, 241, 0.5),
    0 0 100px 40px rgba(99, 102, 241, 0.25),
    0 8px 32px rgba(99, 102, 241, 0.6),
    0 0 0 2px rgba(255, 255, 255, 0.4) inset;
  animation: dualTapPulse 0.5s ease-out;
}

@keyframes dualTapPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1.2); }
}

.dual-viewer-empty {
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4a4a4a;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.3);
}
