/* Custom Global Utility Classes - Only for styles Tailwind cannot handle */

:root {
  --primary-color: #2563eb;
  --secondary-color: #10b981;
  --accent-color: #f59e0b;
  --sidebar-width: 260px;
  --sidebar-width-collapsed: 88px;
  --header-height: 80px;
}

/* Animations - Keep these as Tailwind doesn't support complex keyframe animations */
@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

@keyframes pulse-opacity {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes statUpdate {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
    color: var(--primary-color);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes particleFloat {
  0% {
    transform: translateY(100vh) translateX(0) scale(0);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translateY(-100px) translateX(50px) scale(1);
    opacity: 0;
  }
}

@keyframes shapeMove {
  0%,
  100% {
    transform: translate(0, 0) scale(1);
    opacity: 0.15;
  }
  25% {
    transform: translate(50px, -50px) scale(1.1);
    opacity: 0.25;
  }
  50% {
    transform: translate(-30px, 30px) scale(0.9);
    opacity: 0.2;
  }
  75% {
    transform: translate(40px, 40px) scale(1.05);
    opacity: 0.25;
  }
}

@keyframes backgroundShift {
  0% {
    background-position: center top;
    transform: scale(1);
  }
  50% {
    background-position: center center;
    transform: scale(1.03);
  }
  100% {
    background-position: center bottom;
    transform: scale(1);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 0.95;
    transform: translateY(0);
  }
}

@keyframes floatIcon {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
    opacity: 0.3;
  }
  50% {
    transform: translateY(-20px) rotate(10deg);
    opacity: 0.5;
  }
}

/* Hero Particles Animation */
.hero-particles {
  pointer-events: none;
}

.particle {
  position: absolute;
  width: 3px;
  height: 3px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  animation: particleFloat 12s infinite ease-in-out;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

.particle:nth-child(1) {
  left: 10%;
  animation-delay: 0s;
  animation-duration: 10s;
}

.particle:nth-child(2) {
  left: 25%;
  animation-delay: 1.5s;
  animation-duration: 12s;
}

.particle:nth-child(3) {
  left: 40%;
  animation-delay: 3s;
  animation-duration: 14s;
}

.particle:nth-child(4) {
  left: 55%;
  animation-delay: 0.5s;
  animation-duration: 11s;
}

.particle:nth-child(5) {
  left: 70%;
  animation-delay: 2s;
  animation-duration: 13s;
}

.particle:nth-child(6) {
  left: 85%;
  animation-delay: 4s;
  animation-duration: 15s;
}

.particle:nth-child(7) {
  left: 15%;
  animation-delay: 1s;
  animation-duration: 11s;
}

.particle:nth-child(8) {
  left: 80%;
  animation-delay: 2.5s;
  animation-duration: 12s;
}

.particle:nth-child(9) {
  left: 30%;
  animation-delay: 1.2s;
  animation-duration: 13s;
}

.particle:nth-child(10) {
  left: 60%;
  animation-delay: 3.5s;
  animation-duration: 14s;
}

/* Shapes */
.shape {
  position: absolute;
  border-radius: 50%;
  opacity: 0.15;
  animation: shapeMove 25s ease-in-out infinite;
  filter: blur(40px);
}

.shape-1 {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.4), transparent);
  top: -200px;
  left: -200px;
  animation-delay: 0s;
}

.shape-2 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.3), transparent);
  bottom: -150px;
  right: -150px;
  animation-delay: 5s;
}

.shape-3 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.35), transparent);
  top: 50%;
  left: 10%;
  animation-delay: 10s;
}

.shape-4 {
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.3), transparent);
  bottom: 20%;
  right: 20%;
  animation-delay: 15s;
}

/* Hero Overlay */
.hero-overlay {
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.7) 100%);
}

/* Auth Background Animation */
.auth-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: linear-gradient(
      rgba(102, 126, 234, 0.85),
      rgba(118, 75, 162, 0.85)
    ),
    url("https://images.unsplash.com/photo-1581092160562-40aa08e78837?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2070&q=80");
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  z-index: -1;
  overflow: hidden;
  animation: backgroundShift 25s ease-in-out infinite alternate;
}

.auth-particles {
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 0;
}

/* Landing Page Animations */
.animate-fade-in {
  animation: fadeInUp 0.8s ease-out forwards;
}

.animate-slide-up {
  animation: fadeInUp 1s ease-out 0.2s forwards;
  opacity: 0;
}

.animate-fade-in-delay {
  animation: fadeInUp 1s ease-out 0.4s forwards;
  opacity: 0;
}

.animate-fade-in-delay-2 {
  animation: fadeInUp 1s ease-out 0.6s forwards;
  opacity: 0;
}

.animate-fade-in-delay-3 {
  animation: fadeInUp 1s ease-out 0.8s forwards;
  opacity: 0;
}

[data-aos] {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.animate-in {
  opacity: 1;
  transform: translateY(0);
}

/* Floating Animation */
.floating {
  animation: float 6s ease-in-out infinite;
}

.illustration i {
  animation: floatIcon 4s ease-in-out infinite;
}

/* Stat Update Animation */
.stat-value.updating {
  animation: statUpdate 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-block;
}

/* Status Dot */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  animation: pulse-opacity 2s ease-in-out infinite;
}

/* Loader */
#loader {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #f8fafc;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.spinner {
  width: 60px;
  height: 60px;
  border: 6px solid #e2e8f0;
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.animate-spin-slow {
  animation: spin 1s linear infinite;
}

/* Sidebar Transitions - Keep for dashboard */
.sidebar {
  width: var(--sidebar-width);
  transition: width 0.3s ease, transform 0.3s ease;
}

.sidebar.sidebar-collapsed {
  width: var(--sidebar-width-collapsed);
}

.main-container {
  transition: margin-left 0.3s ease, width 0.3s ease;
  margin-left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
}

.main-container.sidebar-collapsed {
  margin-left: var(--sidebar-width-collapsed);
  width: calc(100% - var(--sidebar-width-collapsed));
}

/* Sidebar Content Hiding on Collapse */
.sidebar.sidebar-collapsed .brand-text,
.sidebar.sidebar-collapsed .nav-text,
.sidebar.sidebar-collapsed .submenu-arrow,
.sidebar.sidebar-collapsed .user-details {
  opacity: 0;
  display: none;
}

.sidebar.sidebar-collapsed .btn-logout .nav-text {
  display: none;
}

.sidebar.sidebar-collapsed .sidebar-nav li,
.sidebar.sidebar-collapsed .sidebar-footer {
  padding: 0 0.5rem;
}

.sidebar.sidebar-collapsed .nav-link,
.sidebar.sidebar-collapsed .btn-logout {
  justify-content: center;
  padding: 0.5rem;
}

.sidebar.sidebar-collapsed .brand {
  justify-content: center;
}

.sidebar.sidebar-collapsed .brand-icon {
  width: 40px;
  height: 40px;
}

.sidebar.sidebar-collapsed .user-profile {
  justify-content: center;
  padding: 0.25rem;
}

.sidebar.sidebar-collapsed .user-avatar {
  margin: 0;
}

/* Mobile Sidebar Overlay */
.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1040;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

body.sidebar-open .sidebar-overlay {
  opacity: 1;
  visibility: visible;
}

/* Responsive Sidebar overrides for Mobile */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width);
    z-index: 1050;
    transition: transform 0.3s ease;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
    z-index: 1050;
  }

  .main-container,
  .main-container.sidebar-collapsed {
    margin-left: 0;
    width: 100%;
  }

  .sidebar-overlay {
    z-index: 1045;
  }

  body.sidebar-open .sidebar-overlay {
    z-index: 1045;
  }
}

/* Mobile Menu Toggle Animation */
.mobile-menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(6px, 6px);
}

.mobile-menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -7px);
}

/* ✅ FIX BLURRING: Optimize text rendering for crisp display */
* {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ✅ FIX BLURRING: Ensure crisp rendering for body and main content */
body {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ✅ FIX BLURRING: Remove translateZ(0) that causes subpixel blurring */
.bg-white,
.rounded-2xl,
.rounded-xl {
  will-change: auto;
  backface-visibility: visible;
  -webkit-backface-visibility: visible;
}

/* ✅ FIX BLURRING: Ensure crisp text in cards and containers */
.bg-white,
.rounded-2xl,
.rounded-xl,
.shadow-sm,
.shadow-md,
.shadow-lg {
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ✅ PERFORMANCE: Optimize charts container */
canvas {
  will-change: contents;
  contain: layout style paint;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* ✅ PERFORMANCE: Smooth scrolling */
html {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* ✅ FIX BLURRING: Ensure crisp table rendering */
table {
  contain: layout;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* ✅ FIX BLURRING: Ensure crisp text in table cells */
table td,
table th {
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ✅ PERFORMANCE: Reduce repaints during scroll */
.space-y-6 > * {
  contain: layout style;
}

/* ✅ FIX BLURRING: Ensure crisp status badges */
.status-badge,
.fault-badge {
  will-change: contents;
  contain: layout style;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* ✅ PERFORMANCE: Disable animations during scroll (handled by JS) */
body.scrolling * {
  animation-play-state: paused !important;
  transition-duration: 0s !important;
}

/* ✅ FIX BLURRING: Remove translateZ(0) from updating animations */
.updating {
  will-change: transform, opacity;
}

/* ✅ Custom scrollbar for cleaner look */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ✅ FIX BLURRING: Ensure crisp rendering for header and sidebar */
header,
aside,
nav {
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ✅ FIX BLURRING: Ensure crisp text in buttons and inputs */
button,
input,
select,
textarea {
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ✅ FIX BLURRING: Ensure crisp rendering for modal content */
.modal-content,
#faultCodeModal,
#faultCodeModal * {
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ✅ FIX BLURRING: Prevent blurring from transforms in modals */
#faultCodeModal > div {
  transform: scale(1);
  will-change: auto;
}

/* ✅ FIX BLURRING: Ensure crisp text in admin tables */
#adminTabsContent,
#cranes-list-container,
#users-list-container,
#assignments-container {
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ✅ FIX BLURRING: Ensure crisp rendering for dashboard content */
#dashboard-content,
#contentArea {
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ✅ FIX BLURRING: Ensure crisp text in KPI cards */
[id^="kpi-"],
[id*="-status"],
[id*="-badge"] {
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ✅ Utilization Analytics Grid - Ensure full width */
#reports-container .grid.grid-cols-1.sm\:grid-cols-2.lg\:grid-cols-4 {
  width: 100%;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 1023px) {
  #reports-container .grid.grid-cols-1.sm\:grid-cols-2.lg\:grid-cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 639px) {
  #reports-container .grid.grid-cols-1.sm\:grid-cols-2.lg\:grid-cols-4 {
    grid-template-columns: 1fr;
  }
}