/* ==========================================================================
   SPENDMINDAI - SKELETON LOADING SYSTEM (SKELETON SCREEN & SHIMMER)
   Design System Matching: Apple Frosted Glass, Dark & Light Mode, Zero-CLS
   ========================================================================== */

/* --- 1. SKELETON DESIGN TOKENS --- */
:root {
    --skeleton-duration: 1.6s;
    --skeleton-radius-sm: 6px;
    --skeleton-radius-md: 10px;
    --skeleton-radius-lg: 16px;
    --skeleton-radius-pill: 9999px;
    --skeleton-radius-circle: 50%;
}

/* Dark Theme Tokens (Zinc / Slate Deep Neutral) */
html[data-theme="dark"] {
    --skeleton-bg: rgba(255, 255, 255, 0.08);
    --skeleton-bg-subtle: rgba(255, 255, 255, 0.04);
    --skeleton-border: rgba(255, 255, 255, 0.08);
    --skeleton-shimmer-gradient: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.22) 50%,
        rgba(255, 255, 255, 0) 100%
    );
}

/* Light Theme Tokens (Apple Parchment / Gray-200 Neutral) */
html[data-theme="light"] {
    --skeleton-bg: #e4e4e7; /* bg-gray-200 / zinc-200 */
    --skeleton-bg-subtle: #f4f4f5;
    --skeleton-border: rgba(0, 0, 0, 0.06);
    --skeleton-shimmer-gradient: linear-gradient(
        90deg,
        rgba(0, 0, 0, 0) 0%,
        rgba(255, 255, 255, 0.65) 50%,
        rgba(0, 0, 0, 0) 100%
    );
}

/* --- 2. KEYFRAME ANIMATIONS --- */
@keyframes skeleton-shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

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

/* Accessibility: Respect Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .skeleton-bone::after {
        animation: none !important;
        display: none !important;
    }
    .skeleton-bone {
        animation: skeleton-pulse 2.5s infinite ease-in-out !important;
    }
}

/* --- 3. ATOMIC SKELETON PRIMITIVES --- */
.skeleton-bone {
    position: relative;
    overflow: hidden;
    background-color: var(--skeleton-bg);
    border-radius: var(--skeleton-radius-sm);
    pointer-events: none;
    user-select: none;
    display: block;
    box-sizing: border-box;
}

/* Shimmer Light Beam Effect */
.skeleton-bone::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    transform: translateX(-100%);
    background-image: var(--skeleton-shimmer-gradient);
    animation: skeleton-shimmer var(--skeleton-duration) infinite cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    pointer-events: none;
}

/* Avatar: Khối tròn w-10 h-10 (40px x 40px) */
.skeleton-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: var(--skeleton-radius-circle);
    flex-shrink: 0;
}

.skeleton-avatar-sm {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    border-radius: var(--skeleton-radius-circle);
    flex-shrink: 0;
}

.skeleton-avatar-lg {
    width: 56px;
    height: 56px;
    min-width: 56px;
    min-height: 56px;
    border-radius: var(--skeleton-radius-circle);
    flex-shrink: 0;
}

/* Tiêu đề / Tên: Khối chữ nhật bo góc, chiều rộng ~60% (hoặc 150px) */
.skeleton-title {
    width: 60%;
    max-width: 220px;
    height: 18px;
    border-radius: var(--skeleton-radius-sm);
    margin-bottom: 6px;
}

.skeleton-title-sm {
    width: 45%;
    max-width: 140px;
    height: 14px;
    border-radius: 4px;
}

.skeleton-title-lg {
    width: 75%;
    max-width: 300px;
    height: 24px;
    border-radius: var(--skeleton-radius-md);
    margin-bottom: 8px;
}

/* Dòng chữ đơn / Single Text Line */
.skeleton-line {
    width: 100%;
    height: 14px;
    border-radius: 4px;
    margin-bottom: 6px;
}

.skeleton-line:last-child {
    margin-bottom: 0;
}

/* Đoạn văn bản: 3 dòng, dòng cuối ngắn hơn (40-50% width) */
.skeleton-paragraph {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
}

.skeleton-paragraph .skeleton-line:nth-child(1) {
    width: 100%;
    height: 13px;
}

.skeleton-paragraph .skeleton-line:nth-child(2) {
    width: 82%;
    height: 13px;
}

.skeleton-paragraph .skeleton-line:nth-child(3) {
    width: 46%; /* 40-50% width dòng cuối */
    height: 13px;
}

/* Khối thẻ / hình ảnh: Tỷ lệ 16:9 hoặc chiều cao cố định */
.skeleton-media-16-9 {
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: var(--skeleton-radius-md);
}

.skeleton-media-box {
    width: 100%;
    height: 180px;
    border-radius: var(--skeleton-radius-md);
}

.skeleton-media-thumb {
    width: 72px;
    height: 72px;
    border-radius: var(--skeleton-radius-md);
    flex-shrink: 0;
}

/* Viên thuốc / Badge / Tag */
.skeleton-pill {
    height: 26px;
    width: 76px;
    border-radius: var(--skeleton-radius-pill);
    flex-shrink: 0;
}

/* Nút bấm (Button) */
.skeleton-btn {
    height: 40px;
    width: 100%;
    border-radius: var(--skeleton-radius-pill);
}

.skeleton-btn-sm {
    height: 32px;
    width: 100px;
    border-radius: var(--skeleton-radius-pill);
}

/* --- 4. COMPOSITE CARD SKELETONS (MATCHING REFERENCE IMAGE 1:1) --- */

/* Card Container Base */
.skeleton-card {
    background: var(--card-bg, rgba(28, 28, 30, 0.85));
    border: 1px solid var(--skeleton-border);
    border-radius: var(--radius-lg, 20px);
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
}

html[data-theme="light"] .skeleton-card {
    background: #ffffff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
}

.skeleton-divider {
    width: 100%;
    height: 1px;
    background: var(--skeleton-border);
    margin: 4px 0;
}

/* Type A: Media Card (Top Left in Reference Image) */
.skeleton-card-media {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.skeleton-card-media .media-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

/* Type B: Profile / Author Card (Center Card in Reference Image) */
.skeleton-card-profile .profile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.skeleton-card-profile .profile-header-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.skeleton-card-profile .profile-body {
    width: 100%;
    height: 220px;
    border-radius: var(--skeleton-radius-md);
}

/* Type C: Feature Banner Card (Top Right in Reference Image) */
.skeleton-card-feature {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Type D: Horizontal Compact Card (Bottom Right in Reference Image) */
.skeleton-card-compact .compact-top {
    display: flex;
    gap: 14px;
    align-items: center;
}

.skeleton-card-compact .compact-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

/* --- 5. SPENDMINDAI ZERO-CLS COMPONENT SKELETONS --- */

/* 5.1 Balance Summary Skeleton */
.skeleton-balance-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.skeleton-balance-label {
    width: 140px;
    height: 14px;
}

.skeleton-balance-amount {
    width: 220px;
    height: 42px;
    border-radius: var(--skeleton-radius-md);
    margin: 6px 0 12px;
}

.skeleton-indicators-row {
    display: flex;
    gap: 16px;
}

.skeleton-indicator-box {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    padding: 10px 14px;
    background: var(--skeleton-bg-subtle);
    border-radius: var(--skeleton-radius-md);
}

/* 5.2 Daily Transaction Item Skeleton (Khớp 1:1 với .daily-item) */
.skeleton-daily-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 56px;
    padding: 12px 16px;
    background: var(--surface-raised, #1c1c1e);
    border-bottom: 1px solid var(--skeleton-border);
    box-sizing: border-box;
}

html[data-theme="light"] .skeleton-daily-item {
    background: #ffffff;
}

.skeleton-daily-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.skeleton-daily-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.skeleton-daily-title {
    width: 55%;
    max-width: 140px;
    height: 15px;
    border-radius: 4px;
}

.skeleton-daily-desc {
    width: 40%;
    max-width: 90px;
    height: 12px;
    border-radius: 4px;
}

.skeleton-daily-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.skeleton-daily-amount {
    width: 80px;
    height: 20px;
    border-radius: 6px;
}

/* 5.3 Calendar Cell Skeleton (Khớp 1:1 với .calendar-cell) */
.skeleton-calendar-cell {
    aspect-ratio: 1;
    min-height: 48px;
    border-radius: 8px;
    background: var(--skeleton-bg-subtle);
    border: 1px solid var(--skeleton-border);
    padding: 6px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-sizing: border-box;
}

.skeleton-cell-day {
    width: 18px;
    height: 14px;
    border-radius: 3px;
}

.skeleton-cell-badge {
    width: 80%;
    height: 10px;
    border-radius: 3px;
    margin-top: auto;
}

/* 5.4 Budget Item Skeleton (Khớp 1:1 với .budget-item) */
.skeleton-budget-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--skeleton-border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.skeleton-budget-item:last-child {
    border-bottom: none;
}

.skeleton-budget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.skeleton-budget-name {
    width: 110px;
    height: 16px;
}

.skeleton-budget-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.skeleton-budget-bar {
    width: 100%;
    height: 8px;
    border-radius: 9999px;
}

/* 5.5 Chart Placeholder Skeletons (Donut & Trend Matching 1:1) */
.skeleton-chart-box {
    width: 100%;
    height: 220px;
    border-radius: var(--skeleton-radius-md);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 12px;
}





/* Trend Chart Skeleton (Khớp Xu hướng thu chi 1:1) */
.skeleton-chart-trend-wrapper {
    width: 100%;
    height: 220px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 12px 10px;
    box-sizing: border-box;
}

.skeleton-trend-bars {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    height: 145px;
    width: 100%;
    box-sizing: border-box;
    gap: 8px;
}

.skeleton-trend-bar {
    flex: 1;
    max-width: 28px;
    border-radius: 6px 6px 0 0;
}

.skeleton-trend-axis {
    display: flex;
    justify-content: space-between;
    width: 100%;
    border-top: 1px solid var(--skeleton-border);
    padding-top: 8px;
    box-sizing: border-box;
    gap: 8px;
}

.skeleton-axis-label {
    flex: 1;
    height: 10px;
    border-radius: 2px;
    max-width: 28px;
}

/* 5.6 Daily Summary Bar Skeleton Values */
.skeleton-summary-val {
    width: 54px;
    height: 18px;
    border-radius: 4px;
    display: inline-block;
    vertical-align: middle;
}

/* 5.6 AI Chatbot Message Skeleton (Khớp avatar + đoạn văn bản 3 dòng) */
.skeleton-chat-message {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 14px;
    max-width: 85%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--skeleton-border);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    margin-bottom: 12px;
    box-sizing: border-box;
}

html[data-theme="light"] .skeleton-chat-message {
    background: #f4f4f5;
}

.skeleton-chat-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.skeleton-chat-author {
    width: 75px;
    height: 12px;
    border-radius: 3px;
}

/* --- 6. UTILITY FADE TRANSITION --- */
.skeleton-fade-out {
    opacity: 0;
    transition: opacity 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

.skeleton-fade-in {
    animation: skeletonContentFadeIn 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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