/* SICMS PWA Enhancement Styles */

/* PWA-Specific Styles */
.pwa-installed {
    /* Hide browser-specific UI when running as PWA */
}

.pwa-installed .browser-only {
    display: none !important;
}

/* iOS PWA Status Bar */
@supports (-webkit-touch-callout: none) {
    .pwa-installed {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Offline Status Indicator */
.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #e74c3c;
    color: white;
    text-align: center;
    padding: 8px;
    font-size: 0.85rem;
    z-index: 9999;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.offline .offline-indicator {
    transform: translateY(0);
}

.offline-indicator::before {
    content: "📵 ";
    margin-right: 8px;
}

/* Pull-to-Refresh Enhancement */
.pull-to-refresh {
    position: relative;
    overflow: hidden;
}

.pull-to-refresh::before {
    content: "⬇️ Pull to refresh";
    position: absolute;
    top: -60px;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--secondary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: transform 0.3s ease;
    z-index: 10;
}

.pull-to-refresh.pulling::before {
    transform: translateY(100%);
}

/* Enhanced Touch Targets for PWA */
@media (max-width: 768px) {
    /* Larger touch targets */
    .btn, .nav-link, .dropdown-item, .page-link {
        min-height: 48px;
        min-width: 48px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 12px 16px;
    }
    
    /* Form controls */
    .form-control, .form-select {
        min-height: 48px;
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px 16px;
    }
    
    /* Checkbox and radio inputs */
    input[type="checkbox"], 
    input[type="radio"] {
        min-width: 24px;
        min-height: 24px;
        transform: scale(1.2);
        margin: 8px;
    }
    
    /* Table improvements for mobile */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    .table th, .table td {
        padding: 16px 12px;
        font-size: 14px;
        line-height: 1.4;
    }
    
    /* Modal improvements */
    .modal-dialog {
        margin: 10px;
        max-width: calc(100vw - 20px);
    }
    
    .modal-content {
        border-radius: 12px;
        max-height: calc(100vh - 40px);
        overflow-y: auto;
    }
    
    .modal-header, .modal-footer {
        padding: 16px 20px;
    }
    
    .modal-body {
        padding: 20px;
    }
}

/* PWA Install Button Styles */
.pwa-install-btn {
    animation: none !important;
    transition: all 0.3s ease;
    border-radius: 20px !important;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
}

.pwa-install-btn:hover {
    background-color: rgba(52, 152, 219, 0.15) !important;
    border-color: #3498db !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.4);
}

.pwa-install-btn.pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
    }
    50% {
        box-shadow: 0 2px 8px rgba(52, 152, 219, 0.6), 0 0 0 8px rgba(52, 152, 219, 0.1);
    }
    100% {
        box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
    }
}

/* Connection Status Styles */
.connection-status {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: rgba(44, 62, 80, 0.95);
    backdrop-filter: blur(10px);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    text-align: center;
    transform: translateY(100px);
    transition: transform 0.3s ease;
    z-index: 1000;
    max-width: 400px;
    margin: 0 auto;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
}

.connection-status.show {
    transform: translateX(-50%) translateY(0);
}

.connection-status.online {
    background: rgba(39, 174, 96, 0.95);
}

.connection-status.offline {
    background: rgba(231, 76, 60, 0.95);
}

/* Loading States for PWA */
.loading-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Dark theme skeleton for SICMS */
.loading-skeleton {
    background: linear-gradient(90deg, #3d3d3d 25%, #4d4d4d 50%, #3d3d3d 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 4px;
    height: 20px;
    margin: 8px 0;
}

/* PWA Splash Screen Simulation */
.pwa-splash {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #1a1d23 0%, #2c3e50 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.pwa-splash.hide {
    opacity: 0;
    pointer-events: none;
}

.pwa-splash .logo {
    width: 120px;
    height: 120px;
    background: var(--secondary-color);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 20px;
    box-shadow: 0 10px 30px rgba(52, 152, 219, 0.3);
}

.pwa-splash .title {
    color: white;
    font-size: 28px;
    font-weight: bold;
    margin-bottom: 10px;
}

.pwa-splash .subtitle {
    color: #bdc3c7;
    font-size: 16px;
    margin-bottom: 40px;
}

.pwa-splash .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(52, 152, 219, 0.3);
    border-top: 3px solid var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Better Focus Indicators for Accessibility */
*:focus {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

button:focus,
.btn:focus,
input:focus,
select:focus,
textarea:focus {
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.3);
}

/* Improved Scroll Behavior */
html {
    scroll-behavior: smooth;
}

/* Handle safe areas for notched devices */
@supports (padding: max(0px)) {
    .main-content {
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
    }
    
    .navbar {
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
    }
}

/* Install Popup Styles (Mobile & Desktop) */
.mobile-install-popup {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    transform: translateZ(0) translateY(100%);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    pointer-events: none;
    will-change: transform;
    opacity: 1;
}

/* Force hide state */
.mobile-install-popup:not(.show) {
    transform: translateZ(0) translateY(100%) !important;
    pointer-events: none !important;
}

/* Explicit show state for mobile */
.mobile-install-popup.show {
    transform: translateZ(0) translateY(0) !important;
    pointer-events: all !important;
}

/* Desktop popup styling */
@media (min-width: 769px) {
    .mobile-install-popup {
        bottom: auto;
        top: 50%;
        left: 50%;
        right: auto;
        width: 480px;
        max-width: 90vw;
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0;
        transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    }
    
    .mobile-install-popup.show {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
        pointer-events: all;
    }
    
    .mobile-install-content {
        border-radius: 16px !important;
        border-top: 2px solid #3498db;
    }
}

/* Mobile show state */
@media (max-width: 768px) {
    .mobile-install-popup.show {
        transform: translateZ(0) translateY(0);
        pointer-events: all;
    }
}

.popup-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}

.mobile-install-popup.show .popup-backdrop {
    opacity: 1;
    pointer-events: all;
}

/* Ensure buttons are clickable */
.mobile-install-content {
    pointer-events: all;
    z-index: 10001;
}

.btn-install-mobile,
.btn-cancel-mobile,
.close-popup {
    pointer-events: all !important;
    z-index: 10002 !important;
    position: relative !important;
}

.mobile-install-content {
    background: linear-gradient(135deg, #1a1d23 0%, #2c3e50 100%);
    border-radius: 20px 20px 0 0;
    padding: 24px;
    margin: 0 auto;
    max-width: 480px;
    position: relative;
    box-shadow: 
        0 -10px 30px rgba(0, 0, 0, 0.4),
        0 -2px 10px rgba(0, 0, 0, 0.2);
    border-top: 2px solid #3498db;
    color: #ffffff !important;
}

/* Ensure popup content is crystal clear - no blur effects */
.mobile-install-content,
.mobile-install-content *,
.install-header,
.install-header *,
.install-benefits,
.install-benefits *,
.install-actions,
.install-actions * {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Clear text rendering */
.mobile-install-content {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Override any inherited SICMS styles specifically for the mobile popup */
.mobile-install-popup h1,
.mobile-install-popup h2,
.mobile-install-popup h3,
.mobile-install-popup h4,
.mobile-install-popup h5,
.mobile-install-popup h6 {
    color: #ffffff !important;
}

.mobile-install-popup p,
.mobile-install-popup span,
.mobile-install-popup div {
    color: #ecf0f1 !important;
}

.mobile-install-popup button {
    font-family: inherit !important;
}

.install-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    position: relative;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.app-icon {
    margin-right: 16px;
    flex-shrink: 0;
    position: relative;
}

.app-icon img {
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.app-info {
    flex: 1;
}

.app-name {
    color: #ffffff !important;
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 4px 0;
    line-height: 1.2;
}

.app-description {
    color: #bdc3c7 !important;
    font-size: 14px;
    margin: 0;
    line-height: 1.3;
    font-weight: 400;
}

.close-popup {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.1) !important;
    color: #bdc3c7 !important;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
}

.close-popup:hover {
    background: rgba(231, 76, 60, 0.2) !important;
    color: #e74c3c !important;
    transform: scale(1.1);
}

.install-benefits {
    margin-bottom: 24px;
}

.benefit-item {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    color: #ecf0f1 !important;
    font-size: 14px;
    font-weight: 400;
}

.benefit-item:last-child {
    margin-bottom: 0;
}

.benefit-item i {
    color: #3498db !important;
    font-size: 16px;
    margin-right: 12px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.benefit-item span {
    color: #ecf0f1 !important;
    line-height: 1.4;
}

.install-actions {
    display: flex;
    gap: 12px;
    flex-direction: column;
}

.btn-install-mobile {
    background: #3498db !important;
    color: white !important;
    border: none !important;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

.btn-install-mobile:hover {
    background: #2980b9 !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(52, 152, 219, 0.3);
}

.btn-install-mobile:active {
    transform: translateY(0);
    background: #1f4e79 !important;
    box-shadow: 0 2px 4px rgba(52, 152, 219, 0.2);
}

.btn-install-mobile:focus {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}

.btn-cancel-mobile {
    background: transparent !important;
    color: #bdc3c7 !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-cancel-mobile:hover {
    background: rgba(255, 255, 255, 0.05) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    color: #ecf0f1 !important;
    transform: translateY(-1px);
}

.btn-cancel-mobile:active {
    transform: translateY(0);
    background: rgba(255, 255, 255, 0.1) !important;
}

.btn-cancel-mobile:focus {
    outline: 2px solid #bdc3c7;
    outline-offset: 2px;
}

/* Desktop install button removed - using popup only */

/* Desktop install button no longer used */
@media (max-width: 768px) {
    .mobile-install-content {
        padding: 20px;
        margin: 0 8px;
        border-radius: 16px 16px 0 0;
    }
    
    .app-name {
        font-size: 18px;
    }
    
    .install-actions {
        gap: 10px;
    }
    
    .btn-install-mobile {
        padding: 14px 20px;
        font-size: 15px;
    }
    
    .btn-cancel-mobile {
        padding: 12px 20px;
    }
}

/* Show desktop button only on larger screens */
@media (min-width: 769px) {
    .mobile-install-popup {
        display: none !important;
    }
}

/* Mobile Install Popup Animations */
@keyframes slideUpIn {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

.mobile-install-popup.show .mobile-install-content {
    animation: slideUpIn 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.mobile-install-popup.hiding .mobile-install-content {
    animation: slideDownOut 0.3s cubic-bezier(0.55, 0.06, 0.68, 0.19);
}

/* Improve mobile touch feedback */
.btn-install-mobile:active,
.btn-cancel-mobile:active,
.close-popup:active {
    transform: scale(0.98);
}

/* Add subtle vibration effect for install button */
@keyframes vibrate {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

.btn-install-mobile.vibrate {
    animation: vibrate 0.3s ease-in-out;
}

/* Complete blur fix for all popup content */
.mobile-install-popup,
.mobile-install-popup *,
.mobile-install-content,
.mobile-install-content *,
.install-header,
.install-header *,
.install-benefits,
.install-benefits *,
.install-actions,
.install-actions *,
.app-icon,
.app-icon *,
.benefit-item,
.benefit-item *,
.btn-install-mobile,
.btn-cancel-mobile {
    -webkit-backface-visibility: hidden !important;
    backface-visibility: hidden !important;
    -webkit-perspective: 1000px !important;
    perspective: 1000px !important;
    -webkit-transform: translate3d(0, 0, 0) !important;
    transform: translate3d(0, 0, 0) !important;
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
    text-rendering: optimizeLegibility !important;
    will-change: auto !important;
}

/* Mobile-specific improvements - NO BLUR */
@media (max-width: 480px) {
    .mobile-install-content {
        margin: 0;
        border-radius: 18px 18px 0 0;
        padding: 20px;
        -webkit-font-smoothing: antialiased !important;
        -moz-osx-font-smoothing: grayscale !important;
        filter: none !important;
        -webkit-filter: none !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
    
    /* Force no blur on all mobile content */
    .mobile-install-popup *,
    .mobile-install-content *,
    .install-header *,
    .install-benefits *,
    .install-actions *,
    .benefit-item *,
    .app-info *,
    .btn-install-mobile *,
    .btn-cancel-mobile * {
        filter: none !important;
        -webkit-filter: none !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        -webkit-font-smoothing: antialiased !important;
        -moz-osx-font-smoothing: grayscale !important;
        text-rendering: optimizeLegibility !important;
    }
}
    
    .install-header {
        margin-bottom: 18px;
        padding-bottom: 14px;
    }
    
    .app-icon img {
        width: 56px;
        height: 56px;
    }
    
    .app-name {
        font-size: 18px;
    }
    
    .app-description {
        font-size: 13px;
    }
    
    .install-benefits {
        margin-bottom: 20px;
    }
    
    .benefit-item {
        font-size: 13px;
        margin-bottom: 10px;
    }
    
    .benefit-item i {
        font-size: 14px;
    }
    
    .install-actions {
        gap: 10px;
    }
    
    .btn-install-mobile {
        padding: 12px 20px;
        font-size: 15px;
    }
    
    .btn-cancel-mobile {
        padding: 12px 20px;
        font-size: 14px;
    }
}

/* Large mobile devices */
@media (max-width: 768px) and (min-width: 481px) {
    .mobile-install-content {
        margin: 0 12px;
        border-radius: 20px 20px 0 0;
    }
    
    .app-icon img {
        width: 60px;
        height: 60px;
    }
}

/* Landscape mobile */
@media (max-height: 600px) and (orientation: landscape) {
    .mobile-install-content {
        padding: 18px;
    }
    
    .install-header {
        margin-bottom: 14px;
        padding-bottom: 10px;
    }
    
    .install-benefits {
        margin-bottom: 14px;
    }
    
    .benefit-item {
        margin-bottom: 8px;
        font-size: 13px;
    }
    
    .install-actions {
        gap: 8px;
    }
    
    .btn-install-mobile {
        padding: 10px 20px;
        font-size: 14px;
    }
    
    .btn-cancel-mobile {
        padding: 10px 20px;
        font-size: 13px;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    .mobile-install-popup,
    .popup-backdrop,
    .mobile-install-content {
        transition: none;
        animation: none;
    }
    
    .btn-install-mobile::before,
    .pwa-install-btn {
        animation: none !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .mobile-install-content {
        border: 2px solid #ffffff;
    }
    
    .btn-install-mobile {
        border: 2px solid #ffffff;
    }
    
    .btn-cancel-mobile {
        border: 2px solid #bdc3c7;
    }
}

/* Dark mode adjustments */
@media (prefers-color-scheme: light) {
    .mobile-install-content {
        background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
        color: #212529;
    }
    
    .app-name {
        color: #212529;
    }
    
    .app-description {
        color: #6c757d;
    }
    
    .benefit-item {
        color: #495057;
    }
    
    .btn-cancel-mobile {
        color: #6c757d;
        border-color: #dee2e6;
    }
    
    .btn-cancel-mobile:hover {
        background: rgba(108, 117, 125, 0.1);
        color: #495057;
    }
    
    .close-popup {
        color: #6c757d;
        background: rgba(108, 117, 125, 0.1);
    }
}

/* PWA-specific button styles */
.install-app-banner {
    background: linear-gradient(45deg, var(--secondary-color), #2980b9);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    margin: 10px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
    position: relative;
    overflow: hidden;
}

.install-app-banner::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.install-app-banner:hover::before {
    left: 100%;
}

.install-app-banner .btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    margin-top: 8px;
}

.install-app-banner .btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}