/* Navbar Styles */
.navbar {
  position: sticky; 
  top: 0; 
  z-index: 40; 
  backdrop-filter: saturate(140%) blur(10px);
  background: rgba(17,19,24,.5); 
  border-bottom: 1px solid #1e2431;
  direction: ltr; /* Force LTR for navbar structure */
}

/* Light mode navbar */
[data-theme="light"] .navbar {
  background: rgba(248,250,252,.85);
  border-bottom: 1px solid #e2e8f0;
}

.nav-inner { 
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
  padding: 14px 0; 
  width: 100%;
  max-width: 100%;
}

/* Brand section with better RTL support */
.brand { 
  display: flex; 
  gap: 10px; 
  align-items: center; 
  font-weight: 800; 
  letter-spacing: .2px;
  flex-shrink: 0;
  direction: ltr; /* Keep brand LTR for consistency */
}

.brand-name {
  font-size: 1.25rem;
  white-space: nowrap;
}

.brand-logo { 
  width: 32px; 
  height: 32px; 
  border-radius: 9px; 
  background: conic-gradient(from 210deg, var(--primary), var(--accent)); 
  box-shadow: 0 6px 14px rgba(56,189,248,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
  margin-left: 10px;

}

.brand-logo svg {
  width: 24px;
  height: 24px;
}


/* Light mode brand logo */
[data-theme="light"] .brand-logo {
  box-shadow: 0 6px 14px rgba(14,165,233,.25);
  color: white;
}

/* Enhanced nav actions with better spacing for Arabic */
.nav-actions { 
  display: flex; 
  gap: 12px; /* Increased from 10px for better Arabic spacing */
  align-items: center; 
  flex-shrink: 0;
}

.cart-btn { 
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: auto;
  white-space: nowrap;
}

.cart-icon {
  font-size: 18px;
  display: flex;
  align-items: center;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.theme-icon {
  font-size: 18px;
  display: flex;
  align-items: center;
}

.cart-count { 
  position: absolute; 
  top: -6px; 
  right: -6px; 
  background: var(--error); 
  color: #fff; 
  font-size: 11px; 
  border-radius: 999px; 
  padding: 2px 6px; 
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

/* Quick checkout button responsive text */
#checkoutQuick {
  white-space: nowrap;
  margin-right: 10px;
}

/* Tablet styles */
@media (max-width: 1024px) {
  .nav-inner {
    padding: 12px 0;
  }
  
  .nav-actions {
    gap: 8px;
  }
}

/* Small tablet/large phone styles */
@media (max-width: 768px) {
  .navbar {
    padding: 0 16px;
  }

  .nav-inner {
    padding: 10px 0;
  }

  .brand-name {
    font-size: 1.1rem;
  }

  .nav-actions {
    gap: 6px;
  }

  .cart-count {
    font-size: 10px;
    min-width: 16px;
    height: 16px;
    padding: 1px 4px;
  }

  /* Adjust button sizes */
  .theme-toggle {
    min-width: 36px;
    height: 36px;
  }

  .cart-btn {
    padding: 8px 12px;
    font-size: 14px;
  }

  #checkoutQuick {
    padding: 8px 12px;
    font-size: 14px;
  }
}

/* Mobile styles */
@media (max-width: 640px) {
  .navbar {
    padding: 0 12px;
  }

  .brand-name {
    font-size: 1rem;
  }

  .brand-logo {
    width: 28px;
    height: 28px;
  }

  .brand-logo svg {
    width: 20px;
    height: 20px;
  }

  .nav-actions {
    gap: 4px;
  }

  /* Hide checkout button text on small screens */
  #checkoutQuick {
    font-size: 0;
    padding: 8px;
    min-width: 40px; /* Increased from 36px */
  }
  
  /* Better icon for Arabic context */
  #checkoutQuick::before {
    content: "💳";
    font-size: 16px;
  }
  
  [lang="ar"] #checkoutQuick::before,
  [data-lang="ar"] #checkoutQuick::before {
    content: "🛒"; /* Shopping cart icon for Arabic */
  }
}

@media  (max-width: 480px) {
  .navbar {
    padding: 0 8px;
  }

  .nav-inner {
    padding: 8px 0;
    position: relative;
  }

  .brand-name {
    display: none; /* Hide brand name on very small screens */
  }

  .brand {
    gap: 0;
  }

  .brand-logo {
    width: 24px;
    height: 24px;
  }

  .brand-logo svg {
    width: 16px;
    height: 16px;
  }

  /* Hide original nav-actions and replace with hamburger */
  .nav-actions {
    display: none;
  }

  /* Mobile hamburger menu */
  .mobile-menu-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    color: var(--text);
    transition: transform 0.2s ease;
  }

  .mobile-menu-toggle:hover {
    transform: scale(1.1);
  }

  .hamburger {
    width: 20px;
    height: 16px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }

  .hamburger span {
    display: block;
    height: 2px;
    width: 100%;
    background: var(--text);
    border-radius: 1px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
  }

  /* Hamburger animation to X */
  .mobile-menu-toggle.open .hamburger span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }

  .mobile-menu-toggle.open .hamburger span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
  }

  .mobile-menu-toggle.open .hamburger span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

  /* Mobile drawer */
  .mobile-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    height: 100vh;
    background: var(--panel);
    border-left: 1px solid var(--border);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(20px);
    z-index: 50;
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
  }

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

  .mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--panel-2);
  }

  .mobile-drawer-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    color: var(--text);
  }

  .mobile-drawer-brand .brand-logo {
    width: 28px;
    height: 28px;
  }

  .mobile-drawer-brand .brand-logo svg {
    width: 18px;
    height: 18px;
  }

  .mobile-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted);
    transition: all 0.2s ease;
    border-radius: 6px;
  }

  .mobile-close-btn:hover {
    background: var(--panel);
    color: var(--text);
  }

  .mobile-drawer-content {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 18px; /* Increased from 16px */
    direction: ltr; /* Keep structure LTR */
  }

  .mobile-nav-item {
    display: flex;
    align-items: center;
    gap: 14px; /* Increased from 12px */
    padding: 14px 18px; /* Increased padding */
    border-radius: 12px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    color: var(--text);
    min-height: 48px; /* Ensure consistent height */
  }

  .mobile-nav-item .nav-text {
    font-weight: 500;
    flex: 1;
    font-size: 15px; /* Slightly larger for better readability */
    line-height: 1.4;
  }

  /* Arabic text in mobile nav */
  [lang="ar"] .mobile-nav-item .nav-text,
  [data-lang="ar"] .mobile-nav-item .nav-text {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-weight: 400;
    font-size: 16px; /* Larger for Arabic readability */
    letter-spacing: 0;
    text-align: right; /* Right align Arabic text */
    direction: rtl; /* RTL for Arabic text */
  }

  /* Language switcher improvements */
  .mobile-language-section {
    margin-top: 12px; /* Increased spacing */
  }

  .mobile-language-options {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    margin-top: 8px; /* Increased from 4px */
  }

  .mobile-lang-option {
    display: flex;
    align-items: center;
    gap: 12px; /* Increased from 8px */
    padding: 12px 16px; /* Increased padding */
    margin: 4px 0; /* Increased from 2px */
    border: none;
    background: var(--panel);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    color: var(--text);
    font-size: 14px;
    min-height: 44px; /* Ensure touch-friendly height */
  }

  /* Better Arabic language option styling */
  .mobile-lang-option .lang-name {
    flex: 1;
    text-align: left;
    font-weight: 500;
    font-size: 15px;
  }

  .mobile-lang-option[data-lang="ar"] .lang-name {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 16px;
    font-weight: 400;
    text-align: right;
    direction: rtl;
  }

  .mobile-theme-toggle {
    margin-bottom: auto;
    padding-top: 24px; /* Increased from 20px */
    border-top: 1px solid var(--border);
  }

  /* Responsive improvements for Arabic */
  @media (max-width: 768px) {
    .nav-actions {
      gap: 10px; /* Slightly reduced for smaller screens */
    }
    
    .nav-actions .btn {
      padding: 8px 14px;
      font-size: 14px;
    }
    
    [lang="ar"] .nav-actions .btn,
    [data-lang="ar"] .nav-actions .btn {
      padding: 8px 16px;
    }
  }

  @media (max-width: 640px) {
    .nav-actions {
      gap: 8px;
    }
    
    /* Improved checkout button for Arabic */
    #checkoutQuick {
      font-size: 0;
      padding: 8px;
      min-width: 40px; /* Increased from 36px */
    }
    
    /* Better icon for Arabic context */
    #checkoutQuick::before {
      content: "💳";
      font-size: 16px;
    }
    
    [lang="ar"] #checkoutQuick::before,
    [data-lang="ar"] #checkoutQuick::before {
      content: "🛒"; /* Shopping cart icon for Arabic */
    }
  }

  @media (max-width: 480px) {
    /* Mobile drawer spacing for Arabic */
    .mobile-drawer-content {
      gap: 16px;
      padding: 18px;
    }
    
    .mobile-nav-item {
      gap: 12px;
      padding: 12px 16px;
    }
    
    [lang="ar"] .mobile-nav-item .nav-text,
    [data-lang="ar"] .mobile-nav-item .nav-text {
      font-size: 15px;
    }
  }

  /* RTL layout support for Arabic */
  [lang="ar"] .navbar,
  [data-lang="ar"] .navbar {
    direction: rtl;
  }

  [lang="ar"] .nav-inner,
  [data-lang="ar"] .nav-inner {
    direction: rtl;
  }

  [lang="ar"] .brand,
  [data-lang="ar"] .brand {
    direction: ltr; /* Keep brand LTR */
    order: 2; /* Move to right side in RTL */
  }

  [lang="ar"] .nav-actions,
  [data-lang="ar"] .nav-actions {
    direction: rtl;
    order: 1; /* Move to left side in RTL */
  }

  [lang="ar"] .mobile-menu-toggle,
  [data-lang="ar"] .mobile-menu-toggle {
    order: 3; /* Keep hamburger on the right in RTL */
  }

  /* Mobile drawer RTL support */
  [lang="ar"] .mobile-drawer,
  [data-lang="ar"] .mobile-drawer {
    right: auto;
    left: 0;
    transform: translateX(-100%);
    border-right: 1px solid var(--border);
    border-left: none;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.3);
    direction: rtl;
  }

  [lang="ar"] .mobile-drawer.open,
  [data-lang="ar"] .mobile-drawer.open {
    transform: translateX(0);
  }

  [lang="ar"] .mobile-drawer-header,
  [data-lang="ar"] .mobile-drawer-header {
    direction: rtl;
  }

  [lang="ar"] .mobile-nav-item,
  [data-lang="ar"] .mobile-nav-item {
    direction: rtl;
  }

  [lang="ar"] .mobile-nav-item:hover,
  [data-lang="ar"] .mobile-nav-item:hover {
    transform: translateX(-4px); /* Reverse direction for RTL */
  }

  /* Smooth transitions for language switching */
  .navbar,
  .nav-inner,
  .nav-actions,
  .mobile-drawer,
  .mobile-nav-item {
    transition: all 0.3s ease;
  }

  /* Improved text rendering for Arabic */
  [lang="ar"],
  [data-lang="ar"] {
    font-feature-settings: "liga" 1, "kern" 1;
    text-rendering: optimizeLegibility;
  }
}

/* Show hamburger menu only on mobile */
.mobile-menu-toggle {
  display: none;
}

@media (min-width: 481px) {
  .mobile-drawer,
  .mobile-drawer-backdrop {
    display: none !important;
  }
}

/* Extra small screens */
@media (max-width: 360px) {
  .navbar {
    padding: 0 4px;
  }

  .nav-inner {
    padding: 8px 0;
  }

  .nav-actions {
    gap: 2px;
  }

  .brand-logo {
    width: 28px;
    height: 28px;
  }

  .brand-logo svg {
    width: 18px;
    height: 18px;
  }

  .theme-toggle,
  #checkoutQuick {
    min-width: 28px;
    height: 28px;
    padding: 4px;
  }

  .cart-btn {
    padding: 4px 6px;
  }
}

/* Landscape mobile orientation */
@media (max-height: 500px) and (orientation: landscape) {
  .nav-inner {
    padding: 8px 0;
  }

  .brand-logo {
    width: 28px;
    height: 28px;
  }

  .theme-toggle,
  .cart-btn,
  #checkoutQuick {
    height: 32px;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  .theme-toggle,
  .cart-btn,
  #checkoutQuick {
    min-height: 44px; /* iOS touch target recommendation */
  }

  .cart-count {
    pointer-events: none; /* Prevent accidental touches */
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .brand-logo {
    box-shadow: 0 6px 14px rgba(56,189,248,.4);
  }

  [data-theme="light"] .brand-logo {
    box-shadow: 0 6px 14px rgba(14,165,233,.3);
  }
}

/* Print styles */
@media print {
  .navbar {
    position: static;
    background: transparent;
    border-bottom: 1px solid #000;
    box-shadow: none;
  }

  .nav-actions {
    display: none;
  }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  .brand-logo {
    transition: none;
  }
  
  .theme-toggle,
  .cart-btn,
  #checkoutQuick {
    transition: none;
  }
}