body {
    margin: 0;
    min-height: 100vh;
    background: linear-gradient(180deg, #4da1d9 0%, #6cb3e3 100%);
    color: #ffffff;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.map-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.7rem 1rem;
    background: rgba(35, 38, 43, 0.9);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: #ffffff;
    text-decoration: none;
    font-weight: 700;
}

.brand img {
    width: 1.9rem;
    height: auto;
}

.back-link {
    color: #dcecff;
    text-decoration: none;
    font-weight: 600;
}

.map-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 0.8rem;
    min-height: calc(100vh - 58px);
    padding: 0.8rem;
}

.toolbar {
    display: flex;
    flex-flow: column nowrap;
    gap: 0.7rem;
    background: rgba(34, 37, 42, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 12px;
    padding: 0.9rem;
}

.mode-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
}

.mode-switch button,
.actions button,
#territory-select {
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    min-height: 2.4rem;
    padding: 0.45rem 0.65rem;
}

.mode-switch button.is-active {
    background: rgba(242, 186, 66, 0.22);
    border-color: rgba(242, 186, 66, 0.75);
}

#territory-select {
    background: rgba(20, 22, 26, 0.9);
}

.actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
}

.color-controls {
    display: flex;
    flex-flow: column nowrap;
    gap: 0.45rem;
    padding: 0.5rem 0.55rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.13);
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.88rem;
    color: #e9f3ff;
}

.pickers {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.35rem 0.5rem;
    align-items: center;
}

.pickers label {
    font-size: 0.78rem;
    color: #dcecff;
}

.pickers input[type="color"] {
    width: 100%;
    min-height: 1.9rem;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 7px;
    background: transparent;
    padding: 0;
}

.active-state {
    margin: 0.2rem 0 0;
    font-size: 0.95rem;
    color: #dcecff;
}

.map-hint {
    margin: 0;
    font-size: 0.85rem;
    color: rgba(220, 236, 255, 0.9);
}

.map-shell {
    position: relative;
    min-height: 640px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    overflow: hidden;
    background: rgba(130, 193, 235, 0.65);
}

#map {
    width: 100%;
    height: 100%;
    min-height: 640px;
}

.leaflet-container {
    background: #78b8e4 !important;
}

.map-status {
    position: absolute;
    right: 0.65rem;
    bottom: 0.65rem;
    z-index: 600;
    background: rgba(34, 37, 42, 0.86);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 0.35rem 0.55rem;
    font-size: 0.85rem;
}

.leaflet-popup-content-wrapper {
    border-radius: 12px !important;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.24) !important;
    background: #ffffff !important;
    border: 1px solid rgba(35, 44, 58, 0.12) !important;
}

.leaflet-popup-tip {
    background: #ffffff !important;
    box-shadow: none !important;
}

.leaflet-popup-pane,
.leaflet-popup {
    opacity: 1 !important;
}

.leaflet-popup-content {
    margin: 0 !important;
}

.commune-popup {
    color: #1f2430;
    padding: 0.4rem 0.5rem;
    min-width: 130px;
    max-width: 170px;
    opacity: 1 !important;
}

.commune-popup h3 {
    margin: 0 0 0.15rem;
    font-size: 0.88rem;
    line-height: 1.15;
    color: #141922;
}

.commune-popup p {
    margin: 0.05rem 0;
    font-size: 0.7rem;
    line-height: 1.15;
    color: #243246;
}

.commune-popup a {
    display: inline;
    margin: 0;
    font-size: 0.7rem;
    line-height: 1.15;
    color: #1f4f93;
    word-break: break-word;
}

.commune-popup .swatches {
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem;
    margin-top: 0.3rem;
}

.commune-popup .swatch {
    display: inline-flex;
    flex-flow: row nowrap;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.65rem;
    color: #2f3b4d;
}

.commune-popup .dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    border: 1px solid rgba(26, 32, 42, 0.2);
}

.commune-popup .dot-fill {
    background: #4f80c7;
}

.commune-popup .dot-border {
    background: #6b3b9f;
}

.leaflet-tooltip.commune-hover-tooltip {
    background: rgba(24, 28, 36, 0.92);
    border: 0;
    border-radius: 6px;
    color: #ffffff;
    padding: 0.2rem 0.45rem;
    font-size: 0.75rem;
    font-weight: 600;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
}

.leaflet-tooltip.commune-hover-tooltip::before {
    border-top-color: rgba(24, 28, 36, 0.92);
}

@media screen and (max-width: 980px) {
    .map-layout {
        grid-template-columns: 1fr;
    }

    .toolbar {
        order: 2;
    }

    .map-shell {
        order: 1;
        min-height: 68vh;
    }

    #map {
        min-height: 68vh;
    }
}
