/**
 * Offline Mode Styles
 *
 * Styles for offline functionality including:
 * - Offline status indicator in header
 * - Download progress modal
 * - Offline banner
 * - Sync toast notifications
 */

/* ===========================================
   CSS Variables
   =========================================== */
:root {
    --offline-warning: #f5a623;
    --offline-error: #dc3545;
    --offline-success: #28a745;
    --offline-info: #368BC1;
    --offline-bg: rgba(0, 0, 0, 0.85);
}

/* ===========================================
   Offline Status Indicator (Header)
   =========================================== */
.offline-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.3s ease;
    cursor: pointer;
    margin-left: auto;
    margin-right: 10px;
}

/* Desktop: Center the offline badge in the top bar when offline */
@media (min-width: 769px) {
    body.is-offline .top .offline-indicator {
        position: absolute !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        order: unset !important;
        z-index: 100;
    }
}

.offline-indicator.hidden {
    display: none;
}

.offline-indicator.offline {
    background: rgba(245, 166, 35, 0.2);
    color: var(--offline-warning);
    border: 1px solid var(--offline-warning);
}

.offline-indicator.syncing {
    background: rgba(54, 139, 193, 0.2);
    color: var(--offline-info);
    border: 1px solid var(--offline-info);
}

.offline-indicator.error {
    background: rgba(220, 53, 69, 0.2);
    color: var(--offline-error);
    border: 1px solid var(--offline-error);
}

.offline-indicator__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.offline-indicator.offline .offline-indicator__dot {
    animation: pulse 2s infinite;
}

.offline-indicator.syncing .offline-indicator__dot {
    animation: spin 1s linear infinite;
    border: 2px solid currentColor;
    border-top-color: transparent;
    background: transparent;
}

.offline-indicator__text {
    white-space: nowrap;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

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

/* ===========================================
   Offline Banner (Below Header)
   =========================================== */
.offline-banner {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px 20px;
    background: linear-gradient(135deg, var(--offline-warning) 0%, #e6951d 100%);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    position: fixed;
    top: 52px; /* Below header - header is ~52px tall */
    left: 0;
    right: 0;
    z-index: 10001; /* Above header z-index (10000) */
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

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

.offline-banner__icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.offline-banner__text {
    flex: 1;
    text-align: center;
}

.offline-banner__dismiss {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s ease;
}

.offline-banner__dismiss:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Adjust content when banner is visible */
body.offline-banner-visible .content {
    padding-top: 40px;
}

/* ===========================================
   Download Progress Modal
   =========================================== */
.offline-download-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--offline-bg);
    z-index: 100001;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.offline-download-modal.visible {
    display: flex;
}

.offline-download-content {
    background: var(--bg-secondary, #fff);
    border-radius: 16px;
    padding: 30px;
    max-width: 450px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.offline-download-content h2 {
    margin: 0 0 10px;
    font-size: 22px;
    color: var(--text-primary, #333);
}

.offline-download-content p {
    margin: 0 0 25px;
    color: var(--text-secondary, #666);
    font-size: 14px;
    line-height: 1.5;
}

.offline-download-progress {
    background: var(--bg-tertiary, #e9ecef);
    border-radius: 10px;
    height: 20px;
    overflow: hidden;
    margin-bottom: 15px;
}

.offline-download-progress__bar {
    height: 100%;
    background: linear-gradient(90deg, var(--offline-info), #2d7bb4);
    border-radius: 10px;
    width: 0%;
    transition: width 0.3s ease;
}

.offline-download-progress__text {
    font-size: 14px;
    color: var(--text-secondary, #666);
    margin-bottom: 20px;
}

.offline-download-storage {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted, #999);
    margin-bottom: 20px;
}

.offline-download-storage__icon {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.offline-download-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.offline-download-btn {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.offline-download-btn--primary {
    background: var(--offline-info);
    color: #fff;
}

.offline-download-btn--primary:hover {
    background: #2d7bb4;
    transform: translateY(-1px);
}

.offline-download-btn--primary:disabled {
    background: var(--bg-tertiary, #ccc);
    cursor: not-allowed;
    transform: none;
}

.offline-download-btn--secondary {
    background: transparent;
    color: var(--text-secondary, #666);
    border: 1px solid var(--border-color, #ddd);
}

.offline-download-btn--secondary:hover {
    background: var(--bg-tertiary, #f5f5f5);
}

/* ===========================================
   Toast Notifications
   =========================================== */
.offline-toasts {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100002;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    max-width: 350px;
}

.offline-toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--bg-secondary, #fff);
    color: var(--text-primary, #333);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    font-size: 14px;
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
}

.offline-toast.visible {
    transform: translateX(0);
}

.offline-toast::before {
    content: '';
    width: 4px;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    border-radius: 8px 0 0 8px;
}

.offline-toast-success {
    border-left: 4px solid var(--offline-success);
}

.offline-toast-success::before {
    background: var(--offline-success);
}

.offline-toast-warning {
    border-left: 4px solid var(--offline-warning);
}

.offline-toast-warning::before {
    background: var(--offline-warning);
}

.offline-toast-error {
    border-left: 4px solid var(--offline-error);
}

.offline-toast-error::before {
    background: var(--offline-error);
}

.offline-toast-info {
    border-left: 4px solid var(--offline-info);
}

.offline-toast-info::before {
    background: var(--offline-info);
}

/* ===========================================
   Sync Status Dropdown
   =========================================== */
.offline-sync-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--bg-secondary, #fff);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    min-width: 280px;
    z-index: 100000;
    overflow: hidden;
}

.offline-sync-dropdown.visible {
    display: block;
}

.offline-sync-dropdown__header {
    padding: 15px;
    border-bottom: 1px solid var(--border-color, #eee);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.offline-sync-dropdown__title {
    font-weight: 600;
    color: var(--text-primary, #333);
    font-size: 14px;
}

.offline-sync-dropdown__status {
    font-size: 12px;
    color: var(--text-secondary, #666);
}

.offline-sync-dropdown__content {
    padding: 15px;
}

.offline-sync-stat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 13px;
}

.offline-sync-stat__label {
    color: var(--text-secondary, #666);
}

.offline-sync-stat__value {
    color: var(--text-primary, #333);
    font-weight: 500;
}

.offline-sync-dropdown__actions {
    padding: 15px;
    border-top: 1px solid var(--border-color, #eee);
    display: flex;
    gap: 10px;
}

.offline-sync-btn {
    flex: 1;
    padding: 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.offline-sync-btn--sync {
    background: var(--offline-info);
    color: #fff;
}

.offline-sync-btn--sync:hover {
    background: #2d7bb4;
}

.offline-sync-btn--clear {
    background: transparent;
    color: var(--offline-error);
    border: 1px solid var(--offline-error);
}

.offline-sync-btn--clear:hover {
    background: rgba(220, 53, 69, 0.1);
}

/* ===========================================
   Mobile Responsive
   =========================================== */
@media (max-width: 768px) {
    .offline-indicator {
        padding: 5px 8px;
    }

    .offline-indicator__text {
        display: none;
    }

    .offline-indicator__dot {
        width: 10px;
        height: 10px;
    }

    .offline-banner {
        top: 48px; /* Mobile header is slightly shorter */
        font-size: 12px;
        padding: 8px 15px;
    }

    .offline-toasts {
        bottom: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }

    .offline-download-content {
        padding: 20px;
    }

    .offline-download-content h2 {
        font-size: 18px;
    }

    .offline-sync-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        margin-top: 0;
        border-radius: 16px 16px 0 0;
        min-width: auto;
    }
}

/* ===========================================
   Sync Progress Modal
   =========================================== */
.sync-progress-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--offline-bg);
    z-index: 100001;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.sync-progress-modal.visible {
    display: flex;
}

.sync-progress-content {
    background: var(--bg-secondary, #fff);
    border-radius: 16px;
    padding: 30px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.sync-progress-header {
    text-align: center;
    margin-bottom: 24px;
}

.sync-progress-header h2 {
    margin: 0 0 8px;
    font-size: 20px;
    color: var(--text-primary, #333);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.sync-progress-header p {
    margin: 0;
    color: var(--text-secondary, #666);
    font-size: 14px;
}

.sync-progress-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--offline-info);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    display: inline-block;
}

/* Progress bar */
.sync-progress-bar-container {
    margin-bottom: 20px;
}

.sync-progress-bar {
    background: var(--bg-tertiary, #e9ecef);
    border-radius: 10px;
    height: 12px;
    overflow: hidden;
    margin-bottom: 8px;
}

.sync-progress-bar__fill {
    height: 100%;
    background: linear-gradient(90deg, var(--offline-info), #2d7bb4);
    border-radius: 10px;
    width: 0%;
    transition: width 0.3s ease;
}

.sync-progress-bar__text {
    font-size: 13px;
    color: var(--text-secondary, #666);
    text-align: center;
}

/* Sync items list */
.sync-progress-items {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.sync-progress-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-tertiary, #f8f9fa);
    border-radius: 8px;
    font-size: 14px;
}

.sync-progress-item__label {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary, #333);
}

.sync-progress-item__icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.sync-progress-item__count {
    font-weight: 600;
    color: var(--offline-info);
    min-width: 40px;
    text-align: right;
}

.sync-progress-item--pending .sync-progress-item__count {
    color: var(--text-secondary, #999);
}

.sync-progress-item--syncing .sync-progress-item__icon::after {
    content: '';
    width: 14px;
    height: 14px;
    border: 2px solid var(--offline-info);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.sync-progress-item--complete .sync-progress-item__icon {
    color: var(--offline-success);
}

.sync-progress-item--error .sync-progress-item__icon {
    color: var(--offline-error);
}

/* Sync status message */
.sync-progress-status {
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary, #666);
    padding: 12px;
    background: var(--bg-tertiary, #f8f9fa);
    border-radius: 8px;
    margin-bottom: 20px;
}

.sync-progress-status--success {
    background: rgba(40, 167, 69, 0.1);
    color: var(--offline-success);
}

.sync-progress-status--error {
    background: rgba(220, 53, 69, 0.1);
    color: var(--offline-error);
}

/* Footer actions */
.sync-progress-footer {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.sync-progress-btn {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    min-width: 100px;
}

.sync-progress-btn--primary {
    background: var(--offline-info);
    color: #fff;
}

.sync-progress-btn--primary:hover {
    background: #2d7bb4;
}

.sync-progress-btn--primary:disabled {
    background: var(--bg-tertiary, #ccc);
    cursor: not-allowed;
}

.sync-progress-btn--secondary {
    background: transparent;
    color: var(--text-secondary, #666);
    border: 1px solid var(--border-color, #ddd);
}

.sync-progress-btn--secondary:hover {
    background: var(--bg-tertiary, #f5f5f5);
}

/* Mobile styles for sync modal */
@media (max-width: 768px) {
    .sync-progress-content {
        padding: 20px;
        max-width: none;
        margin: 0 10px;
    }

    .sync-progress-header h2 {
        font-size: 18px;
    }

    .sync-progress-item {
        padding: 10px 12px;
    }
}

/* ===========================================
   Dark Mode Support
   =========================================== */
.dark-mode .offline-download-content,
.dark-mode-auto .offline-download-content,
.dark-mode .offline-toast,
.dark-mode-auto .offline-toast,
.dark-mode .offline-sync-dropdown,
.dark-mode-auto .offline-sync-dropdown,
.dark-mode .sync-progress-content,
.dark-mode-auto .sync-progress-content {
    background: var(--bg-secondary, #1e1e1e);
    color: var(--text-primary, #e0e0e0);
}

.dark-mode .sync-progress-item,
.dark-mode-auto .sync-progress-item,
.dark-mode .sync-progress-status,
.dark-mode-auto .sync-progress-status,
.dark-mode .sync-progress-bar,
.dark-mode-auto .sync-progress-bar {
    background: var(--bg-tertiary, #2d2d2d);
}

.dark-mode .offline-download-progress,
.dark-mode-auto .offline-download-progress {
    background: var(--bg-tertiary, #2d2d2d);
}

.dark-mode .offline-download-btn--secondary,
.dark-mode-auto .offline-download-btn--secondary {
    border-color: var(--border-color, #444);
    color: var(--text-secondary, #aaa);
}

.dark-mode .offline-download-btn--secondary:hover,
.dark-mode-auto .offline-download-btn--secondary:hover {
    background: var(--bg-tertiary, #2d2d2d);
}

@media (prefers-color-scheme: dark) {
    .dark-mode-auto .offline-download-content,
    .dark-mode-auto .offline-toast,
    .dark-mode-auto .offline-sync-dropdown {
        background: var(--bg-secondary, #1e1e1e);
        color: var(--text-primary, #e0e0e0);
    }
}

/* ============================================
   Offline Mode Menu Filtering
   Hide menu items that require online mode
   ============================================ */

/* When body has is-offline class, hide online-only menu items */
body.is-offline .menu-link--online-only,
body.is-offline .left a[data-requires-online="true"] {
    display: none !important;
}

/* Also hide submenus that only contain online-only items */
body.is-offline .submenu:empty {
    display: none !important;
}

/* Hide parent submenu toggle if all children are online-only */
body.is-offline .has-submenu.menu-submenu--all-online-only {
    display: none !important;
}

/* Visual indicator for menu items that won't work offline */
.menu-link--online-only::after {
    content: '';
    /* No visible indicator when online - items just disappear when offline */
}

/* ===========================================
   Download for Offline Menu Item
   =========================================== */
.menu-offline-download {
    color: var(--offline-info, #368BC1) !important;
}

.menu-offline-download .menu-icon {
    color: var(--offline-info, #368BC1) !important;
}

.menu-offline-download:hover {
    background: rgba(54, 139, 193, 0.1) !important;
}
