/* Custom Styles for Secure Intelligence Network */

/* RTL Support */
[dir="rtl"] {
  text-align: right;
}

[dir="rtl"] .space-x-reverse > * + * {
  margin-right: 1rem;
  margin-left: 0;
}

/* Font Loading */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700&family=Inter:wght@300;400;500;600;700&display=swap');

/* Smooth Scrolling */
html {
  scroll-behavior: smooth;
}

/* Custom Animations */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-fade-in-up {
  animation: fadeInUp 0.8s ease-out;
}

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

.animate-pulse-custom {
  animation: pulse 2s infinite;
}

/* Mobile Drawer Styles */
.mobile-drawer-enter {
  transform: translateX(-100%);
}

.mobile-drawer-enter-rtl {
  transform: translateX(100%);
}

.mobile-drawer-enter-active {
  transform: translateX(0);
  transition: transform 300ms ease-in-out;
}

.mobile-drawer-exit {
  transform: translateX(0);
}

.mobile-drawer-exit-active {
  transform: translateX(-100%);
  transition: transform 300ms ease-in-out;
}

.mobile-drawer-exit-active-rtl {
  transform: translateX(100%);
}

/* Mobile Overlay Animation */
.mobile-overlay-enter {
  opacity: 0;
  visibility: hidden;
}

.mobile-overlay-enter-active {
  opacity: 1;
  visibility: visible;
  transition: opacity 300ms ease-in-out;
}

.mobile-overlay-exit {
  opacity: 1;
  visibility: visible;
}

.mobile-overlay-exit-active {
  opacity: 0;
  visibility: hidden;
  transition: opacity 300ms ease-in-out;
}

/* Focus Ring for Mobile Navigation */
.mobile-nav-link:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.5);
}

/* Prevent scrolling when drawer is open */
.drawer-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* Enhanced z-index and positioning */
/* Navigation Header - Always on Top - Fixed Priority */
nav {
  z-index: 9999 !important;
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  width: 100% !important;
  height: auto !important;
  pointer-events: auto !important;
  transform: none !important;
  isolation: isolate !important;
  contain: layout style paint !important;
}

/* Mobile Menu Button - Absolute Highest Priority */
#mobile-menu-button {
  z-index: 10000 !important;
  position: relative !important;
  pointer-events: auto !important;
  min-width: 48px !important;
  min-height: 48px !important;
  width: 48px !important;
  height: 48px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  touch-action: manipulation !important;
  -webkit-tap-highlight-color: transparent !important;
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
  user-select: none !important;
  transform: none !important;
  isolation: isolate !important;
  contain: layout style paint !important;
  cursor: pointer !important;
  /* Enhanced mobile touch support */
  background: transparent !important;
  border: none !important;
  outline: none !important;
  tap-highlight-color: transparent !important;
  /* Ensure proper hit area */
  padding: 8px !important;
  margin: 0 !important;
  /* Prevent any visual feedback delays */
  -webkit-appearance: none !important;
  appearance: none !important;
  /* Force hardware acceleration for smoother touch */
  will-change: transform !important;
  backface-visibility: hidden !important;
  -webkit-backface-visibility: hidden !important;
}

/* Mobile Overlay - Enhanced */
#mobile-overlay {
  z-index: 9998 !important;
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  background: rgba(0, 0, 0, 0.6) !important;
  backdrop-filter: blur(4px) !important;
  transition: opacity 300ms ease-in-out, visibility 300ms ease-in-out !important;
  will-change: opacity, visibility !important;
  contain: layout style paint !important;
}

#mobile-overlay.opacity-0 {
  opacity: 0 !important;
  pointer-events: none !important;
}

#mobile-overlay.invisible {
  visibility: hidden !important;
  pointer-events: none !important;
}

#mobile-overlay.opacity-100 {
  opacity: 1 !important;
  pointer-events: auto !important;
}

#mobile-overlay.visible {
  visibility: visible !important;
  pointer-events: auto !important;
}

/* Mobile Drawer - Enhanced Positioning */
#mobile-drawer {
  z-index: 9999 !important;
  position: fixed !important;
  top: 0 !important;
  bottom: 0 !important;
  height: 100vh !important;
  width: 80vw !important;
  max-width: 24rem !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch;
  transition: transform 300ms ease-in-out !important;
  will-change: transform !important;
  contain: layout style paint !important;
  pointer-events: auto !important;
  background: rgba(15, 23, 42, 0.98) !important;
  backdrop-filter: blur(24px) !important;
}

/* RTL/LTR positioning */
[dir="rtl"] #mobile-drawer,
.rtl #mobile-drawer,
html[lang="ar"] #mobile-drawer {
  right: 0 !important;
  left: auto !important;
  border-left: 1px solid rgba(51, 65, 85, 0.5) !important;
  border-right: none !important;
}

[dir="ltr"] #mobile-drawer,
.ltr #mobile-drawer,
html[lang="en"] #mobile-drawer {
  left: 0 !important;
  right: auto !important;
  border-right: 1px solid rgba(51, 65, 85, 0.5) !important;
  border-left: none !important;
}

/* Transform states */
#mobile-drawer.translate-x-0 {
  transform: translateX(0) !important;
}

#mobile-drawer.-translate-x-full {
  transform: translateX(-100%) !important;
}

#mobile-drawer.translate-x-full {
  transform: translateX(100%) !important;
}

/* Safe area support for mobile devices */
@supports (padding: max(0px)) {
  #mobile-drawer {
    padding-top: max(env(safe-area-inset-top), 0px) !important;
    padding-bottom: max(env(safe-area-inset-bottom), 0px) !important;
  }
  
  #mobile-drawer.drawer-rtl {
    padding-right: max(env(safe-area-inset-right), 0px) !important;
  }
  
  #mobile-drawer.drawer-ltr {
    padding-left: max(env(safe-area-inset-left), 0px) !important;
  }
}

/* Prevent scrolling when drawer is open - Simplified */
.drawer-open,
body.drawer-open {
  overflow: hidden !important;
}

/* Ensure header stays fixed during scroll */
.header-fixed {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  z-index: 9999 !important;
  width: 100% !important;
  height: auto !important;
}

/* Fix any background elements that might interfere */
.hero-section {
  padding-top: 80px !important; /* Account for fixed header height */
  position: relative;
  z-index: 1 !important;
}

.hero-background-elements {
  pointer-events: none !important;
  z-index: 0 !important;
}

/* Hide elements while drawer is open */
body.drawer-open .floating-ui,
body.drawer-open .fixed:not(nav):not(#mobile-overlay):not(#mobile-drawer):not(#mobile-menu-button) {
  display: none !important;
}

/* Prevent any element from capturing clicks above header */
.hero-section *,
.hero-section svg,
.hero-section div {
  pointer-events: none !important;
}

.hero-section a,
.hero-section button,
.hero-section input,
.hero-section textarea,
.hero-section select {
  pointer-events: auto !important;
}

/* Ensure navigation elements always work */
nav,
nav *,
nav a,
nav button,
nav input {
  pointer-events: auto !important;
}

/* Additional header stability rules */
.header-container {
  position: relative !important;
  z-index: inherit !important;
  pointer-events: auto !important;
}

/* Force header to stay fixed on mobile */
@media (max-width: 768px) {
  nav[class*="fixed"] {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 9999 !important;
  }
  
  /* Prevent scroll interference with header */
  body {
    padding-top: 0 !important;
  }
  
  /* Ensure mobile button always works */
  button[id*="mobile-menu"] {
    position: relative !important;
    z-index: 10000 !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
  }
}

/* Menu icon transitions */
#menu-icon-hamburger,
#menu-icon-close {
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none !important; /* Icons should not capture events */
  position: relative !important;
  z-index: inherit !important;
}

#menu-icon-hamburger.hidden,
#menu-icon-close.hidden {
  opacity: 0;
  transform: scale(0.8);
}

/* Ensure SVG icons inside button don't interfere */
#mobile-menu-button svg,
#mobile-menu-button path,
#mobile-menu-button * {
  pointer-events: none !important;
  touch-action: none !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

/* Prevent decorative elements from capturing clicks - Enhanced */
.absolute[class*="bg-"],
.absolute svg,
.absolute[class*="animate-"],
section .absolute,
.hero-parallax .absolute,
[class*="wave"],
section[class*="bg-gradient-"] .absolute,
section[class*="bg-gradient-"] > .absolute,
.absolute[class*="rounded-full"] {
  pointer-events: none !important;
  z-index: 0 !important;
  position: absolute !important;
  isolation: isolate !important;
}

/* Ensure navigation elements stay clickable */
nav button,
nav a,
nav div {
  pointer-events: auto !important;
  position: relative !important;
  z-index: inherit !important;
}

/* Mobile Menu Button Container */
.md\:hidden {
  position: relative !important;
  z-index: 10000 !important;
  pointer-events: auto !important;
}

/* Responsive visibility */
@media (min-width: 769px) {
  #mobile-drawer,
  #mobile-overlay {
    display: none !important;
  }
}

@media (max-width: 768px) {
  .md\\:hidden {
    display: block;
  }
  
  /* Ensure mobile header is always fixed and on top */
  nav {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 9999 !important;
    width: 100% !important;
  }
  
  /* Mobile menu button enhanced */
  #mobile-menu-button {
    position: relative !important;
    z-index: 10000 !important;
    min-width: 48px !important;
    min-height: 48px !important;
    padding: 8px !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent !important;
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
    /* Enhanced mobile interaction */
    background: rgba(255, 255, 255, 0.1) !important;
    border-radius: 8px !important;
    transition: background-color 0.15s ease !important;
    /* Ensure button stays above all content */
    isolation: isolate !important;
    contain: layout style paint !important;
    /* Force layer creation for better performance */
    transform: translateZ(0) !important;
    will-change: background-color !important;
  }
  
  /* Mobile button hover/active states for better feedback */
  #mobile-menu-button:active,
  #mobile-menu-button:focus {
    background: rgba(255, 255, 255, 0.2) !important;
    outline: none !important;
  }
  
  /* Prevent any interference with mobile header */
  .hero-section {
    padding-top: 80px !important;
  }
}

/* Gradient Text */
.gradient-text {
  background: linear-gradient(135deg, #1e3a8a, #3b82f6, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Hover Effects */
.hover-lift {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.hover-lift:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

/* Custom Buttons */
.btn-primary {
  background: linear-gradient(135deg, #1e3a8a, #3b82f6);
  border: none;
  color: white;
  padding: 0.75rem 2rem;
  border-radius: 0.5rem;
  font-weight: 600;
  transition: all 0.3s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #1e40af, #2563eb);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
  border: none;
  color: white;
  padding: 0.75rem 2rem;
  border-radius: 0.5rem;
  font-weight: 600;
  transition: all 0.3s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-secondary:hover {
  background: linear-gradient(135deg, #d97706, #f59e0b);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(245, 158, 11, 0.3);
}

/* Navigation Styles */
.nav-link {
  position: relative;
  transition: color 0.3s ease;
}

.nav-link::after {
  content: '';
  position: absolute;
  width: 0;
  height: 2px;
  bottom: -5px;
  left: 50%;
  background-color: #f59e0b;
  transition: all 0.3s ease;
  transform: translateX(-50%);
}

.nav-link:hover::after,
.nav-link.text-primary::after {
  width: 80%;
}

/* Card Styles */
.service-card {
  background: white;
  border-radius: 1rem;
  padding: 2rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.service-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  border-color: #3b82f6;
}

/* Form Styles */
.form-input {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: 0.5rem;
  font-size: 1rem;
  transition: all 0.3s ease;
  background-color: white;
}

.form-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-input:focus:invalid {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* Loading Spinner */
.spinner {
  border: 2px solid #f3f4f6;
  border-top: 2px solid #3b82f6;
  border-radius: 50%;
  width: 1.5rem;
  height: 1.5rem;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Success/Error Messages */
.alert {
  padding: 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
}

.alert-success {
  background-color: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.alert-error {
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
}

/* Mobile Menu Animation */
#mobile-menu {
  transition: all 0.3s ease;
  overflow: hidden;
  max-height: 0;
}

#mobile-menu.show {
  max-height: 500px;
}

/* Parallax Effect for Hero Section */
.hero-parallax {
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

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

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

::-webkit-scrollbar-thumb:hover {
  background: #1e40af;
}

/* Print Styles */
@media print {
  .no-print {
    display: none !important;
  }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  .bg-gray-50 {
    background-color: #ffffff;
  }
  
  .text-gray-600 {
    color: #000000;
  }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Dark Mode Support (Future Enhancement) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1f2937;
    --text-primary: #f9fafb;
  }
}

/* Responsive Typography */
@media (max-width: 640px) {
  h1 {
    font-size: 1.875rem;
    line-height: 2.25rem;
  }
  
  h2 {
    font-size: 1.5rem;
    line-height: 2rem;
  }
  
  .hero-title {
    font-size: 2.5rem;
    line-height: 1.2;
  }
}

/* Focus Styles for Accessibility */
*:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Skip Link for Screen Readers */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: #3b82f6;
  color: white;
  padding: 8px;
  text-decoration: none;
  border-radius: 4px;
  z-index: 1000;
}

.skip-link:focus {
  top: 6px;
}

/* Loading States */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.loading * {
  cursor: wait !important;
}

/* Mobile Touch Optimization - Critical Rules */
@media (max-width: 768px) {
  /* Ensure mobile button container has proper touch area */
  .md\:flex .md\:hidden,
  button.md\:flex.md\:hidden {
    position: relative !important;
    z-index: 10000 !important;
    min-width: 48px !important;
    min-height: 48px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    border: none !important;
    outline: none !important;
    cursor: pointer !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent !important;
    -webkit-touch-callout: none !important;
    user-select: none !important;
  }
  
  /* Force all navigation children to respect button boundaries */
  nav > div > div,
  nav > div > div > *,
  .header-container > *,
  .header-container > div > * {
    position: relative !important;
    z-index: inherit !important;
  }
  
  /* Prevent any overflow or positioning issues in header */
  nav,
  nav > *,
  .header-container {
    overflow: visible !important;
    position: relative !important;
  }
  
  /* Ensure button wrapper doesn't clip touch area */
  .md\:hidden {
    overflow: visible !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: auto !important;
    height: auto !important;
    min-width: 48px !important;
    min-height: 48px !important;
  }
  
  /* Critical: Prevent any element from overlaying the button area */
  nav .absolute,
  .header-container .absolute,
  header .absolute {
    z-index: 1 !important;
    pointer-events: none !important;
  }
  
  /* Force proper stacking context for mobile header */
  nav[class*="bg-"] {
    isolation: isolate !important;
    contain: layout style !important;
  }
}

/* Debug helper - remove in production */
#mobile-menu-button::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border: 1px dashed rgba(255, 0, 0, 0.3);
  pointer-events: none;
  z-index: -1;
  border-radius: 8px;
}