/**
 * Nucleus: единая дизайн-система скелетов (shimmer/pulse, токены на корне .nv-skeleton).
 * Стили согласованы с nucleus-dashboard: --nucleus-sk-block при загрузке, здесь — автономные --nv-*.
 * Паттерны: плейсхолдеры и «скелет под контент» (react-loading-skeleton / shadcn / Skeleton).
 */

/* --- токены --- */
.nv-skeleton,
[class^='nv-'][class$='-skeleton'] {
    --nv-sk-bg: color-mix(in srgb, var(--color-surface-elevated, #2a2a2e) 100%, transparent);
    --nv-sk-1: rgba(238, 238, 238, 0.08);
    --nv-sk-2: rgba(238, 238, 238, 0.12);
    --nv-sk-bone: #3f3f46;
    --nv-sk-radius: 8px;
    --nv-sk-radius-pill: 999px;
    --nv-sk-ease: cubic-bezier(0.4, 0, 0.2, 1);
}

body.light-theme .nv-skeleton,
body.light-theme [class^='nv-'][class$='-skeleton'] {
    --nv-sk-1: rgba(0, 0, 0, 0.08);
    --nv-sk-2: rgba(0, 0, 0, 0.12);
    --nv-sk-bone: #e4e4e7;
}

/* --- анимации: pulse (как shadcn) и shimmer (как react-loading-skeleton) --- */
@keyframes nv-sk-pulse {
    0%,
    100% {
        opacity: 0.55;
    }
    50% {
        opacity: 0.9;
    }
}

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

/* Базовая кость: фон + опциональный shimmer (класс .nv-sk-bone--shimmer) */
.nv-sk-bone {
    display: block;
    box-sizing: border-box;
    border-radius: var(--nv-sk-radius);
    background: var(--nv-sk-1);
    min-height: 0.75rem;
    animation: nv-sk-pulse 1.2s var(--nv-sk-ease) infinite;
}

.nv-sk-bone--shimmer {
    background: linear-gradient(90deg, var(--nv-sk-1) 0%, var(--nv-sk-2) 50%, var(--nv-sk-1) 100%);
    background-size: 200% 100%;
    animation: nv-sk-shimmer 1.2s var(--nv-sk-ease) infinite;
}

.nv-sk-bone--round {
    border-radius: var(--nv-sk-radius-pill);
}

.nv-sk-bone--circle {
    border-radius: 50%;
    aspect-ratio: 1;
}

/* Обёртки-композиции: без лишнего визуала, только сетка */
.nv-card-skeleton {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    pointer-events: none;
    user-select: none;
}

.nv-card-skeleton__media {
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: 12px;
    overflow: hidden;
}

.nv-card-skeleton__body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    min-width: 0;
}

/* Таблица: шапка + ряды */
.nv-table-skeleton {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    gap: 0;
    border: 1px solid color-mix(in srgb, var(--nucleus-fin-island-border, rgba(238, 238, 238, 0.08)) 100%, transparent);
    border-radius: 12px;
    overflow: hidden;
    background: var(--color-bg-tertiary, rgba(0, 0, 0, 0.2));
    pointer-events: none;
}

.nv-table-skeleton__row {
    display: grid;
    align-items: center;
    min-height: 48px;
    width: 100%;
    box-sizing: border-box;
    padding: 0 16px;
    border-bottom: 1px solid color-mix(in srgb, var(--nucleus-fin-island-border, rgba(238, 238, 238, 0.06)) 100%, transparent);
    gap: 12px;
}

.nv-table-skeleton__row:last-child {
    border-bottom: none;
}

.nv-table-skeleton__row--head {
    min-height: 44px;
    background: color-mix(in srgb, var(--nv-sk-1) 40%, transparent);
}

/* Форма: пары label / field */
.nv-form-skeleton {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    max-width: 420px;
    min-width: 0;
    pointer-events: none;
}

.nv-form-skeleton__field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

/* Шапка страницы */
.nv-page-header-skeleton {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 52px;
    gap: 16px;
    flex-wrap: wrap;
    pointer-events: none;
    box-sizing: border-box;
}

.nv-page-header-skeleton__lead {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1 1 auto;
}

.nv-page-header-skeleton__actions {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Список (аватар + строки) */
.nv-list-skeleton {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 100%;
    min-width: 0;
    pointer-events: none;
}

.nv-list-skeleton__row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 12px 0;
    min-height: 56px;
    width: 100%;
    box-sizing: border-box;
    border-bottom: 1px solid color-mix(in srgb, var(--nucleus-fin-island-border, rgba(238, 238, 238, 0.06)) 100%, transparent);
}

.nv-list-skeleton__row:last-child {
    border-bottom: none;
}

.nv-list-skeleton__content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
}

/* Drawer: шапка + тело (список линий) + футер */
.nv-drawer-skeleton {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 200px;
    max-width: 420px;
    margin: 0 auto;
    pointer-events: none;
    box-sizing: border-box;
}

.nv-drawer-skeleton__header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0 20px;
    width: 100%;
    box-sizing: border-box;
    gap: 12px;
}

.nv-drawer-skeleton__body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px 0 20px;
    width: 100%;
    flex: 1 1 auto;
    min-height: 120px;
    box-sizing: border-box;
}

.nv-drawer-skeleton__footer {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    padding-top: 16px;
    border-top: 1px solid color-mix(in srgb, var(--nucleus-fin-island-border, rgba(238, 238, 238, 0.08)) 100%, transparent);
    width: 100%;
    box-sizing: border-box;
}

/* График: сетка + псевдо-бар / область */
.nv-chart-skeleton {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    min-width: 0;
    min-height: 200px;
    box-sizing: border-box;
    pointer-events: none;
}

.nv-chart-skeleton__header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: 32px;
}

.nv-chart-skeleton__plot {
    position: relative;
    width: 100%;
    min-height: 200px;
    background: var(--nv-sk-1);
    background-image: linear-gradient(90deg, var(--nv-sk-1) 0%, var(--nv-sk-2) 30%, var(--nv-sk-1) 100%);
    background-size: 200% 100%;
    animation: nv-sk-shimmer 1.3s var(--nv-sk-ease) infinite;
    border-radius: 12px;
    overflow: hidden;
    opacity: 0.85;
}

/* Внутренняя сетка-«столбики» как подсказка чарта */
.nv-chart-skeleton__plot-inner {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 12px;
    /* 20% давало огромный «тёмный зазор» над барами в календаре Nucleus */
    top: 10px;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
    gap: 6px;
    pointer-events: none;
}

.nv-chart-skeleton__bar {
    flex: 1 1 0;
    min-width: 4px;
    border-radius: 4px 4px 0 0;
    background: color-mix(in srgb, #eeeeee 12%, var(--nv-sk-1) 88%);
    opacity: 0.5;
    animation: nv-sk-pulse 1.1s var(--nv-sk-ease) infinite;
}

/* Легенда (опциональные пилюли) */
.nv-chart-skeleton__legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
}

.nv-skeleton--sr {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ========== Nucleus: показ html-скелетов только при is-nucleus-initial-loading ========== */
/* С нейтральным --nucleus-sk-block с корня (Dashboard); острова оверрайдят сами. */
#nucleus-dashboard-container.is-nucleus-initial-loading {
    --nv-sk-1: var(--nucleus-sk-block, rgba(238, 238, 238, 0.1));
    --nv-sk-2: color-mix(
        in srgb,
        var(--nucleus-sk-block, rgba(238, 238, 238, 0.1)) 70%,
        #eeeeee 30%
    );
}

/* Светлая тема: кости из тех же --nucleus-sk-* что и градиенты в nucleus-dashboard (см. :root --color-bg-tertiary). */
:is(body.light-theme, html.light, html.light-theme) #nucleus-dashboard-container.is-nucleus-initial-loading {
    --nv-sk-1: var(--nucleus-sk-block, var(--color-bg-tertiary, #f0f0f0));
    --nv-sk-2: var(--nucleus-sk-shine, color-mix(in srgb, var(--color-bg-tertiary, #f0f0f0) 90%, #eeeeee 10%));
}

#nucleus-dashboard-container [data-initial-skeleton] {
    display: none !important;
    pointer-events: none;
    box-sizing: border-box;
}

#nucleus-dashboard-container.is-nucleus-initial-loading [data-initial-skeleton] {
    display: block !important;
}

/* Шапка Nucleus и рельс вкладок (Dashboard|Budget|…) — без скелета: всегда нормальный контраст и клики. */
#nucleus-dashboard-container.is-nucleus-initial-loading .nucleus-initial-skeleton--pageheader {
    display: none !important;
}

#nucleus-dashboard-container.is-nucleus-initial-loading .nucleus-page-header-toolbar,
#nucleus-dashboard-container.is-nucleus-initial-loading .nucleus-page-header-toolbar__title-group,
#nucleus-dashboard-container.is-nucleus-initial-loading .nucleus-page-header-toolbar__title,
#nucleus-dashboard-container.is-nucleus-initial-loading #nucleus-page-add-btn,
#nucleus-dashboard-container.is-nucleus-initial-loading #nucleus-budgeting-main-tabs,
#nucleus-dashboard-container.is-nucleus-initial-loading .nucleus-budgeting-main-tabs .nucleus-budgeting-main-tab {
    opacity: 1 !important;
    pointer-events: auto !important;
    position: relative;
    z-index: auto;
}

/*
 * Скелет: без общей «карточки» на #nucleus-tab-panel-dashboard — фон/тень только у дочерних островов.
 */
#nucleus-dashboard-container.is-nucleus-initial-loading
    #nucleus-finance-island
    #nucleus-tab-panel-dashboard {
    box-sizing: border-box;
    width: 100%;
    max-width: none;
    margin-left: 0;
    margin-right: 0;
    margin-bottom: 0;
    background: transparent !important;
    background-image: none !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    filter: none !important;
    gap: 0 !important;
    row-gap: 0 !important;
    column-gap: 0 !important;
    overflow: visible;
    -webkit-font-smoothing: antialiased;
}

/* Внутри общей карточки — без второй «коробки» у Cashflow */
#nucleus-dashboard-container.is-nucleus-initial-loading
    #nucleus-finance-island
    #nucleus-tab-panel-dashboard
    #nucleus-overview-cashflow-root.nucleus-cashflow-island {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    margin-bottom: 0 !important;
    width: 100% !important;
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Card (чат) */
#nucleus-dashboard-container.is-nucleus-initial-loading #nucleus-dashboard-extra {
    position: relative;
    min-height: 320px;
    padding: var(--spacing-2xl) var(--nucleus-fin-card-pad-x, 24px) var(--spacing-4xl);
    box-sizing: border-box;
}

#nucleus-dashboard-container.is-nucleus-initial-loading .nucleus-initial-skeleton--dashboard-chat {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 3;
    display: flex !important;
    padding: 12px 0;
    align-items: flex-start;
    box-sizing: border-box;
}

#nucleus-dashboard-container.is-nucleus-initial-loading
    .nucleus-initial-skeleton--dashboard-chat
    .nv-card-skeleton {
    max-width: 100%;
    width: 100%;
    flex: 1 1 auto;
}

/* Между cashflow и #nucleus-budget-insights: ListSkeleton-заглушка категорий (отступы внутри общей карточки) */
#nucleus-dashboard-container.is-nucleus-initial-loading .nucleus-initial-skeleton--budget-insights {
    width: 100%;
    margin: 0 !important;
    padding: var(--spacing-2xl) var(--nucleus-fin-card-pad-x, 24px) 0;
    display: block !important;
    box-sizing: border-box;
}

#nucleus-dashboard-container.is-nucleus-initial-loading #nucleus-assistant-embed {
    opacity: 0.08;
    pointer-events: none;
}

/* Светлый layout: сильнее гасим белизну iframe, пока скелет. */
:is(body.light-theme, html.light, html.light-theme)
    #nucleus-dashboard-container.is-nucleus-initial-loading
    #nucleus-assistant-embed {
    opacity: 0.04;
}

/* #nucleus-finance-planner / #nucleus-taxes-workspace: пульс в nucleus-dashboard.css. */
