/* =============================================================
   Skeleton loading — the shape of the page before its data arrives.

   A skeleton stands in for content that is on its way, drawn at the size
   the real content will take so nothing moves when it lands. One soft band
   of light sweeps left to right across the whole page, passing over every
   block together rather than each block shimmering on its own (the
   gradient is fixed to the viewport), then rests briefly before the next
   pass. Tones are quiet on purpose: a cool grey just off the surface in
   light themes, a muted slate in dark.

   Building blocks (all decorative: put aria-hidden="true" on the skeleton
   and a visually-hidden status beside it, or role="status" on the host):

       <div class="skeleton skeleton-title"></div>
       <div class="skeleton-lines">              text lines, varied widths
           <span class="skeleton skeleton-text"></span> ×3
       </div>
       <span class="skeleton skeleton-avatar"></span>   --sk-size to resize
       <span class="skeleton skeleton-number"></span>   a figure in a line of text
       <span class="skeleton skeleton-btn"></span>
       <span class="skeleton skeleton-input"></span>
       <div class="skeleton skeleton-chart"></div>
       <div class="skeleton skeleton-img" style="--sk-ratio: 16 / 9"></div>
       <div class="skeleton-panes"> <div>…</div> ×columns </div>
       <div class="skeleton-table" style="--sk-cols: 2fr 1fr 1fr 96px">
           <div class="skeleton-row"> <span class="skeleton skeleton-text"></span> ×cols </div>
       </div>

   Any block can be sized in place with --sk-w / --sk-h.

   When the real content replaces a skeleton, give its container
   .app-content-in so it fades in (250ms, 0.98 → 1) instead of popping.

   The page-level skeletons the workspace shell shows while a page loads
   are at the end (.app-page-skeleton); the markup is in
   Views/Shared/_PageSkeletons.cshtml.

   Under prefers-reduced-motion, or the in-app preference, the sweep stops
   and the blocks stay a flat grey; content appears without the fade.
   ============================================================= */

:root {
    --skeleton-base: #eceef2;
    --skeleton-highlight: rgba(255, 255, 255, .85);
    --skeleton-surface: var(--bs-body-bg, #fff);
    --skeleton-edge: rgba(15, 23, 42, .06);
    --skeleton-speed: 1.8s;
}

[data-bs-theme="dark"],
body.dark {
    --skeleton-base: #252f40;
    --skeleton-highlight: rgba(148, 163, 184, .14);
    --skeleton-surface: rgba(30, 41, 59, .55);
    --skeleton-edge: rgba(148, 163, 184, .12);
}

.skeleton {
    display: block;
    width: var(--sk-w, 100%);
    height: var(--sk-h, 1rem);
    flex: none;
    max-width: 100%;
    border-radius: var(--radius-sm, 8px);
    background-color: var(--skeleton-base);
    background-image: linear-gradient(100deg,
        transparent 35%,
        var(--skeleton-highlight) 50%,
        transparent 65%);
    background-size: 200% 100%;
    background-repeat: no-repeat;
    background-attachment: fixed;
    animation: skeleton-sweep var(--skeleton-speed) cubic-bezier(.4, 0, .2, 1) infinite;
    color: transparent !important;
    pointer-events: none;
    user-select: none;
}

/* The band starts fully off the left edge, leaves fully off the right,
   then rests for the last quarter of the cycle. */
@keyframes skeleton-sweep {
    0% { background-position: 140% 0; }
    75%, 100% { background-position: -40% 0; }
}

/* ---- Shapes ---- */

.skeleton-text {
    height: var(--sk-h, .625rem);
    border-radius: var(--radius-pill, 999px);
}

.skeleton-title {
    width: var(--sk-w, 40%);
    height: var(--sk-h, 1.25rem);
    border-radius: var(--radius-pill, 999px);
}

.skeleton-avatar {
    width: var(--sk-size, 40px);
    height: var(--sk-size, 40px);
    border-radius: 50%;
}

.skeleton-btn {
    width: var(--sk-w, 112px);
    height: var(--sk-h, 38px);
    border-radius: var(--radius-sm, 8px);
}

.skeleton-pill {
    width: var(--sk-w, 72px);
    height: var(--sk-h, 22px);
    border-radius: var(--radius-pill, 999px);
}

/* A figure inside a line of text (a stat value): inline, shorter than the
   line, so the line keeps its height when the number replaces it. */
.skeleton-number {
    display: inline-block;
    vertical-align: middle;
    width: var(--sk-w, 2.5ch);
    height: var(--sk-h, .8em);
    border-radius: var(--radius-pill, 999px);
}

.skeleton-input {
    height: var(--sk-h, 38px);
}

.skeleton-chart {
    height: var(--sk-h, 220px);
    border-radius: var(--radius-md, 12px);
}

.skeleton-img {
    height: auto;
    aspect-ratio: var(--sk-ratio, 16 / 9);
    border-radius: var(--radius-md, 12px);
}

/* Paragraph-like stacks: widths vary so it reads as text, not as bars. */
.skeleton-lines {
    display: grid;
    gap: .6rem;
}

    .skeleton-lines > .skeleton:nth-child(4n + 1) { width: var(--sk-w, 92%); }
    .skeleton-lines > .skeleton:nth-child(4n + 2) { width: var(--sk-w, 78%); }
    .skeleton-lines > .skeleton:nth-child(4n + 3) { width: var(--sk-w, 86%); }
    .skeleton-lines > .skeleton:nth-child(4n + 4) { width: var(--sk-w, 60%); }

/* Table rows: one grid per row, columns set by --sk-cols to match the real
   table, and cells that vary in width so columns do not line up as stripes. */
.skeleton-table {
    display: grid;
}

.skeleton-row {
    display: grid;
    grid-template-columns: var(--sk-cols, 2fr 1fr 1fr 1fr);
    align-items: center;
    gap: 16px;
    min-height: var(--sk-row-h, 52px);
    padding: 0 20px;
    border-bottom: 1px solid var(--skeleton-edge);
}

    .skeleton-row:last-child { border-bottom: 0; }
    .skeleton-row > .skeleton:nth-child(3n + 1) { width: 80%; }
    .skeleton-row > .skeleton:nth-child(3n + 2) { width: 62%; }
    .skeleton-row > .skeleton:nth-child(3n + 3) { width: 70%; }
    .skeleton-row:nth-child(even) > .skeleton:nth-child(3n + 1) { width: 66%; }
    .skeleton-row:nth-child(even) > .skeleton:nth-child(3n + 2) { width: 74%; }

    .skeleton-row.skeleton-row-head {
        min-height: 44px;
        background: var(--app-surface-subtle, transparent);
    }

        .skeleton-row.skeleton-row-head > .skeleton { height: .6rem; width: 45%; }

/* A table-cell stand-in for tables whose body is filled by script:
   <tr class="skeleton-tr"><td><span class="skeleton skeleton-text"></span></td>…</tr> */
.skeleton-tr > td { padding-top: 16px !important; padding-bottom: 16px !important; }
.skeleton-tr:nth-child(odd) > td:nth-child(odd) .skeleton,
.skeleton-tr:nth-child(even) > td:nth-child(even) .skeleton { width: 72%; }
.skeleton-tr:nth-child(odd) > td:nth-child(even) .skeleton,
.skeleton-tr:nth-child(even) > td:nth-child(odd) .skeleton { width: 54%; }

/* List items: avatar, two lines, an optional trailing pill. */
.skeleton-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
}

    .skeleton-item > .skeleton-lines { flex: 1; gap: .45rem; }
    .skeleton-item > .skeleton-lines > .skeleton:nth-child(2) { width: 48%; height: .6rem; }

/* One bordered box split into columns (a tree, an editor, a side list):
   <div class="skeleton-panes" style="--sk-panes: 320px 1fr 290px"><div>…</div>×3</div>
   Below 992px of its container only the first pane shows. */
.skeleton-panes {
    display: grid;
    grid-template-columns: var(--sk-panes, 280px minmax(0, 1fr));
    border: 1px solid var(--skeleton-edge);
    border-radius: 14px;
    background: var(--skeleton-surface);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .03);
    overflow: hidden;
}

    .skeleton-panes > * {
        display: grid;
        gap: 14px;
        align-content: start;
        padding: 18px;
    }

    .skeleton-panes > * + * {
        border-inline-start: 1px solid var(--skeleton-edge);
    }

.skeleton-card {
    padding: 20px;
    border: 1px solid var(--skeleton-edge);
    border-radius: var(--radius-lg, 16px);
    background: var(--skeleton-surface);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .03);
}

/* ---- Shared loaders drawn as skeletons ----
   The app's older loaders (.app-loading-state, .app-loading-inline,
   .overview-loader, .synx-modal-loading, the document-preview loaders and
   Leave's organisation tree) are filled with skeleton markup by
   app/components/motion.js wherever they appear; their caption stays for
   screen readers. These rules undo the spinner layout around it. */
.is-skeleton-loader.is-skeleton-loader {
    display: block;
    min-height: 0;
    gap: 0;
    padding: 12px 4px;
    color: inherit;
    text-align: start;
}

    .is-skeleton-loader.is-skeleton-loader::before,
    .is-skeleton-loader.is-skeleton-loader::after {
        content: none;
    }

.skeleton-loader-list > .skeleton-item + .skeleton-item {
    border-top: 1px solid var(--skeleton-edge);
}

.skeleton-loader-tree {
    display: grid;
    gap: 12px;
    padding: 4px;
}

.skeleton-loader-doc {
    display: grid;
    gap: 12px;
    width: min(100%, 720px);
    margin: 0 auto;
    padding: 32px;
}

/* ---- Content arriving ---- */

.app-content-in {
    animation: app-content-in 250ms var(--app-motion-ease-out, cubic-bezier(.2, .8, .2, 1)) both;
}

@keyframes app-content-in {
    from { opacity: 0; transform: scale(.98); }
    to { opacity: 1; transform: none; }
}

/* ---- Page-level skeletons (the workspace shell's loading layer) ----
   Laid out on the same page insets as .synx-main and the same grids as each
   page, so the first paint of the real page lands on the same lines. */

.app-page-skeleton {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* The page insets (app/base/tokens.css) as they apply inside the frame,
       which follow the content area's width (container queries below). */
    padding: 48px 48px 24px;
    text-align: start;
    /* A short hold before it shows, so a page that loads at once never
       flashes a skeleton. */
    animation: skeleton-appear 220ms ease-out 90ms both;
}

@keyframes skeleton-appear {
    from { opacity: 0; }
    to { opacity: 1; }
}

.app-page-skeleton-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

    .app-page-skeleton-head > .skeleton-lines { flex: 1; max-width: 420px; gap: .5rem; }
    .app-page-skeleton-head .skeleton-title { width: 60%; height: 1.75rem; }
    .app-page-skeleton-head .skeleton-text { width: 85%; }

.app-page-skeleton-actions {
    display: flex;
    gap: 8px;
}

/* The shared tab strip (app/components/tabs.css): a rounded track of equal tabs. */
.app-page-skeleton-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    border-radius: 12px;
    background: var(--skeleton-surface);
    border: 1px solid var(--skeleton-edge);
}

    .app-page-skeleton-tabs > .skeleton {
        flex: 1 1 0;
        height: 32px;
        border-radius: 8px;
        opacity: .55;
    }

    .app-page-skeleton-tabs > .skeleton:first-child { opacity: 1; }

.app-page-skeleton-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
}

    .app-page-skeleton-toolbar > .skeleton-input { flex: 1; max-width: 360px; }

.app-page-skeleton-stats {
    display: grid;
    grid-template-columns: repeat(var(--sk-stats, 4), minmax(0, 1fr));
    gap: 16px;
}


.app-page-skeleton-grid {
    display: grid;
    grid-template-columns: repeat(var(--sk-grid, 3), minmax(0, 1fr));
    gap: 20px;
}

    .app-page-skeleton-grid > .skeleton-card { display: grid; gap: 14px; align-content: start; }

/* Expense Management (Views/ExpenseManagement/_ExpenseSkeleton.cshtml):
   the stat row, filter card, type tiles and paired cards of each tab. */
.skeleton-expense,
.skeleton-expense-body {
    display: grid;
    gap: 24px;
    width: 100%;
}

.app-page-skeleton > .skeleton-expense { flex: 1; min-height: 0; align-content: start; }

.skeleton-expense .skeleton-input { width: 100%; }

/* Stat cards: the icon beside the amount, or above it when the cards get
   narrow, on the same breakpoints as .stats-grid in expense-management.css. */
.skeleton-expense-stats { container: sk-expense-stats / inline-size; }

.skeleton-expense-stat {
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: 98px;
    padding: 24px;
    border-radius: 12px;
}

    .skeleton-expense-stat > .skeleton-avatar { --sk-size: 48px; flex-shrink: 0; border-radius: 12px; }
    .skeleton-expense-stat > .skeleton-lines { flex: 1; gap: .6rem; }

@media (min-width: 1025px) {
    @container sk-expense-stats (max-width: 1239px) {
        .skeleton-expense-stat { flex-direction: column; align-items: flex-start; gap: 12px; padding: 20px; min-height: 142px; }
        .skeleton-expense-stat > .skeleton-avatar { --sk-size: 40px; border-radius: 10px; }
        .skeleton-expense-stat > .skeleton-lines { width: 100%; }
    }
}

@media (min-width: 641px) and (max-width: 1024px) {
    @container sk-expense-stats (max-width: 619px) {
        .skeleton-expense-stat { flex-direction: column; align-items: flex-start; gap: 12px; padding: 20px; min-height: 142px; }
        .skeleton-expense-stat > .skeleton-avatar { --sk-size: 40px; border-radius: 10px; }
        .skeleton-expense-stat > .skeleton-lines { width: 100%; }
    }
}

/* One column per field (--sk-fields), like the Payout and My Expenses filters;
   .skeleton-filter-wrap wraps whole cells like the Approvals filters. */
.skeleton-filter {
    display: grid;
    grid-template-columns: repeat(var(--sk-fields, 3), minmax(0, 1fr));
    gap: 12px 16px;
    align-items: end;
}

    .skeleton-filter.skeleton-filter-wrap {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }

    /* Approvals: fields that share the width evenly, beside the Clear button. */
    .skeleton-filter.skeleton-filter-fit {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }

.skeleton-approval-filters {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px 16px;
    align-items: end;
}

.skeleton-expense-types {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 16px;
}

.skeleton-expense-pair {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
}

    .skeleton-expense-pair > .skeleton-card { min-height: 210px; align-content: start; }

/* Overview's two sections load separately: keep the page's gap between them. */
.skeleton-expense[data-expense-skeleton-kind="overview-fuel"] { margin-bottom: 24px; }

@media (max-width: 1024px) {
    .skeleton-expense-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .skeleton-filter { grid-template-columns: minmax(0, 1fr); }
    .skeleton-expense-types { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .skeleton-expense-pair { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
    .skeleton-expense-stats { grid-template-columns: minmax(0, 1fr); }
    .skeleton-expense-types { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.app-page-skeleton .skeleton-card.skeleton-card-flush {
    padding: 0;
    overflow: hidden;
}

/* Inside the shell's loading layer (a size container, see
   app/components/navigation.css) these follow the content area's width,
   matching the breakpoints the page sees inside its frame. */

/* The dashboard grid steps 3 → 2 → 1 columns at 1200px and 768px. */
@container (max-width: 1199.98px) {
    [data-skeleton-kind="dashboard"] .app-page-skeleton-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@container (max-width: 767.98px) {
    [data-skeleton-kind="dashboard"] .app-page-skeleton-grid { grid-template-columns: minmax(0, 1fr); }
}

@container (max-width: 991.98px) {
    .app-page-skeleton { padding: 32px 32px 24px; }
    .app-page-skeleton-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .app-page-skeleton-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .skeleton-panes { grid-template-columns: minmax(0, 1fr); }
    .skeleton-panes > * + * { display: none; }
}

@container (max-width: 575.98px) {
    .app-page-skeleton { padding: 32px 16px 16px; }
    .app-page-skeleton-grid { grid-template-columns: minmax(0, 1fr); }
    .app-page-skeleton-actions > :not(:first-child) { display: none; }
    .skeleton-row { grid-template-columns: 2fr 1fr; }
    .skeleton-row > .skeleton:nth-child(n + 3) { display: none; }
}

/* ---- Reduced motion: the OS setting or the in-app preference ---- */

@media (prefers-reduced-motion: reduce) {
    .skeleton { animation: none; background-image: none; }
    .app-content-in, .app-page-skeleton { animation: none; }
}

:is([data-reduce-animations="true"], .reduce-motion) :is(.skeleton, .app-content-in, .app-page-skeleton) {
    animation: none;
    background-image: none;
}
