/* ==========================================================================
   SKELETON + SHIMMER
   ==========================================================================
   Loading placeholders for SupplyLink. Registered globally by AppAsset, so
   every view under views/site/ can use these classes without registering
   anything itself.

   Two surface contexts exist in this app and they need opposite treatments:

     - Glass surfaces (the blue-gradient pages: suppliers, products, cart,
       order-history) sit on translucent white cards. Skeletons there are
       light-on-dark.
     - Light surfaces (modals, white panels) need dark-on-light. Add the
       `.skeleton-on-light` modifier to the wrapper.

   Markup for the shapes lives in views/site/_skeleton.php so the server and
   the JS helper share one definition. This file owns appearance only.

   Contents:
     1. Tokens
     2. Base + shimmer
     3. Shape variants
     4. Compositions (the repeated page structures)
     5. Wrapper / swap behaviour
     6. Reduced motion
   ========================================================================== */

/* ==========================================================================
   1. TOKENS
   ========================================================================== */

:root {
    /* On glass / dark surfaces */
    --skeleton-base: rgba(255, 255, 255, 0.11);
    --skeleton-highlight: rgba(255, 255, 255, 0.22);
    --skeleton-border: rgba(255, 255, 255, 0.14);

    /* On white surfaces (modals) */
    --skeleton-base-light: rgba(26, 26, 26, 0.07);
    --skeleton-highlight-light: rgba(26, 26, 26, 0.13);
    --skeleton-border-light: rgba(26, 26, 26, 0.09);

    --skeleton-radius: 6px;
    --skeleton-radius-lg: 16px;
    --skeleton-speed: 1.5s;
}

/* ==========================================================================
   2. BASE + SHIMMER
   ==========================================================================
   The sweep is a pseudo-element moved with transform only — no background-
   position animation, which cannot be GPU-composited and repaints the whole
   element on every frame. Matters here because a list shows 6-10 at once. */

.skeleton {
    position: relative;
    overflow: hidden;
    display: block;
    background-color: var(--skeleton-base);
    border-radius: var(--skeleton-radius);
    /* Placeholders must never be read out or focusable */
    pointer-events: none;
    user-select: none;
}

.skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background-image: linear-gradient(
        90deg,
        transparent 0%,
        var(--skeleton-highlight) 50%,
        transparent 100%
    );
    animation: skeleton-shimmer var(--skeleton-speed) ease-in-out infinite;
    will-change: transform;
}

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

/* Stagger rows slightly so a list shimmers as a wave rather than a flat pulse */
.skeleton-list > *:nth-child(2) .skeleton::after,
.skeleton-grid > *:nth-child(2) .skeleton::after { animation-delay: 0.08s; }
.skeleton-list > *:nth-child(3) .skeleton::after,
.skeleton-grid > *:nth-child(3) .skeleton::after { animation-delay: 0.16s; }
.skeleton-list > *:nth-child(4) .skeleton::after,
.skeleton-grid > *:nth-child(4) .skeleton::after { animation-delay: 0.24s; }
.skeleton-list > *:nth-child(5) .skeleton::after,
.skeleton-grid > *:nth-child(5) .skeleton::after { animation-delay: 0.32s; }
.skeleton-list > *:nth-child(n+6) .skeleton::after,
.skeleton-grid > *:nth-child(n+6) .skeleton::after { animation-delay: 0.4s; }

/* -- Light-surface variant ---------------------------------------------- */
.skeleton-on-light .skeleton { background-color: var(--skeleton-base-light); }

.skeleton-on-light .skeleton::after {
    background-image: linear-gradient(
        90deg,
        transparent 0%,
        var(--skeleton-highlight-light) 50%,
        transparent 100%
    );
}

/* ==========================================================================
   3. SHAPE VARIANTS
   ========================================================================== */

.skeleton-text { height: 0.875rem; border-radius: 4px; }
.skeleton-text--sm { height: 0.6875rem; }
.skeleton-text--lg { height: 1.125rem; }

/* Ragged line ends read as text far better than uniform bars */
.skeleton-text--w90 { width: 90%; }
.skeleton-text--w75 { width: 75%; }
.skeleton-text--w60 { width: 60%; }
.skeleton-text--w45 { width: 45%; }
.skeleton-text--w30 { width: 30%; }

.skeleton-title {
    height: 1.5rem;
    width: 55%;
    border-radius: 5px;
}

.skeleton-circle { border-radius: 50%; flex-shrink: 0; }
.skeleton-circle--sm { width: 32px; height: 32px; }
.skeleton-circle--md { width: 44px; height: 44px; }
.skeleton-circle--lg { width: 64px; height: 64px; }

.skeleton-square { border-radius: 10px; flex-shrink: 0; }
.skeleton-square--sm { width: 40px; height: 40px; }
.skeleton-square--md { width: 56px; height: 56px; }
.skeleton-square--lg { width: 80px; height: 80px; }

.skeleton-btn { height: 42px; width: 130px; border-radius: 10px; }
.skeleton-btn--block { width: 100%; }
.skeleton-badge { height: 24px; width: 68px; border-radius: 12px; }
.skeleton-input { height: 48px; width: 100%; border-radius: 10px; }
.skeleton-thumb { width: 100%; height: 150px; border-radius: 12px; }

/* ==========================================================================
   4. COMPOSITIONS
   ==========================================================================
   Each mirrors the real component it stands in for, so swapping in the real
   content does not shift the layout. */

.skeleton-list { display: flex; flex-direction: column; gap: 1rem; }

.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.25rem;
}

/* Shared shell — matches the glass cards used across the app */
.skeleton-card {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--skeleton-border);
    border-radius: var(--skeleton-radius-lg);
    padding: 1.25rem;
    backdrop-filter: blur(10px);
}

.skeleton-on-light .skeleton-card {
    background: rgba(26, 26, 26, 0.02);
    border-color: var(--skeleton-border-light);
    backdrop-filter: none;
}

.skeleton-card__row {
    display: flex;
    align-items: center;
    gap: 0.875rem;
}

.skeleton-card__body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.skeleton-card__footer {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.125rem;
    padding-top: 1rem;
    border-top: 1px solid var(--skeleton-border);
}

.skeleton-on-light .skeleton-card__footer { border-top-color: var(--skeleton-border-light); }

.skeleton-card__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    margin-top: 1rem;
}

/* -- Product row (products.php: title, id/unit chips, qty stepper) ------ */
.skeleton-product {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--skeleton-border);
    border-radius: var(--skeleton-radius-lg);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
}

.skeleton-product__chips { display: flex; gap: 0.625rem; }

/* Mirrors .input-with-controls so the stepper does not jump on swap */
.skeleton-product__stepper {
    height: 52px;
    width: 190px;
    border-radius: 12px;
}

/* -- Stat tile (order-statistics.php) ----------------------------------- */
.skeleton-stat {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--skeleton-border);
    border-radius: var(--skeleton-radius-lg);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* ==========================================================================
   5. WRAPPER / SWAP BEHAVIOUR
   ========================================================================== */

/* Announce to assistive tech that content is loading, once per region,
   rather than letting it read a wall of empty boxes. */
.skeleton-wrap { display: block; }
.skeleton-wrap[hidden] { display: none !important; }

/* Screen-reader-only status text that ships inside every skeleton block */
.skeleton-status {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Cross-fade the real content in. Opacity only — no layout work. */
.skeleton-reveal {
    animation: skeleton-reveal 260ms ease-out both;
}

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

/* Inline variant: a skeleton sitting where a value will appear */
.skeleton-inline {
    display: inline-block;
    vertical-align: middle;
    height: 1em;
    width: 3.5em;
}

/* ==========================================================================
   6. REDUCED MOTION
   ==========================================================================
   A shimmer is a continuously looping animation across the whole viewport —
   exactly what this preference exists to stop. The placeholder shape still
   communicates "loading", so only the sweep is dropped. */

@media (prefers-reduced-motion: reduce) {
    .skeleton::after {
        animation: none;
        transform: none;
        /* Static wash so the block still reads as a placeholder, not an empty box */
        background-image: linear-gradient(
            90deg,
            transparent 0%,
            var(--skeleton-highlight) 50%,
            transparent 100%
        );
        opacity: 0.5;
    }

    .skeleton-reveal { animation: none; }
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 768px) {
    .skeleton-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .skeleton-product__stepper { width: 100%; }
    .skeleton-card { padding: 1rem; }
    .skeleton-product { padding: 1rem; }
    .skeleton-card__meta { gap: 0.875rem; }
    .skeleton-thumb { height: 120px; }
}
