/**
 * Cinco's Go — Mobile & tablet enhancements
 */

:root {
    --nav-height-mobile: 56px;
    --bottom-nav-height: 68px;
    --touch-min: 44px;
    --content-max-tablet: 720px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    overflow-x: hidden;
}

/* Prevent iOS zoom on focus */
@media (max-width: 767.98px) {
    .form-control,
    .form-select,
    .select2-container--bootstrap-5 .select2-selection {
        font-size: 16px !important;
    }
}

/* ——— Public site ——— */
@media (max-width: 575.98px) {
    .hero-section {
        min-height: auto;
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }

    .hero-section .display-4 {
        font-size: 1.75rem;
    }

    .hero-section .lead {
        font-size: 1rem;
    }

    .hero-section .btn-lg {
        width: 100%;
        max-width: 280px;
    }
}

/* ——— Auth ——— */
@media (max-width: 575.98px) {
    .auth-bg .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .auth-bg .card {
        border-radius: 16px;
    }
}

/* ——— Dashboard shell ——— */
@media (min-width: 992px) {
    .main-content {
        padding-bottom: 0 !important;
    }
}

.main-content {
    width: 100%;
    min-width: 0;
}

.top-bar {
    position: sticky;
    top: 0;
    z-index: 1020;
    min-height: var(--nav-height-mobile);
    padding-top: calc(0.5rem + var(--safe-top)) !important;
}

.content-area {
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
}

@media (max-width: 991.98px) {
    .main-content {
        padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 12px);
    }

    .content-area {
        padding-top: 0.75rem !important;
        padding-bottom: 1rem !important;
    }

    h4, h5.page-title-mobile {
        font-size: 1.15rem;
    }
}

/* Bottom navigation — safe area + touch */
.mobile-bottom-nav {
    padding-bottom: calc(8px + var(--safe-bottom));
    padding-top: 6px;
    min-height: calc(var(--bottom-nav-height) + var(--safe-bottom));
    backdrop-filter: blur(12px);
    background: rgba(255, 255, 255, 0.95);
}

.nav-link-mobile {
    min-width: 56px;
    min-height: var(--touch-min);
    justify-content: center;
    padding: 4px 6px;
    -webkit-tap-highlight-color: transparent;
    color: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

button.nav-link-mobile {
    cursor: pointer;
}

.nav-link-mobile span {
    font-size: 0.6rem;
    max-width: 64px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Tablet: slightly larger bottom labels */
@media (min-width: 576px) and (max-width: 991.98px) {
    .nav-link-mobile {
        min-width: 72px;
    }

    .nav-link-mobile span {
        font-size: 0.68rem;
    }

    .nav-link-mobile i {
        font-size: 1.45rem;
    }
}

/* Notifications dropdown on small screens */
@media (max-width: 575.98px) {
    .notif-dropdown {
        width: min(100vw - 24px, 320px) !important;
        max-width: calc(100vw - 24px);
    }
}

/* Touch-friendly buttons */
@media (max-width: 991.98px) {
    .btn,
    .btn-sm {
        min-height: var(--touch-min);
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .btn-sm {
        min-height: 40px;
        padding-left: 0.85rem;
        padding-right: 0.85rem;
    }

    .btn-link {
        min-height: var(--touch-min);
        min-width: var(--touch-min);
    }
}

/* Stat cards — 2 columns on phone */
@media (max-width: 575.98px) {
    .stat-card .card-body {
        padding: 0.85rem;
    }

    .stat-card h4 {
        font-size: 1.25rem;
    }
}

@media (min-width: 576px) and (max-width: 991.98px) {
    .row.g-3 > .col-6 {
        flex: 0 0 auto;
        width: 50%;
    }
}

/* ——— Tracking steps (order / delivery) ——— */
@media (max-width: 767.98px) {
    .tracking-steps {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
        gap: 8px;
        padding: 8px 4px 12px;
        scrollbar-width: none;
    }

    .tracking-steps::-webkit-scrollbar {
        display: none;
    }

    .tracking-steps::before {
        display: none;
    }

    .track-step {
        flex: 0 0 auto;
        min-width: 64px;
        max-width: 72px;
    }

    .track-step span {
        font-size: 0.58rem;
        line-height: 1.2;
    }

    .track-step .step-dot {
        width: 16px;
        height: 16px;
    }
}

/* ——— Customer Instagram-style home ——— */
@media (max-width: 575.98px) {
    .ig-home,
    .ig-browse-page {
        max-width: 100%;
        margin: 0;
        padding-left: 2px;
        padding-right: 2px;
    }

    .ig-greeting-name {
        font-size: 1.25rem;
    }

    .ig-action-grid {
        gap: 8px;
    }

    .ig-action-pill {
        padding: 10px 4px;
        font-size: 0.65rem;
    }

    .ig-action-icon {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }

    .story-circle-item {
        width: 68px;
    }

    .story-ring {
        width: 64px;
        height: 64px;
    }

    .story-circle-label {
        max-width: 68px;
        font-size: 0.65rem;
    }
}

@media (min-width: 576px) and (max-width: 991.98px) {
    .ig-home,
    .ig-browse-page {
        max-width: var(--content-max-tablet);
        margin: 0 auto;
    }

    .content-area:has(.ig-home) {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }
}

/* ——— Rider delivery cards ——— */
@media (max-width: 767.98px) {
    .delivery-job-card .card-body > .d-flex {
        flex-direction: column;
        align-items: stretch !important;
    }

    .delivery-job-card .accept-delivery-job,
    .delivery-job-card .btn-primary {
        width: 100%;
        margin-top: 0.75rem;
    }

    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-bottom: 1px solid #dee2e6;
    }

    .nav-tabs .nav-link {
        white-space: nowrap;
        font-size: 0.85rem;
    }
}

/* Job / order cards — stack actions */
@media (max-width: 575.98px) {
    .card-body > .d-flex.justify-content-between.align-items-start {
        flex-direction: column;
        gap: 0.75rem;
    }

    .card-body > .d-flex.justify-content-between.align-items-start .text-end {
        text-align: left !important;
        width: 100%;
    }

    .card-body .d-flex.gap-2.flex-wrap,
    .card-body .mt-3.d-flex {
        flex-direction: column;
    }

    .card-body .d-flex.gap-2.flex-wrap .btn,
    .card-body .mt-3.d-flex .btn {
        width: 100%;
    }
}

/* ——— Cart checkout ——— */
@media (max-width: 991.98px) {
    .cart-checkout-row {
        flex-direction: column-reverse;
    }

    .cart-checkout-row > [class*="col-lg-4"] {
        position: sticky;
        bottom: calc(var(--bottom-nav-height) + var(--safe-bottom));
        z-index: 100;
        background: #f0f2f5;
        padding-top: 0.5rem;
        margin-bottom: 0.5rem;
    }
}

/* ——— Booking wizard ——— */
@media (max-width: 575.98px) {
    .booking-wizard {
        max-width: 100%;
        padding: 0 2px;
    }

    .wizard-nav .btn {
        flex: 1;
    }

    .wizard-nav.d-flex.gap-2 {
        flex-wrap: wrap;
    }

    .service-card {
        min-height: 100px;
    }

    .row.g-3 > .col-md-4 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

@media (min-width: 576px) and (max-width: 991.98px) {
    .booking-wizard {
        max-width: var(--content-max-tablet);
    }
}

/* ——— Maps ——— */
@media (max-width: 575.98px) {
    .geocode-map {
        height: 220px;
        min-height: 180px;
    }

    .geocode-map-sm {
        height: 180px;
    }
}

/* ——— Admin / dashboard tables ——— */
@media (max-width: 767.98px) {
    .content-area .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-left: -0.5rem;
        margin-right: -0.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .content-area .table-responsive table {
        font-size: 0.8rem;
        min-width: 560px;
    }

    .content-area .table-responsive th,
    .content-area .table-responsive td {
        padding: 0.5rem 0.4rem;
        white-space: nowrap;
    }
}

/* ——— Track order page ——— */
@media (max-width: 575.98px) {
    .track-order-wrap .col-lg-6 {
        padding-left: 0;
        padding-right: 0;
    }

    .track-order-wrap .card-body {
        padding: 1rem !important;
    }
}

/* ——— Fixed cart FAB ——— */
@media (max-width: 991.98px) {
    .fixed-cart-btn {
        bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 12px);
        right: max(12px, env(safe-area-inset-right));
        padding: 12px 20px;
        font-size: 0.9rem;
    }
}

/* ——— Select2 full width ——— */
.select2-container {
    width: 100% !important;
}

/* ——— Tablet desktop-like content width when sidebar hidden ——— */
@media (min-width: 768px) and (max-width: 991.98px) {
    .content-area {
        max-width: 100%;
        padding-left: 1.5rem !important;
        padding-right: 1.5rem !important;
    }

    .card.border-0.shadow-sm {
        border-radius: 14px;
    }
}

/* Reduce motion on mobile for performance */
@media (max-width: 767.98px) and (prefers-reduced-motion: no-preference) {
    .story-ring-flash {
        animation-duration: 3s;
    }
}

/* Landscape phone — shorter hero / more vertical space for content */
@media (max-height: 500px) and (orientation: landscape) {
    .hero-section {
        min-height: auto;
        padding: 1.5rem 0 !important;
    }

    .mobile-bottom-nav {
        padding-top: 4px;
        padding-bottom: 4px;
    }
}
