/* Glassmorphism Navigation Custom Styles */

:root {
  color-scheme: light dark;
  --bg-gradient: radial-gradient(at 0% 0%, rgba(30, 27, 75, 0.5) 0px, transparent 50%),
                      radial-gradient(at 100% 0%, rgba(76, 29, 149, 0.4) 0px, transparent 50%),
                      radial-gradient(at 50% 100%, rgba(15, 23, 42, 0.8) 0px, transparent 50%),
                      #030712;
  --glass-bg: rgba(255, 255, 255, 0.04);
  --glass-bg-hover: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-border-hover: rgba(99, 102, 241, 0.4);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --card-text-primary: #f3f4f6;
  --card-text-secondary: #9ca3af;
  --sidebar-bg: rgba(3, 7, 18, 0.78);
}

:root.dark {
  color-scheme: dark;
}

html.light {
  color-scheme: light;
  --bg-gradient: radial-gradient(at 0% 0%, rgba(224, 231, 255, 0.8) 0px, transparent 50%),
                      radial-gradient(at 100% 0%, rgba(243, 232, 255, 0.8) 0px, transparent 50%),
                      radial-gradient(at 50% 100%, rgba(241, 245, 249, 0.9) 0px, transparent 50%),
                      #f8fafc;
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-bg-hover: rgba(255, 255, 255, 0.95);
  --glass-border: rgba(0, 0, 0, 0.06);
  --glass-border-hover: rgba(99, 102, 241, 0.5);
  --glass-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.03);
  --card-text-primary: #1e293b;
  --card-text-secondary: #64748b;
  --sidebar-bg: rgba(255, 255, 255, 0.82);
}

body {
  color: var(--card-text-primary);
  min-height: 100vh;
}

/* Dedicated fixed gradient layer avoids scroll-time background-attachment repaints */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -20;
  background: var(--bg-gradient);
  pointer-events: none;
}

/* Frosted glass utilities */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  transition: background-color 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  transition: background-color 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.glass-card:hover {
  background: var(--glass-bg-hover);
  border-color: var(--glass-border-hover);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25);
}

@media (prefers-reduced-motion: no-preference) {
  .glass-card {
    transition: background-color 0.25s cubic-bezier(0.16, 1, 0.3, 1),
                border-color 0.25s cubic-bezier(0.16, 1, 0.3, 1),
                box-shadow 0.25s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .glass-card:hover {
    transform: translateY(-2px);
  }
}

.glass-sidebar {
  background: var(--sidebar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--glass-border);
}

.glass-mobile-header {
  background: var(--sidebar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* Native <dialog> modal scrolling & backdrop */
dialog#unlock-modal {
  margin: auto;
  max-width: min(28rem, calc(100vw - 2rem));
  width: 100%;
  color: inherit;
  overflow: visible;
}

dialog#unlock-modal:modal {
  overscroll-behavior: contain;
}

dialog#unlock-modal::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Custom Scrollbar (paired with legacy WebKit fallback inside @supports) */
:root {
  scrollbar-color: rgba(156, 163, 175, 0.3) transparent;
}
@supports not (scrollbar-color: auto) {
  ::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }
  ::-webkit-scrollbar-track {
    background: transparent;
  }
  ::-webkit-scrollbar-thumb {
    background: rgba(156, 163, 175, 0.25);
    border-radius: 9999px;
  }
  ::-webkit-scrollbar-thumb:hover {
    background: rgba(156, 163, 175, 0.45);
  }
}

/* Hide scrollbar for clean horizontal scroll on mobile */
.no-scrollbar::-webkit-scrollbar {
  display: none;
}
.no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* Shaking animation for password error (opt-in when motion is not reduced) */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* Ambient glow pulses */
@keyframes float-slow {
  0%, 100% { transform: translateY(0px) scale(1); }
  50% { transform: translateY(-15px) scale(1.05); }
}

@media (prefers-reduced-motion: no-preference) {
  .animate-shake {
    animation: shake 0.4s ease-in-out;
  }
  @media (min-width: 769px) {
    .animate-float-slow {
      animation: float-slow 10s ease-in-out infinite;
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .animate-pulse,
  .animate-spin {
    animation: none !important;
  }
}

/* Line clamp */
.line-clamp-1 {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Compact Bookmark Card */
.bookmark-card {
  min-height: 48px;
}
.copy-url-btn {
  min-width: 24px;
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.bookmark-card:hover .copy-url-btn,
.bookmark-card:focus-within .copy-url-btn {
  opacity: 1;
}

/* Always expose copy button on touch devices without hover */
@media (hover: none), (pointer: coarse) {
  .copy-url-btn {
    opacity: 0.75 !important;
  }
}

/* Mobile compositing optimization */
@media (max-width: 768px) {
  .glass-card {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }
}

/* Sidebar Collapse Transitions */
#sidebar {
  width: 15.5rem;
  transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), padding 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-reduced-motion: reduce) {
  #sidebar,
  #collapse-icon {
    transition: none !important;
  }
}

#sidebar.is-collapsed {
  width: 4.25rem;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

#sidebar.is-collapsed .sidebar-hide-on-collapse {
  display: none !important;
}

#sidebar.is-collapsed .sidebar-nav-item {
  justify-content: center;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
}

#sidebar.is-collapsed .sidebar-brand {
  justify-content: center;
  width: 100%;
}

#sidebar.is-collapsed #sidebar-collapse-btn {
  display: none;
}

#sidebar.is-collapsed .sidebar-bottom-controls {
  flex-direction: column;
  gap: 0.35rem;
}

#collapse-icon.rotated {
  transform: rotate(180deg);
}

/* Active State for Sidebar ScrollSpy */
.sidebar-nav-item.active {
  background: rgba(99, 102, 241, 0.14) !important;
  color: var(--card-text-primary) !important;
  border-color: rgba(99, 102, 241, 0.38) !important;
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.15);
}
.sidebar-nav-item.active .sidebar-icon-badge {
  background: rgba(99, 102, 241, 0.25) !important;
  color: #c7d2fe !important;
}
html.light .sidebar-nav-item.active .sidebar-icon-badge {
  background: rgba(99, 102, 241, 0.18) !important;
  color: #4f46e5 !important;
}
.sidebar-nav-item.sidebar-vault-item.active {
  background: rgba(245, 158, 11, 0.16) !important;
  border-color: rgba(245, 158, 11, 0.45) !important;
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.16);
}
.sidebar-nav-item.sidebar-vault-item.active .sidebar-icon-badge {
  background: rgba(245, 158, 11, 0.28) !important;
  color: #f59e0b !important;
}

/* Only show desktop sidebar toggle button when sidebar is collapsed */
#sidebar:not(.is-collapsed) ~ main #desktop-sidebar-toggle-btn {
  display: none !important;
}
