/**
 * PWA styles — splash, install UI, standalone native feel
 */

/* ============================================
   Standalone / native app shell
   ============================================ */
html {
    -webkit-tap-highlight-color: transparent;
}

body {
    overscroll-behavior-y: none;
    -webkit-overflow-scrolling: touch;
}

body.pwa-standalone {
    background-color: var(--white);
}

body.pwa-standalone .main-content {
    padding-top: env(safe-area-inset-top, 0px);
}

body.pwa-standalone .mobile-header {
    padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
    min-height: calc(var(--mobile-header-height) + env(safe-area-inset-top, 0px));
}

body.pwa-standalone .mobile-nav {
    padding-bottom: calc(0.35rem + env(safe-area-inset-bottom, 0px));
    height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px));
}

body.pwa-standalone .page-content {
    padding-bottom: 0.5rem;
}

body.pwa-standalone .login-page {
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    min-height: 100dvh;
}

@supports (padding: max(0px)) {
    body.pwa-standalone .mobile-nav {
        padding-bottom: max(0.35rem, env(safe-area-inset-bottom));
    }
}

/* ============================================
   Splash screen
   ============================================ */
.pwa-splash {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--white);
    transition: opacity 0.35s ease, visibility 0.35s ease;
}

.pwa-splash.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.pwa-splash-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transform: scale(1.02);
}

.pwa-splash-overlay {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.72) 0%,
        rgba(255, 255, 255, 0.88) 45%,
        rgba(255, 255, 255, 0.96) 100%
    );
    text-align: center;
    padding: 2rem;
}

.pwa-splash-logo {
    width: 96px;
    height: 96px;
    border-radius: 22px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    margin-bottom: 1rem;
}

.pwa-splash-name {
    font-size: 1.35rem;
    font-weight: 700;
    color: #212529;
    letter-spacing: -0.02em;
}

.pwa-splash-spinner {
    width: 28px;
    height: 28px;
    margin-top: 1.5rem;
    border: 3px solid rgba(var(--primary-rgb), 0.15);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: pwaSpin 0.8s linear infinite;
}

@keyframes pwaSpin {
    to { transform: rotate(360deg); }
}

/* ============================================
   Install prompt — bottom sheet + menu card
   ============================================ */
.pwa-install-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--mobile-nav-height, 70px) + 0.75rem + env(safe-area-inset-bottom, 0px));
    z-index: 1050;
    padding: 0 0.875rem;
    pointer-events: none;
    opacity: 0;
    transform: translateY(110%);
    transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.28s ease;
}

body.logged-out .pwa-install-sheet {
    bottom: calc(0.875rem + env(safe-area-inset-bottom, 0px));
}

.pwa-install-sheet.is-visible {
    pointer-events: auto;
    opacity: 1;
    transform: translateY(0);
}

.pwa-install-sheet-card {
    position: relative;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 20px;
    padding: 1rem 1rem 0.875rem;
    box-shadow:
        0 4px 6px rgba(0, 0, 0, 0.04),
        0 16px 40px rgba(0, 0, 0, 0.12);
}

.pwa-install-sheet-close {
    position: absolute;
    top: 0.65rem;
    right: 0.65rem;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.06);
    color: #6c757d;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0;
    transition: background 0.15s ease;
}

.pwa-install-sheet-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #495057;
}

.pwa-install-sheet-top {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding-right: 1.75rem;
    margin-bottom: 0.875rem;
}

.pwa-install-sheet-icon {
    flex-shrink: 0;
    border-radius: 14px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.pwa-install-sheet-copy {
    min-width: 0;
}

.pwa-install-sheet-title {
    font-size: 1.0625rem;
    font-weight: 700;
    color: #212529;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.pwa-install-sheet-sub {
    margin-top: 0.2rem;
    font-size: 0.8125rem;
    color: #6c757d;
    line-height: 1.35;
}

.pwa-install-sheet-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    border: none;
    border-radius: 14px;
    padding: 0.8rem 1rem;
    background: var(--primary);
    color: #fff;
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1;
    transition: background 0.15s ease, transform 0.15s ease;
}

.pwa-install-sheet-cta:hover,
.pwa-install-sheet-cta:focus {
    background: var(--primary-hover);
    color: #fff;
}

.pwa-install-sheet-cta:active {
    transform: scale(0.98);
}

.pwa-install-sheet-cta-icon {
    font-size: 1.125rem;
}

/* Off-canvas menu promo (always available when sheet dismissed) */
.pwa-menu-promo {
    padding: 0.75rem 1rem 0;
}

.pwa-menu-promo-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    border: 1px solid rgba(var(--primary-rgb), 0.15);
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(var(--primary-rgb), 0.07), rgba(var(--primary-rgb), 0.02));
    padding: 0.75rem 0.875rem;
    text-align: left;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.pwa-menu-promo-btn:hover,
.pwa-menu-promo-btn:focus {
    background: linear-gradient(135deg, rgba(var(--primary-rgb), 0.11), rgba(var(--primary-rgb), 0.04));
    border-color: rgba(var(--primary-rgb), 0.25);
}

.pwa-menu-promo-icon {
    flex-shrink: 0;
    border-radius: 10px;
}

.pwa-menu-promo-copy {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.pwa-menu-promo-title {
    font-size: 0.9375rem;
    font-weight: 700;
    color: #212529;
}

.pwa-menu-promo-sub {
    font-size: 0.75rem;
    color: #6c757d;
}

.pwa-menu-promo-arrow {
    flex-shrink: 0;
    color: var(--primary);
    font-size: 0.875rem;
}

body.pwa-standalone .pwa-install-sheet,
body.pwa-standalone .pwa-menu-promo {
    display: none !important;
}

/* ============================================
   iOS install guide modal + SVG animation
   ============================================ */
.pwa-ios-modal .modal-content {
    border: none;
    border-radius: var(--radius-xl);
    overflow: hidden;
}

.pwa-ios-guide {
    max-width: 280px;
    margin: 0 auto;
}

.pwa-ios-guide svg {
    width: 100%;
    height: auto;
    display: block;
}

.pwa-ios-steps li {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.55rem 0;
    font-size: 0.9375rem;
    color: #495057;
}

.pwa-step-num {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 1px;
}

/* SVG animation sequence */
.pwa-ios-share-btn {
    animation: pwaIosHighlightShare 3.6s ease-in-out infinite;
}

.pwa-ios-sheet {
    opacity: 0;
    transform: translateY(12px);
    animation: pwaIosShowSheet 3.6s ease-in-out infinite;
}

.pwa-ios-a2hs-row {
    animation: pwaIosHighlightA2hs 3.6s ease-in-out infinite;
}

.pwa-ios-finger {
    animation: pwaIosFingerTap 3.6s ease-in-out infinite;
}

.pwa-ios-pulse-1 {
    animation: pwaIosPulse 3.6s ease-out infinite;
}

.pwa-ios-pulse-2 {
    animation: pwaIosPulseA2hs 3.6s ease-out infinite;
}

@keyframes pwaIosHighlightShare {
    0%, 18% { opacity: 1; }
    19%, 55% { opacity: 0.35; }
    56%, 100% { opacity: 1; }
}

@keyframes pwaIosShowSheet {
    0%, 20% { opacity: 0; transform: translateY(16px); }
    28%, 72% { opacity: 1; transform: translateY(0); }
    82%, 100% { opacity: 0; transform: translateY(16px); }
}

@keyframes pwaIosHighlightA2hs {
    0%, 45% { opacity: 0.35; }
    50%, 78% { opacity: 1; }
    85%, 100% { opacity: 0.35; }
}

@keyframes pwaIosFingerTap {
    0%, 12% { transform: translate(0, 0); opacity: 0; }
    16%, 24% { transform: translate(0, 0); opacity: 1; }
    28% { transform: translate(0, 3px) scale(0.92); opacity: 1; }
    32%, 44% { transform: translate(-64px, -92px); opacity: 1; }
    48% { transform: translate(-64px, -88px) scale(0.92); opacity: 1; }
    52%, 100% { transform: translate(-64px, -92px); opacity: 0; }
}

@keyframes pwaIosPulse {
    0%, 24% { opacity: 0; r: 8; }
    28% { opacity: 0.7; r: 8; }
    40% { opacity: 0; r: 22; }
    100% { opacity: 0; r: 22; }
}

@keyframes pwaIosPulseA2hs {
    0%, 46% { opacity: 0; r: 8; }
    50% { opacity: 0.7; r: 8; }
    62% { opacity: 0; r: 22; }
    100% { opacity: 0; r: 22; }
}

/* Hide splash quickly when not standalone */
body:not(.pwa-standalone) .pwa-splash {
    transition-duration: 0.2s;
}
