/* ── Сброс ──────────────────────────────────────────── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
    height: 100vh;
    background: #0f0f1a;
}

/* ── Карта ──────────────────────────────────────────── */
#map {
    position: absolute;
    inset: 0;
    z-index: 1;
}

/* ── Скроллбар ──────────────────────────────────────── */
::-webkit-scrollbar {
    width: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
}

/* ── Панель ─────────────────────────────────────────── */
#panel {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 1000;
    width: 320px;
    max-height: calc(100vh - 32px);
    background: rgba(22, 22, 40, 0.94);
    backdrop-filter: blur(16px);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 4px 32px rgba(0, 0, 0, 0.6);
    transition:
        width 0.3s ease,
        max-width 0.3s ease;
}

#panel-header {
    padding: 14px 18px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
#panel-header h2 {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
#counter {
    font-size: 12px;
    color: #6b6b87;
    font-weight: 500;
}

#panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 14px 18px 18px;
}
#panel-content .placeholder {
    color: #555;
    font-size: 13px;
    text-align: center;
    padding: 40px 0;
    line-height: 1.7;
}

/* ── Карточка ───────────────────────────────────────── */
.settlement-card h3 {
    font-size: 17px;
    font-weight: 600;
    color: #fff;
    margin-bottom: 4px;
    line-height: 1.3;
}
.settlement-card .population {
    font-size: 26px;
    font-weight: 700;
    color: #7dd3fc;
    margin-bottom: 14px;
}
.settlement-card .population span {
    font-size: 13px;
    font-weight: 400;
    color: #6b6b87;
}
.settlement-card .nations-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #555;
    margin: 10px 0 6px;
}

/* ── Donut ──────────────────────────────────────────── */
.donut-wrap {
    position: relative;
    width: 112px;
    height: 112px;
    margin: 0 auto 10px;
}
.donut-center {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: #c0c0d0;
}
.donut-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    justify-content: center;
    margin-bottom: 6px;
}
.legend-item {
    font-size: 10px;
    color: #8b8ba7;
    display: flex;
    align-items: center;
    gap: 4px;
}
.legend-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ── Список национальностей ─────────────────────────── */
.nation-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 4px 0;
    font-size: 12px;
    gap: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}
.nation-row:last-child {
    border-bottom: none;
}
.nation-row .nation-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #c0c0d0;
}
.nation-row .nation-count {
    flex-shrink: 0;
    color: #6b6b87;
    font-size: 11px;
}
.no-data {
    color: #555;
    font-size: 12px;
    font-style: italic;
}

/* ── Легенда маркеров ───────────────────────────────── */
#panel-footer {
    padding: 8px 18px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}
.legend {
    font-size: 10px;
    color: #6b6b87;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    align-items: center;
}
.dot {
    display: inline-block;
    border-radius: 50%;
    vertical-align: middle;
}
.dot.small {
    width: 6px;
    height: 6px;
    background: #fbbf24;
}
.dot.medium {
    width: 8px;
    height: 8px;
    background: #f97316;
}
.dot.large {
    width: 10px;
    height: 10px;
    background: #ef4444;
}
.dot.city {
    width: 12px;
    height: 12px;
    background: #a855f7;
}

/* ── Лоадер ─────────────────────────────────────────── */
#loader {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    background: rgba(22, 22, 40, 0.92);
    backdrop-filter: blur(8px);
    color: #c0c0d0;
    padding: 7px 18px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    transition: opacity 0.25s ease;
    pointer-events: none;
    border: 1px solid rgba(255, 255, 255, 0.06);
}
#loader.hidden {
    opacity: 0;
}

/* ── Кнопки ─────────────────────────────────────────── */
#toggle-panel,
#close-panel {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: #6b6b87;
    width: 28px;
    height: 28px;
    border-radius: 7px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
    transition:
        color 0.2s,
        background 0.2s;
}
#toggle-panel:hover,
#close-panel:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}
#close-panel {
    display: none;
    font-size: 14px;
}
#toggle-panel {
    font-size: 15px;
}

/* Панель развёрнута */
#panel.expanded {
    width: calc(100vw - 32px);
    max-width: 620px;
}
#panel.expanded .settlement-card h3 {
    font-size: 20px;
}
#panel.expanded .donut-wrap {
    width: 140px;
    height: 140px;
}
#panel.expanded .nation-row .nation-name {
    overflow: visible;
    text-overflow: unset;
    white-space: normal;
}

/* ── Оверлей ────────────────────────────────────────── */
#overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

/* ── Leaflet ────────────────────────────────────────── */
.leaflet-control-zoom a {
    background: rgba(22, 22, 40, 0.85) !important;
    color: #c0c0d0 !important;
    border-color: rgba(255, 255, 255, 0.06) !important;
    backdrop-filter: blur(8px);
}
.leaflet-control-zoom a:hover {
    background: rgba(40, 40, 60, 0.9) !important;
    color: #fff !important;
}
.leaflet-tooltip.settlement-tooltip {
    background: rgba(22, 22, 40, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #e0e0e0;
    font-size: 12px;
    padding: 3px 8px;
    border-radius: 6px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}
.leaflet-tooltip.settlement-tooltip::before {
    border-top-color: rgba(22, 22, 40, 0.9);
}

/* ── Мобильная адаптация ────────────────────────────── */
@media (max-width: 600px) {
    #panel {
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 70vh;
        max-width: none;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
        transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
        box-shadow: 0 -4px 32px rgba(0, 0, 0, 0.6);
    }
    #panel.visible {
        transform: translateY(0);
    }
    #close-panel {
        display: block;
    }
    #toggle-panel {
        display: none;
    }
    #overlay.visible {
        display: block;
    }
    .leaflet-control-zoom {
        display: none;
    }
    #panel-footer {
        padding: 6px 14px 10px;
    }
    .legend {
        gap: 6px 10px;
        font-size: 9px;
    }
    #panel.expanded {
        max-height: 92vh;
        border-radius: 20px 20px 0 0;
    }
    #panel.expanded .donut-wrap {
        width: 130px;
        height: 130px;
    }
}
