/* ============================================================
   ControlX ERP — Animations & Visual Interactions
   ============================================================ */

/* ========== Keyframes ========== */

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: none; }
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to   { opacity: 1; transform: none; }
}

@keyframes fadeInLeft {
    from { opacity: 0; transform: translateX(-24px); }
    to   { opacity: 1; transform: none; }
}

@keyframes fadeInRight {
    from { opacity: 0; transform: translateX(24px); }
    to   { opacity: 1; transform: none; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

@keyframes slideInSidebar {
    from { opacity: 0; transform: translateX(-16px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes shimmer {
    0%   { background-position: -800px 0; }
    100% { background-position: 800px 0; }
}

@keyframes pulse-ring {
    0%   { transform: scale(0.8); opacity: 0.8; }
    70%  { transform: scale(1.4); opacity: 0; }
    100% { transform: scale(0.8); opacity: 0; }
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50%       { transform: translateY(-8px); }
}

@keyframes ripple {
    to { transform: scale(4); opacity: 0; }
}

@keyframes spin-slow {
    to { transform: rotate(360deg); }
}

@keyframes countUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes progressFill {
    from { width: 0; }
    to   { width: var(--fill-width, 100%); }
}

@keyframes skeletonWave {
    0%   { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}

@keyframes gradientShift {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes bounceIn {
    0%   { transform: scale(0.3); opacity: 0; }
    50%  { transform: scale(1.05); }
    70%  { transform: scale(0.9); }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

@keyframes notification-badge {
    0%, 100% { transform: scale(1); }
    30%       { transform: scale(1.25); }
    60%       { transform: scale(0.9); }
}

/* ========== Page Entry Animation ========== */

.content-wrapper {
    animation: fadeInUp 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ========== Scroll Reveal ========== */

.reveal {
    opacity: 0;
    transform: translateY(28px);
    transition: opacity 0.55s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.55s cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

.reveal-left {
    opacity: 0;
    transform: translateX(-28px);
    transition: opacity 0.55s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.55s cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal-left.revealed {
    opacity: 1;
    transform: translateX(0);
}

.reveal-scale {
    opacity: 0;
    transform: scale(0.92);
    transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal-scale.revealed {
    opacity: 1;
    transform: scale(1);
}

/* Stagger delays for children */
.stagger-reveal > *:nth-child(1)  { transition-delay: 0.05s; }
.stagger-reveal > *:nth-child(2)  { transition-delay: 0.10s; }
.stagger-reveal > *:nth-child(3)  { transition-delay: 0.15s; }
.stagger-reveal > *:nth-child(4)  { transition-delay: 0.20s; }
.stagger-reveal > *:nth-child(5)  { transition-delay: 0.25s; }
.stagger-reveal > *:nth-child(6)  { transition-delay: 0.30s; }
.stagger-reveal > *:nth-child(7)  { transition-delay: 0.35s; }
.stagger-reveal > *:nth-child(8)  { transition-delay: 0.40s; }
.stagger-reveal > *:nth-child(9)  { transition-delay: 0.45s; }
.stagger-reveal > *:nth-child(10) { transition-delay: 0.50s; }
.stagger-reveal > *:nth-child(11) { transition-delay: 0.55s; }
.stagger-reveal > *:nth-child(12) { transition-delay: 0.60s; }

/* ========== Stat Cards — Number Counter ========== */

.stat-card {
    --card-entrance-delay: 0s;
    animation: fadeInUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) var(--card-entrance-delay) both;
}

.stat-card:nth-child(1) { --card-entrance-delay: 0.05s; }
.stat-card:nth-child(2) { --card-entrance-delay: 0.12s; }
.stat-card:nth-child(3) { --card-entrance-delay: 0.19s; }
.stat-card:nth-child(4) { --card-entrance-delay: 0.26s; }
.stat-card:nth-child(5) { --card-entrance-delay: 0.33s; }
.stat-card:nth-child(6) { --card-entrance-delay: 0.40s; }

.stat-card .stat-value {
    transition: color 0.3s ease;
}

.stat-card:hover .stat-value {
    color: #3b82f6;
}

/* Animated counter target */
[data-counter] {
    display: inline-block;
}

/* ========== Enhanced Stat Card Hover ========== */

.stat-card {
    transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.28s ease,
                border-color 0.28s ease;
    will-change: transform;
}

.stat-card:hover {
    transform: translateY(-5px) scale(1.015);
    box-shadow: 0 12px 32px rgba(59, 130, 246, 0.15), 0 4px 12px rgba(0, 0, 0, 0.08);
    border-color: rgba(59, 130, 246, 0.25);
}

.stat-card .stat-icon {
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.stat-card:hover .stat-icon {
    transform: scale(1.12) rotate(-5deg);
}

/* ========== Card Hover Glow ========== */

.card {
    transition: box-shadow 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
                border-color 0.3s ease;
    will-change: transform;
}

.card-hoverable:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

/* ========== Button Ripple Effect ========== */

.btn {
    position: relative;
    overflow: hidden;
}

.btn .ripple-effect {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
    width: 8px;
    height: 8px;
    transform: scale(0);
    animation: ripple 0.55s linear;
    pointer-events: none;
}

.btn-outline-primary .ripple-effect,
.btn-outline-secondary .ripple-effect {
    background: rgba(59, 130, 246, 0.2);
}

/* ========== Button Micro-interactions ========== */

.btn-primary {
    transition: all 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.4);
}

.btn-primary:active {
    transform: translateY(0) scale(0.97);
}

.btn-outline-primary:hover {
    transform: translateY(-1px);
}

/* ========== Sidebar Nav Link Animations ========== */

.sidebar-nav .nav-link {
    position: relative;
    overflow: hidden;
}

.sidebar-nav .nav-link::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    border-radius: inherit;
}

.sidebar-nav .nav-link:hover::after {
    transform: translateX(0);
}

.sidebar-nav .nav-link i {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.2s ease;
}

    .sidebar-nav .nav-link:hover i {
        transform: scale(1.2);
        color: #60a5fa;
    }
.sidebar-nav .nav-link:hover {
    color: #60a5fa;
}

.sidebar-nav .nav-link.active i {
    animation: bounceIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Sidebar brand icon pulse */
.sidebar-brand .brand-icon {
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.35s ease;
}

.sidebar-brand:hover .brand-icon {
    transform: scale(1.1) rotate(-8deg);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

/* ========== Topbar ========== */

.topbar-icon-btn {
    transition: all 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.topbar-icon-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.topbar-icon-btn:active {
    transform: scale(0.94);
}

/* Notification badge pulse */
.badge-pulse {
    position: relative;
}

.badge-pulse::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    background: #ef4444;
    animation: pulse-ring 2s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
    z-index: -1;
}

/* ========== Table Row Interactions ========== */

table.dataTable tbody tr {
    transition: background-color 0.18s ease, transform 0.18s ease;
}

table.dataTable tbody tr:hover {
    transform: translateX(2px);
}

[dir="rtl"] table.dataTable tbody tr:hover {
    transform: translateX(-2px);
}

/* ========== Form Controls ========== */

.form-control,
.form-select {
    transition: border-color 0.22s ease,
                box-shadow 0.22s ease,
                background-color 0.22s ease,
                transform 0.18s ease;
}

.form-control:focus,
.form-select:focus {
    transform: scale(1.005);
}

.form-label {
    transition: color 0.2s ease;
}

.form-control:focus ~ .form-label,
.form-select:focus ~ .form-label {
    color: #3b82f6;
}

/* ========== Skeleton Loading ========== */

.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 25%,
        rgba(255, 255, 255, 0.06) 50%,
        var(--bg-tertiary) 75%
    );
    background-size: 800px 100%;
    animation: skeletonWave 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
    color: transparent !important;
    pointer-events: none;
    user-select: none;
}

.skeleton * { visibility: hidden; }

.skeleton-text {
    height: 1em;
    border-radius: 4px;
    margin-bottom: 0.5em;
}

.skeleton-text.w-75 { width: 75%; }
.skeleton-text.w-50 { width: 50%; }
.skeleton-text.w-25 { width: 25%; }

.skeleton-card {
    height: 120px;
    border-radius: var(--radius-lg);
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 25%,
        rgba(255, 255, 255, 0.05) 50%,
        var(--bg-tertiary) 75%
    );
    background-size: 800px 100%;
    animation: skeletonWave 1.5s ease-in-out infinite;
}

/* ========== Progress Bar Animated ========== */

.progress .progress-bar {
    animation: progressFill 1.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ========== Dropdown Menus ========== */

@keyframes tbDropIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.dropdown-menu {
    animation: tbDropIn 0.16s ease-out;
}

.dropdown-item {
    transition: background-color 0.18s ease,
                color 0.18s ease,
                padding-left 0.2s ease,
                padding-right 0.2s ease;
}

.dropdown-item:hover {
    padding-left: 18px;
}

[dir="rtl"] .dropdown-item:hover {
    padding-left: inherit;
    padding-right: 18px;
}

/* ========== Modal ========== */

/*
 * Force Bootstrap's z-index hierarchy to hold even when ancestor elements
 * create stacking contexts (e.g. via CSS animations / transforms).
 * The backdrop must always sit below the modal dialog.
 */
.modal-backdrop { z-index: 1040 !important; }
.modal          { z-index: 1055 !important; }

.modal.fade .modal-dialog {
    transform: translateY(-20px) scale(0.97);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.3s ease;
}

.modal.show .modal-dialog {
    transform: translateY(0) scale(1);
}

/* ========== Alerts ========== */

.alert {
    animation: slideInSidebar 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ========== Badges ========== */

.badge {
    transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.22s ease;
}

.badge:hover {
    transform: scale(1.08);
}

/* ========== Page Header ========== */

.page-header {
    animation: fadeInDown 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ========== Quick Action Cards ========== */

.quick-action-card {
    transition: all 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
}

.quick-action-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--gradient-primary);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.quick-action-card:hover::before {
    transform: scaleX(1);
}

.quick-action-card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 10px 28px rgba(59, 130, 246, 0.18);
}

.quick-action-card i {
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.quick-action-card:hover i {
    transform: scale(1.25) rotate(-5deg);
}

/* ========== Toast Notifications ========== */

#toast-container .toast {
    animation: slideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-lg) !important;
}

/* ========== Loading Spinner ========== */

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-color);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin-slow 0.8s linear infinite;
    display: inline-block;
}

/* Full-page overlay loader */
.page-loader {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
    transition: opacity 0.4s ease;
}

.page-loader.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ========== Floating Action Button ========== */

.fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--gradient-primary);
    color: #fff;
    border: none;
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 900;
    animation: fadeInUp 0.5s 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

[dir="rtl"] .fab {
    right: auto;
    left: 28px;
}

.fab:hover {
    transform: scale(1.12) rotate(8deg);
    box-shadow: 0 10px 28px rgba(59, 130, 246, 0.55);
}

/* ========== Hero Icon Grid (Landing) ========== */

.hero-icon-item {
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.3s ease;
}

.hero-icon-item:hover {
    transform: translateY(-6px) scale(1.06);
    box-shadow: 0 12px 28px rgba(59, 130, 246, 0.2);
    z-index: 2;
}

/* ========== Data Table — Entrance ========== */

.dataTables_wrapper {
    animation: fadeIn 0.4s ease both;
}

/* ========== Section Reveal ========== */

.section-fade {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.section-fade.in-view {
    opacity: 1;
    transform: translateY(0);
}

/* ========== Nav Group Toggle Arrow ========== */

.nav-group-toggle .nav-chevron {
    transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}

/* ========== Chart Container Entrance ========== */

.chart-container {
    animation: scaleIn 0.5s 0.15s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ========== Reduced Motion ========== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
