/* =====================================================
   A1 SCHEDULE - MODERN DESIGN SYSTEM
   Created: 2025
   ===================================================== */

/* =====================================================
   DESIGN TOKENS & CSS VARIABLES
   ===================================================== */

:root {
  /* === PRIMARY COLORS === */
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;
  --primary-200: #bfdbfe;
  --primary-300: #93c5fd;
  --primary-400: #60a5fa;
  --primary-500: #3b82f6;  /* Main primary */
  --primary-600: #2563eb;
  --primary-700: #1d4ed8;
  --primary-800: #1e40af;
  --primary-900: #1e3a8a;
  
  /* === NEUTRAL COLORS === */
  --neutral-0: #ffffff;
  --neutral-50: #f8fafc;
  --neutral-100: #f1f5f9;
  --neutral-200: #e2e8f0;
  --neutral-300: #cbd5e1;
  --neutral-400: #94a3b8;
  --neutral-500: #64748b;
  --neutral-600: #475569;
  --neutral-700: #334155;
  --neutral-800: #1e293b;
  --neutral-900: #0f172a;
  
  /* === SEMANTIC COLORS === */
  --success-50: #f0fdf4;
  --success-500: #22c55e;
  --success-600: #16a34a;
  --success-700: #15803d;
  
  --warning-50: #fffbeb;
  --warning-500: #f59e0b;
  --warning-600: #d97706;
  --warning-700: #b45309;
  
  --error-50: #fef2f2;
  --error-500: #ef4444;
  --error-600: #dc2626;
  --error-700: #b91c1c;
  
  --info-50: #f0f9ff;
  --info-500: #06b6d4;
  --info-600: #0891b2;
  --info-700: #0e7490;
  
  /* === SURFACE COLORS === */
  --surface-primary: var(--neutral-0);
  --surface-secondary: var(--neutral-50);
  --surface-tertiary: var(--neutral-100);
  --surface-elevated: var(--neutral-0);
  --surface-overlay: rgba(15, 23, 42, 0.8);
  
  /* === TEXT COLORS === */
  --text-primary: var(--neutral-900);
  --text-secondary: var(--neutral-600);
  --text-tertiary: var(--neutral-500);
  --text-disabled: var(--neutral-400);
  --text-inverse: var(--neutral-0);
  --text-link: var(--primary-600);
  --text-link-hover: var(--primary-700);
  --text-on-color: var(--neutral-0);
  
  /* === BORDER COLORS === */
  --border-primary: var(--neutral-200);
  --border-secondary: var(--neutral-300);
  --border-interactive: var(--primary-300);
  --border-focus: var(--primary-500);
  --border-error: var(--error-500);
  --border-success: var(--success-500);
  
  /* === SPACING SCALE === */ 
  /* Reduced by 33% for more compact forms */
  --space-1: 0.17rem;   /* ~2.67px (was 4px) */
  --space-2: 0.33rem;   /* ~5.33px (was 8px) */
  --space-3: 0.5rem;    /* 8px (was 12px) */
  --space-4: 0.67rem;   /* ~10.67px (was 16px) */
  --space-5: 0.83rem;   /* ~13.33px (was 20px) */
  --space-6: 1rem;      /* 16px (was 24px) */
  --space-8: 1.33rem;   /* ~21.33px (was 32px) */
  --space-10: 1.67rem;  /* ~26.67px (was 40px) */
  --space-12: 2rem;     /* 32px (was 48px) */
  --space-16: 2.67rem;  /* ~42.67px (was 64px) */
  --space-20: 3.33rem;  /* ~53.33px (was 80px) */
  --space-24: 4rem;     /* 64px (was 96px) */
  --space-32: 5.33rem;  /* ~85.33px (was 128px) */
  
  /* === TYPOGRAPHY === */
  --font-family-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-family-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', 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-light: 300;
  --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;
  
  /* === BORDER RADIUS === */
  --radius-none: 0;
  --radius-sm: 0.25rem;    /* 4px */
  --radius-base: 0.375rem; /* 6px */
  --radius-md: 0.5rem;     /* 8px */
  --radius-lg: 0.75rem;    /* 12px */
  --radius-xl: 1rem;       /* 16px */
  --radius-2xl: 1.5rem;    /* 24px */
  --radius-full: 9999px;
  
  /* === SHADOWS === */
  --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-base: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --shadow-xl: 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 === */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
  --z-toast: 1080;
  
  /* === BREAKPOINTS === */
  --breakpoint-sm: 640px;
  --breakpoint-md: 768px;
  --breakpoint-lg: 1024px;
  --breakpoint-xl: 1280px;
  --breakpoint-2xl: 1536px;
  
  /* === ANIMATION === */
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 350ms;
  --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);
  
  /* === COMPONENT SPECIFIC === */
  --sidebar-width: 300px;
  --sidebar-width-collapsed: 80px;
  --header-height: 64px;
  --navbar-height: 56px;
  
  /* === CALENDAR SPECIFIC === */
  --calendar-header-height: 60px;
  --calendar-event-border-radius: var(--radius-md);
  --calendar-today-bg: var(--primary-50);
  --calendar-event-shadow: var(--shadow-sm);
}

/* =====================================================
   DARK MODE SUPPORT
   ===================================================== */

[data-theme="dark"] {
  /* Dark mode color overrides */
  --surface-primary: var(--neutral-900);
  --surface-secondary: var(--neutral-800);
  --surface-tertiary: var(--neutral-700);
  --surface-elevated: var(--neutral-800);
  
  --text-primary: var(--neutral-100);
  --text-secondary: var(--neutral-300);
  --text-tertiary: var(--neutral-400);
  --text-disabled: var(--neutral-500);
  
  --border-primary: var(--neutral-700);
  --border-secondary: var(--neutral-600);
  
  --calendar-today-bg: rgba(59, 130, 246, 0.1);
}

/* =====================================================
   GLOBAL RESET & BASE STYLES
   ===================================================== */

*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Global spacing reduction - 33% for all padding/margin/gap */
.swal2-popup,
.swal2-container,
.modal-content,
.event-modal-container,
.event-section,
.form-group,
.field-group,
.card-section,
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea,
button,
.btn {
  --spacing-multiplier: 0.67;
}

/* Apply multiplier to common spacing */
.swal2-popup { padding: calc(20px * 0.67) !important; }
.swal2-title { padding: calc(20px * 0.67) !important; }
.event-section { padding: calc(1rem * 0.67) !important; margin-bottom: calc(1.5rem * 0.67) !important; }
.event-modal-container { gap: calc(15px * 0.67) !important; }
input, select, textarea { padding: calc(8px * 0.67) calc(12px * 0.67) !important; }
button, .btn { padding: calc(10px * 0.67) calc(20px * 0.67) !important; }
.field-group { margin-bottom: calc(15px * 0.67) !important; }
.form-group { gap: calc(10px * 0.67) !important; }

body {
  font-family: var(--font-family-sans);
  font-size: var(--text-base);
  font-weight: var(--font-normal);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background-color: var(--surface-secondary);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* Ensure content area takes available space */
.content,
.app-layout {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
}

/* Footer always at bottom */
#footer {
  flex-shrink: 0;
  margin-top: auto;
}

/* =====================================================
   SCROLLBAR STYLING
   ===================================================== */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--surface-secondary);
}

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

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

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: var(--neutral-600);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: var(--neutral-500);
}

/* =====================================================
   FOCUS STYLES
   ===================================================== */

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* Remove default focus styles */
:focus:not(:focus-visible) {
  outline: none;
}

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

.app-layout {
  /* flex display already set above */
  flex-direction: row; /* Override for sidebar layout */
  min-height: 100vh;
  background: var(--surface-secondary);
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* Prevent flex items from overflowing */
}

.page-container {
  flex: 1;
  padding: var(--space-4);
  background: var(--surface-secondary);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.content-wrapper {
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Map layout adjustments */
.layout-with-map .main-content {
  flex-direction: row;
}

.layout-with-map .page-container {
  flex: 1;
  min-width: 0;
}

.map-container {
  width: 100%;
  background: var(--surface-primary);
  border-left: none;
  resize: none;
  overflow: hidden;
}

@media (max-width: 1024px) {
  .layout-with-map .main-content {
    flex-direction: column;
  }
  
  .map-container {
    width: 100%;
    height: 300px;
    border-left: none;
    border-top: 1px solid var(--border-primary);
    resize: vertical;
  }
}

/* =====================================================
   RESPONSIVE UTILITIES
   ===================================================== */

@media (max-width: 768px) {
  .page-container {
    padding: var(--space-4);
  }
  
  .content-wrapper {
    padding: 0;
  }
}

/* Hide on mobile */
@media (max-width: 640px) {
  .hidden-mobile {
    display: none !important;
  }
}

/* Hide on desktop */
@media (min-width: 641px) {
  .hidden-desktop {
    display: none !important;
  }
}

/* =====================================================
   ANIMATION BASE
   ===================================================== */

@media (prefers-reduced-motion: no-preference) {
  * {
    transition-duration: var(--duration-fast);
    transition-timing-function: var(--ease-out);
  }
}

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

/* =====================================================
   PRINT STYLES
   ===================================================== */

@media print {
  * {
    background: transparent !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
  
  .no-print {
    display: none !important;
  }
}

/* =====================================================
   SEARCH PAGE COMPONENTS
   ===================================================== */

/* Search Container */
.search-container {
  max-width: 800px;
  margin: 0 auto;
  padding: var(--spacing-lg);
}

/* Search Form Card */
.search-form-card {
  background: var(--neutral-0);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  margin-bottom: var(--spacing-xl);
  border: 1px solid var(--neutral-200);
}

.search-form-header {
  background: var(--gradient-primary);
  color: var(--neutral-0);
  padding: var(--spacing-lg);
  text-align: center;
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  border-radius: 0;
  position: relative;
}

.search-form-header::before {
  content: '🔍';
  font-size: var(--text-xl);
  margin-right: var(--spacing-sm);
}

/* Search Fields Container */
.search-fields-container {
  padding: var(--spacing-xl);
  background: var(--neutral-50);
}

/* Search Field Groups */
.search-field-group {
  background: var(--neutral-0);
  border-radius: var(--border-radius-md);
  border: 2px solid var(--neutral-200);
  margin-bottom: var(--spacing-lg);
  overflow: hidden;
  transition: all var(--duration-normal) var(--ease-out);
  position: relative;
}

.search-field-group:hover {
  border-color: var(--primary-500);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.15);
  transform: translateY(-1px);
}

.search-field-group.focused {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Field Headers with Icons */
.field-header {
  background: linear-gradient(135deg, var(--neutral-100) 0%, var(--neutral-200) 100%);
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--neutral-600);
  border-bottom: 1px solid var(--neutral-300);
  display: flex;
  align-items: center;
}

.field-header.parts { 
  background: linear-gradient(135deg, var(--primary-50) 0%, var(--primary-100) 100%); 
  color: var(--primary-700); 
}

.field-header.customer { 
  background: linear-gradient(135deg, var(--success-50) 0%, var(--success-100) 100%); 
  color: var(--success-700); 
}

.field-header.contact { 
  background: linear-gradient(135deg, var(--warning-50) 0%, var(--warning-100) 100%); 
  color: var(--warning-700); 
}

.field-header.job { 
  background: linear-gradient(135deg, #fce4ec 0%, #f8bbd9 100%); 
  color: #c2185b; 
}

.field-header.photo { 
  background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%); 
  color: #7b1fa2; 
}

.field-header::before {
  margin-right: var(--spacing-sm);
  font-size: var(--text-base);
}

.field-header.parts::before { content: '🔧'; }
.field-header.customer::before { content: '👤'; }
.field-header.contact::before { content: '📞'; }
.field-header.job::before { content: '📋'; }
.field-header.photo::before { content: '📷'; }

/* Form Controls */
.search-field-group .form-control {
  border: none;
  border-radius: 0;
  padding: var(--spacing-md);
  font-size: var(--text-sm);
  background: var(--neutral-0);
  box-shadow: none;
  transition: background-color var(--duration-fast) var(--ease-out);
}

.search-field-group .form-control:focus {
  background: #f8f9ff;
  box-shadow: none;
  border: none;
  outline: none;
}

.search-field-group .form-control::placeholder {
  color: var(--neutral-400);
  font-style: italic;
}

/* Company Selector Special Styling */
#companySelector {
  padding: 0;
}

#companySelect {
  border: none;
  border-radius: 0;
  background: var(--neutral-0);
}

/* Search Button */
.search-btn-container {
  text-align: center;
  padding: var(--spacing-lg) var(--spacing-xl);
  background: var(--neutral-0);
  border-top: 1px solid var(--neutral-200);
}

.search-btn {
  background: var(--gradient-primary);
  border: none;
  padding: var(--spacing-md) var(--spacing-xl);
  border-radius: var(--border-radius-lg);
  color: var(--neutral-0);
  font-weight: var(--font-semibold);
  font-size: var(--text-base);
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-out);
  position: relative;
  overflow: hidden;
  min-width: 140px;
}

.search-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-xl);
}

.search-btn:active {
  transform: translateY(-1px);
}

.search-btn::before {
  content: '🔍';
  margin-right: var(--spacing-sm);
  font-size: var(--text-lg);
}

/* Results Area Styling */
.search-results-container {
  margin-top: var(--spacing-xl);
}

#searchTitle {
  background: var(--gradient-success);
  color: var(--neutral-0);
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: var(--border-radius-md);
  margin-bottom: var(--spacing-lg);
  font-weight: var(--font-semibold);
  text-align: center;
  box-shadow: var(--shadow-md);
}

#searchTitle:empty {
  display: none;
}

#searchResults {
  background: var(--neutral-0);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

#searchResults:empty {
  display: none;
}

/* Job Details Styling */
#jobDetails {
  margin-top: var(--spacing-lg);
  background: var(--neutral-0);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

#jobDetails:empty {
  display: none;
}

/* Modal Styling */
#invoice-modal .modal-content {
  background: var(--neutral-0);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-2xl);
  border: none;
}

.close-btn {
  background: var(--error-500);
  color: var(--neutral-0);
  border: none;
  border-radius: var(--border-radius-full);
  width: 30px;
  height: 30px;
  position: absolute;
  top: 10px;
  right: 10px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  z-index: 1000;
  transition: all var(--duration-fast) var(--ease-out);
}

.close-btn:hover {
  background: var(--error-600);
  transform: scale(1.1);
}

/* Success/Error states */
.search-field-group.success {
  border-color: var(--success-500);
  background: linear-gradient(135deg, var(--success-50) 0%, #e8f5e8 100%);
}

.search-field-group.error {
  border-color: var(--error-500);
  background: linear-gradient(135deg, var(--error-50) 0%, #f8e8e8 100%);
  animation: shake 0.5s var(--ease-out);
}

/* Loading state */
.search-btn.loading {
  pointer-events: none;
  opacity: 0.7;
}

.search-btn.loading::before {
  content: '⏳';
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* Animation for field focus */
@keyframes focusGlow {
  0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.3); }
  70% { box-shadow: 0 0 0 6px rgba(59, 130, 246, 0); }
  100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}

.search-field-group.focused {
  animation: focusGlow 0.6s ease-out;
}

/* Responsive Design for Search */
@media (max-width: 768px) {
  .search-container {
    padding: var(--spacing-md);
  }
  
  .search-fields-container {
    padding: var(--spacing-lg);
  }
  
  .search-form-header {
    font-size: var(--text-base);
    padding: var(--spacing-md);
  }
  
  .search-btn {
    width: 100%;
    min-width: auto;
  }
}