/**
 * Progressive Loading Skeleton Styles
 *
 * Provides smooth loading animations for sensor cards during
 * progressive data loading with Server-Sent Events (SSE).
 *
 * Author: Claude Assistant
 * Created: 2025-12-19
 */

/* ========== Skeleton Loading Animation ========== */

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

@keyframes pulse-opacity {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

/* ========== Skeleton Loading States ========== */

.skeleton-loading {
    position: relative;
    pointer-events: none;
    user-select: none;
}

.skeleton-loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.3) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: inherit;
    z-index: 1;
}

.skeleton-loading .sensor-value .value,
.skeleton-loading .npk-value,
.skeleton-loading .sensor-status small {
    background: linear-gradient(
        90deg,
        #e0e0e0 25%,
        #f0f0f0 50%,
        #e0e0e0 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    color: transparent !important;
    border-radius: 4px;
    display: inline-block;
    min-width: 60px;
    min-height: 1.2em;
}

/* ========== Loading Indicator ========== */

#loading-indicator {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1050;
    background: rgba(255, 255, 255, 0.95);
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: none;
    min-width: 300px;
}

#loading-indicator .progress {
    height: 4px;
    margin-top: 8px;
    background-color: #e0e0e0;
    border-radius: 2px;
    overflow: hidden;
}

#loading-indicator .progress-bar {
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    transition: width 0.3s ease;
    font-size: 10px;
    line-height: 4px;
    color: transparent;
}

#loading-indicator .spinner-border {
    width: 1rem;
    height: 1rem;
    border-width: 2px;
    vertical-align: middle;
    margin-right: 8px;
}

/* ========== Update Animations ========== */

.sensor-card.loaded {
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sensor-value .value.updating {
    animation: pulse-opacity 0.5s ease;
}

.sensor-value .value.updated {
    animation: highlight 0.5s ease;
}

@keyframes highlight {
    0% {
        background-color: transparent;
    }
    50% {
        background-color: rgba(76, 175, 80, 0.2);
    }
    100% {
        background-color: transparent;
    }
}

/* ========== Success/Error Indicators ========== */

.sensor-success {
    position: relative;
}

.sensor-success::after {
    content: '✓';
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: #4caf50;
    color: white;
    border-radius: 50%;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    opacity: 0;
    animation: successPop 0.6s ease forwards;
}

@keyframes successPop {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    50% {
        opacity: 1;
        transform: scale(1.2);
    }
    100% {
        opacity: 0;
        transform: scale(1);
    }
}

.sensor-error {
    border: 2px solid #ff9800 !important;
    background-color: rgba(255, 152, 0, 0.05) !important;
}

/* ========== Loading Progress Bar (Optional) ========== */

.loading-progress-container {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    z-index: 1055;
    height: 3px;
    background: #e0e0e0;
    display: none;
}

.loading-progress-container.active {
    display: block;
}

#loading-progress {
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    transition: width 0.3s ease;
    width: 0%;
}

/* ========== Responsive Design ========== */

@media (max-width: 768px) {
    #loading-indicator {
        min-width: 250px;
        padding: 10px 20px;
        font-size: 14px;
    }
}

/* ========== Dark Mode Support (Optional) ========== */

@media (prefers-color-scheme: dark) {
    .skeleton-loading .sensor-value .value,
    .skeleton-loading .npk-value,
    .skeleton-loading .sensor-status small {
        background: linear-gradient(
            90deg,
            #2a2a2a 25%,
            #3a3a3a 50%,
            #2a2a2a 75%
        );
    }

    #loading-indicator {
        background: rgba(30, 30, 30, 0.95);
        color: #ffffff;
    }

    #loading-indicator .progress {
        background-color: #404040;
    }
}

/* ========== Accessibility ========== */

@media (prefers-reduced-motion: reduce) {
    .skeleton-loading::before,
    .skeleton-loading .sensor-value .value,
    .skeleton-loading .npk-value,
    .skeleton-loading .sensor-status small {
        animation: none;
    }

    .sensor-card.loaded {
        animation: none;
    }

    .sensor-value .value.updating,
    .sensor-value .value.updated {
        animation: none;
    }
}

/* ========== Bootstrap Alert Positioning (for SSE messages) ========== */

.alert.position-fixed {
    max-width: 500px;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translate(-50%, -20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

/* ========== Sequential Chart Loading ========== */

/* Chart card loading state */
.chart-card.loading {
    position: relative;
    min-height: 300px;
}

.chart-card.loading .chart-body {
    position: relative;
}

.chart-card.loading canvas {
    opacity: 0.3;
}

/* Chart loading spinner */
.chart-loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 10;
}

.chart-loading-spinner .spinner-border {
    width: 3rem;
    height: 3rem;
}

/* Chart loaded state */
.chart-card.loaded {
    animation: chartFadeIn 0.5s ease;
}

.chart-card.loaded canvas {
    opacity: 1;
    transition: opacity 0.3s ease;
}

@keyframes chartFadeIn {
    from {
        opacity: 0.7;
    }
    to {
        opacity: 1;
    }
}

/* Chart error state */
.chart-card.error {
    border: 2px solid #ff9800 !important;
}

.chart-error-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.chart-error-message i {
    font-size: 3rem;
    color: #ff9800;
}

/* Chart no data state */
.chart-no-data {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.chart-no-data i {
    font-size: 3rem;
    color: #9e9e9e;
}

/* Graph loading indicator */
#graph-loading-indicator {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1050;
    background: rgba(255, 255, 255, 0.98);
    padding: 15px 25px;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    min-width: 320px;
    backdrop-filter: blur(10px);
}

#graph-loading-indicator .progress {
    height: 8px;
    margin-top: 10px;
    background-color: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
}

#graph-loading-progress {
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transition: width 0.3s ease;
    font-size: 11px;
    line-height: 8px;
    text-align: center;
    color: white;
    font-weight: 600;
}

/* Progress shimmer effect */
@keyframes progress-shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

#graph-loading-progress {
    background-image: linear-gradient(
        90deg,
        #667eea 0%,
        #764ba2 30%,
        #9b59b6 50%,
        #764ba2 70%,
        #667eea 100%
    );
    background-size: 200% 100%;
    animation: progress-shimmer 2s linear infinite;
}

/* Dark mode support for chart loading */
@media (prefers-color-scheme: dark) {
    #graph-loading-indicator {
        background: rgba(30, 30, 30, 0.98);
        color: #ffffff;
    }

    #graph-loading-indicator .progress {
        background-color: #404040;
    }

    .chart-card.loading canvas {
        opacity: 0.2;
    }

    .chart-no-data i,
    .chart-error-message .text-muted {
        color: #aaaaaa !important;
    }
}
