/*
 * mortalkiller/filament-skeleton-loading
 * Skeletons for lazy widgets and sections, and skeleton rows for deferred tables.
 * Plain CSS on purpose: no build step in the consuming app.
 */

.fsl-skeleton {
    --fsl-bone: rgb(0 0 0 / 0.07);
    --fsl-shine: rgb(255 255 255 / 0.55);
    --fsl-border: rgb(0 0 0 / 0.05);
    position: relative;
}

.dark .fsl-skeleton {
    --fsl-bone: rgb(255 255 255 / 0.08);
    --fsl-shine: rgb(255 255 255 / 0.07);
    --fsl-border: rgb(255 255 255 / 0.06);
}

/* Bones and the light sweeping across them */
.fsl-bone {
    position: relative;
    display: block;
    overflow: hidden;
    border-radius: var(--fsl-rounded, var(--fsl-bone-radius, var(--radius-md, 6px)));
    background: var(--fsl-bone);
}

.fsl-bone::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, var(--fsl-shine), transparent);
    animation: fsl-shimmer 1.4s ease-in-out infinite;
}

@keyframes fsl-shimmer {
    to { transform: translateX(100%); }
}

.fsl-line { height: 12px; }
.fsl-title { height: 16px; width: 40%; }
.fsl-value { height: 28px; }

.fsl-heading {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.5;
    opacity: 0.6;
}

/* Cards */
.fsl-card {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 24px;
}

.fsl-card--flush { padding: 0; gap: 0; }

/* Stats */
.fsl-grid {
    display: grid;
    gap: 24px;
}

.fsl-stat {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 24px;
}

@media (max-width: 767px) {
    .fsl-grid { grid-template-columns: minmax(0, 1fr) !important; }
}

/* Charts */
.fsl-chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    height: 200px;
}

.fsl-chart-bars .fsl-bone {
    flex: 1 1 0;
}

.fsl-chart-line {
    display: block;
    width: 100%;
    height: 200px;
    color: var(--fsl-bone);
}

.fsl-chart-ring-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.fsl-chart-ring {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    -webkit-mask: radial-gradient(circle, transparent 54%, #000 55%);
    mask: radial-gradient(circle, transparent 54%, #000 55%);
}

.fsl-legend {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

/* Table widgets */
.fsl-table-head { padding: 20px 24px; }

.fsl-row {
    display: grid;
    grid-template-columns: 1.2fr 2fr 1fr 0.8fr;
    align-items: center;
    gap: 24px;
    padding: 18px 24px;
    border-top: 1px solid var(--fsl-border);
}

/*
 * Filament's own loading containers draw a spinner; draw skeletons instead:
 * deferred tables, the database notifications panel and lazy loaded schemas (sections).
 */
.fi-ta-table-loading-ctn,
.fi-no-notifications-loading-ctn,
.fi-sc-loading {
    --fsl-bone: rgb(0 0 0 / 0.07);
    --fsl-shine: rgb(255 255 255 / 0.55);
    position: relative;
    display: block !important;
    /* Filament gives the spinner box a fixed height: let the skeleton set it. */
    height: auto !important;
    min-height: 0 !important;
    overflow: hidden;
}

.dark .fi-ta-table-loading-ctn,
.dark .fi-no-notifications-loading-ctn,
.dark .fi-sc-loading {
    --fsl-bone: rgb(255 255 255 / 0.08);
    --fsl-shine: rgb(255 255 255 / 0.07);
}

.fi-ta-table-loading-ctn > :not(.fi-sr-only),
.fi-no-notifications-loading-ctn > :not(.fi-sr-only),
.fi-sc-loading > :not(.fi-sr-only) {
    display: none !important;
}

.fi-ta-table-loading-ctn::after,
.fi-no-notifications-loading-ctn::after,
.fi-sc-loading::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, var(--fsl-shine), transparent);
    animation: fsl-shimmer 1.4s ease-in-out infinite;
    pointer-events: none;
}

/* Repeat a rounded cell across four columns and seven rows. */
.fi-ta-table-loading-ctn {
    container-type: inline-size;
    padding: 21px 0 !important;
}

.fi-ta-table-loading-ctn::before {
    --fsl-column-1: calc((100cqw - 48px) * .26);
    --fsl-column-2: calc((100cqw - 48px) * .52);
    --fsl-column-3: calc((100cqw - 48px) * .78);
    content: "";
    display: block;
    width: max(0px, calc((100cqw - 48px) * .22));
    height: 14px;
    margin-inline: 24px;
    margin-block-end: 336px;
    border-radius: var(--fsl-rounded, var(--fsl-bone-radius, var(--radius-md, 6px)));
    background: var(--fsl-bone);
    box-shadow:
        var(--fsl-column-1) 0 var(--fsl-bone),
        var(--fsl-column-2) 0 var(--fsl-bone),
        var(--fsl-column-3) 0 var(--fsl-bone),
        0 56px var(--fsl-bone),
        var(--fsl-column-1) 56px var(--fsl-bone),
        var(--fsl-column-2) 56px var(--fsl-bone),
        var(--fsl-column-3) 56px var(--fsl-bone),
        0 112px var(--fsl-bone),
        var(--fsl-column-1) 112px var(--fsl-bone),
        var(--fsl-column-2) 112px var(--fsl-bone),
        var(--fsl-column-3) 112px var(--fsl-bone),
        0 168px var(--fsl-bone),
        var(--fsl-column-1) 168px var(--fsl-bone),
        var(--fsl-column-2) 168px var(--fsl-bone),
        var(--fsl-column-3) 168px var(--fsl-bone),
        0 224px var(--fsl-bone),
        var(--fsl-column-1) 224px var(--fsl-bone),
        var(--fsl-column-2) 224px var(--fsl-bone),
        var(--fsl-column-3) 224px var(--fsl-bone),
        0 280px var(--fsl-bone),
        var(--fsl-column-1) 280px var(--fsl-bone),
        var(--fsl-column-2) 280px var(--fsl-bone),
        var(--fsl-column-3) 280px var(--fsl-bone),
        0 336px var(--fsl-bone),
        var(--fsl-column-1) 336px var(--fsl-bone),
        var(--fsl-column-2) 336px var(--fsl-bone),
        var(--fsl-column-3) 336px var(--fsl-bone);
}

/* Notifications panel: three notifications (icon, title, two lines of text) */
.fi-no-notifications-loading-ctn { padding: 16px 24px !important; }

.fi-no-notifications-loading-ctn::before {
    content: "";
    display: block;
    height: 228px;
    background:
        radial-gradient(circle at 12px 12px, var(--fsl-bone) 11px, transparent 12px) 0 4px / 24px 76px repeat-y,
        linear-gradient(to bottom, var(--fsl-bone) 0 12px, transparent 12px) 40px 4px / 50% 76px repeat-y,
        linear-gradient(to bottom, var(--fsl-bone) 0 10px, transparent 10px) 40px 26px / 78% 76px repeat-y,
        linear-gradient(to bottom, var(--fsl-bone) 0 10px, transparent 10px) 40px 44px / 42% 76px repeat-y;
}

/* Lazy loaded schemas: form rows (label, field) */
.fi-sc-loading { padding: 4px 0 !important; }

.fi-sc-loading::before {
    content: "";
    display: block;
    /* `.fi-sc` children are laid out by Filament's schema grid rules: give the bones the full width. */
    width: 100%;
    height: 228px;
    background:
        linear-gradient(to bottom, var(--fsl-bone) 0 12px, transparent 12px) 0 0 / 28% 76px repeat-y,
        linear-gradient(to bottom, var(--fsl-bone) 0 36px, transparent 36px) 0 22px / 100% 76px repeat-y;
}


/* Page loader (opt-in: SkeletonLoadingPlugin::pageLoader()) */
#fsl-page-loader {
    position: fixed;
    inset: 0;
    z-index: 2147483000;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    color: var(--primary-600, #0a0a0a);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

#fsl-page-loader.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.2s ease;
}

.dark #fsl-page-loader { background: #0a0a0a; color: #ffffff; }

#fsl-page-loader .fsl-loader-symbol svg { display: block; overflow: visible; }

#fsl-page-loader .fsl-loader-piece {
    transform-box: fill-box;
    transform-origin: center;
    animation: fsl-loader-piece 2.4s cubic-bezier(0.4, 0, 0.2, 1) infinite both;
    animation-play-state: paused;
}

#fsl-page-loader .fsl-loader-piece:nth-of-type(2) { animation-delay: 0.16s; }
#fsl-page-loader .fsl-loader-piece:nth-of-type(3) { animation-delay: 0.32s; }
#fsl-page-loader .fsl-loader-piece:nth-of-type(4) { animation-delay: 0.48s; }
#fsl-page-loader .fsl-loader-piece:nth-of-type(5) { animation-delay: 0.64s; }
#fsl-page-loader .fsl-loader-piece:nth-of-type(6) { animation-delay: 0.8s; }

/* Generic dots: a quicker rise-and-fall instead of the brand sequence */
#fsl-page-loader .fsl-loader-symbol--generic .fsl-loader-piece {
    animation-name: fsl-loader-dot;
    animation-duration: 1.2s;
    animation-timing-function: ease-in-out;
}

@keyframes fsl-loader-dot {
    0%, 70%, 100% { opacity: 0.3; transform: none; }
    35% { opacity: 1; transform: translateY(-10px); }
}

@keyframes fsl-loader-piece {
    0% { opacity: 0; transform: translateY(36px); }
    18%, 62% { opacity: 1; transform: none; }
    82%, 100% { opacity: 0; transform: none; }
}

#fsl-page-loader .fsl-loader-label {
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: #525252;
    animation: fsl-loader-label 1.6s ease-in-out infinite alternate;
    animation-play-state: paused;
}

.dark #fsl-page-loader .fsl-loader-label { color: #a3a3a3; }

#fsl-page-loader.is-visible .fsl-loader-piece,
#fsl-page-loader.is-visible .fsl-loader-label { animation-play-state: running; }

@keyframes fsl-loader-label {
    from { opacity: 0.55; }
    to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .fsl-bone::after,
    .fi-ta-table-loading-ctn::after,
    .fi-no-notifications-loading-ctn::after,
    .fi-sc-loading::after {
        display: none;
        animation: none;
    }

    /* As specific as the generic dots' rule, so their bounce stops too. */
    #fsl-page-loader .fsl-loader-symbol .fsl-loader-piece,
    #fsl-page-loader .fsl-loader-label {
        animation: none;
    }
}

/* Style the cells that Filament already marks as loading. Filament 4 names the colour
 * `--loading-skeleton-background-color`, Filament 5 `--loading-skeleton-bg`: set both. */
.fi-ta-content-loading {
    --loading-skeleton-border-radius: var(--fsl-rounded, var(--fsl-bone-radius, var(--radius-md, 6px)));
    --loading-skeleton-bg: rgb(0 0 0 / 0.07);
    --loading-skeleton-background-color: rgb(0 0 0 / 0.07);
}

.dark .fi-ta-content-loading {
    --loading-skeleton-bg: rgb(255 255 255 / 0.08);
    --loading-skeleton-background-color: rgb(255 255 255 / 0.08);
}

/* Keep Filament's status and load trigger when the content hook supplies a richer placeholder. */
.fsl-deferred-table ~ .fi-ta-content-ctn .fi-ta-table-loading-ctn {
    padding: 0 !important;
}

.fsl-deferred-table ~ .fi-ta-content-ctn .fi-ta-table-loading-ctn::before,
.fsl-deferred-table ~ .fi-ta-content-ctn .fi-ta-table-loading-ctn::after {
    display: none;
}

.fsl-deferred-cells {
    display: grid;
    grid-template-columns: repeat(var(--fsl-columns), minmax(0, 1fr));
    grid-auto-rows: 14px;
    gap: 42px clamp(8px, 3vw, 24px);
    padding: 21px 24px;
}

.fsl-deferred-cards {
    gap: 16px;
    padding: 16px 24px;
}

.fsl-deferred-card {
    display: grid;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--fsl-border);
    border-radius: var(--radius-xl, 12px);
}

.fi-sc-loading[data-fsl-schema="infolist"]::before,
.fi-sc-loading:not([data-fsl-schema])[data-fsl-schema-default="infolist"]::before {
    background:
        linear-gradient(var(--fsl-bone) 0 9px, transparent 9px) 0 0 / 24% 76px repeat-y,
        linear-gradient(var(--fsl-bone) 0 16px, transparent 16px) 0 21px / 65% 76px repeat-y;
}

.fi-sc-loading[data-fsl-schema="list"]::before,
.fi-sc-loading:not([data-fsl-schema])[data-fsl-schema-default="list"]::before {
    background:
        linear-gradient(var(--fsl-bone) 0 40px, transparent 40px) 0 8px / 100% 76px repeat-y;
}

html:has([data-fsl-search]) [role="listbox"][aria-busy="true"] ~ .fi-select-input-message::after {
    content: "";
    display: block;
    width: 72%;
    height: 8px;
    margin-block: 10px 30px;
    border-radius: var(--fsl-rounded, var(--fsl-bone-radius, var(--radius-md, 6px)));
    color: rgb(0 0 0 / 0.07);
    background: currentColor;
    box-shadow: 0 16px currentColor, 0 32px currentColor;
}

.dark:has([data-fsl-search]) [role="listbox"][aria-busy="true"] ~ .fi-select-input-message::after {
    color: rgb(255 255 255 / 0.08);
}

.fi-global-search-ctn:has(> .fsl-global-search-loading) {
    position: relative;
}

.fsl-global-search-loading {
    position: absolute;
    z-index: 10;
    inset-block-start: 100%;
    inset-inline-end: 0;
    width: 100%;
    pointer-events: none;
}

.fi-global-search-ctn:not(:has(input[type="search"]:focus:not(:placeholder-shown))) > .fsl-global-search-loading {
    display: none !important;
}

.fsl-global-search-loading > .fsl-skeleton {
    display: grid;
    gap: 12px;
    padding: 14px;
    background: white;
    border: 1px solid var(--fsl-border);
    border-radius: var(--radius-lg, 8px);
}

.dark .fsl-global-search-loading > .fsl-skeleton {
    background: var(--gray-900, #18181b);
}
