/**
 * Global Enhancements for ALL Pages
 * Applied automatically to every page in the application
 */

/* ============================================
   GLOBAL TYPOGRAPHY
   ============================================ */
/* Ensure fonts apply everywhere */
* {
  font-family: var(--font-body, var(--chakra-fonts-body, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif));
}

html, body {
  font-family: var(--font-body, var(--chakra-fonts-body, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif));
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading, var(--chakra-fonts-heading, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif)) !important;
}

button, input, textarea, select {
  font-family: var(--font-body, var(--chakra-fonts-body, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif));
}

/* ============================================
   SMOOTH SCROLLING
   ============================================ */
html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px; /* Account for fixed headers */
}

/* Respect user preferences for reduced motion */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================
   FOCUS IMPROVEMENTS
   ============================================ */
:focus-visible {
  outline: 3px solid var(--primary, #C53030);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Remove default outline but keep focus-visible */
:focus:not(:focus-visible) {
  outline: none;
}

/* Better focus for links */
a:focus-visible {
  outline: 3px solid var(--primary, #C53030);
  outline-offset: 3px;
}

/* Better focus for buttons */
button:focus-visible {
  outline: 3px solid var(--primary, #C53030);
  outline-offset: 2px;
}

/* Better focus for inputs */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--primary, #C53030);
  outline-offset: 0;
  border-color: var(--primary, #C53030);
}

/* ============================================
   SELECTION STYLING
   ============================================ */
::selection {
  background: var(--primary, #C53030);
  color: white;
  text-shadow: none;
}

::-moz-selection {
  background: var(--primary, #C53030);
  color: white;
  text-shadow: none;
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
/* Webkit browsers (Chrome, Safari, Edge) */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:active {
  background: rgba(0, 0, 0, 0.4);
  background-clip: padding-box;
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.05);
}

/* Dark mode scrollbar */
.chakra-ui-dark ::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
}

.chakra-ui-dark ::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
}

.chakra-ui-dark ::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

.chakra-ui-dark * {
  scrollbar-color: rgba(255, 255, 255, 0.2) rgba(255, 255, 255, 0.05);
}

/* ============================================
   FADE-IN ANIMATIONS
   ============================================ */
@keyframes globalFadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes globalFadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes globalSlideInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.fade-in {
  animation: globalFadeIn 0.6s ease-out forwards;
}

.fade-in-up {
  animation: globalFadeInUp 0.7s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.slide-in-left {
  animation: globalSlideInLeft 0.6s ease-out forwards;
}

.slide-in-right {
  animation: globalSlideInRight 0.6s ease-out forwards;
}

.fade-in-visible {
  animation: globalFadeIn 0.6s ease-out forwards;
}

.fade-in-hidden {
  opacity: 0;
}

/* Staggered animations */
.stagger-1 { animation-delay: 0.1s; }
.stagger-2 { animation-delay: 0.2s; }
.stagger-3 { animation-delay: 0.3s; }
.stagger-4 { animation-delay: 0.4s; }
.stagger-5 { animation-delay: 0.5s; }

/* ============================================
   LOADING SKELETON
   ============================================ */
@keyframes shimmer {
  0% {
    background-position: -1000px 0;
  }
  100% {
    background-position: 1000px 0;
  }
}

.skeleton {
  background: linear-gradient(
    90deg,
    #f0f0f0 0%,
    #e0e0e0 50%,
    #f0f0f0 100%
  );
  background-size: 1000px 100%;
  animation: shimmer 2s infinite linear;
  border-radius: 4px;
}

.chakra-ui-dark .skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
}

/* ============================================
   PULSE ANIMATION
   ============================================ */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ============================================
   SPIN ANIMATION
   ============================================ */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.spin {
  animation: spin 1s linear infinite;
}

/* ============================================
   BACK TO TOP BUTTON
   ============================================ */
.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary, #C53030);
  color: white;
  border: none;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

.back-to-top:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.back-to-top:active {
  transform: translateY(-2px);
}

.back-to-top:focus-visible {
  outline: 3px solid white;
  outline-offset: 2px;
}

/* ============================================
   SKIP TO CONTENT LINK
   ============================================ */
.skip-to-content {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary, #C53030);
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  border-radius: 0 0 4px 0;
  z-index: 10000;
  transition: top 0.3s;
}

.skip-to-content:focus {
  top: 0;
  outline: 3px solid white;
  outline-offset: -3px;
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.no-scroll {
  overflow: hidden;
}

.pointer-events-none {
  pointer-events: none;
}

.pointer-events-auto {
  pointer-events: auto;
}

/* ============================================
   IMPROVED TOUCH TARGETS
   ============================================ */
/* Ensure all interactive elements have minimum 44x44px touch target */
@media (pointer: coarse) {
  button,
  a,
  input[type="button"],
  input[type="submit"],
  input[type="reset"],
  select {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
  .no-print,
  .back-to-top,
  .skip-to-content,
  nav,
  footer,
  aside,
  button {
    display: none !important;
  }
  
  a[href]:after {
    content: " (" attr(href) ")";
  }
  
  * {
    background: white !important;
    color: black !important;
  }
}

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */
@media (prefers-contrast: high) {
  * {
    border-color: currentColor !important;
  }
  
  button,
  a {
    text-decoration: underline;
  }
}

/* ============================================
   PERFORMANCE HINTS
   ============================================ */
.will-change-transform {
  will-change: transform;
}

.will-change-opacity {
  will-change: opacity;
}

.gpu-accelerated {
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* ============================================
   RESPONSIVE IMAGES
   ============================================ */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

img.lazy-loading {
  filter: blur(5px);
  transition: filter 0.3s;
}

img.lazy-loaded {
  filter: blur(0);
}

/* ============================================
   IMPROVED TEXT RENDERING
   ============================================ */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-family: var(--font-body, var(--chakra-fonts-body, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif));
}

/* ============================================
   SAFE AREA INSETS (for mobile notches)
   ============================================ */
@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}
