/**
 * Responsive Utilities - Mobile-First Enhancements
 * Touch optimization, responsive tables, modal improvements
 */

/* ========================================
   Touch Optimization
   ======================================== */

/* Ensure minimum touch target size (44x44px per WCAG) — scoped controls only */
@media (pointer: coarse) {
  .btn,
  .kids-btn,
  .action-btn,
  .panel-bottom-nav a,
  button[type="submit"],
  button.mobile-menu-toggle,
  input[type="checkbox"],
  input[type="radio"],
  select {
    min-width: 44px;
    min-height: 44px;
  }

  .btn,
  .nav-link {
    min-height: 48px;
    padding-top: 12px;
    padding-bottom: 12px;
  }
}

/* Remove hover states on touch devices */
@media (hover: none) {
  .hover\:bg-slate-100:hover {
    background-color: transparent !important;
  }
  
  button:hover,
  a:hover {
    background-color: inherit;
  }
  
  /* But keep active states */
  button:active,
  a:active {
    transform: scale(0.98);
    opacity: 0.8;
  }
}

/* Smooth scrolling for better UX */
html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* ========================================
   Responsive Modal System
   ======================================== */

/* Full-screen modals on mobile */
@media (max-width: 639px) {
  .modal-content {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }
  
  .modal-container {
    padding: 0 !important;
    align-items: flex-start !important;
  }
  
  .modal-body {
    max-height: calc(100vh - 140px) !important;
  }
  
  /* Slide-up animation for mobile modals */
  @keyframes slideUpMobile {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }
  
  .modal-content.is-open {
    animation: slideUpMobile 0.3s ease-out;
  }
}

/* Tablet modals */
@media (min-width: 640px) and (max-width: 1023px) {
  .modal-content {
    max-width: 90vw !important;
    max-height: 90vh !important;
  }
}

/* ========================================
   Responsive Tables
   ======================================== */

/* Desktop: Normal table */
@media (min-width: 1024px) {
  .table-responsive {
    overflow-x: visible;
  }
  
  .data-table {
    display: table;
  }
  
  .table-card-mobile {
    display: none !important;
  }
}

/* Tablet: Horizontal scroll with sticky columns */
@media (min-width: 768px) and (max-width: 1023px) {
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .data-table th:first-child,
  .data-table td:first-child {
    position: sticky;
    right: 0;
    background-color: inherit;
    z-index: 10;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
  }
  
  .data-table thead th:first-child {
    z-index: 11;
  }
}

/* Mobile: Card layout */
@media (max-width: 767px) {
  .table-responsive .data-table {
    display: none;
  }
  
  .table-card-mobile {
    display: block !important;
  }
  
  .table-card {
    background: white;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid rgb(226, 232, 240);
  }
  
  .dark .table-card {
    background: rgb(30, 41, 59);
    border-color: rgb(51, 65, 85);
  }
  
  .table-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid rgb(241, 245, 249);
  }
  
  .dark .table-card-row {
    border-bottom-color: rgb(51, 65, 85);
  }
  
  .table-card-row:last-child {
    border-bottom: none;
  }
  
  .table-card-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: rgb(100, 116, 139);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  
  .dark .table-card-label {
    color: rgb(148, 163, 184);
  }
  
  .table-card-value {
    font-size: 0.875rem;
    font-weight: 600;
    color: rgb(15, 23, 42);
    text-align: left;
  }
  
  .dark .table-card-value {
    color: rgb(241, 245, 249);
  }
}

/* ========================================
   Responsive Grid Utilities
   ======================================== */

.grid-responsive {
  display: grid;
  gap: 1rem;
}

@media (min-width: 640px) {
  .grid-responsive {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .grid-responsive {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1280px) {
  .grid-responsive-4 {
    grid-template-columns: repeat(4, 1fr) !important;
  }
}

/* ========================================
   Responsive Typography
   ======================================== */

/* Fluid typography for better mobile readability */
.text-responsive-xl {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  line-height: 1.2;
}

.text-responsive-lg {
  font-size: clamp(1.25rem, 3vw, 2rem);
  line-height: 1.3;
}

.text-responsive-md {
  font-size: clamp(1rem, 2vw, 1.5rem);
  line-height: 1.4;
}

/* ========================================
   Responsive Spacing
   ======================================== */

.container-responsive {
  padding-left: 1rem;
  padding-right: 1rem;
}

@media (min-width: 640px) {
  .container-responsive {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}

@media (min-width: 1024px) {
  .container-responsive {
    padding-left: 2rem;
    padding-right: 2rem;
  }
}

/* ========================================
   Safe Area Insets (iOS notch/home indicator)
   ======================================== */

.safe-area-inset-bottom {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.safe-area-inset-top {
  padding-top: env(safe-area-inset-top, 0px);
}

/* ========================================
   Orientation-specific styles
   ======================================== */

@media (orientation: landscape) and (max-height: 600px) {
  /* Reduce header/footer heights in landscape mobile */
  .dashboard-header,
  .panel-header {
    min-height: 52px !important;
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
  }
  
  .bottom-nav {
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
  }
  
  .sidebar {
    max-height: 100vh;
  }
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
  /* Hide navigation, buttons, and non-essential elements */
  .sidebar,
  .bottom-nav,
  .mobile-more-drawer,
  .panel-header,
  .dashboard-header,
  button,
  .btn,
  .no-print {
    display: none !important;
  }
  
  /* Reset layout for printing */
  body {
    padding: 0 !important;
  }
  
  main,
  .panel-content {
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
  }
  
  /* Remove shadows and borders */
  .card,
  .modal-content,
  .table-container {
    box-shadow: none !important;
    border: 1px solid #ddd !important;
  }
  
  /* Ensure readable text */
  body,
  .card,
  .data-table {
    color: #000 !important;
    background: #fff !important;
  }
}

/* ========================================
   Accessibility Enhancements
   ======================================== */

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid rgb(59, 130, 246);
  outline-offset: 2px;
}

/* Skip to main content link */
.skip-to-main {
  position: absolute;
  left: -9999px;
  z-index: 999;
  padding: 1rem;
  background-color: rgb(59, 130, 246);
  color: white;
  text-decoration: none;
  font-weight: bold;
  border-radius: 0 0 0.5rem 0.5rem;
}

.skip-to-main:focus {
  left: 50%;
  transform: translateX(-50%);
  top: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .card,
  .btn,
  .form-input,
  .nav-link {
    border: 2px solid currentColor !important;
  }
  
  .nav-link-active,
  .tab-active {
    outline: 3px solid currentColor !important;
    outline-offset: -3px !important;
  }
}
