/* ============================================
   Mobile-First & Touch Optimization Styles
   BusGo Theme - Phase 15.3
   ============================================ */

/* ========== Touch Target Optimization (WCAG 2.1 AAA) ========== */
.btn,
.form-input,
.form-select,
.mobile-nav-link,
.touch-target,
button,
input[type="submit"],
input[type="button"],
a.btn {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation; /* Disable double-tap zoom */
}

/* ========== Mobile Navigation Enhancements ========== */
@media (max-width: 768px) {
    /* Larger tap targets for mobile menu */
    .mobile-menu-item,
    .rd-navbar-nav li a {
        padding: 16px 20px !important;
        font-size: 16px;
        line-height: 1.5;
    }

    /* Improve form field spacing on mobile */
    .form-group {
        margin-bottom: 24px;
    }

    /* Stack buttons vertically on small screens */
    .btn-group-mobile {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

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

/* ========== Smooth Scrolling ========== */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* ========== Prevent Text Size Adjustment ========== */
body {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* ========== Improved Tap Highlight ========== */
* {
    -webkit-tap-highlight-color: rgba(59, 130, 246, 0.1);
}

/* ========== Swipe Gestures Support ========== */
.swipeable {
    touch-action: pan-y;
    user-select: none;
}

/* ========== Pull-to-Refresh Prevention ========== */
body {
    overscroll-behavior-y: contain;
}

/* ========== Mobile-Optimized Cards ========== */
@media (max-width: 768px) {
    .card,
    .box-icon-modern,
    .box-service {
        margin-bottom: 16px;
        border-radius: 12px;
    }

    .card-body {
        padding: 16px;
    }
}

/* ========== Bottom Navigation Bar (App-like) ========== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    padding: 8px 0;
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    display: none;
}

@media (max-width: 768px) {
    .bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }

    /* Add padding to body to prevent content hiding behind bottom nav */
    body.has-bottom-nav {
        padding-bottom: 70px;
    }
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    color: #6b7280;
    text-decoration: none;
    font-size: 12px;
    min-width: 64px;
    transition: color 0.2s;
}

.bottom-nav-item.active {
    color: #3b82f6;
}

.bottom-nav-item i {
    font-size: 24px;
    margin-bottom: 4px;
}

/* ========== Floating Action Button (FAB) ========== */
.fab {
    position: fixed;
    bottom: 80px; /* Above bottom nav */
    right: 16px;
    width: auto;
    min-width: 56px;
    height: 56px;
    border-radius: 28px;
    background: #3b82f6;
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 20px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999;
}

.fab i {
    font-size: 20px;
}

.fab-text {
    white-space: nowrap;
}

.fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.fab:active {
    transform: scale(0.95);
}

/* ========== Mobile-Optimized Modals ========== */
@media (max-width: 768px) {
    .modal {
        padding: 0;
    }

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

    .modal-content {
        height: 100%;
        border-radius: 0;
        border: none;
    }

    .modal-header {
        border-top-left-radius: 0;
        border-top-right-radius: 0;
    }
}

/* ========== Gesture Animations ========== */
@keyframes slideInFromBottom {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideOutToBottom {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(100%);
        opacity: 0;
    }
}

.slide-in-bottom {
    animation: slideInFromBottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.slide-out-bottom {
    animation: slideOutToBottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========== iOS Safe Area Insets ========== */
@supports (padding: env(safe-area-inset-bottom)) {
    .bottom-nav {
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }

    .fab {
        bottom: calc(80px + env(safe-area-inset-bottom));
    }
}

/* ========== Improved Touch Scrolling for iOS ========== */
.scrollable {
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
}

/* ========== Mobile Table Responsiveness ========== */
@media (max-width: 768px) {
    .table-responsive-mobile {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

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

/* ========== Optimized Image Loading ========== */
img {
    max-width: 100%;
    height: auto;
}

img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* ========== Loading Skeleton for Better Perceived Performance ========== */
.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ========== Accessibility: Prefers Reduced Motion ========== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========== Dark Mode Support ========== */
@media (prefers-color-scheme: dark) {
    .bottom-nav {
        background: #1f2937;
        border-top-color: #374151;
    }

    .bottom-nav-item {
        color: #9ca3af;
    }

    .bottom-nav-item.active {
        color: #60a5fa;
    }
}

/* ========== Mobile Form Enhancements ========== */
@media (max-width: 768px) {
    /* Larger input fields for better touch interaction */
    .form-input,
    .form-select,
    textarea.form-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px 36px;
    }
    i {padding-left: 15px;}
    /* Improve checkbox and radio button tap targets */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
        min-width: 20px;
        min-height: 20px;
    }

    /* Better label spacing */
    label {
        margin-bottom: 8px;
        display: block;
    }
}

/* ========== Mobile Typography ========== */
@media (max-width: 768px) {
    h1 {
        font-size: 28px;
        line-height: 1.2;
    }

    h2 {
        font-size: 24px;
        line-height: 1.3;
    }

    h3 {
        font-size: 20px;
        line-height: 1.4;
    }

    p {
        font-size: 16px;
        line-height: 1.6;
    }
}

/* ========== Mobile Spacing Improvements ========== */
@media (max-width: 768px) {
    .section {
        padding-top: 40px;
        padding-bottom: 40px;
    }

    .container {
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* ========== Network Status Indicator ========== */
.network-status {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #f59e0b;
    color: white;
    padding: 8px 16px;
    text-align: center;
    font-size: 14px;
    z-index: 9999;
    transform: translateY(-100%);
    transition: transform 0.3s;
}

.network-status.offline {
    background: #ef4444;
    transform: translateY(0);
}

.network-status.online {
    background: #10b981;
    transform: translateY(0);
}

/* ========== Pull-to-Refresh Indicator (Optional) ========== */
.pull-to-refresh {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    font-size: 14px;
    transform: translateY(-60px);
    transition: transform 0.3s;
}

.pull-to-refresh.active {
    transform: translateY(0);
}

.pull-to-refresh .spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========== Mobile Quote Form Enhancements ========== */
@media (max-width: 768px) {
    .quote-form-wrap,
    .form-wrap {
        padding: 20px;
        border-radius: 12px;
    }

    .form-label {
        font-size: 14px;
        font-weight: 600;
        margin-bottom: 6px;
    }

    /* Better date/time pickers on mobile */
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"] {
        min-height: 48px;
        font-size: 16px;
    }
}

/* ========== Mobile-Optimized Alerts ========== */
@media (max-width: 768px) {
    .alert {
        border-radius: 8px;
        padding: 12px 16px;
        font-size: 14px;
    }
}

/* ========== Better Mobile Menu ========== */
@media (max-width: 768px) {
    .rd-navbar-collapse {
        max-height: calc(100vh - 60px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ========== Mobile-Optimized Hero Sections ========== */
@media (max-width: 768px) {
    .section-intro,
    .section-hero {
        padding-top: 60px;
        padding-bottom: 60px;
    }

    .section-intro h1,
    .section-hero h1 {
        font-size: 32px;
        margin-bottom: 16px;
    }
}

/* ========== Improved Mobile Footer ========== */
@media (max-width: 768px) {
    .footer {
        padding-top: 40px;
        padding-bottom: 80px; /* Extra space for bottom nav */
    }

    .footer-column {
        margin-bottom: 32px;
    }
}

/* Mobile quote form spacing reduction */
@media (max-width: 768px) {
    .row-30 > * {
        margin-bottom: 0;
    }
}

/* Quote form icon positioning */
.form-order-box .form-wrap {
    position: relative;
}

.quote-form-field {
    padding-left: 45px;
}

.quote-form-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    z-index: 5;
}
