/* ===== MAP STYLING ===== */

/* Map Viewport */
.map-viewport {
    flex: 1;
    position: relative;
    background: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGNpcmNsZSBjeD0iMSIgY3k9IjEiIHI9IjEiIGZpbGw9InJnYmEoMjU1LDI1NSwyNTUsMC4wNSkiLz48L3N2Zz4=');
    /* Subtle dot pattern */
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* Vital for pan-zoom */
}

[data-theme="light"] .map-viewport {
    background: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGNpcmNsZSBjeD0iMSIgY3k9IjEiIHI9IjEiIGZpbGw9InJnYmEoMCwwLDAsMC4wNSkiLz48L3N2Zz4=');
}

.map-viewport svg path {
    fill: var(--map-fill);
    /* Stroke must match the dynamic fill to avoid gaps */
    stroke: #ffffff;
    stroke-width: 1.5px;
    /* Always visible white borders */
    stroke-linejoin: round;
    stroke-linecap: round;
    transition: all 0.2s ease;
    cursor: pointer;
}

.map-viewport svg path:hover {
    fill: var(--map-hover);
    stroke: #ffffff;
    stroke-width: 2.5px;
    /* Slightly thicker on hover */
    filter: brightness(1.1);
}

/* Don't apply hover to selected or highlighted elements */
.map-viewport svg path.highlighted:hover,
.map-viewport svg path.selected:hover {
    stroke: #ffffff;
    stroke-width: 3px;
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.8));
}

.map-viewport svg path.highlighted {
    stroke: #ffffff !important;
    stroke-width: 3px !important;
    filter: drop-shadow(0 0 12px rgba(255, 255, 255, 0.9)) drop-shadow(0 0 20px rgba(255, 255, 255, 0.6)) !important;
    /* Glowing white border effect */
    z-index: 100;
}

/* Selected district styling (for Kerala districts) */
.district.selected,
.district.highlighted path,
/* Ensure paths inside highlighted group get the style */
path.selected {
    stroke: #ffffff !important;
    stroke-width: 3px !important;
    filter: drop-shadow(0 0 12px rgba(255, 255, 255, 0.9)) drop-shadow(0 0 20px rgba(255, 255, 255, 0.6)) !important;
}

/* View Layers */
.view-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    /* Hide via display to preventing stacking issues */
    align-items: center;
    justify-content: center;
}

.view-layer.active {
    display: flex;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.pan-zoom-layer {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Will be transformed by JS */
}

.pan-zoom-layer svg {
    max-height: 90vh;
    /* Initial fit */
    max-width: 90vw;
    filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.5));
}

/* Map Tools */
.map-tools {
    position: absolute;
    bottom: 2rem;
    left: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 10;
}

/* Back Icon Button */
.back-icon-btn {
    position: absolute;
    top: 2rem;
    left: 2rem;
    width: 88px;
    height: 88px;
    cursor: pointer;
    z-index: 50;
    transition: transform 0.2s, box-shadow 0.2s;
    object-fit: contain;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.back-icon-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

/* View Toggle Dropdown */
.view-toggle-container {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 100;
}

#report-selector {
    min-width: 60px;
    width: auto;
    max-width: 100px;
    padding-left: 0.5rem;
}

.view-dropdown {
    padding: 0.5rem 2rem 0.5rem 1rem;
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--text-main);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 1em;
    min-width: 120px;
    outline: none;
    transition: all 0.2s;
}

.view-dropdown:hover {
    border-color: var(--border-highlight);
    background-color: var(--bg-sidebar-hover);
}

.view-dropdown:focus {
    border-color: var(--primary);
}

.view-dropdown option {
    background: var(--bg-panel);
    color: var(--text-main);
}

/* Info Sidebar (Map Details) */
.info-sidebar {
    width: 400px;
    /* Widened for better content display */
    background: var(--bg-panel);
    border-left: 1px solid var(--border-light);
    backdrop-filter: none;
    display: flex;
    flex-direction: column;
    z-index: 20;
    box-shadow: none;
    transition: transform 0.3s ease;
}

.sidebar-content {
    padding: 0.25rem 1rem 0.75rem 1rem;
    overflow-y: auto;
    flex: 1;
}

.sidebar-header {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-highlight);
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 500;
    margin-bottom: 0;
    margin-top: 0;
    color: var(--text-main);
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    display: none;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    transition: transform 0.2s;
}

.stat-card:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--accent);
}

.stat-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: white;
}

/* Dealer List Compact */
.dealer-section {
    margin-top: 0.5rem;
}

/* View Toggle (Dealers/Districts) */
.view-toggle {
    display: flex;
    gap: 0;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-light);
}

.toggle-btn {
    flex: 1;
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    position: relative;
}

.toggle-btn:hover {
    color: var(--text-main);
    background: var(--bg-sidebar-hover);
}

.toggle-btn.active {
    color: var(--text-highlight);
    border-bottom-color: var(--primary);
}

.dealer-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    /* Super compact VS Code style */
}

.dealer-item-compact {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    border-radius: 3px;
    cursor: default;
    transition: background 0.1s;
}

.dealer-item-compact:hover {
    background: var(--bg-sidebar-hover);
}

.dealer-rank {
    min-width: 20px;
    text-align: right;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.dealer-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.dealer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.dealer-name {
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 8px;
    font-weight: 400;
}

.dealer-sales {
    color: var(--text-highlight);
    font-weight: 500;
    font-size: 0.85rem;
    white-space: nowrap;
}

.contribution-bar-bg {
    width: 100%;
    height: 2px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 1px;
    overflow: hidden;
}

.contribution-bar-fill {
    height: 100%;
    background: var(--primary);
    opacity: 0.8;
}

/* District Sales List (matching dealer list style) */
.district-sales-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.district-item-compact {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    border-radius: 3px;
    cursor: default;
    transition: background 0.1s;
    position: relative;
}

.district-item-compact:hover {
    background: var(--bg-sidebar-hover);
}

.district-rank {
    min-width: 20px;
    text-align: right;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.district-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.district-row {
    display: grid;
    grid-template-columns: 1fr 60px 100px;
    align-items: center;
    font-size: 0.9rem;
    gap: 8px;
}

.district-name {
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 400;
}

.district-percentage {
    color: var(--accent);
    font-weight: 500;
    font-size: 0.8rem;
    white-space: nowrap;
    opacity: 0.9;
    text-align: right;
    margin-right: 0;
}

.district-sales {
    color: var(--text-highlight);
    font-weight: 500;
    font-size: 0.85rem;
    white-space: nowrap;
    text-align: right;
}

/* Mobile Responsiveness for Map Elements */
@media (max-width: 900px) {
    .map-viewport {
        flex: 1;
    }

    /* Takes available space */

    .info-sidebar {
        width: 100%;
        height: 45vh;
        /* Drawer style */
        position: absolute;
        bottom: 0;
        left: 0;
        border-left: none;
        border-top: 1px solid var(--border-highlight);
        transform: translateY(calc(100% - 60px));
        /* Peeking */
    }

    .info-sidebar.open {
        transform: translateY(0);
    }

    /* Add handle for drawer */
    .sidebar-content::before {
        content: "";
        display: block;
        width: 40px;
        height: 4px;
        background: var(--border-highlight);
        border-radius: 2px;
        margin: -1rem auto 1rem;
    }

    .map-tools {
        bottom: calc(45vh + 1rem);
    }
}

/* Map Tooltip Styles */
.map-tooltip {
    position: absolute;
    background: var(--surface-card);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--duration-fast);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    min-width: 200px;
}

.map-tooltip.visible {
    opacity: 1;
}

.tooltip-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-3);
    border-bottom: 1px solid var(--border-light);
    padding-bottom: var(--space-2);
}

.tooltip-stats {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.tooltip-stat {
    display: flex;
    justify-content: space-between;
}

.tooltip-label {
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.tooltip-value {
    color: var(--text-primary);
    font-weight: var(--font-medium);
    font-size: var(--text-sm);
}

.tooltip-hint {
    color: var(--text-muted);
    font-size: var(--text-xs);
    text-align: center;
    font-style: italic;
}

/* Map Legend */
.map-legend {
    position: absolute;
    bottom: var(--space-6, 24px);
    right: var(--space-6, 24px);
    background: rgba(30, 41, 59, 0.9);
    /* Semi-transparent Slate-800 */
    padding: var(--space-4, 16px);
    border-radius: var(--radius-md, 8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    color: #f8fafc;
    font-family: 'Inter', sans-serif;
    z-index: 500;
    min-width: 140px;
}

.legend-title {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: #f8fafc;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: #cbd5e1;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 4px;
    flex-shrink: 0;
}