/**
 * Base CSS - Reset, Typography, Design Tokens
 * Modern design system with tonal color palette + Inter font
 */

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

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

/* ============================================
   DESIGN TOKENS
   ============================================ */
:root {
  /* ---- Brand (tonal) ---- */
  --brand-50:  #f0f4ff;
  --brand-100: #e0eaff;
  --brand-200: #c7d9fe;
  --brand-300: #a5bbfa;
  --brand-400: #7e94f4;
  --brand-500: #5b6ef5;   /* primary */
  --brand-600: #4a5ce8;   /* hover */
  --brand-700: #3a4bd4;   /* active */
  --brand-800: #2f3bb0;
  --brand-900: #1e2a8a;

  /* ---- Accent ---- */
  --accent-500: #8b5cf6;
  --accent-600: #7c3aed;

  /* ---- Semantic ---- */
  --success: #16a34a;
  --success-50: #ecfdf5;
  --success-100: #d1fae5;
  --warning: #d97706;
  --warning-50: #fffbeb;
  --warning-100: #fef3c7;
  --danger: #dc2626;
  --danger-50: #fef2f2;
  --danger-100: #fee2e2;
  --info: #0284c7;
  --info-50: #f0f9ff;
  --info-100: #dbeafe;

  /* ---- Neutral ---- */
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* ---- Surfaces ---- */
  --surface-page:    #f4f6fb;
  --surface-card:    #ffffff;
  --surface-elev:    #ffffff;
  --surface-sidebar: #1a1d2e;
  --surface-sidebar-hover: #232742;

  /* ---- Backward-compat aliases ---- */
  --primary-color: var(--brand-500);
  --primary-dark:  var(--brand-600);
  --primary-light: var(--brand-400);
  --secondary-color: var(--accent-500);

  --success-color: var(--success);
  --success-light: var(--success-100);
  --warning-color: var(--warning);
  --warning-light: var(--warning-100);
  --danger-color:  var(--danger);
  --danger-light:  var(--danger-100);
  --info-color:    var(--info);
  --info-light:    var(--info-100);

  --text-primary:   var(--gray-900);
  --text-secondary: var(--gray-600);
  --text-muted:     var(--gray-400);
  --text-light:     #ffffff;

  --bg-primary: var(--surface-page);
  --bg-white:   var(--surface-card);
  --bg-light:   var(--gray-50);
  --bg-hover:   var(--gray-100);
  --bg-dark:    var(--gray-800);

  --border-color: var(--gray-200);
  --border-light: var(--gray-100);
  --border-radius: 8px;

  /* ---- Spacing ---- */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;

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

  /* ---- Shadows ---- */
  --shadow-xs: 0 1px 2px rgba(17, 24, 39, 0.06);
  --shadow-sm: 0 1px 3px rgba(17, 24, 39, 0.08), 0 1px 2px rgba(17, 24, 39, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(17, 24, 39, 0.08), 0 2px 4px -2px rgba(17, 24, 39, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(17, 24, 39, 0.10), 0 4px 6px -4px rgba(17, 24, 39, 0.06);
  --shadow-xl: 0 20px 25px -5px rgba(17, 24, 39, 0.10), 0 8px 10px -6px rgba(17, 24, 39, 0.05);
  --shadow-brand: 0 8px 24px -8px rgba(91, 110, 245, 0.45);

  /* ---- Transitions ---- */
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* ---- Z-index ---- */
  --z-sticky: 50;
  --z-sidebar: 200;
  --z-overlay: 250;
  --z-dropdown: 300;
  --z-modal: 1000;
  --z-toast: 1100;
  --z-tooltip: 1200;

  /* ---- Layout ---- */
  --sidebar-width: 240px;
  --sidebar-width-collapsed: 72px;
  --topbar-height: 60px;

  /* ---- Fonts ---- */
  --font-sans: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  --font-arabic: 'Inter', 'Segoe UI', 'Tahoma', Arial, sans-serif;
}

/* ============================================
   TYPOGRAPHY
   ============================================ */
html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--text-primary);
  background-color: var(--surface-page);
  font-feature-settings: 'cv11', 'ss01';
}

html[lang="ar"] body { font-family: var(--font-arabic); }
html[dir="rtl"] body { text-align: right; }

/* Prevent FOUC */
html.lang-loading body { visibility: hidden; }
html:not(.lang-loading) body { visibility: visible; }

/* Headings */
h1, h2, h3, h4, h5, h6 {
  margin-bottom: var(--spacing-sm);
  font-weight: 600;
  line-height: 1.25;
  color: var(--gray-900);
  letter-spacing: -0.01em;
}

h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.375rem; font-weight: 700; }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }
h5 { font-size: 0.9375rem; }
h6 { font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--gray-500); }

p { margin-bottom: var(--spacing-md); }

/* Links */
a {
  color: var(--brand-600);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--brand-700); }

/* Lists */
ul, ol {
  padding-left: var(--spacing-lg);
  margin-bottom: var(--spacing-md);
}
html[dir="rtl"] ul, html[dir="rtl"] ol {
  padding-left: 0;
  padding-right: var(--spacing-lg);
}

img { max-width: 100%; height: auto; }
table { width: 100%; border-collapse: collapse; }

input, select, textarea, button {
  font-family: inherit;
  font-size: inherit;
}

/* Selection */
::selection {
  background-color: var(--brand-200);
  color: var(--brand-900);
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); background-clip: padding-box; border: 2px solid transparent; }

/* ============================================
   ACCESSIBILITY
   ============================================ */
:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}
:focus:not(:focus-visible) { outline: none; }

@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;
  }
}

.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;
}
