/**
 * mobile.css - Mobile-specific responsive overrides
 * InspectKit Fire Inspection PWA
 *
 * This file contains mobile-specific styles and utility classes
 * for touch targets, responsive layouts, and accessibility.
 *
 * NFR31: Touch targets minimum 48x48px
 * FR32: All interactive elements accessible with touch targets of minimum 48px
 *
 * Breakpoints (matching styles.css and industrial.css):
 * - Desktop: min-width 993px
 * - Tablet/Large Mobile: max-width 992px
 * - Tablet Portrait: max-width 768px
 * - Small Mobile: max-width 480px
 */

/* ==========================================================================
   Touch Target Utility Classes
   ========================================================================== */

/**
 * Apply to any interactive element that needs 48px minimum touch target
 */
.touch-target-48 {
    min-height: 48px;
    min-width: 48px;
}

/**
 * Apply for 44px minimum (WCAG AA minimum, use 48px when possible)
 */
.touch-target-min {
    min-height: 44px;
    min-width: 44px;
}

/**
 * Enhanced touch target with padding for inline elements
 */
.touch-enhanced {
    min-height: 48px;
    padding: 12px 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ==========================================================================
   Touch Device Specific Styles
   ========================================================================== */

/**
 * Styles only applied on touch devices (no hover, coarse pointer)
 */
@media (hover: none) and (pointer: coarse) {
    /* Ensure all buttons meet touch target requirements */
    .btn,
    button:not(.mobile-menu-toggle):not(.toggle-password) {
        min-height: 48px;
    }

    /* Form controls need adequate touch targets */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"],
    select,
    textarea {
        min-height: 48px;
    }

    /* Clickable list items and cards */
    .clickable,
    [onclick],
    [role="button"] {
        min-height: 48px;
    }

    /* Remove hover effects that don't work well on touch */
    .btn:hover {
        transform: none;
    }

    /* Add active state feedback instead */
    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
}

/* ==========================================================================
   Responsive Table Utilities
   ========================================================================== */

/**
 * Wrapper for horizontal scrolling tables on mobile
 */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    .table-responsive {
        margin-bottom: 1rem;
        border-radius: 8px;
        border: 1px solid #e2e8f0;
    }

    .table-responsive table {
        margin-bottom: 0;
    }
}

/**
 * Convert table to card layout on mobile
 * Apply .table-cards-mobile to the table element
 */
@media (max-width: 768px) {
    .table-cards-mobile {
        border: none;
    }

    .table-cards-mobile thead {
        display: none;
    }

    .table-cards-mobile tbody tr {
        display: block;
        margin-bottom: 1rem;
        padding: 1rem;
        background: white;
        border-radius: 8px;
        border: 1px solid #e2e8f0;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }

    .table-cards-mobile tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border: none;
        border-bottom: 1px solid #f1f5f9;
    }

    .table-cards-mobile tbody td:last-child {
        border-bottom: none;
    }

    .table-cards-mobile tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #64748b;
        font-size: 0.85rem;
        text-transform: uppercase;
    }
}

/* ==========================================================================
   Spacing Utilities for Touch Target Gaps
   ========================================================================== */

/**
 * Minimum gap between adjacent touch targets (8px recommended)
 */
.touch-gap {
    gap: 8px;
}

.touch-gap-sm {
    gap: 4px;
}

.touch-gap-md {
    gap: 12px;
}

.touch-gap-lg {
    gap: 16px;
}

@media (max-width: 768px) {
    /* Ensure button groups have adequate spacing on mobile */
    .btn-group,
    .button-group,
    .action-buttons {
        gap: 8px;
    }

    /* Stack buttons vertically if needed */
    .btn-group-mobile-stack {
        flex-direction: column;
    }

    .btn-group-mobile-stack .btn {
        width: 100%;
    }
}

/* ==========================================================================
   Mobile Layout Helpers
   ========================================================================== */

@media (max-width: 768px) {
    /* Full-width elements on mobile */
    .mobile-full-width {
        width: 100% !important;
    }

    /* Hide on mobile */
    .mobile-hidden {
        display: none !important;
    }

    /* Stack flex items vertically on mobile */
    .mobile-stack {
        flex-direction: column !important;
    }

    /* Center text on mobile */
    .mobile-text-center {
        text-align: center !important;
    }
}

@media (min-width: 769px) {
    /* Show only on mobile */
    .mobile-only {
        display: none !important;
    }
}

/* ==========================================================================
   Safe Area Handling (iOS notch, home indicator)
   ========================================================================== */

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    /* Add padding for iOS safe areas when needed */
    .safe-area-bottom {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .safe-area-top {
        padding-top: env(safe-area-inset-top);
    }
}

/* ==========================================================================
   Modal Mobile Optimizations
   ========================================================================== */

@media (max-width: 768px) {
    .modal-overlay {
        padding: 0.5rem;
    }

    .modal-container,
    .modal-content {
        max-height: 90vh;
        margin: 0;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem;
    }

    /* Close button touch target */
    .modal-close {
        min-width: 48px;
        min-height: 48px;
    }
}

/* ==========================================================================
   Bottom Navigation Spacing
   ========================================================================== */

@media (max-width: 992px) {
    /* Add bottom padding to main content when mobile nav is visible */
    .container,
    main,
    .content {
        padding-bottom: 80px;
    }
}

/* ==========================================================================
   Form Controls Mobile Optimization
   ========================================================================== */

@media (max-width: 768px) {
    /* Stack form labels above inputs */
    .form-group label {
        display: block;
        margin-bottom: 0.5rem;
    }

    /* Full-width inputs on mobile */
    .form-group input,
    .form-group select,
    .form-group textarea {
        width: 100%;
    }

    /* Adequate spacing between form groups */
    .form-group + .form-group {
        margin-top: 1rem;
    }
}

/* ==========================================================================
   Icon Button Touch Targets
   ========================================================================== */

/**
 * Icon-only buttons need extra padding to meet touch target size
 */
.btn-icon {
    min-width: 48px;
    min-height: 48px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon i,
.btn-icon svg {
    font-size: 1.25rem;
    width: 24px;
    height: 24px;
}

/* ==========================================================================
   Link Touch Targets
   ========================================================================== */

@media (max-width: 768px) {
    /* Navigation links in lists need adequate touch targets */
    nav a,
    .nav-link,
    .menu-link {
        min-height: 48px;
        display: flex;
        align-items: center;
        padding: 0.75rem 1rem;
    }

    /* Inline text links should have adequate padding */
    a.touch-link {
        display: inline-block;
        padding: 8px 4px;
        margin: -8px -4px;
    }
}

/* ==========================================================================
   SSE Connection Status Mobile Styles (Story 7.6)
   ========================================================================== */

/**
 * Mobile-specific styles for SSE connection status indicators
 * These complement the mobile-nav.js connection status display
 */

/* Mobile nav status indicator colors for SSE states */
@media (max-width: 992px) {
    /* SSE Connected - Green */
    .mobile-nav-status .status-indicator.sse-connected,
    .sync-popup .status-indicator.sse-connected {
        background-color: #22c55e;
        box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.3);
    }

    /* SSE Disconnected - Red */
    .mobile-nav-status .status-indicator.sse-disconnected,
    .sync-popup .status-indicator.sse-disconnected {
        background-color: #ef4444;
        box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.3);
    }

    /* SSE Reconnecting - Orange with pulse */
    .mobile-nav-status .status-indicator.sse-reconnecting,
    .sync-popup .status-indicator.sse-reconnecting {
        background-color: #f97316;
        box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.3);
        animation: mobileReconnectingPulse 1s infinite;
    }

    @keyframes mobileReconnectingPulse {
        0%, 100% {
            opacity: 1;
            transform: scale(1);
        }
        50% {
            opacity: 0.6;
            transform: scale(0.95);
        }
    }

    /* Reconnecting label text style */
    .mobile-nav-status .status-label.reconnecting {
        color: #fdba74;
    }
}

/* Connection status touch target for mobile nav */
.mobile-nav-status {
    min-width: 48px;
    min-height: 48px;
}

/* Sync popup connection status section */
.sync-popup-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
}

.sync-popup-status .status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.sync-popup-status-text {
    font-weight: 500;
    color: #1e293b;
}

/* Connection details in popup */
.sync-popup-connection-details {
    background: #f8fafc;
    border-radius: 8px;
    padding: 0.75rem;
    margin-top: 0.5rem;
    font-size: 0.875rem;
}

.sync-popup-connection-details .detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0;
}

.sync-popup-connection-details .detail-label {
    color: #64748b;
}

.sync-popup-connection-details .detail-value {
    color: #1e293b;
    font-weight: 500;
}
