/**
 * Skeleton Loader & Loading States
 * Phase 03: Loading States & Micro-interactions
 */

/* ========================================
   Skeleton Loader Base
   ======================================== */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: 4px;
}

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

/* ========================================
   KPI Card Skeleton
   ======================================== */
.kpi-skeleton {
    padding: 1.25rem;
}

.kpi-skeleton .skeleton-title {
    width: 60%;
    height: 12px;
    margin-bottom: 12px;
}

.kpi-skeleton .skeleton-value {
    width: 80%;
    height: 28px;
    margin-bottom: 12px;
}

.kpi-skeleton .skeleton-subtitle {
    width: 50%;
    height: 10px;
    margin-bottom: 8px;
}

.kpi-skeleton .skeleton-trend {
    width: 40%;
    height: 18px;
}

/* ========================================
   Chart Skeleton
   ======================================== */
.chart-skeleton {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding: 1rem;
    height: 100%;
    min-height: 280px;
}

.chart-skeleton-bars {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: 200px;
    padding: 0 1rem;
}

.chart-skeleton-bar {
    flex: 1;
    max-width: 30px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: 4px 4px 0 0;
}

.chart-skeleton-bar:nth-child(1) { height: 60%; animation-delay: 0s; }
.chart-skeleton-bar:nth-child(2) { height: 80%; animation-delay: 0.1s; }
.chart-skeleton-bar:nth-child(3) { height: 45%; animation-delay: 0.2s; }
.chart-skeleton-bar:nth-child(4) { height: 90%; animation-delay: 0.3s; }
.chart-skeleton-bar:nth-child(5) { height: 55%; animation-delay: 0.4s; }
.chart-skeleton-bar:nth-child(6) { height: 75%; animation-delay: 0.5s; }
.chart-skeleton-bar:nth-child(7) { height: 40%; animation-delay: 0.6s; }
.chart-skeleton-bar:nth-child(8) { height: 85%; animation-delay: 0.7s; }

.chart-skeleton-line {
    width: 90%;
    height: 2px;
    margin-top: 12px;
}

/* Doughnut Chart Skeleton */
.chart-skeleton-doughnut {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 250px;
}

.chart-skeleton-circle {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    border: 30px solid;
    border-color: #f0f0f0 #e8e8e8 #f0f0f0 #e0e0e0;
    animation: skeleton-rotate 2s linear infinite;
}

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

/* ========================================
   Table Skeleton
   ======================================== */
.table-skeleton {
    width: 100%;
}

.table-skeleton-row {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
}

.table-skeleton-cell {
    height: 16px;
}

.table-skeleton-cell:nth-child(1) { flex: 2; }
.table-skeleton-cell:nth-child(2) { flex: 2; }
.table-skeleton-cell:nth-child(3) { flex: 1; }
.table-skeleton-cell:nth-child(4) { flex: 1; }

/* ========================================
   Loading Overlay
   ======================================== */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: inherit;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f0f0f0;
    border-top-color: #007bff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ========================================
   Fade In Animation
   ======================================== */
.fade-in {
    animation: fadeIn 0.4s ease-out forwards;
    opacity: 0;
}

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

/* Staggered fade-in for lists */
.fade-in-stagger > * {
    animation: fadeIn 0.4s ease-out forwards;
    opacity: 0;
}

.fade-in-stagger > *:nth-child(1) { animation-delay: 0.05s; }
.fade-in-stagger > *:nth-child(2) { animation-delay: 0.1s; }
.fade-in-stagger > *:nth-child(3) { animation-delay: 0.15s; }
.fade-in-stagger > *:nth-child(4) { animation-delay: 0.2s; }
.fade-in-stagger > *:nth-child(5) { animation-delay: 0.25s; }
.fade-in-stagger > *:nth-child(6) { animation-delay: 0.3s; }
.fade-in-stagger > *:nth-child(7) { animation-delay: 0.35s; }
.fade-in-stagger > *:nth-child(8) { animation-delay: 0.4s; }
.fade-in-stagger > *:nth-child(9) { animation-delay: 0.45s; }
.fade-in-stagger > *:nth-child(10) { animation-delay: 0.5s; }

/* ========================================
   Pulse Animation (for real-time data)
   ======================================== */
.pulse-highlight {
    animation: pulse 1s ease-out;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 123, 255, 0.4);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(0, 123, 255, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(0, 123, 255, 0);
    }
}

/* Success pulse */
.pulse-success {
    animation: pulse-success 1s ease-out;
}

@keyframes pulse-success {
    0% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.4);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(40, 167, 69, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0);
    }
}

/* ========================================
   Number Counter Animation
   ======================================== */
.count-up {
    display: inline-block;
    transition: transform 0.3s ease;
}

.count-up.counting {
    transform: scale(1.05);
}

/* ========================================
   Micro-interactions
   ======================================== */

/* Card hover lift effect */
.card-lift {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-lift:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1) !important;
}

/* Button press effect */
.btn-press {
    transition: transform 0.1s ease;
}

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

/* Table row highlight on hover */
.table-hover-highlight tbody tr {
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.table-hover-highlight tbody tr:hover {
    background-color: rgba(0, 123, 255, 0.05) !important;
}

/* Badge pop-in animation */
.badge-animate {
    animation: badge-pop 0.3s ease-out;
}

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

/* ========================================
   Refresh Indicator
   ======================================== */
.refresh-indicator {
    position: fixed;
    top: 70px;
    right: 20px;
    background: #007bff;
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
    transform: translateX(150%);
    transition: transform 0.3s ease;
    z-index: 1000;
}

.refresh-indicator.show {
    transform: translateX(0);
}

.refresh-indicator .spinner-border {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

/* ========================================
   Empty State
   ======================================== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    color: #6c757d;
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}

.empty-state-text {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.empty-state-subtext {
    font-size: 0.875rem;
    opacity: 0.7;
}

/* ========================================
   Form Skeleton
   ======================================== */
.form-skeleton {
    padding: 1rem;
}

.form-skeleton-group {
    margin-bottom: 1.5rem;
}

.form-skeleton-label {
    width: 30%;
    height: 14px;
    margin-bottom: 8px;
}

.form-skeleton-input {
    width: 100%;
    height: 44px;
    border-radius: 6px;
}

.form-skeleton-textarea {
    width: 100%;
    height: 100px;
    border-radius: 6px;
}

/* ========================================
   Detail Card Skeleton
   ======================================== */
.detail-skeleton {
    padding: 1.5rem;
}

.detail-skeleton-header {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.detail-skeleton-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
}

.detail-skeleton-title {
    width: 200px;
    height: 24px;
    margin-bottom: 8px;
}

.detail-skeleton-subtitle {
    width: 150px;
    height: 16px;
}

.detail-skeleton-content {
    display: grid;
    gap: 1rem;
}

.detail-skeleton-row {
    display: flex;
    gap: 1rem;
}

.detail-skeleton-cell {
    flex: 1;
    height: 20px;
}

/* ========================================
   Card Grid Skeleton
   ======================================== */
.card-grid-skeleton {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.card-skeleton {
    background: var(--bg-white, #fff);
    border: 1px solid var(--border-default, #e5e7eb);
    border-radius: 8px;
    padding: 1.25rem;
}

.card-skeleton-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.card-skeleton-badge {
    width: 60px;
    height: 24px;
    border-radius: 12px;
}

.card-skeleton-title {
    width: 70%;
    height: 20px;
    margin-bottom: 12px;
}

.card-skeleton-text {
    width: 90%;
    height: 14px;
    margin-bottom: 8px;
}

.card-skeleton-footer {
    display: flex;
    gap: 8px;
    margin-top: 1rem;
}

.card-skeleton-btn {
    width: 80px;
    height: 32px;
    border-radius: 6px;
}

/* ========================================
   Map Skeleton
   ======================================== */
.map-skeleton {
    width: 100%;
    height: 300px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.map-skeleton-icon {
    width: 48px;
    height: 48px;
    opacity: 0.5;
}
