* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #ffffff;
    --surface: #f5f5f7;
    --surface-hover: #e8e8ed;
    --border: #d2d2d7;
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --accent: #0071e3;
    --accent-hover: #0077ed;
    --success: #30d158;
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
    background: var(--surface);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 125px;
    background: var(--bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-header {
    padding: 8px 4px 6px;
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 12px;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.03em;
    margin-bottom: 2px;
}

.tagline {
    font-size: 7px;
    color: var(--text-secondary);
    font-weight: 400;
    line-height: 1.1;
}

.controls {
    padding: 4px;
    flex: 1;
}

.control-group {
    margin-bottom: 8px;
}

.label {
    display: block;
    font-size: 7px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

/* Segmented Control */
.segmented-control {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--surface);
    border-radius: 10px;
    padding: 2px;
    gap: 2px;
    position: relative;
}

.segmented-control.category-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
}

.segmented-control.category-grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

.segmented-control input[type="radio"] {
    display: none;
}

.segment {
    padding: 4px 4px;
    text-align: center;
    font-size: 8px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-primary);
}

.segmented-control input[type="radio"]:checked + .segment {
    background: var(--bg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Search Box */
.search-box {
    position: relative;
}

.input {
    width: 100%;
    padding: 4px 4px;
    font-size: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    transition: all 0.2s;
    font-family: inherit;
}

.input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.1);
}

.input::placeholder {
    color: var(--text-secondary);
}

.dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 240px;
    overflow-y: auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 100;
}

.dropdown.show {
    display: block;
}

.dropdown-item {
    padding: 4px 4px;
    cursor: pointer;
    font-size: 8px;
    border-bottom: 1px solid var(--surface);
    transition: background 0.15s;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: var(--surface);
}

.dropdown-item-name {
    display: block;
    font-weight: 500;
    margin-bottom: 1px;
}

.dropdown-item-meta {
    font-size: 6px;
    color: var(--text-secondary);
}

/* Toggle Switch */
.toggle-switch {
    display: flex;
    gap: 8px;
}

.toggle-btn {
    flex: 1;
    padding: 4px;
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: 4px;
    font-size: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    color: var(--text-primary);
}

.toggle-btn:hover {
    background: var(--surface);
}

.toggle-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Stats Box */
.stats-box {
    background: var(--surface);
    border-radius: 4px;
    padding: 4px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 6px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 600;
    margin-bottom: 2px;
}

.stat-value {
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
}

/* Legend */
.legend-box {
    padding: 6px 4px;
    border-top: 1px solid var(--border);
}

.legend-title {
    font-size: 7px;
    font-weight: 600;
    margin-bottom: 4px;
}

.gradient-bar {
    height: 16px;
    border-radius: 4px;
    /* Reverse Spectral colormap: blue/purple -> green -> yellow -> orange -> red */
    background: linear-gradient(90deg,
        rgb(102, 194, 165) 0%,   /* Cyan-green (low values) */
        rgb(171, 221, 164) 15%,  /* Green */
        rgb(230, 245, 152) 29%,  /* Yellow-green */
        rgb(254, 224, 139) 43%,  /* Yellow */
        rgb(253, 174, 97) 58%,   /* Orange */
        rgb(244, 109, 67) 72%,   /* Orange-red */
        rgb(213, 62, 79) 86%,    /* Red */
        rgb(158, 1, 66) 100%     /* Dark red/purple (high values) */
    );
    margin-bottom: 8px;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 6px;
    color: var(--text-secondary);
    font-weight: 500;
    gap: 1px;
}

.legend-labels span {
    flex: 1;
    text-align: center;
}

.legend-labels span:first-child {
    text-align: left;
}

.legend-labels span:last-child {
    text-align: right;
}

/* Data Source */
.hover-hint {
    padding: 16px 24px;
    margin-bottom: 24px;
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    line-height: 1.5;
}

.hover-hint svg {
    flex-shrink: 0;
    color: rgba(59, 130, 246, 0.7);
}

.data-source {
    padding: 20px 24px 24px;
    border-top: 1px solid var(--border);
}

.data-source-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    margin-bottom: 8px;
}

.data-source-link {
    display: block;
    font-size: 13px;
    color: var(--accent);
    text-decoration: none;
    line-height: 1.5;
    transition: color 0.2s;
}

.data-source-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Map Area */
.map-area {
    flex: 1;
    position: relative;
    background: var(--surface);
}

.map-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.map-title-container {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    max-width: 90%;
    width: max-content;
}

.map-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

#indiaMap {
    width: 100%;
    height: 100%;
    display: block;
}

.district {
    stroke: #000000;
    stroke-width: 0.5;
    cursor: pointer;
    transition: stroke 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.district:hover {
    stroke: var(--accent);
    stroke-width: 1.5;
}

/* State Boundaries */
.state-boundary {
    fill: none;
    stroke: #000000;
    stroke-width: 2.5;
    stroke-linejoin: round;
    pointer-events: none;
}

/* Loading */
.loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading.hide {
    display: none;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--surface);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading p {
    margin-top: 16px;
    font-size: 14px;
    color: var(--text-secondary);
}

/* Block Loading Indicators */
.spinner-small {
    width: 16px;
    height: 16px;
    border: 2px solid var(--surface);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

.block-loading-status {
    margin-top: 12px;
    padding: 12px;
    background: var(--surface);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-secondary);
}

.loading-indicator {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

.segment-loading {
    position: relative;
}

.segment-loading.loaded .loading-indicator {
    display: none;
}

input[type="radio"]:disabled + label {
    opacity: 0.5;
    cursor: not-allowed;
}

input[type="radio"]:disabled + label:hover {
    background: transparent;
    color: var(--text-primary);
}

/* Map Controls */
.map-controls {
    position: absolute;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-btn {
    width: 40px;
    height: 40px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow);
}

.control-btn:hover {
    background: var(--surface);
    transform: scale(1.05);
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn svg {
    color: var(--text-primary);
}

/* Tooltip */
.tooltip {
    position: fixed;
    top: 120px;
    left: 20px;
    background: rgba(29, 29, 31, 0.95);
    backdrop-filter: blur(20px);
    color: white;
    padding: 12px 16px;
    border-radius: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 1000;
    font-size: 13px;
    min-width: 280px;
    max-width: 400px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

@media (min-width: 1024px) {
    .tooltip {
        left: auto;
        right: calc(33.333% + 20px); /* Position it on the map area, accounting for 1/3 sidebar */
    }
}

.tooltip.show {
    opacity: 1;
}

.tooltip-title {
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 14px;
}

.tooltip-subtitle {
    font-size: 12px;
    opacity: 0.7;
    margin-bottom: 10px;
}

.tooltip-row {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 12px;
}

.tooltip-label {
    opacity: 0.7;
}

.tooltip-value {
    font-weight: 600;
}

/* Scrollbar */
.sidebar::-webkit-scrollbar,
.dropdown::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track,
.dropdown::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb,
.dropdown::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.dropdown::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Browse View */
.browse-container {
    width: 100%;
    height: 100%;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.browse-header {
    padding: 32px 40px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
}

.browse-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0;
}

.browse-search {
    width: 320px;
    padding: 10px 14px;
    font-size: 15px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    transition: all 0.2s;
    font-family: inherit;
}

.browse-search:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.1);
    background: var(--bg);
}

.browse-stats {
    padding: 16px 40px;
    background: var(--surface);
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.browse-table-container {
    flex: 1;
    overflow-y: auto;
    padding: 0 40px 40px;
}

.browse-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.browse-table thead th {
    position: sticky;
    top: 0;
    background: var(--bg);
    padding: 16px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
    z-index: 10;
}

.browse-table thead th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}

.browse-table thead th.sortable:hover {
    color: var(--text-primary);
}

.browse-table thead th.sortable .sort-icon {
    margin-left: 6px;
    font-size: 10px;
    opacity: 0.3;
}

.browse-table thead th.sortable.active .sort-icon {
    opacity: 1;
    color: var(--accent);
}

.browse-table thead th.sortable.active {
    color: var(--accent);
}

.browse-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.browse-table tbody tr:hover {
    background: var(--surface);
}

.browse-table tbody td {
    padding: 16px 12px;
    color: var(--text-primary);
}

.browse-table tbody td:first-child {
    font-weight: 500;
}

.browse-table tbody td:nth-child(2),
.browse-table tbody td:nth-child(3) {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.browse-table tbody td:nth-child(4) {
    font-size: 13px;
    color: var(--text-secondary);
}

.view-btn {
    padding: 6px 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.view-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 113, 227, 0.3);
}

.view-btn:active {
    transform: translateY(0);
}

/* Footer */
.site-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 16px 24px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
    flex-wrap: wrap;
    gap: 12px;
}

.footer-section {
    display: flex;
    align-items: center;
}

.footer-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 0;
}

.footer-link {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s;
}

.footer-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Adjust container for footer */
.container {
    padding-bottom: 50px;
}

/* Responsive */
/* Mobile Optimizations */
@media (max-width: 768px) {
    /* Container Layout */
    .container {
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
        position: relative;
    }

    /* Sidebar - Fixed at bottom */
    .sidebar {
        width: 100%;
        max-height: 45vh;
        height: auto;
        border-right: none;
        border-top: 1px solid var(--border);
        overflow-y: auto;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        background: var(--bg);
        transition: max-height 0.3s ease-in-out, border-top 0.3s ease-in-out;
        display: flex;
        flex-direction: column;
    }

    /* Order sidebar children - View mode first, then other controls */
    .sidebar .controls {
        order: 1;
    }

    .sidebar .sidebar-header {
        order: 2;
    }

    .sidebar .hover-hint {
        order: 3;
    }

    .sidebar .legend-box {
        order: 4;
    }

    .sidebar .data-source {
        order: 5;
    }

    /* Sidebar Header */
    .sidebar-header {
        padding: 16px 16px 12px;
        background: var(--bg);
        border-bottom: 1px solid var(--border);
    }

    .logo {
        font-size: 24px;
    }

    .tagline {
        font-size: 11px;
    }

    /* Hover Hint */
    .hover-hint {
        padding: 12px 16px;
        margin-bottom: 16px;
        font-size: 12px;
    }

    .hover-hint svg {
        width: 14px;
        height: 14px;
        margin-right: 6px;
    }

    /* View Mode Tabs - First in controls */
    .control-group:has(input[name="viewMode"]) {
        order: 1;
        padding: 12px 16px;
        margin: 0 -16px;
        border-bottom: 1px solid var(--border);
        background: var(--bg);
    }

    .segmented-control {
        grid-template-columns: 1fr 1.2fr 1.2fr 1.2fr !important;
        gap: 2px !important;
        font-size: 11px;
    }

    .segmented-control .segment {
        padding: 10px 4px !important;
        font-size: 10px !important;
        min-height: 40px;
    }

    /* Controls Section */
    .controls {
        padding: 0 16px 16px;
        gap: 16px;
        max-height: calc(45vh - 60px);
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

    .control-group {
        gap: 8px;
    }

    /* Move colormap to bottom within controls */
    #colormapControl {
        order: 101;
    }

    /* Data source at bottom - styling */
    .data-source {
        padding: 12px 16px;
        font-size: 11px;
    }

    .data-source-label {
        font-size: 10px;
        margin-bottom: 4px;
    }

    .data-source-link {
        font-size: 11px;
    }

    .control-label {
        font-size: 11px;
        font-weight: 600;
    }

    /* Category/Tribe Controls */
    .segmented-control input[type="radio"] + label {
        padding: 10px 12px;
        font-size: 12px;
    }

    /* Tribe Search */
    .tribe-input-wrapper input {
        font-size: 14px;
        padding: 10px 12px;
    }

    .tribe-dropdown {
        font-size: 12px;
        max-height: 200px;
    }

    /* Colormap Dropdown */
    select {
        padding: 10px 12px;
        font-size: 13px;
    }

    /* Main Content Area - fills space above bottom sidebar */
    .map-area {
        flex: 1;
        height: calc(100vh - 45vh);
        overflow: hidden;
        padding-bottom: 0;
        position: relative;
        margin-bottom: 45vh;
    }

    /* Map View */
    .map-container {
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #map {
        min-height: 400px;
        height: 50vh;
    }

    /* Map Title */
    .map-title-container {
        top: 60px; /* Positioned below sub-tab navigation bar */
        left: 50%;
        transform: translateX(-50%);
        max-width: 90%;
        max-width: calc(100% - 68px);
        padding: 6px 12px;
        pointer-events: none;
    }

    .map-title {
        font-size: 11px;
        pointer-events: auto;
        line-height: 1.3;
    }

    /* Hide map titles in language views on mobile for cleaner UI */
    #languageViewL1 .map-title-container,
    #languageViewL2 .map-title-container {
        display: none;
    }

    /* Tooltip - Mobile Positioning */
    .tooltip {
        position: fixed;
        top: auto !important;
        left: 50% !important;
        bottom: 80px !important;
        transform: translateX(-50%) !important;
        max-width: 90vw;
        font-size: 12px;
        padding: 10px 12px;
    }

    .language-tooltip {
        position: fixed;
        top: auto !important;
        left: 50% !important;
        bottom: 80px !important;
        transform: translateX(-50%) !important;
        max-width: 90vw;
        min-width: auto;
        font-size: 12px;
        padding: 10px 12px;
    }

    /* Map Controls */
    .map-controls {
        bottom: 20px;
        right: 10px;
        gap: 8px;
    }

    .control-btn {
        width: 44px;
        height: 44px;
        border-radius: 22px;
    }

    /* Legend */
    .legend {
        bottom: auto;
        top: 60px;
        left: 10px;
        padding: 12px;
        font-size: 11px;
    }

    .legend-title {
        font-size: 11px;
        margin-bottom: 8px;
    }

    .legend-gradient {
        height: 12px;
        margin: 6px 0;
    }

    .legend-label {
        font-size: 9px;
    }

    /* Tables - All Views */
    .browse-container,
    .language-container {
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Language containers should not block the toggle button */
    .language-container {
        position: relative;
    }

    .browse-header,
    .tribes-table-header {
        flex-direction: column;
        align-items: stretch;
        padding: 16px;
        gap: 12px;
    }

    .browse-title,
    .tribes-table-title {
        font-size: 18px;
    }

    .browse-search {
        width: 100%;
        padding: 10px 12px;
        font-size: 14px;
    }

    .browse-stats {
        padding: 0 16px 8px;
        font-size: 12px;
    }

    /* Table Container - Horizontal Scroll */
    .browse-table-container {
        padding: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .browse-table {
        font-size: 12px;
        min-width: 600px; /* Force horizontal scroll */
    }

    .browse-table thead th {
        padding: 10px 8px;
        font-size: 11px;
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
    }

    .browse-table tbody td {
        padding: 10px 8px;
    }

    /* View Button */
    .view-btn {
        padding: 6px 12px;
        font-size: 11px;
        white-space: nowrap;
    }

    /* Language View Specific */
    #languageMapL1,
    #languageMapL2 {
        min-height: 350px;
        height: 50vh;
        max-height: 50vh;
        position: relative;
        z-index: 1;
    }

    /* Ensure language containers don't block the menu toggle */
    .language-container {
        position: relative;
        z-index: 1;
    }

    /* Reserve top-right corner for toggle button - prevent SVG overflow */
    #languageViewL1,
    #languageViewL2 {
        padding-top: 10px;
        padding-right: 10px;
    }

    #languageViewL1 #languageMapL1,
    #languageViewL2 #languageMapL2 {
        overflow: visible;
    }

    .language-explanation {
        display: none; /* Hide language explanation on mobile to save space */
    }

    .language-explanation h3 {
        font-size: 18px;
        margin-bottom: 16px;
    }

    .explanation-section {
        margin-bottom: 20px;
    }

    .explanation-section h4 {
        font-size: 14px;
        margin-bottom: 8px;
    }

    .explanation-section p,
    .explanation-section li {
        font-size: 13px;
        line-height: 1.6;
    }

    /* Footer */
    .footer {
        padding: 12px 16px;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }

    .footer-text {
        font-size: 11px;
    }

    .footer-links {
        gap: 12px;
    }

    .footer-link {
        font-size: 11px;
    }

    /* Loading Spinner */
    .loading {
        padding: 40px 16px;
    }

    .spinner {
        width: 40px;
        height: 40px;
    }

    /* Mobile Menu Toggle Button */
    .mobile-menu-toggle {
        position: fixed;
        top: 10px;
        right: 10px;
        width: 44px;
        height: 44px;
        background: var(--bg);
        border: 1px solid var(--border);
        border-radius: 22px;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 10001;
        cursor: pointer;
        box-shadow: var(--shadow);
        transition: all 0.3s;
        pointer-events: auto;
    }

    .mobile-menu-toggle:active {
        transform: scale(0.95);
        background: var(--surface);
    }

    .mobile-menu-toggle svg {
        width: 24px;
        height: 24px;
        color: var(--text-primary);
    }

    /* Sidebar collapsed state */
    .sidebar.collapsed {
        max-height: 0 !important;
        overflow: hidden !important;
        border-bottom: none !important;
    }

    /* Legend styling within sidebar */
    .legend-box {
        padding: 12px 16px;
    }

    .legend-title {
        font-size: 11px;
        margin-bottom: 8px;
    }

    .gradient-bar {
        height: 16px;
        margin-bottom: 6px;
    }

    .legend-labels {
        font-size: 9px;
    }
}

/* Extra Small Mobile (< 480px) */
@media (max-width: 480px) {
    .sidebar {
        max-height: 50vh;
    }

    .logo {
        font-size: 20px;
    }

    .segmented-control {
        grid-template-columns: 1fr 1fr !important;
        grid-template-rows: 1fr 1fr;
        gap: 4px !important;
    }

    .segmented-control .segment {
        font-size: 11px !important;
        padding: 10px 8px !important;
    }

    .map-title {
        font-size: 12px;
    }

    .browse-table {
        min-width: 500px;
        font-size: 11px;
    }

    .browse-table thead th,
    .browse-table tbody td {
        padding: 8px 6px;
    }

    .control-btn {
        width: 40px;
        height: 40px;
    }

    .legend {
        padding: 10px;
        font-size: 10px;
    }

    .tooltip,
    .language-tooltip {
        font-size: 11px;
        padding: 8px 10px;
    }
}

/* Landscape Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .sidebar {
        max-height: 35vh;
    }

    .map-area {
        height: calc(100vh - 35vh);
    }

    #map,
    #languageMapL1,
    #languageMapL2 {
        height: 60vh;
    }
}

/* Language View Styles */
.language-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: white;
}

.language-container .browse-header {
    padding: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.language-container .browse-subtitle {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

#languageMap,
#languageMapL1,
#languageMapL2 {
    flex: 1;
    width: 100%;
    height: 100%;
}

.language-tooltip {
    position: fixed;
    top: 120px;
    left: 20px;
    background: rgba(29, 29, 31, 0.95);
    backdrop-filter: blur(20px);
    color: white;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10000;
    min-width: 320px;
    max-width: 400px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

@media (min-width: 1024px) {
    .language-tooltip {
        left: auto;
        right: calc(33.333% + 20px);
    }
}

.language-tooltip.show {
    opacity: 1;
}

.language-tooltip h4 {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 6px;
}

.language-tooltip .diversity-stat {
    margin: 6px 0;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
}

.language-tooltip .diversity-stat strong {
    color: #fbbf24;
}

.language-tooltip .lang-section {
    margin-top: 12px;
}

.language-tooltip .lang-section h5 {
    margin: 0 0 4px 0;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #9ca3af;
}

.language-tooltip .lang-list {
    margin: 0;
    padding-left: 16px;
    font-size: 11px;
    line-height: 1.6;
}

.language-tooltip .lang-list li {
    margin: 2px 0;
}

.language-tooltip .lang-name {
    font-weight: 500;
}

.language-tooltip .lang-pop {
    color: #9ca3af;
    font-size: 10px;
    margin-left: 4px;
}

/* Language Explanation Section */
.language-explanation {
    padding: 2rem;
    background: #f9fafb;
    border-top: 1px solid var(--border-color);
    overflow-y: auto;
    max-height: 400px;
}

.language-explanation h3 {
    margin: 0 0 1.5rem 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.language-explanation .explanation-section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: white;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.language-explanation .explanation-section:last-child {
    margin-bottom: 0;
}

.language-explanation h4 {
    margin: 0 0 0.75rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.language-explanation p {
    margin: 0.5rem 0;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.language-explanation ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.language-explanation li {
    margin: 0.25rem 0;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.language-explanation strong {
    color: var(--text-primary);
    font-weight: 600;
}

.language-explanation sub,
.language-explanation sup {
    font-size: 0.75em;
}

/* Make language container scrollable */
.language-container {
    overflow-y: auto;
}

/* Isolated tribes table row selection */
#isolatedTableBody tr.selected-row {
    background-color: #fef3c7 !important;
    border-left: 3px solid #f59e0b;
}

#isolatedTableBody tr.selected-row:hover {
    background-color: #fde68a !important;
}

/* District Details Table (appears when clicking districts in ST view) */
.district-details-container {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 2px solid #e5e7eb;
    box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
    max-height: 50vh;
    overflow-y: auto;
    z-index: 200;
}

.district-details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
    position: sticky;
    top: 0;
    z-index: 1;
}

.close-btn {
    font-size: 1.5rem;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    line-height: 1;
}

.close-btn:hover {
    color: #374151;
}

.district-details-table-wrapper {
    overflow-x: auto;
}

.district-details-table {
    width: 100%;
    border-collapse: collapse;
}

.district-details-table thead {
    background: #f3f4f6;
    position: sticky;
    top: 0;
}

.district-details-table th {
    font-weight: 600;
    border-bottom: 2px solid #d1d5db;
}

.district-details-table td {
    border-bottom: 1px solid #e5e7eb;
}

.district-details-table tbody tr:hover {
    background-color: #f9fafb !important;
}

/* Sortable headers for district details */
.district-details-table thead th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}

.district-details-table thead th.sortable:hover {
    color: #2563eb;
}

.district-details-table thead th.sortable .sort-icon {
    margin-left: 6px;
    font-size: 10px;
    opacity: 0.3;
}

.district-details-table thead th.sortable.active .sort-icon {
    opacity: 1;
    color: #2563eb;
}

.district-details-table thead th.sortable.active {
    color: #2563eb;
}

/* Mobile adjustments for district details */
@media (max-width: 768px) {
    .district-details-container {
        max-height: 60vh;
    }

    .district-details-header h3 {
        font-size: 0.875rem;
    }

    .district-details-table th,
    .district-details-table td {
        padding: 0.5rem !important;
        font-size: 0.75rem;
    }
}

/* State Map Legend */
.state-map-legend {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.95);
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 100;
    min-width: 180px;
}

.state-map-legend .legend-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 8px;
    text-align: center;
}

.state-map-legend .legend-gradient {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.state-map-legend .gradient-bar {
    height: 12px;
    border-radius: 4px;
    background: linear-gradient(90deg, #5e4fa2, #ffffbf, #9e0142);
}

.state-map-legend .legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: #6b7280;
}

@media (max-width: 768px) {
    .state-map-legend {
        bottom: 10px;
        right: 10px;
        padding: 8px 12px;
        min-width: 140px;
    }
}

/* Mobile Styles */
@media (max-width: 768px) {
    .state-st-container,
    .state-language-container {
        height: calc(100vh - 64px) !important;
        display: flex;
        flex-direction: column;
    }

    .state-selector-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
        padding: 12px !important;
    }

    .state-selector-bar label { font-size: 12px; }

    .state-selector-bar select {
        width: 100% !important;
        min-width: unset !important;
        padding: 12px !important;
        font-size: 16px !important;
        border-radius: 8px;
    }

    .state-selector-bar .flex.items-center.gap-2.ml-4 {
        margin-left: 0 !important;
        width: 100%;
    }

    .state-selector-bar .flex.rounded-md {
        width: 100%;
        display: flex;
    }

    .state-mode-btn {
        flex: 1;
        padding: 12px 8px !important;
        font-size: 14px !important;
    }

    #stateSTStats,
    #stateLanguageStats {
        margin-left: 0 !important;
        text-align: center;
        font-size: 12px;
        padding-top: 4px;
        border-top: 1px solid var(--border);
    }

    .state-map-section,
    .state-language-map-section {
        flex: 1;
        min-height: 300px;
    }

    #stateSTMap,
    #stateLanguageMap {
        width: 100%;
        height: 100%;
    }

    #stateSTTitle,
    #stateLanguageTitle {
        font-size: 14px !important;
        padding: 8px 12px;
    }

    #stateSTDetailsContainer,
    #stateLanguageDetailsContainer {
        max-height: 50vh;
        width: calc(100% - 20px);
        left: 10px;
        right: 10px;
        bottom: 60px;
    }

    .language-section { margin-bottom: 16px; }
    .language-section h4 { font-size: 12px; padding-bottom: 8px; }

    .grid.grid-cols-1.lg\\:grid-cols-\\[1fr_250px\\] {
        grid-template-columns: 1fr !important;
    }

    #controlsSidebar { display: none !important; }

    #mobileDrawer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 70vh;
        overflow-y: auto;
        z-index: 1000;
        transform: translateY(100%);
        transition: transform 0.3s ease-in-out;
        background: white;
        border-top-left-radius: 16px;
        border-top-right-radius: 16px;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }

    #mobileDrawer.open { transform: translateY(0); }

    .drawer-handle {
        width: 40px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
        margin: 12px auto;
    }

    #tribesSubTabs,
    #languagesSubTabs,
    #browseSubTabs,
    #isolatedSubTabs {
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px 12px;
    }

    .sub-tab-btn {
        padding: 8px 12px !important;
        font-size: 12px !important;
        flex: 1;
        min-width: 80px;
        text-align: center;
    }

    nav .text-xl { font-size: 16px !important; }

    #mobileTabSelect {
        font-size: 14px;
        padding: 8px 12px;
        max-width: 140px;
    }

    .tooltip,
    .language-tooltip {
        position: fixed !important;
        bottom: 20px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        top: auto !important;
        max-width: calc(100vw - 40px);
        z-index: 9999;
    }

    .map-title-container {
        position: relative;
        top: auto;
        left: auto;
        transform: none;
        padding: 8px 12px;
        text-align: center;
        background: rgba(255, 255, 255, 0.9);
    }

    .map-title { font-size: 12px; }

    .browse-table th,
    .browse-table td {
        padding: 8px 6px !important;
        font-size: 11px !important;
    }

    #isolatedView {
        display: flex;
        flex-direction: column;
        height: calc(100vh - 64px);
    }

    #isolatedView .map-section { flex: 1; min-height: 200px; }
    #isolatedView .isolated-table-section { max-height: 40vh; overflow-y: auto; }

    footer { padding: 8px 12px !important; font-size: 10px !important; }
    footer .text-blue-600 { font-size: 10px; }

    .district-label-group .district-name { font-size: 7px !important; font-weight: 600 !important; }
    .district-label-group .district-value { font-size: 6px !important; font-weight: 500 !important; }
}

@media (max-width: 480px) {
    .state-selector-bar { padding: 8px !important; gap: 8px !important; }
    .state-mode-btn { padding: 10px 6px !important; font-size: 12px !important; }
    .state-selector-bar .flex.items-center.gap-2.ml-4 > label { display: none; }

    .state-map-legend { padding: 6px 8px; min-width: 120px; }
    .state-map-legend .legend-title { font-size: 10px; }
    .state-map-legend .legend-labels { font-size: 9px; }

    nav h1 { font-size: 14px !important;
    }

    #mobileTabSelect {
        font-size: 12px;
        padding: 6px 8px;
        max-width: 120px;
    }

    #tribesSubTabs,
    #languagesSubTabs,
    #browseSubTabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .sub-tab-btn { flex: 0 0 auto; white-space: nowrap; }

    .district-label-group .district-name {
        font-size: 5px !important;
        font-weight: 700 !important;
    }

    .district-label-group .district-value {
        font-size: 4px !important;
        font-weight: 600 !important;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    .state-st-container,
    .state-language-container { height: calc(100vh - 56px) !important; }

    .state-selector-bar {
        flex-direction: row !important;
        flex-wrap: wrap;
        padding: 8px 12px !important;
    }

    .state-selector-bar select { width: auto !important; min-width: 150px !important; flex: 1; }
    .state-selector-bar .flex.items-center.gap-2.ml-4 { margin-left: auto !important; width: auto; }
    #stateSTStats,
    #stateLanguageStats { width: 100%; border-top: none; padding-top: 0; }
    nav .h-16 { height: 48px !important; }
}

@media (hover: none) and (pointer: coarse) {
    .tab-btn,
    .sub-tab-btn,
    button { min-height: 44px; }
    select { min-height: 44px; }
    .tab-btn:hover,
    .sub-tab-btn:hover { background: inherit; }
    .tab-btn.active,
    .sub-tab-btn.active { background: var(--accent); color: white; }
}
