html, body, #app {
    height: 100%;
}

#app {
    min-height: 100%;
}

.main-content {
    /* Responsive main content */
}

.footer {
    margin-top: -12px;
}


/* Mobile-first responsive design */
* {
    -webkit-tap-highlight-color: transparent;
}

body {
    -webkit-touch-callout: none;
    overscroll-behavior-x: none; /* Only prevent horizontal overscroll */
    overscroll-behavior-y: auto; /* Allow vertical overscroll for pull-to-refresh */
}

/* Allow text selection for content areas */
.main-content,
.content,
p, span, div:not(.no-select),
input, textarea, select {
    -webkit-user-select: text;
    -khtml-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Prevent text selection only for UI elements */
button, .btn, nav, .sidebar, .no-select {
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Safe area handling for Capacitor apps */
.safe-area-top {
    padding-top: env(safe-area-inset-top);
}

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

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

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

/* Touch-friendly interactions */
.touch-manipulation {
    touch-action: manipulation;
}

/* Canvas styles */
.canvas-disable {
    cursor: not-allowed;
    pointer-events: none;
    opacity: 0.5;
}

canvas.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Mobile navigation - Enhanced for latest Samsung & Apple devices */
@media screen and (max-width: 1279px) {
    /* Show hamburger button on all mobile/tablet devices */
    #sidebar-toggle {
        display: flex !important;
        min-height: 44px !important;
        min-width: 44px !important;
        -webkit-tap-highlight-color: transparent;
    }

    /* Force sidebar to be hidden by default on mobile/tablet */
    #logo-sidebar.-translate-x-full {
        transform: translateX(-100%) !important;
        -webkit-transform: translateX(-100%) !important;
        -moz-transform: translateX(-100%) !important;
        -ms-transform: translateX(-100%) !important;
        will-change: transform;
    }

    /* Force sidebar to be visible when translate-x-0 is applied */
    #logo-sidebar.translate-x-0 {
        transform: translateX(0) !important;
        -webkit-transform: translateX(0) !important;
        -moz-transform: translateX(0) !important;
        -ms-transform: translateX(0) !important;
        will-change: transform;
    }

    .main-content {
        padding-left: 0 !important;
        margin-left: 0 !important;
    }
}

/* Ensure desktop behavior works only on large screens */
@media screen and (min-width: 1280px) {
    #sidebar-toggle {
        display: none !important;
    }

    #logo-sidebar {
        transform: translateX(0) !important;
        -webkit-transform: translateX(0) !important;
        -moz-transform: translateX(0) !important;
        -ms-transform: translateX(0) !important;
    }
}

/* Additional support for specific device ranges */
@media screen and (min-width: 768px) and (max-width: 1279px) {
    /* Large phones and tablets */
    #logo-sidebar.-translate-x-full {
        transform: translate3d(-100%, 0, 0) !important;
        -webkit-transform: translate3d(-100%, 0, 0) !important;
    }

    #logo-sidebar.translate-x-0 {
        transform: translate3d(0, 0, 0) !important;
        -webkit-transform: translate3d(0, 0, 0) !important;
    }
}

/* Mobile landscape optimizations */
@media (max-width: 1024px) and (orientation: landscape) {
    #sidebar-toggle {
        display: block !important;
        position: fixed;
        top: 1rem;
        left: 1rem;
        z-index: 50;
        background: rgba(255, 255, 255, 0.9);
        backdrop-filter: blur(10px);
        border-radius: 0.5rem;
        padding: 0.5rem;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    }

    .main-content {
        padding-top: 4rem;
    }
}

/* Mobile portrait optimizations */
@media (max-width: 768px) and (orientation: portrait) {
    .main-content {
        padding-left: 0 !important;
        margin-left: 0 !important;
    }

    #logo-sidebar {
        transform: translateX(-100%);
    }
}

/* Touch feedback for buttons */
button:active,
.btn:active,
[role="button"]:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
}

/* Improved scrolling on mobile */
.scroll-container {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
}

/* Mobile-friendly form elements */
input, textarea, select {
    font-size: 16px; /* Prevents zoom on iOS */
}

/* Mobile data tables */
@media (max-width: 768px) {
    .dataTables_wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table.dataTable {
        font-size: 0.875rem;
    }

    .dataTables_length,
    .dataTables_filter,
    .dataTables_info,
    .dataTables_paginate {
        margin-bottom: 1rem;
    }

    .dataTables_filter input {
        width: 100% !important;
        margin-left: 0 !important;
    }
}

/* Mobile signature pad */
@media (max-width: 768px) {
    canvas {
        max-width: 100%;
        height: auto;
        touch-action: none;
    }

    .signature-pad {
        width: 100%;
        height: 200px;
        border: 1px solid #ccc;
        border-radius: 8px;
    }
}

/* Prevent horizontal scroll on mobile */
html, body {
    overflow-x: hidden;
    width: 100%;
}

/* Ensure proper bottom spacing for mobile devices */
@media screen and (max-width: 768px) {
    .main-content {
        padding-bottom: max(3rem, env(safe-area-inset-bottom, 3rem)) !important;
    }

    /* Add extra bottom padding to container */
    .container.mx-auto {
        padding-bottom: max(2rem, env(safe-area-inset-bottom, 2rem));
    }

    /* Ensure grid has proper bottom spacing */
    .grid.grid-cols-1 {
        margin-bottom: max(2rem, env(safe-area-inset-bottom, 2rem));
    }

    /* Fix for dashboard specific containers */
    .container.mx-auto.max-w-screen-xl {
        padding-bottom: max(3rem, env(safe-area-inset-bottom, 3rem)) !important;
    }
}

/* Mobile-friendly dropdowns */
@media (max-width: 768px) {
    .dropdown-menu {
        position: fixed !important;
        top: auto !important;
        bottom: env(safe-area-inset-bottom, 1rem) !important;
        left: 1rem !important;
        right: 1rem !important;
        transform: none !important;
        max-height: 50vh;
        overflow-y: auto;
        border-radius: 1rem;
        box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    }
}


/* Mobile schedule optimizations */
@media (max-width: 768px) {
    .time-card {
        min-height: 44px; /* iOS minimum touch target */
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    .add-time-container button {
        min-height: 44px;
        font-size: 14px;
    }
}

/* Mobile workorder cards */
@media (max-width: 768px) {
    .workorder-card {
        margin-bottom: 1rem;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .workorder-card .card-header {
        padding: 1rem;
        border-bottom: 1px solid #e5e7eb;
    }

    .workorder-card .card-content {
        padding: 1rem;
    }

    .workorder-card .card-footer {
        padding: 1rem;
        background-color: #f9fafb;
        border-top: 1px solid #e5e7eb;
    }
}


/* Mobile timesheet table improvements */
@media (max-width: 768px) {
    .timesheet-card {
        border-radius: 12px;
        box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
        margin-bottom: 1rem;
        overflow: hidden;
    }

    .timesheet-card-header {
        background-color: #f8fafc;
        padding: 1rem;
        border-bottom: 1px solid #e2e8f0;
    }

    .timesheet-card-content {
        padding: 1rem;
    }

    .timesheet-card-footer {
        padding: 1rem;
        background-color: #f1f5f9;
        border-top: 1px solid #e2e8f0;
    }

    /* Ensure buttons are touch-friendly */
    .edit-time-btn,
    .delete-btn {
        min-height: 44px !important;
        min-width: 44px !important;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    /* Fix for correction input fields */
    .correction-input {
        min-height: 44px;
        font-size: 16px;
        border-radius: 8px;
        border: 1px solid #d1d5db;
        padding: 0.75rem;
    }

    .correction-input:focus {
        outline: none;
        border-color: #3b82f6;
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }
}

/* Fix for mobile navigation spacing */
@media (max-width: 768px) {
    main.pt-16 {
        padding-top: max(4rem, env(safe-area-inset-top, 4rem)) !important;
    }

    /* Ensure proper spacing for content */
    .max-w-7xl.mx-auto {
        padding-left: 1rem;
        padding-right: 1rem;
        padding-bottom: max(2rem, env(safe-area-inset-bottom, 2rem));
    }

    /* Fix for stats cards on mobile */
    .grid.grid-cols-1.sm\\:grid-cols-4 {
        gap: 1rem;
        margin-bottom: 1.5rem;
    }

    /* Ensure proper button spacing */
    .flex.space-x-2 > * + * {
        margin-left: 0.5rem;
    }

    .flex.space-x-3 > * + * {
        margin-left: 0.75rem;
    }
}

/* Enhanced touch feedback */
@media (max-width: 768px) {
    button:active,
    .btn:active,
    [role="button"]:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }

    /* Prevent double-tap zoom on buttons */
    button,
    .btn,
    [role="button"] {
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
}

/* Loading spinner optimizations */
.spinner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.spinner {
    border: 6px solid #f3f3f3;
    border-top: 6px solid #094B87;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@media (min-width: 768px) {
    .spinner {
        border-width: 8px;
        width: 60px;
        height: 60px;
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Notification positioning for mobile */
.notify {
    z-index: 1000000;
    position: fixed;
    top: env(safe-area-inset-top, 1rem);
    left: 1rem;
    right: 1rem;
}

/* Mobile-specific utility classes */
@media (max-width: 768px) {
    .mobile-hidden {
        display: none !important;
    }

    .mobile-full-width {
        width: 100% !important;
    }

    .mobile-text-center {
        text-align: center !important;
    }

    .mobile-p-4 {
        padding: 1rem !important;
    }

    .mobile-mb-4 {
        margin-bottom: 1rem !important;
    }
}

/* Tablet optimizations */
@media (min-width: 768px) and (max-width: 1024px) {
    .tablet-grid-2 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .tablet-text-base {
        font-size: 1rem !important;
    }
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .high-dpi-border {
        border-width: 0.5px;
    }
}

/* Dark mode support for mobile apps */
@media (prefers-color-scheme: dark) {
    .auto-dark {
        background-color: #1f2937;
        color: #f9fafb;
    }

    .auto-dark-border {
        border-color: #374151;
    }
}

/* Latest Samsung Galaxy optimizations */
/* Galaxy S24 Ultra (412x915) */
@media screen and (max-width: 412px) and (min-height: 915px) and (min-resolution: 3dppx) {
    #sidebar-toggle {
        top: max(1rem, env(safe-area-inset-top, 1rem));
        left: max(1rem, env(safe-area-inset-left, 1rem));
    }

    #signatureModal .relative.bg-white {
        max-height: calc(100vh - 2rem);
    }
}

/* Galaxy S24+ (384x854) */
@media screen and (max-width: 384px) and (min-height: 854px) and (min-resolution: 3dppx) {
    .signature-pad canvas {
        height: 120px !important;
    }

    #sidebar-toggle {
        width: 48px;
        height: 48px;
    }
}

/* Galaxy S24 (360x780) */
@media screen and (max-width: 360px) and (min-height: 780px) and (min-resolution: 3dppx) {
    .signature-pad canvas {
        height: 110px !important;
    }

    #signatureModal .text-sm {
        font-size: 0.8rem;
    }

    #sidebar-toggle {
        width: 44px;
        height: 44px;
    }
}

/* Galaxy S23 Ultra (412x892) */
@media screen and (max-width: 412px) and (min-height: 892px) and (max-height: 915px) and (min-resolution: 3dppx) {
    #logo-sidebar {
        width: 280px;
    }
}

/* Galaxy S22 Ultra (412x869) */
@media screen and (max-width: 412px) and (min-height: 869px) and (max-height: 892px) and (min-resolution: 3dppx) {
    #signatureModal .space-y-4 {
        gap: 0.75rem;
    }
}

/* Latest iPhone optimizations */
/* iPhone 15 Pro Max (430x932) */
@media screen and (max-width: 430px) and (min-height: 932px) and (-webkit-min-device-pixel-ratio: 3) {
    #sidebar-toggle {
        top: max(1.5rem, env(safe-area-inset-top, 1.5rem));
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    #signatureModal {
        padding: 0.5rem;
    }
}

/* iPhone 15 Pro (393x852) */
@media screen and (max-width: 393px) and (min-height: 852px) and (-webkit-min-device-pixel-ratio: 3) {
    .signature-pad canvas {
        height: 120px !important;
    }

    #logo-sidebar {
        width: 300px;
    }
}

/* iPhone 15 (390x844) */
@media screen and (max-width: 390px) and (min-height: 844px) and (-webkit-min-device-pixel-ratio: 3) {
    .signature-pad canvas {
        height: 120px !important;
    }

    #sidebar-toggle {
        border-radius: 12px;
    }
}

/* iPhone 14 Pro Max (430x932) */
@media screen and (max-width: 430px) and (min-height: 932px) and (max-height: 932px) and (-webkit-min-device-pixel-ratio: 3) {
    #signatureModal .relative.bg-white {
        border-radius: 1.5rem;
        max-height: calc(100vh - 1rem);
    }
}

/* iPhone 14 Pro (393x852) */
@media screen and (max-width: 393px) and (min-height: 852px) and (max-height: 852px) and (-webkit-min-device-pixel-ratio: 3) {
    #sidebar-toggle {
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    }
}

/* Cache busting and performance optimizations */
@media screen and (max-width: 768px) {
    /* Force hardware acceleration */
    #sidebar-toggle,
    #logo-sidebar,
    #signatureModal,
    .signature-pad canvas {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        will-change: transform;
    }

    /* Prevent iOS zoom on form inputs */
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px !important;
        -webkit-appearance: none;
        border-radius: 8px;
    }

    /* Enhanced touch targets */
    button,
    .btn,
    a,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
        touch-action: manipulation;
    }

    /* Smooth scrolling for mobile */
    * {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}

/* Dynamic viewport height for mobile browsers */
:root {
    --vh: 1vh;
}

@media screen and (max-width: 768px) {
    .min-h-screen {
        min-height: calc(var(--vh, 1vh) * 100);
    }

    .h-screen {
        height: calc(var(--vh, 1vh) * 100);
    }
}

/* Accessibility improvements for mobile */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Enhanced focus styles for keyboard navigation */
button:focus,
input:focus,
select:focus,
textarea:focus,
a:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* Mobile-specific print styles */
@media print {
    .no-print {
        display: none !important;
    }

    body {
        font-size: 12pt;
        line-height: 1.4;
    }

    .print-break {
        page-break-before: always;
    }
}
