/**
 * AG Grid / Recline MultiView Integration
 * 
 * Hides Recline's built-in controls when AG Grid (Grid tab) is active,
 * as AG Grid provides its own filtering, pagination, and row count.
 * These controls remain visible for Graph and Map views.
 */

/* ==========================================================================
   Custom Properties (Design Tokens)
   ========================================================================== */

:root {
    --ag-recline-accent: #c800a1;
    --ag-recline-text: #495057;
    --ag-recline-text-muted: #6c757d;
    --ag-recline-border: #dee2e6;
    --ag-recline-bg-light: #f8f9fa;
    --ag-recline-bg-lighter: #e9ecef;
    --ag-recline-spinner-bg: #efefef;
    
    /* Chart-specific design tokens */
    --ag-chart-header-height: 50px;
    --ag-chart-body-height: 680px;
    --ag-chart-wrapper-min-height: calc(var(--ag-chart-header-height) + var(--ag-chart-body-height));
    --ag-chart-border-radius: 8px;
    --ag-chart-spacing: 16px;
}

/* ==========================================================================
   Recline Integration - Hide Controls When Grid Active
   ========================================================================== */

body {
    background-image: none;
}

.recline-view-container {
    &:has(.ag-grid-fullscreen) {
        padding: 50px;
    }
}

.recline-data-explorer {
    &:has(.navigation button[data-view="grid"].active) {
        .data-view-sidebar,
        .recline-results-info,
        .recline-pager,
        .menu-right,
        .query-editor-here {
            display: none !important;
        }
    }
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

.recline-ag-grid-container .hidden,
.recline-ag-grid-container.hidden {
    display: none !important;
}

/* ==========================================================================
   AG Grid Container Layout
   ========================================================================== */

.recline-ag-grid-container {
    &.ag-grid-fullscreen {
        display: flex;
        flex-direction: column;
        height: 70vh;
        min-height: 500px;
    }

    /* AG Grid wrapper */
    .ag-theme-quartz {
        width: 100%;
    }

    /* Fixed height for iframe mode */
    .ag-grid-iframe-mode {
        height: 680px;
    }

    /* Flex-fill for fullscreen mode */
    .ag-grid-fullscreen-mode {
        flex: 1;
        min-height: 400px;
    }
}

/* ==========================================================================
   Toolbar
   ========================================================================== */

.ag-grid-toolbar-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 10px;

    .btn-toolbar {
        display: flex;
        flex-direction: column;
        gap: 10px;
        width: 100%;
    }

    .btn-toolbar > .btn-group {
        display: flex;
        width: 100%;
    }

    .btn-toolbar > .btn-group > .btn {
        flex: 1;
    }
}

/* Desktop: horizontal toolbar layout */
@media (width >= 992px) {
    .ag-grid-toolbar-container {
        flex-direction: row;
        align-items: center;
        gap: 15px;

        .btn-toolbar {
            flex-direction: row;
            gap: 10px;
            width: auto;
            margin-left: auto;
        }

        .btn-toolbar > .btn-group {
            width: auto;
        }

        .btn-toolbar > .btn-group > .btn {
            flex: none;
        }
    }
}

/* ==========================================================================
   Quick Filter
   ========================================================================== */

.ag-grid-quick-filter {
    width: 100%;
    position: relative;

    input.form-control {
        padding-right: 30px;
    }

    .ag-grid-quick-filter-clear {
        position: absolute;
        right: 5px;
        top: 50%;
        translate: 0 -50%;
        padding: 0 5px;
        font-size: 18px;
        line-height: 1;
        color: #999;
        background: transparent;
        border: none;
        cursor: pointer;

        &:hover {
            color: #333;
        }
    }
}

/* Desktop: constrain quick filter width */
@media (width >=992px) {
    .ag-grid-quick-filter {
        flex: 1;
        max-width: 300px;
        width: auto;
    }
}

/* ==========================================================================
   Loading & Error States
   ========================================================================== */

.ag-grid-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    height: 300px;
    background: linear-gradient(
        135deg,
        var(--ag-recline-bg-light) 0%,
        var(--ag-recline-bg-lighter) 100%
    );
    border-radius: 8px;
    border: 1px solid var(--ag-recline-border);
}

.ag-grid-loading-spinner {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 2px 8px rgb(0 0 0 / 8%);
    transform: rotate(45deg);

    /* Rotating gradient creates the chasing border effect */
    &::before {
        content: "";
        position: absolute;
        inset: 50% auto auto 50%;
        width: 150%;
        height: 150%;
        background: conic-gradient(
            var(--ag-recline-accent) 0deg,
            var(--ag-recline-accent) 90deg,
            transparent 90deg
        );
        transform-origin: center;
        animation: ag-grid-border-spin 1.5s linear infinite;
        translate: -50% -50%;
    }

    /* Inner white box that masks the gradient */
    &::after {
        content: "";
        position: absolute;
        inset: 3px;
        border-radius: 9px;
        background: var(--ag-recline-spinner-bg);
    }
}

@keyframes ag-grid-border-spin {
    from {
        rotate: 0deg;
    }

    to {
        rotate: 360deg;
    }
}

.ag-grid-loading-text {
    font-size: 15px;
    font-weight: 500;
    color: var(--ag-recline-text);
    letter-spacing: 0.3px;
}

.ag-grid-loading-subtext {
    font-size: 13px;
    color: var(--ag-recline-text-muted);
    margin-top: -12px;
}

.ag-grid-error {
    margin: 20px 0;
}

/* ==========================================================================
   Integrated Charts Container
   ========================================================================== */

#ag-charts-parent {
    min-height: 160px;
}

.ag-chart-wrapper {
    display: flex;
    flex-direction: column;
    min-height: var(--ag-chart-wrapper-min-height);
    height: auto;
    border: 1px solid var(--ag-recline-border);
    border-radius: var(--ag-chart-border-radius);
    background: #fff;
    overflow: hidden;
}

.ag-chart-wrapper-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    height: var(--ag-chart-header-height);
    padding-block: 12px;
    padding-inline: var(--ag-chart-spacing);
    background: var(--ag-recline-bg-light);
    border-block-end: 1px solid var(--ag-recline-border);
}

.ag-chart-wrapper-title {
    margin: 0;
    font-size: var(--ag-chart-spacing);
    font-weight: 600;
    color: var(--ag-recline-text);
}

.ag-chart-wrapper-close {
    padding-block: 4px;
    padding-inline: 10px;
    font-size: 20px;
    line-height: 1;
    color: var(--ag-recline-text-muted);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.ag-chart-wrapper-close:hover {
    background: var(--ag-recline-bg-lighter);
    color: var(--ag-recline-text);
}

.ag-chart-wrapper-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: var(--ag-chart-body-height);
    overflow: visible;
}

/* Main chart element (direct child from chartRef.chartElement) */
.ag-chart-wrapper-body > * {
    width: 100%;
    height: var(--ag-chart-body-height);
    min-height: var(--ag-chart-body-height);
    flex-shrink: 0;
}

/* Ensure config panel and other chart UI elements are visible */
.ag-chart-wrapper-body :is(.ag-chart-menu, .ag-chart-settings-panel, .ag-popup) {
    position: absolute;
    z-index: 1000;
}

.ag-chart-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--ag-chart-spacing);
    height: 100%;
    padding: 30px;
    background: var(--ag-recline-bg-light);
    border: 2px dashed var(--ag-recline-border);
    border-radius: var(--ag-chart-border-radius);
    text-align: center;
}

.ag-chart-placeholder-icon {
    font-size: 48px;
    opacity: 0.5;
}

.ag-chart-placeholder p {
    margin: 0;
    font-size: 14px;
    color: var(--ag-recline-text-muted);
}

/* ==========================================================================
   AG Grid Tooltips
   ========================================================================== */

/* Make tooltip background solid instead of opaque/transparent */
.ag-tooltip {
    background-color: #fff !important;
    opacity: 1 !important;
}