/**
 * DocuFinch EHS Design System
 * Professional color palette, typography, and spacing tokens
 * NOTE: Primary colors should match tailwind/application.css (Teal #0D9488)
 */

/* ===== GLOBAL SCALE - Reduces entire UI to ~80% ===== */
html {
  font-size: 13px; /* Base 13px instead of 16px = ~81% scale */
}

@media (min-width: 640px) {
  html {
    font-size: 14px; /* Slightly larger on tablet+ */
  }
}

/* ===== COLOR PALETTE ===== */
:root {
  /* Primary - Teal (Professional, Trust, Safety) - Aligned with Tailwind config */
  --color-primary-50: #f0fdfa;
  --color-primary-100: #ccfbf1;
  --color-primary-200: #99f6e4;
  --color-primary-300: #5eead4;
  --color-primary-400: #2dd4bf;
  --color-primary-500: #14b8a6;
  --color-primary-600: #0d9488;
  --color-primary-700: #0f766e;
  --color-primary-800: #115e59;
  --color-primary-900: #134e4a;
  --color-primary-950: #042f2e;

  /* Success - Green */
  --color-success-50: #f0fdf4;
  --color-success-100: #dcfce7;
  --color-success-500: #22c55e;
  --color-success-600: #16a34a;
  --color-success-700: #15803d;

  /* Warning - Amber */
  --color-warning-50: #fffbeb;
  --color-warning-100: #fef3c7;
  --color-warning-500: #f59e0b;
  --color-warning-600: #d97706;
  --color-warning-700: #b45309;

  /* Danger - Red */
  --color-danger-50: #fef2f2;
  --color-danger-100: #fee2e2;
  --color-danger-500: #ef4444;
  --color-danger-600: #dc2626;
  --color-danger-700: #b91c1c;

  /* Neutral - Slate */
  --color-neutral-50: #f8fafc;
  --color-neutral-100: #f1f5f9;
  --color-neutral-200: #e2e8f0;
  --color-neutral-300: #cbd5e1;
  --color-neutral-400: #94a3b8;
  --color-neutral-500: #64748b;
  --color-neutral-600: #475569;
  --color-neutral-700: #334155;
  --color-neutral-800: #1e293b;
  --color-neutral-900: #0f172a;
  --color-neutral-950: #020617;

  /* Semantic Colors */
  --color-background: #ffffff;
  --color-surface: #f8fafc;
  --color-border: #e2e8f0;
  --color-text-primary: #0f172a;
  --color-text-secondary: #475569;
  --color-text-muted: #94a3b8;

  /* ===== TYPOGRAPHY ===== */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

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

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

  /* Line Heights */
  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;
  --leading-loose: 2;

  /* ===== SPACING ===== */
  --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 */

  /* ===== BORDERS ===== */
  --border-width: 1px;
  --border-width-2: 2px;
  --border-radius-sm: 0.375rem;  /* 6px */
  --border-radius: 0.5rem;       /* 8px */
  --border-radius-lg: 0.75rem;   /* 12px */
  --border-radius-xl: 1rem;      /* 16px */
  --border-radius-full: 9999px;

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

  /* ===== LAYOUT - DEFINED IN tailwind/application.css (loads last, wins) ===== */
  /* --sidebar-width, --sidebar-collapsed, --topbar-height, --content-max-width */
  /* DO NOT duplicate here - see tailwind/application.css for single source of truth */

  /* ===== TRANSITIONS ===== */
  --transition-fast: 150ms ease-in-out;
  --transition-base: 200ms ease-in-out;
  --transition-slow: 300ms ease-in-out;

  /* ===== Z-INDEX ===== */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
}

/* ===== DARK MODE ===== */
/* Use .dark class for consistency with Tailwind/Hotwire pattern */
.dark,
[data-theme="dark"] {
  --color-background: #0f172a;
  --color-surface: #1e293b;
  --color-border: #334155;
  --color-text-primary: #f8fafc;
  --color-text-secondary: #cbd5e1;
  --color-text-muted: #64748b;
}

/* ===== BASE STYLES ===== */
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text-primary);
  background-color: var(--color-surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== UTILITY CLASSES ===== */
.card {
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--border-radius-lg);
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.dark .card {
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.card:hover {
  box-shadow: 
    0 16px 48px rgba(0, 0, 0, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transform: translateY(-2px);
}

.dark .card:hover {
  box-shadow: 
    0 16px 48px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
}

.card-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.dark .card-header {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.card-body {
  padding: var(--space-6);
}

.btn-primary {
  background-color: var(--color-primary-500);
  color: white;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--border-radius);
  font-weight: var(--font-medium);
  transition: background-color var(--transition-fast);
}

.btn-primary:hover {
  background-color: var(--color-primary-600);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--border-radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
}

.badge-success {
  background-color: var(--color-success-100);
  color: var(--color-success-700);
}

.badge-warning {
  background-color: var(--color-warning-100);
  color: var(--color-warning-700);
}

.badge-danger {
  background-color: var(--color-danger-100);
  color: var(--color-danger-700);
}

/* ===== LAYOUT COMPONENTS ===== */
.app-layout {
  min-height: 100vh;
  width: 100%;
}

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  max-width: var(--sidebar-width);
  /* background handled by sidebar-glass class */
  border-right: var(--border-width) solid var(--color-border);
  transition: width var(--transition-base);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: var(--z-fixed);
  flex-shrink: 0;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  width: auto;
  transition: margin-left var(--transition-base);
  overflow-x: hidden;
}

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

.topbar {
  height: var(--topbar-height);
  background: var(--color-background);
  border-bottom: var(--border-width) solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-3);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

/* ===== EXTRACTED UTILITY CLASSES ===== */
/* These replace overly long Tailwind class strings (300+ chars) */

/* Toggle Switch - replaces 400+ char inline class string */
.toggle-switch {
  width: 2.75rem;
  height: 1.5rem;
  background-color: #e5e7eb;
  border-radius: 9999px;
  position: relative;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.25rem;
  height: 1.25rem;
  background-color: white;
  border: 1px solid #d1d5db;
  border-radius: 9999px;
  transition: transform 0.2s ease;
}

.toggle-switch.active {
  background-color: #2563eb;
}

.toggle-switch.active::after {
  transform: translateX(100%);
  border-color: white;
}

.dark .toggle-switch {
  background-color: #374151;
}

.dark .toggle-switch.active {
  background-color: #2563eb;
}

/* Primary Button - standardized */
.btn-primary {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 1rem;
  background-color: var(--color-primary-600);
  color: white;
  border-radius: 0.5rem;
  font-weight: 500;
  transition: all 0.15s ease;
}

.btn-primary:hover {
  background-color: var(--color-primary-700);
}

.btn-primary:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.3);
}

/* Secondary Button */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  border-radius: 0.5rem;
  font-weight: 500;
  transition: all 0.15s ease;
  background-color: white;
}

.btn-secondary:hover {
  background-color: var(--color-neutral-50);
}

.dark .btn-secondary {
  background-color: var(--color-neutral-800);
  border-color: var(--color-neutral-600);
  color: var(--color-neutral-300);
}

.dark .btn-secondary:hover {
  background-color: var(--color-neutral-700);
}

/* Stat Card - for KPI/metrics displays */
.stat-card {
  background-color: white;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border-radius: 0.5rem;
  padding: 1.25rem;
}

.stat-card-glass {
  background: var(--glass-bg-heavy);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-glass);
}

.dark .stat-card {
  background-color: var(--color-neutral-800);
}

/* Page Header - standardized */
.page-header {
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  color: var(--color-text-primary);
}

.dark .page-title {
  color: white;
}

.page-description {
  margin-top: 0.25rem;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .topbar {
    padding: 0 var(--space-4);
  }

  .content-container {
    padding: var(--space-4);
  }
}
