/*
 * deboTrack motion — small, quick touches that make the CRM feel responsive.
 * Loaded after theme.css by resources/views/debotrack/layout/head.blade.php; behaviour is in motion.js.
 *
 * Rules of thumb: everything is under 0.4s, nothing blocks clicking, and every effect (except the thin
 * progress bar) is switched off for people who ask their system to reduce motion.
 * Hover/press effects use the individual `translate` / `scale` properties so they never fight a library's
 * own `transform` (e.g. drag-and-drop on the kanban board).
 */

/* Thin progress bar along the top while a page or data request is loading. */
#dt-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    z-index: 100000;
    pointer-events: none;
    background: var(--brand-color);
    box-shadow: 0 0 8px var(--brand-color);
    transform: scaleX(0);
    transform-origin: left;
    opacity: 0;
}
#dt-progress.dt-on { opacity: 1; transition: transform 8s cubic-bezier(.1, .6, .2, 1); transform: scaleX(.85); }
#dt-progress.dt-done { opacity: 0; transition: transform .2s ease-out, opacity .4s .2s; transform: scaleX(1); }

/* Loading skeletons: calm neutral bars with one slow, soft sweep (Krayin's default is a hard-edged
   blue-grey strip that reads as flicker). Reduced-motion users get plain static bars. */
.shimmer {
    border-radius: 6px;
    background: rgba(0, 0, 0, .06) !important;
    animation: none !important;
}
html.dark .shimmer { background: rgba(255, 255, 255, .06) !important; }

@media (prefers-reduced-motion: no-preference) {

    @keyframes dt-sweep {
        0% { background-position: 120% 0; }
        100% { background-position: -120% 0; }
    }
    .shimmer {
        background: linear-gradient(100deg, rgba(0, 0, 0, .05) 35%, rgba(0, 0, 0, .10) 50%, rgba(0, 0, 0, .05) 65%) 120% 0 / 220% 100% no-repeat !important;
        animation: dt-sweep 2.4s ease-in-out infinite !important;
    }
    html.dark .shimmer {
        background: linear-gradient(100deg, rgba(255, 255, 255, .04) 35%, rgba(255, 255, 255, .09) 50%, rgba(255, 255, 255, .04) 65%) 120% 0 / 220% 100% no-repeat !important;
    }

    /* Smooth jumps between sections (e.g. the Student / Enquiry Details tabs on the lead form). */
    html { scroll-behavior: smooth; }

    /* Real data rows (they have a hover colour; the loading skeleton's placeholder rows do not, and must not
       animate or they would flicker when replaced) ease in one after another when data arrives, and again
       after a search, sort or page change. */
    @keyframes dt-row-in {
        from { opacity: 0; transform: translateY(6px); }
        to { opacity: 1; transform: none; }
    }
    .row.grid[class*="hover:bg-gray-50"] { animation: dt-row-in .32s cubic-bezier(.2, .7, .2, 1) backwards; }
    .row.grid[class*="hover:bg-gray-50"]:nth-child(2) { animation-delay: 0ms; }
    .row.grid[class*="hover:bg-gray-50"]:nth-child(3) { animation-delay: 30ms; }
    .row.grid[class*="hover:bg-gray-50"]:nth-child(4) { animation-delay: 60ms; }
    .row.grid[class*="hover:bg-gray-50"]:nth-child(5) { animation-delay: 90ms; }
    .row.grid[class*="hover:bg-gray-50"]:nth-child(6) { animation-delay: 120ms; }
    .row.grid[class*="hover:bg-gray-50"]:nth-child(7) { animation-delay: 150ms; }
    .row.grid[class*="hover:bg-gray-50"]:nth-child(8) { animation-delay: 180ms; }
    .row.grid[class*="hover:bg-gray-50"]:nth-child(9) { animation-delay: 210ms; }
    .row.grid[class*="hover:bg-gray-50"]:nth-child(10) { animation-delay: 240ms; }
    .row.grid[class*="hover:bg-gray-50"]:nth-child(11) { animation-delay: 270ms; }

    /* Kanban cards fade in (opacity only, so drag-and-drop transforms are never fought). */
    @keyframes dt-fade-in { from { opacity: 0; } to { opacity: 1; } }
    .lead-item { animation: dt-fade-in .3s ease backwards; }

    /* Links and buttons change colour smoothly instead of snapping. */
    a, button { transition: color .15s ease, background-color .15s ease, border-color .15s ease, opacity .15s ease; }

    /* Buttons: lift a little on hover, press in on click. */
    .primary-button,
    .secondary-button,
    .transparent-button {
        transition: translate .15s ease, scale .15s ease, box-shadow .2s ease, background-color .2s ease, filter .2s ease;
    }
    .primary-button:not(:disabled):hover,
    .secondary-button:not(:disabled):hover { translate: 0 -1px; box-shadow: 0 6px 14px rgba(0, 0, 0, .12); }
    .primary-button:not(:disabled):active,
    .secondary-button:not(:disabled):active,
    .transparent-button:not(:disabled):active { translate: 0 0; scale: .97; box-shadow: none; }

    /* Kanban cards: rise on hover (not while being dragged). */
    .lead-item { transition: translate .18s ease, box-shadow .2s ease; }
    .lead-item:hover:not(.sortable-chosen):not(.sortable-ghost) { translate: 0 -3px; box-shadow: 0 10px 22px rgba(0, 0, 0, .14); }

    /* Sidebar: items change background smoothly (no sideways nudge: it made the hovered item look misaligned
       next to the pop-out submenu). */
    [class*="group/item"] > a { transition: background-color .15s ease; }

    /* Form fields: soft green glow when focused. */
    input:not([type="checkbox"]):not([type="radio"]):focus,
    select:focus,
    textarea:focus { box-shadow: 0 0 0 3px var(--dt-accent-tint); transition: box-shadow .2s ease, border-color .2s ease; }

    /* Switching light/dark fades instead of snapping (motion.js adds the class for 0.35s). */
    html.dt-theme-anim,
    html.dt-theme-anim * {
        transition: background-color .3s ease, color .3s ease, border-color .3s ease, fill .3s ease !important;
    }

    /* Footer message changes. */
    .dt-msg { transition: opacity .35s ease, translate .35s ease; }
    .dt-msg.dt-out { opacity: 0; translate: 0 5px; }
}

/* Footer message: while motion.js is choosing the greeting the bar's text is held back (invisible), so the
   stock "Welcome to deboTrack" line never flashes before it is replaced. `dt-js` is added by an inline script
   in the page head and removed again by motion.js (or after 2.5s, whichever comes first). */
html.dt-js div.fixed.bottom-0.left-0.right-0 p:not(.dt-msg) { opacity: 0; }

/* Footer message is clickable (shows the next line) — hint it with the cursor. */
.dt-msg { cursor: pointer; user-select: none; }

/* ---------------------------------------------------------------------------
   Page-to-page transitions (Chrome / Edge). Every menu click is a normal page load, so instead of a blank
   flash the browser keeps the old page on screen, then cross-fades to the new one. The header, sidebar and
   footer bar are given their own names so they stay still while only the content fades.
   Browsers without support simply load the page as before.
   --------------------------------------------------------------------------- */
@view-transition { navigation: auto; }

header.sticky { view-transition-name: dt-header; }
div.fixed[class*="top-[60px]"][class*="w-[200px]"] { view-transition-name: dt-sidebar; }
div.fixed.bottom-0[class*="max-w-[200px]"] { view-transition-name: dt-collapse; }
div.fixed.bottom-0.left-0.right-0 { view-transition-name: dt-footer; }

::view-transition-group(root) { animation-duration: .22s; }
::view-transition-old(root) { animation-timing-function: ease-in; }
::view-transition-new(root) { animation-timing-function: ease-out; }

@media (prefers-reduced-motion: reduce) {
    @view-transition { navigation: none; }
}
