/* Mobile Optimizations for CollabMatch
 * Comprehensive mobile-first responsive styles
 * Touch-friendly interactions and proper viewport handling
 */

/* =============================================
   TOUCH-FRIENDLY BUTTON & INPUT SIZES
   Minimum 44px tap targets for accessibility
   ============================================= */

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

    .btn-sm {
        min-height: 40px;
        padding: 0.5rem 0.875rem;
        font-size: 0.875rem;
    }

    .btn-lg {
        min-height: 52px;
        padding: 0.75rem 1.5rem;
    }

    .form-control,
    .form-select {
        min-height: 48px;
        padding: 0.75rem 1rem;
        font-size: 16px !important; /* Prevents iOS zoom on focus */
    }

    .form-control-sm,
    .form-select-sm {
        min-height: 44px;
        font-size: 16px !important;
    }

    textarea.form-control {
        min-height: 100px;
    }

    input[type="checkbox"],
    input[type="radio"] {
        width: 22px;
        height: 22px;
        min-width: 22px;
    }

    .form-check {
        padding-left: 2rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .form-check-input {
        margin-top: 0;
    }

    .form-check-label {
        padding-left: 0.5rem;
    }
}

/* =============================================
   MOBILE SPACING & LAYOUT
   ============================================= */

@media (max-width: 767.98px) {
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .py-4 {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }

    .mb-4 {
        margin-bottom: 1rem !important;
    }

    .mb-5 {
        margin-bottom: 1.5rem !important;
    }

    .gap-3 {
        gap: 0.75rem !important;
    }

    .gap-4 {
        gap: 1rem !important;
    }

    h1, .h1 {
        font-size: 1.5rem;
    }

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

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

    .display-6 {
        font-size: 1.5rem;
    }

    .fs-1 {
        font-size: 2rem !important;
    }

    .fs-2 {
        font-size: 1.5rem !important;
    }
}

/* =============================================
   CARD STACKING & MOBILE CARDS
   ============================================= */

@media (max-width: 767.98px) {
    .card {
        margin-bottom: 0.75rem;
    }

    .card-body {
        padding: 1rem;
    }

    .card .d-flex.justify-content-between {
        flex-direction: column;
        gap: 0.5rem;
    }

    .card-hover:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }

    .stat-card .card-body {
        padding: 0.875rem;
    }

    .stat-card h3 {
        font-size: 1.375rem;
    }

    .stat-card .fs-2 {
        font-size: 1.25rem !important;
    }

    .stat-card .small {
        font-size: 0.75rem;
    }

    .row.g-3 {
        --bs-gutter-x: 0.75rem;
        --bs-gutter-y: 0.75rem;
    }

    .col-6 .card {
        height: 100%;
    }
}

/* =============================================
   NAVIGATION MOBILE IMPROVEMENTS
   ============================================= */

@media (max-width: 1199.98px) {
    /* Ensure navbar is clean and items don't show until hamburger clicked */
    .navbar {
        position: sticky !important;
        top: 0 !important;
        z-index: 1050 !important;
    }
    
    /* Let Bootstrap handle collapse visibility - DO NOT override display */
    .navbar-collapse {
        position: absolute !important;
        top: 100% !important;
        left: 0 !important;
        right: 0 !important;
        background: #0f172a !important;
        padding: 1rem !important;
        overflow-y: auto !important;
        max-height: calc(100vh - 60px) !important;
        z-index: 1049 !important;
        -webkit-overflow-scrolling: touch;
        box-shadow: 0 10px 50px rgba(0, 0, 0, 0.9) !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    }
    
    /* When NOT shown, Bootstrap sets display:none - we just ensure no visibility leaks */
    .navbar-collapse:not(.show) {
        /* Let Bootstrap handle this - don't override display */
    }
    
    /* When shown, ensure proper layout */
    .navbar-collapse.show {
        display: flex !important;
        flex-direction: column !important;
    }
    
    /* Prevent any items from leaking outside collapsed nav */
    .navbar-collapse .navbar-nav {
        width: 100% !important;
        flex-direction: column !important;
    }
    
    .navbar-nav {
        gap: 0;
    }

    .navbar-nav .nav-link {
        padding: 0.875rem 1rem;
        min-height: 48px;
        display: flex;
        align-items: center;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    /* Ensure buttons in navbar stack properly */
    .navbar-nav .btn {
        width: 100% !important;
        margin: 0.5rem 0 !important;
        text-align: center !important;
        justify-content: center !important;
    }

    .navbar-toggler {
        min-width: 44px;
        min-height: 44px;
        padding: 0.5rem;
        border: 1px solid rgba(255, 255, 255, 0.2) !important;
    }

    .dropdown-menu {
        position: static !important;
        float: none;
        width: 100%;
        margin: 0;
        background: rgba(255, 255, 255, 0.05);
        border: none;
        box-shadow: none;
    }

    .dropdown-item {
        padding: 0.875rem 1.5rem;
        min-height: 48px;
        display: flex;
        align-items: center;
    }
}

/* =============================================
   TABLES - RESPONSIVE HORIZONTAL SCROLL
   ============================================= */

@media (max-width: 767.98px) {
    .table-responsive {
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
    }

    .table {
        font-size: 0.875rem;
    }

    .table th,
    .table td {
        padding: 0.75rem 0.5rem;
        white-space: nowrap;
    }

    .table td .btn {
        padding: 0.375rem 0.625rem;
        font-size: 0.75rem;
    }

    .table-card-mobile {
        display: block;
    }

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

    .table-card-mobile tbody tr {
        display: block;
        margin-bottom: 1rem;
        padding: 1rem;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 8px;
        border: 1px solid rgba(255, 255, 255, 0.1);
    }

    .table-card-mobile tbody td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        border: none;
        white-space: normal;
    }

    .table-card-mobile tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #94a3b8;
        margin-right: 1rem;
    }
}

/* =============================================
   MODALS & OVERLAYS - MOBILE FRIENDLY
   ============================================= */

@media (max-width: 767.98px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-dialog-centered {
        min-height: calc(100% - 1rem);
    }

    .modal-content {
        border-radius: 16px;
    }

    .modal-header,
    .modal-footer {
        padding: 1rem;
    }

    .modal-body {
        padding: 1rem;
        max-height: 60vh;
        overflow-y: auto;
    }

    .modal-footer .btn {
        flex: 1;
    }

    .offcanvas {
        --bs-offcanvas-width: 100%;
    }

    .offcanvas-body {
        padding: 1rem;
    }
}

/* =============================================
   FORM INPUT OPTIMIZATIONS
   ============================================= */

@media (max-width: 767.98px) {
    .form-floating > .form-control {
        height: calc(3.5rem + 2px);
    }

    .input-group .form-control {
        min-height: 48px;
    }

    .input-group .btn {
        min-height: 48px;
    }

    input[type="email"],
    input[type="tel"],
    input[type="url"],
    input[type="number"] {
        font-size: 16px !important;
    }

    .form-label {
        font-size: 0.875rem;
        margin-bottom: 0.375rem;
    }

    .form-text {
        font-size: 0.75rem;
    }

    .invalid-feedback,
    .valid-feedback {
        font-size: 0.75rem;
    }

    .form-group + .form-group {
        margin-top: 1rem;
    }
}

/* =============================================
   DASHBOARD SPECIFIC MOBILE STYLES
   ============================================= */

@media (max-width: 767.98px) {
    .dashboard-header {
        flex-direction: column;
        gap: 1rem;
    }

    .dashboard-header h1 {
        font-size: 1.25rem;
    }

    .dashboard-header .badge {
        font-size: 0.6875rem;
    }

    .avatar-circle {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    .avatar-circle-sm {
        width: 32px;
        height: 32px;
    }

    .avatar-circle img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }

    .progress {
        height: 6px;
    }
}

/* =============================================
   AI HUB MOBILE STYLES
   ============================================= */

@media (max-width: 767.98px) {
    .quota-status {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .quota-status .vr {
        display: none;
    }

    .quick-action-btn {
        padding: 1rem !important;
    }

    .quick-action-btn i {
        font-size: 1.25rem !important;
    }

    .quick-action-btn span {
        font-size: 0.75rem !important;
    }

    .unlock-more-section .row {
        flex-direction: column;
    }

    .unlock-more-section .text-lg-end {
        text-align: left !important;
        margin-top: 1rem;
    }
}

/* =============================================
   ONBOARDING WIZARD MOBILE STYLES
   ============================================= */

@media (max-width: 576px) {
    .onboarding-container {
        padding: 0.5rem;
        align-items: flex-start;
    }

    .onboarding-card {
        border-radius: 12px;
        margin-top: 0.5rem;
    }

    .onboarding-header {
        padding: 1rem 1.25rem;
    }

    .onboarding-body {
        padding: 1.25rem;
    }

    .onboarding-footer {
        padding: 1rem 1.25rem;
        flex-direction: column-reverse;
        gap: 0.75rem;
    }

    .onboarding-footer > div {
        width: 100%;
    }

    .onboarding-footer .btn-nav {
        width: 100%;
        text-align: center;
    }

    .step-title {
        font-size: 1.25rem;
    }

    .step-subtitle {
        font-size: 0.875rem;
    }

    .platform-item {
        flex-wrap: wrap;
    }

    .platform-item .platform-url {
        flex: 0 0 100%;
        margin-top: 0.5rem;
        margin-left: calc(18px + 1rem);
    }

    .niche-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.375rem;
    }

    .niche-card {
        padding: 0.5rem;
    }

    .niche-card i {
        font-size: 1rem;
    }

    .niche-card span {
        font-size: 0.6875rem;
    }

    .action-card {
        padding: 0.875rem;
    }

    .action-card i {
        font-size: 1.25rem;
        width: 32px;
    }

    .action-card-content h5 {
        font-size: 0.9375rem;
    }

    .action-card-content p {
        font-size: 0.75rem;
    }

    .collab-type-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }

    .avatar-upload {
        width: 80px;
        height: 80px;
    }
}

/* =============================================
   PREVENT HORIZONTAL SCROLL
   ============================================= */

html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

.container,
.container-fluid,
.row {
    max-width: 100%;
}

@media (max-width: 767.98px) {
    .row {
        margin-left: 0;
        margin-right: 0;
    }

    .col, [class*="col-"] {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    img {
        max-width: 100%;
        height: auto;
    }

    .text-truncate {
        max-width: 100%;
    }

    pre, code {
        max-width: 100%;
        overflow-x: auto;
        white-space: pre-wrap;
        word-wrap: break-word;
    }
}

/* =============================================
   TOUCH FEEDBACK & ACTIVE STATES
   ============================================= */

@media (max-width: 767.98px) {
    .btn:active,
    .nav-link:active,
    .dropdown-item:active,
    .list-group-item:active {
        opacity: 0.8;
        transform: scale(0.98);
    }

    .card-hover:active,
    a.card:active {
        transform: scale(0.98);
    }

    a, button, .btn, .nav-link {
        -webkit-tap-highlight-color: rgba(59, 130, 246, 0.1);
        touch-action: manipulation;
    }
}

/* =============================================
   SAFE AREA INSETS (for notched devices)
   ============================================= */

@supports (padding: max(0px)) {
    .navbar {
        padding-top: max(0.5rem, env(safe-area-inset-top));
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .container-fluid {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .modal-footer,
    .onboarding-footer,
    .fixed-bottom {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* =============================================
   STICKY CTA BUTTONS FOR MOBILE
   ============================================= */

@media (max-width: 767.98px) {
    .sticky-cta-mobile {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: linear-gradient(to top, #0f172a 80%, transparent);
        padding: 1rem;
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
        z-index: 1040;
    }

    .sticky-cta-mobile .btn {
        width: 100%;
        min-height: 48px;
    }

    .has-sticky-cta {
        padding-bottom: 80px;
    }
}

/* =============================================
   BADGE & PILL MOBILE ADJUSTMENTS
   ============================================= */

@media (max-width: 767.98px) {
    .badge {
        font-size: 0.6875rem;
        padding: 0.375rem 0.5rem;
    }

    .badge.fs-6 {
        font-size: 0.75rem !important;
    }
}

/* =============================================
   LIST GROUP MOBILE STYLES
   ============================================= */

@media (max-width: 767.98px) {
    .list-group-item {
        padding: 0.875rem 1rem;
    }

    .list-group-item .d-flex {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

/* =============================================
   ENTERPRISE PAGES MOBILE STYLES
   ============================================= */

@media (max-width: 767.98px) {
    .api-docs-sidebar {
        display: none;
    }

    .api-docs-sidebar.show {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: #0f172a;
        z-index: 1050;
        padding: 1rem;
        overflow-y: auto;
    }

    .enterprise-header {
        flex-direction: column;
        gap: 1rem;
    }

    .enterprise-stats .row {
        gap: 0.5rem;
    }
}

/* =============================================
   LOADING & SKELETON STATES
   ============================================= */

@media (max-width: 767.98px) {
    .skeleton {
        background: linear-gradient(90deg, rgba(255,255,255,0.05) 25%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0.05) 75%);
        background-size: 200% 100%;
        animation: skeleton-loading 1.5s infinite;
    }

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

/* =============================================
   CONTENT STUDIO TABS MOBILE FIXES
   ============================================= */

@media (max-width: 767.98px) {
    .cs-tabs {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        padding: 0 0.75rem !important;
        gap: 0.25rem !important;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    .cs-tabs::-webkit-scrollbar {
        display: none;
    }
    
    .cs-tab-btn {
        flex: 0 0 auto !important;
        min-width: auto !important;
        padding: 0.75rem 0.875rem !important;
        font-size: 0.75rem !important;
        white-space: nowrap !important;
        scroll-snap-align: start;
        display: flex !important;
        align-items: center !important;
        gap: 0.35rem !important;
    }
    
    .cs-tab-btn i {
        font-size: 0.875rem !important;
    }
    
    .cs-tab-btn span {
        display: none;
    }
    
    /* Mobile-friendly toolbar scrolling hint */
    .cs-tabs-wrapper {
        position: relative;
    }
    
    .cs-tabs-wrapper::after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 30px;
        background: linear-gradient(to left, rgba(15, 23, 42, 0.9), transparent);
        pointer-events: none;
    }
    
    /* Library and package toolbars */
    .library-toolbar,
    .pkg-lib-toolbar {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }
    
    .library-toolbar .btn,
    .pkg-lib-toolbar .btn {
        flex: 0 0 auto !important;
        font-size: 0.75rem !important;
        padding: 0.5rem 0.75rem !important;
    }
}
