/* =====================================================
   Mobile App Layer v8 - Tiles + smooth performance
   ===================================================== */

:root {
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    --bottom-nav-h: 68px;
    --brand: #0d9488;
}

html, body {
    font-family: 'Cairo', Tahoma, sans-serif !important;
    -webkit-tap-highlight-color: transparent;
}

body.native-app .install-banner,
.native-app .install-banner { display: none !important; }

.install-banner { display: none; }
.install-banner.show {
    display: flex;
    position: fixed;
    top: calc(10px + var(--safe-top));
    left: 12px; right: 12px;
    z-index: 2000;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 8px 24px rgba(15, 118, 110, 0.2);
    padding: 12px 14px;
    align-items: center;
    gap: 12px;
    border: 2px solid #99f6e4;
}
.install-banner img { width: 44px; height: 44px; border-radius: 12px; }
.install-banner .txt { flex: 1; }
.install-banner .txt strong { display: block; font-size: 0.9rem; }
.install-banner .txt span { font-size: 0.75rem; color: #64748b; }
.install-banner .btn-install {
    background: linear-gradient(135deg, #0d9488, #14b8a6);
    color: #fff; border: none; border-radius: 12px;
    font-weight: 800; padding: 0.5rem 0.85rem;
}

.bottom-nav { display: none; }

/* ===== Quick action tiles (always defined) ===== */
.app-tiles-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
    width: 100%;
}
.app-tiles-grid .span-3 { grid-column: span 3; }
.app-tiles-grid .span-2 { grid-column: span 2; }

a.app-tile,
.app-tile {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    width: 100% !important;
    min-height: 96px !important;
    padding: 14px 8px !important;
    border-radius: 18px !important;
    text-decoration: none !important;
    color: #0f766e !important;
    background: #fff !important;
    border: 1px solid rgba(13, 148, 136, 0.12) !important;
    box-shadow: 0 4px 14px rgba(15, 118, 110, 0.08) !important;
    font-weight: 800 !important;
    font-size: 0.88rem !important;
    line-height: 1.25 !important;
    text-align: center !important;
    box-sizing: border-box !important;
    -webkit-user-select: none;
    user-select: none;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.app-tile:hover,
.app-tile:focus,
.app-tile:visited {
    text-decoration: none !important;
    color: #0f766e !important;
}
.app-tile:active {
    transform: scale(0.97);
}
.app-tile .tile-icon {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-size: 1.35rem;
    color: #fff !important;
    flex-shrink: 0;
}
.app-tile .tile-label {
    display: block;
    color: inherit !important;
    text-decoration: none !important;
}

.app-tile.t-green .tile-icon { background: linear-gradient(135deg, #22c55e, #16a34a); }
.app-tile.t-amber .tile-icon { background: linear-gradient(135deg, #f59e0b, #d97706); }
.app-tile.t-blue .tile-icon { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.app-tile.t-purple .tile-icon { background: linear-gradient(135deg, #a78bfa, #7c3aed); }
.app-tile.t-whatsapp .tile-icon,
.app-tile.t-teal .tile-icon { background: linear-gradient(135deg, #25d366, #128c7e); }
.app-tile.t-pink .tile-icon { background: linear-gradient(135deg, #f472b6, #db2777); }
.app-tile.t-cyan .tile-icon { background: linear-gradient(135deg, #22d3ee, #0891b2); }
.app-tile.t-indigo .tile-icon,
.app-tile.t-red .tile-icon { background: linear-gradient(135deg, #6366f1, #4f46e5); }

.mobile-hero {
    width: 100%;
    box-sizing: border-box;
    background: linear-gradient(135deg, #0f766e, #0d9488 55%, #14b8a6);
    color: #fff;
    border-radius: 22px;
    padding: 18px;
    margin-bottom: 12px;
}
.mobile-hero h3 { margin: 0 0 4px; font-weight: 800; }
.mobile-hero p { margin: 0; opacity: 0.9; font-size: 0.9rem; }

@media (max-width: 991.98px) {
    html, body, body.app-mode {
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
        padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 10px) !important;
        /* lighter bg = less WebView paint lag */
        background: #f0fdfa !important;
        margin: 0 !important;
    }

    .app-wrapper {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        max-width: 100vw !important;
    }

    .mobile-topbar {
        flex: 0 0 auto !important;
        width: 100% !important;
        height: auto !important;
        align-self: stretch !important;
        position: sticky !important;
        top: 0;
        z-index: 1030;
        padding: calc(10px + var(--safe-top)) 14px 10px !important;
        background: #0d9488 !important;
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        box-sizing: border-box;
    }
    .brand-mini strong { color: #fff; font-size: 1rem; }
    .brand-mini div { color: rgba(255,255,255,.85) !important; }

    aside.sidebar,
    .sidebar.offcanvas-lg {
        width: min(86vw, 320px) !important;
        max-width: 320px !important;
        margin: 0 !important;
        flex: none !important;
        visibility: hidden !important;
        transform: translateX(110%) !important;
    }
    aside.sidebar.show,
    .sidebar.offcanvas-lg.show {
        visibility: visible !important;
        transform: none !important;
    }

    .main-content {
        display: block !important;
        width: 100% !important;
        max-width: 100vw !important;
        margin: 0 !important;
        margin-right: 0 !important;
        margin-left: 0 !important;
        padding: 12px !important;
        flex: 1 1 auto !important;
        box-sizing: border-box !important;
    }

    .app-footer, .quick-fab, .page-header-mobile { display: none !important; }

    .bottom-nav {
        display: flex !important;
        position: fixed !important;
        bottom: 0; left: 0; right: 0;
        width: 100% !important;
        height: calc(var(--bottom-nav-h) + var(--safe-bottom));
        padding-bottom: var(--safe-bottom);
        background: #fff;
        border-top: 1px solid #ccfbf1;
        z-index: 1060;
        justify-content: space-around;
        box-sizing: border-box;
    }
    .bottom-nav a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        text-decoration: none;
        color: #64748b;
        font-size: 0.7rem;
        font-weight: 800;
        min-height: 56px;
    }
    .bottom-nav a i { font-size: 1.35rem; }
    .bottom-nav a.active { color: #0d9488; }
    .bottom-nav a.nav-center { position: relative; top: -12px; }
    .bottom-nav a.nav-center .nav-center-btn {
        width: 56px; height: 56px; border-radius: 18px;
        background: linear-gradient(135deg, #f59e0b, #d97706);
        color: #fff; display: grid; place-items: center;
        font-size: 1.45rem;
        box-shadow: 0 6px 14px rgba(245,158,11,.35);
        border: 3px solid #fff;
    }
    .bottom-nav a.nav-center span { display: none; }
    .bottom-nav a.nav-center.active .nav-center-btn {
        background: linear-gradient(135deg, #0d9488, #14b8a6);
    }

    .panel, .stat-card {
        border-radius: 18px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        box-shadow: 0 4px 12px rgba(13,148,136,0.1) !important;
    }
    .stat-card:hover { transform: none !important; }

    .app-tile { min-height: 100px !important; }

    .big-btn, .btn.big-btn {
        width: 100% !important;
        min-height: 56px !important;
        border-radius: 16px !important;
        font-weight: 800 !important;
    }
    .form-control, .form-select, .code-input {
        min-height: 52px !important;
        font-size: 16px !important;
        border-radius: 14px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    .chart-box { height: 200px !important; }
    .offline-bar { width: 100% !important; left: 0 !important; right: 0 !important; }

    /* Reduce motion / paint cost in app */
    .native-app .stat-card,
    .native-app .panel,
    .native-app .app-tile {
        box-shadow: 0 2px 8px rgba(13,148,136,0.08) !important;
    }
    .native-app .animate-in { animation: none !important; }
}

@media (min-width: 992px) {
    .mobile-only { display: none !important; }
    .bottom-nav { display: none !important; }
}

@media all and (display-mode: standalone) {
    .install-banner { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
