/* Purpose: Mobile-responsive and accessibility enhancements for EHR-Africa */

/* Mobile-First Responsive Design */
@media (max-width: 768px) {
  /* Body and Layout */
  body {
    margin: 10px;
    font-size: 16px; /* Prevents iOS zoom on input focus */
  }
  
  h1 {
    font-size: 24px;
  }
  
  h2 {
    font-size: 20px;
  }
  
  h3 {
    font-size: 18px;
  }
  
  /* Touch-Optimized Buttons */
  button,
  .btn,
  .action-btn {
    min-height: 44px; /* iOS minimum touch target */
    min-width: 44px;
    font-size: 16px; /* Prevents zoom */
    padding: 12px 16px;
    margin: 5px 0;
  }
  
  /* Inputs and Forms */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="date"],
  input[type="password"],
  input[type="number"],
  select,
  textarea {
    font-size: 16px; /* Prevents iOS zoom */
    min-height: 44px;
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
  }
  
  /* Tables - Horizontal Scroll */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  
  table thead {
    display: table;
    width: 100%;
    table-layout: fixed;
  }
  
  table tbody {
    display: table;
    width: 100%;
    table-layout: fixed;
  }
  
  /* Dashboard Grid - Stack Vertically */
  .dashboard-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  
  .dashboard-grid button {
    width: 100%;
  }
  
  /* Action Buttons - Stack Vertically */
  td > div {
    display: flex;
    flex-direction: column;
    gap: 5px;
  }
  
  td button {
    width: 100%;
    margin: 2px 0;
  }
  
  /* Navigation Buttons */
  div[style*="margin-bottom: 20px"] button {
    margin: 5px 0;
    width: 100%;
  }
  
  /* Modals - Full Screen on Mobile */
  [style*="position: fixed"][style*="z-index: 10000"] {
    padding: 10px !important;
  }
  
  [style*="position: fixed"][style*="z-index: 10000"] > div {
    max-width: 100% !important;
    margin: 0 !important;
  }
  
  /* Fixed Positioning Elements */
  #logged-in-info,
  #org-info {
    position: static !important;
    text-align: center;
    margin: 10px 0;
  }
  
  /* Forms */
  form {
    width: 100%;
  }
  
  label {
    font-size: 14px;
  }
  
  /* Backup Section on Dashboard */
  div[style*="background: #fff3cd"] {
    padding: 10px !important;
  }
  
  div[style*="display: flex"][style*="gap: 10px"] {
    flex-direction: column !important;
  }
  
  div[style*="display: flex"][style*="gap: 10px"] button {
    width: 100% !important;
    margin: 5px 0 !important;
  }
}

/* Tablet Landscape */
@media (min-width: 769px) and (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  table {
    font-size: 14px;
  }
  
  button {
    font-size: 14px;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  body {
    background-color: #1a1a1a;
    color: #e0e0e0;
  }
  
  h1, h2, h3 {
    color: #f0f0f0;
  }
  
  table {
    background-color: #2d2d2d;
    color: #e0e0e0;
    border-color: #444;
  }
  
  table th {
    background: linear-gradient(135deg, #2d5f2e, #265426);
    color: #e0e0e0;
  }
  
  table td {
    border-color: #444;
  }
  
  table tr:nth-child(even) {
    background-color: #252525;
  }
  
  table tr:hover {
    background-color: #333;
  }
  
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="date"],
  input[type="password"],
  input[type="number"],
  select,
  textarea {
    background-color: #2d2d2d;
    color: #e0e0e0;
    border-color: #555;
  }
  
  button {
    filter: brightness(0.9);
  }
  
  .card {
    background-color: #2d2d2d;
    color: #e0e0e0;
  }
  
  a {
    color: #66b2ff;
  }
}

/* High Contrast Mode for Accessibility */
@media (prefers-contrast: high) {
  body {
    background-color: white;
    color: black;
  }
  
  table th {
    background: black;
    color: white;
  }
  
  button {
    border: 2px solid black;
  }
  
  a {
    text-decoration: underline;
    font-weight: bold;
  }
}

/* Reduced Motion for Accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Print Styles */
@media print {
  body {
    background: white;
    color: black;
  }
  
  button,
  .no-print,
  #logged-in-info,
  #org-info {
    display: none !important;
  }
  
  table {
    page-break-inside: avoid;
  }
  
  h1, h2, h3 {
    page-break-after: avoid;
  }
}

/* Accessibility Enhancements */

/* Skip to main content link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #4CAF50;
  color: white;
  padding: 8px;
  text-decoration: none;
  border-radius: 0 0 4px 0;
  z-index: 100000;
}

.skip-link:focus {
  top: 0;
}

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 3px solid #4CAF50;
  outline-offset: 2px;
}

/* Larger touch targets */
input[type="checkbox"],
input[type="radio"] {
  min-width: 20px;
  min-height: 20px;
  cursor: pointer;
}

/* 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;
}

/* Improve readability */
p, li {
  line-height: 1.6;
}

/* Ensure sufficient color contrast */
.low-contrast {
  color: #333;
  background-color: #f5f5f5;
}

/* Loading states */
.loading {
  opacity: 0.6;
  pointer-events: none;
  position: relative;
}

.loading::after {
  content: "Loading...";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 10px 20px;
  border-radius: 4px;
  font-size: 14px;
}


