/* ==========================================================
   ACMOBOOK PWA — iOS-like Progressive Web App Experience
========================================================== */

/* ----------------------------------------------------------
   Safe Area & Standalone Mode
---------------------------------------------------------- */

: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);
    --pwa-nav-height: calc(74px + var(--pwa-safe-bottom));
    --pwa-header-height: calc(74px + var(--pwa-safe-top));
    --pwa-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --pwa-ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --pwa-ease-ios: cubic-bezier(0.32, 0.72, 0, 1);
    --pwa-duration: 0.35s;
}

html {
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

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

.pwa-standalone .acmo-mobile-header {
    padding-top: var(--pwa-safe-top);
    height: var(--pwa-header-height);
}

.pwa-standalone .mobile-bottom-nav {
    padding-bottom: var(--pwa-safe-bottom);
    height: var(--pwa-nav-height);
}

.pwa-standalone .site-main,
.pwa-standalone main {
    padding-bottom: calc(92px + var(--pwa-safe-bottom));
}

/* ----------------------------------------------------------
   View Transitions
---------------------------------------------------------- */

::view-transition-old(root) {
    animation: pwa-fade-out 0.28s var(--pwa-ease-ios) both;
}

::view-transition-new(root) {
    animation: pwa-fade-in 0.28s var(--pwa-ease-ios) both;
}

@keyframes pwa-fade-out {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(-30px); }
}

@keyframes pwa-fade-in {
    from { opacity: 0; transform: translateX(30px); }
    to   { opacity: 1; transform: translateX(0); }
}

.pwa-page-exit {
    animation: pwa-page-exit 0.28s var(--pwa-ease-ios) forwards;
}

.pwa-page-enter {
    animation: pwa-page-enter 0.32s var(--pwa-ease-ios) both;
}

@keyframes pwa-page-exit {
    to { opacity: 0; transform: translateX(-20px); }
}

@keyframes pwa-page-enter {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ----------------------------------------------------------
   Page Skeleton Loaders
---------------------------------------------------------- */

.pwa-page-skeleton {
    padding: 20px 16px;
    animation: pwa-fade-in 0.2s ease;
}

.pwa-skeleton-header {
    margin-bottom: 24px;
}

.pwa-skeleton-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

@media (min-width: 576px) {
    .pwa-skeleton-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ----------------------------------------------------------
   Pull to Refresh
---------------------------------------------------------- */

.pwa-ptr-indicator {
    position: fixed;
    top: -60px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: transform 0.2s var(--pwa-ease-ios), opacity 0.2s;
    pointer-events: none;
    opacity: 0;
}

.pwa-ptr-indicator.pulling,
.pwa-ptr-indicator.refreshing {
    opacity: 1;
}

.pwa-ptr-spinner {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 4px 20px rgba(15, 23, 42, 0.12);
    color: #6C63FF;
}

.pwa-ptr-indicator.ready .pwa-ptr-spinner {
    transform: scale(1.1);
    color: #4F46E5;
}

.pwa-ptr-indicator.refreshing .pwa-ptr-spinner svg {
    animation: pwa-ptr-spin 0.8s linear infinite;
}

@keyframes pwa-ptr-spin {
    to { transform: rotate(360deg); }
}

.pwa-ptr-text {
    font-size: 12px;
    font-weight: 600;
    color: #64748B;
    white-space: nowrap;
}

/* ----------------------------------------------------------
   Edge Swipe Back Indicator
---------------------------------------------------------- */

.pwa-edge-back-indicator {
    position: fixed;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 99998;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(108, 99, 255, 0.15);
    border-radius: 50%;
    color: #6C63FF;
    font-size: 18px;
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
}

/* ----------------------------------------------------------
   Touch Feedback
---------------------------------------------------------- */

.touch-active {
    transform: scale(0.94) !important;
    opacity: 0.85;
    transition: transform 0.1s var(--pwa-ease-spring), opacity 0.1s !important;
}

.mobile-bottom-nav a,
.mobile-bottom-nav button,
.mobile-icon-btn,
.mobile-create-btn {
    transition: transform 0.15s var(--pwa-ease-spring), color 0.2s, background 0.2s;
    -webkit-user-select: none;
    user-select: none;
}

.mobile-bottom-nav a:active,
.mobile-bottom-nav button:active,
.mobile-icon-btn:active,
.mobile-create-btn:active {
    transform: scale(0.88);
}

/* ----------------------------------------------------------
   Enhanced Bottom Navigation (iOS Tab Bar)
---------------------------------------------------------- */

@media (max-width: 991px) {

    .mobile-bottom-nav {
        backdrop-filter: saturate(180%) blur(20px);
        -webkit-backdrop-filter: saturate(180%) blur(20px);
        background: rgba(255, 255, 255, 0.88);
        border-top: 0.5px solid rgba(0, 0, 0, 0.08);
        box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.04);
        transition: transform 0.3s var(--pwa-ease-ios);
    }

    .mobile-bottom-nav a,
    .mobile-bottom-nav button {
        position: relative;
        min-height: var(--touch-min, 44px);
        padding: 6px 0;
        font-size: 10px;
        font-weight: 500;
        letter-spacing: 0.01em;
        transition: color 0.2s, transform 0.15s var(--pwa-ease-spring);
    }

    .mobile-bottom-nav a.active,
    .mobile-bottom-nav button.active {
        color: #6C63FF;
        font-weight: 600;
    }

    .mobile-bottom-nav a.active::before,
    .mobile-bottom-nav button.active::before {
        content: '';
        position: absolute;
        top: 2px;
        left: 50%;
        transform: translateX(-50%);
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: #6C63FF;
    }

    .mobile-bottom-nav a.active i,
    .mobile-bottom-nav button.active i {
        transform: scale(1.08);
        transition: transform 0.2s var(--pwa-ease-spring);
    }

    .mobile-create-btn {
        width: 58px !important;
        height: 58px !important;
        margin-top: -28px;
        border: 3px solid #fff !important;
        box-shadow:
            0 8px 24px rgba(108, 99, 255, 0.4),
            0 2px 8px rgba(108, 99, 255, 0.2);
        transition: transform 0.2s var(--pwa-ease-spring), box-shadow 0.2s;
    }

    .mobile-create-btn:active {
        transform: scale(0.9) !important;
        box-shadow: 0 4px 12px rgba(108, 99, 255, 0.3);
    }

    .mobile-create-btn.active {
        transform: rotate(45deg);
    }

    /* Sticky header enhancements */
    .acmo-mobile-header {
        padding-top: var(--pwa-safe-top);
        height: var(--pwa-header-height);
        backdrop-filter: saturate(180%) blur(20px);
        -webkit-backdrop-filter: saturate(180%) blur(20px);
        background: rgba(255, 255, 255, 0.92);
        border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
        transition: transform 0.3s var(--pwa-ease-ios), box-shadow 0.3s;
    }

    .acmo-mobile-header.scrolled {
        box-shadow: 0 1px 12px rgba(15, 23, 42, 0.06);
    }

    .acmo-mobile-header.header-hidden {
        transform: translateY(-100%);
    }

    .mobile-search-wrap {
        top: var(--pwa-header-height);
        backdrop-filter: saturate(180%) blur(16px);
        -webkit-backdrop-filter: saturate(180%) blur(16px);
        background: rgba(255, 255, 255, 0.9);
        transition: top 0.3s var(--pwa-ease-ios);
    }

    /* Native sheet animations */
    .mobile-bottom-sheet {
        transition: bottom 0.4s var(--pwa-ease-ios), transform 0.3s var(--pwa-ease-ios);
        border-radius: 14px 14px 0 0;
    }

    .mobile-sheet-overlay,
    .mobile-overlay {
        transition: opacity 0.3s var(--pwa-ease-ios);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }

    .mobile-sidebar,
    .mobile-right-panel {
        transition: left 0.35s var(--pwa-ease-ios), right 0.35s var(--pwa-ease-ios), transform 0.3s var(--pwa-ease-ios);
        padding-top: var(--pwa-safe-top);
    }

    .mobile-sheet-body a {
        border-radius: 14px;
        transition: background 0.2s, transform 0.15s var(--pwa-ease-spring);
    }

    .mobile-sheet-body a:active {
        transform: scale(0.98);
        background: #EEF2FF;
    }

    .mobile-sheet-handle {
        width: 36px;
        height: 5px;
        background: rgba(0, 0, 0, 0.15);
        border-radius: 3px;
    }
}

/* ----------------------------------------------------------
   Install Banner
---------------------------------------------------------- */

.pwa-install-banner {
    position: fixed;
    bottom: calc(var(--pwa-nav-height, 74px) + 12px);
    left: 12px;
    right: 12px;
    z-index: 13000;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-radius: 16px;
    padding: 14px 16px;
    box-shadow:
        0 8px 32px rgba(15, 23, 42, 0.12),
        0 0 0 0.5px rgba(0, 0, 0, 0.06);
    transform: translateY(120%);
    opacity: 0;
    transition: transform 0.4s var(--pwa-ease-ios), opacity 0.4s;
}

.pwa-install-banner.visible {
    transform: translateY(0);
    opacity: 1;
}

.pwa-install-content {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.pwa-install-icon img {
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(108, 99, 255, 0.2);
}

.pwa-install-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pwa-install-text strong {
    font-size: 15px;
    font-weight: 700;
    color: #0F172A;
}

.pwa-install-text span {
    font-size: 13px;
    color: #64748B;
}

.pwa-install-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.pwa-install-dismiss {
    padding: 8px 16px;
    border: none;
    background: #F1F5F9;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    color: #64748B;
    cursor: pointer;
    transition: background 0.2s;
}

.pwa-install-btn {
    padding: 8px 20px;
    border: none;
    background: linear-gradient(135deg, #6C63FF, #1FA2FF);
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    transition: transform 0.15s var(--pwa-ease-spring);
}

.pwa-install-btn:active {
    transform: scale(0.96);
}

/* iOS Install Hint */
.pwa-ios-hint {
    position: fixed;
    bottom: calc(var(--pwa-nav-height, 74px) + 8px);
    left: 12px;
    right: 12px;
    z-index: 13001;
    transform: translateY(120%);
    opacity: 0;
    transition: transform 0.4s var(--pwa-ease-ios), opacity 0.4s;
}

.pwa-ios-hint.visible {
    transform: translateY(0);
    opacity: 1;
}

.pwa-ios-hint-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    background: #0F172A;
    color: #fff;
    border-radius: 14px;
    font-size: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.pwa-ios-hint-content i {
    font-size: 18px;
    vertical-align: middle;
}

.pwa-ios-hint-close {
    background: none;
    border: none;
    color: #94A3B8;
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

/* ----------------------------------------------------------
   Update Toast
---------------------------------------------------------- */

.pwa-update-toast {
    position: fixed;
    top: calc(var(--pwa-safe-top, 0px) + 12px);
    left: 50%;
    transform: translateX(-50%) translateY(-120%);
    z-index: 14000;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: #0F172A;
    color: #fff;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    transition: transform 0.4s var(--pwa-ease-ios);
}

.pwa-update-toast.visible {
    transform: translateX(-50%) translateY(0);
}

.pwa-update-btn {
    padding: 6px 14px;
    border: none;
    background: #6C63FF;
    color: #fff;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

/* ----------------------------------------------------------
   Offline Status Bar
---------------------------------------------------------- */

html.is-offline::before {
    content: 'No internet connection';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 15000;
    padding: calc(var(--pwa-safe-top, 0px) + 6px) 16px 6px;
    background: #EF4444;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    animation: pwa-slide-down 0.3s var(--pwa-ease-ios);
}

html.is-offline.pwa-standalone::before {
    padding-top: calc(var(--pwa-safe-top, 0px) + 6px);
}

@keyframes pwa-slide-down {
    from { transform: translateY(-100%); }
    to   { transform: translateY(0); }
}

/* ----------------------------------------------------------
   Offline Page
---------------------------------------------------------- */

.pwa-offline-page .site-main {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    padding-bottom: 120px;
}

.pwa-offline-container {
    text-align: center;
    padding: 40px 24px;
    max-width: 360px;
    margin: 0 auto;
}

.pwa-offline-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(108, 99, 255, 0.1), rgba(31, 162, 255, 0.1));
    border-radius: 24px;
    font-size: 36px;
    color: #6C63FF;
}

.pwa-offline-container h1 {
    font-size: 24px;
    font-weight: 800;
    color: #0F172A;
    margin-bottom: 12px;
}

.pwa-offline-container p {
    font-size: 15px;
    color: #64748B;
    line-height: 1.6;
    margin-bottom: 28px;
}

.pwa-offline-retry {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.pwa-offline-home {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #6C63FF;
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
}

/* ----------------------------------------------------------
   Responsive Layout Enhancements
---------------------------------------------------------- */

@media (max-width: 991px) {
    .footer {
        padding-bottom: calc(100px + var(--pwa-safe-bottom));
    }

    .site-main {
        padding-top: 0;
    }

    /* Card list responsive */
    .talent-card,
    .opportunity-card,
    .acmo-card {
        transition: transform 0.2s var(--pwa-ease-spring);
    }

    .talent-card:active,
    .opportunity-card:active,
    .acmo-card:active {
        transform: scale(0.98);
    }
}

/* Hide install banner on desktop */
@media (min-width: 992px) {
    .pwa-install-banner,
    .pwa-ios-hint,
    .pwa-ptr-indicator,
    .pwa-edge-back-indicator {
        display: none !important;
    }
}

/* Touch pressed & loading skeleton overlay */
.touch-pressed {
    transform: scale(0.94) !important;
    opacity: 0.85;
    transition: transform 0.1s var(--pwa-ease-spring), opacity 0.1s !important;
}

.is-loading {
    position: relative;
    overflow: hidden;
}

.is-loading > img {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.is-loading:not(.is-loading) > img {
    opacity: 1;
}

/* Reduce motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .pwa-page-enter,
    .pwa-page-exit {
        animation: none;
    }
}
