/*
 * Mobile and iPad Responsive Styles
 * Property Management System
 *
 * This CSS file provides comprehensive mobile and tablet responsive styles
 * that can be included across all templates for consistent mobile experience.
 */

/* ==========================================================================
   Base Mobile Styles
   ========================================================================== */

/* Ensure proper viewport behavior */
* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

img,
svg,
video,
canvas {
    max-width: 100%;
    height: auto;
}

iframe {
    max-width: 100%;
}

/* ==========================================================================
   Touch-Friendly Interactive Elements
   ========================================================================== */

/* Minimum touch target size for mobile devices */
.btn, .button, .action-btn, .tab-btn, input[type="submit"], input[type="button"], button {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Larger touch targets for small screens */
.subcontractor-statement-subcontractor-col {
    width: 9rem;
    max-width: 9rem;
    white-space: normal;
    overflow-wrap: anywhere;
}

@media (max-width: 768px) {
    .btn, .button, .action-btn, .tab-btn, input[type="submit"], input[type="button"], button {
        min-height: 44px;
        padding: 10px 14px;
        font-size: 14px;
        line-height: 1.2;
    }

    /* Keep subcontractor statement action buttons compact on mobile. */
    .subcontractor-statement-actions .btn.btn-sm {
        min-height: 34px;
        min-width: 34px;
        padding: 6px 10px;
        font-size: 12px;
        line-height: 1.1;
    }

    .subcontractor-statement-period {
        display: inline-flex;
        flex-direction: column;
        align-items: flex-start;
        line-height: 1.15;
    }

    .subcontractor-statement-period-separator {
        display: none;
    }

    .subcontractor-statement-subcontractor-col {
        width: 7rem;
        max-width: 7rem;
    }
}

/* Form inputs touch-friendly sizing */
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="tel"], input[type="url"], input[type="search"], textarea, select {
    min-height: 44px;
    padding: 12px;
    font-size: 16px; /* Prevents zoom on iOS */
    border-radius: 8px;
    border: 1px solid #ddd;
    width: 100%;
}

@media (max-width: 768px) {
    input[type="text"], input[type="email"], input[type="password"], input[type="number"],
    input[type="tel"], input[type="url"], input[type="search"], textarea, select {
        min-height: 48px;
        padding: 14px;
        font-size: 16px;
    }
}

/* ==========================================================================
   Responsive Tables
   ========================================================================== */

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

@media (max-width: 768px) {
    .table-responsive {
        margin: 0 -10px;
        border-radius: 0;
    }

    .table-responsive table {
        min-width: 600px;
    }

    .table {
        min-width: 600px;
        font-size: 14px;
    }

    .table th, .table td {
        padding: 8px 6px;
        white-space: nowrap;
    }

    .table th {
        font-size: 12px;
        font-weight: 600;
    }
}

@media (max-width: 480px) {
    .table {
        font-size: 12px;
    }

    .table th, .table td {
        padding: 6px 4px;
    }

    .table th {
        font-size: 11px;
    }
}

/* ==========================================================================
   Mobile Navigation
   ========================================================================== */

.mobile-nav-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    color: #333;
}

@media (max-width: 768px) {
    .mobile-nav-toggle {
        display: block;
    }

    .nav-menu {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: white;
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        z-index: 1000;
    }

    .nav-menu.active {
        display: block;
    }

    .nav-menu a {
        display: block;
        padding: 16px 20px;
        border-bottom: 1px solid #eee;
        color: #333;
        text-decoration: none;
        font-size: 16px;
    }

    .nav-menu a:hover {
        background: #f8f9fa;
    }
}

/* ==========================================================================
   Mobile Cards and Containers
   ========================================================================== */

.card, .dashboard-container, .content-container {
    margin: 0 auto;
    padding: 20px;
}

@media (max-width: 768px) {
    .card, .dashboard-container, .content-container {
        padding: 15px;
        margin: 10px;
        border-radius: 8px;
    }
}

@media (max-width: 480px) {
    .card, .dashboard-container, .content-container {
        padding: 10px;
        margin: 5px;
        border-radius: 4px;
    }
}

/* ==========================================================================
   Mobile Grid Systems
   ========================================================================== */

.grid, .stats-container, .form-grid {
    display: grid;
    gap: 20px;
}

@media (max-width: 768px) {
    .grid, .stats-container, .form-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
}

@media (max-width: 480px) {
    .grid, .stats-container, .form-grid {
        gap: 10px;
    }
}

/* Two-column grid for tablets */
@media (min-width: 481px) and (max-width: 768px) {
    .grid-tablet-2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ==========================================================================
   Mobile Typography
   ========================================================================== */

h1, .h1 {
    font-size: 2.5rem;
    line-height: 1.2;
}

h2, .h2 {
    font-size: 2rem;
    line-height: 1.3;
}

h3, .h3 {
    font-size: 1.5rem;
    line-height: 1.4;
}

@media (max-width: 768px) {
    h1, .h1 {
        font-size: 1.75rem;
    }

    h2, .h2 {
        font-size: 1.35rem;
    }

    h3, .h3 {
        font-size: 1.15rem;
    }

    h4, .h4 {
        font-size: 1rem;
    }

    h5, .h5,
    h6, .h6 {
        font-size: 0.9rem;
    }

    .form-label,
    label,
    legend {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    h1, .h1 {
        font-size: 1.5rem;
    }

    h2, .h2 {
        font-size: 1.25rem;
    }

    h3, .h3 {
        font-size: 1.1rem;
    }

    h4, .h4 {
        font-size: 0.95rem;
    }

    h5, .h5,
    h6, .h6 {
        font-size: 0.85rem;
    }
}

/* ==========================================================================
   Mobile Modals and Overlays
   ========================================================================== */

.modal {
    padding: 20px;
    box-sizing: border-box;
}

.modal-content {
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 12px;
}

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

    .modal-content {
        width: 95%;
        margin: 5% auto;
        border-radius: 8px;
    }
}

@media (max-width: 480px) {
    .modal {
        padding: 0;
    }

    .modal-content {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
        overflow-y: auto;
    }
}

/* ==========================================================================
   Mobile Forms
   ========================================================================== */

.form-row {
    display: grid;
    gap: 15px;
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr;
        gap: 10px;
        margin-bottom: 15px;
    }
}

.form-group {
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .form-group {
        margin-bottom: 15px;
    }
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
}

/* ==========================================================================
   Mobile Utilities
   ========================================================================== */

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

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

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

    .show-mobile-inline {
        display: inline;
    }

    .show-mobile-flex {
        display: flex;
    }
}

/* Text alignment utilities */
@media (max-width: 768px) {
    .text-center-mobile {
        text-align: center;
    }

    .text-left-mobile {
        text-align: left;
    }
}

/* Spacing utilities */
@media (max-width: 768px) {
    .p-mobile-0 { padding: 0 !important; }
    .p-mobile-1 { padding: 8px !important; }
    .p-mobile-2 { padding: 16px !important; }
    .p-mobile-3 { padding: 24px !important; }

    .m-mobile-0 { margin: 0 !important; }
    .m-mobile-1 { margin: 8px !important; }
    .m-mobile-2 { margin: 16px !important; }
    .m-mobile-3 { margin: 24px !important; }
}

/* ==========================================================================
   Mobile-Specific Components
   ========================================================================== */

/* Mobile-friendly pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 20px 0;
}

@media (max-width: 768px) {
    .pagination {
        gap: 4px;
        margin: 15px 0;
    }

    .pagination a, .pagination span {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 8px;
        font-size: 14px;
    }
}

/* Mobile-friendly badges and status indicators */
.badge, .status-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .badge, .status-badge {
        padding: 8px 14px;
        font-size: 11px;
    }
}

/* Mobile-friendly action button groups */
.action-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    .action-group {
        gap: 4px;
    }

    .action-group .action-btn {
        flex: 1;
        min-width: 0;
    }
}

@media (max-width: 480px) {
    .action-group {
        flex-direction: column;
    }

    .action-group .action-btn {
        width: 100%;
    }
}

/* ==========================================================================
   iPad Specific Styles
   ========================================================================== */

@media (min-width: 768px) and (max-width: 1024px) {
    /* iPad portrait and landscape */
    .container {
        max-width: 90%;
    }

    .grid-ipad-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-ipad-3 {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Larger touch targets for iPad */
    .btn, .button, .action-btn {
        min-height: 48px;
        padding: 12px 20px;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .no-print {
        display: none !important;
    }

    .table {
        font-size: 12px;
    }

    .action-btn, .btn {
        display: none;
    }

    .modal {
        display: none;
    }
}

/* ==========================================================================
   Accessibility Improvements
   ========================================================================== */

/* Focus styles for keyboard navigation */
.btn:focus, .action-btn:focus, input:focus, select:focus, textarea:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn, .action-btn {
        border: 2px solid currentColor;
    }
}

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

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .modal-content {
        background-color: #2d3748;
        color: #e2e8f0;
    }

    .table th {
        background-color: #4a5568;
        color: #e2e8f0;
    }
}

@media (max-width: 768px) {
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .nav-tabs .nav-link {
        white-space: nowrap;
        flex-shrink: 0;
    }

    .pagination {
        flex-wrap: wrap;
    }

    .btn-group {
        flex-wrap: wrap;
    }

    .modal-dialog {
        margin: 0;
        max-width: 100%;
        width: 100%;
    }

    .modal-content {
        border-radius: 0;
    }
}

@media (max-width: 576px) {
    .modal-dialog {
        height: 100%;
    }

    .modal-content {
        min-height: 100vh;
    }

    .modal-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}
