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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    display: flex;
    height: 100vh;
    overflow: hidden;
    background: #1a1a2e;
    color: #e0e0e0;
}

#sidebar {
    width: 340px;
    min-width: 200px;
    max-width: 60vw;
    height: 100vh;
    overflow-y: auto;
    scrollbar-width: none; /* Firefox */
    background: #16213e;
    padding: 20px;
    border-right: none;
    z-index: 1000;
}

#sidebar::-webkit-scrollbar {
    display: none; /* Chrome, Safari */
}

/* Resize handle between sidebar and map */
#resize-handle {
    width: 6px;
    height: 100vh;
    background: #0f3460;
    cursor: col-resize;
    flex-shrink: 0;
    transition: background 0.2s;
    z-index: 1001;
}

#resize-handle:hover,
#resize-handle.active {
    background: #e94560;
}

#sidebar h1 {
    font-size: 1.5em;
    color: #e94560;
    margin-bottom: 2px;
}

.subtitle {
    font-size: 0.8em;
    color: #888;
    margin-bottom: 16px;
}

#map {
    flex: 1;
    height: 100vh;
}

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

.control-group > label {
    display: block;
    font-size: 0.8em;
    font-weight: 600;
    color: #a0a0c0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

/* Toggle buttons */
.toggle-group {
    display: flex;
    gap: 0;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #0f3460;
}

.toggle-btn {
    flex: 1;
    padding: 8px;
    border: none;
    background: #1a1a2e;
    color: #888;
    cursor: pointer;
    font-size: 0.85em;
    transition: all 0.2s;
}

.toggle-btn.active {
    background: #e94560;
    color: white;
    font-weight: 600;
}

.toggle-btn:hover:not(.active) {
    background: #253554;
}

/* Month grid */
.month-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}

.month-btn {
    padding: 6px 4px;
    border: 1px solid #0f3460;
    border-radius: 4px;
    background: #1a1a2e;
    color: #aaa;
    cursor: pointer;
    font-size: 0.8em;
    transition: all 0.2s;
}

.month-btn.active {
    background: #e94560;
    color: white;
    border-color: #e94560;
    font-weight: 600;
}

.month-btn:hover:not(.active) {
    background: #253554;
    border-color: #4a6fa5;
}

/* Select */
select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #0f3460;
    border-radius: 6px;
    background: #1a1a2e;
    color: #e0e0e0;
    font-size: 0.9em;
    cursor: pointer;
}

select optgroup {
    color: #e94560;
    font-weight: 600;
}

select option {
    color: #e0e0e0;
    background: #1a1a2e;
}

/* Composite panel */
.preset-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-bottom: 12px;
}

.preset-btn {
    padding: 6px 8px;
    border: 1px solid #0f3460;
    border-radius: 4px;
    background: #1a1a2e;
    color: #aaa;
    cursor: pointer;
    font-size: 0.75em;
    transition: all 0.2s;
}

.preset-btn.active {
    background: #533483;
    color: white;
    border-color: #533483;
}

.preset-btn:hover:not(.active) {
    background: #253554;
}

/* Sliders */
.composite-sliders {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.slider-label {
    font-size: 0.75em;
    color: #aaa;
    width: 110px;
    min-width: 110px;
}

.comp-slider {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: #0f3460;
    border-radius: 2px;
    outline: none;
}

.comp-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #e94560;
    cursor: pointer;
}

.comp-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #e94560;
    cursor: pointer;
    border: none;
}

.slider-value {
    font-size: 0.75em;
    color: #888;
    width: 24px;
    text-align: right;
}

.slider-info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #0f3460;
    color: #888;
    font-size: 0.7em;
    font-style: normal;
    cursor: help;
    position: relative;
    vertical-align: middle;
    margin-left: 2px;
    flex-shrink: 0;
}

.slider-info:hover {
    background: #e94560;
    color: #fff;
}

.slider-info::after {
    content: attr(data-tip);
    position: absolute;
    left: 0;
    bottom: calc(100% + 8px);
    background: #16213e;
    color: #e0e0e0;
    border: 1px solid #0f3460;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 11px;
    line-height: 1.4;
    width: 220px;
    white-space: normal;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 100;
}

.slider-info:hover::after {
    opacity: 1;
}

.slider-direction {
    font-size: 0.75em;
    font-weight: bold;
    width: 14px;
    text-align: center;
    color: #4ecca3;
}

.slider-direction.invert {
    color: #e94560;
}

.composite-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.composite-save-btn {
    padding: 5px 12px;
    background: #0f3460;
    color: #e0e0e0;
    border: 1px solid #1a4a8a;
    border-radius: 6px;
    font-size: 0.75em;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.composite-save-btn:hover {
    background: #1a4a8a;
    border-color: #4ecca3;
}

.save-feedback {
    font-size: 0.72em;
    color: #4ecca3;
    opacity: 0;
    transition: opacity 0.3s;
}

.save-feedback.show {
    opacity: 1;
}

/* Ranking */
#ranking {
    margin-top: 12px;
    border-top: 1px solid #0f3460;
    padding-top: 10px;
    container-type: inline-size;
}

.ranking-columns {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

@container (min-width: 480px) {
    .ranking-columns {
        flex-direction: row;
        gap: 16px;
    }
    .ranking-col {
        flex: 1;
        min-width: 0;
    }
}

#ranking h3 {
    font-size: 0.85em;
    color: #a0a0c0;
    margin-bottom: 6px;
}

#ranking-list-cities,
#ranking-list-depts {
    font-size: 0.8em;
    padding-left: 20px;
    max-height: 160px;
    overflow-y: auto;
    scrollbar-width: none;
}

#ranking-list-cities::-webkit-scrollbar,
#ranking-list-depts::-webkit-scrollbar {
    display: none;
}


#ranking-list-cities li,
#ranking-list-depts li {
    padding: 2px 0;
    color: #ccc;
}

#ranking-list-cities li .rank-score,
#ranking-list-depts li .rank-score {
    float: right;
    color: #4ecca3;
    font-weight: 600;
}

#ranking-list-cities li:nth-child(-n+3),
#ranking-list-depts li:nth-child(-n+3) {
    color: #ffd700;
    font-weight: 600;
}

/* Info panel */
#info-panel {
    margin-top: 16px;
    padding: 12px;
    background: #1a1a2e;
    border-radius: 8px;
    border: 1px solid #0f3460;
}

#info-panel h3 {
    font-size: 1em;
    color: #e94560;
    margin-bottom: 8px;
}

#info-content {
    font-size: 0.82em;
    line-height: 1.6;
}

#info-content .info-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

#info-content .info-label {
    color: #888;
}

#info-content .info-value {
    color: #e0e0e0;
    font-weight: 600;
}

#info-content .info-value.highlight {
    color: #4ecca3;
}

/* Chart panel */
#chart-panel {
    margin-top: 12px;
    padding: 12px;
    background: #1a1a2e;
    border-radius: 8px;
    border: 1px solid #0f3460;
}

#chart-panel h3 {
    font-size: 0.85em;
    color: #a0a0c0;
    margin-bottom: 8px;
}

.chart-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 8px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #0f3460;
}

.chart-tab {
    flex: 1;
    padding: 5px 8px;
    border: none;
    background: #1a1a2e;
    color: #888;
    cursor: pointer;
    font-size: 0.75em;
    transition: all 0.2s;
}

.chart-tab.active {
    background: #e94560;
    color: white;
    font-weight: 600;
}

.chart-tab:hover:not(.active) {
    background: #253554;
}

#month-chart {
    width: 100% !important;
    max-height: 180px;
}

/* Station panel */
#station-panel {
    margin-top: 12px;
    padding: 10px;
    background: #1a1a2e;
    border-radius: 8px;
    border: 1px solid #0f3460;
}

#station-panel h3 {
    font-size: 0.85em;
    color: #a0a0c0;
    margin-bottom: 6px;
}

#station-list {
    font-size: 0.75em;
    max-height: 150px;
    overflow-y: auto;
    scrollbar-width: none;
}

#station-list::-webkit-scrollbar {
    display: none;
}

.station-item {
    padding: 4px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    color: #aaa;
    cursor: pointer;
}

.station-item:hover {
    color: #4ecca3;
}

/* Leaflet overrides */
.leaflet-container {
    background: #1a1a2e;
}

.leaflet-zoom-box {
    border: none !important;
    background: none !important;
}

.leaflet-interactive:focus {
    outline: none !important;
}

.leaflet-container svg:focus,
.leaflet-container path:focus {
    outline: none !important;
}

.info.legend {
    background: rgba(22, 33, 62, 0.95);
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid #0f3460;
    color: #e0e0e0;
    font-size: 0.8em;
    line-height: 1.6;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.info.legend h4 {
    margin-bottom: 6px;
    color: #e94560;
    font-size: 0.95em;
}

.info.legend i {
    width: 18px;
    height: 12px;
    display: inline-block;
    margin-right: 6px;
    border-radius: 2px;
    vertical-align: middle;
}

.dept-tooltip {
    background: rgba(22, 33, 62, 0.95) !important;
    color: #e0e0e0 !important;
    border: 1px solid #0f3460 !important;
    border-radius: 6px !important;
    padding: 8px 12px !important;
    font-size: 0.85em !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
}

.dept-tooltip .tippy-arrow { display: none; }

.dept-tooltip .tooltip-name {
    font-weight: 700;
    color: #e94560;
    margin-bottom: 2px;
}

.dept-tooltip .tooltip-value {
    color: #4ecca3;
    font-weight: 600;
}

/* City tooltip */
.city-tooltip {
    background: rgba(22, 33, 62, 0.95) !important;
    color: #ffd700 !important;
    border: 1px solid #ffd700 !important;
    border-radius: 4px !important;
    padding: 4px 8px !important;
    font-size: 0.8em !important;
    font-weight: 600 !important;
}

/* City popup */
.city-popup .leaflet-popup-content-wrapper {
    background: rgba(22, 33, 62, 0.98);
    color: #e0e0e0;
    border-radius: 8px;
    border: 1px solid #0f3460;
}

.city-popup .leaflet-popup-tip {
    background: rgba(22, 33, 62, 0.98);
}

.city-popup .leaflet-popup-close-button {
    color: #888 !important;
}

/* Loading overlay */
#loading {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(26, 26, 46, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    font-size: 1.2em;
    color: #e94560;
}

/* Compare select panel (floating, non-blocking) */
#compare-select-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 320px;
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 12px;
    padding: 14px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    z-index: 2500;
}

#compare-select-panel .compare-header {
    margin-bottom: 4px;
}

#compare-search {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #253554;
    border-radius: 8px;
    background: #1a1a2e;
    color: #e0e0e0;
    font-size: 0.85em;
    margin-bottom: 6px;
    outline: none;
    box-sizing: border-box;
}

#compare-search:focus {
    border-color: #4a6fa5;
}

#compare-search-results {
    max-height: 150px;
    overflow-y: auto;
    scrollbar-width: thin;
    margin-bottom: 8px;
}

#compare-selected-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.compare-search-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    color: #ccc;
    font-size: 0.85em;
    transition: background 0.15s;
}

.compare-search-item:hover {
    background: #253554;
}

.compare-search-item.selected {
    background: #253554;
    border-left: 3px solid #4ecca3;
}

/* Compare modal */
#compare-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.compare-modal-content {
    background: #16213e;
    border-radius: 12px;
    border: 1px solid #0f3460;
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    overflow-y: auto;
    scrollbar-width: none;
    padding: 20px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.compare-modal-content::-webkit-scrollbar {
    display: none;
}

.compare-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.compare-header h3 {
    color: #e94560;
    font-size: 1.1em;
    margin: 0;
}

.compare-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82em;
}

.compare-table th {
    padding: 6px 8px;
    text-align: center;
    border-bottom: 2px solid #0f3460;
    font-weight: 700;
    position: relative;
}

.compare-table td {
    padding: 5px 8px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: #ccc;
}

.compare-table .compare-label {
    text-align: left;
    color: #888;
    font-weight: 600;
}

.compare-table .compare-best {
    color: #4ecca3;
    font-weight: 700;
}

.compare-remove {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 0.8em;
    margin-left: 4px;
}

.compare-remove:hover {
    color: #e94560;
}

/* Compare badges on map */
.compare-badge span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

#compare-map-clear {
    position: absolute;
    bottom: 20px;
    left: 10px;
    z-index: 1000;
    background: #16213e;
    color: #e94560;
    border: 1px solid #e94560;
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 0.8em;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    transition: background 0.2s;
}

#compare-map-clear:hover {
    background: #e94560;
    color: #fff;
}

/* Chat sidebar button */
#chat-sidebar-btn {
    margin-bottom: 16px;
}

#chat-sidebar-btn.hidden {
    display: none;
}

#chat-toggle {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e94560;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(233, 69, 96, 0.15), rgba(233, 69, 96, 0.05));
    color: #e94560;
    font-size: 0.95em;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

#chat-toggle:hover {
    background: linear-gradient(135deg, rgba(233, 69, 96, 0.3), rgba(233, 69, 96, 0.1));
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(233, 69, 96, 0.3);
}

.chat-icon {
    font-size: 1.1em;
}

.chat-btn-hint {
    font-size: 0.7em;
    color: #888;
    text-align: center;
    margin-top: 4px;
}

/* Pro badge */
.pro-badge {
    background: #4ecca3;
    color: #0a0f1e;
    font-size: 0.6em;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 4px;
    letter-spacing: 0.5px;
    vertical-align: middle;
}

/* Ranking upgrade link */
.ranking-upgrade {
    list-style: none;
    margin-top: 4px;
}
.ranking-upgrade a {
    color: #e94560;
    font-size: 0.75em;
    text-decoration: none;
}
.ranking-upgrade a:hover {
    text-decoration: underline;
}

/* Upgrade modal */
#upgrade-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4000;
}

.upgrade-modal-content {
    background: #16213e;
    border-radius: 16px;
    border: 1px solid #0f3460;
    padding: 32px;
    max-width: 520px;
    width: 90%;
    position: relative;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
    text-align: center;
}

.upgrade-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: #888;
    font-size: 1.2em;
    cursor: pointer;
}
.upgrade-close:hover { color: #e0e0e0; }

.upgrade-title {
    margin: 0 0 4px;
    color: #e0e0e0;
    font-size: 1.4em;
}

.upgrade-subtitle {
    color: #888;
    margin: 0 0 20px;
    font-size: 0.85em;
}

.pricing-cards {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 20px;
}

.pricing-card {
    background: #0a0f1e;
    border: 1px solid #0f3460;
    border-radius: 12px;
    padding: 20px;
    flex: 1;
    max-width: 200px;
    position: relative;
}

.pricing-card.featured {
    border-color: #e94560;
}

.pricing-card h3 {
    margin: 0 0 8px;
    color: #aaa;
    font-size: 0.85em;
    font-weight: 400;
}

.pricing-price {
    font-size: 2em;
    font-weight: 700;
    color: #e0e0e0;
    margin-bottom: 4px;
}

.pricing-price span {
    font-size: 0.4em;
    color: #888;
    font-weight: 400;
}

.pricing-detail {
    font-size: 0.72em;
    color: #4ecca3;
    margin: 0 0 8px;
}

.pricing-badge {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #e94560;
    color: #fff;
    font-size: 0.65em;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 10px;
}

.pricing-btn {
    width: 100%;
    padding: 8px 0;
    border: none;
    border-radius: 8px;
    background: #e94560;
    color: #fff;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 8px;
}

.pricing-btn:hover {
    background: #d63851;
}

.pro-features-list {
    text-align: left;
    list-style: none;
    padding: 0;
    margin: 0;
}

.pro-features-list li {
    padding: 4px 0;
    color: #aaa;
    font-size: 0.8em;
}

.pro-features-list li::before {
    content: "✓ ";
    color: #4ecca3;
    font-weight: 700;
}

/* Pro toast */
.pro-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: #4ecca3;
    color: #0a0f1e;
    padding: 10px 24px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9em;
    z-index: 5000;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}

.pro-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Chat panel */
#chat-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    height: 520px;
    min-width: 300px;
    min-height: 350px;
    max-width: 90vw;
    max-height: 90vh;
    z-index: 2001;
    background: #16213e;
    border-radius: 12px;
    border: 1px solid #0f3460;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

/* Chat resize handle (top-left corner) */
.chat-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 16px;
    height: 16px;
    cursor: nw-resize;
    z-index: 10;
}

.chat-resize-handle::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 8px;
    height: 8px;
    border-top: 2px solid #888;
    border-left: 2px solid #888;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.chat-resize-handle:hover::after {
    opacity: 1;
    border-color: #e94560;
}

#chat-panel.open {
    display: flex;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #0f3460;
    color: #e94560;
    font-weight: 700;
    font-size: 0.9em;
}

.chat-header-btn {
    background: none;
    border: none;
    color: #aaa;
    font-size: 1.1em;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}

.chat-header-btn:hover {
    color: #e94560;
    background: rgba(255, 255, 255, 0.1);
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: none;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-messages::-webkit-scrollbar {
    display: none;
}

.chat-msg {
    display: flex;
}

.chat-msg.user {
    justify-content: flex-end;
}

.msg-bubble {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.82em;
    line-height: 1.5;
    word-wrap: break-word;
}

.msg-bubble.bot {
    background: #1a1a2e;
    color: #e0e0e0;
    border-bottom-left-radius: 4px;
}

.msg-bubble.user {
    background: #e94560;
    color: white;
    border-bottom-right-radius: 4px;
}

/* Typing animation */
.msg-bubble.typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.msg-bubble.typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #888;
    animation: typing-bounce 1.2s infinite;
}

.msg-bubble.typing span:nth-child(2) { animation-delay: 0.2s; }
.msg-bubble.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Weight tags */
.weight-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.weight-tag {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.weight-tag.tag-positive {
    background: rgba(78, 204, 163, 0.2);
    color: #4ecca3;
    border: 1px solid rgba(78, 204, 163, 0.3);
}

.weight-tag.tag-negative {
    background: rgba(233, 69, 96, 0.2);
    color: #e94560;
    border: 1px solid rgba(233, 69, 96, 0.3);
}

.weight-tag:hover {
    transform: scale(1.05);
    filter: brightness(1.2);
}

.apply-weights-btn {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 6px 12px;
    border: 1px solid #4ecca3;
    border-radius: 6px;
    background: rgba(78, 204, 163, 0.15);
    color: #4ecca3;
    font-size: 0.78em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.apply-weights-btn:hover {
    background: rgba(78, 204, 163, 0.3);
}

/* Suggestions */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 0 12px 8px;
}

.suggestion-btn {
    padding: 4px 10px;
    border: 1px solid #0f3460;
    border-radius: 12px;
    background: #1a1a2e;
    color: #aaa;
    font-size: 0.72em;
    cursor: pointer;
    transition: all 0.2s;
}

.suggestion-btn:hover {
    background: #253554;
    color: #e0e0e0;
    border-color: #4a6fa5;
}

/* Chat input */
.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid #0f3460;
    background: #0f3460;
}

.chat-input-row textarea {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #253554;
    border-radius: 16px;
    background: #1a1a2e;
    color: #e0e0e0;
    font-size: 0.82em;
    font-family: inherit;
    outline: none;
    resize: none;
    overflow-y: hidden;
    max-height: 120px;
    line-height: 1.4;
}

.chat-input-row textarea:focus {
    border-color: #e94560;
}

.chat-input-row button {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: #e94560;
    color: white;
    font-size: 1em;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-input-row button:hover {
    background: #d63350;
}

/* Auth section */
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.sidebar-header h1 {
    margin-bottom: 2px;
}

.sidebar-header .subtitle {
    margin-bottom: 0;
}

#auth-section {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 6px;
}

#auth-login-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid #0f3460;
    border-radius: 6px;
    background: #1a1a2e;
    color: #aaa;
    font-size: 0.75em;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

#auth-login-btn:hover {
    background: #253554;
    color: #e0e0e0;
    border-color: #4a6fa5;
}

#auth-user-info {
    display: flex;
    align-items: center;
    gap: 6px;
}

.auth-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}

.auth-name {
    font-size: 0.72em;
    color: #aaa;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.auth-btn-small {
    background: none;
    border: 1px solid #333;
    border-radius: 4px;
    color: #888;
    font-size: 0.7em;
    cursor: pointer;
    padding: 2px 6px;
}

.auth-btn-small:hover {
    color: #e94560;
    border-color: #e94560;
}

/* API Key Modal */
#apikey-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4000;
}

.apikey-modal-content {
    background: #16213e;
    border-radius: 12px;
    border: 1px solid #0f3460;
    padding: 24px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.apikey-modal-content h3 {
    color: #e94560;
    margin-bottom: 8px;
}

.apikey-modal-content p {
    font-size: 0.85em;
    color: #aaa;
    margin-bottom: 8px;
}

.apikey-help a {
    color: #4ecca3;
    text-decoration: none;
    font-size: 0.8em;
}

.apikey-help a:hover {
    text-decoration: underline;
}

#apikey-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #0f3460;
    border-radius: 6px;
    background: #1a1a2e;
    color: #e0e0e0;
    font-size: 0.9em;
    margin: 8px 0;
    outline: none;
}

#apikey-input:focus {
    border-color: #e94560;
}

.apikey-error {
    color: #e94560;
    font-size: 0.8em;
    margin-bottom: 8px;
}

.apikey-actions {
    display: flex;
    gap: 8px;
}

.apikey-btn {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #0f3460;
    border-radius: 6px;
    background: #1a1a2e;
    color: #aaa;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.2s;
}

.apikey-btn.primary {
    background: #e94560;
    color: white;
    border-color: #e94560;
}

.apikey-btn.primary:hover {
    background: #d63350;
}

.apikey-btn.danger {
    color: #e94560;
    border-color: #e94560;
    background: rgba(233, 69, 96, 0.1);
    font-size: 0.75em;
}

.apikey-btn.danger:hover {
    background: rgba(233, 69, 96, 0.2);
}

.apikey-btn:hover:not(.primary):not(.danger) {
    background: #253554;
    color: #e0e0e0;
}

/* History panel in chat */
.history-list {
    padding: 8px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    margin-bottom: 4px;
    background: #1a1a2e;
    border-radius: 6px;
    border: 1px solid #0f3460;
    font-size: 0.78em;
    cursor: pointer;
    transition: all 0.2s;
}

.history-item:hover {
    border-color: #4a6fa5;
    background: #253554;
}

.history-item-title {
    color: #e0e0e0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item-date {
    color: #666;
    font-size: 0.85em;
    margin-left: 8px;
    flex-shrink: 0;
}

.history-item-actions {
    display: flex;
    gap: 4px;
    margin-left: 8px;
}

.history-item-btn {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 1em;
    padding: 2px;
}

.history-item-btn:hover {
    color: #e94560;
}

.history-item-btn.apply:hover {
    color: #4ecca3;
}

/* ============ Mobile-only elements: hidden on desktop ============ */
.bottom-sheet-handle {
    display: none;
}

#mobile-sidebar-toggle,
#mobile-chat-toggle {
    display: none;
}

/* ============ Tablet (768px - 1024px) ============ */
@media (min-width: 768px) and (max-width: 1024px) {
    #sidebar {
        width: 280px;
        min-width: 200px;
    }
    #chat-panel {
        width: 340px;
        height: 480px;
    }
    #compare-select-panel {
        width: 280px;
    }
    .slider-label {
        width: 90px;
        min-width: 90px;
        font-size: 0.7em;
    }
}

/* ============ Mobile (< 768px) ============ */
@media (max-width: 767px) {
    /* Map: full screen background */
    #map {
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        height: 100vh;
        height: 100dvh;
        width: 100vw;
        z-index: 1;
    }

    /* Hide resize handle */
    #resize-handle {
        display: none;
    }

    /* Mobile hamburger button */
    #mobile-sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 1100;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        border: 1px solid #0f3460;
        background: rgba(22, 33, 62, 0.9);
        color: #e0e0e0;
        font-size: 1.3em;
        cursor: pointer;
        box-shadow: 0 2px 10px rgba(0,0,0,0.4);
    }

    #mobile-sidebar-toggle:active {
        background: #0f3460;
    }

    /* Mobile chat button */
    #mobile-chat-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 12px;
        right: 12px;
        z-index: 1100;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        border: 1px solid #e94560;
        background: rgba(22, 33, 62, 0.9);
        color: #e0e0e0;
        font-size: 1.2em;
        cursor: pointer;
        box-shadow: 0 2px 10px rgba(0,0,0,0.4);
    }

    #mobile-chat-toggle:active {
        background: #e94560;
    }

    body:has(#chat-panel.open) #mobile-chat-toggle {
        z-index: 2100;
    }

    /* Sidebar → Bottom Sheet */
    #sidebar {
        position: fixed;
        bottom: 0; left: 0; right: 0;
        width: 100% !important;
        min-width: auto;
        max-width: none;
        height: auto;
        max-height: 100vh;
        max-height: 100dvh;
        border-right: none;
        border-top: none;
        border-radius: 16px 16px 0 0;
        z-index: 1000;
        transform: translateY(calc(100% - 60px));
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        padding: 8px 16px 20px;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
    }

    #sidebar.bottom-sheet-peek {
        transform: translateY(calc(100% - 45vh));
    }

    #sidebar.bottom-sheet-open {
        transform: translateY(0);
    }

    /* Drag handle */
    .bottom-sheet-handle {
        display: block;
        width: 40px;
        height: 5px;
        background: #555;
        border-radius: 3px;
        margin: 4px auto 10px;
        cursor: grab;
        flex-shrink: 0;
    }

    .bottom-sheet-handle:active {
        background: #888;
    }

    /* Compact sidebar header */
    .sidebar-header h1 {
        font-size: 1.1em;
    }

    .sidebar-header .subtitle {
        font-size: 0.7em;
    }

    /* Touch-friendly targets */
    .toggle-btn, .month-btn, .preset-btn,
    .chart-tab, #compare-btn, #toggle-cities {
        min-height: 40px;
    }

    select {
        min-height: 40px;
        font-size: 0.85em;
    }

    .month-btn {
        padding: 8px 2px;
        font-size: 0.8em;
    }

    /* Sliders: bigger thumbs */
    .comp-slider::-webkit-slider-thumb {
        width: 22px;
        height: 22px;
    }
    .comp-slider::-moz-range-thumb {
        width: 22px;
        height: 22px;
    }

    .slider-label {
        width: 80px;
        min-width: 80px;
        font-size: 0.7em;
    }

    .slider-info::after {
        left: 0;
        width: 200px;
    }

    /* Chat panel: full width bottom sheet */
    #chat-panel {
        width: 100% !important;
        max-width: 100vw;
        height: 85vh;
        height: 85dvh;
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: 16px 16px 0 0;
    }

    /* Hide chat resize handle on mobile */
    .chat-resize-handle {
        display: none;
    }

    /* Compare select panel: full width */
    #compare-select-panel {
        width: calc(100% - 20px);
        bottom: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }

    /* Compare modal: near full screen */
    .compare-modal-content {
        width: 95%;
        max-width: 95%;
        max-height: 90vh;
        max-height: 90dvh;
    }

    /* Compare clear button: adjust for mobile */
    #compare-map-clear {
        bottom: 70px;
    }

    /* Legend: smaller on mobile */
    .info.legend {
        font-size: 0.65em;
        max-width: 120px;
    }

    /* Chart panel compact */
    #chart-panel {
        padding: 8px;
    }

    /* Info panel compact */
    #info-panel {
        padding: 8px;
    }

    /* Ranking: smaller text */
    #ranking-list-cities,
    #ranking-list-depts {
        font-size: 0.75em;
        max-height: 120px;
    }
}
