/**
 * MongezPOS PWA Offline Styles
 * Styles for offline mode indicators, sync status, and PWA UI elements
 */

/* ========================================
   Offline Banner
   ======================================== */
.offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 99999;
    font-weight: 500;
    font-size: 14px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

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

/* Push content down when offline banner is visible */
body .wrapper {
    transition: padding-top 0.3s ease;
}

body.offline-mode .wrapper {
    padding-top: 40px;
}

.offline-banner i {
    font-size: 1.2em;
}

.offline-banner .pending-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 600;
}

.offline-banner .btn-sync-now {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.offline-banner .btn-sync-now:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ========================================
   Sync Status Indicator
   ======================================== */
.sync-status-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: white;
    border-radius: 50px;
    padding: 12px 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 99998;
    transition: all 0.3s ease;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

.sync-status-indicator.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.sync-status-indicator.syncing {
    background: #3b82f6;
    color: white;
}

.sync-status-indicator.syncing .sync-spinner {
    animation: spin 1s linear infinite;
}

.sync-status-indicator.success {
    background: #10b981;
    color: white;
}

.sync-status-indicator.error {
    background: #ef4444;
    color: white;
}

.sync-status-indicator.pending {
    background: #f59e0b;
    color: white;
}

.sync-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ========================================
   Offline Transaction Badge
   ======================================== */
.offline-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f59e0b;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.offline-badge i {
    font-size: 10px;
}

.offline-badge.synced {
    background: #10b981;
}

.offline-badge.failed {
    background: #ef4444;
}

/* ========================================
   Pending Sync List
   ======================================== */
.pending-sync-list {
    max-height: 350px;
    overflow-y: auto;
}

.pending-sync-item {
    padding: 12px 15px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.pending-sync-item:hover {
    background: #f9fafb;
}

.pending-sync-item:last-child {
    border-bottom: none;
}

.pending-sync-item .item-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.pending-sync-item .item-title {
    font-weight: 600;
    color: #1f2937;
    font-size: 14px;
}

.pending-sync-item .item-meta {
    font-size: 12px;
    color: #6b7280;
}

.pending-sync-item .type-badge {
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.pending-sync-item .type-badge.sell {
    background: #dbeafe;
    color: #1d4ed8;
}

.pending-sync-item .type-badge.purchase {
    background: #dcfce7;
    color: #15803d;
}

.pending-sync-item .type-badge.expense {
    background: #fef3c7;
    color: #b45309;
}

.pending-sync-item .type-badge.contact {
    background: #f3e8ff;
    color: #7c3aed;
}

.pending-sync-item .type-badge.stock_adjustment {
    background: #fce7f3;
    color: #be185d;
}

.pending-sync-item .retry-count {
    font-size: 11px;
    color: #dc2626;
    margin-left: 8px;
}

/* ========================================
   PWA Install Prompt
   ======================================== */
.pwa-install-prompt {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    max-width: 400px;
    background: white;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 99999;
    display: none;
}

.pwa-install-prompt.visible {
    display: block;
    animation: slideUp 0.3s ease;
}

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

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

.pwa-install-prompt .prompt-icon {
    width: 48px;
    height: 48px;
    background: #0f766e;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pwa-install-prompt .prompt-icon img {
    width: 32px;
    height: 32px;
}

.pwa-install-prompt h4 {
    margin: 0;
    font-size: 18px;
    color: #1f2937;
}

.pwa-install-prompt p {
    color: #6b7280;
    font-size: 14px;
    margin: 0 0 16px 0;
    line-height: 1.5;
}

.pwa-install-prompt .prompt-actions {
    display: flex;
    gap: 10px;
}

.pwa-install-prompt .btn-install {
    flex: 1;
    background: #0f766e;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: background 0.2s;
}

.pwa-install-prompt .btn-install:hover {
    background: #115e59;
}

.pwa-install-prompt .btn-dismiss {
    background: #f3f4f6;
    color: #374151;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    transition: background 0.2s;
}

.pwa-install-prompt .btn-dismiss:hover {
    background: #e5e7eb;
}

/* ========================================
   Sync Dashboard Modal
   ======================================== */
.sync-dashboard .info-box-icon {
    width: 70px;
}

.sync-dashboard .sync-progress {
    background: #f3f4f6;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
}

.sync-dashboard .progress-bar-container {
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 10px;
}

.sync-dashboard .progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #0f766e, #14b8a6);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.sync-dashboard .sync-stats {
    display: flex;
    justify-content: space-around;
    text-align: center;
    padding: 15px 0;
}

.sync-dashboard .sync-stat {
    flex: 1;
}

.sync-dashboard .sync-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: #1f2937;
}

.sync-dashboard .sync-stat-label {
    font-size: 12px;
    color: #6b7280;
    margin-top: 4px;
}

.sync-dashboard .last-sync-info {
    background: #f0fdfa;
    border: 1px solid #99f6e4;
    border-radius: 8px;
    padding: 12px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.sync-dashboard .last-sync-info i {
    color: #0f766e;
    font-size: 18px;
}

.sync-dashboard .last-sync-info .info-text {
    flex: 1;
}

.sync-dashboard .last-sync-info .info-label {
    font-size: 12px;
    color: #6b7280;
}

.sync-dashboard .last-sync-info .info-value {
    font-weight: 600;
    color: #1f2937;
}

/* ========================================
   Offline Receipt
   ======================================== */
.offline-receipt {
    border: 2px dashed #f59e0b;
    padding: 15px;
    margin: 10px 0;
    background: #fffbeb;
}

.offline-receipt .offline-warning {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #92400e;
}

.offline-receipt .offline-warning i {
    font-size: 18px;
    color: #d97706;
}

.offline-receipt .temp-invoice-notice {
    text-align: center;
    font-size: 12px;
    color: #6b7280;
    padding: 10px;
    background: #f3f4f6;
    border-radius: 4px;
    margin-top: 10px;
}

/* ========================================
   Online Status Indicator in Header
   ======================================== */
.online-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
}

.online-status-dot.online {
    background: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.online-status-dot.offline {
    background: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.1);
    }
}

/* ========================================
   Data Refresh Indicator
   ======================================== */
.data-refresh-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.data-refresh-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.data-refresh-content {
    background: white;
    border-radius: 16px;
    padding: 30px;
    text-align: center;
    max-width: 300px;
}

.data-refresh-content .refresh-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #e5e7eb;
    border-top-color: #0f766e;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

.data-refresh-content h4 {
    margin: 0 0 10px 0;
    color: #1f2937;
}

.data-refresh-content p {
    margin: 0;
    color: #6b7280;
    font-size: 14px;
}

.data-refresh-content .refresh-progress {
    margin-top: 15px;
    font-size: 12px;
    color: #6b7280;
}

/* ========================================
   Conflict Resolution UI
   ======================================== */
.conflict-item {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 10px;
}

.conflict-item .conflict-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.conflict-item .conflict-title {
    font-weight: 600;
    color: #991b1b;
}

.conflict-item .conflict-actions {
    display: flex;
    gap: 8px;
}

.conflict-item .btn-resolve {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 4px;
    cursor: pointer;
    border: none;
    font-weight: 500;
}

.conflict-item .btn-use-local {
    background: #3b82f6;
    color: white;
}

.conflict-item .btn-use-server {
    background: #6b7280;
    color: white;
}

.conflict-item .conflict-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 10px;
}

.conflict-item .conflict-version {
    background: white;
    border-radius: 6px;
    padding: 10px;
}

.conflict-item .conflict-version-label {
    font-size: 11px;
    color: #6b7280;
    text-transform: uppercase;
    margin-bottom: 8px;
}

/* ========================================
   Responsive Adjustments
   ======================================== */
@media (max-width: 768px) {
    .offline-banner {
        padding: 8px 12px;
        font-size: 12px;
    }

    .sync-status-indicator {
        bottom: 10px;
        right: 10px;
        left: 10px;
        padding: 10px 15px;
        justify-content: center;
    }

    .pwa-install-prompt {
        left: 10px;
        right: 10px;
        bottom: 10px;
        padding: 15px;
    }

    .pwa-install-prompt .prompt-actions {
        flex-direction: column;
    }

    .sync-dashboard .sync-stats {
        flex-wrap: wrap;
    }

    .sync-dashboard .sync-stat {
        flex: 0 0 50%;
        margin-bottom: 10px;
    }
}

/* ========================================
   Load Data Prompt
   ======================================== */
.pwa-load-data-prompt {
    position: fixed;
    top: 60px;
    right: 20px;
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    padding: 12px 16px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.4);
    z-index: 99998;
    max-width: 400px;
    animation: slideInRight 0.3s ease;
}

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

.pwa-load-data-prompt .load-data-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.pwa-load-data-prompt i.fa-database {
    font-size: 1.5em;
}

.pwa-load-data-prompt span {
    flex: 1;
    font-size: 14px;
    min-width: 150px;
}

.pwa-load-data-prompt .btn {
    padding: 6px 12px;
    font-size: 12px;
}

.pwa-load-data-prompt .btn-primary {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
}

.pwa-load-data-prompt .btn-primary:hover {
    background: rgba(255, 255, 255, 0.3);
}

.pwa-load-data-prompt .btn-default {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    padding: 6px;
}

.pwa-load-data-prompt .btn-default:hover {
    color: white;
}

/* RTL Support */
[dir="rtl"] .pwa-load-data-prompt {
    right: auto;
    left: 20px;
}

/* ========================================
   Print Styles - Hide offline elements
   ======================================== */
@media print {
    .offline-banner,
    .sync-status-indicator,
    .pwa-install-prompt,
    .pwa-load-data-prompt,
    .data-refresh-overlay {
        display: none !important;
    }

    .offline-receipt .offline-warning {
        border: 1px solid #000;
        background: none;
    }
}
