/*
 * ASHOKA - global motion & feedback layer
 * Loaded after style.css by templates/layout.html; driven by static/js/ui-motion.js.
 * Everything here is pure CSS/SVG (no GIFs): tiny, theme-coloured, and it
 * switches off for people who asked their device for reduced motion.
 */

/* ---------- Top progress bar (any fetch / form submit / page change) ---------- */
#app-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    z-index: 2000;
    background: linear-gradient(90deg, var(--fx-accent, #f7df4c), #ffb020);
    box-shadow: 0 0 10px rgba(247, 223, 76, 0.7);
    opacity: 0;
    pointer-events: none;
    transition: width 0.25s ease, opacity 0.3s ease;
}
#app-progress.is-active {
    opacity: 1;
    width: 80%;
    transition: width 8s cubic-bezier(0.1, 0.6, 0.2, 1), opacity 0.2s ease;
}
#app-progress.is-done {
    width: 100%;
    transition: width 0.2s ease, opacity 0.4s ease 0.2s;
    opacity: 0;
}

/* ---------- Submit buttons while the request is running ---------- */
.btn.is-submitting {
    position: relative;
    pointer-events: none;
    opacity: 0.85;
}
.btn.is-submitting .app-btn-spinner {
    display: inline-block;
    width: 0.95em;
    height: 0.95em;
    margin-right: 0.45em;
    vertical-align: -0.12em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: app-spin 0.7s linear infinite;
}

/* ---------- Toasts (server flash messages + window.notify) ---------- */
#app-toasts {
    z-index: 2100;
    max-width: min(420px, calc(100vw - 2rem));
}
#app-toasts .toast {
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.8));
    backdrop-filter: blur(18px) saturate(160%);
    box-shadow: 0 18px 40px rgba(2, 8, 23, 0.18);
    color: #0b1220;
    font-weight: 500;
}
#app-toasts .toast.showing,
#app-toasts .toast.show {
    animation: app-toast-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2) backwards;
}
#app-toasts .toast-body {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
}
#app-toasts .toast .btn-close {
    margin-left: auto;
    flex-shrink: 0;
}
.app-toast-icon {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
}
.app-toast-icon svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.app-toast-icon svg .draw {
    stroke-dasharray: 60;
    stroke-dashoffset: 60;
    animation: app-draw 0.5s ease-out 0.15s forwards;
}
.toast-success .app-toast-icon { background: rgba(25, 135, 84, 0.14); color: #198754; }
.toast-error   .app-toast-icon { background: rgba(220, 53, 69, 0.14); color: #dc3545; }
.toast-warning .app-toast-icon { background: rgba(255, 176, 32, 0.18); color: #b26a00; }
.toast-info    .app-toast-icon { background: rgba(13, 110, 253, 0.12); color: #0d6efd; }
#app-toasts .toast.toast-error { border-left: 4px solid #dc3545; }
#app-toasts .toast.toast-success { border-left: 4px solid #198754; }
#app-toasts .toast.toast-warning { border-left: 4px solid #ffb020; }
#app-toasts .toast.toast-info { border-left: 4px solid #0d6efd; }

/* ---------- Big success check (window.notify.celebrate) ---------- */
.app-celebrate {
    position: fixed;
    inset: 0;
    z-index: 2050;
    display: grid;
    place-items: center;
    background: rgba(11, 18, 32, 0.25);
    backdrop-filter: blur(4px);
    animation: app-fade 0.25s ease backwards;
    pointer-events: none;
}
.app-celebrate .app-celebrate-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 26px;
    padding: 2rem 2.5rem;
    text-align: center;
    box-shadow: 0 24px 60px rgba(2, 8, 23, 0.25);
    animation: app-pop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.3) backwards;
}
.app-celebrate svg {
    width: 88px;
    height: 88px;
    fill: none;
    stroke: #198754;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.app-celebrate svg .ring {
    stroke-dasharray: 260;
    stroke-dashoffset: 260;
    animation: app-draw 0.6s ease-out forwards;
}
.app-celebrate svg .draw {
    stroke-dasharray: 60;
    stroke-dashoffset: 60;
    animation: app-draw 0.4s ease-out 0.45s forwards;
}
.app-celebrate .app-celebrate-text {
    margin-top: 0.75rem;
    font-weight: 800;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
}
.app-celebrate.is-leaving {
    animation: app-fade 0.3s ease reverse forwards;
}

/* ---------- Cards glide in when a page opens ---------- */
.theme-fashion .card {
    animation: app-rise 0.45s ease-out backwards;
}
.theme-fashion .card:nth-child(2) { animation-delay: 0.05s; }
.theme-fashion .card:nth-child(3) { animation-delay: 0.10s; }
.theme-fashion .card:nth-child(4) { animation-delay: 0.15s; }
.theme-fashion .card:nth-child(n+5) { animation-delay: 0.20s; }
.theme-fashion .row > [class*="col"]:nth-child(2) > .card { animation-delay: 0.06s; }
.theme-fashion .row > [class*="col"]:nth-child(3) > .card { animation-delay: 0.12s; }
.theme-fashion .row > [class*="col"]:nth-child(4) > .card { animation-delay: 0.18s; }
.theme-fashion .row > [class*="col"]:nth-child(n+5) > .card { animation-delay: 0.24s; }
.theme-fashion .modal .card { animation: none; }

/* KPI numbers count up (ui-motion.js); keep width stable while they tick */
.glass-kpi .h4[data-count] {
    font-variant-numeric: tabular-nums;
}

/* ---------- Skeleton placeholder for panels that load by fetch ---------- */
.skeleton {
    display: block;
    border-radius: 10px;
    min-height: 1em;
    background: linear-gradient(90deg, rgba(16, 24, 40, 0.06) 25%, rgba(16, 24, 40, 0.12) 37%, rgba(16, 24, 40, 0.06) 63%);
    background-size: 400% 100%;
    animation: app-shimmer 1.4s ease infinite;
}
.skeleton-text { height: 0.9em; margin: 0.35em 0; }
.skeleton-title { height: 1.4em; width: 45%; margin-bottom: 0.6em; }
.skeleton-block { height: 120px; }

/* ---------- Keyframes ---------- */
@keyframes app-spin { to { transform: rotate(360deg); } }
@keyframes app-draw { to { stroke-dashoffset: 0; } }
@keyframes app-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes app-pop {
    from { opacity: 0; transform: scale(0.7) translateY(12px); }
    to { opacity: 1; transform: none; }
}
@keyframes app-rise {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
}
@keyframes app-toast-in {
    from { opacity: 0; transform: translateX(24px) scale(0.96); }
    to { opacity: 1; transform: none; }
}
@keyframes app-shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: 0 0; }
}

/* ---------- Respect the device's reduced-motion setting ---------- */
@media (prefers-reduced-motion: reduce) {
    #app-progress,
    .btn.is-submitting .app-btn-spinner,
    #app-toasts .toast,
    .app-toast-icon svg .draw,
    .app-celebrate,
    .app-celebrate .app-celebrate-card,
    .app-celebrate svg .ring,
    .app-celebrate svg .draw,
    .theme-fashion .card,
    .skeleton {
        animation: none !important;
        transition: none !important;
    }
    .app-toast-icon svg .draw,
    .app-celebrate svg .ring,
    .app-celebrate svg .draw {
        stroke-dashoffset: 0;
    }
}
