/* ==========================================================================
   Connect Plus - Premium Stylesheet (RTL & Dark/Light Theme Support)
   ========================================================================== */

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

:root {
  --font-cairo: 'Cairo', system-ui, -apple-system, sans-serif;
  --font-inter: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-primary-light: #3b82f6;
  --color-accent: #06b6d4;
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --color-purple: #8b5cf6;
  
  /* Light Theme */
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(226, 232, 240, 0.8);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-glow: 0 0 20px rgba(37, 99, 235, 0.15);
}

[data-theme="dark"],
html.dark {
  --bg-main: #0b0f19;
  --bg-card: #131b2e;
  --bg-card-subtle: #1a243b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #1e293b;
  --glass-bg: rgba(19, 27, 46, 0.92);
  --glass-border: rgba(30, 41, 59, 0.85);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 25px rgba(59, 130, 246, 0.25);
}

* {
  box-sizing: border-box;
}

[dir="rtl"], html[dir="rtl"] * {
  font-family: var(--font-cairo);
}

[dir="ltr"], html[dir="ltr"] * {
  font-family: var(--font-inter);
}

html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden !important;
  position: relative;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  margin: 0;
  padding: 0;
  overflow-x: hidden !important;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* RTL Direction (Arabic) */
[dir="rtl"], html[dir="rtl"] body {
  direction: rtl;
  text-align: right;
}

/* LTR Direction (English) */
[dir="ltr"], html[dir="ltr"] body {
  direction: ltr;
  text-align: left;
}

/* Inputs & Forms Direction Support */
[dir="rtl"] input,
[dir="rtl"] textarea,
[dir="rtl"] select {
  direction: rtl;
  text-align: right;
}

[dir="ltr"] input,
[dir="ltr"] textarea,
[dir="ltr"] select {
  direction: ltr;
  text-align: left;
}

/* Automatically flip general text-right to left in LTR mode */
html[dir="ltr"] .text-right:not(.keep-right) {
  text-align: left !important;
}

/* Mobile Drawer alignment for LTR */
html[dir="ltr"] #mobileMenuDrawerContent {
  left: 0 !important;
  right: auto !important;
  border-left: none !important;
  border-right: 1px solid #1e293b !important;
}

header, main, footer, nav, #pwaDirectBanner, #mobileRoleNav, #mobileBottomBar {
  max-width: 100vw !important;
  box-sizing: border-box !important;
}

/* Mobile responsive layout fixes */
@media (max-width: 640px) {
  .glass-panel {
    padding: 1rem !important;
  }
}

/* Glassmorphism Classes */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-md);
}

.glass-panel-glow {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-glow);
}

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

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #94a3b840;
  border-radius: 9999px;
}

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

/* Pulsing Badge & Live Indicator */
.live-pulse {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #10b981;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 8px rgba(16, 185, 129, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.animate-slide-right {
  animation: slideInRight 0.35s ease-out forwards;
}

/* Stepper Track Animation */
.step-active {
  background: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.step-done {
  background: #10b981;
  color: white;
}

.step-pending {
  background: var(--bg-card-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

/* Barcode Font / Style */
.barcode-box {
  font-family: 'Courier New', Courier, monospace;
  letter-spacing: 3px;
  background: #ffffff;
  color: #000000;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px dashed #64748b;
  display: inline-block;
}

/* Driver Phone Frame Simulator */
.driver-phone-container {
  max-width: 420px;
  margin: 0 auto;
  border: 10px solid #1e293b;
  border-radius: 36px;
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  background: var(--bg-main);
  position: relative;
}

.driver-phone-notch {
  width: 130px;
  height: 20px;
  background: #1e293b;
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
  z-index: 50;
}

/* Signature Pad Canvas */
.signature-canvas-pad,
#signatureCanvas,
#signatureCanvasDesktop,
#signatureCanvasMobile {
  background: #ffffff;
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  cursor: crosshair;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
}

/* Mobile App Bar & Responsive Rules */
@media (max-width: 1023px) {
  body {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  
  .driver-phone-container {
    border: none;
    max-width: 100%;
    border-radius: 1.25rem;
    box-shadow: none;
  }
  
  .driver-phone-notch {
    display: none;
  }

  /* Compact glass panels on mobile */
  .glass-panel {
    border-radius: 1.25rem;
  }
}

/* ==========================================================================
   Mobile Web App Enhancements (Native App Feel)
   ========================================================================== */

/* 1. Mobile Pill Tabs Horizontal Scroller */
.mobile-pill-tabs,
.no-scrollbar {
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

.mobile-pill-tabs::-webkit-scrollbar,
.no-scrollbar::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.mobile-pill-tabs > * {
  flex-shrink: 0;
}

/* 2. Safe Area Insets for Modern Mobile Devices (Notch & Home Bar) */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #mobileBottomBar {
    padding-bottom: max(0.5rem, calc(env(safe-area-inset-bottom) + 0.25rem));
  }
  #globalModal > div {
    padding-bottom: max(1.25rem, calc(env(safe-area-inset-bottom) + 1rem));
  }
}

/* 3. Mobile Bottom Sheet Modal Transition & Styling */
@media (max-width: 639px) {
  #globalModal {
    padding: 0 !important;
    align-items: flex-end !important;
  }
  #globalModal > div {
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    border-top-left-radius: 1.75rem !important;
    border-top-right-radius: 1.75rem !important;
    max-height: 88vh !important;
    width: 100% !important;
    max-width: 100% !important;
    animation: slideUpMobile 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  }
}

@keyframes slideUpMobile {
  from {
    transform: translateY(100%);
    opacity: 0.5;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* 4. Touch-Friendly Interactive Elements */
@media (max-width: 768px) {
  button, select, input, a {
    min-height: 38px;
  }
  .barcode-box {
    word-break: break-all;
  }
}

/* Responsive Navigation Bar Polish & Spacing */
#desktopRoleNav {
  max-width: fit-content;
  white-space: nowrap;
}

#headerActionsContainer {
  flex-shrink: 0 !important;
  white-space: nowrap !important;
}

#headerActionsContainer > * {
  flex-shrink: 0 !important;
}

@media (min-width: 1024px) and (max-width: 1260px) {
  #desktopRoleNav {
    gap: 0.2rem !important;
    padding: 0.2rem !important;
  }
  #desktopRoleNav .nav-btn {
    padding: 0.25rem 0.35rem !important;
    font-size: 0.68rem !important;
    gap: 0.2rem !important;
  }
  #desktopRoleNav .nav-btn i {
    width: 0.85rem !important;
    height: 0.85rem !important;
  }
  .manager-tab-badge {
    max-width: 78px !important;
    padding-left: 0.35rem !important;
    padding-right: 0.35rem !important;
  }
  .manager-tab-role {
    display: none !important;
  }
}

@media (min-width: 1261px) and (max-width: 1440px) {
  #desktopRoleNav .nav-btn {
    padding: 0.35rem 0.5rem;
    font-size: 0.72rem;
    gap: 0.25rem;
  }
}

/* Print Stylesheet for AWB and Invoices */
@media print {
  body * {
    visibility: hidden;
  }
  #printModalContainer, #printModalContainer * {
    visibility: visible;
  }
  #printModalContainer {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    background: #ffffff !important;
    color: #000000 !important;
  }
  .no-print {
    display: none !important;
  }
}

/* Logo Styling - Crisp Vector Rendering without blur or shadow */
.logo-glow {
  filter: none;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.logo-glow:hover {
  filter: none;
  transform: scale(1.03);
}

