/**
 * Loading States - Apple Design
 * Skeleton loaders, spinners, and progress bars
 */

/* ============================================================================
   Skeleton Loaders
   ============================================================================ */

.skeleton-card,
.skeleton-list-item,
.skeleton-article,
.skeleton-table-row {
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

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

.skeleton-card {
    background: #ffffff;
    border: 1px solid #D2D2D7;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

.skeleton-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.6),
        transparent
    );
    animation: skeleton-shimmer 1.5s infinite;
}

@keyframes skeleton-shimmer {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* Card Types */
.skeleton-card-news {
    display: flex;
    flex-direction: column;
}

.skeleton-card-image-overlay {
    position: relative;
    overflow: hidden;
}

.skeleton-card-institute {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.skeleton-card-journal,
.skeleton-card-heritage {
    position: relative;
    overflow: hidden;
}

/* Skeleton Image */
.skeleton-image {
    background: #E5E5EA;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.skeleton-image-16-9 {
    width: 100%;
    padding-top: 56.25%; /* 16:9 aspect ratio */
}

.skeleton-image-4-3 {
    width: 100%;
    padding-top: 75%; /* 4:3 aspect ratio */
}

.skeleton-image-square {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    margin: 0 auto 16px;
}

.skeleton-image-journal {
    width: 100%;
    padding-top: 125%; /* 4:5 aspect ratio */
}

.skeleton-image-heritage {
    width: 100%;
    padding-top: 66.67%; /* 3:2 aspect ratio */
}

/* Skeleton Content */
.skeleton-content {
    padding: 16px;
}

.skeleton-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
}

/* Skeleton Elements */
.skeleton-badge {
    width: 80px;
    height: 24px;
    background: #E5E5EA;
    border-radius: 12px;
    margin-bottom: 12px;
}

.skeleton-title {
    width: 80%;
    height: 20px;
    background: #E5E5EA;
    border-radius: 4px;
    margin-bottom: 8px;
}

.skeleton-title-short {
    width: 60%;
}

.skeleton-title-overlay {
    width: 70%;
    height: 24px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
}

.skeleton-title-article {
    width: 90%;
    height: 32px;
    margin-bottom: 16px;
}

.skeleton-text {
    width: 100%;
    height: 16px;
    background: #E5E5EA;
    border-radius: 4px;
    margin-bottom: 8px;
}

.skeleton-text-short {
    width: 70%;
}

.skeleton-text-meta {
    width: 100px;
    height: 14px;
}

/* List Skeleton */
.skeleton-list-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: #ffffff;
    border-bottom: 1px solid #D2D2D7;
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    background: #E5E5EA;
    border-radius: 50%;
    flex-shrink: 0;
}

.skeleton-avatar-small {
    width: 40px;
    height: 40px;
}

.skeleton-list-content {
    flex: 1;
}

/* Article Skeleton */
.skeleton-article {
    max-width: 800px;
    margin: 0 auto;
}

.skeleton-article-header {
    margin-bottom: 32px;
}

.skeleton-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 16px;
}

.skeleton-article-image {
    width: 100%;
    padding-top: 56.25%; /* 16:9 */
    background: #E5E5EA;
    border-radius: 12px;
    margin: 32px 0;
}

.skeleton-article-content {
    margin-top: 32px;
}

/* Table Skeleton */
.skeleton-table-row td {
    padding: 16px;
    vertical-align: middle;
}

.skeleton-checkbox {
    width: 20px;
    height: 20px;
    background: #E5E5EA;
    border-radius: 4px;
}

.skeleton-actions {
    width: 80px;
    height: 32px;
    background: #E5E5EA;
    border-radius: 6px;
}

/* ============================================================================
   Apple Spinner
   ============================================================================ */

.apple-spinner {
    display: inline-block;
    position: relative;
}

.spinner-ring {
    width: 100%;
    height: 100%;
    border: 3px solid;
    border-top-color: transparent;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spinner-rotate 0.8s linear infinite;
}

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

/* Spinner Sizes */
.apple-spinner[style*="20px"] .spinner-ring {
    border-width: 2px;
}

.apple-spinner[style*="60px"] .spinner-ring {
    border-width: 4px;
}

/* Spinner in Container */
.loading-state {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.loading-state .apple-spinner {
    margin: 0 auto;
}

/* ============================================================================
   Progress Bar
   ============================================================================ */

.apple-progress-bar {
    width: 100%;
    height: 4px;
    position: relative;
}

.progress-track {
    width: 100%;
    height: 100%;
    background: #E5E5EA;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: #007AFF;
    border-radius: 2px;
    transition: width 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Indeterminate Progress */
.apple-progress-bar.indeterminate .progress-fill {
    width: 30% !important;
    animation: progress-indeterminate 1.5s ease-in-out infinite;
}

@keyframes progress-indeterminate {
    0% {
        transform: translateX(-100%);
    }
    50% {
        transform: translateX(300%);
    }
    100% {
        transform: translateX(-100%);
    }
}

/* ============================================================================
   Retry Loading
   ============================================================================ */

.retry-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #6E6E73;
    text-align: center;
}

.retry-loading .apple-spinner {
    margin-bottom: 16px;
}

.retry-loading p {
    font-size: 16px;
    color: #6E6E73;
    margin: 0;
}

/* ============================================================================
   Error States
   ============================================================================ */

.error-container {
    text-align: center;
    padding: 40px 24px;
    max-width: 400px;
    margin: 0 auto;
}

.error-icon {
    font-size: 64px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.error-icon .material-icons {
    font-size: 64px;
}

.error-title {
    font-size: 24px;
    font-weight: 600;
    color: #1D1D1F;
    margin: 0 0 12px 0;
    letter-spacing: -0.01em;
}

.error-message {
    font-size: 16px;
    color: #6E6E73;
    line-height: 1.5;
    margin: 0 0 32px 0;
}

.error-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.error-action-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    background-color: #007AFF;
}

.error-action-btn:hover {
    opacity: 0.8;
    transform: scale(0.98);
}

.error-action-btn:active {
    transform: scale(0.96);
}

.error-action-btn-secondary {
    background-color: #F5F5F7;
    color: #1D1D1F;
}

.error-action-btn-secondary:hover {
    background-color: #E5E5EA;
}

/* Error Overlay */
.error-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: error-overlay-fade-in 0.2s ease-out;
}

@keyframes error-overlay-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.error-overlay-exit {
    animation: error-overlay-fade-out 0.2s ease-out;
}

@keyframes error-overlay-fade-out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.error-overlay-content {
    background: #ffffff;
    border: 1px solid #D2D2D7;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    animation: error-content-slide-in 0.2s ease-out;
}

@keyframes error-content-slide-in {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ============================================================================
   Offline Banner
   ============================================================================ */

.offline-banner {
    position: fixed;
    top: 52px; /* Below nav bar */
    left: 0;
    right: 0;
    background: #FFF9E6;
    border-bottom: 1px solid #FFD700;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 9999;
    animation: offline-banner-slide-down 0.3s ease-out;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

@keyframes offline-banner-slide-down {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}

.offline-banner.hidden {
    animation: offline-banner-slide-up 0.3s ease-out;
    animation-fill-mode: forwards;
}

@keyframes offline-banner-slide-up {
    from {
        transform: translateY(0);
    }
    to {
        transform: translateY(-100%);
    }
}

.offline-banner-icon {
    color: #FF9500;
    font-size: 20px;
}

.offline-banner-text {
    font-size: 14px;
    color: #1D1D1F;
    flex: 1;
    text-align: center;
}

.offline-banner-close {
    background: none;
    border: none;
    color: #6E6E73;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.offline-banner-close:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #1D1D1F;
}

.offline-badge {
    display: inline-block;
    padding: 4px 8px;
    background: #E5E5EA;
    border-radius: 6px;
    font-size: 12px;
    color: #6E6E73;
    margin-left: 8px;
    font-weight: 500;
}

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

@media (max-width: 768px) {
    .error-container {
        padding: 32px 20px;
    }
    
    .error-icon {
        font-size: 48px;
    }
    
    .error-icon .material-icons {
        font-size: 48px;
    }
    
    .error-title {
        font-size: 20px;
    }
    
    .error-message {
        font-size: 14px;
    }
    
    .error-action-btn {
        width: 100%;
        padding: 14px 24px;
    }
    
    .offline-banner {
        top: 52px;
        padding: 10px 16px;
        flex-wrap: wrap;
    }
    
    .offline-banner-text {
        font-size: 13px;
    }
}

