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

.hidden {
    display: none !important;
}

body {
    height: 100vh;
    font-family:
        "Inter",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    background: #0f0f0f;
    color: #e0e0e0;
    overflow: hidden;
    position: relative;
}

#sidebar {
    width: 300px;
    background: #1e1e1e;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    border-right: 1px solid #333;
    overflow-y: auto;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: transform 0.2s ease;
}

#sidebar.collapsed {
    transform: translateX(-100%);
}

#sidebar.collapsed *:not(.sidebar-toggle) {
    opacity: 0;
    pointer-events: none;
}

#sidebar.collapsed .sidebar-toggle,
.btn-collapsed {
    left: 5px !important;
}

.sidebar-toggle {
    position: fixed;
    top: 10px;
    left: 305px;
    z-index: 1100;
    background: #2a2a2a;
    border: 1px solid #444;
    color: #aaa;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: left 0.2s ease;
}

.sidebar-toggle:hover {
    background: #3a3a3a;
    color: #fff;
}

#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

.drag-handle {
    display: none;
    width: 40px;
    height: 5px;
    background: #555;
    border-radius: 5px;
    margin: 0 auto 15px auto;
    cursor: grab;
}

h2 {
    font-size: 1.2em;
    font-weight: 600;
    color: #e0e0e0;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.lang-switcher {
    position: relative;
    flex-shrink: 0;
    margin-left: auto;
}

.lang-btn {
    background: transparent;
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 1em;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
    transition:
        background 0.15s,
        border-color 0.15s;
    flex-shrink: 0;
}

.lang-btn:hover {
    background: #333;
    border-color: #7c3aed;
}

.lang-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 6px;
    overflow: hidden;
    z-index: 2000;
    min-width: 130px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.lang-menu.open {
    display: block;
}

.lang-option {
    display: block;
    width: 100%;
    background: transparent;
    border: none;
    color: #ccc;
    font-size: 0.85em;
    padding: 8px 12px;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s;
    white-space: nowrap;
}

.lang-option:hover {
    background: #3a3a3a;
    color: #fff;
}

.lang-option.active {
    color: #a78bfa;
    font-weight: 600;
}

h3 {
    font-size: 0.85em;
    font-weight: 500;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn {
    padding: 10px 14px;
    border: 1px solid #333;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9em;
    transition: all 0.2s ease;
    color: #e0e0e0;
    background: #2a2a2a;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn-icon {
    flex-shrink: 0;
}

.btn:hover {
    background: #3a3a3a;
    border-color: #555;
}

.btn.active {
    background: #3a3a3a;
    border-color: #00d4ff;
    color: #00d4ff;
    box-shadow: 0 0 0 1px #00d4ff;
}

/* Кнопки Старт/Финиш */
.btn-start {
    background: #1a3a1a !important;
    border-color: #4caf50 !important;
    color: #4caf50 !important;
    font-weight: 600;
}

.btn-start:hover {
    background: #2a5a2a !important;
}

.btn-start.active {
    background: #4caf50 !important;
    color: #000 !important;
    box-shadow: 0 0 10px #4caf50;
}

.btn-end {
    background: #3a1a1a !important;
    border-color: #f44336 !important;
    color: #f44336 !important;
    font-weight: 600;
}

.btn-end:hover {
    background: #5a2a2a !important;
}

.btn-end.active {
    background: #f44336 !important;
    color: #000 !important;
    box-shadow: 0 0 10px #f44336;
}

/* Кнопка Промежуточные */
.btn-intermediate {
    display: flex;
    align-items: center;
}

.btn-intermediate.active {
    background: #ff9800 !important;
    color: #000 !important;
    border-color: #ff9800 !important;
    box-shadow: 0 0 10px #ff9800;
}

/* Глаз на кнопке */
.eye-toggle {
    cursor: pointer;
    font-size: 1em;
    opacity: 0.7;
    transition: opacity 0.2s;
    user-select: none;
    margin-left: auto;
    padding: 6px 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.eye-toggle:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.08);
}

.eye-toggle.hidden-intermediates {
    opacity: 0.5;
}

/* Заголовок списка точек */
.points-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}

/* Стрелка сворачивания списка */
.points-toggle {
    cursor: pointer;
    font-size: 1em;
    opacity: 0.6;
    transition:
        transform 0.3s,
        opacity 0.2s;
    user-select: none;
}

.points-toggle:hover {
    opacity: 1;
}

.points-toggle.collapsed {
    transform: rotate(-90deg);
}

/* Список точек */
.waypoints-list {
    max-height: 300px;
    overflow-y: auto;
    transition: max-height 0.3s ease;
    list-style: none;
    padding: 0;
    margin-top: 10px;
}

.waypoints-list.collapsed {
    max-height: 0;
    overflow: hidden;
    margin-top: 0;
}

#points-list li {
    padding: 6px 0;
    border-bottom: 1px solid #2a2a2a;
    font-size: 0.85em;
    color: #aaa;
    display: flex;
    align-items: center;
    gap: 6px;
}

#points-list li .point-text {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Экспорт */
.export-container {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.btn-export {
    padding: 6px 10px;
    border: 1px solid #333;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.8em;
    transition: all 0.2s ease;
    color: #888;
    background: transparent;
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    justify-content: center;
}

.btn-export:hover {
    background: #2a2a2a;
    color: #e0e0e0;
    border-color: #555;
}

#feedbackBtn {
    color: #c4b5fd;
    background: rgba(124, 58, 237, 0.08);
    border-color: rgba(124, 58, 237, 0.45);
    box-shadow: 0 0 0 1px rgba(124, 58, 237, 0.08) inset;
}

#feedbackBtn:hover {
    color: #ddd6fe;
    background: rgba(124, 58, 237, 0.14);
    border-color: rgba(124, 58, 237, 0.65);
}

.export-options {
    position: relative;
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 5px;
    padding: 3px;
    display: flex;
    gap: 3px;
    z-index: 10;
}

.export-options.hidden {
    display: none;
}

.export-option {
    background: #3a3a3a;
    color: #e0e0e0;
    border: 1px solid #555;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.75em;
    transition: all 0.2s;
    flex: 1;
    text-align: center;
}

.export-option:hover {
    background: #00d4ff;
    color: #000;
    border-color: #00d4ff;
}

/* Результаты */
.sidebar-spacer {
    flex: 1;
}

#results {
    padding: 10px 0;
    border-top: 1px solid #333;
    font-size: 0.85em;
    color: #888;
}

#distance {
    margin: 0;
}

#distance span {
    color: #fff;
    font-weight: 600;
    font-size: 1.1em;
}

/* Подписи на маркерах Старт/Финиш */
.start-end-marker {
    position: relative;
}

.marker-label {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
}

.marker-label-start {
    border: 1px solid #4caf50;
}

.marker-label-end {
    border: 1px solid #f44336;
}

/* Километровые метки */
.km-marker {
    background: transparent;
    border: none;
    text-align: center;
}

.km-text {
    font-size: 10px;
    font-weight: 600;
    color: #ffffff;
    text-shadow:
        -1px -1px 0 #000,
        1px -1px 0 #000,
        -1px 1px 0 #000,
        1px 1px 0 #000,
        0px 0px 4px rgba(0, 0, 0, 0.9);
    background: rgba(0, 0, 0, 0.5);
    padding: 2px 5px;
    border-radius: 3px;
    white-space: nowrap;
    display: block;
}

.km-text.major-text {
    font-size: 11px;
}

/* Переключатель слоев: горизонтальная панель (десктоп) */
.layer-switcher {
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 6px;
    display: flex;
    gap: 6px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}

/* Кнопки-гамбургеры: скрыты на десктопе */
.menu-hamburger,
.layers-btn {
    display: none;
}

/* Панель слоев: скрыта на десктопе */
.layers-panel {
    display: none;
}

.layer-btn {
    background: #2a2a2a;
    color: #aaa;
    border: 1px solid transparent;
    padding: 8px 14px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 500;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.layer-btn:hover {
    background: #3a3a3a;
    color: #fff;
}

.layer-btn.active {
    background: #00d4ff;
    color: #000;
    border-color: #00d4ff;
    font-weight: 600;
}

/* Скрываем атрибуцию */
.leaflet-control-attribution a[href*="leafletjs"] {
    display: none !important;
}

.leaflet-control-attribution {
    background: rgba(30, 30, 30, 0.85) !important;
    color: #888 !important;
    font-size: 10px !important;
    padding: 2px 6px !important;
    border-radius: 3px 0 0 0 !important;
}

.leaflet-control-attribution a {
    color: #aaa !important;
    text-decoration: none !important;
}

.leaflet-control-attribution a:hover {
    color: #ccc !important;
    text-decoration: underline !important;
}

/* Мобильные */
@media (max-width: 768px) {
    /* Гамбургеры */
    .menu-hamburger,
    .layers-btn {
        display: flex;
        position: fixed;
        z-index: 1200;
        background: #1e1e1e;
        color: #ccc;
        border: 1px solid #333;
        border-radius: 8px;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
        transition: background 0.2s;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .menu-hamburger {
        width: auto;
        height: 42px;
        padding: 0 12px 0 10px;
        gap: 6px;
    }

    .layers-btn {
        width: 42px;
        height: 42px;
    }

    .menu-hamburger:hover,
    .layers-btn:hover {
        background: #2a2a2a;
        color: #fff;
    }

    .hamburger-label {
        font-size: 0.85em;
        font-weight: 500;
        line-height: 1;
    }

    .menu-hamburger {
        top: 10px;
        left: 10px;
    }

    .layers-btn {
        top: 10px;
        right: 10px;
    }

    /* Панель слоев */
    .layers-panel {
        display: flex;
        position: fixed;
        top: 60px;
        right: 10px;
        width: 200px;
        background: #1a1a1a;
        border: 1px solid #333;
        border-radius: 10px;
        z-index: 1150;
        flex-direction: column;
        padding: 12px;
        gap: 4px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
        transform: translateY(-10px);
        opacity: 0;
        pointer-events: none;
        transition: all 0.2s ease;
    }

    .layers-panel.open {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
    }

    .layers-panel-header {
        display: none;
    }

    .layers-panel .layer-btn {
        width: 100%;
        text-align: left;
        padding: 10px 12px;
        border-radius: 6px;
        font-size: 0.85em;
        min-height: 40px;
    }

    /* Скрываем горизонтальный переключатель */
    .layer-switcher {
        display: none;
    }

    /* Сайдбар: выезжает слева */
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        max-width: 85vw;
        height: 100%;
        max-height: 100%;
        transform: translateX(-100%);
        border-right: 1px solid #333;
        border-top: none;
        border-radius: 0;
        padding: 60px 16px 20px 16px;
        gap: 12px;
        transition: transform 0.25s ease;
        background: #1a1a1a;
    }

    #sidebar.open {
        transform: translateX(0);
    }

    #sidebar.collapsed {
        transform: translateX(-100%);
    }

    #sidebar.collapsed *:not(.sidebar-toggle) {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-toggle {
        display: none;
    }

    .btn-collapsed {
        display: none;
    }

    .drag-handle {
        display: none;
    }

    h2 {
        font-size: 1em;
        margin-bottom: 4px;
    }

    .controls {
        gap: 6px;
    }

    .btn {
        padding: 12px 14px;
        font-size: 0.9em;
        border-radius: 8px;
        min-height: 44px;
    }

    .sidebar-spacer {
        flex: 0;
    }

    #results {
        padding: 8px 0 0 0;
    }

    #distance span {
        font-size: 1em;
    }

    .waypoints-list {
        max-height: 150px;
    }

    .edit-name-input {
        font-size: 16px;
    }

    .edit-name-btn {
        padding: 8px 12px;
        min-height: 40px;
        min-width: 40px;
        border-radius: 6px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .edit-name-btn svg {
        width: 16px;
        height: 16px;
    }

    .point-label div {
        font-size: 10px !important;
        padding: 2px 6px !important;
    }
    .export-options {
        flex-direction: row;
    }

    .export-options {
        flex-direction: row;
    }

    .export-option {
        padding: 6px;
        font-size: 0.8em;
    }

    #points-list li {
        font-size: 0.8em;
    }

    #sidebar {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .btn:active {
        transform: scale(0.97);
    }
}

/* Карандашик и редактирование имени */
.edit-name-btn {
    cursor: pointer;
    font-size: 1.25em;
    opacity: 1;
    padding: 2px 8px;
    border-radius: 4px;
    background: #3a2a5a;
    color: #c4b5fd;
    border: 1px solid #7c3aed;
    transition: all 0.2s;
    user-select: none;
    line-height: 1;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.edit-name-btn:hover {
    background: #7c3aed;
    color: #fff;
    box-shadow: 0 0 8px rgba(124, 58, 237, 0.5);
}

.point-name {
    color: #c4b5fd;
    font-weight: 500;
}

.edit-name-input {
    background: #2a2a2a;
    border: 1px solid #7c3aed;
    border-radius: 4px;
    color: #e0e0e0;
    padding: 2px 6px;
    font-size: 0.85em;
    width: 100%;
    min-width: 0;
    flex: 1;
    outline: none;
}

.edit-name-input:focus {
    border-color: #a78bfa;
    box-shadow: 0 0 0 1px #a78bfa;
}

.mode-indicator {
    display: none;
    position: fixed;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1500;
    background: #1e1e1e;
    color: #e0e0e0;
    border: 1px solid #7c3aed;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 0.85em;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
    pointer-events: none;
}

.mode-indicator.visible {
    display: block;
}

.feedback-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feedback-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
}

.feedback-dialog {
    position: relative;
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 10px;
    padding: 20px;
    width: 90%;
    max-width: 360px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.feedback-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 0.95em;
    font-weight: 600;
    color: #e0e0e0;
}

.feedback-close {
    background: transparent;
    border: none;
    color: #888;
    font-size: 1.1em;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.15s;
}

.feedback-close:hover {
    color: #fff;
}

.feedback-textarea {
    width: 100%;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 6px;
    color: #e0e0e0;
    padding: 10px;
    font-size: 0.85em;
    font-family: inherit;
    resize: vertical;
    outline: none;
    margin-bottom: 12px;
}

.feedback-textarea:focus {
    border-color: #7c3aed;
}

.feedback-send {
    width: 100%;
    justify-content: center;
}

.feedback-status {
    margin-top: 8px;
    font-size: 0.8em;
    text-align: center;
    min-height: 1.2em;
}

.feedback-status.success {
    color: #4ade80;
}

.feedback-status.error {
    color: #f87171;
}
