/* ============================================
   RESPONSIVE & ACCESSIBILITY STYLES
   ============================================ */

/* ============================================
   BASE RESPONSIVE STYLES
   ============================================ */

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

/* Smooth scrolling for better UX */
html {
  scroll-behavior: smooth;
}

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 3px solid #3b82f6;
  outline-offset: 2px;
}

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

/* ============================================
   TOUCH-FRIENDLY INTERACTIONS
   ============================================ */

/* Minimum touch target size: 44x44px (WCAG 2.1 AA) */
button,
a,
input[type="button"],
input[type="submit"],
input[type="reset"],
.btn,
.touch-target {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Increase tap area for small interactive elements */
.touch-target-small {
  position: relative;
}

.touch-target-small::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  min-width: 44px;
  min-height: 44px;
}

/* Touch-friendly spacing for mobile */
@media (max-width: 768px) {
  .touch-spacing > * + * {
    margin-top: 0.75rem;
  }
  
  .touch-spacing-horizontal > * + * {
    margin-left: 0.75rem;
  }
}

/* ============================================
   RESPONSIVE NAVIGATION
   ============================================ */

/* Mobile menu toggle button */
.mobile-menu-button {
  display: none;
}

@media (max-width: 768px) {
  .mobile-menu-button {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: transparent;
    border: none;
    cursor: pointer;
  }
  
  /* Hide desktop navigation on mobile */
  .desktop-nav {
    display: none;
  }
  
  /* Mobile navigation styles */
  .mobile-nav {
    display: none;
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    z-index: 40;
    overflow-y: auto;
    padding: 1rem;
  }
  
  .mobile-nav.active {
    display: block;
  }
  
  .mobile-nav a {
    display: block;
    padding: 1rem;
    font-size: 1rem;
    color: #374151;
    text-decoration: none;
    border-bottom: 1px solid #e5e7eb;
  }
  
  .mobile-nav a:hover,
  .mobile-nav a:focus {
    background-color: #f3f4f6;
  }
  
  .mobile-nav a.active {
    background-color: #eff6ff;
    color: #2563eb;
    font-weight: 600;
  }
}

/* ============================================
   RESPONSIVE GRID LAYOUTS
   ============================================ */

/* Responsive grid for metrics/cards */
.responsive-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

@media (max-width: 640px) {
  .responsive-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* Two-column responsive layout */
.responsive-two-col {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

@media (max-width: 1024px) {
  .responsive-two-col {
    grid-template-columns: 1fr;
  }
}

/* Three-column responsive layout */
.responsive-three-col {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

@media (max-width: 768px) {
  .responsive-three-col {
    grid-template-columns: 1fr;
  }
}

/* ============================================
   RESPONSIVE TABLES
   ============================================ */

/* Make tables responsive on mobile */
@media (max-width: 768px) {
  .responsive-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .responsive-table table {
    min-width: 600px;
  }
  
  /* Card-style table for mobile */
  .responsive-table-cards {
    display: block;
  }
  
  .responsive-table-cards thead {
    display: none;
  }
  
  .responsive-table-cards tbody,
  .responsive-table-cards tr,
  .responsive-table-cards td {
    display: block;
  }
  
  .responsive-table-cards tr {
    margin-bottom: 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 1rem;
    background: white;
  }
  
  .responsive-table-cards td {
    padding: 0.5rem 0;
    border: none;
  }
  
  .responsive-table-cards td::before {
    content: attr(data-label);
    font-weight: 600;
    display: inline-block;
    width: 120px;
    color: #6b7280;
  }
}

/* ============================================
   RESPONSIVE FORMS
   ============================================ */

/* Stack form elements on mobile */
@media (max-width: 640px) {
  .form-row {
    flex-direction: column;
  }
  
  .form-row > * {
    width: 100% !important;
  }
}

/* Touch-friendly form inputs */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
textarea,
select {
  min-height: 44px;
  font-size: 16px; /* Prevents zoom on iOS */
  padding: 0.75rem;
}

/* ============================================
   RESPONSIVE MODALS
   ============================================ */

@media (max-width: 640px) {
  .modal-content {
    width: 95vw !important;
    max-width: 95vw !important;
    margin: 1rem;
  }
  
  .modal-content .modal-body {
    max-height: 70vh;
    overflow-y: auto;
  }
}

/* ============================================
   ACCESSIBILITY: SKIP LINKS
   ============================================ */

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #000;
  color: #fff;
  padding: 8px;
  text-decoration: none;
  z-index: 100;
}

.skip-link:focus {
  top: 0;
}

/* ============================================
   ACCESSIBILITY: SCREEN READER ONLY
   ============================================ */

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

.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  padding: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ============================================
   ACCESSIBILITY: FOCUS INDICATORS
   ============================================ */

/* Enhanced focus for interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #3b82f6;
  outline-offset: 2px;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Focus within for containers */
.focus-within-ring:focus-within {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* ============================================
   ACCESSIBILITY: HIGH CONTRAST
   ============================================ */

@media (prefers-contrast: high) {
  * {
    border-color: currentColor !important;
  }
  
  button,
  .btn {
    border: 2px solid currentColor;
  }
}

/* ============================================
   ACCESSIBILITY: REDUCED MOTION
   ============================================ */

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

/* ============================================
   RESPONSIVE CALENDAR
   ============================================ */

@media (max-width: 768px) {
  /* Stack calendar controls vertically */
  .calendar-controls {
    flex-direction: column;
    gap: 1rem;
  }
  
  .calendar-controls > * {
    width: 100%;
  }
  
  /* Simplify calendar view on mobile */
  .calendar-grid {
    font-size: 0.875rem;
  }
  
  .calendar-event {
    font-size: 0.75rem;
    padding: 0.25rem;
  }
  
  /* Hide time labels on very small screens */
  @media (max-width: 480px) {
    .calendar-time-label {
      font-size: 0.625rem;
    }
  }
}

/* ============================================
   RESPONSIVE DASHBOARD
   ============================================ */

@media (max-width: 640px) {
  /* Stack dashboard metrics vertically */
  .dashboard-metrics {
    grid-template-columns: 1fr !important;
  }
  
  /* Simplify metric cards */
  .metric-card {
    padding: 1rem;
  }
  
  .metric-card .metric-value {
    font-size: 2rem;
  }
  
  /* Stack quick actions */
  .quick-actions {
    grid-template-columns: 1fr !important;
  }
}

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

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

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

/* Show only on mobile */
.show-mobile {
  display: none !important;
}

@media (max-width: 768px) {
  .show-mobile {
    display: block !important;
  }
  
  .show-mobile-flex {
    display: flex !important;
  }
  
  .show-mobile-inline {
    display: inline !important;
  }
}

/* ============================================
   RESPONSIVE TEXT
   ============================================ */

@media (max-width: 640px) {
  h1 {
    font-size: 1.5rem;
  }
  
  h2 {
    font-size: 1.25rem;
  }
  
  h3 {
    font-size: 1.125rem;
  }
  
  .text-responsive {
    font-size: 0.875rem;
  }
}

/* ============================================
   ACCESSIBILITY: ARIA LIVE REGIONS
   ============================================ */

[aria-live] {
  position: relative;
}

/* Visual indicator for live regions (dev mode) */
[aria-live][data-dev-mode]::before {
  content: 'LIVE: ' attr(aria-live);
  position: absolute;
  top: -20px;
  left: 0;
  font-size: 10px;
  color: #ef4444;
  font-weight: bold;
}

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

@media print {
  /* Hide navigation and non-essential elements */
  nav,
  .no-print,
  button,
  .btn {
    display: none !important;
  }
  
  /* Ensure content is visible */
  body {
    background: white;
    color: black;
  }
  
  /* Expand all content */
  .container {
    max-width: 100%;
  }
  
  /* Page breaks */
  .page-break-before {
    page-break-before: always;
  }
  
  .page-break-after {
    page-break-after: always;
  }
  
  .page-break-avoid {
    page-break-inside: avoid;
  }
}

/* ============================================
   RESPONSIVE SPACING
   ============================================ */

@media (max-width: 640px) {
  .container {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  
  .section-spacing {
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
  }
}

/* ============================================
   TOUCH GESTURES
   ============================================ */

/* Prevent text selection on double-tap */
.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;
}

/* ============================================
   KEYBOARD NAVIGATION HELPERS
   ============================================ */

/* Visible focus for keyboard users */
.keyboard-focus:focus-visible {
  outline: 3px solid #3b82f6;
  outline-offset: 2px;
  z-index: 10;
}

/* Tab navigation order indicator (dev mode) */
[tabindex][data-dev-mode]::after {
  content: attr(tabindex);
  position: absolute;
  top: 0;
  right: 0;
  background: #3b82f6;
  color: white;
  font-size: 10px;
  padding: 2px 4px;
  border-radius: 2px;
}
