/* Utility Classes - Common patterns and reusable components */
/* Import this after styles.css and before mobile.css */

/* =============================================================================
   GRID UTILITIES
   ============================================================================= */

.grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  transform: translateZ(0); /* Force GPU acceleration */
  will-change: auto;
}

.grid-cols-1 { grid-template-columns: repeat(1, 1fr); }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

/* Responsive grid utilities */
@media (max-width: 768px) {
  .grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* =============================================================================
   FLEX UTILITIES
   ============================================================================= */

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.flex-row {
  flex-direction: row;
}

.items-center {
  align-items: center;
}

.items-start {
  align-items: flex-start;
}

.items-end {
  align-items: flex-end;
}

.justify-center {
  justify-content: center;
}

.justify-between {
  justify-content: space-between;
}

.justify-start {
  justify-content: flex-start;
}

.justify-end {
  justify-content: flex-end;
}

.flex-1 {
  flex: 1;
}

.flex-wrap {
  flex-wrap: wrap;
}

/* =============================================================================
   SPACING UTILITIES
   ============================================================================= */

.gap-xs { gap: 0.25rem; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 0.75rem; }
.gap-lg { gap: 1rem; }
.gap-xl { gap: 1.5rem; }

.p-xs { padding: 0.25rem; }
.p-sm { padding: 0.5rem; }
.p-md { padding: 0.75rem; }
.p-lg { padding: 1rem; }
.p-xl { padding: 1.5rem; }

.px-xs { padding-left: 0.25rem; padding-right: 0.25rem; }
.px-sm { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-md { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-lg { padding-left: 1rem; padding-right: 1rem; }
.px-xl { padding-left: 1.5rem; padding-right: 1.5rem; }

.py-xs { padding-top: 0.25rem; padding-bottom: 0.25rem; }
.py-sm { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-md { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.py-lg { padding-top: 1rem; padding-bottom: 1rem; }
.py-xl { padding-top: 1.5rem; padding-bottom: 1.5rem; }

.m-xs { margin: 0.25rem; }
.m-sm { margin: 0.5rem; }
.m-md { margin: 0.75rem; }
.m-lg { margin: 1rem; }
.m-xl { margin: 1.5rem; }

.mx-xs { margin-left: 0.25rem; margin-right: 0.25rem; }
.mx-sm { margin-left: 0.5rem; margin-right: 0.5rem; }
.mx-md { margin-left: 0.75rem; margin-right: 0.75rem; }
.mx-lg { margin-left: 1rem; margin-right: 1rem; }
.mx-xl { margin-left: 1.5rem; margin-right: 1.5rem; }

.my-xs { margin-top: 0.25rem; margin-bottom: 0.25rem; }
.my-sm { margin-top: 0.5rem; margin-bottom: 0.5rem; }
.my-md { margin-top: 0.75rem; margin-bottom: 0.75rem; }
.my-lg { margin-top: 1rem; margin-bottom: 1rem; }
.my-xl { margin-top: 1.5rem; margin-bottom: 1.5rem; }

/* =============================================================================
   BORDER RADIUS UTILITIES
   ============================================================================= */

.rounded-sm { border-radius: var(--border-radius-sm); }
.rounded { border-radius: var(--border-radius); }
.rounded-lg { border-radius: var(--border-radius-lg); }
.rounded-full { border-radius: var(--border-radius-full); }

/* =============================================================================
   COMMON BUTTON PATTERNS
   ============================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition);
  border-radius: var(--border-radius);
  text-decoration: none;
  font-family: inherit;
  background: var(--card-color);
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  gap: 0.5rem;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  border-color: var(--primary-color);
}

.btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.btn-base {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition);
  border-radius: var(--border-radius);
  text-decoration: none;
  font-family: inherit;
  background: var(--card-color);
  color: var(--text-primary);
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  border-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background-color: var(--secondary-color);
  color: white;
  border-color: var(--secondary-color);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
}

.btn-secondary:hover {
  background-color: var(--secondary-hover);
  border-color: var(--secondary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-outline {
  background-color: transparent;
  color: var(--primary-color);
  border: 1px solid var(--primary-color);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
}

.btn-outline:hover {
  background-color: var(--primary-color);
  color: white;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn-accent {
  background-color: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
}

.btn-accent:hover {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Cookie preferences specific button styling */
.btn-cookie-preferences {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  border: none;
  padding: 0.875rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--border-radius-lg);
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.2);
}

.btn-cookie-preferences:hover {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

/* Dark mode specific adjustments for cookie preferences button */
html[data-theme="dark"] .btn-cookie-preferences {
  background: linear-gradient(135deg, #34d399 0%, #10b981 100%);
  box-shadow: 0 2px 4px rgba(52, 211, 153, 0.3);
}

html[data-theme="dark"] .btn-cookie-preferences:hover {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  box-shadow: 0 4px 12px rgba(52, 211, 153, 0.4);
}

.btn-sm {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

.btn-lg {
  padding: 1rem 1.5rem;
  font-size: 1.125rem;
}

/* =============================================================================
   CARD PATTERNS
   ============================================================================= */

.card-base {
  background-color: var(--card-color);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  transition: var(--transition);
}

.card-shadow {
  box-shadow: var(--shadow);
}

.card-shadow-md {
  box-shadow: var(--shadow-md);
}

.card-hover:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

/* =============================================================================
   INPUT PATTERNS
   ============================================================================= */

.input-base {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background-color: var(--surface-color);
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: var(--transition);
}

.input-base::placeholder {
  color: var(--text-muted);
}

.input-base:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(107, 114, 128, 0.1);
}

.input-search {
  padding-left: 2.5rem;
  border-radius: var(--border-radius-full);
}

/* =============================================================================
   THEME-AWARE COMPONENTS
   ============================================================================= */

.surface {
  background-color: var(--surface-color);
  color: var(--text-primary);
}

.card {
  background-color: var(--card-color);
  color: var(--text-primary);
  border-color: var(--border-color);
}

/* =============================================================================
   DISPLAY UTILITIES
   ============================================================================= */

.block { display: block; }
.inline-block { display: inline-block; }
.inline { display: inline; }
.hidden { display: none !important; }

.visible { visibility: visible; }
.invisible { visibility: hidden; }

/* =============================================================================
   POSITIONING UTILITIES
   ============================================================================= */

.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.sticky { position: sticky; }

.z-10 { z-index: 10; }
.z-20 { z-index: 20; }
.z-30 { z-index: 30; }
.z-40 { z-index: 40; }
.z-50 { z-index: 50; }

/* =============================================================================
   TEXT UTILITIES
   ============================================================================= */

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }

.text-sm { font-size: 0.875rem; }
.text-base { font-size: 1rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }

.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

/* =============================================================================
   WIDTH & HEIGHT UTILITIES
   ============================================================================= */

.w-full { width: 100%; }
.w-auto { width: auto; }
.h-full { height: 100%; }
.h-auto { height: auto; }

.max-w-sm { max-width: 24rem; }
.max-w-md { max-width: 28rem; }
.max-w-lg { max-width: 32rem; }
.max-w-xl { max-width: 36rem; }

.min-h-0 { min-height: 0; }
.min-h-full { min-height: 100%; }
.min-h-screen { min-height: 100vh; }

/* =============================================================================
   OVERFLOW UTILITIES
   ============================================================================= */

.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.overflow-scroll { overflow: scroll; }
.overflow-x-auto { overflow-x: auto; }
.overflow-y-auto { overflow-y: auto; }

/* =============================================================================
   RESPONSIVE UTILITIES
   ============================================================================= */

.desktop-only {
  display: flex;
}

.mobile-only {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
}

.mobile-settings-section {
  display: none;
}

@media (max-width: 768px) {
  .desktop-only {
    display: none !important;
  }
  
  .mobile-only {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  .mobile-settings-section {
    display: block;
  }
}

/* =============================================================================
   SIDEBAR PROTECTION - Ensures sidebar is never affected by form loading states
   ============================================================================= */

/* Protect sidebar from form-loading and similar classes */
.sidebar,
.sidebar *:not(.nav-link):not(.nav-link *),
#sidebar,
#sidebar *:not(.nav-link):not(.nav-link *),
nav.sidebar,
nav.sidebar *:not(.nav-link):not(.nav-link *) {
    /* Override any form-loading effects */
    opacity: 1 !important;
    pointer-events: auto !important;
    filter: none !important;
    visibility: visible !important;
    cursor: auto !important;
    
    /* Ensure proper display */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Special rules for navigation links */
.sidebar .nav-link,
.sidebar .nav-link *,
.sidebar .nav-item a,
.sidebar .nav-item a *,
#sidebar .nav-link,
#sidebar .nav-link *,
#sidebar .nav-item a,
#sidebar .nav-item a *,
nav.sidebar .nav-link,
nav.sidebar .nav-link *,
nav.sidebar .nav-item a,
nav.sidebar .nav-item a * {
    cursor: pointer !important;
    pointer-events: auto !important;
    opacity: 1 !important;
    color: inherit !important;
    text-decoration: none !important;
    display: flex !important;
    align-items: center !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
}

/* Exception: allow sidebar overlay to be hidden when not active */
.sidebar-overlay:not(.active),
#sidebarOverlay:not(.active) {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Exception: allow sidebar itself to be hidden when not open on mobile */
@media (max-width: 768px) {
    .sidebar:not(.open),
    #sidebar:not(.open),
    nav.sidebar:not(.open) {
        transform: translateX(-100%) !important;
    }
}

/* Ensure form-loading class can never interfere with sidebar functionality */
.sidebar.form-loading,
.sidebar .form-loading,
#sidebar.form-loading,
#sidebar .form-loading,
nav.sidebar.form-loading,
nav.sidebar .form-loading {
    opacity: 1 !important;
    pointer-events: auto !important;
    filter: none !important;
    position: relative !important;
}

/* Remove any pseudo-elements that might be added by form-loading */
.sidebar.form-loading::before,
.sidebar.form-loading::after,
.sidebar .form-loading::before,
.sidebar .form-loading::after,
#sidebar.form-loading::before,
#sidebar.form-loading::after,
#sidebar .form-loading::before,
#sidebar .form-loading::after {
    display: none !important;
    content: none !important;
}
