/* Custom CSS for Pharmacy Home Care System */

/* Root Variables */
:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --success-color: #22c55e;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-800: #1f2937;
  --gray-900: #111827;
}

/* Base Styles */
* {
  box-sizing: border-box;
}

body {
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Loading States */
.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 1s ease-in-out infinite;
}

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

/* Card Animations */
.card-hover {
  transition: all 0.2s ease-in-out;
}

.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Status Indicators */
.status-online {
  background-color: #22c55e;
}

.status-busy {
  background-color: #f59e0b;
}

.status-offline {
  background-color: #6b7280;
}

.status-urgent {
  background-color: #ef4444;
  animation: pulse-urgent 2s infinite;
}

@keyframes pulse-urgent {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Patient Card Styles */
.patient-card {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid #e5e7eb;
  cursor: pointer;
}

.patient-card:hover {
  border-color: var(--primary-color);
  box-shadow: 0 8px 25px -8px rgba(37, 99, 235, 0.3);
}

.patient-card.priority-high {
  border-left: 4px solid #ef4444;
}

.patient-card.priority-medium {
  border-left: 4px solid #f59e0b;
}

.patient-card.priority-low {
  border-left: 4px solid #22c55e;
}

/* Button Styles */
.btn-primary {
  background-color: var(--primary-color);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  font-weight: 500;
  transition: background-color 0.2s;
  border: none;
  cursor: pointer;
}

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

.btn-primary:disabled {
  background-color: #9ca3af;
  cursor: not-allowed;
}

/* Form Styles */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-800);
  margin-bottom: 0.25rem;
}

.form-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input.error {
  border-color: var(--danger-color);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* Schedule Grid */
.schedule-grid {
  display: grid;
  grid-template-columns: 80px repeat(7, 1fr);
  gap: 1px;
  background-color: #e5e7eb;
  border-radius: 0.5rem;
  overflow: hidden;
}

.schedule-cell {
  background-color: white;
  padding: 0.5rem;
  min-height: 60px;
}

.schedule-cell.time-slot {
  background-color: var(--gray-100);
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
}

.schedule-cell.header {
  background-color: var(--primary-color);
  color: white;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Visit Status Styles */
.visit-status-pending {
  background-color: #fef3c7;
  color: #92400e;
}

.visit-status-confirmed {
  background-color: #d1fae5;
  color: #065f46;
}

.visit-status-in-progress {
  background-color: #dbeafe;
  color: #1e40af;
}

.visit-status-completed {
  background-color: #f3f4f6;
  color: #374151;
}

.visit-status-cancelled {
  background-color: #fee2e2;
  color: #991b1b;
}

/* Medication Adherence Indicator */
.adherence-excellent {
  background: linear-gradient(90deg, #22c55e 0%, #16a34a 100%);
}

.adherence-good {
  background: linear-gradient(90deg, #84cc16 0%, #65a30d 100%);
}

.adherence-fair {
  background: linear-gradient(90deg, #f59e0b 0%, #d97706 100%);
}

.adherence-poor {
  background: linear-gradient(90deg, #ef4444 0%, #dc2626 100%);
}

/* Care Level Badges */
.care-level-1 { background-color: #dbeafe; color: #1e40af; }
.care-level-2 { background-color: #dcfce7; color: #166534; }
.care-level-3 { background-color: #fef3c7; color: #92400e; }
.care-level-4 { background-color: #fed7aa; color: #9a3412; }
.care-level-5 { background-color: #fee2e2; color: #991b1b; }

/* Responsive Design */
@media (max-width: 768px) {
  .schedule-grid {
    grid-template-columns: 60px repeat(3, 1fr);
  }
  
  .patient-card {
    margin-bottom: 0.75rem;
  }
  
  .btn-primary {
    width: 100%;
    margin-bottom: 0.5rem;
  }
}

/* Print Styles */
@media print {
  .no-print {
    display: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
  
  .patient-card {
    break-inside: avoid;
    border: 1px solid #ccc !important;
    box-shadow: none !important;
    margin-bottom: 1rem;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  .dark-mode {
    background-color: #1f2937;
    color: #f9fafb;
  }
  
  .dark-mode .patient-card {
    background-color: #374151;
    border-color: #4b5563;
  }
  
  .dark-mode .form-input {
    background-color: #374151;
    border-color: #4b5563;
    color: #f9fafb;
  }
}

/* Accessibility */
.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;
}

/* Focus Indicators */
.focus-visible:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  .patient-card {
    border-width: 2px;
  }
  
  .btn-primary {
    border: 2px solid currentColor;
  }
}

/* ============================================================================
   Enhanced Visual Accessibility Styles (v0.1.13)
   ============================================================================ */

/* Priority Color System */
.priority-emergency {
  background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
  border-left: 6px solid #dc2626;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.15);
}

.priority-urgent {
  background: linear-gradient(135deg, #fff7ed 0%, #fed7aa 100%);
  border-left: 6px solid #ea580c;
  box-shadow: 0 4px 12px rgba(234, 88, 12, 0.15);
}

.priority-routine {
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border-left: 6px solid #3b82f6;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

/* Enhanced Focus States */
.enhanced-focus:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 3px;
  border-radius: 8px;
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.2);
}

/* Status Pulse Animations */
@keyframes emergency-pulse {
  0%, 100% { 
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.7);
  }
  50% { 
    box-shadow: 0 0 0 10px rgba(220, 38, 38, 0);
  }
}

@keyframes urgent-pulse {
  0%, 100% { 
    box-shadow: 0 0 0 0 rgba(234, 88, 12, 0.7);
  }
  50% { 
    box-shadow: 0 0 0 8px rgba(234, 88, 12, 0);
  }
}

.status-emergency {
  animation: emergency-pulse 2s infinite;
}

.status-urgent {
  animation: urgent-pulse 2s infinite;
}

/* Enhanced Typography Scale */
.text-hierarchy-1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.text-hierarchy-2 {
  font-size: clamp(1.25rem, 3vw, 1.5rem);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.text-hierarchy-3 {
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  font-weight: 600;
  line-height: 1.4;
}

.text-hierarchy-4 {
  font-size: clamp(0.875rem, 2vw, 1rem);
  font-weight: 500;
  line-height: 1.5;
}

/* Medical Icons Enhancement */
.medical-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-size: 0.875rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.medical-icon.emergency {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  color: white;
  animation: emergency-pulse 2s infinite;
}

.medical-icon.warning {
  background: linear-gradient(135deg, #ea580c, #c2410c);
  color: white;
}

.medical-icon.info {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: white;
}

.medical-icon.success {
  background: linear-gradient(135deg, #16a34a, #15803d);
  color: white;
}

/* Enhanced Card Hover Effects */
.card-enhanced-hover {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center;
}

.card-enhanced-hover:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 
    0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.card-enhanced-hover:active {
  transform: translateY(-2px) scale(1.01);
}

/* Color Blind Friendly Patterns */
.colorblind-pattern-dots::before {
  content: '';
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 0.75rem;
  height: 0.75rem;
  background: radial-gradient(circle, currentColor 2px, transparent 2px);
  background-size: 4px 4px;
}

.colorblind-pattern-stripes::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: repeating-linear-gradient(
    45deg,
    currentColor,
    currentColor 2px,
    transparent 2px,
    transparent 6px
  );
}

/* Enhanced Button States */
.btn-enhanced {
  position: relative;
  overflow: hidden;
  transform: perspective(1px) translateZ(0);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-enhanced::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.btn-enhanced:hover::before {
  left: 100%;
}

.btn-enhanced:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

/* Loading States Enhancement */
.loading-enhanced {
  position: relative;
  overflow: hidden;
}

.loading-enhanced::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.4),
    transparent
  );
  animation: loading-shimmer 2s infinite;
}

@keyframes loading-shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* Reduced Motion Preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .status-emergency,
  .status-urgent {
    animation: none;
  }
}

/* High DPI Screens Enhancement */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .medical-icon {
    border: 0.5px solid rgba(255, 255, 255, 0.2);
  }
  
  .patient-card {
    border-width: 0.5px;
  }
}

/* ============================================================================
   Contextual Font Scaling & Adaptive UI System (v0.1.13)
   ============================================================================ */

/* Context-based Font Scaling */
[data-context="emergency"] {
  font-size: 1.25rem !important;
  font-weight: 800 !important;
  color: #dc2626 !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  line-height: 1.3;
}

[data-context="medication"] {
  font-size: 1.15rem !important;
  font-weight: 700 !important;
  color: #1d4ed8 !important;
  line-height: 1.4;
}

[data-context="patient"] {
  font-size: 1.12rem !important;
  font-weight: 600 !important;
  color: #1f2937 !important;
  line-height: 1.4;
}

[data-context="schedule"] {
  font-size: 1.10rem !important;
  font-weight: 600 !important;
  color: #059669 !important;
  line-height: 1.5;
}

[data-context="notes"] {
  font-size: 1.00rem !important;
  font-weight: 500 !important;
  color: #6b7280 !important;
  line-height: 1.6;
}

/* Font Scaling Panel */
#font-scaling-panel {
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(229, 231, 235, 0.8);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

/* Global Font Scale CSS Variables */
:root {
  --global-font-scale: 1;
  --time-brightness: 1;
  --time-contrast: 1;
  --time-blue-light: 1;
}

/* Apply global scale to scalable text */
.scalable-text {
  font-size: calc(1rem * var(--global-font-scale));
}

/* Time-based Adjustments */
.time-morning {
  filter: brightness(var(--time-brightness)) contrast(var(--time-contrast));
}

.time-afternoon {
  filter: brightness(var(--time-brightness)) contrast(var(--time-contrast));
}

.time-evening {
  filter: brightness(var(--time-brightness)) contrast(var(--time-contrast)) sepia(0.1);
}

.time-night {
  filter: brightness(var(--time-brightness)) contrast(var(--time-contrast)) sepia(0.2);
  background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
  color: #f9fafb;
}

.time-night .patient-card {
  background: rgba(55, 65, 81, 0.8);
  border-color: #6b7280;
  color: #f3f4f6;
}

/* Adaptive UI - Frequent Use Indicators */
.frequent-use-highlight {
  position: relative;
  border: 2px solid #22c55e;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.1) 0%, rgba(34, 197, 94, 0.05) 100%);
}

.frequent-use-highlight::before {
  content: '★';
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  background: #22c55e;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: bold;
  box-shadow: 0 2px 4px rgba(34, 197, 94, 0.3);
}

.very-frequent-use {
  animation: gentle-glow 3s ease-in-out infinite;
}

@keyframes gentle-glow {
  0%, 100% {
    box-shadow: 0 4px 8px rgba(34, 197, 94, 0.2);
  }
  50% {
    box-shadow: 0 6px 12px rgba(34, 197, 94, 0.4);
  }
}

.usage-indicator {
  animation: usage-pulse 2s ease-in-out infinite;
}

@keyframes usage-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

/* Accessibility Toggle Button */
#accessibility-toggle {
  animation: accessibility-bounce 3s ease-in-out infinite;
}

@keyframes accessibility-bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

/* Context Preset Buttons */
.context-preset {
  transition: all 0.2s ease;
  border: 2px solid transparent;
}

.context-preset:hover {
  border-color: currentColor;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.context-preset.active {
  border-color: currentColor;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Enhanced Focus for Accessibility */
[data-track="true"]:focus-visible,
[data-track-id]:focus-visible {
  outline: 3px solid #3b82f6;
  outline-offset: 3px;
  border-radius: 6px;
  box-shadow: 0 0 0 6px rgba(59, 130, 246, 0.2);
}

/* Responsive Font Scaling Panel */
@media (max-width: 1024px) {
  #font-scaling-panel {
    position: fixed;
    top: auto;
    bottom: 80px;
    right: 4px;
    left: 4px;
    width: auto;
    max-width: 400px;
    margin: 0 auto;
  }
  
  #font-scaling-panel.hidden {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
  }
  
  #font-scaling-panel:not(.hidden) {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
    transition: transform 0.3s ease, opacity 0.3s ease;
  }
}

/* Usage Analytics Overlay */
.usage-analytics-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.usage-analytics-panel {
  background: white;
  border-radius: 12px;
  padding: 2rem;
  max-width: 500px;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

/* Print Optimizations for Scaled Content */
@media print {
  [data-context] {
    font-size: inherit !important;
    color: black !important;
    font-weight: normal !important;
  }
  
  .frequent-use-highlight,
  .very-frequent-use {
    border: 1px solid #ccc !important;
    background: white !important;
    box-shadow: none !important;
    animation: none !important;
  }
  
  #font-scaling-panel,
  #accessibility-toggle {
    display: none !important;
  }
}

/* ============================================================================
   Interactive Patient Cards Enhancement (v0.1.16)
   ============================================================================ */

/* Enhanced Patient Card Interactions */
.patient-card {
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.patient-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(37, 99, 235, 0.1), transparent);
  transition: left 0.5s ease;
  z-index: 1;
}

.patient-card:hover::before {
  left: 100%;
}

.patient-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 30px rgba(37, 99, 235, 0.15);
  border-color: #3b82f6;
}

/* Patient Card Status Colors */
.patient-card[data-status="stable"] {
  border-left: 4px solid #22c55e;
}

.patient-card[data-status="monitoring"] {
  border-left: 4px solid #f59e0b;
}

.patient-card[data-status="urgent"] {
  border-left: 4px solid #ef4444;
  animation: urgent-border-pulse 2s infinite;
}

@keyframes urgent-border-pulse {
  0%, 100% {
    border-left-color: #ef4444;
  }
  50% {
    border-left-color: #dc2626;
  }
}

/* Priority Indicators */
.patient-card.priority-high::after {
  content: '!';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 20px;
  height: 20px;
  background: #ef4444;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  animation: priority-pulse 1.5s infinite;
  z-index: 2;
}

@keyframes priority-pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }
}

/* Modal Enhancements */
.modal-overlay {
  animation: modal-fade-in 0.3s ease-out;
}

.modal-content {
  animation: modal-slide-in 0.3s ease-out;
}

@keyframes modal-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modal-slide-in {
  from {
    transform: translateY(-30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Interactive Button States */
.patient-card button {
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.patient-card button::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transition: width 0.4s ease, height 0.4s ease;
  transform: translate(-50%, -50%);
  z-index: 0;
}

.patient-card button:active::before {
  width: 200px;
  height: 200px;
}

.patient-card button span {
  position: relative;
  z-index: 1;
}

/* Search and Filter Enhancements */
.filter-active {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: white;
  border-color: #1d4ed8;
}

.sort-indicator::after {
  content: '↓';
  margin-left: 4px;
  font-size: 0.75rem;
  opacity: 0.7;
}

/* Loading State Enhancements */
.patient-cards-loading {
  animation: loading-fade-in 0.5s ease-out;
}

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

/* Responsive Patient Cards */
@media (max-width: 768px) {
  .patient-card {
    margin-bottom: 1rem;
  }
  
  .patient-card:hover {
    transform: none;
  }
  
  .patient-card:active {
    transform: scale(0.98);
  }
}

/* High Contrast Mode for Patient Cards */
@media (prefers-contrast: high) {
  .patient-card {
    border: 2px solid #000;
    background: #fff;
  }
  
  .patient-card[data-status="urgent"] {
    border: 3px solid #000;
    background: #fff5f5;
  }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
  .patient-card:hover::before {
    display: none;
  }
  
  .patient-card:active {
    background-color: #f8fafc;
    transform: scale(0.99);
  }
}