/* ==========================================================================
   ELIAS - Global Styles & CSS Variables
   AI-Powered Distribution & Customer Intelligence Platform
   ========================================================================== */

/* ---------- Google Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Noto+Sans+Arabic:wght@400;500;600;700&family=Noto+Sans+Devanagari:wght@400;500;600;700&display=swap');

/* ---------- CSS Custom Properties (Light Mode - Default) ---------- */
:root {
  /* Brand Colors */
  --primary: #094B7C;
  --primary-hover: #073D66;
  --primary-light: #E8F4FD;
  --secondary: #3B82F6;
  --accent: #F97316;
  --success: #22C55E;
  --warning: #F59E0B;
  --danger: #EF4444;
  --info: #3B82F6;

  /* Background */
  --bg-primary: #F8FAFC;
  --bg-white: #FFFFFF;

  /* Text */
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;

  /* Borders */
  --border: #E2E8F0;
  --border-hover: #CBD5E1;

  /* Spacing (8dp system) */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-base: 16px;
  --space-lg: 20px;
  --space-xl: 24px;
  --space-2xl: 32px;
  --space-3xl: 48px;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

  /* Sidebar */
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 72px;
  --topbar-height: 64px;
  --mobile-nav-height: 64px;

  /* Transitions */
  --transition-fast: 150ms ease-out;
  --transition-base: 200ms ease-out;
  --transition-slow: 300ms ease-out;
}

/* ---------- Dark Mode ---------- */
.dark {
  --primary: #2D8AC7;
  --primary-hover: #3A9BD8;
  --primary-light: #0C2D4A;
  --bg-primary: #0F172A;
  --bg-white: #1E293B;
  --text-primary: #F1F5F9;
  --text-secondary: #CBD5E1;
  --text-muted: #64748B;
  --border: #334155;
  --border-hover: #475569;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

/* ---------- Base Styles ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', 'Noto Sans Arabic', 'Noto Sans Devanagari', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Typography ---------- */
h1 { font-size: 30px; font-weight: 700; line-height: 1.2; }
h2 { font-size: 24px; font-weight: 600; line-height: 1.3; }
h3 { font-size: 20px; font-weight: 600; line-height: 1.3; }
h4 { font-size: 16px; font-weight: 600; line-height: 1.4; }

/* ---------- Focus States (Accessibility) ---------- */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Focus ring for buttons and interactive elements */
.btn:focus-visible,
.form-input:focus-visible,
select:focus-visible,
[role="menuitem"]:focus-visible,
[role="tab"]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(9, 75, 124, 0.15);
}

.dark .btn:focus-visible,
.dark .form-input:focus-visible,
.dark select:focus-visible {
  box-shadow: 0 0 0 4px rgba(45, 138, 199, 0.2);
}

/* ---------- Screen Reader Only ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Skip to Content Link ---------- */
.skip-to-content {
  position: absolute;
  top: -100%;
  left: 0;
  z-index: 9999;
  padding: 8px 16px;
  background: var(--primary);
  color: #fff;
  font-weight: 500;
  text-decoration: none;
  border-radius: 0 0 var(--radius-md) 0;
  transition: top var(--transition-fast);
}

.skip-to-content:focus {
  top: 0;
}

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

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

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

.dark ::-webkit-scrollbar-thumb {
  background: var(--border);
}

/* ---------- Layout ---------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding-top: var(--topbar-height);
  min-height: 100vh;
  transition: margin-left var(--transition-base);
}

.sidebar-collapsed .main-content {
  margin-left: var(--sidebar-collapsed-width);
}

.page-container {
  padding: var(--space-xl);
  max-width: 1536px;
  margin: 0 auto;
}

/* ---------- Utility: Animations ---------- */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes slide-in-right {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes bounce-pin {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.animate-fade-in {
  animation: fade-in 200ms ease-out forwards;
}

.animate-slide-up {
  animation: slide-up 200ms ease-out forwards;
}

.animate-pulse-badge {
  animation: pulse-badge 2s ease-in-out infinite;
}

/* ---------- Performance: Layout Containment ---------- */
.page-container {
  contain: layout style;
}

.data-table-wrapper {
  contain: layout;
}

.sidebar {
  will-change: transform;
}

.modal-overlay,
[id$="-modal-overlay"] {
  will-change: opacity;
}

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Responsive: Mobile ---------- */
@media (max-width: 767px) {
  .main-content {
    margin-left: 0;
    padding-bottom: var(--mobile-nav-height);
  }

  .page-container {
    padding: var(--space-base);
  }
}

/* ---------- Responsive: Tablet ---------- */
@media (min-width: 768px) and (max-width: 1023px) {
  .main-content {
    margin-left: var(--sidebar-collapsed-width);
  }
}

/* ---------- Third-Party Dark Mode Overrides ---------- */

/* Tom Select Dark Mode */
.dark .ts-wrapper .ts-control {
  background: var(--bg-white);
  color: var(--text-primary);
  border-color: var(--border);
}

.dark .ts-wrapper .ts-dropdown {
  background: var(--bg-white);
  border-color: var(--border);
  color: var(--text-primary);
}

.dark .ts-wrapper .ts-dropdown .option:hover,
.dark .ts-wrapper .ts-dropdown .active {
  background: var(--primary-light);
}

/* DataTables Dark Mode */
.dark .dataTables_wrapper {
  color: var(--text-primary);
}

.dark table.dataTable {
  border-color: var(--border) !important;
}

.dark table.dataTable thead th,
.dark table.dataTable thead td {
  background: var(--bg-white) !important;
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
}

.dark table.dataTable tbody tr {
  background: var(--bg-white) !important;
  color: var(--text-primary) !important;
}

.dark table.dataTable tbody tr:hover {
  background: var(--primary-light) !important;
}

.dark .dataTables_info,
.dark .dataTables_length,
.dark .dataTables_filter {
  color: var(--text-secondary) !important;
}

.dark .dataTables_paginate .paginate_button {
  color: var(--text-secondary) !important;
}

.dark .dataTables_paginate .paginate_button.current {
  background: var(--primary) !important;
  color: #fff !important;
  border-color: var(--primary) !important;
}

/* SweetAlert2 Dark Mode */
.dark .swal2-popup {
  background: var(--bg-white);
  color: var(--text-primary);
}

.dark .swal2-title {
  color: var(--text-primary);
}

.dark .swal2-html-container {
  color: var(--text-secondary);
}

/* Air Datepicker Dark Mode */
.dark .air-datepicker {
  background: var(--bg-white);
  border-color: var(--border);
  color: var(--text-primary);
}

.dark .air-datepicker-cell.-selected- {
  background: var(--primary);
}

.dark .air-datepicker-cell.-current- {
  color: var(--primary);
}

.dark .air-datepicker-nav--title,
.dark .air-datepicker-nav--action svg {
  color: var(--text-primary);
}

.dark .air-datepicker-cell {
  color: var(--text-secondary);
}

.dark .air-datepicker-cell.-disabled- {
  color: var(--text-muted);
}

/* Leaflet Dark Mode */
.dark .leaflet-control-zoom a {
  background: var(--bg-white);
  color: var(--text-primary);
  border-color: var(--border);
}

.dark .leaflet-control-zoom a:hover {
  background: var(--primary-light);
}

.dark .leaflet-control-attribution {
  background: rgba(15, 23, 42, 0.8);
  color: var(--text-muted);
}

.dark .leaflet-control-attribution a {
  color: var(--text-secondary);
}

.dark .leaflet-popup-content-wrapper {
  background: var(--bg-white);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
}

.dark .leaflet-popup-tip {
  background: var(--bg-white);
}

/* DataTables Dark Mode - Pagination & Inputs */
.dark .dataTables_paginate .paginate_button:hover {
  background: var(--primary-light) !important;
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
}

.dark .dataTables_paginate .paginate_button.disabled {
  color: var(--text-muted) !important;
}

.dark .dataTables_filter input,
.dark .dataTables_length select {
  background: var(--bg-white) !important;
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
}

.dark .dataTables_filter input:focus,
.dark .dataTables_length select:focus {
  border-color: var(--primary) !important;
}

.dark .dataTables_empty {
  color: var(--text-muted) !important;
}

/* Tom Select Dark Mode - Additional */
.dark .ts-wrapper .ts-control input {
  color: var(--text-primary);
}

.dark .ts-wrapper .ts-control .item {
  background: var(--primary-light);
  color: var(--text-primary);
  border-color: var(--border);
}

.dark .ts-wrapper.focus .ts-control {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45, 138, 199, 0.15);
}

/* ---------- Dark mode form input overrides ---------- */
.dark input[type="date"],
.dark input[type="time"],
.dark input[type="datetime-local"],
.dark input[type="number"],
.dark select {
  color-scheme: dark;
}

/* ---------- Dark mode scrollbar ---------- */
.dark ::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

.dark ::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}
