/* =================================================================
   Responsive and Mobile-Friendly Utilities
   ================================================================= */

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    overflow-x: hidden;
}

/* =================================================================
   Form Input Optimizations for Mobile
   ================================================================= */

/* Touch-friendly form inputs */
input,
textarea,
select,
button {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 0.5rem;
    font-size: 16px; /* Prevents iOS zoom */
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="date"],
textarea,
select {
    min-height: 44px; /* iOS accessibility minimum */
    padding: 0.75rem 1rem;
    border: 2px solid #d1d5db;
    background-color: #ffffff;
    transition: all 0.3s ease;
    width: 100%;
    display: block;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Button touch targets */
button,
.btn,
a.button {
    min-height: 44px;
    min-width: 44px;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

/* Prevent double-tap zoom on buttons */
button,
.btn {
    touch-action: manipulation;
}

/* =================================================================
   Responsive Container
   ================================================================= */

.container {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding-left: 1rem;
    padding-right: 1rem;
}

@media (min-width: 640px) {
    .container {
        max-width: 640px;
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
}

@media (min-width: 768px) {
    .container {
        max-width: 768px;
    }
}

@media (min-width: 1024px) {
    .container {
        max-width: 1024px;
    }
}

@media (min-width: 1280px) {
    .container {
        max-width: 1280px;
    }
}

@media (min-width: 1536px) {
    .container {
        max-width: 1536px;
    }
}

/* =================================================================
   Responsive Grid System
   ================================================================= */

.grid {
    display: grid;
    gap: 1rem;
}

.grid-cols-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
}

@media (min-width: 640px) {
    .sm\:grid-cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 768px) {
    .md\:grid-cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .md\:grid-cols-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .lg\:grid-cols-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .lg\:grid-cols-4 {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* =================================================================
   Mobile Navigation
   ================================================================= */

/* Hide mobile menu by default */
.mobile-menu {
    display: none;
}

@media (max-width: 767px) {
    .mobile-menu {
        display: block;
    }

    .desktop-menu {
        display: none;
    }

    /* Mobile menu toggle */
    .mobile-menu-button {
        display: block;
        padding: 0.5rem;
        cursor: pointer;
    }
}

/* Hamburger menu */
.hamburger {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 24px;
    height: 24px;
}

.hamburger span {
    display: block;
    height: 3px;
    width: 100%;
    background-color: currentColor;
    border-radius: 2px;
    transition: all 0.3s ease;
}

/* =================================================================
   Responsive Tables
   ================================================================= */

@media (max-width: 767px) {
    .responsive-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .responsive-table table {
        min-width: 100%;
    }
}

/* Card-based table on mobile */
@media (max-width: 639px) {
    .table-card-mobile table {
        border: 0;
    }

    .table-card-mobile thead {
        display: none;
    }

    .table-card-mobile tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #e5e7eb;
        border-radius: 0.5rem;
        padding: 1rem;
        background: white;
    }

    .table-card-mobile td {
        display: block;
        text-align: right;
        padding: 0.5rem 0;
        border-bottom: 1px solid #f3f4f6;
    }

    .table-card-mobile td:last-child {
        border-bottom: 0;
    }

    .table-card-mobile td:before {
        content: attr(data-label);
        font-weight: bold;
        display: block;
        margin-bottom: 0.25rem;
        color: #6b7280;
        font-size: 0.875rem;
    }
}

/* =================================================================
   Image Optimizations
   ================================================================= */

img {
    max-width: 100%;
    height: auto;
    display: block;
}

.img-responsive {
    width: 100%;
    height: auto;
}

/* =================================================================
   Utility Classes
   ================================================================= */

/* Text responsiveness */
@media (max-width: 640px) {
    .text-responsive-lg {
        font-size: 1.25rem; /* 20px */
    }

    .text-responsive-xl {
        font-size: 1.5rem; /* 24px */
    }

    .text-responsive-2xl {
        font-size: 1.75rem; /* 28px */
    }
}

/* Spacing utilities */
.p-safe {
    padding: 1rem;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

/* Hide/Show on mobile */
@media (max-width: 767px) {
    .hide-mobile {
        display: none !important;
    }
}

@media (min-width: 768px) {
    .show-mobile-only {
        display: none !important;
    }
}

/* =================================================================
   Touch Gestures
   ================================================================= */

.swipeable {
    touch-action: pan-y pinch-zoom;
}

.no-touch-action {
    touch-action: none;
}

/* =================================================================
   Loading States
   ================================================================= */

.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* =================================================================
   Accessibility Improvements
   ================================================================= */

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Skip to main content link */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: #667eea;
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-to-main:focus {
    top: 0;
}

/* 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;
}

/* =================================================================
   Performance Optimizations
   ================================================================= */

/* GPU acceleration for animations */
.gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
}

/* Reduce motion for accessibility */
@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;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .auto-dark-mode {
        background-color: #1a202c;
        color: #e2e8f0;
    }

    .auto-dark-mode input,
    .auto-dark-mode textarea,
    .auto-dark-mode select {
        background-color: #2d3748;
        color: #e2e8f0;
        border-color: #4a5568;
    }
}

/* =================================================================
   Work Order Page Specific Responsive Styles
   ================================================================= */

/* Mobile Navigation */
@media (max-width: 767px) {
    /* Show mobile menu button */
    .mobile-nav-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 0.5rem;
        cursor: pointer;
    }

    /* Hide desktop navigation items */
    nav .hidden.md\:block {
        display: none !important;
    }

    /* Mobile menu overlay */
    .mobile-menu-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9998;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .mobile-menu-overlay.active {
        display: block;
        opacity: 1;
    }

    /* Mobile slide-out menu */
    .mobile-nav-menu {
        position: fixed;
        top: 0;
        right: -100%;
        width: 85%;
        max-width: 320px;
        height: 100vh;
        background: white;
        z-index: 9999;
        transition: right 0.3s ease;
        overflow-y: auto;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    }

    .mobile-nav-menu.active {
        right: 0;
    }

    .mobile-nav-menu-header {
        background: #4f46e5;
        color: white;
        padding: 1rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .mobile-nav-menu a {
        display: block;
        padding: 1rem;
        color: #374151;
        border-bottom: 1px solid #e5e7eb;
        text-decoration: none;
        transition: background 0.2s ease;
    }

    .mobile-nav-menu a:hover {
        background: #f3f4f6;
    }

    .mobile-nav-menu a i {
        width: 24px;
        margin-left: 0.5rem;
    }
}

/* Page Header Responsive */
@media (max-width: 767px) {
    header .mx-auto {
        padding: 1rem !important;
    }

    header h1 {
        font-size: 1.25rem !important;
    }

    header p {
        font-size: 0.75rem !important;
    }

    header .flex {
        flex-direction: column;
        gap: 0.75rem;
    }

    header a {
        font-size: 0.875rem;
        padding: 0.5rem 1rem;
    }
}

/* Main Content Responsive */
@media (max-width: 1023px) {
    main.mx-auto {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    /* Stack grid columns */
    .lg\:grid-cols-3 {
        grid-template-columns: 1fr !important;
    }

    .lg\:col-span-2 {
        grid-column: span 1 !important;
    }

    /* Hide workflow indicator on tablet/mobile */
    .workflow-indicator {
        display: none !important;
    }
}

/* Form Section Responsive */
@media (max-width: 767px) {
    /* Card padding */
    .bg-white.shadow.rounded-lg {
        padding: 1rem !important;
    }

    /* Form grid - single column on mobile */
    .grid.grid-cols-1.md\:grid-cols-2,
    .grid.grid-cols-2 {
        grid-template-columns: 1fr !important;
    }

    .grid.grid-cols-1.md\:grid-cols-3,
    .grid.grid-cols-3 {
        grid-template-columns: 1fr !important;
    }

    .grid.grid-cols-1.md\:grid-cols-4,
    .grid.md\:grid-cols-4 {
        grid-template-columns: 1fr !important;
    }

    /* Form labels */
    label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
    }

    /* Form inputs - full width */
    input[type="text"],
    input[type="number"],
    input[type="date"],
    textarea,
    select {
        width: 100% !important;
        font-size: 16px !important; /* Prevents iOS zoom */
        padding: 0.75rem !important;
    }

    /* Radio buttons grid */
    .grid.grid-cols-2.md\:grid-cols-3,
    .grid.grid-cols-3 {
        grid-template-columns: 1fr !important;
        gap: 0.5rem !important;
    }

    /* Radio button labels */
    label.inline-flex.items-center {
        padding: 0.75rem !important;
    }

    /* Section titles */
    h3.text-lg {
        font-size: 1rem !important;
    }

    /* Section padding */
    .p-6 {
        padding: 1rem !important;
    }
}

/* Search Form Responsive */
@media (max-width: 767px) {
    /* Search form - stack vertically */
    form.flex.gap-3 {
        flex-direction: column !important;
    }

    form.flex.gap-3 input {
        width: 100% !important;
    }

    form.flex.gap-3 button,
    form.flex.gap-3 a {
        width: 100% !important;
        text-align: center;
        justify-content: center;
    }
}

/* Table Responsive */
@media (max-width: 767px) {
    /* Hide table on mobile, show card view */
    .overflow-x-auto table {
        display: none;
    }

    /* Mobile card view for table data */
    .mobile-card-view {
        display: block !important;
    }

    .mobile-card-item {
        background: white;
        border: 1px solid #e5e7eb;
        border-radius: 0.5rem;
        padding: 1rem;
        margin-bottom: 1rem;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }

    .mobile-card-item .card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 0.75rem;
        border-bottom: 1px solid #e5e7eb;
        margin-bottom: 0.75rem;
    }

    .mobile-card-item .card-row {
        display: flex;
        justify-content: space-between;
        padding: 0.375rem 0;
        font-size: 0.875rem;
    }

    .mobile-card-item .card-label {
        color: #6b7280;
        font-weight: 500;
    }

    .mobile-card-item .card-value {
        color: #111827;
    }

    .mobile-card-item .card-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-top: 0.75rem;
        padding-top: 0.75rem;
        border-top: 1px solid #e5e7eb;
    }

    .mobile-card-item .card-actions a {
        flex: 1;
        min-width: calc(50% - 0.25rem);
        text-align: center;
        padding: 0.5rem;
        font-size: 0.75rem;
    }
}

@media (min-width: 768px) {
    .mobile-card-view {
        display: none !important;
    }
}

/* Action Buttons Responsive */
@media (max-width: 767px) {
    /* Action buttons - stack vertically */
    .flex.justify-center.gap-2,
    .flex.gap-2 {
        flex-direction: column;
        gap: 0.5rem !important;
    }

    .flex.justify-center.gap-2 a,
    .flex.gap-2 a,
    .flex.gap-2 button {
        width: 100% !important;
        text-align: center;
        justify-content: center;
    }

    /* Submit buttons at bottom */
    .flex.justify-between {
        flex-direction: column;
        gap: 0.75rem;
    }

    .flex.justify-between button,
    .flex.justify-between a {
        width: 100%;
    }
}

/* Attachments Section Responsive */
@media (max-width: 767px) {
    .attachment-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .attachment-item a {
        width: 100%;
        text-align: center;
    }
}

/* Workflow History Timeline Responsive */
@media (max-width: 767px) {
    .timeline-item {
        padding-left: 1.5rem;
    }

    .timeline-dot {
        width: 0.75rem;
        height: 0.75rem;
    }

    .timeline-item .text-sm {
        font-size: 0.75rem;
    }
}

/* Status Badge Responsive */
@media (max-width: 767px) {
    .status-badge {
        font-size: 0.625rem;
        padding: 0.25rem 0.5rem;
    }
}

/* Sidebar Info Card Responsive */
@media (max-width: 1023px) {
    /* Show sidebar content inline */
    .lg\:col-span-1 {
        margin-top: 1.5rem;
    }
}

/* File Input Responsive */
@media (max-width: 767px) {
    input[type="file"] {
        font-size: 0.875rem;
    }

    .file\:mr-4 {
        margin-right: 0.5rem;
    }

    .file\:px-4 {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

/* Print Styles */
@media print {
    .workflow-indicator,
    nav,
    .mobile-nav-toggle,
    button[type="submit"],
    .action-buttons {
        display: none !important;
    }

    main {
        padding: 0 !important;
    }

    .bg-white.shadow {
        box-shadow: none !important;
        border: 1px solid #e5e7eb;
    }
}

/* Landscape Mode Optimizations */
@media (max-width: 767px) and (orientation: landscape) {
    header h1 {
        font-size: 1rem !important;
    }

    .workflow-indicator {
        display: none !important;
    }
}

/* Very Small Screens (< 360px) */
@media (max-width: 359px) {
    body {
        font-size: 14px;
    }

    header h1 {
        font-size: 1rem !important;
    }

    .p-6, .p-4 {
        padding: 0.75rem !important;
    }

    button, .btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
}
