/* ==========================================================================
   HORIZON MOTION SYSTEM (Apple / Linear / Stripe style)
   - GPU-accelerated (transform & opacity only)
   - Respects prefers-reduced-motion AND user toggle html[data-motion="reduced"]
   - 100% print-safe (@media print)
   ========================================================================== */

:root {
    --hm-ease: cubic-bezier(0.22, 1, 0.36, 1);
    --hm-ease-snap: cubic-bezier(0.2, 0.8, 0.2, 1);
    --hm-ease-spring: cubic-bezier(0.34, 1.45, 0.64, 1);
    --hm-fast: 160ms;
    --hm-base: 260ms;
    --hm-slow: 420ms;
}

/* Native Cross-Document View Transitions (Chrome 126+, Edge, Safari 18.2+) */
@view-transition {
    navigation: auto;
}

::view-transition-old(root) {
    animation: hmViewOut 160ms var(--hm-ease) both;
}

::view-transition-new(root) {
    animation: hmViewIn 220ms var(--hm-ease) both;
}

@keyframes hmViewOut {
    from { opacity: 1; }
    to   { opacity: 0.92; }
}

@keyframes hmViewIn {
    from { opacity: 0.92; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   1. TOP NAVIGATION PROGRESS BAR (YouTube / GitHub / Linear style)
   ========================================================================== */
.hm-top-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 2.5px;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 220ms ease;
}

.hm-top-progress.is-active {
    opacity: 1;
}

.hm-top-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--er-primary, #0070d2) 0%, #38bdf8 60%, #818cf8 100%);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.65);
    border-radius: 0 2px 2px 0;
    transition: width 260ms var(--hm-ease);
}

/* ==========================================================================
   2. SMOOTH THEME TRANSITION (Chiaro <-> Scuro)
   ========================================================================== */
html.hm-theme-transitioning,
html.hm-theme-transitioning body,
html.hm-theme-transitioning .er-sidebar,
html.hm-theme-transitioning .er-topbar,
html.hm-theme-transitioning .panel,
html.hm-theme-transitioning .stat-card,
html.hm-theme-transitioning .module-card,
html.hm-theme-transitioning .class-tile,
html.hm-theme-transitioning .er-modal,
html.hm-theme-transitioning .pc-drawer,
html.hm-theme-transitioning .pf-drawer,
html.hm-theme-transitioning .er-table th,
html.hm-theme-transitioning .er-table td {
    transition: background-color 260ms var(--hm-ease),
                color 220ms var(--hm-ease),
                border-color 240ms var(--hm-ease) !important;
}

.hm-theme-spin {
    display: inline-block;
    animation: hmThemePop 340ms var(--hm-ease-spring);
}

@keyframes hmThemePop {
    0%   { transform: rotate(-90deg) scale(0.7); opacity: 0.5; }
    65%  { transform: rotate(12deg) scale(1.12); opacity: 1; }
    100% { transform: rotate(0deg) scale(1); opacity: 1; }
}

/* ==========================================================================
   3. PAGE, PANEL & CARD STAGGERED ENTRANCES
   ========================================================================== */
@keyframes hmFadeUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes hmFadeScale {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes hmRowIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Primary ER workspace sections */
.er-content > .welcome-banner,
.er-content > .panel,
.er-content > .overview-grid,
.er-content > .modules-section,
.er-content > .er-alert,
.er-content > .pc-cmdbar,
.er-content > .ha-cmdbar,
.er-content > .pf-hero,
.er-content > .pf-grid,
.er-content > .pc-split {
    animation: hmFadeUp var(--hm-base) var(--hm-ease) both;
}

.er-content > *:nth-child(2) { animation-delay: 35ms; }
.er-content > *:nth-child(3) { animation-delay: 65ms; }
.er-content > *:nth-child(4) { animation-delay: 95ms; }
.er-content > *:nth-child(5) { animation-delay: 120ms; }

/* Staggered KPI Cards, Module Cards, Class Tiles & PCTO Cards */
.stats-grid > .stat-card,
.modules-grid > .module-card,
.class-code-grid > .class-tile,
.pc-kpis > *,
.pc-classes-grid > *,
.pf-timeline > .pf-card,
.ctx-grid > .ctx-card {
    animation: hmFadeScale var(--hm-base) var(--hm-ease) both;
}

.stats-grid > *:nth-child(1),
.modules-grid > *:nth-child(1),
.class-code-grid > *:nth-child(1),
.pc-kpis > *:nth-child(1),
.pc-classes-grid > *:nth-child(1),
.pf-timeline > *:nth-child(1),
.ctx-grid > *:nth-child(1) { animation-delay: 20ms; }

.stats-grid > *:nth-child(2),
.modules-grid > *:nth-child(2),
.class-code-grid > *:nth-child(2),
.pc-kpis > *:nth-child(2),
.pc-classes-grid > *:nth-child(2),
.pf-timeline > *:nth-child(2),
.ctx-grid > *:nth-child(2) { animation-delay: 50ms; }

.stats-grid > *:nth-child(3),
.modules-grid > *:nth-child(3),
.class-code-grid > *:nth-child(3),
.pc-kpis > *:nth-child(3),
.pc-classes-grid > *:nth-child(3),
.pf-timeline > *:nth-child(3),
.ctx-grid > *:nth-child(3) { animation-delay: 80ms; }

.stats-grid > *:nth-child(4),
.modules-grid > *:nth-child(4),
.class-code-grid > *:nth-child(4),
.pc-kpis > *:nth-child(4),
.pc-classes-grid > *:nth-child(4),
.pf-timeline > *:nth-child(4),
.ctx-grid > *:nth-child(4) { animation-delay: 110ms; }

.stats-grid > *:nth-child(5),
.modules-grid > *:nth-child(5),
.class-code-grid > *:nth-child(5),
.pc-kpis > *:nth-child(5),
.pc-classes-grid > *:nth-child(5),
.pf-timeline > *:nth-child(5) { animation-delay: 140ms; }

.modules-grid > *:nth-child(6),
.class-code-grid > *:nth-child(6),
.pc-classes-grid > *:nth-child(6) { animation-delay: 165ms; }

.modules-grid > *:nth-child(7),
.class-code-grid > *:nth-child(7),
.pc-classes-grid > *:nth-child(7) { animation-delay: 190ms; }

.modules-grid > *:nth-child(8),
.class-code-grid > *:nth-child(8),
.pc-classes-grid > *:nth-child(8) { animation-delay: 215ms; }

.modules-grid > *:nth-child(n+9),
.class-code-grid > *:nth-child(n+9),
.pc-classes-grid > *:nth-child(n+9) { animation-delay: 235ms; }

/* Subtle table row entrance (first 12 rows only so huge tables stay instant) */
.er-table tbody tr:nth-child(-n+12),
.pc-table tbody tr:nth-child(-n+12) {
    animation: hmRowIn 220ms var(--hm-ease) both;
}
.er-table tbody tr:nth-child(1), .pc-table tbody tr:nth-child(1) { animation-delay: 15ms; }
.er-table tbody tr:nth-child(2), .pc-table tbody tr:nth-child(2) { animation-delay: 32ms; }
.er-table tbody tr:nth-child(3), .pc-table tbody tr:nth-child(3) { animation-delay: 49ms; }
.er-table tbody tr:nth-child(4), .pc-table tbody tr:nth-child(4) { animation-delay: 66ms; }
.er-table tbody tr:nth-child(5), .pc-table tbody tr:nth-child(5) { animation-delay: 83ms; }
.er-table tbody tr:nth-child(6), .pc-table tbody tr:nth-child(6) { animation-delay: 100ms; }
.er-table tbody tr:nth-child(7), .pc-table tbody tr:nth-child(7) { animation-delay: 115ms; }
.er-table tbody tr:nth-child(8), .pc-table tbody tr:nth-child(8) { animation-delay: 130ms; }
.er-table tbody tr:nth-child(n+9):nth-child(-n+12),
.pc-table tbody tr:nth-child(n+9):nth-child(-n+12) { animation-delay: 145ms; }

.er-table tbody tr,
.pc-table tbody tr {
    transition: background-color var(--hm-fast) var(--hm-ease);
}

/* ==========================================================================
   4. CARD, TILE, SIDEBAR & TAB MICRO-INTERACTIONS
   ========================================================================== */
.stat-card,
.module-card,
.class-tile,
.pf-card,
.pc-class-card,
.ctx-card {
    transition: transform var(--hm-fast) var(--hm-ease),
                box-shadow var(--hm-base) var(--hm-ease),
                border-color var(--hm-fast) var(--hm-ease),
                background-color var(--hm-fast) var(--hm-ease);
}

.module-card:hover,
.class-tile:hover,
.pc-class-card:hover,
.ctx-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.08);
}

.module-card:active,
.class-tile:active,
.pc-class-card:active {
    transform: translateY(0) scale(0.99);
}

.stat-card:hover {
    transform: translateY(-1.5px);
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.07);
}

.module-card .module-cta {
    transition: transform var(--hm-fast) var(--hm-ease), color var(--hm-fast) ease;
    display: inline-block;
}

.module-card:hover .module-cta {
    transform: translateX(3px);
}

/* Sidebar navigation items */
.sidebar-nav .nav-item {
    transition: background-color var(--hm-fast) var(--hm-ease),
                color var(--hm-fast) var(--hm-ease),
                transform var(--hm-fast) var(--hm-ease),
                padding-left var(--hm-fast) var(--hm-ease);
}

.sidebar-nav .nav-item:hover:not(.is-active) {
    transform: translateX(2px);
}

.sidebar-nav .nav-item .nav-dot {
    transition: transform 220ms var(--hm-ease-spring), background-color var(--hm-fast) ease;
}

.sidebar-nav .nav-item.is-active .nav-dot,
.sidebar-nav .nav-item:hover .nav-dot {
    transform: scale(1.25);
}

/* Segmented Tabs (PCTO, HorizonAudit, Login) */
.ha-tabs a,
.pc-tabs a,
.pc-subtabs a,
.login-tab {
    transition: background-color var(--hm-fast) var(--hm-ease),
                color var(--hm-fast) var(--hm-ease),
                box-shadow var(--hm-base) var(--hm-ease),
                transform var(--hm-fast) var(--hm-ease);
}

.ha-tabs a:active,
.pc-tabs a:active,
.pc-subtabs a:active,
.login-tab:active {
    transform: scale(0.97);
}

/* Attendance cells & status pills micro-feedback */
.att-btn,
.att-cell-btn,
.status-badge,
.pc-pill,
.pf-pill {
    transition: transform var(--hm-fast) var(--hm-ease-snap),
                background-color var(--hm-fast) ease,
                box-shadow var(--hm-fast) ease;
}

.att-btn:hover,
.att-cell-btn:hover {
    transform: translateY(-1px) scale(1.04);
}

.att-btn:active,
.att-cell-btn:active {
    transform: scale(0.94);
}

/* ==========================================================================
   5. TACTILE BUTTONS, RIPPLE WAVE & FORM SUBMIT SPINNER
   ========================================================================== */
.er-btn,
.btn,
.btn-primary,
.pc-btn,
.icon-action-btn {
    position: relative;
    overflow: hidden;
    transition: transform var(--hm-fast) var(--hm-ease-snap),
                background-color var(--hm-fast) ease,
                border-color var(--hm-fast) ease,
                box-shadow var(--hm-fast) ease,
                color var(--hm-fast) ease;
}

.er-btn:hover:not(:disabled),
.pc-btn:hover:not(:disabled),
.icon-action-btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

.er-btn:active:not(:disabled),
.btn:active:not(:disabled),
.btn-primary:active:not(:disabled),
.pc-btn:active:not(:disabled),
.icon-action-btn:active:not(:disabled) {
    transform: translateY(0) scale(0.97);
}

/* Ripple Wave */
.hm-ripple {
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    background: currentColor;
    opacity: 0.22;
    pointer-events: none;
    animation: hmRipple 520ms var(--hm-ease) forwards;
}

@keyframes hmRipple {
    to {
        transform: scale(2.6);
        opacity: 0;
    }
}

/* Inline Button Spinner on Form Submit */
.hm-is-loading {
    pointer-events: none;
    opacity: 0.86;
}

.hm-is-loading::after {
    content: "";
    display: inline-block;
    width: 13px;
    height: 13px;
    margin-left: 7px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    vertical-align: -2px;
    animation: hmSpin 620ms linear infinite;
}

@keyframes hmSpin {
    to { transform: rotate(360deg); }
}

/* Form controls subtle focus transition */
.er-field input,
.er-field select,
.er-field textarea,
.form-input {
    transition: border-color var(--hm-fast) ease,
                box-shadow var(--hm-fast) ease,
                background-color var(--hm-fast) ease;
}

/* ==========================================================================
   6. MODALS & SLIDE-OVER DRAWERS (Smooth Enter + Backdrop Blur)
   ========================================================================== */
.er-modal-backdrop:not(.is-hidden) {
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    animation: hmBackdropIn 180ms var(--hm-ease) both;
}

.er-modal-backdrop:not(.is-hidden) .er-modal {
    animation: hmModalIn 240ms var(--hm-ease) both;
}

.er-modal-backdrop.hm-closing {
    animation: hmBackdropOut 150ms ease forwards;
}

.er-modal-backdrop.hm-closing .er-modal {
    animation: hmModalOut 150ms ease forwards;
}

@keyframes hmBackdropIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes hmBackdropOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

@keyframes hmModalIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.965);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes hmModalOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(8px) scale(0.97);
    }
}

/* Slide-Over Drawers (PCTO Staff, PCTO Family, HorizonScuole, generic) */
.pc-drawer-bg.open,
.pf-drawer-backdrop.open,
.hs-drawer-bg.open,
#granularModulesDrawer[style*="flex"] {
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    animation: hmBackdropIn 200ms var(--hm-ease) both;
}

.pc-drawer-bg.open .pc-drawer,
.pf-drawer-backdrop.open .pf-drawer,
.hs-drawer-bg.open .hs-drawer,
#granularModulesDrawer[style*="flex"] > div {
    animation: hmDrawerIn 280ms var(--hm-ease) both;
}

#onboardModal[style*="flex"],
#newSchoolModal[style*="flex"],
#editSchoolModal[style*="flex"] {
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    animation: hmBackdropIn 180ms var(--hm-ease) both;
}

#onboardModal[style*="flex"] > div,
#newSchoolModal[style*="flex"] > div,
#editSchoolModal[style*="flex"] > div {
    animation: hmModalIn 240ms var(--hm-ease) both;
}

@keyframes hmDrawerIn {
    from {
        opacity: 0.7;
        transform: translateX(36px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Avatar context popover */
#avatarContextMenu:not(.is-hidden) {
    animation: hmPopoverUp 190ms var(--hm-ease) both;
    transform-origin: bottom center;
}

@keyframes hmPopoverUp {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==========================================================================
   7. TOAST NOTIFICATIONS WITH COUNTDOWN BAR & EXIT ANIMATION
   ========================================================================== */
.er-toast {
    position: relative;
    overflow: hidden;
    animation: hmToastIn 260ms var(--hm-ease) both !important;
}

.er-toast::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.45);
    transform-origin: left center;
    animation: hmToastTimer var(--hm-toast-ms, 4200ms) linear forwards;
}

.er-toast:hover::after {
    animation-play-state: paused;
}

.er-toast.hm-toast-out {
    animation: hmToastOut 200ms var(--hm-ease) forwards !important;
}

@keyframes hmToastIn {
    from {
        opacity: 0;
        transform: translateX(22px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes hmToastOut {
    from {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateX(26px) scale(0.96);
    }
}

@keyframes hmToastTimer {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

/* ==========================================================================
   8. DATA & PROGRESS ANIMATIONS (Progress Bars, PCTO Ring, Alerts)
   ========================================================================== */
.pf-bar > span,
.pc-bar > span,
.hm-progress-fill {
    transition: width 680ms var(--hm-ease);
}

.pf-ring-wrap svg circle[stroke-dashoffset] {
    transition: stroke-dashoffset 820ms var(--hm-ease);
}

/* Announcement banner slide fade */
#horizonGlobalAnnBox [data-ann-slide] {
    animation: hmFadeUp 260ms var(--hm-ease) both;
}

/* ==========================================================================
   9. LOGIN & PUBLIC LANDING PAGE ANIMATIONS
   ========================================================================== */
.login-brand-pane .brand-pane-hero {
    animation: hmFadeUp 420ms var(--hm-ease) 60ms both;
}

.login-brand-pane .hero-school-card {
    animation: hmFadeScale 380ms var(--hm-ease) 160ms both;
}

.login-card-v2 {
    animation: hmFadeScale 360ms var(--hm-ease) 40ms both;
}

/* Scroll-Reveal Utility (Landing Page & Long Views) */
.hm-reveal {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 460ms var(--hm-ease),
                transform 460ms var(--hm-ease);
    transition-delay: var(--hm-delay, 0ms);
}

.hm-reveal.hm-revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Subtle ambient pulse on online status dots */
.status-dot {
    animation: hmStatusPulse 2.8s ease-in-out infinite;
}

@keyframes hmStatusPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
    50%      { box-shadow: 0 0 0 5px rgba(34, 197, 94, 0); }
}

/* Motion Toggle Pill in Topbar / Profile */
.hm-motion-btn.is-reduced {
    opacity: 0.65;
    border-style: dashed !important;
}

/* ==========================================================================
   10. REDUCED MOTION & PRINT SAFETY
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .hm-reveal {
        opacity: 1 !important;
        transform: none !important;
    }
    .hm-top-progress {
        display: none !important;
    }
}

html[data-motion="reduced"] *,
html[data-motion="reduced"] *::before,
html[data-motion="reduced"] *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

html[data-motion="reduced"] .hm-reveal {
    opacity: 1 !important;
    transform: none !important;
}

html[data-motion="reduced"] .hm-top-progress {
    display: none !important;
}

@media print {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
    .hm-reveal {
        opacity: 1 !important;
        transform: none !important;
    }
    .hm-top-progress,
    .hm-ripple {
        display: none !important;
    }
}
