/* ECharts heatmap layout */
.heatmap-container {
    position: relative;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    overflow: visible;
}

#treemap {
    position: relative;
    width: 100%;
    height: 1000px;
}

#zoomToggle {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 3;
    padding: 10px;
    background-color: var(--ga-color-border-soft);
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

#zoomToggle:hover {
    background-color: var(--ga-color-border);
}

#zoomToggle.active {
    background-color: #4CAF50;
    color: var(--ga-color-surface);
}

.tooltip-title {
    font-weight: bold;
    margin-bottom: 5px;
}

.is-heatmap-dragging {
    cursor: grabbing;
}

.heatmap-empty {
    width: min(100%, 1200px);
    margin: 24px auto;
    padding: 24px;
    border: 1px solid #d9e2ec;
    border-radius: var(--ga-radius-lg);
    background: #f7fafc;
    color: #243b53;
    text-align: center;
}

/* Hidden during normal ECharts rendering; shown only if JS marks a real fallback. */
.heatmap-fallback {
    display: none;
}

.heatmap-container.is-fallback #treemap {
    display: none;
}

.heatmap-container.is-fallback .heatmap-fallback {
    display: grid;
    gap: 16px;
    width: 100%;
}

.heatmap-sector-fallback {
    border: 1px solid #d7e0ea;
    border-radius: var(--ga-radius-lg);
    overflow: hidden;
    background: var(--ga-color-surface);
}

.heatmap-sector-fallback header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: #f5f7fa;
    border-bottom: 1px solid #d7e0ea;
}

.heatmap-sector-fallback h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--ga-color-heading);
}

.heatmap-sector-fallback header span {
    font-size: 13px;
    font-weight: 700;
    color: #334155;
}

.heatmap-tile-grid {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 4px;
    padding: 4px;
}

.heatmap-tile {
    grid-column: span 1;
    min-height: 78px;
    padding: 8px;
    background: var(--ga-color-muted-2);
    color: var(--ga-color-surface);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    overflow: hidden;
}

.heatmap-change-loss-xl {
    background: #7f1d1d;
}

.heatmap-change-loss-lg {
    background: #b91c1c;
}

.heatmap-change-loss-md {
    background: #ef4444;
}

.heatmap-change-loss-sm {
    background: #fca5a5;
}

.heatmap-change-flat {
    background: #ca8a04;
}

.heatmap-change-gain-sm {
    background: #65a30d;
}

.heatmap-change-gain-md {
    background: #16a34a;
}

.heatmap-change-gain-lg {
    background: #15803d;
}

.heatmap-change-gain-xl {
    background: #166534;
}

.heatmap-change-neutral {
    background: #8a94a6;
}

.heatmap-span-1 {
    grid-column: span 1;
}

.heatmap-span-2 {
    grid-column: span 2;
}

.heatmap-span-3 {
    grid-column: span 3;
}

.heatmap-span-4 {
    grid-column: span 4;
}

.heatmap-tile strong,
.heatmap-tile span,
.heatmap-tile small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.heatmap-tile strong {
    font-size: 14px;
}

.heatmap-tile span,
.heatmap-tile small {
    font-size: 12px;
}

.heatmap-tile small {
    opacity: 0.92;
}

@media (max-width: 767px) {
    .heatmap-container {
        width: 100%;
        max-width: 100%;
    }

    #treemap {
        width: 100%;
        height: 500px;
    }

    #zoomToggle {
        top: 10px;
        right: 10px;
    }

    .tooltip-title {
        font-size: 14px;
    }

    .heatmap-tile-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .heatmap-tile,
    .heatmap-span-1,
    .heatmap-span-2,
    .heatmap-span-3,
    .heatmap-span-4 {
        grid-column: span 1;
    }

    .heatmap-tile {
        min-height: 68px;
    }
}
