/* 
PHC System v0.3.0 Mobile-First Design System
Atomic Design + Mobile Optimization + PWA Ready
*/

/* ===== CSS CUSTOM PROPERTIES ===== */
:root {
  /* Color Palette - Mobile Optimized Contrast */
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;
  --primary-500: #3b82f6;
  --primary-600: #2563eb;
  --primary-700: #1d4ed8;
  --primary-900: #1e3a8a;
  
  --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;
  
  --success-500: #10b981;
  --warning-500: #f59e0b;
  --danger-500: #ef4444;
  
  /* Typography Scale - Mobile Optimized */
  --text-xs: 0.75rem;    /* 12px */
  --text-sm: 0.875rem;   /* 14px */
  --text-base: 1rem;     /* 16px - Mobile base */
  --text-lg: 1.125rem;   /* 18px */
  --text-xl: 1.25rem;    /* 20px */
  --text-2xl: 1.5rem;    /* 24px */
  --text-3xl: 1.875rem;  /* 30px */
  
  /* Spacing Scale - Touch Optimized */
  --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 */
  
  /* Touch Target Sizes */
  --touch-target-min: 44px;    /* WCAG AAA minimum */
  --touch-target-comfort: 48px; /* Comfortable tap size */
  --touch-target-large: 56px;   /* Large actions */
  
  /* Border Radius */
  --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;  /* Circular */
  
  /* Animation Properties */
  --duration-instant: 150ms;
  --duration-quick: 200ms;
  --duration-normal: 300ms;
  --duration-slow: 500ms;
  
  --easing-standard: cubic-bezier(0.4, 0, 0.2, 1);
  --easing-enter: cubic-bezier(0, 0, 0.2, 1);
  --easing-exit: cubic-bezier(0.4, 0, 1, 1);
  
  /* 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;
  
  /* Mobile Safe Areas */
  --safe-area-inset-top: env(safe-area-inset-top);
  --safe-area-inset-right: env(safe-area-inset-right);
  --safe-area-inset-bottom: env(safe-area-inset-bottom);
  --safe-area-inset-left: env(safe-area-inset-left);
}

/* ===== RESET & BASE STYLES ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  /* 62.5% = 10px base for easier rem calculations */
  font-size: 62.5%;
  /* Prevent adjustments of font size after orientation changes */
  -webkit-text-size-adjust: 100%;
  /* Smooth scrolling for iOS */
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'sans-serif';
  font-size: 1.6rem; /* 16px */
  line-height: 1.5;
  color: var(--gray-900);
  background-color: var(--gray-50);
  /* Smooth font rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Prevent horizontal scrolling */
  overflow-x: hidden;
}

/* ===== ATOMS - BASIC ELEMENTS ===== */

/* Typography Atoms */
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }

.font-normal { font-weight: 400; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.text-gray-500 { color: var(--gray-500); }
.text-gray-600 { color: var(--gray-600); }
.text-gray-700 { color: var(--gray-700); }
.text-gray-900 { color: var(--gray-900); }
.text-primary-600 { color: var(--primary-600); }
.text-success-500 { color: var(--success-500); }
.text-warning-500 { color: var(--warning-500); }
.text-danger-500 { color: var(--danger-500); }

/* Button Atoms - Touch Optimized */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target-min);
  padding: var(--space-3) var(--space-4);
  border: none;
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--duration-quick) var(--easing-standard);
  /* Prevent zoom on double tap (iOS) */
  touch-action: manipulation;
  /* Remove default button styles */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  /* Add subtle shadow for depth */
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.btn:focus {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

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

.btn-primary:hover,
.btn-primary:active {
  background-color: var(--primary-700);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px 0 rgba(59, 130, 246, 0.4);
}

.btn-secondary {
  background-color: white;
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
}

.btn-secondary:hover,
.btn-secondary:active {
  background-color: var(--gray-50);
  border-color: var(--gray-300);
}

.btn-success {
  background-color: var(--success-500);
  color: white;
}

.btn-warning {
  background-color: var(--warning-500);
  color: white;
}

.btn-danger {
  background-color: var(--danger-500);
  color: white;
}

/* Icon Button */
.btn-icon {
  min-width: var(--touch-target-min);
  padding: var(--space-3);
  border-radius: var(--radius-full);
}



/* Input Atoms - Touch Optimized */
.input {
  width: 100%;
  min-height: var(--touch-target-min);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  background-color: white;
  transition: all var(--duration-quick) var(--easing-standard);
  /* Prevent zoom on focus (iOS) */
  font-size: 16px;
}

.input:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Badge Atoms */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  line-height: 1;
}

.badge-primary { background-color: var(--primary-100); color: var(--primary-700); }
.badge-success { background-color: #dcfce7; color: #166534; }
.badge-warning { background-color: #fef3c7; color: #92400e; }
.badge-danger { background-color: #fecaca; color: #991b1b; }

/* ===== MOLECULES - COMPONENT COMBINATIONS ===== */

/* Search Box Molecule */
.search-box {
  position: relative;
  width: 100%;
}

.search-box .input {
  padding-left: var(--space-12);
}

.search-box .search-icon {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  pointer-events: none;
}

/* Patient Card Molecule - Mobile Optimized */
.patient-card {
  display: flex;
  flex-direction: column;
  background: white;
  border-radius: var(--radius-xl);
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  overflow: hidden;
  transition: all var(--duration-normal) var(--easing-standard);
  /* Touch optimizations */
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}

.patient-card:hover,
.patient-card:active {
  box-shadow: 0 8px 25px -5px rgba(0, 0, 0, 0.15);
  transform: translateY(-2px);
}

.patient-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  min-height: var(--touch-target-comfort);
}

.patient-card-body {
  padding: 0 var(--space-4) var(--space-4);
}

.patient-card-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--gray-100);
  background-color: var(--gray-50);
}

/* Action Bar Molecule */
.action-bar {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3);
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.1);
}

/* Status Indicator Molecule */
.status-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
}

.status-dot.online { background-color: var(--success-500); }
.status-dot.offline { background-color: var(--gray-400); }
.status-dot.warning { background-color: var(--warning-500); }
.status-dot.critical { background-color: var(--danger-500); }

/* ===== ORGANISMS - COMPLEX COMPONENTS ===== */

/* Navigation Organism - Mobile First */
.bottom-navigation {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: white;
  border-top: 1px solid var(--gray-200);
  padding-bottom: var(--safe-area-inset-bottom);
  z-index: var(--z-fixed);
  /* iOS safe area support */
  padding-bottom: calc(var(--safe-area-inset-bottom) + var(--space-2));
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target-large);
  padding: var(--space-2);
  text-decoration: none;
  color: var(--gray-500);
  transition: all var(--duration-quick) var(--easing-standard);
  /* Touch optimization */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item.active {
  color: var(--primary-600);
}

.bottom-nav-item:active {
  transform: scale(0.95);
}

.bottom-nav-icon {
  font-size: 2.4rem;
  margin-bottom: var(--space-1);
}

.bottom-nav-label {
  font-size: var(--text-xs);
  font-weight: 500;
}

/* Patient List Organism */
.patient-list {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-4);
  padding-bottom: calc(var(--space-8) + var(--touch-target-large) + var(--safe-area-inset-bottom));
}

/* Dashboard Organism - Mobile Layout */
.dashboard {
  padding: var(--space-4);
  padding-bottom: calc(var(--space-8) + var(--touch-target-large) + var(--safe-area-inset-bottom));
}

.dashboard-header {
  margin-bottom: var(--space-6);
}

.dashboard-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  margin-bottom: var(--space-2);
}

.dashboard-subtitle {
  color: var(--gray-600);
}

.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.stat-card {
  background: white;
  padding: var(--space-4);
  border-radius: var(--radius-xl);
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.stat-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--primary-600);
}

.stat-label {
  font-size: var(--text-sm);
  color: var(--gray-600);
  margin-top: var(--space-1);
}

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

/* Mobile First Breakpoints */
/* Default styles are for mobile (320px+) */

/* Large Mobile (425px+) */
@media (min-width: 26.5625em) { /* 425px */
  .patient-list {
    grid-template-columns: 1fr;
  }
  
  .dashboard-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Tablet (768px+) */
@media (min-width: 48em) { /* 768px */
  :root {
    --text-base: 1.4rem; /* Slightly larger for tablets */
  }
  
  .patient-list {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .dashboard-stats {
    grid-template-columns: repeat(4, 1fr);
  }
  
  /* Hide bottom navigation on tablets */
  .bottom-navigation {
    display: none;
  }
  
  /* Show sidebar navigation instead */
  .sidebar-navigation {
    display: block;
  }
}

/* Desktop (1024px+) */
@media (min-width: 64em) { /* 1024px */
  .patient-list {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .dashboard {
    max-width: 1200px;
    margin: 0 auto;
  }
}

/* Large Desktop (1440px+) */
@media (min-width: 90em) { /* 1440px */
  .patient-list {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ===== ANIMATION & MOTION ===== */

/* Scroll-based animations for performance */
@media (prefers-reduced-motion: no-preference) {
  .animate-fade-in {
    animation: fadeIn var(--duration-normal) var(--easing-enter) both;
  }
  
  .animate-slide-up {
    animation: slideUp var(--duration-normal) var(--easing-enter) both;
  }
  
  .animate-bounce {
    animation: bounce var(--duration-slow) var(--easing-standard) both;
  }
}

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

@keyframes slideUp {
  from { 
    opacity: 0;
    transform: translateY(30px);
  }
  to { 
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bounce {
  0%, 20%, 53%, 80%, 100% {
    transform: translate3d(0, 0, 0);
  }
  40%, 43% {
    transform: translate3d(0, -8px, 0);
  }
  70% {
    transform: translate3d(0, -4px, 0);
  }
  90% {
    transform: translate3d(0, -2px, 0);
  }
}

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

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --gray-200: #000000;
    --gray-300: #000000;
    --primary-600: #0000ff;
  }
}

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

/* Focus management for keyboard navigation */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--primary-600);
  color: white;
  padding: 8px;
  z-index: 1000;
  text-decoration: none;
  border-radius: 4px;
}

.skip-link:focus {
  top: 6px;
}

/* Screen reader only content */
.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;
}

/* ===== TOUCH & GESTURE OPTIMIZATIONS ===== */

/* Improve touch targets */
.touch-target {
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
}

/* Remove tap highlight on iOS */
.no-tap-highlight {
  -webkit-tap-highlight-color: transparent;
}

/* Prevent text selection on UI elements */
.no-select {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Enable momentum scrolling on iOS */
.momentum-scroll {
  -webkit-overflow-scrolling: touch;
}

/* ===== PWA OPTIMIZATIONS ===== */

/* Safe area handling for notched devices */
.safe-area-top {
  padding-top: var(--safe-area-inset-top);
}

.safe-area-bottom {
  padding-bottom: var(--safe-area-inset-bottom);
}

.safe-area-left {
  padding-left: var(--safe-area-inset-left);
}

.safe-area-right {
  padding-right: var(--safe-area-inset-right);
}

/* Prevent zoom on input focus (iOS) */
@media screen and (max-width: 767px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="url"],
  input[type="search"],
  textarea,
  select {
    font-size: 16px !important;
  }
}

/* ===== DARK MODE SUPPORT (Future Enhancement) ===== */
@media (prefers-color-scheme: dark) {
  /* Dark mode variables would go here */
  /* Currently maintaining light mode focus for medical context */
}