/**
 * Layout Manager CSS - Custom scrollbar và smooth transitions
 * Version: 1.0.1 
 * Date: 2025-10-05
 * Updated: Added Dashboard Expansion styling
 */

/* === LAYOUT MANAGER STYLES === */

/* Container với overflow được quản lý động */
#grid-stack-container {
    /* Smooth transitions khi thay đổi overflow */
    transition: all 0.2s ease-in-out;
    
    /* Custom scrollbar cho Webkit browsers */
    scrollbar-width: thin;
    scrollbar-color: rgba(156, 163, 175, 0.3) transparent;
    
    /* KHẮC PHỤC: Đảm bảo luôn có thể scroll khi cần */
    overflow: auto;
    
    /* THÊM: Prevent loss of scroll position */
    scroll-behavior: smooth;
    position: relative;
}

/* Custom Webkit Scrollbar */
#grid-stack-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#grid-stack-container::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 4px;
}

#grid-stack-container::-webkit-scrollbar-thumb {
    background-color: rgba(156, 163, 175, 0.3);
    border-radius: 4px;
    border: 1px solid transparent;
    background-clip: padding-box;
    transition: background-color 0.2s ease-in-out;
}

#grid-stack-container::-webkit-scrollbar-thumb:hover {
    background-color: rgba(156, 163, 175, 0.5);
}

#grid-stack-container::-webkit-scrollbar-thumb:active {
    background-color: rgba(156, 163, 175, 0.7);
}

/* Dark mode scrollbar */
.dark #grid-stack-container {
    scrollbar-color: rgba(75, 85, 99, 0.3) transparent;
}

.dark #grid-stack-container::-webkit-scrollbar-thumb {
    background-color: rgba(75, 85, 99, 0.3);
}

.dark #grid-stack-container::-webkit-scrollbar-thumb:hover {
    background-color: rgba(75, 85, 99, 0.5);
}

.dark #grid-stack-container::-webkit-scrollbar-thumb:active {
    background-color: rgba(75, 85, 99, 0.7);
}

/* === RESPONSIVE BEHAVIOR === */

/* Trên mobile, luôn cho phép scroll */
@media (max-width: 768px) {
    #grid-stack-container {
        overflow: auto !important;
    }
}

/* === ANIMATION STATES === */

/* Khi container đang loading/updating */
#grid-stack-container.updating {
    opacity: 0.9;
    transition: opacity 0.15s ease-in-out;
}

/* Khi container có content */
#grid-stack-container.has-content {
    opacity: 1;
}

/* === GRID STACK ITEM ENHANCEMENTS === */

/* Đảm bảo grid items không gây overflow không mong muốn */
.grid-stack-item {
    /* Overflow behavior cho từng widget */
    overflow: visible;
}

.grid-stack-item-content {
    /* Đảm bảo nội dung widget không vượt quá bounds */
    max-width: 100%;
    max-height: 100%;
    box-sizing: border-box;
}

/* Widget content có scroll riêng nếu cần */
.widget-content-scrollable {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(156, 163, 175, 0.2) transparent;
}

.widget-content-scrollable::-webkit-scrollbar {
    width: 6px;
}

.widget-content-scrollable::-webkit-scrollbar-track {
    background: transparent;
}

.widget-content-scrollable::-webkit-scrollbar-thumb {
    background-color: rgba(156, 163, 175, 0.2);
    border-radius: 3px;
}

.widget-content-scrollable::-webkit-scrollbar-thumb:hover {
    background-color: rgba(156, 163, 175, 0.4);
}

/* === UTILITY CLASSES === */

/* Force disable scroll */
.overflow-disabled {
    overflow: hidden !important;
}

/* Force enable scroll */
.overflow-enabled {
    overflow: auto !important;
}

/* Smooth scrolling behavior */
.smooth-scroll {
    scroll-behavior: smooth;
}

/* THÊM: Backup classes để khôi phục scroll */
.force-scroll-y {
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

.force-scroll-x {
    overflow-x: auto !important;
    overflow-y: hidden !important;
}

.force-scroll-both {
    overflow: auto !important;
}

/* Emergency scroll restore */
.scroll-emergency-restore {
    overflow: auto !important;
    max-height: 100vh !important;
    position: relative !important;
}

/* === LAYOUT DEBUGGING === */

/* Debug mode để kiểm tra boundaries */
.layout-debug #grid-stack-container {
    border: 2px dashed rgba(239, 68, 68, 0.5);
    position: relative;
}

.layout-debug .grid-stack-item {
    border: 1px solid rgba(59, 130, 246, 0.5);
    background-color: rgba(59, 130, 246, 0.05);
}

.layout-debug #grid-stack-container::before {
    content: 'Container: ' attr(data-debug-info);
    position: absolute;
    top: 4px;
    left: 4px;
    background: rgba(239, 68, 68, 0.8);
    color: white;
    padding: 2px 6px;
    font-size: 10px;
    border-radius: 3px;
    z-index: 9999;
    pointer-events: none;
}

/* === ACCESSIBILITY === */

/* Focus indicators cho scroll areas */
#grid-stack-container:focus-visible {
    outline: 2px solid rgba(59, 130, 246, 0.5);
    outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    #grid-stack-container {
        scroll-behavior: auto;
        transition: none;
    }
    
    #grid-stack-container.updating {
        transition: none;
    }
}

/* === PERFORMANCE OPTIMIZATIONS === */

/* Will-change cho smooth animations */
#grid-stack-container {
    will-change: scroll-position, transform;
}

.grid-stack-item {
    will-change: transform;
}

/* Contain layout calculations */
#grid-stack-container {
    contain: layout style;
}

/* === DASHBOARD EXPANSION STYLES === */

/* Dashboard Expanded Overlay */
.dashboard-expanded-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(5px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease-in-out;
    opacity: 1;
}

.dashboard-expanded-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

/* Content inside expanded overlay */
.dashboard-expanded-overlay .dashboard-content-moved {
    width: 95vw;
    height: 95vh;
    max-width: none;
    max-height: none;
    background: white;
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    overflow: auto;
    padding: 20px;
    position: relative;
}

/* Dark mode support */
.dark .dashboard-expanded-overlay .dashboard-content-moved {
    background: #1f2937;
    color: white;
}

/* Floating Bubble */
.floating-bubble {
    position: fixed;
    top: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    background: #ef4444;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10000;
    box-shadow: 0 10px 25px rgba(239, 68, 68, 0.3);
    transition: all 0.3s ease-in-out;
    color: white;
}

.floating-bubble:hover {
    background: #dc2626;
    transform: scale(1.1);
    box-shadow: 0 15px 35px rgba(239, 68, 68, 0.4);
}

.floating-bubble.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transform: scale(0.8);
}

/* Hidden elements during expansion */
.expand-hidden {
    display: none !important;
}

/* Smooth animations for expansion */
.dashboard-expansion-transition {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .dashboard-expanded-overlay .dashboard-content-moved {
        width: 98vw;
        height: 98vh;
        padding: 15px;
        border-radius: 8px;
    }
    
    .floating-bubble {
        width: 50px;
        height: 50px;
        top: 20px;
        right: 20px;
    }
}