/* Карта острова (/server/map/) — подложка из tools/render_map.py + Leaflet.
   Палитра тянется из переменных style.css, чтобы страница жила в одном стиле. */

.map-head-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.map-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.map-toolbar .muted { margin: 0; }

.map-layers {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.map-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 16px;
    align-items: start;
}

.map-shell {
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
    background: #0e1418;
    box-shadow: var(--shadow);
}

.map-canvas {
    width: 100%;
    height: clamp(420px, 74vh, 820px);
    /* Цвет моря с подложки (map-base.jpg) — поля по бокам квадратного арта
       сливаются с ним, а не выглядят «пустым» чёрным прямоугольником. */
    background: #142d2e;
    font-family: var(--font);
}

.map-shell.is-editing .map-canvas { cursor: crosshair; }

/* Leaflet под тёмную тему */
.map-canvas .leaflet-container { background: #142d2e; }
.map-canvas .leaflet-control-zoom a {
    background: var(--bg-elevated);
    color: var(--text);
    border-bottom-color: var(--border);
}
.map-canvas .leaflet-control-zoom a:hover {
    background: var(--bg-soft);
    color: var(--green-bright);
}

/* Копирайт подложки (тайлы scum-map) — тёмная плашка в правом нижнем углу */
.map-canvas .leaflet-control-attribution {
    background: rgba(14, 20, 24, .78);
    color: var(--text-muted);
    font-size: .68rem;
    line-height: 1.4;
    padding: 2px 8px;
    border-radius: var(--radius) 0 0 0;
    backdrop-filter: blur(6px);
}

.map-canvas .leaflet-control-attribution a {
    color: var(--green-bright);
    text-decoration: none;
}

/* Плитки 1280 px: при уменьшении браузер сглаживает их сам, «мыло» от
   пиксельного масштабирования тут не нужно. */
.map-canvas .leaflet-tile { image-rendering: auto; }

/* --- плашки поверх карты ------------------------------------------------ */
.map-overlay {
    position: absolute;
    z-index: 500;
    margin: 0;
    font-size: .78rem;
    line-height: 1.3;
    pointer-events: none;
}

.map-overlay--coords {
    left: 12px;
    bottom: 12px;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(14, 20, 24, .84);
    border: 1px solid rgba(255, 255, 255, .08);
    color: var(--text);
    backdrop-filter: blur(6px);
    font-variant-numeric: tabular-nums;
}

.map-overlay--coords b { color: var(--green-bright); font-weight: 600; }

.map-overlay--hint {
    right: 12px;
    top: 12px;
    max-width: 46%;
    padding: 5px 10px;
    border-radius: var(--radius);
    background: rgba(14, 20, 24, .72);
    color: var(--text-muted);
    text-align: right;
}

/* Подложка не загрузилась: без этого блока карта выглядела серым прямоугольником */
.map-overlay--error {
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    max-width: min(460px, calc(100% - 40px));
    padding: 14px 18px;
    border-radius: var(--radius);
    border: 1px solid var(--red);
    background: rgba(20, 12, 12, .94);
    color: #f0b0a7;
    text-align: center;
    pointer-events: auto;
}

.map-overlay--error code {
    color: #ffd9d2;
}

.map-shell--noart .map-canvas {
    background-image: repeating-linear-gradient(45deg, #141a1e 0 12px, #10161a 12px 24px);
}

/* --- метки на карте ----------------------------------------------------- */
.map-pin {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 15px;
    line-height: 1;
    background: rgba(14, 20, 24, .92);
    border: 2px solid var(--pin-color, var(--orange));
    box-shadow: 0 2px 6px rgba(0, 0, 0, .55);
    transition: transform .15s ease;
}

.map-pin-wrap:hover .map-pin { transform: scale(1.12); }
.map-pin-wrap.leaflet-marker-draggable .map-pin { cursor: grab; border-style: dashed; }

/* --- попап метки -------------------------------------------------------- */
.map-canvas .leaflet-popup-content-wrapper {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.map-canvas .leaflet-popup-tip {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
}

.map-canvas .leaflet-popup-content {
    margin: 12px 14px;
    font-size: .88rem;
    line-height: 1.45;
}

.map-canvas .leaflet-popup-close-button { color: var(--text-muted); }

.map-popup-head {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .98rem;
    line-height: 1.3;
}

.map-popup-icon {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    border-radius: 50%;
    border: 2px solid var(--pin-color, var(--orange));
    background: rgba(14, 20, 24, .8);
    font-size: 13px;
}

.map-popup-type {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.map-popup-desc { margin: 8px 0; color: var(--text); }

.map-popup-coords {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
    font-size: .76rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* --- боковая панель: поиск, фильтры, список ----------------------------- */
.map-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    position: sticky;
    top: 12px;
    max-height: clamp(420px, 74vh, 820px);
    overflow: auto;
}

.map-search { display: block; }
.map-search .input { width: 100%; }
.map-panel .filters { margin-bottom: 0; }

.map-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.map-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 6px 8px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.map-list-item:hover { background: var(--bg-soft); border-color: var(--border); }
.map-list-item.is-active { background: rgba(90, 125, 60, .18); border-color: var(--green); }

.map-list-icon {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    border-radius: 50%;
    border: 2px solid var(--pin-color, var(--orange));
    background: rgba(14, 20, 24, .7);
    font-size: 13px;
}

.map-list-text { display: flex; flex-direction: column; min-width: 0; }

.map-list-name {
    font-weight: 600;
    font-size: .88rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.map-list-meta { color: var(--text-muted); font-size: .74rem; }

.map-empty, .map-note { margin: 0; }

/* --- форма редактора ---------------------------------------------------- */
.map-form {
    position: absolute;
    z-index: 600;
    left: 12px;
    top: 12px;
    width: min(340px, calc(100% - 24px));
    max-height: calc(100% - 24px);
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    font-size: .82rem;
    box-shadow: var(--shadow);
}

.map-form[hidden] { display: none; }

.map-form-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.map-form label {
    display: flex;
    flex-direction: column;
    gap: 3px;
    color: var(--text-muted);
    font-size: .76rem;
}

.map-form input,
.map-form select,
.map-form textarea { width: 100%; font-size: .85rem; }
.map-form textarea { min-height: 64px; }

.map-form-row { display: flex; gap: 8px; }
.map-form-row > label { flex: 1; min-width: 0; }

.map-form-row--footer { align-items: center; justify-content: space-between; }

.map-check {
    flex-direction: row !important;
    align-items: center;
    gap: 6px;
    color: var(--text);
    font-size: .8rem;
}

.map-check input { width: auto; }

.map-form input[type="color"] { height: 32px; padding: 2px; }

/* --- всплывающее уведомление -------------------------------------------- */
.map-toast {
    position: absolute;
    z-index: 700;
    left: 50%;
    bottom: 16px;
    margin: 0;
    max-width: calc(100% - 32px);
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(14, 20, 24, .94);
    border: 1px solid var(--green);
    color: var(--text);
    font-size: .8rem;
    opacity: 0;
    transform: translate(-50%, 8px);
    transition: opacity .18s ease, transform .18s ease;
    pointer-events: none;
}

.map-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.map-toast[data-kind="error"] { border-color: var(--red); color: #f0b0a7; }

/* --- мелочи ------------------------------------------------------------- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.map-popup-coords code { font-size: .76rem; }

.map-popup-sector {
    padding: 1px 8px;
    border-radius: 999px;
    background: rgba(90, 125, 60, .24);
    color: var(--green-bright);
    font-weight: 600;
}

.map-popup-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 10px;
}

/* --- сетка секторов A–J × 1–10 ------------------------------------------- */

/* Кнопки «Сектора» и «Редактор» показывают включённое состояние атрибутом. */
.map-toolbar [aria-pressed="true"] {
    border-color: var(--green);
    color: var(--green-bright);
    background: rgba(90, 125, 60, .18);
}

.map-grid-line {
    stroke: rgba(159, 213, 196, .55);
    stroke-width: 1;
    stroke-dasharray: 4 4;
}

.map-grid-label {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 0;
    color: rgba(233, 240, 238, .85);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .02em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .9), 0 0 6px rgba(0, 0, 0, .7);
    pointer-events: none;
    user-select: none;
}

/* --- адаптив ------------------------------------------------------------ */
@media (max-width: 960px) {
    .map-layout { grid-template-columns: 1fr; }
    .map-canvas { height: 60vh; min-height: 380px; }
    .map-panel { position: static; max-height: none; }
    .map-overlay--hint { display: none; }
    .map-overlay--coords { right: 12px; }
}

@media (prefers-reduced-motion: reduce) {
    .map-pin, .map-toast { transition: none; }
}

