/* ============================================================================
   DASHBOARD STYLES
   ============================================================================
   Styles for the dashboard feature including:
   - Dashboard layout and grid
   - Widget containers
   - Individual widget types
   - Widget selector dialog
   - Loading and error states

   The dashboard uses a 12-column CSS Grid layout that automatically
   adjusts widgets to fit the available space.
   ============================================================================ */

/* ============================================================================
   DASHBOARD LAYOUT
   ============================================================================ */

.dashboard-page {
    background-color: #f5f7fa;
    height: calc(100vh - 200px);
    overflow: hidden;
}

.dashboard-viewer {
    width: 100%;
    height: 100%;
    overflow: auto;
}

/* Dashboard header with title and action buttons */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.dashboard-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dashboard-title h4 {
    margin: 0;
    font-weight: bold;
    color: #333;
}

.dashboard-title i {
    color: #2196F3;
    font-size: 1.2em;
}

.layout-name {
    color: #666;
    font-size: 0.9em;
}

.dashboard-actions {
    display: flex;
    gap: 10px;
}

/* Buttons in dashboard header need position:relative for badge positioning */
.dashboard-actions .btn {
    position: relative;
}

/* Company count badge styling for dashboard header button */
.dashboard-actions .company-count-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #2196F3;
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Date range label styling for dashboard header button */
.dashboard-actions .date-range-label {
    font-size: 0.75rem;
    margin-left: 4px;
}

/* Global date selector styling */
.global-date-selector .btn.has-selection {
    background-color: #e3f2fd;
    border-color: #2196F3;
    color: #1976D2;
}

/* Global date panel popup */
.global-date-panel {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    z-index: 1050;
    width: 340px;
    max-width: 95vw;
}

.date-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
}

.date-panel-header h6 {
    margin: 0;
    font-size: 0.95rem;
    color: #333;
}

.date-panel-body {
    padding: 16px;
}

.date-preset-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.date-preset-buttons .btn {
    flex: 1 1 calc(33% - 6px);
    min-width: 90px;
    font-size: 0.8rem;
    padding: 6px 8px;
}

.date-custom-range label {
    color: #666;
    margin-bottom: 4px;
}

.date-panel-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #eee;
    background: #f8f9fa;
    border-radius: 0 0 8px 8px;
}

/* ============================================================================
   WIDGET GRID
   ============================================================================
   A 12-column CSS Grid that widgets snap to. The grid has a small gap
   between widgets for visual separation.
   ============================================================================ */

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: minmax(100px, auto);
    gap: 16px;
    align-items: start;
}

/* ============================================================================
   SORTABLE TABLE HEADERS
   ============================================================================ */

.sortable-header {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.sortable-header:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.sortable-header i {
    margin-left: 5px;
    font-size: 0.85em;
}

/* ============================================================================
   RESPONSIVE STYLES
   ============================================================================ */

/* Responsive: Stack widgets on small screens */
@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .widget-container {
        grid-column: span 1 !important;
    }
}

@media (max-width: 1200px) and (min-width: 769px) {
    .dashboard-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* ============================================================================
   WIDGET CONTAINER
   ============================================================================
   The container that wraps each widget, providing consistent styling
   and the header with action buttons.
   ============================================================================ */

.widget-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: visible;
    display: flex;
    flex-direction: column;
    min-height: 180px;
    transition: box-shadow 0.2s ease;
    position: relative;
    z-index: 1;
    align-self: stretch;
}

/* Elevate widget when popup is open so it appears above other widgets */
.widget-container.popup-open {
    z-index: 100;
}

.widget-container:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.widget-container.loading {
    opacity: 0.8;
}

.widget-container.error {
    border: 1px solid #f44336;
}

/* ============================================================================
   DRAG AND DROP STYLES
   ============================================================================
   Styles for the drag handle and visual feedback during drag operations.
   ============================================================================ */

/* Drag handle - grip icon on the left side of widget header */
.widget-drag-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-right: 8px;
    cursor: grab;
    color: #aaa;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.widget-drag-handle:hover {
    background: #eee;
    color: #666;
}

.widget-drag-handle:active {
    cursor: grabbing;
    background: #e0e0e0;
    color: #333;
}

/* Widget being dragged */
.widget-container.dragging {
    opacity: 0.6;
    transform: scale(0.98);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25);
    z-index: 1000;
    cursor: grabbing;
}

/* Widget that is a valid drop target */
.widget-container.drop-target {
    border: 2px dashed #2196F3;
    background: #e3f2fd;
    box-shadow: 0 0 0 4px rgba(33, 150, 243, 0.2);
    transform: scale(1.02);
}

.widget-container.drop-target .widget-header {
    background: #bbdefb;
}

/* Grid state when dragging is active */
.dashboard-grid.is-dragging .widget-container:not(.dragging):not(.drop-target) {
    /* Slightly fade non-involved widgets */
    opacity: 0.85;
}

.dashboard-grid.is-dragging .widget-container:not(.dragging) {
    /* Show pointer cursor to indicate droppable */
    cursor: pointer;
}

/* Smooth transitions for position swapping */
.widget-container {
    transition: box-shadow 0.2s ease, transform 0.2s ease, opacity 0.2s ease, border 0.2s ease;
}

/* Widget header */
.widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
    background: #fafafa;
    transition: background 0.2s ease;
}

.widget-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: bold;
    color: #333;
    font-size: 0.9rem;
}

.widget-icon {
    color: #2196F3;
}

.widget-header-actions {
    display: flex;
    gap: 5px;
}

.widget-action-btn {
    background: none;
    border: none;
    padding: 5px 8px;
    cursor: pointer;
    color: #666;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.widget-action-btn:hover {
    background: #eee;
    color: #333;
}

/* Active state for toggle buttons (e.g., All Companies toggle) */
.widget-action-btn.active {
    background: #e3f2fd;
    color: #2196F3;
}

.widget-action-btn.active:hover {
    background: #bbdefb;
    color: #1976D2;
}

.widget-remove-btn:hover {
    background: #ffebee;
    color: #f44336;
}

/* Widget body */
.widget-body {
    flex: 1;
    padding: 15px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-height: 0;
    overflow: auto;
}

/* Widget footer */
.widget-footer {
    padding: 8px 15px;
    border-top: 1px solid #eee;
    font-size: 0.75rem;
    color: #999;
}

.last-updated {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* ============================================================================
   WIDGET RESIZE HANDLES
   ============================================================================
   Resize handles appear on hover at the edges and corner of the widget.
   Users can drag these to resize the widget.
   ============================================================================ */

.widget-resize-handle {
    position: absolute;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 100;
    pointer-events: auto;
}

.widget-container:hover .widget-resize-handle {
    opacity: 1;
}

/* Right edge handle - for horizontal resize */
.widget-resize-right {
    right: 0;
    top: 40px;
    bottom: 20px;
    width: 6px;
    cursor: ew-resize;
    background: linear-gradient(to right, transparent, rgba(33, 150, 243, 0.3));
}

.widget-resize-right:hover {
    background: linear-gradient(to right, transparent, rgba(33, 150, 243, 0.6));
}

/* Bottom edge handle - for vertical resize */
.widget-resize-bottom {
    bottom: 0;
    left: 20px;
    right: 20px;
    height: 6px;
    cursor: ns-resize;
    background: linear-gradient(to bottom, transparent, rgba(33, 150, 243, 0.3));
}

.widget-resize-bottom:hover {
    background: linear-gradient(to bottom, transparent, rgba(33, 150, 243, 0.6));
}

/* Corner handle - for diagonal resize (both dimensions) */
.widget-resize-corner {
    right: 0;
    bottom: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 50%, rgba(33, 150, 243, 0.5) 50%);
    border-radius: 0 0 8px 0;
}

.widget-resize-corner:hover {
    background: linear-gradient(135deg, transparent 40%, rgba(33, 150, 243, 0.8) 40%);
}

/* Visual indicator when actively resizing */
.widget-container.resizing {
    outline: 2px dashed #2196F3;
    outline-offset: 2px;
}

/* ============================================================================
   WIDGET LOADING AND ERROR STATES
   ============================================================================ */

.widget-loading,
.widget-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
}

.widget-loading .spinner-border {
    width: 30px;
    height: 30px;
}

.widget-error i {
    font-size: 2rem;
    color: #f44336;
    margin-bottom: 10px;
}

.widget-error p {
    color: #666;
    margin-bottom: 10px;
}

.no-data-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
    text-align: center;
    color: #999;
}

.no-data-message i {
    font-size: 2.5rem;
    margin-bottom: 15px;
    opacity: 0.5;
}

.no-data-message p {
    margin: 0;
}

/* ============================================================================
   DASHBOARD EMPTY/LOADING/ERROR STATES
   ============================================================================ */

.dashboard-loading,
.dashboard-error,
.dashboard-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.dashboard-loading .spinner-border {
    width: 50px;
    height: 50px;
    margin-bottom: 20px;
}

.dashboard-loading p,
.dashboard-error p,
.dashboard-empty p {
    color: #666;
    margin-bottom: 20px;
}

.dashboard-error i,
.dashboard-empty i {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.3;
}

.dashboard-error i {
    color: #f44336;
    opacity: 1;
}

.dashboard-empty i {
    color: #2196F3;
}

.dashboard-error h5,
.dashboard-empty h5 {
    color: #333;
    margin-bottom: 10px;
}

/* ============================================================================
   STATUS MESSAGE
   ============================================================================ */

.dashboard-status {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: bold;
    z-index: 1000;
    animation: slideIn 0.3s ease;
}

.dashboard-status.success {
    background: #4CAF50;
    color: white;
}

.dashboard-status.error {
    background: #f44336;
    color: white;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ============================================================================
   KPI CARD WIDGET
   ============================================================================ */

.kpi-card {
    text-align: center;
    padding: 10px;
}

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 15px;
}

.kpi-icon {
    font-size: 1.2rem;
    color: #2196F3;
}

.kpi-title {
    font-size: 0.85rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kpi-values-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.kpi-value-row {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 10px;
}

.kpi-value-row .kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #333;
    line-height: 1.2;
    margin-bottom: 0;
    min-width: 80px;
    text-align: right;
}

.kpi-value-row .kpi-label {
    font-size: 0.85rem;
    color: #666;
    text-align: left;
    min-width: 100px;
}

/* Clickable KPI metrics for drill-down */
.kpi-value-row.clickable {
    cursor: pointer;
    padding: 4px 8px;
    margin: -4px -8px;
    border-radius: 4px;
    transition: background-color 0.15s ease;
}

.kpi-value-row.clickable:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Single value display (fallback) */
.kpi-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: #333;
    line-height: 1.2;
    margin-bottom: 10px;
}

/* Adjust value size based on number of items */
.kpi-values-container:has(.kpi-value-row:nth-child(4)) .kpi-value,
.kpi-values-container:has(.kpi-value-row:nth-child(5)) .kpi-value {
    font-size: 1.25rem;
}

.kpi-values-container:has(.kpi-value-row:only-child) .kpi-value {
    font-size: 2rem;
}

.kpi-trend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 0.85rem;
}

.kpi-trend.trend-positive {
    color: #4CAF50;
}

.kpi-trend.trend-negative {
    color: #f44336;
}

.kpi-subtitle {
    font-size: 0.8rem;
    color: #999;
    margin-top: 10px;
}

.kpi-date-range {
    font-size: 0.7rem;
    color: #888;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #eee;
}

/* KPI color classes */
.kpi-green { background: linear-gradient(135deg, #e8f5e9, #c8e6c9); }
.kpi-yellow { background: linear-gradient(135deg, #fff3e0, #ffe0b2); }
.kpi-red { background: linear-gradient(135deg, #ffebee, #ffcdd2); }

/* KPI drill-down enabled - clickable with hover effect */
.kpi-card.drill-down-enabled {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card.drill-down-enabled:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.25);
}

/* ============================================================================
   CHART WIDGETS
   ============================================================================ */

.chart-widget {
    width: 100%;
    height: 100%;
}

.widget-title {
    font-weight: bold;
    color: #333;
    margin-bottom: 10px;
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* ============================================================================
   TABLE WIDGET
   ============================================================================ */

.table-widget {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.table-container {
    flex: 1;
    overflow-y: auto;
}

/* Scrollbar styling for table container */
.table-container::-webkit-scrollbar {
    width: 8px;
}

.table-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

.widget-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.widget-table th {
    background: #f5f5f5;
    padding: 6px 8px;
    text-align: left;
    font-weight: bold;
    color: #333;
    border-bottom: 2px solid #ddd;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 1;
}

.widget-table th:hover {
    background: #eee;
}

.widget-table th.sorted {
    background: #e3f2fd;
    color: #2196F3;
}

.sort-icon {
    margin-left: 5px;
    font-size: 0.75rem;
}

.widget-table td {
    padding: 5px 8px;
    border-bottom: 1px solid #eee;
    color: #555;
}

.widget-table tbody tr:hover {
    background: #f9f9f9;
}

/* Clickable rows for drill-down - cursor and enhanced hover effect */
.widget-table.clickable-rows tbody tr {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.widget-table.clickable-rows tbody tr:hover {
    background: #e3f2fd;
}

.widget-table tbody tr.clickable {
    cursor: pointer;
}

.widget-table tbody tr.clickable:hover {
    background: #e3f2fd;
}

.table-footer {
    padding: 4px 0 0;
    font-size: 0.7rem;
    color: #999;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

/* ============================================================================
   GAUGE WIDGET
   ============================================================================ */

.gauge-widget {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.gauge-target {
    margin-top: 10px;
    font-size: 0.85rem;
    color: #666;
}

/* ============================================================================
   WIDGET SELECTOR DIALOG
   ============================================================================ */

.widget-selector-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.widget-selector-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 1001;
    display: flex;
    flex-direction: column;
}

.widget-selector-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #eee;
}

.widget-selector-header h5 {
    margin: 0;
    font-weight: bold;
}

.widget-selector-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.widget-selector-categories {
    width: 200px;
    border-right: 1px solid #eee;
    padding: 15px;
    overflow-y: auto;
}

.category-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: none;
    background: none;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    color: #555;
    transition: all 0.2s ease;
    margin-bottom: 5px;
}

.category-btn:hover {
    background: #f5f5f5;
}

.category-btn.active {
    background: #e3f2fd;
    color: #2196F3;
    font-weight: bold;
}

.category-btn .badge {
    margin-left: auto;
    background: #eee;
    color: #666;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 0.75rem;
}

.category-btn.active .badge {
    background: #2196F3;
    color: white;
}

.widget-search-row {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px 20px;
    border-bottom: 1px solid #eee;
    background: #fafafa;
}

.multi-level-filter {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: #555;
    cursor: pointer;
    white-space: nowrap;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background 0.2s ease;
}

.multi-level-filter:hover {
    background: #e8e8e8;
}

.multi-level-filter input[type="checkbox"] {
    cursor: pointer;
}

.multi-level-filter i {
    color: #28a745;
}

.widget-search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fff;
    max-width: 400px;
}

.widget-search-box i {
    color: #999;
}

.widget-search-box input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 0.9rem;
}

.widget-search-box input::placeholder {
    color: #aaa;
}

.btn-clear-search {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: #999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-clear-search:hover {
    color: #666;
}

.widget-selector-widgets {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
    align-content: start;
}

.widget-card {
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.widget-card:hover {
    border-color: #2196F3;
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.15);
}

.widget-card.selected {
    border-color: #2196F3;
    background: #e3f2fd;
}

.widget-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.widget-card-icon {
    color: #2196F3;
}

.widget-card-name {
    font-weight: bold;
    color: #333;
    flex: 1;
}

.widget-type-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    background: #f5f5f5;
    color: #666;
    border-radius: 4px;
    text-transform: uppercase;
}

/* Drill-down indicator in widget selector */
.drill-down-indicator {
    font-size: 0.9rem;
    margin-left: 4px;
    cursor: help;
    opacity: 0.9;
}

.drill-down-indicator:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Multi-level drill-down indicator in widget selector (3+ levels) */
.multi-level-indicator {
    font-size: 0.85rem;
    margin-left: 4px;
    cursor: help;
    opacity: 0.9;
}

.multi-level-indicator:hover {
    opacity: 1;
    transform: scale(1.1);
}

.widget-card-description {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 10px;
    line-height: 1.4;
}

.widget-card-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.75rem;
    color: #999;
}

.widget-category i {
    margin-right: 4px;
}

.system-widget-badge {
    background: #e8f5e9;
    color: #4CAF50;
    padding: 2px 6px;
    border-radius: 4px;
}

.no-widgets-message {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #999;
}

.no-widgets-message i {
    font-size: 3rem;
    margin-bottom: 15px;
    opacity: 0.3;
}

.widget-selector-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid #eee;
}

.widget-selector-footer .selection-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.widget-selector-footer .selection-actions button {
    white-space: nowrap;
}

.widget-selector-footer .selection-info {
    font-size: 0.85rem;
    color: #666;
}

.widget-selector-footer .footer-buttons {
    display: flex;
    gap: 10px;
}

/* ============================================================================
   WIDGET PARAMETER PANEL
   ============================================================================ */

.parameter-panel-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
}

.parameter-panel {
    position: absolute;
    top: 35px;
    right: 0;
    width: 320px;
    max-height: 400px;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    display: flex;
    flex-direction: column;
}

.parameter-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
    font-weight: bold;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
}

.parameter-panel-header i {
    color: #6c757d;
}

.parameter-panel-header span {
    flex: 1;
}

.parameter-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.parameter-item {
    margin-bottom: 15px;
}

.parameter-item:last-child {
    margin-bottom: 0;
}

.parameter-label {
    display: block;
    font-size: 0.85rem;
    font-weight: bold;
    color: #495057;
    margin-bottom: 4px;
}

.parameter-input-group {
    display: flex;
    align-items: center;
}

.parameter-input-group .form-control,
.parameter-input-group .form-select {
    flex: 1;
}

.parameter-info {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.parameter-info .badge {
    font-size: 0.7rem;
    font-weight: normal;
}

.parameter-panel-footer {
    display: flex;
    justify-content: space-between;
    padding: 12px 15px;
    border-top: 1px solid #eee;
    background: #f8f9fa;
    border-radius: 0 0 8px 8px;
}

/* Parameter indicator on widget header */
.widget-has-params .widget-action-btn.params-btn {
    color: #17a2b8;
}

.widget-has-custom-params .widget-action-btn.params-btn {
    color: #28a745;
}

/* ============================================================================
   WIDGET INFO PANEL
   ============================================================================ */

.widget-info-panel {
    position: absolute;
    top: 35px;
    right: 0;
    width: 300px;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.info-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
    font-weight: bold;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
    color: #333;
}

.info-panel-close {
    background: none;
    border: none;
    padding: 4px 8px;
    cursor: pointer;
    color: #666;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.info-panel-close:hover {
    background: #eee;
    color: #333;
}

.info-panel-content {
    padding: 15px;
    max-height: 350px;
    overflow-y: auto;
}

.info-section {
    margin-bottom: 15px;
}

.info-section:last-child {
    margin-bottom: 0;
}

.info-section label {
    display: block;
    font-size: 0.75rem;
    font-weight: bold;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.info-section p {
    margin: 0;
    font-size: 0.9rem;
    color: #333;
    line-height: 1.4;
}

.info-section p.text-muted {
    font-style: italic;
    color: #999;
}

/* Filter Parameters List in Info Panel */
.filter-params-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-param-item {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px 8px;
    background: #f8f9fa;
    border-radius: 4px;
    font-size: 0.85rem;
}

.filter-param-item .param-label {
    font-weight: 600;
    color: #495057;
    margin-right: 4px;
}

.filter-param-item .param-value {
    color: #333;
}

.filter-param-item .param-value.custom-override {
    color: #0d6efd;
    font-weight: 600;
}

/* Info button active state */
.widget-action-btn.info-btn.active {
    background: #e3f2fd;
    color: #2196F3;
}

.widget-action-btn.info-btn.active:hover {
    background: #bbdefb;
    color: #1976D2;
}

/* ============================================================================
   POPUP POSITIONING - OPEN UPWARD WHEN NEAR BOTTOM
   ============================================================================
   When a widget is near the bottom of the dashboard, popups should open
   upward instead of downward to prevent being cut off.
   ============================================================================ */

/* Modifier class for widgets near the bottom - open popups upward */
.widget-container.popup-upward .widget-info-panel,
.widget-container.popup-upward .parameter-panel {
    top: auto;
    bottom: 35px;
    animation: slideUp 0.2s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Adjust border radius when opening upward */
.widget-container.popup-upward .widget-info-panel .info-panel-header,
.widget-container.popup-upward .parameter-panel .parameter-panel-header {
    border-radius: 0 0 0 0;
}

.widget-container.popup-upward .widget-info-panel,
.widget-container.popup-upward .parameter-panel {
    border-radius: 8px 8px 8px 0;
}

.widget-container.popup-upward .widget-info-panel .info-panel-header {
    border-radius: 8px 8px 0 0;
    border-bottom: 1px solid #eee;
}

.widget-container.popup-upward .parameter-panel .parameter-panel-header {
    border-radius: 8px 8px 0 0;
}

.widget-container.popup-upward .parameter-panel .parameter-panel-footer {
    border-radius: 0 0 8px 8px;
}

/* ============================================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================================ */

@media (max-width: 600px) {
    .widget-selector-body {
        flex-direction: column;
    }

    .widget-selector-categories {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #eee;
        display: flex;
        overflow-x: auto;
        padding: 10px;
    }

    .category-btn {
        flex-shrink: 0;
        margin-bottom: 0;
        margin-right: 5px;
    }

    .dashboard-header {
        flex-direction: column;
        gap: 15px;
    }

    .dashboard-actions {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================================================
   COMPANY SELECTOR PANEL (SuperUsers Only)
   ============================================================================
   Allows SuperUsers (Company 1) to select which companies to include in
   widget data queries. Similar structure to parameter panel.
   ============================================================================ */

.company-panel-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
}

.company-panel {
    position: absolute;
    top: 35px;
    right: 0;
    width: 350px;
    max-height: 450px;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    animation: slideDown 0.2s ease;
}

.company-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
    font-weight: bold;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
}

.company-panel-header i {
    color: #2196F3;
}

.company-panel-header span {
    flex: 1;
}

/* Search box within the panel */
.company-panel-search {
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    background: #fafafa;
}

.company-panel-search .input-group-text {
    background: white;
    border-right: none;
}

.company-panel-search .form-control {
    border-left: none;
}

.company-panel-search .form-control:focus {
    box-shadow: none;
    border-color: #ced4da;
}

/* Quick actions row */
.company-panel-actions {
    display: flex;
    align-items: center;
    padding: 8px 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    font-size: 0.85rem;
}

.company-panel-actions .btn-link {
    padding: 2px 8px;
    font-size: 0.8rem;
    text-decoration: none;
}

.company-panel-actions .btn-link:hover {
    text-decoration: underline;
}

.company-panel-actions .company-count {
    margin-left: auto;
    color: #6c757d;
    font-size: 0.8rem;
}

/* Scrollable company list */
.company-panel-body {
    flex: 1;
    overflow-y: auto;
    min-height: 150px;
    max-height: 280px;
}

.company-list {
    padding: 5px 0;
}

.company-item {
    display: flex;
    align-items: center;
    padding: 8px 15px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.company-item:hover {
    background: #f5f5f5;
}

.company-item.selected {
    background: #e3f2fd;
}

.company-item .form-check {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.company-item .form-check-input {
    margin: 0;
    cursor: pointer;
}

.company-item .form-check-label {
    margin: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.company-item .company-name {
    font-weight: bold;
    color: #333;
}

.company-item .company-number {
    font-size: 0.8rem;
    color: #999;
}

/* Footer with action buttons */
.company-panel-footer {
    display: flex;
    justify-content: space-between;
    padding: 12px 15px;
    border-top: 1px solid #eee;
    background: #f8f9fa;
    border-radius: 0 0 8px 8px;
}

/* Company count badge on the widget header button */
.company-count-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #2196F3;
    color: white;
    font-size: 0.65rem;
    font-weight: bold;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    border-radius: 8px;
    text-align: center;
    padding: 0 4px;
}

/* Make the button position relative for the badge */
.widget-action-btn {
    position: relative;
}

/* Company button active state */
.widget-action-btn.active .company-count-badge {
    background: #1976D2;
}

/* Popup upward adjustments for company panel */
.widget-container.popup-upward .company-panel {
    top: auto;
    bottom: 35px;
    animation: slideUp 0.2s ease;
}

.widget-container.popup-upward .company-panel .company-panel-header {
    border-radius: 8px 8px 0 0;
}

.widget-container.popup-upward .company-panel .company-panel-footer {
    border-radius: 0 0 8px 8px;
}

/* ============================================================================
   SQL DEBUG PANEL (SuperUsers Only)
   ============================================================================
   Allows SuperUsers to view the executed SQL query for debugging purposes.
   Shows the full populated SQL that was run against the database.
   ============================================================================ */

/* SQL Debug Modal - Movable dialog for viewing executed queries */
/* z-index must be higher than drill-down modal (99999) to appear on top */
.sql-debug-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.sql-debug-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 700px;
    max-width: 90vw;
    max-height: 80vh;
    background: white;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.2s ease;
    z-index: 100001;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -45%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

.sql-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    font-weight: bold;
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    color: white;
    border-radius: 10px 10px 0 0;
    cursor: move;
    user-select: none;
}

.sql-modal-header span {
    display: flex;
    align-items: center;
}

.sql-modal-header i {
    color: #4CAF50;
}

.sql-modal-close {
    background: none;
    border: none;
    padding: 6px 10px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.7);
    border-radius: 4px;
    transition: all 0.2s ease;
    font-size: 1.1rem;
}

.sql-modal-close:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.sql-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    max-height: calc(80vh - 60px);
}

.sql-section {
    margin-bottom: 15px;
}

.sql-section:last-child {
    margin-bottom: 0;
}

.sql-section label {
    display: flex;
    align-items: center;
    font-size: 0.75rem;
    font-weight: bold;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

/* SQL Copy button styling */
.sql-section label .btn-outline-light {
    color: #0d6efd;
    border-color: #0d6efd;
    background: transparent;
    padding: 2px 8px;
    font-size: 0.75rem;
}

.sql-section label .btn-outline-light:hover {
    color: #fff;
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.sql-section p {
    margin: 0;
    font-size: 0.9rem;
    color: #333;
}

.query-mode-badge .badge {
    font-size: 0.8rem;
}

.sql-query-text {
    background: #1a1a2e;
    color: #7fdbca;
    padding: 15px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 400px;
    overflow-y: auto;
    margin: 0;
    line-height: 1.5;
}

/* SQL debug button styling */
.widget-action-btn.sql-debug-btn {
    color: #4CAF50;
}

.widget-action-btn.sql-debug-btn:hover {
    background: #e8f5e9;
    color: #388E3C;
}

.widget-action-btn.sql-debug-btn.active {
    background: #c8e6c9;
    color: #2E7D32;
}

/* Expand/Collapse button */
.widget-action-btn.expand-btn {
    color: #9C27B0;
}

.widget-action-btn.expand-btn:hover {
    background: #f3e5f5;
    color: #7B1FA2;
}

.widget-action-btn.expand-btn.active {
    background: #e1bee7;
    color: #6A1B9A;
}

/* ============================================================================
   DRILL-DOWN MODAL - GLOBAL STYLES
   ============================================================================
   These styles ensure the drill-down modal appears above ALL other elements.
   Using very high z-index to guarantee visibility.
   ============================================================================ */

.drill-down-backdrop {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: rgba(0, 0, 0, 0.6) !important;
    z-index: 99998 !important;
}

.drill-down-modal {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: 90% !important;
    max-width: 1200px !important;
    max-height: 85vh !important;
    background: white !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(0, 0, 0, 0.1) !important;
    z-index: 99999 !important;
    display: flex !important;
    flex-direction: column !important;
}

.drill-down-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 16px 20px;
    border-bottom: 1px solid #dee2e6;
    background: linear-gradient(135deg, #f8f9fa, #ffffff);
    border-radius: 12px 12px 0 0;
}

.drill-down-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.drill-down-header-actions .btn-outline-success {
    border-color: #4CAF50;
    color: #4CAF50;
}

.drill-down-header-actions .btn-outline-success:hover {
    background-color: #4CAF50;
    color: white;
}

/* ============================================================================
   ADDING WIDGETS OVERLAY
   ============================================================================
   Shows a loading overlay while widgets are being added to the dashboard.
   ============================================================================ */

.adding-widgets-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.adding-widgets-content {
    background: white;
    padding: 30px 50px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.adding-widgets-content .loading-spinner {
    width: 64px;
    height: 64px;
    margin-bottom: 15px;
}

.adding-widgets-content p {
    margin: 0;
    font-size: 1.1rem;
    color: #333;
    font-weight: 500;
}
