@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  :root {
    --background: 0 0% 100%;
    --foreground: 222.2 84% 4.9%;

    --card: 0 0% 100%;
    --card-foreground: 222.2 84% 4.9%;

    --popover: 0 0% 100%;
    --popover-foreground: 222.2 84% 4.9%;

    --primary: 222.2 47.4% 11.2%;
    --primary-foreground: 210 40% 98%;

    --secondary: 210 40% 96.1%;
    --secondary-foreground: 222.2 47.4% 11.2%;

    --muted: 210 40% 96.1%;
    --muted-foreground: 215.4 16.3% 46.9%;

    --accent: 210 40% 96.1%;
    --accent-foreground: 222.2 47.4% 11.2%;

    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 210 40% 98%;

    --border: 214.3 31.8% 91.4%;
    --input: 214.3 31.8% 91.4%;
    --ring: 222.2 84% 4.9%;

    --radius: 0.5rem;

    --sidebar-background: 0 0% 98%;

    --sidebar-foreground: 240 5.3% 26.1%;

    --sidebar-primary: 240 5.9% 10%;

    --sidebar-primary-foreground: 0 0% 98%;

    --sidebar-accent: 240 4.8% 95.9%;

    --sidebar-accent-foreground: 240 5.9% 10%;

    --sidebar-border: 220 13% 91%;

    --sidebar-ring: 217.2 91.2% 59.8%;
  }

  .dark {
    --background: 222.2 84% 4.9%;
    --foreground: 210 40% 98%;

    --card: 222.2 84% 4.9%;
    --card-foreground: 210 40% 98%;

    --popover: 222.2 84% 4.9%;
    --popover-foreground: 210 40% 98%;

    --primary: 210 40% 98%;
    --primary-foreground: 222.2 47.4% 11.2%;

    --secondary: 217.2 32.6% 17.5%;
    --secondary-foreground: 210 40% 98%;

    --muted: 217.2 32.6% 17.5%;
    --muted-foreground: 215 20.2% 65.1%;

    --accent: 217.2 32.6% 17.5%;
    --accent-foreground: 210 40% 98%;

    --destructive: 0 62.8% 30.6%;
    --destructive-foreground: 210 40% 98%;

    --border: 217.2 32.6% 17.5%;
    --input: 217.2 32.6% 17.5%;
    --ring: 212.7 26.8% 83.9%;
    --sidebar-background: 240 5.9% 10%;
    --sidebar-foreground: 240 4.8% 95.9%;
    --sidebar-primary: 224.3 76.3% 48%;
    --sidebar-primary-foreground: 0 0% 100%;
    --sidebar-accent: 240 3.7% 15.9%;
    --sidebar-accent-foreground: 240 4.8% 95.9%;
    --sidebar-border: 240 3.7% 15.9%;
    --sidebar-ring: 217.2 91.2% 59.8%;
  }
}

@layer base {
  * {
    @apply border-border;
  }

  body {
    @apply bg-background text-foreground;
  }

  /* Responsive tables */
  .table-container {
    @apply w-full overflow-x-auto;
  }

  @media (max-width: 768px) {
    table {
      @apply text-sm;
    }
    
    th, td {
      @apply px-2 py-1.5;
    }
  }

  /* Responsive dialogs */
  @media (max-width: 640px) {
    [role="dialog"] {
      @apply max-w-[95vw];
    }
  }

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

  /* Hide scrollbar for Chrome, Safari and Opera */
  .no-scrollbar::-webkit-scrollbar {
    display: none;
  }

  /* Hide scrollbar for IE, Edge and Firefox */
  .no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }

  /* Print styles */
  @media print {
    @page {
      size: A4;
      margin: 1cm;
    }

    body {
      print-color-adjust: exact;
      -webkit-print-color-adjust: exact;
    }

    .print\:hidden {
      display: none !important;
    }

    .print\:block {
      display: block !important;
    }

    .print\:break-inside-avoid {
      break-inside: avoid;
    }

    .print\:p-8 {
      padding: 2rem;
    }

    .print\:grid-cols-4 {
      grid-template-columns: repeat(4, minmax(0, 1fr));
    }

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

    .print\:mt-4 {
      margin-top: 1rem;
    }
  }
}

/* Leaflet map custom styles */
.leaflet-container {
  font-family: inherit;
  direction: rtl;
  z-index: 1;
}

.leaflet-popup-content-wrapper {
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.leaflet-popup-content {
  margin: 0;
  min-width: 200px;
}

/* Custom marker animations */
@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }
}

.custom-location-marker,
.current-location-marker,
.temp-location-marker {
  animation: pulse 2s infinite;
}

/* Motorcycle marker - smooth rotation */
.motorcycle-marker {
  transition: transform 0.5s ease-out;
}

.motorcycle-marker img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Leaflet controls RTL fix */
.leaflet-control {
  direction: ltr;
}

.leaflet-bar {
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  border-radius: 4px;
}

/* Map container */
.leaflet-container a {
  color: #3b82f6;
}

.leaflet-touch .leaflet-bar {
  border: none;
}

/* Document preview styles for Word templates */
.document-content {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.document-content p {
  margin-bottom: 0.5em;
  line-height: 1.5;
}

.document-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  direction: rtl;
}

.document-content table td,
.document-content table th {
  border: 1px solid #000;
  padding: 8px;
  text-align: right;
}

.document-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1em auto;
}

.document-content h1,
.document-content h2,
.document-content h3 {
  margin-top: 1em;
  margin-bottom: 0.5em;
  font-weight: bold;
}

.document-content strong,
.document-content b {
  font-weight: bold;
}

.document-content em,
.document-content i {
  font-style: italic;
}

.document-content ul,
.document-content ol {
  margin: 0.5em 0;
  padding-right: 2em;
}

/* Preserve red text color for editable fields */
.document-content [style*="color: rgb(255, 0, 0)"],
.document-content [style*="color: red"],
.document-content [style*="color:#ff0000"],
.document-content [style*="color:#FF0000"] {
  color: #ef4444 !important;
  background-color: #fef2f2;
  padding: 2px 4px;
  border-bottom: 2px dashed #ef4444;
}

/* Fullscreen dialogs override for mobile */
@media (max-width: 640px) {
  .chat-fullscreen[role="dialog"] {
    max-width: 100vw !important;
    max-height: 100svh !important;
  }
}

/* Fullscreen chat layout helper */
.chat-fullscreen {
  contain: layout;
}
.chat-fullscreen > * {
  height: 100svh;
}

/* Safe area for iOS devices */
@supports (padding: max(0px)) {
  .safe-area-bottom {
    padding-bottom: max(env(safe-area-inset-bottom), 0.75rem);
  }
}

/* Smooth message animations */
@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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