/**
 * Modern Dashboard Styles
 * Beautiful, responsive dashboard with smooth animations
 */

/* Dashboard Control Bar */
.dashboard-control-bar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.dark .dashboard-control-bar {
    background: linear-gradient(135deg, #4338ca 0%, #6d28d9 100%);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

.control-bar-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.control-btn {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.control-btn-primary {
    background: rgba(255, 255, 255, 0.9);
    color: #667eea;
}

.control-btn-primary:hover {
    background: white;
}

.control-btn.active {
    background: #10b981;
    border-color: #10b981;
}

/* Hide edit-mode-only controls by default */
.control-btn.edit-mode-only {
    display: none !important;
}

/* Confirm modal styling */
.confirm-modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: rgba(0, 0, 0, 0.5) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 10000 !important;
}

.confirm-modal-content {
    background: #ffffff !important;
    border-radius: 16px !important;
    padding: 24px !important;
    max-width: 400px !important;
    width: 90% !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25) !important;
}

.dark .confirm-modal-content {
    background: #1f2937 !important;
    border: 1px solid #374151 !important;
}

.confirm-modal-content h3 {
    color: #111827 !important;
    font-size: 18px !important;
    font-weight: 600 !important;
    margin: 0 0 8px 0 !important;
}

.confirm-modal-content p {
    color: #6b7280 !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    margin: 0 !important;
}

.dark .confirm-modal-content h3 {
    color: #f3f4f6 !important;
}

.dark .confirm-modal-content p {
    color: #9ca3af !important;
}

/* Base confirm button styles */
.confirm-btn {
    padding: 10px 20px !important;
    border-radius: 8px !important;
    font-weight: 500 !important;
    font-size: 14px !important;
    cursor: pointer !important;
    min-width: 100px !important;
    text-align: center !important;
}

.confirm-btn.cancel-btn {
    background: #f3f4f6 !important;
    color: #374151 !important;
    border: 1px solid #e5e7eb !important;
}

.dark .confirm-btn.cancel-btn {
    background: #374151 !important;
    color: #d1d5db !important;
    border-color: #4b5563 !important;
}

.confirm-btn.cancel-btn:hover {
    background: #e5e7eb !important;
}

.dark .confirm-btn.cancel-btn:hover {
    background: #4b5563 !important;
}

.confirm-btn.action-btn {
    background: #ea580c !important;
    color: white !important;
    border: none !important;
}

.confirm-btn.action-btn:hover {
    background: #c2410c !important;
}

/* Show edit-mode-only controls when dashboard is in edit mode */
.edit-mode ~ .dashboard-control-bar .control-btn.edit-mode-only,
.dashboard-control-bar:has(~ .edit-mode) .control-btn.edit-mode-only,
body.dashboard-editing .control-btn.edit-mode-only {
    display: inline-flex !important;
}

.control-label {
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
}

.control-select {
    padding: 0.375rem 0.75rem;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    font-size: 0.875rem;
    color: #4b5563;
    cursor: pointer;
}

/* Dashboard Grid Container */
/* CSS Grid provides fallback layout when Muuri hasn't initialized yet */
/* Muuri overrides with absolute positioning once loaded */
.modern-dashboard-grid {
    position: relative;  /* Required for Muuri */
    min-height: 400px;   /* Ensure container has height for absolutely positioned items */
    margin-bottom: 2rem;
    transition: all 0.3s ease;
    /* Fallback grid layout - prevents stacking if Muuri fails to load */
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

/* Fallback positioning for widgets before Muuri initializes */
/* Muuri will override with position: absolute when it loads */
.modern-dashboard-grid .dashboard-widget:not(.muuri-item) {
    position: relative;
}

/* Layout Variations */
.modern-dashboard-grid.layout-compact {
    gap: 0.5rem;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.modern-dashboard-grid.layout-comfortable {
    gap: 1.25rem;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.modern-dashboard-grid.layout-spacious {
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

/* Edit Mode - use outline instead of padding to avoid layout shift */
.modern-dashboard-grid.edit-mode {
    background-image: radial-gradient(circle, #e5e7eb 1px, transparent 1px);
    background-size: 20px 20px;
    outline: 2px dashed #9ca3af;
    outline-offset: -2px;
    border-radius: 12px;
    min-height: 400px;
}

/* Wiggle animation disabled for now - testing swap functionality */

/* Dashboard Widgets - Muuri uses absolute positioning */
.dashboard-widget {
    /* Background is now handled by Tailwind classes in JS */
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    position: absolute;  /* Required for Muuri */
    display: block;
    z-index: 1;
    overflow: hidden;
    margin: 8px;  /* Gap between widgets */
    cursor: pointer;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

/* Inner content wrapper (required by Muuri) */
.dashboard-widget .widget-content-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Ensure all text within widgets is visible in dark mode */
.dashboard-widget p,
.dashboard-widget span:not(.control-label):not(.control-btn span),
.dashboard-widget h1,
.dashboard-widget h2,
.dashboard-widget h3,
.dashboard-widget h4,
.dashboard-widget h5,
.dashboard-widget h6,
.dashboard-widget div,
.dashboard-widget td,
.dashboard-widget th,
.dashboard-widget li {
    color: inherit;
}

/* Default text colors for dashboard content */
.dashboard-widget {
    color: #111827;
}

.dark .dashboard-widget {
    color: #f3f4f6;
}

/* Dark mode shadow adjustment */
.dark .dashboard-widget {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.24), 0 1px 2px rgba(0, 0, 0, 0.48);
}

/* Widget hover effect - indicates clickability */
.dashboard-widget:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

/* Disable hover lift in edit mode (dragging takes priority) */
.edit-mode .dashboard-widget:hover {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    transform: none;
    cursor: grab;
}

.edit-mode .dashboard-widget:active {
    cursor: grabbing;
}

/* ========================================
   Widget Resize Handles (Edit Mode)
   ======================================== */

/* Base handle - invisible until edit mode */
.resize-handle {
    position: absolute;
    z-index: 10;
    display: none;
    background: transparent;
}

/* Show handles only in edit mode */
.edit-mode .dashboard-widget .resize-handle {
    display: block;
}

/* Allow resize handles to extend outside widget bounds in edit mode */
.edit-mode .dashboard-widget {
    overflow: visible !important;
}

/* But keep content clipped inside the widget */
.edit-mode .dashboard-widget .widget-content-wrapper,
.edit-mode .dashboard-widget .widget-content {
    overflow: hidden;
}

/* Default widget heights in edit mode - can be overridden by inline resize styles */
.edit-mode .widget-small {
    height: 180px;
}
.edit-mode .widget-medium {
    height: 280px;
}
.edit-mode .widget-large {
    height: 380px;
}

/* Edge handles - horizontal (top/bottom) */
.resize-n, .resize-s {
    height: 8px;
    left: 12px;
    right: 12px;
    cursor: ns-resize;
}
.resize-n { top: -4px; }
.resize-s { bottom: -4px; }

/* Edge handles - vertical (left/right) */
.resize-e, .resize-w {
    width: 8px;
    top: 12px;
    bottom: 12px;
    cursor: ew-resize;
}
.resize-e { right: -4px; }
.resize-w { left: -4px; }

/* Corner handles */
.resize-ne, .resize-nw, .resize-se, .resize-sw {
    width: 12px;
    height: 12px;
}
.resize-ne { top: -4px; right: -4px; cursor: nesw-resize; }
.resize-nw { top: -4px; left: -4px; cursor: nwse-resize; }
.resize-se { bottom: -4px; right: -4px; cursor: nwse-resize; }
.resize-sw { bottom: -4px; left: -4px; cursor: nesw-resize; }

/* Visual indicator on hover */
.resize-handle:hover {
    background: rgba(59, 130, 246, 0.3);
    border-radius: 2px;
}

/* ========================================
   Visible Resize Handle Indicators
   ======================================== */

/* Corner handles - visible grip indicators */
.edit-mode .resize-se::after,
.edit-mode .resize-sw::after,
.edit-mode .resize-ne::after,
.edit-mode .resize-nw::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    border: 2px solid #94a3b8;
    border-radius: 2px;
    background: white;
    transition: border-color 0.15s, transform 0.15s;
}

/* Position grips at corners */
.edit-mode .resize-se::after { bottom: 2px; right: 2px; }
.edit-mode .resize-sw::after { bottom: 2px; left: 2px; }
.edit-mode .resize-ne::after { top: 2px; right: 2px; }
.edit-mode .resize-nw::after { top: 2px; left: 2px; }

/* Hover state - highlight blue */
.edit-mode .resize-handle:hover::after {
    border-color: #3b82f6;
    transform: scale(1.2);
}

/* Edge handles - subtle line indicators (top/bottom) */
.edit-mode .resize-n::after,
.edit-mode .resize-s::after {
    content: '';
    position: absolute;
    width: 30px;
    height: 3px;
    background: #cbd5e1;
    border-radius: 2px;
    left: 50%;
    transform: translateX(-50%);
    transition: background-color 0.15s;
}
.edit-mode .resize-n::after { top: 0; }
.edit-mode .resize-s::after { bottom: 0; }

/* Edge handles - subtle line indicators (left/right) */
.edit-mode .resize-e::after,
.edit-mode .resize-w::after {
    content: '';
    position: absolute;
    width: 3px;
    height: 30px;
    background: #cbd5e1;
    border-radius: 2px;
    top: 50%;
    transform: translateY(-50%);
    transition: background-color 0.15s;
}
.edit-mode .resize-e::after { right: 0; }
.edit-mode .resize-w::after { left: 0; }

/* Edge hover - highlight blue */
.edit-mode .resize-n:hover::after,
.edit-mode .resize-s:hover::after {
    background: #3b82f6;
    transform: translateX(-50%) scaleX(1.2);
}

.edit-mode .resize-e:hover::after,
.edit-mode .resize-w:hover::after {
    background: #3b82f6;
    transform: translateY(-50%) scaleY(1.2);
}

/* Resizing state - elevate widget during resize */
.dashboard-widget.resizing {
    z-index: 1000 !important;
    opacity: 0.95;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

/* Disable hover transform during resize */
.dashboard-widget.resizing:hover {
    transform: none;
}

/* Hide resize handles on touch devices */
@media (hover: none) and (pointer: coarse) {
    .resize-handle {
        display: none !important;
    }
}

/* Widget Sizes - explicit dimensions for Muuri layout */
.widget-small {
    width: calc(33.333% - 16px);  /* 3 columns */
    height: 150px;
}

.widget-medium {
    width: calc(50% - 16px);  /* 2 columns */
    height: 200px;
}

.widget-large {
    width: calc(66.666% - 16px);  /* 2/3 width */
    height: 350px;
}

/* Responsive widget sizes */
@media (max-width: 1024px) {
    .widget-small {
        width: calc(50% - 16px);  /* 2 columns on tablet */
    }
    .widget-medium {
        width: calc(100% - 16px);  /* Full width on tablet */
    }
    .widget-large {
        width: calc(100% - 16px);
    }
}

@media (max-width: 640px) {
    .widget-small,
    .widget-medium,
    .widget-large {
        width: calc(100% - 16px);  /* Full width on mobile */
    }
}

/* Size-specific content adjustments */
.widget-small .widget-content {
    font-size: 0.9rem;
}

/* General metric value styling */
.metric-value {
    font-weight: 700;
    color: #111827;
}

.dark .metric-value {
    color: #f3f4f6;
}

.widget-small .metric-value {
    font-size: 1.5rem;
    color: #111827;
}

.dark .widget-small .metric-value {
    color: #f3f4f6;
}

.widget-medium .widget-content {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.widget-large .widget-content {
    font-size: 1.1rem;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.widget-large .metric-value {
    font-size: 2.5rem;
    color: #111827;
}

.dark .widget-large .metric-value {
    color: #f3f4f6;
}

.widget-full {
    grid-column: 1 / -1;
    grid-row: span 2;
}

/* Responsive sizes */
@media (max-width: 768px) {
    .widget-small {
        grid-column: span 1;
        min-height: 100px;
    }

    .widget-medium {
        grid-column: span 1;
        min-height: 150px;
    }

    .widget-large {
        grid-column: span 1;
        grid-row: span 2;
        min-height: 250px;
    }
}

/* Widget Header */
.widget-header {
    display: none;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background: linear-gradient(180deg, rgba(0,0,0,0.03) 0%, transparent 100%);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.edit-mode .widget-header {
    display: flex;
}

.widget-drag-handle {
    cursor: move !important;
    padding: 0.25rem;
    border-radius: 6px;
    transition: all 0.2s;
    position: relative;
    z-index: 100;
    pointer-events: auto !important;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.widget-drag-handle:hover {
    background: rgba(59, 130, 246, 0.2);
    transform: scale(1.1);
}

.widget-drag-handle:active {
    background: rgba(59, 130, 246, 0.3);
    cursor: grabbing !important;
}

.drag-icon {
    color: #9ca3af;
}

.dark .drag-icon {
    color: #6b7280;
}

.widget-actions {
    display: flex;
    gap: 0.25rem;
}

.widget-action-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    color: #6b7280;
}

.dark .widget-action-btn {
    color: #9ca3af;
}

.widget-action-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.dark .widget-action-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.widget-settings:hover {
    color: #3b82f6;
}

.widget-remove:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* Widget Content */
.widget-content {
    flex: 1;
    padding: 1.25rem;
    display: flex;
    flex-direction: column; /* Stack children vertically to fill space */
    gap: 1rem;
    min-height: 0; /* Allow flex shrinking */
    overflow: hidden;
}

/* Make chart SVGs responsive - only target chart containers, not icon SVGs */
.widget-content .steamgraph-container svg,
.widget-content .treemap-container svg,
.widget-content .chart-container svg {
    width: 100%;
    height: 100%;
}

.widget-content .chart-container,
.widget-content .steamgraph-container,
.widget-content .treemap-container {
    width: 100%;
    height: 100%;
    flex: 1;
    min-height: 0;
}

/* Make chart wrapper divs fill widget-content */
.widget-content .steamgraph-widget,
.widget-content .treemap-widget,
.widget-content > div {
    width: 100%;
    flex: 1;
    min-height: 0;
    color: #111827;
}

.dark .widget-content {
    color: #f3f4f6;
}

.dark .widget-content > div {
    color: #f3f4f6;
}

.widget-large .widget-content {
    padding: 1.5rem;
}

.widget-content > .widget-icon {
    width: 48px;
    height: 48px;
    flex: 0 0 48px; /* Don't grow, don't shrink, fixed height */
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, rgba(59, 130, 246, 0.05) 100%);
}

.widget-info {
    flex: 1 1 auto; /* Grow to fill remaining space */
    display: flex;
    flex-direction: column;
}

.widget-label {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 0.25rem;
}

.dark .widget-label {
    color: #9ca3af;
}

.widget-value {
    font-size: 1.875rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.25rem;
    color: #111827;
}

.dark .widget-value {
    color: #f3f4f6;
}

.widget-sublabel {
    font-size: 0.75rem;
    color: #9ca3af;
}

.dark .widget-sublabel {
    color: #6b7280;
}

/* Text overflow handling for resized widgets */
.widget-label,
.widget-sublabel {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.widget-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Small widget text adjustments */
.widget-small .widget-value,
.dashboard-widget[style*="width"][style*="height"] .widget-value {
    font-size: clamp(1rem, 4vw, 1.875rem);
}

.widget-small .widget-label,
.dashboard-widget[style*="width"][style*="height"] .widget-label {
    font-size: clamp(0.65rem, 2vw, 0.875rem);
}

/* Ensure widget content doesn't overflow bounds */
.widget-info {
    flex: 1;
    min-width: 0; /* Allow text truncation in flex child */
    overflow: hidden;
}

/* Widget Colors */
.widget-blue .widget-icon {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.15) 0%, rgba(59, 130, 246, 0.05) 100%);
}

.widget-red .widget-icon {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.15) 0%, rgba(239, 68, 68, 0.05) 100%);
}

.widget-green .widget-icon {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15) 0%, rgba(16, 185, 129, 0.05) 100%);
}

.widget-yellow .widget-icon {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15) 0%, rgba(245, 158, 11, 0.05) 100%);
}

.widget-purple .widget-icon {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15) 0%, rgba(139, 92, 246, 0.05) 100%);
}

/* Muuri Drag States */

/* Widget being actively dragged */
.dashboard-widget.muuri-item-dragging {
    z-index: 3;
    cursor: grabbing !important;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25), 0 8px 16px rgba(0, 0, 0, 0.15);
}

.dark .dashboard-widget.muuri-item-dragging {
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4), 0 8px 16px rgba(0, 0, 0, 0.3);
}

/* Widget animating back to place after drag release */
.dashboard-widget.muuri-item-releasing {
    z-index: 2;
}

/* Hidden widgets (filtered out) */
.dashboard-widget.muuri-item-hidden {
    z-index: 0;
}

/* Placeholder shown where dragged item will land */
.dashboard-widget.muuri-item-placeholder {
    opacity: 0.5;
    background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%) !important;
    border: 2px dashed #6366f1;
}

.dark .dashboard-widget.muuri-item-placeholder {
    background: linear-gradient(135deg, #312e81 0%, #3730a3 100%) !important;
    border-color: #818cf8;
}

/* iOS-style Wiggle Animation for Edit Mode */
/* IMPORTANT: Apply wiggle to inner content, NOT the widget itself */
/* Muuri uses transform on .dashboard-widget for positioning - don't override it */
@keyframes widget-wiggle {
    0%, 100% { transform: rotate(-1deg); }
    50% { transform: rotate(1deg); }
}

/* Apply wiggle to the widget-content-wrapper inside, not the widget itself */
.modern-dashboard-grid.edit-mode .dashboard-widget:not(.muuri-item-dragging):not(.muuri-item-releasing) > * {
    animation: widget-wiggle 0.4s ease-in-out infinite;
    transform-origin: center center;
}

/* Stagger wiggle for natural feel */
.modern-dashboard-grid.edit-mode .dashboard-widget:nth-child(even):not(.muuri-item-dragging) > * {
    animation-delay: 0.2s;
}

/* Stop wiggle while dragging */
.dashboard-widget.muuri-item-dragging > * {
    animation: none !important;
}

/* Widget Library Modal */
.widget-library-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1;
}

.modal-content {
    position: relative;
    z-index: 2;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    max-width: 800px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.dark .modal-content {
    background: #1f2937;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dark .modal-header {
    border-color: #374151;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #111827;
}

.dark .modal-title {
    color: #f3f4f6;
}

.modal-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 8px;
    font-size: 24px;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #f3f4f6;
    color: #111827;
}

.dark .modal-close:hover {
    background: #374151;
    color: #f3f4f6;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

/* Forecast modal table dark mode styles */
.dark .widget-library-modal table td,
.dark .widget-library-modal table th {
    color: #f3f4f6 !important;
}

.dark .widget-library-modal table td[style*="green"],
.dark .widget-library-modal [style*="#4ade80"] {
    color: #4ade80 !important;
}

.dark .widget-library-modal table td[style*="red"],
.dark .widget-library-modal [style*="#f87171"] {
    color: #f87171 !important;
}

.widget-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.widget-card {
    padding: 1.5rem;
    background: #f9fafb;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.dark .widget-card {
    background: #111827;
    border-color: #374151;
}

.widget-card:hover {
    border-color: #3b82f6;
    background: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.dark .widget-card:hover {
    background: #1f2937;
}

.widget-card-icon {
    margin-bottom: 0.75rem;
    color: #6b7280;
}

.widget-card:hover .widget-card-icon {
    color: #3b82f6;
}

.widget-card-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.25rem;
}

.dark .widget-card-title {
    color: #e5e7eb;
}

.widget-card-size {
    font-size: 0.75rem;
    color: #9ca3af;
    text-transform: uppercase;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

.dashboard-widget {
    animation: fadeIn 0.3s ease-out;
}

/* Mobile Optimizations */
@media (max-width: 640px) {
    .modern-dashboard-grid {
        grid-template-columns: 1fr;
    }

    .control-bar-inner {
        flex-direction: column;
        align-items: stretch;
    }

    .control-group {
        flex-wrap: wrap;
    }

    .control-btn span {
        display: none;
    }

    .control-btn {
        padding: 0.75rem;
    }
}

/* Treemap Widget Styles */
.treemap-widget {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.treemap-container {
    flex: 1;
    min-height: 200px;
    position: relative;
}

.treemap-container svg {
    width: 100%;
    height: 100%;
}

.treemap-view-select {
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #d1d5db;
    font-size: 12px;
    background: white;
    cursor: pointer;
}

.dark .treemap-view-select {
    background: #374151;
    border-color: #4b5563;
    color: #f3f4f6;
}

.treemap-total {
    font-size: 14px;
    font-weight: 500;
}

/* Treemap tooltip styles */
.treemap-tooltip {
    position: absolute;
    padding: 10px 14px;
    background: rgba(15, 23, 42, 0.95);
    color: white;
    border-radius: 8px;
    font-size: 13px;
    pointer-events: none;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    max-width: 200px;
}

.treemap-tooltip .tooltip-title {
    font-weight: 600;
    margin-bottom: 4px;
    color: #60a5fa;
}

.treemap-tooltip .tooltip-value {
    font-size: 16px;
    font-weight: 700;
}

.treemap-tooltip .tooltip-subtitle {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2px;
}

/* ========================================
   Sunburst Widget & Modal Styles
   ======================================== */

/* Widget container */
.sunburst-widget {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sunburst-container {
    flex: 1;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sunburst-container svg {
    width: 100%;
    height: 100%;
}

/* Modal overlay */
.sunburst-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.sunburst-modal-overlay .modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

/* Modal content - near full screen */
.sunburst-modal-content {
    position: relative;
    z-index: 1;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border-radius: 20px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.15);
    width: 96vw;
    max-width: 1600px;
    height: 94vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.sunburst-modal-content.dark {
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5), 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* Modal header */
.sunburst-modal-content .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 28px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.5);
}

.sunburst-modal-content.dark .modal-header {
    border-bottom-color: rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
}

/* Modal controls */
.sunburst-modal-content .modal-controls {
    padding: 14px 28px;
    background: rgba(249, 250, 251, 0.8);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.sunburst-modal-content.dark .modal-controls {
    background: rgba(17, 24, 39, 0.6);
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

/* Flow toggle buttons */
.flow-toggle {
    display: flex;
    overflow: hidden;
}

.flow-btn {
    background: white;
    color: #6b7280;
    border: none;
    transition: all 0.2s;
}

.flow-btn:hover {
    background: #f3f4f6;
}

.flow-btn.active {
    background: #8b5cf6;
    color: white;
}

.sunburst-modal-content.dark .flow-btn {
    background: #374151;
    color: #9ca3af;
}

.sunburst-modal-content.dark .flow-btn:hover {
    background: #4b5563;
}

.sunburst-modal-content.dark .flow-btn.active {
    background: #8b5cf6;
    color: white;
}

/* Breadcrumb */
.breadcrumb {
    font-size: 14px;
}

.breadcrumb-path {
    font-weight: 500;
}

/* Modal body */
.sunburst-modal-content .modal-body {
    flex: 1;
    padding: 16px 24px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0; /* Important for flex children */
}

.sunburst-modal-chart {
    width: 100%;
    height: 100%;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.sunburst-modal-chart svg {
    max-width: 100%;
    max-height: 100%;
}

/* Stats Panel */
.sunburst-stats-panel {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 200px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(0, 0, 0, 0.08);
    font-size: 12px;
    z-index: 10;
}

.sunburst-modal-content.dark .sunburst-stats-panel {
    background: rgba(30, 41, 59, 0.95);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.sunburst-stats-panel .stats-header {
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6b7280;
    margin-bottom: 10px;
}

.sunburst-modal-content.dark .sunburst-stats-panel .stats-header {
    color: #9ca3af;
}

.sunburst-stats-panel .stats-title {
    font-weight: 600;
    font-size: 13px;
    color: #1f2937;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sunburst-modal-content.dark .sunburst-stats-panel .stats-title {
    color: #f3f4f6;
}

.sunburst-stats-panel .stats-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.sunburst-stats-panel .stats-label {
    color: #6b7280;
    font-size: 11px;
}

.sunburst-modal-content.dark .sunburst-stats-panel .stats-label {
    color: #9ca3af;
}

.sunburst-stats-panel .stats-value {
    font-weight: 600;
    color: #1f2937;
}

.sunburst-modal-content.dark .sunburst-stats-panel .stats-value {
    color: #f3f4f6;
}

.sunburst-stats-panel .stats-value-large {
    font-size: 16px;
    color: #7c3aed;
}

.sunburst-modal-content.dark .sunburst-stats-panel .stats-value-large {
    color: #a78bfa;
}

.sunburst-stats-panel .stats-divider {
    height: 1px;
    background: rgba(0, 0, 0, 0.08);
    margin: 10px 0;
}

.sunburst-modal-content.dark .sunburst-stats-panel .stats-divider {
    background: rgba(255, 255, 255, 0.1);
}

.sunburst-stats-panel .stats-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 0;
}

.sunburst-stats-panel .stats-name {
    color: #4b5563;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

.sunburst-modal-content.dark .sunburst-stats-panel .stats-name {
    color: #d1d5db;
}

.sunburst-stats-panel .stats-more {
    font-size: 10px;
    color: #9ca3af;
    font-style: italic;
    text-align: right;
    padding-top: 4px;
}

.sunburst-stats-panel .stats-counts {
    font-size: 11px;
    color: #6b7280;
}

.sunburst-modal-content.dark .sunburst-stats-panel .stats-counts {
    color: #9ca3af;
}

.sunburst-stats-panel .stats-count {
    padding: 2px 0;
}

/* Responsive: hide stats panel on small screens */
@media (max-width: 768px) {
    .sunburst-stats-panel {
        display: none;
    }
}

/* Modal footer */
.sunburst-modal-content .modal-footer {
    padding: 14px 28px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    background: rgba(249, 250, 251, 0.8);
}

.sunburst-modal-content.dark .modal-footer {
    background: rgba(17, 24, 39, 0.6);
    border-top-color: rgba(255, 255, 255, 0.08);
}

/* Legend */
.legend-container {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    align-items: center;
}

.legend-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Sunburst arc hover effect */
.sunburst-arc {
    transition: opacity 0.2s ease;
}

.sunburst-arc:hover {
    opacity: 0.85;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .sunburst-modal-content {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .sunburst-modal-chart {
        height: 350px;
    }

    .modal-controls .flex {
        flex-direction: column;
        gap: 12px;
    }
}