/*
 * Mobile-First Common Utilities
 * Shared responsive styles for BetterRoofing platform
 */

/* Touch-Friendly Tap Targets */
.touch-target {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Prevent iOS Zoom on Input Focus */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="password"],
input[type="date"],
input[type="time"],
select,
textarea {
    font-size: 16px !important; /* Prevents iOS zoom */
}

/* Smooth Scrolling for Touch Devices */
.scroll-container {
    overflow-x: auto;
    overflow-y: hidden;
    -ms-overflow-style: none;
}

.scroll-container::-webkit-scrollbar {
    display: none;
}

/* Mobile-Optimized Spacing */
@media (max-width: 768px) {
    .mobile-stack {
        flex-direction: column !important;
        gap: 12px !important;
    }

    .mobile-2-columns {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

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

    .mobile-padding {
        padding: 16px !important;
    }

    .mobile-margin {
        margin: 16px 0 !important;
    }

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

    .mobile-hide {
        display: none !important;
    }

    .mobile-show {
        display: block !important;
    }
}

/* Common Mobile Button Styles */
@media (max-width: 768px) {
    button,
    .btn,
    a.btn {
        min-height: 44px;
        padding: 12px 16px;
        font-size: 15px;
        -webkit-tap-highlight-color: var(--input-focus-ring);
    }

    button:active,
    .btn:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
}

/* Stack Form Groups on Mobile */
@media (max-width: 768px) {
    .form-row,
    .button-group {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .form-row > *,
    .button-group > * {
        width: 100%;
    }
}

/* Mobile-Friendly Modals */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 10px;
    }

    .modal-content {
        max-width: calc(100vw - 20px);
        max-height: calc(100vh - 20px);
        margin: 0;
    }

    .modal-header {
        padding: 16px;
        border-bottom: 1px solid var(--border-light);
    }

    .modal-body {
        padding: 16px;
        overflow-y: auto;
    }

    .modal-footer {
        padding: 12px 16px;
        border-top: 1px solid var(--border-light);
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .modal-footer button {
        width: 100%;
    }
}

/* Mobile Table to Cards */
@media (max-width: 768px) {
    table.mobile-cards {
        display: block;
        width: 100%;
    }

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

    table.mobile-cards tbody {
        display: block;
    }

    table.mobile-cards tr {
        display: block;
        background: var(--bg-secondary);
        margin-bottom: 12px;
        border: 1px solid var(--border-light);
        border-radius: 8px;
        padding: 16px;
    }

    table.mobile-cards td {
        display: block;
        padding: 4px 0;
        border: none;
    }

    table.mobile-cards td:before {
        content: attr(data-label);
        display: block;
        font-weight: 600;
        color: var(--text-tertiary);
        font-size: 11px;
        text-transform: uppercase;
        margin-bottom: 4px;
    }

    .mobile-card-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .mobile-card-actions > .btn,
    .mobile-card-actions > button {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .mobile-card-actions {
        grid-template-columns: 1fr;
    }
}

/* Horizontal Scrollable Tabs */
@media (max-width: 768px) {
    .tabs-container {
        overflow-x: auto;
        overflow-y: hidden;
        -ms-overflow-style: none;
        white-space: nowrap;
    }

    .tabs-container::-webkit-scrollbar {
        display: none;
    }

    .tab {
        display: inline-block;
        white-space: nowrap;
    }
}

/* Better Touch Feedback */
a,
button,
.clickable {
    -webkit-tap-highlight-color: var(--input-focus-ring);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Accessible Touch Targets for Checkboxes/Radio */
@media (max-width: 768px) {
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 24px;
        min-height: 24px;
        width: 24px;
        height: 24px;
    }

    label {
        cursor: pointer;
        min-height: 44px;
        display: flex;
        align-items: center;
        gap: 8px;
    }
}

/* Mobile Navigation Helpers */
@media (max-width: 768px) {
    .mobile-nav {
        position: sticky;
        top: 0;
        z-index: 100;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-light);
    }

    .mobile-nav-scroll {
        overflow-x: auto;
        display: flex;
    }

    .mobile-nav-scroll::-webkit-scrollbar {
        display: none;
    }
}

/* Safe Area Insets for Notched Devices */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }

    .header,
    .footer {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
}

/* Landscape Orientation Adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .modal-content {
        max-height: calc(100vh - 10px);
    }

    body {
        font-size: 14px;
    }

    .header {
        padding: 8px 16px;
    }
}

/* Pull-to-Refresh Helper (Prevent Overscroll) */
body {
    overscroll-behavior-y: contain;
}

/* Improved Focus States for Accessibility */
@media (max-width: 768px) {
    *:focus-visible {
        outline: 3px solid var(--input-focus-border);
        outline-offset: 2px;
    }
}

/* Loading States */
.mobile-loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--bg-hover);
    border-top: 3px solid var(--brand-blue);
    border-radius: 50%;
    animation: mobile-spin 1s linear infinite;
}

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

/* Typography Helpers for Mobile */
@media (max-width: 768px) {
    h1 { font-size: 24px; line-height: 1.2; }
    h2 { font-size: 20px; line-height: 1.3; }
    h3 { font-size: 18px; line-height: 1.3; }
    h4 { font-size: 16px; line-height: 1.4; }
    h5 { font-size: 14px; line-height: 1.4; }
    h6 { font-size: 13px; line-height: 1.4; }

    p, li {
        font-size: 14px;
        line-height: 1.6;
    }

    small {
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    h1 { font-size: 22px; }
    h2 { font-size: 18px; }
    h3 { font-size: 16px; }

    p, li {
        font-size: 13px;
    }
}
