/* Custom CSS - Optimized for Tailwind-first approach */

/* ============================================
   DESIGN TOKENS (Keep for compatibility)
   ============================================ */
:root {
  --color-primary: #15DFC3;
  --color-primary-600: #12c7ae;
  --color-primary-700: #0fa997;
  --color-text: #111827;
  --color-bg: #F8FAF9;
  --color-surface: #FFFFFF;
  --color-border: #E6E6E6;
  --color-text-dark: #E4F2F0;
  --color-bg-dark: #0E0F0F;
  --color-surface-dark: #1A1C1C;
  --color-border-dark: #2A2D2D;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
}

.dark {
  --color-text: var(--color-text-dark);
  --color-bg: var(--color-bg-dark);
  --color-surface: var(--color-surface-dark);
  --color-border: var(--color-border-dark);
}

/* ============================================
   GLOBAL POLISH
   ============================================ */
html {
  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
}

/* ============================================
   TEXT SELECTION
   ============================================ */
::selection {
  background: rgba(21, 223, 195, 0.2);
  color: inherit;
}

.dark ::selection {
  background: rgba(21, 223, 195, 0.3);
}

/* ============================================
   CUSTOM SCROLLBAR
   ============================================ */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: rgba(230, 230, 230, 0.1);
}

.dark ::-webkit-scrollbar-track {
  background: rgba(42, 45, 45, 0.1);
}

::-webkit-scrollbar-thumb {
  background: #15DFC3;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #15DFC3;
}

* {
  scrollbar-width: thin;
  scrollbar-color: rgb(21 223 195 / 20%) rgba(230, 230, 230, 0.1);
}

.dark * {
  scrollbar-color: rgb(21 223 195 / 20%) rgba(42, 45, 45, 0.1);
}

/* ============================================
   INPUT AUTOFILL
   ============================================ */
input:-webkit-autofill {
  background-color: #F8FAF9;
  color: #2E2E2E;
  border: 1px solid #E6E6E6;
  -webkit-text-fill-color: #2E2E2E;
  -webkit-box-shadow: 0 0 0px 1000px #F8FAF9 inset;
  transition: background-color 5000s ease-in-out 0s;
}

input:-webkit-autofill:focus {
  border-color: #15DFC3;
  -webkit-text-fill-color: #2E2E2E;
}

.dark input:-webkit-autofill {
  -webkit-text-fill-color: #E4F2F0;
  -webkit-box-shadow: 0 0 0px 1000px #0E0F0F inset;
}

.dark input:-webkit-autofill:focus {
  -webkit-text-fill-color: #E4F2F0;
}

/* ============================================
   TOGGLE CHECKBOX (Functional Component)
   ============================================ */
.toggle-checkbox:checked+.toggle-label {
  background-color: #15DFC3;
}

.toggle-label {
  display: inline-block;
  width: 42px;
  height: 22px;
  background-color: #E6E6E6;
  border-radius: 9999px;
  position: relative;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.dark .toggle-label {
  background-color: #2A2D2D;
}

.toggle-label::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #FFFFFF;
  border-radius: 9999px;
  transition: transform 0.3s ease;
}

.dark .toggle-label::before {
  background: #1A1C1C;
}

.toggle-checkbox:checked+.toggle-label::before {
  transform: translateX(20px);
}

/* ============================================
   POPUP MENUS (Tools & Actions) - Using Tailwind
   ============================================ */
/* Popup menus now use Tailwind utilities - keeping only active state toggle for JavaScript */
.tools.active .tools-popup {
  display: block;
}

.btn-delete {
  pointer-events: auto !important;
  z-index: 9999 !important;
  position: relative !important;
}

/* ============================================
   SIDEBAR FUNCTIONALITY
   ============================================ */

/* Sidebar Responsive Behavior */
@media (max-width: 1023px) {
  #sidebar {
    z-index: 40;
  }
  
  #desktopSidebarToggle {
    display: none !important;
  }
}

@media (min-width: 1024px) {
  #sidebar {
    z-index: 20;
  }
  
  #mobileSidebarToggle {
    display: none !important;
  }
}

/* Sidebar Width States */
#sidebar {
  width: 16rem;
}

#sidebar.sidebar-compact {
  width: 4rem;
}

/* Sidebar Backdrop (Mobile) */
@media (max-width: 1023px) {
  .sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 35;
    opacity: 0;
    visibility: hidden;
  }
  
  .sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
  }
}

/* Sidebar Compact Mode - Text Hiding */
.sidebar-text {
  max-width: 100%;
  overflow: hidden;
}

#sidebar.sidebar-compact .sidebar-text {
  opacity: 0;
  max-width: 0;
  overflow: hidden;
}

#sidebar.sidebar-compact .font-medium,
#sidebar.sidebar-compact .font-semibold,
#sidebar.sidebar-compact h3,
#sidebar.sidebar-compact h1,
#sidebar.sidebar-compact p,
#sidebar.sidebar-compact .ml-auto {
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

/* Ensure essential elements remain visible in compact mode */
#sidebar.sidebar-compact button,
#sidebar.sidebar-compact a,
#sidebar.sidebar-compact .flex-shrink-0,
#sidebar.sidebar-compact .w-8,
#sidebar.sidebar-compact .h-8,
#sidebar.sidebar-compact .w-5,
#sidebar.sidebar-compact .h-5,
#sidebar.sidebar-compact .w-4,
#sidebar.sidebar-compact .h-4,
#sidebar.sidebar-compact svg {
  opacity: 1 !important;
  max-width: none !important;
}

/* Sidebar Tooltips */
.sidebar-tooltip {
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 0.75rem;
  padding: 0.5rem 0.75rem;
  background-color: rgba(0, 0, 0, 0.9);
  color: white;
  font-size: 0.75rem;
  border-radius: 0.375rem;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  z-index: 50;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.sidebar-tooltip::before {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 4px solid transparent;
  border-right-color: rgba(0, 0, 0, 0.9);
}

#sidebar:not(.sidebar-compact) .sidebar-tooltip {
  display: none;
}

#sidebar.sidebar-compact .group:hover .sidebar-tooltip,
#sidebar.sidebar-compact a:hover .sidebar-tooltip,
#sidebar.sidebar-compact button:hover .sidebar-tooltip {
  opacity: 1;
  visibility: visible;
}

.dark .sidebar-tooltip {
  background: rgba(31, 41, 55, 0.95);
}

.dark .sidebar-tooltip::before {
  border-right-color: rgba(31, 41, 55, 0.95);
}

/* Portal Tooltip (Dynamic tooltips) */
.portal-tooltip {
  position: fixed;
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(8px);
}

.portal-tooltip::before {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-right-color: rgba(0, 0, 0, 0.9);
}

.dark .portal-tooltip {
  background: rgba(30, 30, 30, 0.95);
  color: #f3f4f6;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.dark .portal-tooltip::before {
  border-right-color: rgba(30, 30, 30, 0.95);
}

/* ============================================
   PROGRESS BAR SHIMMER (Sidebar)
   ============================================ */
@keyframes progressShimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

#sidebar .p-4 .relative.w-full.h-3::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.2) 50%, transparent 100%);
  animation: progressShimmer 2s infinite;
  border-radius: inherit;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */
@media (max-width: 1023px) {
  #sidebar {
    width: 16rem !important;
  }
  
  #sidebar.sidebar-compact {
    width: 16rem !important;
  }
  
  .sidebar-tooltip {
    display: none !important;
  }
}

@media (min-width: 1024px) {
  #sidebar.sidebar-compact {
    transform: translateX(0);
  }
  
  #sidebar.sidebar-compact .flex.items-center.justify-between,
  #sidebar.sidebar-compact .flex.items-center.gap-3 {
    justify-content: center;
  }
  
  #sidebar.sidebar-compact .px-4 {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
  
  #sidebar.sidebar-compact .px-3 {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
  
  #sidebar.sidebar-compact .space-x-3 > * + * {
    margin-left: 0 !important;
  }
  
  #sidebar.sidebar-compact .sidebar-text {
    display: none !important;
  }
  
  #sidebar.sidebar-compact a,
  #sidebar.sidebar-compact button {
    position: relative;
  }
}

/* ============================================
   MINIMAL PAGE LOAD ANIMATIONS (Tailwind-first)
   ============================================ */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

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

/* Initial hidden state - prevents flash */
.page-load-animate {
  opacity: 0;
}

.page-load-animate.fade-in {
  animation: fadeIn 0.35s ease-out forwards;
}

.page-load-animate.fade-in-up {
  animation: fadeInUp 0.4s ease-out forwards;
}

.page-load-animate.slide-in-right {
  animation: slideInRight 0.4s ease-out forwards;
}

/* Stagger delays for natural flow - optimized timings */
.page-load-animate[data-delay="0"] { animation-delay: 0ms; }
.page-load-animate[data-delay="30"] { animation-delay: 30ms; }
.page-load-animate[data-delay="50"] { animation-delay: 50ms; }
.page-load-animate[data-delay="80"] { animation-delay: 80ms; }
.page-load-animate[data-delay="100"] { animation-delay: 100ms; }
.page-load-animate[data-delay="120"] { animation-delay: 120ms; }
.page-load-animate[data-delay="150"] { animation-delay: 150ms; }
.page-load-animate[data-delay="180"] { animation-delay: 180ms; }
.page-load-animate[data-delay="200"] { animation-delay: 200ms; }
.page-load-animate[data-delay="250"] { animation-delay: 250ms; }
.page-load-animate[data-delay="300"] { animation-delay: 300ms; }

/* Respect reduced motion preference (accessibility) */
@media (prefers-reduced-motion: reduce) {
  .page-load-animate {
    opacity: 1;
    transform: none;
    animation: none !important;
  }
}
