@tailwind base;
@tailwind components;
@tailwind utilities;

/* Custom styles */
html {
  font-size: 14px;
  scroll-behavior: smooth;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  margin-bottom: 60px;
}

/* RTL/LTR support using logical properties */
[dir="rtl"] {
  direction: rtl;
}

[dir="ltr"] {
  direction: ltr;
}

/* Logical properties for spacing - automatically adapts to RTL/LTR */
[dir="rtl"] .space-x-reverse > * + * {
  margin-right: 0.5rem;
  margin-left: 0;
}

[dir="ltr"] .space-x-reverse > * + * {
  margin-left: 0.5rem;
  margin-right: 0;
}

/* Sidebar positioning */
[dir="rtl"] #sidebar {
  right: 0;
  left: auto;
}

[dir="ltr"] #sidebar {
  left: 0;
  right: auto;
}

/* Main content margin - using logical properties */
[dir="rtl"] main[class*="lg:mr-64"] {
  margin-right: 16rem;
  margin-left: 0;
}

[dir="ltr"] main[class*="lg:ml-64"] {
  margin-left: 16rem;
  margin-right: 0;
}

/* Text alignment */
[dir="rtl"] .text-start {
  text-align: right;
}

[dir="ltr"] .text-start {
  text-align: left;
}

[dir="rtl"] .text-end {
  text-align: left;
}

[dir="ltr"] .text-end {
  text-align: right;
}

/* Icon spacing - ml-2 and mr-2 adapt to direction */
[dir="rtl"] .ml-2 {
  margin-left: 0;
  margin-right: 0.5rem;
}

[dir="ltr"] .ml-2 {
  margin-left: 0.5rem;
  margin-right: 0;
}

[dir="rtl"] .mr-2 {
  margin-right: 0;
  margin-left: 0.5rem;
}

[dir="ltr"] .mr-2 {
  margin-right: 0.5rem;
  margin-left: 0;
}

/* Arrow direction */
[dir="rtl"] .fa-arrow-left {
  transform: scaleX(1);
}

[dir="ltr"] .fa-arrow-left {
  transform: scaleX(-1);
}

[dir="rtl"] .fa-arrow-right {
  transform: scaleX(-1);
}

[dir="ltr"] .fa-arrow-right {
  transform: scaleX(1);
}

/* Dropdown menu fix - keeps menu open when moving mouse from button to menu */
.group {
  position: relative;
}

.group > div[class*="absolute"] {
  top: 100%;
  padding-top: 0.5rem;
  margin-top: -0.5rem;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.animate-fade-in {
  animation: fadeIn 0.5s ease-out;
}

.animate-slide-in {
  animation: slideIn 0.5s ease-out;
}

/* Smooth transitions for all interactive elements */
a, button, input, select, textarea {
  transition: all 0.2s ease-in-out;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  background: #3b82f6;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: #2563eb;
}

/* Focus styles */
input:focus,
select:focus,
textarea:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Loading spinner */
.spinner {
  border: 3px solid #f3f3f3;
  border-top: 3px solid #3b82f6;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Card hover effects */
.card-hover {
  transition: all 0.3s ease;
}

.card-hover:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Table row hover */
.table-row-hover {
  transition: background-color 0.15s ease;
}

.table-row-hover:hover {
  background-color: #eff6ff;
}

/* Button pulse effect */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Sidebar Styles */
#sidebar {
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 #f1f5f9;
}

#sidebar::-webkit-scrollbar {
  width: 6px;
}

#sidebar::-webkit-scrollbar-track {
  background: #f1f5f9;
}

#sidebar::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

#sidebar::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Sidebar active state */
#sidebar nav a.active {
  background-color: #eff6ff;
  color: #2563eb;
  font-weight: 600;
}

/* Dark Mode Styles */
.dark #sidebar nav a.active {
  background-color: #1e3a8a;
  color: #60a5fa;
}

/* Dark mode scrollbar */
.dark ::-webkit-scrollbar-track {
  background: #1f2937;
}

.dark ::-webkit-scrollbar-thumb {
  background: #4b5563;
}

.dark ::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

/* Dark mode sidebar scrollbar */
.dark #sidebar::-webkit-scrollbar-track {
  background: #1f2937;
}

.dark #sidebar::-webkit-scrollbar-thumb {
  background: #4b5563;
}

.dark #sidebar::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

/* Dark mode transitions - smooth color changes */
html {
  transition: background-color 0.2s ease, color 0.2s ease;
}

body {
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Prevent flash of unstyled content */
html {
  color-scheme: light;
  background-color: #f9fafb;
}

html.dark {
  color-scheme: dark;
  background-color: #111827;
}

/* Prevent flash for body */
body {
  background-color: #f9fafb;
  transition: background-color 0.2s ease;
}

html.dark body {
  background-color: #111827;
}

/* Prevent flash for main content areas */
main {
  background-color: #f9fafb;
  transition: background-color 0.2s ease;
}

html.dark main {
  background-color: #111827;
}

/* Global dark mode support - will be overridden by explicit dark: classes */
.dark [class*="bg-white"]:not([class*="dark:bg"]) {
  background-color: #1f2937;
}

.dark [class*="text-gray-900"]:not([class*="dark:text"]) {
  color: #f3f4f6;
}

.dark [class*="text-gray-700"]:not([class*="dark:text"]) {
  color: #d1d5db;
}

.dark [class*="text-gray-600"]:not([class*="dark:text"]) {
  color: #9ca3af;
}

.dark [class*="border-gray-200"]:not([class*="dark:border"]) {
  border-color: #4b5563;
}

.dark [class*="bg-gray-50"]:not([class*="dark:bg"]) {
  background-color: #374151;
}

.dark [class*="bg-gray-100"]:not([class*="dark:bg"]) {
  background-color: #4b5563;
}
