/**
 * mobile-app.css - Ultra-Premium Mobile App Experience for Farms ERP & Portal
 * Strictly active on mobile screens (max-width: 768px) and webview/APK
 */

@media (max-width: 768px) {
    :root {
        --app-primary: #10b981;
        --app-primary-dark: #059669;
        --app-surface: #ffffff;
        --app-bg: #f8fafc;
        --app-text: #0f172a;
        --app-muted: #64748b;
        --app-border: rgba(226, 232, 240, 0.8);
        --app-bottom-nav-height: 68px;
    }

    body {
        background-color: var(--app-bg) !important;
        padding-bottom: calc(var(--app-bottom-nav-height) + env(safe-area-inset-bottom, 12px) + 20px) !important;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    /* ==========================================================================
       1. NATIVE-FEEL TOP APP BAR
       ========================================================================== */
    .mobile-app-bar {
        position: sticky;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1040;
        height: 62px;
        background: rgba(255, 255, 255, 0.88);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-bottom: 1px solid rgba(0, 0, 0, 0.06);
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 16px;
        box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.03);
    }

    .mobile-app-brand {
        display: flex;
        align-items: center;
        gap: 10px;
        text-decoration: none;
    }

    .mobile-app-brand img {
        width: 36px;
        height: 36px;
        border-radius: 10px;
        box-shadow: 0 4px 10px rgba(16, 185, 129, 0.2);
    }

    .mobile-app-brand .brand-title {
        font-weight: 800;
        font-size: 1.15rem;
        color: #0f172a;
        line-height: 1.2;
    }

    .mobile-app-brand .brand-badge {
        font-size: 0.65rem;
        background: rgba(16, 185, 129, 0.12);
        color: var(--app-primary-dark);
        font-weight: 700;
        padding: 1px 6px;
        border-radius: 6px;
        display: inline-block;
    }

    .mobile-app-actions {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .btn-app-icon {
        width: 38px;
        height: 38px;
        border-radius: 12px;
        background: #f1f5f9;
        border: 1px solid rgba(0, 0, 0, 0.04);
        display: flex;
        align-items: center;
        justify-content: center;
        color: #334155;
        font-size: 0.95rem;
        text-decoration: none;
        position: relative;
        transition: all 0.2s ease;
    }

    .btn-app-icon:active {
        transform: scale(0.92);
        background: #e2e8f0;
    }

    .btn-app-demo {
        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        color: #ffffff !important;
        font-size: 0.8rem;
        font-weight: 700;
        padding: 6px 14px;
        border-radius: 9999px;
        text-decoration: none;
        display: flex;
        align-items: center;
        gap: 6px;
        box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
    }

    .btn-app-demo:active {
        transform: scale(0.95);
    }

    /* Hide the old bulky desktop navbar on mobile */
    .navbar-custom {
        display: none !important;
    }

    /* ==========================================================================
       2. HORIZONTAL STORIES / QUICK HIGHLIGHTS
       ========================================================================== */
    .mobile-stories-container {
        padding: 14px 12px 6px;
        overflow-x: auto;
        display: flex;
        gap: 12px;
        scrollbar-width: none;
        -ms-overflow-style: none;
        scroll-snap-type: x mandatory;
    }
    .mobile-stories-container::-webkit-scrollbar {
        display: none;
    }

    .story-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        flex-shrink: 0;
        text-decoration: none;
        scroll-snap-align: start;
        cursor: pointer;
    }

    .story-avatar-wrap {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        padding: 2.5px;
        background: linear-gradient(135deg, #10b981, #06b6d4);
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 10px rgba(16, 185, 129, 0.15);
        transition: transform 0.2s;
    }

    .story-item:active .story-avatar-wrap {
        transform: scale(0.92);
    }

    .story-avatar {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background: #ffffff;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #10b981;
        font-size: 1.3rem;
        border: 2px solid #ffffff;
    }

    .story-label {
        font-size: 0.72rem;
        font-weight: 700;
        color: #334155;
        text-align: center;
        max-width: 66px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* ==========================================================================
       3. APP HERO SECTION (COMPACT & MODERN)
       ========================================================================== */
    .hero {
        padding: 14px 16px 20px !important;
        min-height: auto !important;
        background: transparent !important;
    }

    .mobile-app-hero-card {
        background: linear-gradient(145deg, #ffffff 0%, #f0fdf4 100%);
        border: 1px solid rgba(16, 185, 129, 0.2);
        border-radius: 24px;
        padding: 20px 18px;
        box-shadow: 0 10px 30px -8px rgba(16, 185, 129, 0.12);
        position: relative;
        overflow: hidden;
        margin-bottom: 16px;
    }

    .mobile-app-hero-card::after {
        content: '';
        position: absolute;
        bottom: -30px;
        left: -30px;
        width: 120px;
        height: 120px;
        background: radial-gradient(circle, rgba(16, 185, 129, 0.15) 0%, transparent 70%);
        border-radius: 50%;
        pointer-events: none;
    }

    .hero-badge-pill {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        background: rgba(16, 185, 129, 0.15);
        color: #047857;
        font-size: 0.75rem;
        font-weight: 700;
        padding: 4px 12px;
        border-radius: 9999px;
        margin-bottom: 10px;
        border: 1px solid rgba(16, 185, 129, 0.3);
    }

    .hero-title {
        font-size: 1.65rem !important;
        font-weight: 900 !important;
        line-height: 1.35 !important;
        margin-bottom: 10px !important;
        color: #0f172a !important;
    }

    .hero-title span {
        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        -webkit-background-clip: text;
        background-clip: text;
        -webkit-text-fill-color: transparent;
    }

    .hero-desc {
        font-size: 0.88rem !important;
        line-height: 1.6 !important;
        color: #64748b !important;
        margin-bottom: 18px !important;
    }

    .mobile-hero-cta-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .btn-mobile-primary {
        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        color: #ffffff !important;
        font-weight: 800;
        font-size: 0.88rem;
        padding: 12px 14px;
        border-radius: 14px;
        text-align: center;
        text-decoration: none;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
        border: none;
    }

    .btn-mobile-primary:active {
        transform: scale(0.96);
    }

    .btn-mobile-secondary {
        background: #ffffff;
        color: #0f172a !important;
        font-weight: 700;
        font-size: 0.88rem;
        padding: 12px 14px;
        border-radius: 14px;
        text-align: center;
        text-decoration: none;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        border: 1px solid #e2e8f0;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    }

    .btn-mobile-secondary:active {
        transform: scale(0.96);
        background: #f8fafc;
    }

    /* Hide the huge old desktop stacked buttons on mobile */
    .hero .d-flex.flex-wrap.gap-3 {
        display: none !important;
    }

    /* ==========================================================================
       4. BENTO GRID STATS & SMART CARDS
       ========================================================================== */
    .mobile-bento-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        padding: 0 16px 20px;
    }

    .bento-card {
        background: #ffffff;
        border-radius: 20px;
        padding: 16px;
        border: 1px solid rgba(226, 232, 240, 0.8);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.02);
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        position: relative;
        text-decoration: none;
        color: inherit;
        transition: transform 0.2s ease;
    }

    .bento-card:active {
        transform: scale(0.96);
    }

    .bento-card.full-width {
        grid-column: span 2;
    }

    .bento-card.ai-highlight {
        background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
        color: #ffffff;
        border: 1px solid rgba(16, 185, 129, 0.4);
        box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.4);
    }

    .bento-icon-pill {
        width: 38px;
        height: 38px;
        border-radius: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.1rem;
        margin-bottom: 12px;
    }

    .bento-num {
        font-size: 1.45rem;
        font-weight: 900;
        line-height: 1.1;
        margin-bottom: 4px;
        color: #0f172a;
    }

    .bento-card.ai-highlight .bento-num {
        color: #ffffff;
    }

    .bento-label {
        font-size: 0.75rem;
        font-weight: 700;
        color: #64748b;
    }

    .bento-card.ai-highlight .bento-label {
        color: #94a3b8;
    }

    /* ==========================================================================
       5. NATIVE BOTTOM NAVIGATION BAR (FIXED)
       ========================================================================== */
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--app-bottom-nav-height);
        background: rgba(255, 255, 255, 0.94);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid rgba(0, 0, 0, 0.08);
        box-shadow: 0 -4px 25px rgba(0, 0, 0, 0.06);
        display: flex;
        align-items: center;
        justify-content: space-around;
        padding: 0 8px;
        padding-bottom: env(safe-area-inset-bottom, 8px);
        z-index: 1035; /* Lower than backdrop (1050) & modal (1055) */
        transition: transform 0.25s ease, opacity 0.2s ease, visibility 0.25s ease;
    }

    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        text-decoration: none;
        color: #64748b;
        font-size: 0.72rem;
        font-weight: 700;
        padding: 6px 0;
        border-radius: 12px;
        transition: color 0.15s ease;
    }

    .bottom-nav-item i {
        font-size: 1.25rem;
        transition: transform 0.2s ease;
    }

    .bottom-nav-item.active {
        color: var(--app-primary-dark);
    }

    .bottom-nav-item.active i {
        transform: translateY(-2px);
    }

    .bottom-nav-item:active {
        transform: scale(0.92);
        color: var(--app-primary);
    }

    /* Center Elevated FAB */
    .bottom-nav-fab-wrap {
        flex: 1;
        display: flex;
        justify-content: center;
        position: relative;
    }

    .bottom-nav-fab {
        width: 52px;
        height: 52px;
        border-radius: 50%;
        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        color: #ffffff !important;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.35rem;
        box-shadow: 0 6px 20px rgba(16, 185, 129, 0.45);
        border: 4px solid #ffffff;
        position: absolute;
        top: -24px;
        cursor: pointer;
        transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    }

    .bottom-nav-fab:active {
        transform: scale(0.9) rotate(45deg);
    }

    /* ==========================================================================
       6. NATIVE BOTTOM SHEETS (OFFCANVAS)
       ========================================================================== */
    .offcanvas-bottom.app-bottom-sheet {
        border-top-left-radius: 28px !important;
        border-top-right-radius: 28px !important;
        border-top: 1px solid rgba(0, 0, 0, 0.08) !important;
        box-shadow: 0 -15px 40px rgba(0, 0, 0, 0.15) !important;
        max-height: 85vh;
        height: auto;
        padding-bottom: env(safe-area-inset-bottom, 16px);
    }

    .sheet-drag-handle {
        width: 44px;
        height: 5px;
        background: #cbd5e1;
        border-radius: 9999px;
        margin: 10px auto 14px;
    }

    .sheet-module-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        padding: 6px 0;
    }

    .sheet-module-card {
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 18px;
        padding: 14px;
        display: flex;
        flex-direction: column;
        gap: 8px;
        text-decoration: none;
        color: #0f172a;
        transition: all 0.2s ease;
    }

    .sheet-module-card:active {
        transform: scale(0.96);
        background: #f1f5f9;
    }

    .sheet-module-card .icon-box {
        width: 40px;
        height: 40px;
        border-radius: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.15rem;
    }

    /* Adjust Floating WhatsApp for Mobile */
    .floating-whatsapp {
        bottom: calc(var(--app-bottom-nav-height) + 16px) !important;
        left: 16px !important;
        right: auto !important;
        width: 48px !important;
        height: 48px !important;
        font-size: 24px !important;
        box-shadow: 0 6px 16px rgba(37, 211, 102, 0.35) !important;
        z-index: 1030 !important;
    }

    /* Badge Contrast & Readability Safeguard */
    .badge.bg-success, .badge.text-bg-success {
        background-color: #10b981 !important;
        color: #ffffff !important;
    }
    .badge.bg-light, .badge.bg-white {
        color: #1e293b !important;
        background-color: #f1f5f9 !important;
    }
    .badge.bg-primary, .badge.text-bg-primary {
        background-color: #0284c7 !important;
        color: #ffffff !important;
    }
    .badge.bg-warning, .badge.text-bg-warning {
        background-color: #f59e0b !important;
        color: #1e293b !important;
    }
    .badge.bg-danger, .badge.text-bg-danger {
        background-color: #ef4444 !important;
        color: #ffffff !important;
    }

    /* ==========================================================================
       7. MOBILE MODALS & FORM FOOTERS (PREVENT OVERLAY & FIX BUTTON VISIBILITY)
       ========================================================================== */
    /* Complete suppression of mobile bottom nav & floating elements when any modal is open */
    body.modal-open .mobile-bottom-nav,
    body.modal-open .floating-whatsapp,
    .modal-open .mobile-bottom-nav,
    .modal-open .floating-whatsapp,
    .modal.show ~ .mobile-bottom-nav {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
        transform: translateY(100%) !important;
    }

    /* Polish modal dimensions and accessibility on mobile devices */
    .modal {
        padding-left: 0 !important;
        padding-right: 0 !important;
        z-index: 1055 !important;
    }

    .modal-backdrop {
        z-index: 1050 !important;
    }

    .modal-dialog {
        margin: 0.75rem auto 3.5rem auto !important;
        max-width: 95% !important;
        width: 95% !important;
    }

    .modal-content {
        border-radius: 20px !important;
        border: 1px solid rgba(0, 0, 0, 0.08) !important;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2) !important;
        overflow: hidden;
    }

    .modal-header {
        padding: 1rem 1.25rem !important;
    }

    .modal-body {
        padding: 1.25rem !important;
    }

    .modal-footer {
        padding: 1rem 1.25rem !important;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 12px)) !important;
        background-color: #f8fafc !important;
        border-top: 1px solid rgba(0, 0, 0, 0.08) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-end !important;
        flex-wrap: wrap !important;
        gap: 10px !important;
    }

    .modal-footer > * {
        margin: 0 !important;
    }

    .modal-footer .btn {
        min-height: 46px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0.6rem 1.25rem !important;
        font-weight: 700 !important;
        font-size: 0.95rem !important;
        border-radius: 12px !important;
    }

    .modal-footer .btn-primary,
    .modal-footer .btn-info,
    .modal-footer .btn-success,
    .modal-footer button[type="submit"] {
        flex: 1 1 auto;
        box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
    }
}

