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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f0f0f0;
    overflow: hidden;
}

/* ── Map ── */
#map {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ── Control Panel ── */
#panel {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 340px;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    padding: 20px;
    z-index: 10;
}

#panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 16px;
    cursor: pointer;
}

#panel.collapsed #panel-header {
    margin-bottom: 0;
}

#panel h1 {
    font-size: 17px;
    font-weight: 700;
    color: #1a1a2e;
    line-height: 1.2;
}

#panel .subtitle {
    font-size: 12px;
    color: #666;
    margin-top: 3px;
}

#panel-toggle {
    flex-shrink: 0;
    background: none;
    border: none;
    font-size: 16px;
    color: #999;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
    transition: transform 0.2s;
}

#panel-toggle:hover {
    color: #333;
    background: #f0f0f0;
}

#panel.collapsed #panel-toggle {
    transform: rotate(180deg);
}

#panel-body {
    transition: none;
}

#panel.collapsed #panel-body {
    display: none;
}

/* ── Controls ── */
.control-group {
    margin-bottom: 14px;
}

.control-group label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #555;
    margin-bottom: 5px;
}

/* HCPCS Search */
#ndc-search {
    position: relative;
}

#ndc-input {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    color: #333;
    outline: none;
    transition: border-color 0.15s;
}

#ndc-input:focus {
    border-color: #4a6cf7;
}

#ndc-input::placeholder {
    color: #aaa;
}

/* Dropdown */
.dropdown {
    position: fixed;
    max-height: 320px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 100;
}

.dropdown-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.1s;
}

.dropdown-section {
    padding: 6px 12px 3px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #8a8fa3;
    background: #f7f8fa;
    border-bottom: 1px solid #f0f0f0;
    position: sticky;
    top: 0;
}

.dropdown-item:hover,
.dropdown-item.active {
    background: #f0f4ff;
}

.dropdown-item .code {
    font-weight: 700;
    font-size: 13px;
    color: #1a1a2e;
    font-family: "SF Mono", "Consolas", "Monaco", monospace;
}

.dropdown-item .desc {
    font-size: 12px;
    color: #555;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dropdown-item .meta {
    font-size: 11px;
    color: #999;
    margin-top: 2px;
}

.dropdown-item.selected {
    opacity: 0.55;
}

.dropdown-item .check {
    color: #4a6cf7;
    font-size: 12px;
    font-weight: 400;
}

/* Selected HCPCS codes (chips) */
.selected-codes {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.code-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    background: #f0f4ff;
    border-radius: 5px;
    font-size: 12px;
    line-height: 1.3;
}

.code-chip-label {
    font-weight: 700;
    color: #4a6cf7;
    font-family: "SF Mono", "Consolas", "Monaco", monospace;
    flex-shrink: 0;
}

.code-chip-desc {
    color: #555;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.code-chip-remove {
    flex-shrink: 0;
    background: none;
    border: none;
    font-size: 16px;
    line-height: 1;
    color: #999;
    cursor: pointer;
    padding: 0 2px;
    border-radius: 3px;
}

.code-chip-remove:hover {
    color: #e33;
    background: rgba(227, 51, 51, 0.1);
}

/* Quarter select */
#quarter-select {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    color: #333;
    background: #fff;
    outline: none;
    cursor: pointer;
}

#quarter-select:focus {
    border-color: #4a6cf7;
}

/* ── Legend ── */
#legend {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid #eee;
}

.legend-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #555;
    margin-bottom: 8px;
}

.legend-bar {
    position: relative;
}

#legend-gradient {
    height: 14px;
    border-radius: 3px;
    border: 1px solid #ddd;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 3px;
    font-size: 11px;
    color: #777;
}

.legend-note {
    margin-top: 8px;
    font-size: 11px;
    color: #999;
    display: flex;
    align-items: center;
    gap: 5px;
}

.no-data-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    background: #e8e8e8;
    border: 1px solid #ccc;
    border-radius: 2px;
}

/* ── Tooltip ── */
#tooltip {
    position: absolute;
    pointer-events: none;
    background: rgba(26, 26, 46, 0.92);
    color: #fff;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.5;
    z-index: 20;
    max-width: 280px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

#tooltip .county-name {
    font-weight: 700;
    font-size: 14px;
}

#tooltip .county-state {
    color: #aab;
    font-size: 12px;
}

#tooltip .tooltip-value {
    margin-top: 4px;
    font-size: 15px;
    font-weight: 600;
    color: #7ecbff;
}

#tooltip .tooltip-label {
    font-size: 11px;
    color: #aab;
}

/* ── County detail card ── */
#county-detail {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    padding: 16px 20px 20px;
    z-index: 50;
    max-height: 45vh;
    overflow-y: auto;
    transition: transform 0.2s ease;
}

#county-detail.hidden {
    transform: translateY(100%);
    pointer-events: none;
}

#county-detail-close {
    position: absolute;
    top: 10px;
    right: 14px;
    background: none;
    border: none;
    font-size: 22px;
    color: #999;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
}

#county-detail-close:hover {
    color: #333;
    background: #f0f0f0;
}

#county-detail .detail-header {
    margin-bottom: 10px;
    padding-right: 28px;
}

#county-detail .detail-county {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a2e;
}

#county-detail .detail-state {
    font-size: 13px;
    color: #666;
}

#county-detail .detail-pop {
    font-size: 13px;
    color: #888;
    margin-top: 2px;
}

#county-detail .detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-top: 8px;
}

#county-detail .detail-table th {
    text-align: left;
    font-weight: 600;
    color: #666;
    padding: 6px 8px;
    border-bottom: 2px solid #e8e8e8;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

#county-detail .detail-table th:not(:first-child) {
    text-align: right;
}

#county-detail .detail-table td {
    padding: 6px 8px;
    border-bottom: 1px solid #f0f0f0;
    color: #333;
}

#county-detail .detail-table td:not(:first-child) {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

#county-detail .detail-table .code-col {
    font-weight: 600;
    color: #4a6cf7;
    font-family: "SF Mono", "Consolas", "Monaco", monospace;
    font-size: 12px;
}

#county-detail .detail-table .desc-col {
    color: #555;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#county-detail .detail-table tr.total-row td {
    border-top: 2px solid #ddd;
    border-bottom: none;
    font-weight: 700;
    color: #1a1a2e;
}

#county-detail .detail-no-data {
    color: #999;
    font-size: 13px;
    padding: 8px 0;
}

@media (min-width: 601px) {
    #county-detail {
        left: auto;
        right: 12px;
        bottom: 12px;
        max-width: 480px;
        border-radius: 12px;
        max-height: 50vh;
    }

    #county-detail.hidden {
        transform: translateY(calc(100% + 12px));
    }
}

/* ── Loading ── */
#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255,255,255,0.95);
    padding: 20px 32px;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: #555;
    z-index: 50;
}

.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid #ddd;
    border-top-color: #4a6cf7;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ── Attribution ── */
#attribution {
    position: absolute;
    bottom: 4px;
    right: 8px;
    font-size: 10px;
    color: #888;
    background: rgba(255,255,255,0.8);
    padding: 2px 6px;
    border-radius: 3px;
    z-index: 5;
}

#attribution a {
    color: #4a6cf7;
    text-decoration: none;
}

/* ── View toggle ── */
.view-toggle {
    display: flex;
    border: 1.5px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
}

.view-btn {
    flex: 1;
    padding: 7px 0;
    border: none;
    background: #fff;
    font-size: 13px;
    font-weight: 500;
    color: #666;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.view-btn:not(:last-child) {
    border-right: 1.5px solid #ddd;
}

.view-btn.active {
    background: #4a6cf7;
    color: #fff;
}

.view-btn:not(.active):hover {
    background: #f0f4ff;
}

/* ── Export button ── */
.export-btn {
    display: block;
    width: 100%;
    margin-top: 14px;
    padding: 10px 0;
    background: #4a6cf7;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

.export-btn:hover:not(:disabled) {
    background: #3a5ce5;
}

.export-btn:disabled {
    background: #ccc;
    color: #888;
    cursor: not-allowed;
}

/* ── No-data message ── */
#no-data-msg {
    margin-top: 16px;
    padding: 12px 14px;
    background: #faf8f0;
    border: 1px solid #e8e0c8;
    border-radius: 6px;
    font-size: 13px;
    color: #666;
    text-align: center;
    line-height: 1.4;
}

/* ── Methodology Overlay ── */
#methodology-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

#methodology-panel {
    position: relative;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    padding: 36px 40px;
    max-width: 720px;
    width: calc(100% - 40px);
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    line-height: 1.6;
    color: #333;
    font-size: 14px;
}

#methodology-panel h2 {
    font-size: 22px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid #e8e8e8;
}

#methodology-panel section {
    margin-bottom: 20px;
}

#methodology-panel h3 {
    font-size: 16px;
    font-weight: 600;
    color: #1a1a2e;
    margin-bottom: 8px;
}

#methodology-panel h4 {
    font-size: 14px;
    font-weight: 600;
    color: #444;
    margin-top: 12px;
    margin-bottom: 6px;
}

#methodology-panel p {
    margin-bottom: 10px;
}

#methodology-panel ol,
#methodology-panel ul {
    margin: 8px 0 12px 24px;
}

#methodology-panel li {
    margin-bottom: 6px;
}

#methodology-panel a {
    color: #4a6cf7;
    text-decoration: none;
}

#methodology-panel a:hover {
    text-decoration: underline;
}

#methodology-panel code {
    background: #f0f0f0;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 13px;
    font-family: "SF Mono", "Consolas", "Monaco", monospace;
}

#methodology-panel .formula {
    background: #f0f4ff;
    border-left: 3px solid #4a6cf7;
    padding: 10px 14px;
    margin: 10px 0;
    font-style: italic;
    border-radius: 0 6px 6px 0;
}

.methodology-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
}

.methodology-table th,
.methodology-table td {
    border: 1px solid #e0e0e0;
    padding: 8px 10px;
    text-align: left;
    vertical-align: top;
}

.methodology-table th {
    background: #f5f7fa;
    font-weight: 600;
    white-space: nowrap;
}

.methodology-table td:nth-child(2) {
    text-align: center;
    white-space: nowrap;
}

.methodology-footer {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #e8e8e8;
    font-size: 13px;
    color: #777;
    text-align: center;
}

.methodology-footer a {
    color: #4a6cf7;
    text-decoration: none;
}

.methodology-footer a:hover {
    text-decoration: underline;
}

#methodology-close {
    position: sticky;
    top: 0;
    float: right;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    font-size: 28px;
    color: #999;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 4px;
    z-index: 1;
}

#methodology-close:hover {
    color: #333;
    background: #f0f0f0;
}

#methodology-link {
    color: #4a6cf7;
    text-decoration: none;
    cursor: pointer;
}

#methodology-link:hover {
    text-decoration: underline;
}

/* ── Utility ── */
.hidden {
    display: none !important;
}

/* ── Responsive ── */
@media (max-width: 600px) {
    #panel {
        width: calc(100% - 24px);
        max-height: 50vh;
    }

    #methodology-panel {
        padding: 24px 20px;
        width: calc(100% - 20px);
        max-height: calc(100vh - 16px);
        max-height: calc(100dvh - 16px);
        border-radius: 8px;
    }
}
