/* ==========================================================================
   Mobile Touch Target & Accessibility Fixes
   Ensures all interactive elements meet minimum 44x44px touch target size
   per WCAG 2.5.5 / Apple HIG guidelines.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Buttons - minimum 44px height
   -------------------------------------------------------------------------- */
.btn,
button:not(.navbar-toggler):not(.btn-close):not(.chat-close) {
    min-height: 44px;
}

@media (max-width: 768px) {
    .btn {
        min-height: 44px;
        padding-top: 0.625rem;
        padding-bottom: 0.625rem;
        font-size: 1rem;
    }

    .btn-sm {
        min-height: 44px;
        padding: 0.5rem 0.875rem;
    }

    .btn-lg {
        min-height: 48px;
    }
}

/* --------------------------------------------------------------------------
   Navigation links - minimum 44px touch area
   -------------------------------------------------------------------------- */
@media (max-width: 991px) {
    .navbar-nav .nav-link {
        min-height: 44px;
        padding: 0.75rem 1rem;
        display: flex;
        align-items: center;
    }

    .navbar-nav .dropdown-item {
        min-height: 44px;
        padding: 0.75rem 1.25rem;
        display: flex;
        align-items: center;
    }

    .navbar-toggler {
        min-width: 44px;
        min-height: 44px;
        padding: 0.5rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* --------------------------------------------------------------------------
   Form inputs - minimum 44px height
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="password"],
    input[type="search"],
    input[type="url"],
    input[type="date"],
    select,
    textarea {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: 0.625rem 0.875rem;
    }

    .input-group .form-control,
    .input-group .form-select {
        min-height: 44px;
    }

    .input-group-text {
        min-height: 44px;
        padding: 0.625rem 0.875rem;
    }
}

/* --------------------------------------------------------------------------
   Checkbox & Radio - enlarged clickable area
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .form-check {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding-left: 2rem;
    }

    .form-check-input {
        width: 1.25em;
        height: 1.25em;
        margin-top: 0;
    }

    .form-check-label {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding: 0.5rem 0;
        cursor: pointer;
    }

    /* Enlarge clickable area for btn-check radio/checkbox groups */
    .btn-check + .btn {
        min-height: 44px;
        padding: 0.625rem 1rem;
    }
}

/* --------------------------------------------------------------------------
   Links - ensure minimum tap target
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .footer a {
        display: inline-flex;
        align-items: center;
        min-height: 36px;
        line-height: 1.4;
    }

    .footer ul li {
        margin-bottom: 0;
    }

    .breadcrumb-item a,
    .pagination .page-link {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding: 0.5rem 0.75rem;
    }
}

/* --------------------------------------------------------------------------
   Close buttons
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .btn-close {
        width: 44px;
        height: 44px;
        padding: 0.75rem;
        background-size: 0.875rem;
    }

    .alert .btn-close {
        padding: 1rem;
    }
}

/* --------------------------------------------------------------------------
   Cards and interactive areas
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .card-link,
    a.card {
        display: block;
    }

    /* Ensure tag/badge elements have enough space when tappable */
    a.badge,
    a.tag,
    .suggestion-tag a {
        min-height: 32px;
        padding: 0.375rem 0.75rem;
        display: inline-flex;
        align-items: center;
    }
}

/* --------------------------------------------------------------------------
   Spacing between interactive elements (prevent mis-taps)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .btn + .btn,
    .nav-link + .nav-link {
        margin-top: 0.25rem;
    }

    .d-flex.gap-2 {
        gap: 0.5rem !important;
    }
}

/* --------------------------------------------------------------------------
   Tab and pill nav items
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .nav-tabs .nav-link,
    .nav-pills .nav-link {
        min-height: 44px;
        padding: 0.625rem 1rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* --------------------------------------------------------------------------
   Modal interaction elements
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .modal-header .btn-close {
        width: 44px;
        height: 44px;
    }

    .modal-footer .btn {
        min-height: 44px;
        flex: 1;
    }
}

/* ==========================================================================
   Viewport & Safe Area Insets (for notched phones / viewport-fit=cover)
   ========================================================================== */

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

@media (max-width: 768px) {
    /* Prevent child elements from causing horizontal overflow */
    .container,
    .container-fluid,
    main,
    section,
    .row {
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Ensure images/media don't overflow */
    img, video, iframe, embed, object {
        max-width: 100%;
        height: auto;
    }

    /* Prevent tables from causing overflow */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Prevent code blocks from causing overflow */
    pre, code {
        overflow-x: auto;
        max-width: 100%;
    }
}

/* --------------------------------------------------------------------------
   Safe area insets for notched phones (iPhone X+, etc.)
   Applied when viewport-fit=cover is set on the viewport meta tag
   -------------------------------------------------------------------------- */
@supports (padding: env(safe-area-inset-top)) {
    /* Navbar respects safe area */
    .navbar-custom {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    /* Footer respects safe area */
    .footer {
        padding-bottom: max(2rem, env(safe-area-inset-bottom));
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    /* Floating action buttons avoid safe areas */
    .talk-to-agent-fab {
        bottom: max(20px, env(safe-area-inset-bottom));
        right: max(90px, calc(env(safe-area-inset-right) + 90px));
    }

    @media (max-width: 576px) {
        .talk-to-agent-fab {
            bottom: max(16px, calc(env(safe-area-inset-bottom) + 16px));
            right: max(16px, calc(env(safe-area-inset-right) + 16px));
        }
    }

    /* Container padding for landscape notch */
    @media (max-width: 768px) and (orientation: landscape) {
        .container {
            padding-left: max(12px, env(safe-area-inset-left));
            padding-right: max(12px, env(safe-area-inset-right));
        }
    }

    /* Flash messages */
    .alert {
        margin-left: env(safe-area-inset-left);
        margin-right: env(safe-area-inset-right);
    }

    /* Modal on mobile */
    @media (max-width: 768px) {
        .modal-content {
            padding-bottom: env(safe-area-inset-bottom);
        }
    }
}
