/**
 * PWA Install Button Styles for CliveMart
 */

/**
 * Global Page Loading Styles for CliveMart
 */

/* Global Mobile Scrolling Fixes - Apply to all mobile devices */
@media (max-width: 768px), (hover: none) and (pointer: coarse) {
    html {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
        height: auto !important;
        min-height: 100vh !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
        height: auto !important;
        min-height: 100vh !important;
        margin: 0 !important;
        padding: 0 !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior-y: none !important;
        -webkit-overscroll-behavior-y: none !important;
    }
    
    /* Prevent any element from causing horizontal scroll */
    * {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Common elements that cause overflow */
    .container, .container-fluid, .row, .col, [class*="col-"] {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    /* Media elements */
    img, video, iframe, canvas, svg, picture {
        max-width: 100% !important;
        height: auto !important;
    }
    
    /* Layout elements */
    .navbar, .header, .footer, .main, .content, .wrapper {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
}

/* Install Button Container */
.pwa-install-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    align-items: center;
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    border-radius: 50px;
    box-shadow: 0 4px 20px rgba(0, 123, 255, 0.3);
    padding: 4px;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.pwa-install-container.pwa-install-show {
    transform: translateY(0);
    opacity: 1;
}

/* Install Button */
.pwa-install-btn {
    background: transparent;
    border: none;
    color: white;
    padding: 12px 20px;
    border-radius: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
    outline: none;
    user-select: none;
}

.pwa-install-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.02);
}

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

/* Install Button Icon */
.pwa-install-icon {
    font-size: 18px;
    line-height: 1;
    animation: pulse-icon 2s infinite;
}

@keyframes pulse-icon {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Install Button Text */
.pwa-install-text {
    white-space: nowrap;
    font-weight: 600;
}

/* Close Button */
.pwa-install-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    margin-left: 8px;
    transition: all 0.2s ease;
    outline: none;
}

.pwa-install-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* Instruction Modal */
.pwa-instruction-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.pwa-modal-content {
    background: white;
    border-radius: 16px;
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pwa-modal-header {
    padding: 20px 24px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.pwa-modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: #333;
}

.pwa-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.pwa-modal-close:hover {
    background: #f5f5f5;
    color: #333;
}

.pwa-modal-body {
    padding: 20px 24px;
    color: #555;
    line-height: 1.6;
}

.pwa-modal-body ol {
    margin: 16px 0;
    padding-left: 20px;
}

.pwa-modal-body li {
    margin-bottom: 8px;
}

.pwa-modal-body strong {
    color: #007bff;
    font-weight: 600;
}

.pwa-modal-footer {
    padding: 0 24px 24px;
    display: flex;
    justify-content: center;
}

.pwa-modal-btn {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
}

.pwa-modal-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

/* Success Message */
.pwa-success-message {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10001;
    animation: slideInRight 0.3s ease;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.pwa-success-content {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    padding: 16px 20px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 20px rgba(40, 167, 69, 0.3);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.pwa-success-icon {
    font-size: 20px;
}

.pwa-success-text {
    font-weight: 600;
    font-size: 14px;
}

/* Hide install button on mobile devices */
@media (max-width: 768px), 
       (hover: none) and (pointer: coarse),
       (max-device-width: 768px) {
    .pwa-install-container {
        display: none !important;
    }
    
    /* Fix mobile scrolling issues */
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
    
    /* Prevent extra white space on mobile */
    body {
        position: relative !important;
        min-height: 100vh !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Ensure content doesn't create horizontal overflow */
    * {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Fix for elements that might cause overflow */
    .container, .row, .col, .content {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    /* Prevent bounce scrolling and white space */
    html {
        -webkit-overflow-scrolling: touch !important;
    }
    
    body {
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: none !important;
        -webkit-overscroll-behavior: none !important;
    }
    
    /* Fix for iOS Safari bounce scrolling */
    .main-content, .page-content, main {
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* Prevent horizontal scroll on any element */
    img, video, iframe, canvas, svg {
        max-width: 100% !important;
        height: auto !important;
    }
    
    /* Additional mobile fixes for browser view */
    html {
        height: auto !important;
        min-height: 100vh !important;
    }
    
    body {
        height: auto !important;
        min-height: 100vh !important;
    }
    
    /* Prevent any element from extending beyond viewport */
    .container-fluid, .container, .row, .col-* {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    /* Fix for common Bootstrap/framework issues */
    .navbar, .header, .footer, .main, .content {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    
    .pwa-install-btn {
        padding: 14px 20px;
        font-size: 16px;
        flex: 1;
        justify-content: center;
    }
    
    .pwa-install-text {
        font-size: 16px;
    }
    
    .pwa-modal-content {
        margin: 20px;
        width: calc(100% - 40px);
    }
    
    .pwa-success-message {
        top: 16px;
        right: 16px;
        left: 16px;
    }
}

@media (max-width: 480px) {
    .pwa-install-container {
        bottom: 12px;
        left: 12px;
        right: 12px;
    }
    
    .pwa-modal-content {
        margin: 16px;
        width: calc(100% - 32px);
    }
    
    .pwa-modal-header,
    .pwa-modal-body,
    .pwa-modal-footer {
        padding-left: 20px;
        padding-right: 20px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .pwa-modal-content {
        background: #1a1a1a;
        color: #e0e0e0;
    }
    
    .pwa-modal-header h3 {
        color: #e0e0e0;
    }
    
    .pwa-modal-body {
        color: #b0b0b0;
    }
    
    .pwa-modal-close {
        color: #b0b0b0;
    }
    
    .pwa-modal-close:hover {
        background: #333;
        color: #e0e0e0;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .pwa-install-container {
        border: 2px solid white;
    }
    
    .pwa-install-btn {
        border: 1px solid rgba(255, 255, 255, 0.5);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .pwa-install-container,
    .pwa-install-btn,
    .pwa-modal-content,
    .pwa-success-message {
        animation: none;
        transition: none;
    }
    
    .pwa-install-icon {
        animation: none;
    }
}

/* Standalone PWA Styles */
@media (display-mode: standalone), (display-mode: fullscreen) {
    /* Hide install button when app is already installed */
    .pwa-install-container {
        display: none !important;
    }
    
    /* Force fullscreen behavior - but allow natural content height */
    html {
        width: 100vw !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow-x: hidden !important;
        min-height: 100vh !important;
        min-height: 100dvh !important;
    }
    
    body {
        width: 100vw !important;
        margin: 0 !important;
        padding: 0 !important;
        padding-top: env(safe-area-inset-top) !important;
        padding-bottom: env(safe-area-inset-bottom) !important;
        padding-left: env(safe-area-inset-left) !important;
        padding-right: env(safe-area-inset-right) !important;
        overflow-x: hidden !important;
        position: relative !important;
        min-height: 100vh !important;
        min-height: 100dvh !important;
    }
    
    /* Remove any browser-specific margins and UI elements */
    * {
        -webkit-tap-highlight-color: transparent !important;
        -webkit-touch-callout: none !important;
        -webkit-user-select: none !important;
        user-select: none !important;
    }
    
    /* Allow text selection for inputs and content areas */
    input, textarea, [contenteditable], .selectable {
        -webkit-user-select: text !important;
        user-select: text !important;
    }
}

/* iOS Safari standalone mode specific styles */
@media (display-mode: standalone) and (-webkit-touch-callout: none) {
    /* Status bar area styling for iOS */
    .header, .navbar, .top-bar {
        padding-top: calc(env(safe-area-inset-top) + 10px);
    }
    
    /* Bottom safe area for iOS home indicator */
    .footer, .bottom-nav, .fixed-bottom {
        padding-bottom: calc(env(safe-area-inset-bottom) + 10px);
    }
}

/* Android standalone mode specific styles */
@media (display-mode: standalone) and (not (-webkit-touch-callout: none)) {
    /* Android specific adjustments */
    .header, .navbar {
        padding-top: 10px;
    }
}

/* Fullscreen mode styles */
@media (display-mode: fullscreen) {
    body {
        padding: 0;
        margin: 0;
    }
    
    .pwa-install-container {
        display: none !important;
    }
}

/* Window controls overlay for desktop PWA */
@media (display-mode: window-controls-overlay) {
    .header, .navbar {
        padding-left: env(titlebar-area-x);
        padding-right: calc(100vw - env(titlebar-area-x) - env(titlebar-area-width));
        padding-top: env(titlebar-area-height);
    }
    
    .pwa-install-container {
        display: none !important;
    }
}

/* PWA Update Banner */
.pwa-update-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10002;
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    padding: 12px 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    animation: slideDownUpdate 0.3s ease;
}

@keyframes slideDownUpdate {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.pwa-update-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1200px;
    margin: 0 auto;
}

.pwa-update-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pwa-update-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

/* Standalone mode body class styles */
.pwa-standalone {
    /* Disable text selection for native app feel */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    
    /* Disable callouts on iOS */
    -webkit-touch-callout: none;
    
    /* Prevent zoom */
    -ms-touch-action: manipulation;
    touch-action: manipulation;
    
    /* Smooth scrolling */
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Allow text selection for specific elements in standalone mode */
.pwa-standalone input,
.pwa-standalone textarea,
.pwa-standalone [contenteditable],
.pwa-standalone .selectable,
.pwa-standalone p,
.pwa-standalone span,
.pwa-standalone div.content {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Native-like transitions in standalone mode */
.pwa-standalone * {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    -webkit-tap-highlight-color: transparent;
}

/* Button and link styling for native feel */
.pwa-standalone button,
.pwa-standalone .btn,
.pwa-standalone a.button {
    -webkit-appearance: none;
    appearance: none;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.pwa-standalone button:active,
.pwa-standalone .btn:active,
.pwa-standalone a.button:active {
    transform: scale(0.98);
    opacity: 0.8;
}

/* Hide scrollbars in standalone mode for cleaner look */
.pwa-standalone::-webkit-scrollbar {
    display: none;
}

.pwa-standalone {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Status bar spacing for different devices */
@supports (padding-top: env(safe-area-inset-top)) {
    .pwa-standalone .header,
    .pwa-standalone .navbar,
    .pwa-standalone .top-bar {
        padding-top: calc(env(safe-area-inset-top) + 10px);
    }
    
    .pwa-standalone .footer,
    .pwa-standalone .bottom-nav,
    .pwa-standalone .fixed-bottom {
        padding-bottom: calc(env(safe-area-inset-bottom) + 10px);
    }
}

/* Landscape mode adjustments for standalone */
@media (orientation: landscape) and (display-mode: standalone) {
    .pwa-standalone .header,
    .pwa-standalone .navbar {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

/* PWA Install Modal */
.pwa-install-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10003;
    backdrop-filter: blur(10px);
    animation: fadeInModal 0.3s ease;
}

@keyframes fadeInModal {
    from {
        opacity: 0;
        backdrop-filter: blur(0px);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(10px);
    }
}

.pwa-install-modal-content {
    background: white;
    border-radius: 20px;
    padding: 40px 30px;
    text-align: center;
    max-width: 350px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUpModal 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUpModal {
    from {
        opacity: 0;
        transform: translateY(50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.pwa-install-modal-content h3 {
    margin: 20px 0 10px;
    font-size: 22px;
    font-weight: 600;
    color: #333;
}

.pwa-install-modal-content p {
    margin: 0 0 30px;
    color: #666;
    line-height: 1.5;
}

/* Install Spinner */
.pwa-install-spinner {
    width: 60px;
    height: 60px;
    margin: 0 auto 20px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    animation: spinInstall 1s linear infinite;
}

@keyframes spinInstall {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Install Progress Bar */
.pwa-install-progress {
    width: 100%;
    height: 6px;
    background: #f0f0f0;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 20px;
}

.pwa-install-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #0056b3);
    border-radius: 3px;
    width: 0%;
    animation: progressInstall 3s ease-in-out forwards;
}

@keyframes progressInstall {
    0% { width: 0%; }
    30% { width: 30%; }
    60% { width: 70%; }
    100% { width: 100%; }
}

/* Dark mode for install modal */
@media (prefers-color-scheme: dark) {
    .pwa-install-modal-content {
        background: #1a1a1a;
        color: #e0e0e0;
    }
    
    .pwa-install-modal-content h3 {
        color: #e0e0e0;
    }
    
    .pwa-install-modal-content p {
        color: #b0b0b0;
    }
    
    .pwa-install-progress {
        background: #333;
    }
}
