/* Fix header not pushing on sidebar hover when minimized */
body[data-kt-app-sidebar-hoverable=true][data-kt-app-sidebar-minimize=on]:has(.app-sidebar:hover) .app-header {
    left: calc(var(--bs-app-sidebar-width-actual) + var(--bs-app-sidebar-gap-start, 0px) + var(--bs-app-sidebar-gap-end, 0px)) !important;
    transition: left 0.3s ease !important;
}

/* Search collapsed/hover fix */
[data-kt-app-sidebar-minimize="on"] #kt_app_sidebar .app-sidebar-search-default {
    display: none !important;
}

[data-kt-app-sidebar-minimize="on"] #kt_app_sidebar .app-sidebar-search-minimize {
    display: flex !important;
}

[data-kt-app-sidebar-minimize="on"] #kt_app_sidebar:hover .app-sidebar-search-default {
    display: block !important;
}

[data-kt-app-sidebar-minimize="on"] #kt_app_sidebar:hover .app-sidebar-search-minimize {
    display: none !important;
}

/* Hide DataTables 2.x native sort span — we use custom KI icons instead */
table.dataTable thead .dt-column-order,
table.dataTable thead .dt-column-order::before,
table.dataTable thead .dt-column-order::after {
    display: none !important;
    content: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    background: none !important;
}

@keyframes iconSpin {
    from { transform: rotate(0); }
    to { transform: rotate(360deg); }
}

#kt_app_sidebar .menu-link:hover .menu-icon i {
    animation: iconSpin 0.4s ease;
}

/* Sidebar Theme Variables */
:root {
    --sb-bg: #ffffff;
    --sb-border: #e2e8f0;
    --sb-text: #64748b;
    --sb-text-active: #0f172a;
    --sb-item-bg-active: rgba(59, 130, 246, 0.08);
    --sb-footer-bg: rgba(248, 250, 252, 0.8);
    --sb-glow: transparent;
}

[data-bs-theme="dark"] {
    --sb-bg: #020617;
    --sb-border: #1e293b;
    --sb-text: #94a3b8;
    --sb-text-active: #ffffff;
    --sb-item-bg-active: rgba(59, 130, 246, 0.15);
    --sb-footer-bg: rgba(15, 23, 42, 0.6);
    --sb-glow: linear-gradient(to bottom, transparent, #3b82f633, transparent);
}

.app-sidebar {
    background: var(--sb-bg) !important;
    border-right: 1px solid var(--sb-border) !important;
    transition: background 0.3s ease, border-color 0.3s ease;
}

.sb-glow-edge {
    background: var(--sb-glow);
}

/* Sidebar Footer Responsive Fixes */
@media (max-width: 991.98px) {
    .app-sidebar-footer {
        padding: 1rem !important;
    }
}

/* Custom Scrollbar for Sidebar */
#kt_app_sidebar_menu_wrapper::-webkit-scrollbar {
    width: 4px;
}
#kt_app_sidebar_menu_wrapper::-webkit-scrollbar-track {
    background: transparent;
}
#kt_app_sidebar_menu_wrapper::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
}
#kt_app_sidebar_menu_wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(59, 130, 246, 0.3);
}

[data-bs-theme="dark"] #kt_app_sidebar_menu_wrapper::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
}
[data-bs-theme="dark"] #kt_app_sidebar_menu_wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(59, 130, 246, 0.4);
}

/* Sidebar Footer Hover */
.app-sidebar-footer .hover-elevate-up {
    background: var(--sb-footer-bg);
    border: 1px solid var(--sb-border);
    transition: all 0.2s ease;
    width: 100%;
}
.app-sidebar-footer .hover-elevate-up:hover {
    background: var(--sb-item-bg-active);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* Sidebar Minimized State Logic */
[data-kt-app-sidebar-minimize="on"] .app-sidebar-footer .hover-elevate-up {
    padding: 0.5rem !important;
    justify-content: center !important;
    gap: 0 !important;
    border: none !important;
    background: transparent !important;
    width: auto !important;
}

body[data-kt-app-sidebar-minimize="on"] .app-sidebar-footer .d-flex.flex-column,
body[data-kt-app-sidebar-minimize="on"] .app-sidebar-footer .btn-icon,
body[data-kt-app-sidebar-minimize="on"] .app-sidebar-search-default {
    display: none !important;
}

body[data-kt-app-sidebar-minimize="on"] .app-sidebar-logo-default {
    display: none !important;
}

body[data-kt-app-sidebar-minimize="on"] .app-sidebar-logo-minimize {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

/* Ensure Sidebar Footer is full on mobile drawer */
@media (max-width: 991.98px) {
    .app-sidebar-footer .d-flex.flex-column,
    .app-sidebar-footer .btn-icon,
    .app-sidebar-footer .profile-btn,
    .app-sidebar-footer .logout-btn {
        display: flex !important;
    }
    .app-sidebar-footer .hover-elevate-up {
        width: 100% !important;
        justify-content: flex-start !important;
        gap: 0.75rem !important;
        padding: 0.75rem !important;
    }
}

/* Active Sidebar Item Glow */
.sb-active {
    position: relative;
}
.sb-active::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background: rgba(59, 130, 246, 0.1);
    filter: blur(15px);
    transform: translate(-50%, -50%);
    z-index: -1;
    border-radius: 10px;
}

/* Sidebar Link Hover States - Power Overrides */
[data-kt-app-layout] .app-sidebar .menu-item .menu-link {
    transition: all 0.2s ease !important;
    background-color: transparent !important;
}

[data-kt-app-layout] .app-sidebar .menu-item .menu-link .menu-title {
    color: var(--sb-text) !important;
}

[data-kt-app-layout] .app-sidebar .menu-item .menu-link:hover:not(.sb-active):not(.sb-child-active) {
    background-color: var(--sb-item-bg-active) !important;
}

[data-kt-app-layout] .app-sidebar .menu-item .menu-link:hover .menu-title,
[data-kt-app-layout] .app-sidebar .menu-item.show > .menu-link .menu-title,
[data-kt-app-layout] .app-sidebar .menu-item.here > .menu-link .menu-title {
    color: var(--sb-text-active) !important;
}

[data-kt-app-layout] .app-sidebar .menu-item .menu-link:hover .menu-icon i,
[data-kt-app-layout] .app-sidebar .menu-item .menu-link:hover .menu-arrow {
    color: var(--sb-text-active) !important;
}

/* Active Item Overrides */
.sb-active .menu-title, .sb-child-active .menu-title {
    color: var(--sb-text-active) !important;
}

/* Ensure sub-menu items also behave */
[data-kt-app-layout] .app-sidebar .menu-sub .menu-link:hover:not(.sb-child-active) {
    color: var(--sb-text-active) !important;
    background-color: transparent !important;
}

/* Illustrative Day/Night Toggle Styles */
.day-night-wrapper {
    display: flex;
    align-items: center;
    transition: all 0.3s ease;
}

.day-night-wrapper:hover {
    transform: translateY(-2px) scale(1.02);
}

.day-night-label {
    position: relative;
    display: block;
    width: 76px;
    height: 38px;
    background: #4facfe;
    background-image: linear-gradient(120deg, #89f7fe 0%, #66a6ff 100%);
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    overflow: hidden;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.1), 0 2px 5px rgba(0,0,0,0.05);
    border: 1px solid rgba(255,255,255,0.2);
}

.day-night-label:active {
    transform: scale(0.92);
}

.day-night-handle {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 30px;
    height: 30px;
    background: #ffce54;
    border-radius: 50%;
    transition: all 0.4s ease;
    z-index: 5;
    box-shadow: 0 0 15px #ffce54, 0 0 25px rgba(255, 206, 84, 0.4), inset -3px -3px 0 rgba(0,0,0,0.1);
    transform: translateX(0);
}

.day-night-stars {
    position: absolute;
    top: 8px;
    left: 12px;
    width: 2px;
    height: 2px;
    background: white;
    border-radius: 50%;
    box-shadow: 8px 14px 0 white, 18px 4px 0 white, 22px 16px 0 white, 4px 22px 0 white;
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes starFloat {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(3px); }
}

.day-night-clouds {
    position: absolute;
    top: 20px;
    right: 8px;
    width: 14px;
    height: 7px;
    background: rgba(255,255,255,0.9);
    border-radius: 10px;
    box-shadow: -6px -3px 0 1px rgba(255,255,255,0.9), -12px 0 0 rgba(255,255,255,0.9);
    opacity: 1;
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    animation: cloudFloat 3s infinite ease-in-out;
}

@keyframes cloudFloat {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(-3px); }
}

/* Dark Mode State */
html[data-bs-theme="dark"] .day-night-label {
    background: #0f172a;
    background-image: linear-gradient(to right, #0f172a 0%, #1e293b 100%);
    border-color: rgba(255,255,255,0.1);
}

html[data-bs-theme="dark"] .day-night-handle {
    transform: translateX(38px) rotate(40deg);
    background: #f1f5f9;
    box-shadow: 0 0 15px rgba(255,255,255,0.4), 0 0 30px rgba(59, 130, 246, 0.4), inset -8px -4px 0 #cbd5e1;
}

html[data-bs-theme="dark"] .day-night-stars {
    opacity: 1;
    transform: translateY(0);
    animation: starFloat 4s infinite ease-in-out;
}

html[data-bs-theme="dark"] .day-night-clouds {
    opacity: 0;
    transform: translateY(20px);
    animation: none;
}

/* Theme Switch Animation (View Transition API) */
::view-transition-old(root),
::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}

::view-transition-old(root) {
    z-index: 1;
}

::view-transition-new(root) {
    z-index: 9999;
    animation: 700ms cubic-bezier(0.4, 0, 0.2, 1) both theme-reveal;
}

@keyframes theme-reveal {
    from {
        clip-path: circle(0% at var(--theme-x) var(--theme-y));
    }
    to {
        clip-path: circle(150% at var(--theme-x) var(--theme-y));
    }
}

/* Ensure no transitions on theme change for elements that might conflict */
[data-kt-app-layout] {
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* --- Premium NProgress Styling --- */
#nprogress {
    pointer-events: none;
}

#nprogress .bar {
    background: #3E97FF; /* Metronic Primary */
    position: fixed;
    z-index: 1060; /* Above header/modals but below some critical overlays */
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    box-shadow: 0 0 10px rgba(62, 151, 255, 0.5);
    transition: background 0.3s ease;
}

/* Glow effect */
#nprogress .peg {
    display: block;
    position: absolute;
    right: 0px;
    width: 100px;
    height: 100%;
    box-shadow: 0 0 15px #3E97FF, 0 0 8px #3E97FF;
    opacity: 1.0;
    transform: rotate(3deg) translate(0px, -4px);
}

/* Spinner adjustment */
#nprogress .spinner {
    display: block;
    position: fixed;
    z-index: 1060;
    top: 15px;
    right: 15px;
}

#nprogress .spinner-icon {
    width: 18px;
    height: 18px;
    box-sizing: border-box;
    border: solid 2px transparent;
    border-top-color: #3E97FF;
    border-left-color: #3E97FF;
    border-radius: 50%;
    animation: nprogress-spinner 400ms linear infinite;
}

.nprogress-custom-parent {
    overflow: hidden;
    position: relative;
}

.nprogress-custom-parent #nprogress .spinner,
.nprogress-custom-parent #nprogress .bar {
    position: absolute;
}

@keyframes nprogress-spinner {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Adjust for Dark Mode */
[data-bs-theme="dark"] #nprogress .bar {
    background: #3b82f6; /* Slightly brighter for dark mode visibility */
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.7);
}
[data-bs-theme="dark"] #nprogress .peg {
    box-shadow: 0 0 20px #3b82f6, 0 0 10px #3b82f6;
}
[data-bs-theme="dark"] #nprogress .spinner-icon {
    border-top-color: #3b82f6;
    border-left-color: #3b82f6;
}

/* --- Command Palette (Spotlight Search) --- */
#modal_command_palette .modal-content {
    background: rgba(255, 255, 255, 0.8) !important;
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
}

[data-bs-theme="dark"] #modal_command_palette .modal-content {
    background: rgba(30, 41, 59, 0.8) !important;
}

#command_palette_results .command-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    color: var(--bs-gray-700);
    margin-bottom: 0.25rem;
}

#command_palette_results .command-item:hover,
#command_palette_results .command-item.active {
    background: var(--bs-primary);
    color: white !important;
    transform: translateX(5px);
}

#command_palette_results .command-item .command-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bs-gray-100);
    border-radius: 0.5rem;
    margin-right: 1rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

#command_palette_results .command-item .command-icon i {
    font-size: 1.5rem;
    margin-right: 0 !important;
    background: transparent !important;
}

#command_palette_results .command-item:hover .command-icon,
#command_palette_results .command-item.active .command-icon {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* --- Button Loading States --- */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 1.2rem;
    height: 1.2rem;
    top: 50%;
    left: 50%;
    margin-top: -0.6rem;
    margin-left: -0.6rem;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-right-color: transparent;
    animation: btn-spinner 0.6s linear infinite;
}

@keyframes btn-spinner {
    to { transform: rotate(360deg); }
}

/* --- Premium Page Contrast & Backgrounds --- */
[data-bs-theme="light"] body {
    background-color: #f5f7f9 !important;
}

[data-bs-theme="light"] .card:not(.card-flush) {
    box-shadow: 0 0.5rem 1.5rem 0.5rem rgba(0, 0, 0, 0.04) !important;
}

[data-bs-theme="light"] .card.card-flush {
    box-shadow: 0 0.1rem 1rem 0.25rem rgba(0, 0, 0, 0.02) !important;
}

[data-bs-theme="dark"] .card {
    border: 1px solid rgba(255, 255, 255, 0.05) !important;
}

/* --- View Transitions API (Circular Expansion) --- */
::view-transition-old(root),
::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}

::view-transition-old(root) {
    z-index: 1;
}

::view-transition-new(root) {
    z-index: 9999;
    animation: 0.7s cubic-bezier(0.4, 0, 0.2, 1) reveal both;
}

@keyframes reveal {
    from {
        clip-path: circle(0% at var(--theme-x, 50%) var(--theme-y, 50%));
    }
    to {
        clip-path: circle(150% at var(--theme-x, 50%) var(--theme-y, 50%));
    }
}

/* Fallback for browsers without View Transition support */
@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

