/* =============================================================================
   RDDSquare — Chart, Map, KPI, Heatmap, Panel styles
   ============================================================================= */


/* Fullscreen targets the whole .panel-section (header + body), not just the
   map/chart container. The Fullscreen API renders only the fullscreened
   element and its descendants — the toolbar buttons live in
   .panel-section-header, a SIBLING of the container, so fullscreening the
   container alone hid them. Fullscreening the section keeps the header (and
   its print / save / clear / collapse buttons) on screen. The section is a
   flex column: header pinned at top, map/chart fills the rest. */
.panel-section:fullscreen {
    width: 100vw;
    height: 100vh;
    background: var(--rdd-surface, #ffffff);
    display: flex;
    flex-direction: column;
}

    /* Header keeps its intrinsic height at the top of the fullscreen view. */
    .panel-section:fullscreen .panel-section-header {
        flex: 0 0 auto;
    }

    /* Map / chart body fills all remaining space below the header. height:auto
       overrides the base height:100% so flex controls the sizing here. */
    .panel-section:fullscreen .panel-map-container,
    .panel-section:fullscreen .panel-chart-container {
        flex: 1 1 auto;
        min-height: 0;
        height: auto;
    }

    .panel-section:fullscreen .panel-map-container {
        padding: 0;
    }

    .panel-section:fullscreen .esri-view {
        width: 100% !important;
        height: 100% !important;
    }

    /* Chart.js canvas fills the flex body; chartInst.resize() (fired on enter)
       finalizes the pixel dimensions. */
    .panel-section:fullscreen .panel-chart-container canvas {
        flex: 1 1 auto;
        min-height: 0;
        width: 100% !important;
        max-height: none;
    }
/* ── Side panel containers ──────────────────────────────────────────────────── */

.panel-map-container {
    flex: 1 1 0;
    min-height: 0;
    position: relative;
    background: #e8eef4;
    overflow: hidden;
    /* Explicit height so ArcGIS MapView renders correctly */
    height: 100%;
}

    .panel-map-container .esri-view {
        width: 100%;
        height: 100%;
    }

.panel-chart-container {
    flex: 1 1 0;
    min-height: 0;
    position: relative;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

    .panel-chart-container canvas {
        flex: 1 1 0;
        min-height: 0;
        max-height: 100%;
    }

/* Empty state */
.panel-empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: #8a9bb0;
    font-size: 13px;
    text-align: center;
    padding: 24px;
    pointer-events: none;
}

    .panel-empty-state calcite-icon {
        opacity: 0.3;
    }

/* Status bar */
.panel-status-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    font-size: 11px;
    color: var(--rdd-text-muted, #5a6a80);
    background: #f4f7fb;
    border-bottom: 1px solid var(--rdd-border, #dde3ee);
    flex-shrink: 0;
}

.dark-theme .panel-status-bar {
    background: #0f1e30;
    border-color: #1e3050;
}

/* ── Panel badge in chat ─────────────────────────────────────────────────────── */

.panel-badge {
    padding: 4px 0;
}

.panel-badge-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #eef5ff;
    border: 1px solid #c0d8f8;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    color: #0d5ea6;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    font-family: inherit;
}

    .panel-badge-btn:hover {
        background: #ddeaff;
        box-shadow: 0 1px 4px rgba(13,94,166,0.15);
    }

.dark-theme .panel-badge-btn {
    background: #0d1f38;
    border-color: #1e4070;
    color: #7ab8f5;
}

    .dark-theme .panel-badge-btn:hover {
        background: #122843;
    }

/* ── Chart block (inline — KPI + heatmap only) ──────────────────────────────── */

.chart-block {
    margin-top: 10px;
    padding: 14px 16px 16px;
    background: var(--rdd-surface, #fff);
    border: 1px solid var(--rdd-border, #dde3ee);
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.dark-theme .chart-block {
    background: #111e2e;
    border-color: #1e3050;
}

.chart-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.chart-btn-row {
    display: flex;
    gap: 6px;
}

.chart-action-btn {
    background: #f0f4fb;
    border: 1px solid #c8d8ee;
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 11px;
    color: #0d5ea6;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
}

    .chart-action-btn:hover {
        background: #ddeaff;
    }

.dark-theme .chart-action-btn {
    background: #182a40;
    border-color: #2a4060;
    color: #7ab8f5;
}

.chart-subtitle {
    font-size: 11px;
    color: var(--rdd-text-muted, #5a6a80);
    margin-bottom: 10px;
    font-style: italic;
}

.chart-canvas-wrap {
    position: relative;
    width: 100%;
    max-height: 340px;
}

    .chart-canvas-wrap canvas {
        display: block;
        width: 100% !important;
        max-height: 340px;
    }

/* ── KPI card ───────────────────────────────────────────────────────────────── */

.kpi-block {
    border-left: 3px solid var(--rdd-accent, #f0a500);
}

.kpi-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.kpi-card {
    flex: 1 1 120px;
    min-width: 110px;
    max-width: 190px;
    background: #f8f9fb;
    border: 1px solid var(--rdd-border, #dde3ee);
    border-radius: 8px;
    padding: 12px 14px;
    text-align: center;
}

.dark-theme .kpi-card {
    background: #182a40;
    border-color: #2a4060;
}

.kpi-value {
    font-size: 22px;
    font-weight: 700;
    color: #0d5ea6;
    line-height: 1.2;
    margin-bottom: 4px;
}

.dark-theme .kpi-value {
    color: #7ab8f5;
}

.kpi-label {
    font-size: 10px;
    color: var(--rdd-text-muted, #5a6a80);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

/* ── Heatmap ────────────────────────────────────────────────────────────────── */

.heatmap-block {
    border-left: 3px solid #0d5ea6;
    overflow: hidden;
}

.heatmap-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 11px;
}

    .heatmap-table th {
        padding: 5px 8px;
        background: #f4f7fb;
        color: #0d2240;
        font-weight: 600;
        text-align: left;
        border: 1px solid var(--rdd-border, #dde3ee);
        white-space: nowrap;
    }

.dark-theme .heatmap-table th {
    background: #182a40;
    color: #a8c8f0;
    border-color: #2a4060;
}

.heatmap-table td {
    padding: 5px 8px;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.4);
    min-width: 56px;
    transition: opacity 0.1s;
}

    .heatmap-table td:hover {
        opacity: 0.85;
        outline: 2px solid #f0a500;
    }

/* ── CSV download ───────────────────────────────────────────────────────────── */

.csv-block {
    padding: 10px 14px;
    background: #f8f9fb;
    border: 1px solid var(--rdd-border, #dde3ee);
    border-radius: 6px;
    margin-top: 8px;
}

.dark-theme .csv-block {
    background: #111e2e;
    border-color: #1e3050;
}

.csv-download-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #0d5ea6;
    color: #fff;
    text-decoration: none;
    border-radius: 5px;
    padding: 7px 14px;
    font-size: 12px;
    font-weight: 600;
    transition: background 0.15s;
}

    .csv-download-btn:hover {
        background: #0d4a82;
    }

.csv-subtitle {
    font-weight: 400;
    opacity: 0.8;
    font-size: 11px;
}

/* ── Chart overlay ──────────────────────────────────────────────────────────── */

#rdd-chart-overlay {
    animation: rdd-fade-in 0.18s ease;
}

@keyframes rdd-fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* ── Map overlay ────────────────────────────────────────────────────────────── */

#rdd-map-overlay {
    animation: rdd-fade-in 0.18s ease;
}
