/*
 * IMPACCT 2.0 — India Choropleth Heatmap
 * 2-column layout: Map (with dropdown) | Stat Cards
 * All colors via theme CSS variables.
 */

.india-heatmap {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 20px;
    position: relative;
    box-shadow: var(--shadow-sm);
}

/* ── Loading ── */
.heatmap-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 80px 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.heatmap-loading-spinner {
    width: 20px; height: 20px;
    border: 2px solid var(--border-primary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── 2-column body ── */
.heatmap-body {
    display: flex;
    min-height: 420px;
}

/* ── Map column ── */
.heatmap-map-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 0 20px 14px;
}

/* Map header with title + dropdown */
.heatmap-map-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 4px 10px;
    border-bottom: 1px solid var(--border-primary);
    margin-bottom: 8px;
}

.heatmap-map-title {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-primary);
}

.heatmap-mode-select {
    padding: 6px 12px;
    font-size: 0.78rem;
    border-radius: 6px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--input-text);
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s;
}

.heatmap-mode-select:focus {
    border-color: var(--accent-primary);
}

/* SVG */
.india-svg {
    flex: 1;
    width: 100%;
    max-height: 400px;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.12));
    animation: mapReveal 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes mapReveal {
    from { opacity: 0; transform: scale(0.95) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.heatmap-state {
    cursor: pointer;
    transition: fill 0.3s ease, stroke-width 0.2s ease, filter 0.25s ease;
    stroke-linejoin: round;
}

.heatmap-state:hover,
.heatmap-state.state-active {
    stroke: var(--accent-primary) !important;
    stroke-width: 0.45 !important;
    filter: brightness(1.2) drop-shadow(0 0 8px rgba(59, 130, 246, 0.45));
}

/* Scale */
.heatmap-scale-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    margin-top: 6px;
    width: 200px;
    align-self: center;
}

.heatmap-scale-inline span {
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.heatmap-scale-bar {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(to right,
        rgba(59,130,246,0.06), rgba(59,130,246,0.2),
        rgba(59,130,246,0.4), rgba(59,130,246,0.6),
        rgba(59,130,246,0.85), rgba(59,130,246,1));
}

/* ── Stat cards column ── */
.heatmap-cards-col {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px 16px;
    justify-content: center;
    border-left: 1px solid var(--border-primary);
}

/* Single stat card */
.hm-stat-card {
    border-radius: 14px;
    padding: 20px 18px;
    background: var(--card-bg);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    animation: cardSlideIn 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: default;
}

.hm-stat-card:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

@keyframes cardSlideIn {
    from { opacity: 0; transform: translateX(24px); }
    to { opacity: 1; transform: translateX(0); }
}

.hm-stat-icon {
    font-size: 1.5rem;
    opacity: 0.9;
    flex-shrink: 0;
}

.hm-stat-content { flex: 1; min-width: 0; }

.hm-stat-val {
    font-size: 1.35rem;
    font-weight: 900;
    line-height: 1.1;
    letter-spacing: -0.5px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.hm-stat-label {
    font-size: 0.65rem;
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-top: 4px;
    font-weight: 600;
}

/* ── Split card (Category | Sector) ── */
.hm-split-card {
    display: flex;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    animation: cardSlideIn 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: default;
}

.hm-split-card:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

.hm-split-half {
    flex: 1;
    background: var(--card-bg);
    color: #fff;
    padding: 16px 12px;
    text-align: center;
}

.hm-split-half:first-child {
    border-right: 1px solid rgba(255, 255, 255, 0.15);
}

.hm-split-val {
    font-size: 1.4rem;
    font-weight: 900;
    line-height: 1;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.hm-split-label {
    font-size: 0.6rem;
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-top: 5px;
    font-weight: 600;
}

/* ── Tooltip ── */
.heatmap-tooltip {
    position: absolute;
    background: var(--bg-secondary);
    border: 1px solid var(--border-secondary);
    border-radius: 10px;
    padding: 12px 16px;
    color: var(--text-primary);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.04);
    pointer-events: none;
    z-index: 50;
    white-space: nowrap;
    backdrop-filter: blur(12px);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.18s ease, transform 0.18s ease;
    min-width: 160px;
}

.heatmap-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.heatmap-tooltip-name {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-primary);
}

.heatmap-tooltip-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    padding: 2px 0;
}

.heatmap-tooltip-row span {
    color: var(--text-muted);
}

.heatmap-tooltip-row strong {
    color: var(--accent-primary);
    font-family: 'SF Mono', Monaco, monospace;
}

.heatmap-tooltip-pct {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.heatmap-tooltip-bar {
    height: 4px;
    background: var(--bg-primary, var(--bg-card));
    border-radius: 2px;
    overflow: hidden;
    margin-top: 6px;
}

.heatmap-tooltip-bar-fill {
    height: 100%;
    background: var(--accent-primary);
    border-radius: 2px;
}

/* ── Responsive ── */

/* Tablet: stack map above cards */
@media (max-width: 900px) {
    .heatmap-body {
        flex-direction: column;
    }

    .heatmap-map-col {
        min-height: 260px;
        padding: 12px 16px 8px;
    }

    .heatmap-cards-col {
        width: auto;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px;
        border-left: none;
        border-top: 1px solid var(--border-primary);
    }

    .hm-stat-card {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
        padding: 14px 12px;
    }

    .hm-split-card {
        flex: 1 1 100%;
    }

    .heatmap-map-header {
        padding: 10px 0 8px;
    }
}

/* Phone: single column cards, compact map */
@media (max-width: 480px) {
    .india-heatmap {
        margin-bottom: 12px;
    }

    .heatmap-map-col {
        min-height: 220px;
        padding: 8px 12px 6px;
    }

    .india-svg {
        max-height: 240px;
    }

    .heatmap-map-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .heatmap-mode-select {
        width: 100%;
    }

    .heatmap-scale-inline {
        width: 140px;
    }

    .heatmap-cards-col {
        flex-direction: column;
        gap: 6px;
        padding: 8px 10px;
    }

    .hm-stat-card {
        flex: none;
        width: 100%;
        padding: 12px 14px;
        gap: 10px;
    }

    .hm-stat-icon {
        font-size: 1.2rem;
    }

    .hm-stat-val {
        font-size: 1.1rem;
    }

    .hm-stat-label {
        font-size: 0.6rem;
    }

    .hm-split-card {
        flex: none;
        width: 100%;
    }

    .hm-split-half {
        padding: 12px 8px;
    }

    .hm-split-val {
        font-size: 1.1rem;
    }

    /* Hide tooltip on touch devices — use tap instead */
    .heatmap-tooltip {
        display: none !important;
    }
}
