/* ============================================================
   MATRONICS PWA — native app feel on phones & tablets
   (standalone / Add to Home Screen)
   ============================================================ */

:root {
    --pwa-safe-top: env(safe-area-inset-top, 0px);
    --pwa-safe-bottom: env(safe-area-inset-bottom, 0px);
    --pwa-safe-left: env(safe-area-inset-left, 0px);
    --pwa-safe-right: env(safe-area-inset-right, 0px);
}

html {
    -webkit-text-size-adjust: 100%;
}

html.pwa-standalone {
    -webkit-tap-highlight-color: rgba(79, 70, 229, 0.15);
    overscroll-behavior-y: none;
}

html.pwa-standalone body {
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    overscroll-behavior-y: none;
    touch-action: manipulation;
}

html.pwa-standalone .app-container {
    min-height: 100dvh;
    min-height: -webkit-fill-available;
}

html.pwa-standalone .sidebar {
    padding-top: var(--pwa-safe-top);
    padding-bottom: var(--pwa-safe-bottom);
    padding-left: var(--pwa-safe-left);
}

html.pwa-standalone .main-content {
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    padding-bottom: var(--pwa-safe-bottom);
}

html.pwa-standalone .topbar {
    padding-top: calc(10px + var(--pwa-safe-top));
    padding-left: calc(16px + var(--pwa-safe-left));
    padding-right: calc(16px + var(--pwa-safe-right));
    position: sticky;
    top: 0;
    z-index: 900;
    background: var(--bg-secondary, #f8fafc);
}

html.pwa-standalone .page-content {
    padding-left: calc(var(--page-padding, 24px) + var(--pwa-safe-left));
    padding-right: calc(var(--page-padding, 24px) + var(--pwa-safe-right));
}

html.pwa-standalone .modal {
    padding-top: calc(20px + var(--pwa-safe-top));
    padding-bottom: calc(20px + var(--pwa-safe-bottom));
}

/* Install banner — respect iPhone home indicator */
#pwaInstallBanner {
    padding-bottom: calc(12px + var(--pwa-safe-bottom)) !important;
    padding-left: calc(14px + var(--pwa-safe-left)) !important;
    padding-right: calc(14px + var(--pwa-safe-right)) !important;
}

#pwaInstallBanner.pwa-install-visible {
    display: flex !important;
}

/* iOS install walkthrough sheet */
#pwaIosSheet {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100000;
    background: rgba(15, 23, 42, 0.55);
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}

#pwaIosSheet.open {
    display: flex;
}

#pwaIosSheet .pwa-ios-panel {
    background: #fff;
    width: 100%;
    max-width: 480px;
    border-radius: 20px 20px 0 0;
    padding: 20px 20px calc(24px + var(--pwa-safe-bottom));
    animation: pwaSheetUp 0.28s ease;
}

@keyframes pwaSheetUp {
    from { transform: translateY(100%); opacity: 0.6; }
    to { transform: translateY(0); opacity: 1; }
}

#pwaIosSheet .pwa-ios-step {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 12px 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: 14px;
    color: #334155;
    line-height: 1.45;
}

#pwaIosSheet .pwa-ios-step:last-child {
    border-bottom: none;
}

#pwaIosSheet .pwa-ios-num {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #eef2ff;
    color: #4f46e5;
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Login page in standalone */
html.pwa-standalone body.login-page,
html.pwa-standalone .login-page body {
    padding-top: var(--pwa-safe-top);
    padding-bottom: var(--pwa-safe-bottom);
    min-height: 100dvh;
}

/* Tablets — sidebar stays overlay like phone when narrow */
@media (min-width: 768px) and (max-width: 1024px) {
    html.pwa-standalone .page-content {
        max-width: 100%;
    }
}

/* Prevent double-tap zoom delay on buttons (keeps pinch-zoom for accessibility) */
html.pwa-standalone button,
html.pwa-standalone .btn,
html.pwa-standalone a.btn {
    touch-action: manipulation;
}
