/* CSS Reset & Base Styles */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

body {
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

/* CSS Variables */
:root {
  /* ========================================
     COLORS
     ======================================== */

  /* Base Colors */
  --color-white: #ffffff;
  --color-black: #000000;

  /* Gray Scale */
  --color-gray-50: #fafafa;
  --color-gray-100: #f5f5f5;
  --color-gray-200: #e5e5e5;
  --color-gray-300: #d4d4d4;
  --color-gray-400: #a3a3a3;
  --color-gray-500: #737373;
  --color-gray-600: #525252;
  --color-gray-700: #404040;
  --color-gray-800: #262626;
  --color-gray-900: #171717;

  /* Blue Scale */
  --color-blue-50: #eff6ff;
  --color-blue-100: #dbeafe;
  --color-blue-500: #3b82f6;
  --color-blue-600: #2563eb;
  --color-blue-700: #1d4ed8;

  /* Red Scale */
  --color-red-50: #fef2f2;
  --color-red-100: #fee2e2;
  --color-red-300: #fca5a5;
  --color-red-600: #dc2626;
  --color-red-700: #b91c1c;
  --color-red-800: #991b1b;

  /* Green Scale */
  --color-green-50: #f0fdf4;
  --color-green-100: #dcfce7;
  --color-green-600: #16a34a;
  --color-green-700: #15803d;
  --color-green-800: #166534;
  --color-green-900: #14532d;

  /* Yellow Scale */
  --color-yellow-50: #fefce8;
  --color-yellow-100: #fef3c7;
  --color-yellow-600: #ca8a04;
  --color-yellow-700: #a16207;
  --color-yellow-800: #854d0e;
  --color-yellow-900: #78350f;

  /* Semantic Text Colors (WCAG AA compliant) */
  --text-primary: #1a1a1a; /* 16.2:1 on white */
  --text-secondary: #525252; /* 8.6:1 on white */
  --text-tertiary: #737373; /* 5.7:1 on white */
  --text-disabled: #a3a3a3; /* 3.2:1 (large text only) */
  --text-inverse: #ffffff;

  /* Semantic Background Colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-tertiary: #e5e5e5;
  --bg-overlay: rgba(0, 0, 0, 0.5);

  /* Semantic Border Colors */
  --border-default: #e5e5e5;
  --border-hover: #d4d4d4;
  --border-focus: #2563eb;
  --border-error: #dc2626;

  /* Semantic Status Colors (Badge/Alert backgrounds and text) */
  --status-success-bg: #dcfce7;
  --status-success-text: #14532d; /* 8.2:1 on bg */

  --status-warning-bg: #fef3c7;
  --status-warning-text: #78350f; /* 7.1:1 on bg */

  --status-error-bg: #fee2e2;
  --status-error-text: #7f1d1d; /* 8.9:1 on bg */

  --status-info-bg: #dbeafe;
  --status-info-text: #1e3a8a; /* 9.1:1 on bg */

  /* Link Colors */
  --link-default: #2563eb; /* 5.8:1 on white */
  --link-hover: #1d4ed8; /* 7.7:1 on white */
  --link-visited: #7c3aed; /* 5.2:1 on white */

  /* ========================================
     TYPOGRAPHY
     ======================================== */

  /* Font Families */
  --font-sans:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono:
    'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;

  /* Font Sizes */
  --font-size-xs: 0.75rem; /* 12px */
  --font-size-sm: 0.875rem; /* 14px */
  --font-size-base: 1rem; /* 16px */
  --font-size-lg: 1.125rem; /* 18px */
  --font-size-xl: 1.25rem; /* 20px */
  --font-size-2xl: 1.5rem; /* 24px */
  --font-size-3xl: 1.875rem; /* 30px */
  --font-size-4xl: 2.25rem; /* 36px */
  --font-size-5xl: 3rem; /* 48px */

  /* Font Weights */
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Line Heights */
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.75;

  /* ========================================
     SPACING SCALE
     ======================================== */

  --space-0: 0;
  --space-1: 0.25rem; /* 4px */
  --space-2: 0.5rem; /* 8px */
  --space-3: 0.75rem; /* 12px */
  --space-4: 1rem; /* 16px */
  --space-5: 1.25rem; /* 20px */
  --space-6: 1.5rem; /* 24px */
  --space-8: 2rem; /* 32px */
  --space-10: 2.5rem; /* 40px */
  --space-12: 3rem; /* 48px */
  --space-16: 4rem; /* 64px */
  --space-20: 5rem; /* 80px */
  --space-24: 6rem; /* 96px */
  --space-32: 8rem; /* 128px */

  /* ========================================
     BORDER TOKENS
     ======================================== */

  /* Border Widths */
  --border-none: 0;
  --border-thin: 1px;
  --border-medium: 2px;
  --border-thick: 4px;

  /* Border Radius */
  --radius-none: 0;
  --radius-sm: 0.25rem; /* 4px */
  --radius-md: 0.375rem; /* 6px */
  --radius-lg: 0.5rem; /* 8px */
  --radius-xl: 0.75rem; /* 12px */
  --radius-2xl: 1rem; /* 16px */
  --radius-full: 9999px;

  /* ========================================
     SHADOW SCALE
     ======================================== */

  --shadow-none: none;
  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  --shadow-inner: inset 0 2px 4px 0 rgba(0, 0, 0, 0.05);

  /* ========================================
     Z-INDEX SCALE (Groups of 100)
     ======================================== */

  --z-base: 0;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-fixed: 300;
  --z-modal-backdrop: 400;
  --z-modal: 500;
  --z-popover: 600;
  --z-toast: 700;
  --z-tooltip: 800;
  --z-notification: 900;

  /* ========================================
     TRANSITION SYSTEM (Composable)
     ======================================== */

  /* Timing Functions (Easing) */
  --ease-linear: linear;
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
  --ease-sharp: cubic-bezier(0.4, 0, 0.6, 1);

  /* Durations */
  --duration-instant: 0ms;
  --duration-fast: 150ms;
  --duration-base: 250ms;
  --duration-slow: 350ms;
  --duration-slower: 500ms;

  /* Composable Transitions */
  --transition-fast: var(--duration-fast) var(--ease-out);
  --transition-base: var(--duration-base) var(--ease-in-out);
  --transition-slow: var(--duration-slow) var(--ease-in-out);
  --transition-bounce: var(--duration-base) var(--ease-bounce);

  /* Common Transition Properties */
  --transition-colors:
    color var(--transition-fast), background-color var(--transition-fast),
    border-color var(--transition-fast);
  --transition-opacity: opacity var(--transition-base);
  --transition-transform: transform var(--transition-base);
  --transition-all: all var(--transition-base);

  /* ========================================
     LAYOUT
     ======================================== */

  --container-max-width: 1280px;
  --header-height: 64px;
  --sidebar-width: 280px;
}

/* Base Typography */
body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  color: var(--color-gray-900);
  background: var(--color-white);
}

h1 {
  font-size: var(--font-size-3xl);
  font-weight: 600;
  line-height: 1.2;
}

h2 {
  font-size: var(--font-size-2xl);
  font-weight: 600;
  line-height: 1.3;
}

h3 {
  font-size: var(--font-size-xl);
  font-weight: 600;
  line-height: 1.4;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

/* ========================================
   ANIMATION KEYFRAMES
   ======================================== */

/* Fade animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

/* Scale animations (for modals) */
@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes scaleOut {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.95);
  }
}

/* Slide animations (for toasts, drawers) */
@keyframes slideInRight {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

@keyframes slideOutRight {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(100%);
  }
}

@keyframes slideInUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes slideOutDown {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(100%);
  }
}

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

/* Spin animation (for loading spinners) */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Bounce animation */
@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

/* Pulse animation (for loading states) */
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Shake animation (for errors) */
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  10%,
  30%,
  50%,
  70%,
  90% {
    transform: translateX(-5px);
  }
  20%,
  40%,
  60%,
  80% {
    transform: translateX(5px);
  }
}

/* ========================================
   REDUCED MOTION SUPPORT
   ======================================== */

/**
 * Disable animations for users who prefer reduced motion
 * Respects prefers-reduced-motion: reduce system preference
 */
@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;
  }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Focus visible utility (keyboard navigation) */
.focus-visible:focus {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

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

/* ========================================
   ACCESSIBILITY ENHANCEMENTS
   ======================================== */

/* Skip navigation link - hidden until focused */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-black);
  color: var(--color-white);
  padding: var(--space-2) var(--space-4);
  text-decoration: none;
  z-index: 100;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  border-radius: 0 0 var(--radius-md) 0;
}

.skip-link:focus {
  top: 0;
  outline: 2px solid var(--color-blue-500);
  outline-offset: 2px;
}

/* Footer placeholder links - styled as disabled text */
.footer-link-placeholder {
  color: var(--color-gray-500);
  cursor: not-allowed;
  font-size: var(--font-size-sm);
}

/* Main content focus - remove outline when programmatically focused */
#main-content:focus {
  outline: none;
}

/* ========================================
   ADMIN LAYOUT - RESPONSIVE
   ======================================== */

/* Admin layout grid */
.admin-layout {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 64px 1fr;
  height: 100vh;
  background: #f5f5f5;
}

@media (min-width: 768px) {
  .admin-layout {
    grid-template-columns: 250px 1fr;
  }
}

/* Admin main content */
.admin-main {
  grid-column: 1;
  grid-row: 2;
  padding: 16px;
  overflow: auto;
}

@media (min-width: 768px) {
  .admin-main {
    grid-column: 2;
    padding: 24px;
  }
}

/* Admin sidebar */
.admin-sidebar {
  grid-column: 1;
  grid-row: 2;
  background: #2c3e50;
  color: white;
  padding: 16px 0;
  overflow-y: auto;
  display: none;
}

@media (min-width: 768px) {
  .admin-sidebar {
    display: block;
    padding: 24px 0;
  }
}

/* Mobile admin sidebar (hidden by default) */
@media (max-width: 767px) {
  .admin-sidebar.mobile-open {
    display: block;
    position: fixed;
    top: 64px;
    left: 0;
    width: 250px;
    height: calc(100vh - 64px);
    z-index: 100;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.2);
  }
}
