/* =========================================================================
   ControlPot Mobile App Experience
   Shared responsive styles for ALL dashboards and pages
   ========================================================================= */

/* Safe area for notch devices (iPhone X+) */
:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* Smooth scrolling everywhere */
html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior-y: contain;
}

/* PWA standalone mode adjustments */
@media (display-mode: standalone) {
    body {
        padding-top: var(--safe-top);
    }
    .wa-header, .admin-topbar, .app-header {
        padding-top: var(--safe-top);
    }
}

/* ============================================================
   PWA Install Banner
   ============================================================ */
.pwa-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #0F3D3E 0%, #0a2e2f 100%);
    color: white;
    padding: 16px 18px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 99999;
    box-shadow: 0 -4px 30px rgba(0,0,0,0.4);
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.pwa-install-banner.show {
    transform: translateY(0);
}

.pwa-install-banner .pwa-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
}

.pwa-install-banner .pwa-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pwa-install-banner .pwa-info {
    flex: 1;
    min-width: 0;
}

.pwa-install-banner .pwa-info strong {
    display: block;
    font-size: 14px;
    font-weight: 700;
}

.pwa-install-banner .pwa-info small {
    font-size: 11px;
    opacity: 0.8;
}

.pwa-install-btn {
    background: #25D366;
    color: white;
    border: none;
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.pwa-install-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.6);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    flex-shrink: 0;
}

/* ============================================================
   Admin Dashboard Mobile Overrides
   ============================================================ */
@media (max-width: 992px) {
    /* Sidebar overlay with backdrop */
    .admin-sidebar {
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .admin-sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 0 0 60px rgba(0,0,0,0.3);
    }

    .admin-main-content {
        margin-left: 0 !important;
    }

    /* Topbar compact */
    .admin-topbar {
        height: 56px;
        padding: 0 12px;
    }

    .topbar-breadcrumb span {
        font-size: 15px;
    }

    .admin-page-content {
        padding: 16px !important;
    }

    /* Sidebar overlay backdrop */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
        opacity: 0;
        transition: opacity 0.3s;
    }

    .sidebar-backdrop.active {
        display: block;
        opacity: 1;
    }

    /* Cards responsive */
    .premium-card {
        padding: 16px;
        border-radius: 12px;
    }

    .page-title-premium {
        font-size: 22px;
    }

    .page-header-premium {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
}

@media (max-width: 768px) {
    .admin-topbar {
        height: 52px;
        padding: 0 10px;
    }

    .topbar-right {
        gap: 8px;
    }

    .topbar-action-btn {
        width: 34px;
        height: 34px;
        font-size: 14px;
    }

    .admin-page-content {
        padding: 12px !important;
    }

    /* KPI cards stack */
    .dashboard-kpis, .stats-grid, .kpi-grid, .stat-cards {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }

    /* Tables scroll horizontal */
    .premium-card table,
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Forms full width */
    .form-row, .form-group-row {
        flex-direction: column !important;
    }

    input, select, textarea {
        font-size: 16px !important; /* Prevent iOS zoom */
    }
}

@media (max-width: 480px) {
    .dashboard-kpis, .stats-grid, .kpi-grid, .stat-cards {
        grid-template-columns: 1fr !important;
    }

    .page-title-premium {
        font-size: 20px;
    }
}

/* ============================================================
   Non-Admin Dashboard Mobile (Franqueado, Tecnico, Auditor)
   ============================================================ */
@media (max-width: 768px) {
    /* App header compact */
    .app-header {
        padding: 8px 12px;
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .app-header .header-content {
        gap: 8px;
    }

    .app-header h1 {
        font-size: 16px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Quick menu as full-width bottom sheet */
    .quick-menu {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        max-height: 70vh;
        overflow-y: auto;
        background: white;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -10px 40px rgba(0,0,0,0.2);
        padding: 20px 16px;
        padding-bottom: calc(20px + var(--safe-bottom));
        z-index: 10001;
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .quick-menu-item {
        border-radius: 12px !important;
        padding: 14px 12px !important;
        text-align: center;
        flex-direction: column;
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 12px;
    }

    .quick-menu-icon {
        font-size: 24px;
    }

    /* Dashboard cards */
    .dashboard-card, .stat-card, .card {
        border-radius: 12px;
        padding: 14px;
    }

    /* Franchise dashboard */
    .dashboard-franqueado .stat-cards {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    /* Technician dashboard */
    .tecnico-dashboard .stat-cards {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    /* Auditor dashboard */
    .auditor-dashboard .stat-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    /* Buttons touch-friendly */
    .btn, button, a.btn, .quick-menu-item {
        min-height: 44px;
    }

    /* Footer compact on logged pages */
    footer {
        padding: 20px 16px !important;
    }

    footer > div {
        flex-direction: column !important;
        gap: 20px !important;
    }

    /* WhatsApp float - smaller on mobile */
    .whatsapp-float {
        bottom: 15px;
        right: 15px;
        padding: 10px;
        border-radius: 50%;
    }
}

/* ============================================================
   Maintenance Wizard Mobile (Public - /m/ routes)
   ============================================================ */
@media (max-width: 768px) {
    .manutencao-container, .etapa-container {
        padding: 16px;
        margin: 0;
        border-radius: 0;
    }

    .etapa-header h2 {
        font-size: 18px;
    }

    .video-upload-area {
        padding: 20px;
    }
}

/* ============================================================
   Auth Pages Mobile
   ============================================================ */
@media (max-width: 480px) {
    .auth-page {
        padding: 16px;
        align-items: flex-start;
        padding-top: 60px;
    }

    .login-box {
        padding: 24px;
        border-radius: 16px;
    }
}

/* ============================================================
   Catalog / Public Pages Mobile
   ============================================================ */
@media (max-width: 768px) {
    .product-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
        padding: 0 10px;
    }
}

@media (max-width: 400px) {
    .product-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================================
   Smooth Transitions & Touch Optimizations
   ============================================================ */

/* Remove 300ms click delay */
a, button, input, select, textarea {
    touch-action: manipulation;
}

/* Scrollbar hiding for clean mobile look */
.filters-bar::-webkit-scrollbar,
.uso-filter-chips::-webkit-scrollbar,
.quick-menu::-webkit-scrollbar {
    display: none;
}

.filters-bar,
.uso-filter-chips,
.quick-menu {
    scrollbar-width: none;
}

/* Pull-to-refresh style overscroll */
body {
    overscroll-behavior: contain;
}

/* Selection color */
::selection {
    background: rgba(15, 61, 62, 0.2);
}
