/* ===== Fixes and Optimizations ===== */

/* ===== Browser Compatibility Fixes ===== */
/* Webkit browsers */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  .text-gradient {
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
  
  .glass-effect {
    -webkit-backdrop-filter: blur(10px);
  }
}

/* Firefox */
@-moz-document url-prefix() {
  .form-control {
    -moz-appearance: none;
  }
  
  .btn {
    -moz-user-select: none;
  }
}

/* Safari */
@media not all and (min-resolution: 0.001dpcm) {
  @supports (-webkit-appearance: none) {
    .hero-title {
      -webkit-transform: translateZ(0);
      transform: translateZ(0);
    }
  }
}

/* Edge */
@supports (-ms-ime-align: auto) {
  .card-3d {
    -ms-transform-style: flat;
  }
}

/* ===== Performance Optimizations ===== */
/* Hardware acceleration */
.gpu-accelerated {
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  will-change: transform;
}

/* Smooth scrolling for mobile */
@media (max-width: 768px) {
  html {
    -webkit-overflow-scrolling: touch;
  }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .card-3d,
  .icon-3d,
  .cube-3d,
  .sphere-3d,
  .torus-3d,
  .helix-3d {
    animation: none !important;
    transform: none !important;
  }
  
  .floating-element {
    animation: none !important;
  }
  
  .logo-3d {
    animation: none !important;
  }
}

/* ===== Loading Performance ===== */
.loading-optimization {
  content-visibility: auto;
  contain-intrinsic-size: auto 300px;
}

/* Image lazy loading */
img[loading="lazy"] {
  transition: opacity 0.3s ease;
}

img[loading="lazy"]:not(.loaded) {
  opacity: 0;
}

img[loading="lazy"].loaded {
  opacity: 1;
}

/* ===== Memory Leak Prevention ===== */
/* Clean up animations */
.animation-cleanup {
  animation: none !important;
  transition: none !important;
}

/* Remove event listeners */
.event-cleanup {
  pointer-events: none;
}

/* ===== CSS Containment ===== */
.layout-containment {
  contain: layout;
}

.paint-containment {
  contain: paint;
}

.size-containment {
  contain: size;
}

.strict-containment {
  contain: strict;
}

.content-containment {
  contain: content;
}

/* ===== Font Loading Optimization ===== */
.font-display-optional {
  font-display: optional;
}

.font-display-swap {
  font-display: swap;
}

.font-display-fallback {
  font-display: fallback;
}

/* ===== Critical CSS Above the Fold ===== */
.critical-css {
  /* Above the fold styles */
  font-family: var(--font-primary);
  line-height: 1.6;
  color: var(--dark-color);
  background: var(--white-color);
}

/* ===== Layout Shift Prevention ===== */
.size-placeholder {
  min-height: 200px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

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

/* ===== Scroll Performance ===== */
.scroll-container {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Debounced scroll events */
.scroll-optimized {
  will-change: transform;
  transform: translateZ(0);
}

/* ===== Touch Device Optimizations ===== */
@media (hover: none) and (pointer: coarse) {
  .btn:hover {
    transform: none;
  }
  
  .card-3d:hover {
    transform: none;
  }
  
  .hover-lift:hover {
    transform: none;
  }
  
  .hover-scale:hover {
    transform: none;
  }
  
  .nav-link::after {
    display: none;
  }
}

/* ===== High DPI Display Fixes ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .text-3d {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  
  .hero-title {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

/* ===== Print Styles ===== */
@media print {
  * {
    background: transparent !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
  
  .loading-screen,
  .three-container,
  .floating-elements {
    display: none !important;
  }
  
  .hero-section {
    background: white !important;
    color: black !important;
  }
  
  .btn {
    border: 2px solid black !important;
  }
}

/* ===== Focus Styles for Accessibility ===== */
.focus-visible {
  outline: 2px solid var(--secondary-color);
  outline-offset: 2px;
}

.focus-visible:focus-visible {
  outline: 2px solid var(--secondary-color);
  outline-offset: 2px;
}

/* Remove focus outline for mouse users */
.focus-visible:not(:focus-visible) {
  outline: none;
}

/* ===== Color Contrast Fixes ===== */
.contrast-fix {
  color: var(--dark-color);
  background: var(--white-color);
}

.contrast-fix-dark {
  color: var(--white-color);
  background: var(--dark-color);
}

/* Ensure WCAG compliance */
.wcag-compliant {
  color: #000000;
  background: #ffffff;
}

.wcag-compliant-dark {
  color: #ffffff;
  background: #000000;
}

/* ===== Form Validation Fixes ===== */
.form-control.is-invalid {
  border-color: #dc3545;
  box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

.form-control.is-valid {
  border-color: #28a745;
  box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
}

.invalid-feedback {
  display: block;
  color: #dc3545;
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

.valid-feedback {
  display: block;
  color: #28a745;
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* ===== Modal Fixes ===== */
.modal-dialog {
  transform: translate(0, 0) !important;
}

.modal.fade .modal-dialog {
  transition: transform 0.3s ease-out;
}

.modal.show .modal-dialog {
  transform: scale(1);
}

/* ===== Dropdown Fixes ===== */
.dropdown-menu {
  border: 1px solid rgba(0, 0, 0, 0.125);
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.dropdown-item {
  transition: background-color 0.15s ease-in-out;
}

.dropdown-item:hover {
  background-color: rgba(0, 0, 0, 0.03);
}

/* ===== Tooltip Fixes ===== */
.tooltip {
  font-size: 0.875rem;
  z-index: 1070;
}

.tooltip-inner {
  background-color: var(--dark-color);
  color: var(--white-color);
  border-radius: 0.25rem;
  padding: 0.5rem 0.75rem;
}

/* ===== Popover Fixes ===== */
.popover {
  border: 1px solid rgba(0, 0, 0, 0.125);
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.popover-header {
  background-color: rgba(0, 0, 0, 0.03);
  border-bottom: 1px solid rgba(0, 0, 0, 0.125);
}

/* ===== Carousel Fixes ===== */
.carousel-item {
  transition: transform 0.6s ease-in-out;
}

.carousel-control-prev,
.carousel-control-next {
  opacity: 0.8;
  transition: opacity 0.15s ease;
}

.carousel-control-prev:hover,
.carousel-control-next:hover {
  opacity: 1;
}

/* ===== Navbar Fixes ===== */
.navbar-toggler {
  border: none;
  padding: 0.25rem 0.5rem;
}

.navbar-toggler:focus {
  box-shadow: 0 0 0 0.2rem rgba(56, 189, 248, 0.25);
}

/* ===== Card Fixes ===== */
.card {
  border: 1px solid rgba(0, 0, 0, 0.125);
  box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
  transition: box-shadow 0.15s ease-in-out;
}

.card:hover {
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

/* ===== Alert Fixes ===== */
.alert {
  border: 1px solid transparent;
  border-radius: 0.375rem;
}

.alert-dismissible .btn-close {
  padding: 0.5rem 0.5rem;
  margin: -0.5rem -0.5rem -0.5rem auto;
}

/* ===== Progress Bar Fixes ===== */
.progress {
  height: 1rem;
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: 0.375rem;
}

.progress-bar {
  transition: width 0.6s ease;
}

/* ===== Badge Fixes ===== */
.badge {
  font-size: 0.75em;
  font-weight: 700;
  line-height: 1;
  padding: 0.35em 0.65em;
  border-radius: 0.375rem;
}

/* ===== List Group Fixes ===== */
.list-group-item {
  border: 1px solid rgba(0, 0, 0, 0.125);
}

.list-group-item:first-child {
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
}

.list-group-item:last-child {
  border-bottom-left-radius: inherit;
  border-bottom-right-radius: inherit;
}

/* ===== Pagination Fixes ===== */
.pagination {
  margin-bottom: 0;
}

.page-link {
  color: var(--primary-color);
  background-color: var(--white-color);
  border: 1px solid rgba(0, 0, 0, 0.125);
  transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
}

.page-link:hover {
  color: var(--primary-color);
  background-color: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.125);
}

.page-link:focus {
  box-shadow: 0 0 0 0.2rem rgba(56, 189, 248, 0.25);
}

/* ===== Breadcrumb Fixes ===== */
.breadcrumb {
  background-color: rgba(0, 0, 0, 0.03);
  border-radius: 0.375rem;
}

.breadcrumb-item + .breadcrumb-item::before {
  float: left;
  padding-right: 0.5rem;
  color: rgba(0, 0, 0, 0.5);
  content: var(--bs-breadcrumb-divider, "/");
}

/* ===== Spinner Fixes ===== */
.spinner-border {
  width: 2rem;
  height: 2rem;
  border: 0.25em solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spinner-border 0.75s linear infinite;
}

.spinner-grow {
  width: 2rem;
  height: 2rem;
  background-color: currentColor;
  border-radius: 50%;
  opacity: 0;
  animation: spinner-grow 0.75s linear infinite;
}

@keyframes spinner-border {
  to {
    transform: rotate(360deg);
  }
}

@keyframes spinner-grow {
  0% {
    transform: scale(0);
  }
  50% {
    opacity: 1;
    transform: none;
  }
}

/* ===== Toast Fixes ===== */
.toast {
  background-color: rgba(255, 255, 255, 0.85);
  background-clip: padding-box;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(10px);
  opacity: 0;
  border-radius: 0.375rem;
}

.toast.show {
  opacity: 1;
}

.toast-header {
  background-color: rgba(255, 255, 255, 0.85);
  background-clip: padding-box;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  border-top-left-radius: calc(0.375rem - 1px);
  border-top-right-radius: calc(0.375rem - 1px);
}

/* ===== Offcanvas Fixes ===== */
.offcanvas {
  background-clip: padding-box;
  outline: 0;
  transition: transform 0.3s ease-in-out;
}

.offcanvas-header {
  border-bottom: 1px solid rgba(0, 0, 0, 0.125);
}

.offcanvas-title {
  margin-bottom: 0;
  line-height: 1.5;
}

.offcanvas-body {
  flex-grow: 1;
  padding: 1rem;
  overflow-y: auto;
}

/* ===== Placeholder Fixes ===== */
.placeholder {
  display: inline-block;
  min-height: 1em;
  vertical-align: middle;
  cursor: wait;
  background-color: currentColor;
  opacity: 0.5;
  border-radius: 0.375rem;
}

.placeholder.btn::before {
  display: inline-block;
  content: "";
}

/* ===== Ratio Fixes ===== */
.ratio {
  position: relative;
  width: 100%;
}

.ratio::before {
  display: block;
  padding-top: var(--bs-aspect-ratio);
  content: "";
}

.ratio > * {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* ===== Sticky Fixes ===== */
.sticky-top {
  position: sticky;
  top: 0;
  z-index: 1020;
}

.sticky-bottom {
  position: sticky;
  bottom: 0;
  z-index: 1020;
}

/* ===== Visually Hidden ===== */
.visually-hidden,
.visually-hidden-focusable:not(:focus):not(:focus-within) {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ===== Stretched Link ===== */
.stretched-link::after {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  content: "";
}

/* ===== Text Truncation ===== */
.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Vertical Alignment ===== */
.align-baseline {
  vertical-align: baseline !important;
}

.align-top {
  vertical-align: top !important;
}

.align-middle {
  vertical-align: middle !important;
}

.align-bottom {
  vertical-align: bottom !important;
}

.align-text-bottom {
  vertical-align: text-bottom !important;
}

.align-text-top {
  vertical-align: text-top !important;
}

/* ===== Float ===== */
.float-start {
  float: left !important;
}

.float-end {
  float: right !important;
}

.float-none {
  float: none !important;
}

/* ===== Clearfix ===== */
.clearfix::after {
  display: block;
  clear: both;
  content: "";
}

/* ===== Position ===== */
.position-static {
  position: static !important;
}

.position-relative {
  position: relative !important;
}

.position-absolute {
  position: absolute !important;
}

.position-fixed {
  position: fixed !important;
}

.position-sticky {
  position: sticky !important;
}

/* ===== Display ===== */
.d-none {
  display: none !important;
}

.d-inline {
  display: inline !important;
}

.d-inline-block {
  display: inline-block !important;
}

.d-block {
  display: block !important;
}

.d-grid {
  display: grid !important;
}

.d-table {
  display: table !important;
}

.d-table-row {
  display: table-row !important;
}

.d-table-cell {
  display: table-cell !important;
}

.d-flex {
  display: flex !important;
}

.d-inline-flex {
  display: inline-flex !important;
}

/* ===== Shadow Utilities ===== */
.shadow-none {
  box-shadow: none !important;
}

.shadow-sm {
  box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075) !important;
}

.shadow {
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
}

.shadow-lg {
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.175) !important;
}

/* ===== Width Utilities ===== */
.w-25 {
  width: 25% !important;
}

.w-50 {
  width: 50% !important;
}

.w-75 {
  width: 75% !important;
}

.w-100 {
  width: 100% !important;
}

.w-auto {
  width: auto !important;
}

/* ===== Height Utilities ===== */
.h-25 {
  height: 25% !important;
}

.h-50 {
  height: 50% !important;
}

.h-75 {
  height: 75% !important;
}

.h-100 {
  height: 100% !important;
}

.h-auto {
  height: auto !important;
}

/* ===== Spacing Utilities ===== */
.m-0 {
  margin: 0 !important;
}

.m-1 {
  margin: 0.25rem !important;
}

.m-2 {
  margin: 0.5rem !important;
}

.m-3 {
  margin: 1rem !important;
}

.m-4 {
  margin: 1.5rem !important;
}

.m-5 {
  margin: 3rem !important;
}

.m-auto {
  margin: auto !important;
}

.p-0 {
  padding: 0 !important;
}

.p-1 {
  padding: 0.25rem !important;
}

.p-2 {
  padding: 0.5rem !important;
}

.p-3 {
  padding: 1rem !important;
}

.p-4 {
  padding: 1.5rem !important;
}

.p-5 {
  padding: 3rem !important;
}

/* ===== Border Utilities ===== */
.border {
  border: 1px solid rgba(0, 0, 0, 0.125) !important;
}

.border-0 {
  border: 0 !important;
}

.border-top {
  border-top: 1px solid rgba(0, 0, 0, 0.125) !important;
}

.border-right {
  border-right: 1px solid rgba(0, 0, 0, 0.125) !important;
}

.border-bottom {
  border-bottom: 1px solid rgba(0, 0, 0, 0.125) !important;
}

.border-left {
  border-left: 1px solid rgba(0, 0, 0, 0.125) !important;
}

.rounded {
  border-radius: 0.375rem !important;
}

.rounded-sm {
  border-radius: 0.25rem !important;
}

.rounded-lg {
  border-radius: 0.5rem !important;
}

.rounded-circle {
  border-radius: 50% !important;
}

.rounded-pill {
  border-radius: 50rem !important;
}

.rounded-0 {
  border-radius: 0 !important;
}

/* ===== Text Utilities ===== */
.text-left {
  text-align: left !important;
}

.text-center {
  text-align: center !important;
}

.text-right {
  text-align: right !important;
}

.text-lowercase {
  text-transform: lowercase !important;
}

.text-uppercase {
  text-transform: uppercase !important;
}

.text-capitalize {
  text-transform: capitalize !important;
}

.font-weight-light {
  font-weight: 300 !important;
}

.font-weight-normal {
  font-weight: 400 !important;
}

.font-weight-bold {
  font-weight: 700 !important;
}

.font-italic {
  font-style: italic !important;
}

/* ===== Color Utilities ===== */
.text-primary {
  color: var(--primary-color) !important;
}

.text-secondary {
  color: var(--secondary-color) !important;
}

.text-success {
  color: #28a745 !important;
}

.text-danger {
  color: #dc3545 !important;
}

.text-warning {
  color: #ffc107 !important;
}

.text-info {
  color: #17a2b8 !important;
}

.text-light {
  color: #f8f9fa !important;
}

.text-dark {
  color: #343a40 !important;
}

.text-white {
  color: #fff !important;
}

.text-muted {
  color: #6c757d !important;
}

.bg-primary {
  background-color: var(--primary-color) !important;
}

.bg-secondary {
  background-color: var(--secondary-color) !important;
}

.bg-success {
  background-color: #28a745 !important;
}

.bg-danger {
  background-color: #dc3545 !important;
}

.bg-warning {
  background-color: #ffc107 !important;
}

.bg-info {
  background-color: #17a2b8 !important;
}

.bg-light {
  background-color: #f8f9fa !important;
}

.bg-dark {
  background-color: #343a40 !important;
}

.bg-white {
  background-color: #fff !important;
}

.bg-transparent {
  background-color: transparent !important;
}