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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #2c3e50;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.03);
    overflow: visible;
}

.header {
    background: linear-gradient(135deg, #5a67d8 0%, #667eea 50%, #764ba2 100%);
    color: white;
    padding: 50px 40px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -10%;
    width: 400px;
    height: 400px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
}

.header h1 {
    font-size: 2.8em;
    margin-bottom: 12px;
    font-weight: 700;
    letter-spacing: -0.5px;
    position: relative;
    z-index: 1;
}

.header p {
    font-size: 1.05em;
    opacity: 0.92;
    font-weight: 400;
    position: relative;
    z-index: 1;
    letter-spacing: 0.3px;
}

.content {
    padding: 50px;
    overflow: visible;
}

.controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
    background: linear-gradient(135deg, #f8f9fb 0%, #f0f3f7 100%);
    padding: 35px;
    border-radius: 12px;
    border: 1px solid rgba(102, 126, 234, 0.1);
    overflow: visible;
}

.control-group {
    display: flex;
    flex-direction: column;
    overflow: visible;
}

label {
    font-weight: 600;
    margin-bottom: 10px;
    color: #2c3e50;
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

select, input {
    padding: 12px 14px;
    border: 1px solid #d1d8e0;
    border-radius: 8px;
    font-size: 0.95em;
    transition: all 0.2s ease;
    background-color: white;
    color: #2c3e50;
    font-weight: 500;
}

select:hover, input:hover {
    border-color: #667eea;
    background-color: #fafbfc;
}

select:focus, input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.12);
    background-color: white;
}

/* Multiselect Typeahead Styles */
.typeahead-container {
    position: relative;
    width: 100%;
    overflow: visible;
}

.typeahead-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    border: 1px solid #d1d8e0;
    border-radius: 8px;
    background-color: white;
    min-height: 46px;
    cursor: text;
    transition: all 0.2s ease;
}

.typeahead-tags:hover {
    border-color: #667eea;
    background-color: #fafbfc;
}

.typeahead-tags.focused {
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.12);
    background-color: white;
}

.typeahead-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 6px;
    font-size: 0.85em;
    font-weight: 500;
}

.typeahead-tag-remove {
    cursor: pointer;
    font-size: 1.1em;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.typeahead-tag-remove:hover {
    opacity: 1;
}

.typeahead-input {
    flex: 1;
    min-width: 150px;
    border: none;
    outline: none;
    padding: 4px;
    font-size: 0.95em;
    background: transparent;
}

.typeahead-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 300px;
    overflow-y: auto;
    background: white;
    border: 1px solid #d1d8e0;
    border-radius: 8px;
    margin-top: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: none;
}

.typeahead-dropdown.show {
    display: block;
}

.typeahead-group-label {
    padding: 8px 12px;
    font-weight: 700;
    font-size: 0.8em;
    color: #667eea;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #f8f9fb;
    border-bottom: 1px solid #e2e8f0;
}

.typeahead-option {
    padding: 10px 12px;
    cursor: pointer;
    transition: background-color 0.15s;
    font-size: 0.9em;
}

.typeahead-option:hover {
    background-color: #f0f3f7;
}

.typeahead-option.selected {
    background-color: #e3f2fd;
    color: #667eea;
    font-weight: 600;
}

.typeahead-option.highlighted {
    background-color: #667eea;
    color: white;
}

.typeahead-option.special {
    font-weight: bold;
    background: #e3f2fd;
}

.button-group {
    display: flex;
    gap: 12px;
    grid-column: 1 / -1;
    justify-content: center;
    margin-top: 15px;
}

button {
    padding: 12px 32px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.25);
    letter-spacing: 0.3px;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.35);
}

button:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.status {
    margin: 24px 0;
    padding: 16px 20px;
    border-radius: 8px;
    text-align: center;
    font-weight: 500;
    display: none;
    border-left: 4px solid;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.status.loading {
    background: #e3f2fd;
    color: #1565c0;
    display: block;
    border-left-color: #1565c0;
}

.status.success {
    background: #e8f5e9;
    color: #2e7d32;
    display: block;
    border-left-color: #2e7d32;
}

.status.error {
    background: #ffebee;
    color: #c62828;
    display: block;
    border-left-color: #c62828;
}

#chartSection {
    display: none;
}

.chart-container {
    background: linear-gradient(135deg, #f8f9fb 0%, #f0f3f7 100%);
    padding: 35px;
    border-radius: 12px;
    margin-top: 40px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(102, 126, 234, 0.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
}

.chart-title {
    text-align: center;
    font-size: 1.6em;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 28px;
    letter-spacing: -0.3px;
}

#pieChart {
    width: 100% !important;
    height: 500px;
    flex: 1;
}

#pieChart > div {
    width: 100% !important;
    height: 100% !important;
}

.svg-container {
    width: 100% !important;
}

.data-info {
    background: linear-gradient(135deg, #eef2ff 0%, #f0f4ff 100%);
    padding: 24px;
    border-radius: 8px;
    margin-top: 24px;
    border-left: 4px solid #667eea;
    border: 1px solid rgba(102, 126, 234, 0.15);
}

.data-info h3 {
    color: #2c3e50;
    margin-bottom: 12px;
    font-size: 1.05em;
    font-weight: 600;
}

.data-info p {
    color: #555;
    line-height: 1.7;
    margin: 8px 0;
    font-size: 0.95em;
}

.error-box {
    background: linear-gradient(135deg, #ffe8e8 0%, #ffebee 100%);
    padding: 24px;
    border-radius: 8px;
    color: #c62828;
    margin-top: 24px;
    border-left: 4px solid #c62828;
    border: 1px solid rgba(198, 40, 40, 0.15);
    font-weight: 500;
}

@media (max-width: 768px) {
    .content {
        padding: 30px;
    }

    .controls {
        grid-template-columns: 1fr;
        padding: 25px;
        gap: 18px;
    }

    .header {
        padding: 35px 25px;
    }

    .header h1 {
        font-size: 2em;
    }

    .header p {
        font-size: 0.95em;
    }

    #pieChart {
        height: 400px;
    }

    .chart-container {
        padding: 25px;
    }

    .chart-title {
        font-size: 1.3em;
        margin-bottom: 20px;
    }
}

/* Small Multiples Grid */
.small-multiples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    width: 100%;
    padding: 20px;
}

.small-multiple-chart {
    background: linear-gradient(135deg, #f8f9fb 0%, #f0f3f7 100%);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid rgba(102, 126, 234, 0.1);
    height: 350px;
}

.small-multiple-title {
    font-weight: bold;
    text-align: center;
    margin-bottom: 10px;
    color: #333;
}

@media (max-width: 768px) {
    .small-multiples-grid {
        grid-template-columns: 1fr;
    }

    .small-multiple-chart {
        height: 300px;
    }
}

/* Chart Type Buttons */
.chart-type-btn {
    padding: 10px 16px;
    font-size: 0.9em;
    border-radius: 6px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.chart-type-btn:hover {
    background: #f0f4ff;
    transform: translateY(-1px);
}

.chart-type-btn.active {
    background: #667eea;
    color: white;
}

/* Chart Options Controls */
.chart-options-control {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    align-items: center;
    flex-wrap: wrap;
}

.chart-options-control label {
    font-weight: 600;
    color: #333;
    min-width: 120px;
}

.control-button {
    padding: 8px 16px;
    font-size: 0.9em;
    border-radius: 4px;
    border: 1px solid #ccc;
    background: white;
    color: #333;
    cursor: pointer;
    transition: all 0.2s;
}

.control-button:hover {
    background: #f8f9fa;
    border-color: #999;
}

.control-button.active {
    border-color: #667eea;
    background: #667eea;
    color: white;
}

.control-select {
    padding: 8px 12px;
    border-radius: 4px;
    border: 1px solid #ccc;
    font-size: 0.9em;
    cursor: pointer;
}

.control-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Control Errors */
.controls-error {
    display: none;
    grid-column: 1 / -1;
    background: #ffebee;
    padding: 15px;
    border-radius: 6px;
    color: #c62828;
    border-left: 4px solid #c62828;
    margin-top: 10px;
}

/* Chart Section */
#chartSection {
    display: none;
}

/* Chart Type Controls Container */
.chart-type-controls-container {
    margin-bottom: 20px;
}

.chart-type-label {
    font-weight: 600;
    color: #333;
    display: block;
    margin-bottom: 12px;
}

.chart-type-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Chart Options Section */
.chart-options-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid #e0e0e0;
}

.chart-options-header {
    margin: 0 0 15px 0;
    color: #333;
    font-size: 1.1em;
    border-bottom: 2px solid #667eea;
    padding-bottom: 8px;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chart-options-toggle {
    font-size: 0.8em;
    transition: transform 0.3s;
}

/* Chart Options Content */
#chartOptionsContent {
    /* No default styles needed, controlled by JavaScript */
}

/* Control Groups */
.chart-options-control-group {
    display: none;
    gap: 15px;
    margin-bottom: 15px;
    align-items: center;
    flex-wrap: wrap;
}

.chart-options-control-group label:first-child {
    font-weight: 600;
    color: #333;
    min-width: 120px;
}

.chart-options-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Specific control group modifiers */
#stackOrderControls,
#groupingModeControls,
#multiSplitGroupingControls,
#jurisdictionOrderControls,
#cumulativeLevelControls,
#discreteLevelControls,
#cumulativeBarLevelControls,
#mapStatControls,
#heatMapMetricControls,
#differenceBarMetricControls,
#differenceBarOrientationControls,
#barOrientationControls,
#barZeroPointControls {
    /* All inherit from .chart-options-control-group */
}

#policyChangesControls {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    align-items: center;
    flex-wrap: wrap;
}

/* Policy Info */
.policy-info {
    display: none;
    margin-top: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.policy-info h3 {
    color: #333;
    margin-top: 0;
}

.policy-info > p {
    color: #666;
    font-size: 0.9em;
    margin-bottom: 15px;
}

/* Data Info */
.data-info {
    display: none;
}

.data-info h3 {
    margin-bottom: 15px;
}

.data-info p {
    margin-bottom: 8px;
}

.data-info #docId {
    font-family: monospace;
    font-size: 0.9em;
}

/* Excluded Data Note */
#excludedDataNote {
    display: none;
    margin-top: 15px;
    padding: 12px;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 4px;
    color: #856404;
    font-size: 0.9em;
}

/* Error Box */
.error-box {
    display: none;
}

/* ==================== SORTABLE TABLE STYLES ==================== */
.sortable-table-container {
    margin: 20px 0;
    padding: 20px;
    background: white;
    border-radius: 8px;
    overflow-x: auto;
}

.sortable-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

.sortable-table thead tr {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-align: left;
    font-weight: 600;
}

.sortable-table th,
.sortable-table td {
    padding: 14px 18px;
    border-bottom: 1px solid #e2e8f0;
}

.sortable-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
    position: relative;
}

.sortable-table th.sortable:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sortable-table tbody tr {
    transition: background 0.2s;
}

.sortable-table tbody tr:nth-of-type(even) {
    background: #f8f9fa;
}

.sortable-table tbody tr:hover {
    background: #e8ecf1;
}

.sortable-table td {
    text-align: center;
}

.sortable-table td.row-label {
    text-align: left;
    font-weight: 500;
    color: #2d3748;
    background: #f7fafc;
}

.sortable-table th.rank-column {
    width: 40px;
    min-width: 40px;
    text-align: center;
    padding: 14px 8px;
}

.sortable-table td.rank-cell {
    color: #a0aec0;
    font-weight: 500;
    font-size: 0.85em;
    text-align: center;
    width: 40px;
    min-width: 40px;
    padding: 14px 8px;
    background: #f7fafc;
}

.sortable-table td.suppressed {
    color: #a0aec0;
    font-style: italic;
}

.sortable-table tbody tr:last-of-type td {
    border-bottom: none;
}

/* Urban Institute Info Button and Overlay */
.urban-info-btn {
    display: none;
    width: 20px;
    height: 20px;
    padding: 0;
    margin-left: 8px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    line-height: 20px;
    text-align: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.urban-info-btn:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.urban-info-btn.visible {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.metric-label-row {
    display: flex;
    align-items: center;
}

/* Urban Institute Info Overlay */
.urban-info-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.urban-info-overlay.visible {
    display: flex;
}

.urban-info-content {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    margin: 20px;
    animation: slideUp 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.urban-info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 28px;
    border-bottom: 1px solid #e2e8f0;
    background: linear-gradient(135deg, #f8f9fb 0%, #f0f3f7 100%);
    border-radius: 16px 16px 0 0;
}

.urban-info-header h3 {
    margin: 0;
    font-size: 1.2em;
    color: #2c3e50;
    font-weight: 600;
}

.urban-info-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #718096;
    padding: 0;
    width: 32px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    border-radius: 8px;
    transition: all 0.2s;
}

.urban-info-close:hover {
    background: #edf2f7;
    color: #2d3748;
}

.urban-info-body {
    padding: 28px;
}

.urban-info-body h4 {
    color: #2c3e50;
    font-size: 1em;
    font-weight: 600;
    margin: 20px 0 12px 0;
}

.urban-info-body h4:first-child {
    margin-top: 0;
}

.urban-info-body p {
    color: #4a5568;
    line-height: 1.7;
    margin-bottom: 12px;
    font-size: 0.95em;
}

.urban-info-body ul {
    margin: 12px 0;
    padding-left: 24px;
    color: #4a5568;
}

.urban-info-body li {
    margin-bottom: 8px;
    line-height: 1.6;
    font-size: 0.95em;
}

.urban-info-body a {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
}

.urban-info-body a:hover {
    text-decoration: underline;
}

.urban-info-source {
    margin-top: 20px;
    padding: 16px;
    background: linear-gradient(135deg, #eef2ff 0%, #f0f4ff 100%);
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.urban-info-source p {
    margin: 0;
    font-size: 0.9em;
    color: #4a5568;
}
