/* ============================================================
   ТЕМИЗАЦИЯ
   ============================================================ */
:root {
    --bg: #eef1f6;
    --surface: #ffffff;
    --surface-2: #f3f5f9;
    --text: #15172b;
    --text-2: #5b6275;
    --text-muted: #9aa1b1;
    --border: #e7eaf0;
    --accent: #4f46e5;
    --accent-soft: #eef2ff;
    --accent-grad: linear-gradient(309deg, #0cf -6.06%, #007aff 33.55%, #630eff 65.79%, #aa4cff 96.45%);
    --shadow: 0 8px 30px rgba(20, 23, 43, 0.14);
    --shadow-sm: 0 2px 12px rgba(20, 23, 43, 0.10);
    --glass: rgba(255, 255, 255, 0.82);
    --header-fg: #ffffff;
    --radius: 20px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1016;
        --surface: #171a23;
        --surface-2: #1f232f;
        --text: #f2f4f8;
        --text-2: #aab1c2;
        --text-muted: #6c7385;
        --border: #262b38;
        --accent: #8b85ff;
        --accent-soft: #20243a;
        --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
        --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.4);
        --glass: rgba(23, 26, 35, 0.78);
        --header-fg: #ffffff;
        color-scheme: dark;
    }
}

html.theme-dark {
    --bg: #0e1016;
    --surface: #171a23;
    --surface-2: #1f232f;
    --text: #f2f4f8;
    --text-2: #aab1c2;
    --text-muted: #6c7385;
    --border: #262b38;
    --accent: #8b85ff;
    --accent-soft: #20243a;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.4);
    --glass: rgba(23, 26, 35, 0.78);
    --header-fg: #ffffff;
    color-scheme: dark;
}

html.theme-light {
    --bg: #eef1f6;
    --surface: #ffffff;
    --surface-2: #f3f5f9;
    --text: #15172b;
    --text-2: #5b6275;
    --text-muted: #9aa1b1;
    --border: #e7eaf0;
    --accent: #4f46e5;
    --accent-soft: #eef2ff;
    --shadow: 0 8px 30px rgba(20, 23, 43, 0.14);
    --shadow-sm: 0 2px 12px rgba(20, 23, 43, 0.10);
    --glass: rgba(255, 255, 255, 0.82);
    --header-fg: #ffffff;
    color-scheme: light;
}

/* ============================================================
   БАЗА
   ============================================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}
html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    touch-action: pan-y;
    transition: background 0.3s, color 0.3s;
}
#map {
    width: 100%;
    height: 100%;
    position: absolute;
    inset: 0;
    z-index: 1;
    background: var(--bg);
}
/* Тёмная карта: инверсия тайлов OSM */
html.theme-dark #map .leaflet-tile {
    filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9);
}
@media (prefers-color-scheme: dark) {
    #map .leaflet-tile { filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9); }
}

/* ===== ВЕРХНЯЯ ПАНЕЛЬ ===== */
#header {
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 10;
    padding: max(14px, env(safe-area-inset-top)) 16px 12px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0) 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
}
#header > * { pointer-events: auto; }
#brand { display: flex; align-items: center; gap: 10px; }
#brand .icon {
    width: 38px; height: 38px;
    background: var(--glass);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
#brand .title {
    color: var(--header-fg);
    font-size: 16px; font-weight: 600;
    text-shadow: 0 1px 10px rgba(0, 0, 0, 0.35);
    line-height: 1.2; letter-spacing: -0.3px;
}
#brand .subtitle {
    color: rgba(255, 255, 255, 0.82);
    font-size: 11px; font-weight: 400; letter-spacing: -0.2px;
}
#header-actions { display: flex; gap: 8px; }
.header-btn {
    width: 42px; height: 42px;
    background: var(--glass);
    border: none; border-radius: 13px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: transform 0.18s, background 0.18s;
    flex-shrink: 0;
}
.header-btn:active { transform: scale(0.9); }
.header-btn svg { width: 21px; height: 21px; fill: var(--text); }

/* ===== КНОПКИ ЗУМА ===== */
#zoom-controls {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    display: flex; flex-direction: column; gap: 8px;
    pointer-events: none;
}
#zoom-controls .zoom-btn {
    pointer-events: auto;
    width: 46px; height: 46px;
    background: var(--glass);
    border: none; border-radius: 14px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: transform 0.18s, background 0.18s;
    flex-shrink: 0;
}
#zoom-controls .zoom-btn:active { transform: scale(0.9); }
#zoom-controls .zoom-btn svg { width: 24px; height: 24px; fill: var(--text); }

/* ===== НИЖНЯЯ ПАНЕЛЬ (ШАТЁР) ===== */
#bottom-sheet {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    z-index: 20;
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: var(--shadow);
    max-height: 82vh;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; flex-direction: column;
    will-change: transform;
}
#bottom-sheet.closed { transform: translateY(calc(100% - 66px)); }
#bottom-sheet.open { transform: translateY(0); }

#sheet-handle {
    flex-shrink: 0;
    padding: 10px 16px 8px;
    display: flex; flex-direction: column; align-items: center;
    cursor: pointer; user-select: none;
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    touch-action: none;
    min-height: 56px; justify-content: center;
}
#sheet-handle .bar {
    width: 38px; height: 4px;
    background: var(--text-muted);
    border-radius: 4px; margin-bottom: 6px; flex-shrink: 0; opacity: 0.5;
}
#sheet-handle .bar-info {
    display: flex; justify-content: space-between; width: 100%;
    font-size: 13px; color: var(--text-2); align-items: center;
}
#sheet-handle .bar-info .label { font-weight: 600; font-size: 14px; color: var(--text); }
#sheet-handle .bar-info .count {
    font-weight: 600; color: var(--accent);
    background: var(--accent-soft);
    padding: 3px 12px; border-radius: 20px; font-size: 13px;
}

#search-wrap {
    flex-shrink: 0;
    padding: 8px 16px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
#search-wrap input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 13px;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    background: var(--surface-2);
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
    height: 48px; letter-spacing: -0.2px;
}
#search-wrap input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
#search-wrap input::placeholder { color: var(--text-muted); }

#list-container {
    flex: 1;
    overflow-y: auto;
    padding: 4px 12px calc(20px + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
#list-container::-webkit-scrollbar { width: 4px; }
#list-container::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; opacity: 0.4; }

.point-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px;
    border-radius: 14px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    border-bottom: 1px solid var(--border);
    min-height: 58px;
}
.point-item.pressed { background: var(--surface-2); transform: scale(0.985); }
.point-item.selected { background: var(--accent-soft); }
.point-item .number {
    flex-shrink: 0;
    width: 30px; height: 30px;
    background: var(--accent-grad);
    color: #fff; font-weight: 600; font-size: 12px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}
.point-item .info { flex: 1; min-width: 0; }
.point-item .info .name {
    font-weight: 600; font-size: 14px; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.2px;
}
.point-item .info .address {
    font-size: 13px; color: var(--text-2);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.2px;
}
.point-item .info .district {
    font-size: 11px; color: var(--text-2);
    background: var(--surface-2);
    padding: 2px 10px; border-radius: 20px;
    display: inline-block; margin-top: 3px; font-weight: 400;
}
.point-item .dist {
    font-size: 12px; color: var(--accent); font-weight: 600;
    flex-shrink: 0; margin-left: 4px;
}

/* кнопка «Поделиться» в списке (когда гео выключено) — квадратная, в стиле миниапп */
.share-btn {
    flex-shrink: 0; width: 40px; height: 40px;
    border: 1px solid var(--border); border-radius: 12px;
    background: var(--surface-2); color: var(--accent);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: transform 0.1s, background 0.15s;
}
.share-btn:active { transform: scale(0.96); background: var(--accent-soft); }
.share-btn svg { width: 20px; height: 20px; }

/* тост-уведомление */
#toast {
    position: absolute; left: 50%;
    bottom: calc(96px + env(safe-area-inset-bottom));
    transform: translateX(-50%) translateY(10px);
    background: rgba(20, 23, 43, 0.92); color: #fff;
    padding: 10px 18px; border-radius: 22px;
    font-size: 13px; font-weight: 500; font-family: Inter, system-ui, sans-serif;
    z-index: 60; opacity: 0; pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    max-width: 80%; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#empty-state {
    display: none; text-align: center;
    padding: 40px 20px; color: var(--text-muted); font-size: 14px;
}
#empty-state.active { display: block; }

/* ===== КЛАСТЕРЫ ===== */
.marker-cluster {
    background: transparent !important;
}
.marker-cluster div {
    width: 38px !important; height: 38px !important;
    margin: 0 !important;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent-grad) !important;
    color: #fff !important; font-weight: 700; font-size: 13px;
    border-radius: 50% !important;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
    border: 3px solid var(--surface);
}

/* ============================================================
   АДАПТИВ — ДЕСКТОП / ШИРОКИЕ ЭКРАНЫ (боковая панель)
   ============================================================ */
@media (min-width: 768px) {
    #bottom-sheet {
        left: auto; right: 0; top: 0; bottom: 0;
        width: min(400px, 38vw);
        max-height: 100%;
        border-radius: 0;
        box-shadow: var(--shadow);
    }
    #bottom-sheet.closed { transform: translateX(100%); }
    #bottom-sheet.open { transform: translateX(0); }
    #sheet-handle { border-radius: 0; }
    #zoom-controls { right: calc(min(400px, 38vw) + 16px); }
    #header { padding: 16px 20px 12px; }
}
@media (min-width: 768px) and (max-height: 600px) {
    #bottom-sheet { width: min(360px, 42vw); }
}

/* ============================================================
   АДАПТИВ — МОБИЛЬНЫЕ
   ============================================================ */
@media (max-width: 480px) {
    #brand .title { font-size: 14px; }
    #brand .subtitle { display: none; }
    .header-btn { width: 38px; height: 38px; }
    #header { padding: max(10px, env(safe-area-inset-top)) 12px 10px; }
    #zoom-controls { right: 12px; bottom: calc(64px + env(safe-area-inset-bottom)); }
    #zoom-controls .zoom-btn { width: 42px; height: 42px; }
    #zoom-controls .zoom-btn svg { width: 22px; height: 22px; }
    #bottom-sheet { max-height: 86vh; }
    #bottom-sheet.closed { transform: translateY(calc(100% - 56px)); }
    #sheet-handle { padding: 8px 12px 6px; min-height: 48px; }
    #sheet-handle .bar-info { font-size: 12px; }
    #sheet-handle .bar-info .label { font-size: 13px; }
    #sheet-handle .bar-info .count { font-size: 12px; padding: 2px 10px; }
    #search-wrap { padding: 6px 12px 10px; }
    #search-wrap input { font-size: 14px; padding: 8px 14px; height: 44px; }
    .point-item { padding: 8px 10px; min-height: 50px; gap: 10px; }
    .point-item .number { width: 26px; height: 26px; font-size: 11px; }
    .point-item .info .name { font-size: 13px; }
    .point-item .info .address { font-size: 12px; }
    #list-container { padding: 2px 8px calc(16px + env(safe-area-inset-bottom)); }
}

@media (max-width: 380px) {
    #brand .title { font-size: 13px; }
    #brand .icon { width: 32px; height: 32px; font-size: 15px; }
    .header-btn { width: 34px; height: 34px; }
    .header-btn svg { width: 18px; height: 18px; }
    #zoom-controls { right: 10px; }
    #zoom-controls .zoom-btn { width: 38px; height: 38px; }
    #zoom-controls .zoom-btn svg { width: 20px; height: 20px; }
    #bottom-sheet.closed { transform: translateY(calc(100% - 50px)); }
    #sheet-handle { min-height: 42px; padding: 6px 10px 4px; }
}

@media (min-height: 800px) and (max-width: 767px) {
    #bottom-sheet { max-height: 76vh; }
}

/* ===== Leaflet ===== */
.leaflet-control-zoom { display: none !important; }
.leaflet-control-attribution {
    font-size: 9px !important; opacity: 0.55;
    font-family: 'Inter', system-ui, sans-serif !important;
    background: var(--glass) !important;
    color: var(--text-2) !important;
}
.custom-popup .leaflet-popup-content-wrapper {
    border-radius: 14px !important;
    background: var(--surface) !important;
    color: var(--text) !important;
    box-shadow: var(--shadow) !important;
}
.custom-popup .leaflet-popup-content { font-family: 'Inter', system-ui, sans-serif !important; font-size: 13px !important; }
.custom-popup .leaflet-popup-tip { background: var(--surface) !important; }

/* ============================================================
   ВЫБОР ПРИЛОЖЕНИЯ ДЛЯ МАРШРУТА
   ============================================================ */
#route-modal {
    position: absolute; inset: 0; z-index: 50;
    display: none; align-items: flex-end; justify-content: center;
    background: rgba(10, 12, 20, 0.45);
}
#route-modal.open { display: flex; }
#route-sheet {
    width: 100%;
    max-width: 520px;
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: var(--shadow);
    padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
    animation: sheetUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes sheetUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.modal-handle {
    width: 38px; height: 4px; background: var(--text-muted);
    border-radius: 4px; opacity: 0.5; margin: 4px auto 12px;
}
.modal-title { font-size: 17px; font-weight: 700; color: var(--text); text-align: center; }
.modal-sub {
    font-size: 13px; color: var(--text-2); text-align: center;
    margin: 4px 0 14px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    padding: 0 8px;
}
.route-app {
    width: 100%; display: flex; align-items: center; gap: 14px;
    padding: 14px 16px; margin-bottom: 10px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 16px; cursor: pointer; text-align: left;
    transition: transform 0.1s, background 0.15s;
}
.route-app:active { transform: scale(0.98); background: var(--accent-soft); }
.route-ico {
    width: 44px; height: 44px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; background: var(--surface); border-radius: 12px;
}
.route-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.route-name { font-size: 15px; font-weight: 600; color: var(--text); }
.route-desc { font-size: 12px; color: var(--text-2); }
.route-cancel {
    width: 100%; padding: 14px; margin-top: 2px;
    background: transparent; border: none; border-radius: 14px;
    font-size: 15px; font-weight: 600; color: var(--text-2); cursor: pointer;
}
.route-cancel:active { background: var(--surface-2); }

/* кнопка маршрута в popup Leaflet */
.popup-route-btn {
    margin-top: 8px; width: 100%;
    padding: 8px 12px; border: none; border-radius: 10px;
    background: var(--accent-grad); color: #fff;
    font-size: 13px; font-weight: 600; font-family: Inter, system-ui, sans-serif;
    cursor: pointer;
}
.popup-route-btn:active { opacity: 0.85; }

@media (min-width: 768px) {
    #route-modal { align-items: center; }
    #route-sheet { border-radius: var(--radius); animation: none; }
}
