/* PWA Public Styles - Expert v4.1 (Design Sync & Responsive) */

:root {
    --pwa-main: #6e2d91;
    --pwa-sec: #00bef2;
    --pwa-dark: #0f0f12;
    --pwa-light: #ffffff;
    --pwa-glass: rgba(255, 255, 255, 0.05);
    /* Injected dynamic colors via JS/Inline styles in template possible, 
       but we define defaults here as fallback */
    --pwa-banner-bg: rgba(30, 30, 40, 0.95);
    --pwa-banner-text: #ffffff;
    --pwa-banner-btn: #6e2d91;
}

/* --- Loader --- */
#gestory-pwa-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999999;
    transition: opacity 0.5s;
    opacity: 1;
}

#gestory-pwa-loader.fade-out {
    opacity: 0;
    pointer-events: none;
}

#gestory-pwa-loader.theme-dark {
    background: var(--pwa-dark);
    color: #fff;
}

#gestory-pwa-loader.theme-light {
    background: #f8f9fa;
    color: #333;
}

#gestory-pwa-loader.theme-glass {
    background: rgba(15, 15, 18, 0.85);
    backdrop-filter: blur(25px);
    color: #fff;
}

.loader-content {
    text-align: center;
    max-width: 80%;
}

.loader-logo {
    width: var(--pwa-logo-size, 80px);
    height: var(--pwa-logo-size, 80px);
    border-radius: var(--pwa-logo-radius, 20px);
    margin-bottom: 16px;
    object-fit: contain;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    background: transparent;
    display: block;
}

.loader-message {
    font-family: 'Inter', sans-serif;
    font-size: 1.1rem;
    font-weight: 500;
    margin-top: 20px;
}

/* 1. Orbit Loader */
.loader-orbit {
    width: 60px;
    height: 60px;
    margin: 0 auto;
    position: relative;
}

.orbit-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 2px solid var(--pwa-main);
    border-radius: 50%;
    border-right-color: transparent;
    border-bottom-color: transparent;
    animation: pwaSpin 1s linear infinite;
}

.orbit-core {
    position: absolute;
    top: 15px;
    left: 15px;
    width: 30px;
    height: 30px;
    background: var(--pwa-sec);
    border-radius: 50%;
    opacity: 0.6;
    animation: pwaPulse 1.2s infinite ease-in-out;
}

@keyframes pwaSpin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes pwaPulse {
    0% {
        transform: scale(0.8);
        opacity: 0.4;
    }

    100% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

/* --- Install Banner (SMART & RESPONSIVE) --- */
#gestory-pwa-install-banner {
    position: fixed;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    width: calc(100% - 40px);
    max-width: 450px;
    background: var(--pwa-banner-bg);
    color: var(--pwa-banner-text);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 20px;
    z-index: 999999;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    gap: 15px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

#gestory-pwa-install-banner.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

#gestory-pwa-install-banner.pos-bottom {
    bottom: 25px;
}

#gestory-pwa-install-banner.pos-top {
    top: 25px;
}

/* Giant Icon Fix - STRICTURE SIZE */
.banner-icon-wrap {
    flex-shrink: 0;
    width: 56px;
    height: 56px;
}

.banner-icon {
    width: 56px !important;
    height: 56px !important;
    border-radius: 12px;
    object-fit: cover;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.banner-info {
    flex: 1;
    min-width: 0;
}

.banner-title {
    font-weight: 800;
    font-size: 1.05rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.banner-desc {
    font-size: 0.85rem;
    opacity: 0.8;
    line-height: 1.3;
}

.btn-install {
    background: var(--pwa-banner-btn);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: 0.2s;
    white-space: nowrap;
}

.btn-install:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.btn-close {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #222;
    color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.1);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

/* STYLE: COMPACT */
#gestory-pwa-install-banner.compact {
    padding: 10px 16px;
    border-radius: 50px;
    max-width: 380px;
}

#gestory-pwa-install-banner.compact .banner-desc {
    display: none;
}

#gestory-pwa-install-banner.compact .banner-icon-wrap,
#gestory-pwa-install-banner.compact .banner-icon {
    width: 36px !important;
    height: 36px !important;
}

#gestory-pwa-install-banner.compact .banner-title {
    font-size: 0.95rem;
}

/* STYLE: FLOATING ICON */
#gestory-pwa-install-banner.floating_icon {
    width: 64px;
    height: 64px;
    padding: 0;
    border-radius: 18px;
    justify-content: center;
    overflow: visible;
    left: auto;
    right: 25px;
    transform: translateY(20px);
}

#gestory-pwa-install-banner.floating_icon.visible {
    transform: translateY(0);
}

#gestory-pwa-install-banner.floating_icon .banner-info,
#gestory-pwa-install-banner.floating_icon .banner-actions {
    display: none;
}

#gestory-pwa-install-banner.floating_icon .banner-icon-wrap,
#gestory-pwa-install-banner.floating_icon .banner-icon {
    width: 64px !important;
    height: 64px !important;
    border-radius: 18px;
}

/* Mobile Adjustments */
@media (max-width: 480px) {
    #gestory-pwa-install-banner {
        width: calc(100% - 30px);
        padding: 15px;
    }

    .banner-title {
        font-size: 1rem;
    }

    .banner-desc {
        font-size: 0.8rem;
    }

    .banner-icon-wrap,
    .banner-icon {
        width: 48px !important;
        height: 48px !important;
    }
}

/* === PREMIUM LOADERS === */

/* 4. Pulse Loader */
.loader-pulse {
    width: 60px;
    height: 60px;
    background: var(--pwa-theme-color, #6e2d91);
    border-radius: 50%;
    animation: pwaPulseScale 1.8s infinite;
    box-shadow: 0 0 0 0 rgba(110, 45, 145, 0.7);
}

@keyframes pwaPulseScale {
    0% {
        box-shadow: 0 0 0 0 rgba(110, 45, 145, 0.7);
    }

    50% {
        box-shadow: 0 0 0 30px rgba(110, 45, 145, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(110, 45, 145, 0);
    }
}

/* 5. Wave Loader */
.loader-wave {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 60px;
}

.loader-wave span {
    width: 6px;
    background: var(--pwa-theme-color, #6e2d91);
    border-radius: 3px;
    animation: pwaWave 1.2s infinite ease-in-out;
}

.loader-wave span:nth-child(1) {
    animation-delay: 0s;
}

.loader-wave span:nth-child(2) {
    animation-delay: 0.1s;
}

.loader-wave span:nth-child(3) {
    animation-delay: 0.2s;
}

.loader-wave span:nth-child(4) {
    animation-delay: 0.3s;
}

.loader-wave span:nth-child(5) {
    animation-delay: 0.4s;
}

@keyframes pwaWave {

    0%,
    100% {
        height: 10px;
    }

    50% {
        height: 40px;
    }
}

/* 6. Dots Loader */
.loader-dots {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
}

.loader-dots span {
    width: 12px;
    height: 12px;
    background: var(--pwa-theme-color, #6e2d91);
    border-radius: 50%;
    animation: pwaBounceDots 1.4s infinite;
}

.loader-dots span:nth-child(1) {
    animation-delay: 0s;
}

.loader-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.loader-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pwaBounceDots {

    0%,
    100% {
        transform: translateY(0);
        opacity: 0.6;
    }

    50% {
        transform: translateY(-20px);
        opacity: 1;
    }
}

/* 7. Glitch Loader */
.loader-glitch {
    font-size: 3rem;
    font-weight: 900;
    color: var(--pwa-theme-color, #6e2d91);
    position: relative;
    text-transform: uppercase;
    letter-spacing: 2px;
    animation: pwaGlitch 2s infinite;
}

.loader-glitch::before,
.loader-glitch::after {
    content: 'Gestory+';
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
}

.loader-glitch::before {
    animation: pwaGlitch1 2s infinite;
    color: #00bef2;
    z-index: -1;
}

.loader-glitch::after {
    animation: pwaGlitch2 2s infinite;
    color: #ff006e;
    z-index: -2;
}

@keyframes pwaGlitch {

    0%,
    100% {
        text-shadow: none;
    }

    50% {
        text-shadow: -2px 0 #ff006e, 2px 0 #00bef2;
    }
}

@keyframes pwaGlitch1 {
    0% {
        clip-path: polygon(0 0, 100% 0, 100% 0%, 0 0%);
        transform: translate(0);
    }

    20% {
        clip-path: polygon(0 0, 100% 0, 100% 20%, 0 20%);
        transform: translate(-2px, 2px);
    }

    100% {
        clip-path: polygon(0 0, 100% 0, 100% 0%, 0 0%);
        transform: translate(0);
    }
}

@keyframes pwaGlitch2 {
    0% {
        clip-path: polygon(0 100%, 100% 100%, 100% 100%, 0 100%);
        transform: translate(0);
    }

    20% {
        clip-path: polygon(0 80%, 100% 80%, 100% 100%, 0 100%);
        transform: translate(2px, -2px);
    }

    100% {
        clip-path: polygon(0 100%, 100% 100%, 100% 100%, 0 100%);
        transform: translate(0);
    }
}

/* 8. Ring Loader */
.loader-ring {
    width: 60px;
    height: 60px;
    position: relative;
}

.loader-ring::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid rgba(110, 45, 145, 0.2);
    border-top-color: var(--pwa-theme-color, #6e2d91);
    border-radius: 50%;
    animation: pwaRingSpin 0.8s linear infinite;
}

@keyframes pwaRingSpin {
    to {
        transform: rotate(360deg);
    }
}

/* Progress Bar - Enhanced */
.loader-progress {
    width: 120px;
    height: 4px;
    background: rgba(110, 45, 145, 0.1);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.loader-progress-inner {
    height: 100%;
    background: linear-gradient(90deg, var(--pwa-theme-color, #6e2d91), #00bef2);
    border-radius: 10px;
    animation: pwaProgressFill 2.5s ease-in-out infinite;
}

@keyframes pwaProgressFill {
    0% {
        width: 0%;
    }

    50% {
        width: 100%;
    }

    100% {
        width: 100%;
    }
}

/* --- Update Toast (Hot-Reload) --- */
#pwa-update-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    background: #1e1e28;
    color: #fff;
    padding: 14px 22px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    gap: 15px;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    font-family: 'Inter', sans-serif;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#pwa-update-toast.visible {
    transform: translateY(0);
    opacity: 1;
}

#pwa-update-toast .pwa-update-text {
    font-size: 0.95rem;
    font-weight: 500;
}

#pwa-update-toast-btn {
    background: var(--pwa-theme-color, #6e2d91);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 700;
    transition: 0.2s;
}

#pwa-update-toast-btn:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

/* Loader Footer */
.loader-footer {
    position: absolute;
    bottom: 30px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 0.8rem;
    opacity: 0.5;
    color: inherit;
    font-family: sans-serif;
    letter-spacing: 0.5px;
}

/* --- ANALYTICS VIEW FIXES (Universal Mobile Fix) --- */

/* 1. Container Margins & Padding */
@media (max-width: 768px) {
    /* Target common main wrappers and body content area */
    main.pwa-main, 
    .gestory-analytics-wrapper,
    div[class*="analytics"],
    div[class*="content"],
    .preview-container, /* Adding preview container for consistent testing */
    .pwa-admin-container /* Adding admin container */
    {
        padding-left: 20px !important;
        padding-right: 20px !important; 
        box-sizing: border-box;
        overflow-x: hidden; /* Prevent horizontal scroll */
    }

    /* Fix for cards hitting edges */
    .stat-card, 
    .chart-container, 
    .info-box,
    .analytics-card,
    .section /* Generic section wrapper */
    {
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100% !important;
        box-sizing: border-box;
        max-width: 100% !important;
    }
}

/* 2. Responsive Charts (Canvas) */
canvas, 
.chart-canvas,
.chart-container canvas {
    max-width: 100% !important;
    height: auto !important;
    display: block; /* Removes inline spacing issues */
}

/* 3. Grid Adjustments for Stats */
@media (max-width: 600px) {
    .grid-stats,
    .analytics-grid,
    .stats-row,
    .preview-content .loaders-grid, /* Specific target for preview grid */
    .preview-content .badge-grid,   /* Specific target for badge grid */
    .compatibility-grid
    {
        display: grid !important;
        grid-template-columns: 1fr !important; /* Stack vertically on small screens */
        gap: 15px !important;
    }
    
    /* If they use flex, force column */
    .flex-row,
    .stats-flex {
        flex-direction: column !important;
    }
}

/* 4. Text Readability & Safety */
.stat-value, 
.chart-title,
h1, h2, h3,
.banner-title,
.banner-desc {
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal; /* Ensure text wraps */
}