/* =========================================
   1. ПЕРЕМЕННЫЕ И ТЕМЫ (Добавлена Контрастная)
   ========================================= */
:root {
    --bg-main: #f4f4f5;
    --bg-panel: #ffffff;
    --bg-input: #f4f4f5;
    --text-main: #1d1d1f;
    --text-muted: #86868b;
    --border-color: #e5e5ea;
    --primary: #007aff;
    --fab-bg: #ffffff;
}
[data-theme="dark"] {
    --bg-main: #000000;
    --bg-panel: #1c1c1e;
    --bg-input: #2c2c2e;
    --text-main: #f5f5f7;
    --text-muted: #98989d;
    --border-color: #38383a;
    --fab-bg: #2c2c2e;
}
[data-theme="contrast"] {
    --bg-main: #000000;
    --bg-panel: #1c1c1e;
    --bg-input: #000000;
    --text-main: #ffffff;
    --text-muted: #ffff00; /* Яркий желтый для muted текстов */
    --border-color: #ffffff;
    --primary: #ffffff; /* Белые кнопки для максимального контраста */
    --fab-bg: #1c1c1e;
}

/* =========================================
   2. БАЗОВЫЕ НАСТРОЙКИ СТРАНИЦЫ
   ========================================= */
body, html { margin: 0; padding: 0; height: 100dvh; font-family: -apple-system, BlinkMacSystemFont, sans-serif; overflow: hidden; background-color: var(--bg-main); color: var(--text-main); -webkit-tap-highlight-color: transparent;}
.wrapper { display: flex; height: 100dvh; width: 100%; position: relative; }

/* =========================================
   3. БОКОВОЕ МЕНЮ (Десктоп)
   ========================================= */
.sidebar-nav { width: 72px; min-width: 72px; height: 100%; background-color: var(--bg-panel); border-right: 1px solid var(--border-color); display: flex; flex-direction: column; align-items: center; padding-top: 15px; z-index: 1020; }
.nav-tab { width: 100%; display: flex; flex-direction: column; align-items: center; padding: 14px 0; cursor: pointer; color: var(--text-muted); transition: 0.2s; border-left: 3px solid transparent; }
.nav-tab.active { color: var(--primary); border-left-color: var(--primary); background: rgba(0, 122, 255, 0.05); }
.nav-tab .icon { font-size: 20px; margin-bottom: 6px; }
.nav-tab .label { font-size: 10px; font-weight: 700; text-transform: uppercase; }

/* =========================================
   4. КОНТЕЙНЕР ДЛЯ ПАНЕЛЕЙ (Шторка)
   ========================================= */
.sidebar-content { width: 380px; min-width: 380px; height: 100%; background-color: var(--bg-panel); z-index: 1010; display: flex; flex-direction: column; position: relative; border-right: 1px solid var(--border-color); transition: height 0.3s cubic-bezier(0.25, 1, 0.5, 1); }
.panel { display: none !important; padding: 15px; flex-grow: 1; overflow-y: auto; flex-direction: column; height: 100%; box-sizing: border-box;}
.panel.active { display: flex !important; }

/* =========================================
   5. ЭЛЕМЕНТЫ UI (Поиск, Опции)
   ========================================= */
.search-wrapper { position: relative; margin-bottom: 15px; display: flex; align-items: center; flex-shrink: 0; }
.search-box { width: 100%; padding: 14px 45px 14px 40px; border-radius: 12px; border: 1px solid var(--border-color); background-color: var(--bg-input); font-size: 15px; outline: none; box-sizing: border-box; color: var(--text-main); font-weight: 500; }
.search-icon { position: absolute; left: 12px; font-size: 16px; color: var(--text-muted);}
.mic-icon { position: absolute; right: 10px; font-size: 18px; color: var(--primary); cursor: pointer; padding: 5px;}
.quick-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 15px; }
.chip-btn { background: var(--bg-panel); border: 1px solid var(--border-color); padding: 8px 12px; border-radius: 16px; font-size: 13px; color: var(--text-main); cursor: pointer; font-weight: 600; }
.chip-btn.chip-active { background: #34c759; color: #fff; border-color: #34c759; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; font-weight: 600; text-transform: uppercase;}
.form-input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border-color); background: var(--bg-input); font-size: 15px; outline: none; color: var(--text-main); font-weight: 500;}
.checkbox-group { display: flex; flex-direction: column; gap: 8px; }
.cb-card { display:flex; align-items:center; gap:10px; padding:12px; background:var(--bg-input); border-radius:12px; border: 1px solid var(--border-color); cursor: pointer;}
.cb-card input { width: 20px; height: 20px; }

/* =========================================
   6. МАРШРУТЫ
   ========================================= */
.route-tabs { display: flex; justify-content: space-between; background: var(--bg-input); padding: 4px; border-radius: 12px; margin-bottom: 15px;}
.r-tab { flex: 1; text-align: center; font-size: 20px; padding: 8px 0; cursor: pointer; border-radius: 10px; color: var(--text-muted); transition: 0.2s;}
.r-tab.active { background: var(--bg-panel); color: var(--primary); box-shadow: 0 2px 6px rgba(0,0,0,0.05);}

/* Контейнер маршрутов */
.route-input-group {
    background: var(--bg-input);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
    position: relative;
}

/* Строка с точкой */
.route-point {
    display: flex;
    align-items: center;
    padding: 12px 45px 12px 60px; /* КРИТИЧНО: 60px слева под реверс, 45px справа под крестик */
    position: relative;
    cursor: pointer;
}
.route-point:first-child {
    border-bottom: 1px solid var(--border-color);
}

/* Поле ввода */
.route-input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    font-size: 15px;
    color: var(--text-main);
    outline: none;
    pointer-events: none;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

/* Крестики очистки (✕) - возвращаем в правый край */
.clear-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: var(--text-muted);
    padding: 4px;
    z-index: 5;
}
.clear-btn:hover { color: #ff3b30; }

/* Кнопка реверса (⇅) - переносим в левый край */
.swap-btn {
    position: absolute;
    left: 12px; /* Было right: 12px */
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    color: var(--text-muted);
    transition: 0.2s;
    z-index: 10;
}
.swap-btn:hover { color: var(--primary); }

/* === ПРОФЕССИОНАЛЬНЫЕ НАСТРОЙКИ ДОСТУПНОСТИ === */
.accessibility-settings { display: flex; flex-direction: column; gap: 12px; }
.accessibility-settings .group-title { font-size: 11px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 2px; margin-left: 5px;}

/* Обертка для аккордеона */
.need-card-wrapper { background: var(--bg-input); border-radius: 14px; border: 1px solid var(--border-color); overflow: hidden; transition: 0.3s ease; }
.need-card-wrapper:focus-within { border-color: var(--primary); }

/* Основная карточка */
.need-card { display: flex; align-items: center; padding: 14px; position: relative; z-index: 2; background: var(--bg-input); }
.need-icon { font-size: 24px; width: 32px; text-align: center; flex-shrink: 0; }
.need-info { flex-grow: 1; display: flex; flex-direction: column; gap: 2px; padding-right: 55px; }
.need-name { font-weight: 700; font-size: 15px; color: var(--text-main); }
.need-desc { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

/* Скрытое подменю с функциями */
.need-sub-options { display: none; padding: 12px 14px 14px 58px; flex-direction: column; gap: 12px; border-top: 1px solid var(--border-color); background: rgba(0,0,0,0.02); }
.need-card-wrapper.expanded .need-sub-options { display: flex; animation: fadeIn 0.3s ease; }

/* Дизайн внутренних чекбоксов */
.sub-option-label { font-size: 13px; color: var(--text-main); display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.sub-option-label input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; margin: 0; }

/* === СТИЛИЗАЦИЯ SWITCH (ПЕРЕКЛЮЧАТЕЛЯ) === */
.switch { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); width: 44px; height: 26px; flex-shrink: 0; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; } /* Скрываем сам чекбокс */

.slider { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border-color); transition: .3s; border-radius: 26px; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.15); }

/* Состояния вкл/выкл */
input:checked + .slider { background-color: #34c759; /* Зеленый Apple стиль */ }
input:focus + .slider { box-shadow: 0 0 1px #34c759; }
input:checked + .slider:before { transform: translateX(18px); }

.route-result-box { display: none; padding: 15px; background: var(--bg-input); border-radius: 16px; text-align: center;}
#routeTime { margin:0 0 5px 0; font-weight:800; font-size:24px; color: var(--primary); }
#routeDist { margin:0; color:var(--text-muted); font-size:14px; }
.action-buttons { display: flex; gap: 8px; margin-top: 15px; }
.start-nav-btn { flex: 2; padding: 14px; background: #34c759; color: white; border: none; border-radius: 12px; font-weight: 700; cursor: pointer; }
.reset-btn { flex: 1; padding: 14px; background: var(--border-color); color: var(--text-main); border: none; border-radius: 12px; font-weight: 600; cursor: pointer;}
/* =========================================
   7. СОВМЕЩЕННЫЙ СПИСОК / КАРТОЧКА ДЕТАЛЕЙ
   ========================================= */
.results-list { flex-grow: 1; display: flex; flex-direction: column; gap: 8px; padding-bottom: 20px; }
.result-item { padding: 14px; border-radius: 14px; background: var(--bg-input); cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.result-title { font-weight: 700; font-size: 15px; color: var(--text-main); }
.result-desc { font-size: 12px; color: var(--text-muted); }
/* === КАРТОЧКА ДЕТАЛЕЙ ЗАВЕДЕНИЯ === */
.place-detail-card {
    background: var(--bg-panel);
    border-radius: 16px;
    margin-top: 10px;
    border: 1px solid var(--border-color);
    overflow: hidden; /* Важно: обрезает углы у фото */
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    position: relative;
}

/* Кнопка закрытия поверх фото */
.place-detail-card .close-card {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0,0,0,0.5);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    cursor: pointer;
    color: white;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(4px);
    transition: 0.2s;
}
.place-detail-card .close-card:hover { background: #ff3b30; }

/* Обложка и фото */
.card-cover { position: relative; width: 100%; height: 150px; background: #e5e5ea; }
.card-cover img { width: 100%; height: 100%; object-fit: cover; }

/* Бейджи поверх фото */
.card-badges { position: absolute; bottom: 12px; left: 12px; display: flex; gap: 6px; flex-wrap: wrap; z-index: 2; }
.badge { padding: 6px 10px; border-radius: 8px; font-size: 11px; font-weight: 700; color: white; backdrop-filter: blur(4px); box-shadow: 0 2px 4px rgba(0,0,0,0.3); }
.badge-green { background: rgba(52, 199, 89, 0.85); }
.badge-orange { background: rgba(255, 149, 0, 0.85); }
.badge-red { background: rgba(255, 59, 48, 0.85); }
.badge-purple { background: rgba(175, 82, 222, 0.85); }

/* Контентная часть */
.card-content { padding: 16px; }
.card-title { margin: 0 0 6px 0; font-size: 18px; font-weight: 800; color: var(--text-main); }
.card-meta { font-size: 12px; font-weight: 700; color: var(--primary); margin-bottom: 10px; }
.card-desc { margin: 0 0 16px 0; font-size: 13px; color: var(--text-muted); line-height: 1.5; }

/* Кнопка навигации */
.start-nav-btn { width: 100%; padding: 14px; background: #34c759; color: white; border: none; border-radius: 12px; font-weight: 700; cursor: pointer; font-size: 15px; transition: 0.2s; box-shadow: 0 2px 8px rgba(52, 199, 89, 0.2);}
.start-nav-btn:hover { background: #28a745; transform: translateY(-1px); }.accessibility-badge { display: block; padding: 8px; background: #34c759; color: white; border-radius: 8px; font-size: 11px; font-weight: 600; line-height: 1.4; }
.accessibility-badge.partial { background: #ff9500; }
.accessibility-badge.none { background: #ff3b30; }

/* =========================================
   8. КАРТА И КОНТРОЛЫ
   ========================================= */
#map-container { flex-grow: 1; height: 100%; position: relative; }
#map { height: 100%; width: 100%; background-color: var(--border-color); }
.map-controls-right { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); z-index: 200; display: flex; flex-direction: column; gap: 10px; transition: 0.3s; }
.map-btn-group { background: var(--fab-bg); border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); display: flex; flex-direction: column; border: 1px solid var(--border-color); }
.map-btn { width: 40px; height: 40px; display: flex; justify-content: center; align-items: center; cursor: pointer; font-weight: 600; color: var(--text-main); border-bottom: 1px solid var(--border-color);}
.map-fab { width: 40px; height: 40px; background: var(--fab-bg); border-radius: 50%; display: flex; justify-content: center; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1); cursor: pointer; border: 1px solid var(--border-color); color: var(--text-main);}
.map-fab-ai { width: 40px; height: 40px; border-radius: 50%; display: flex; justify-content: center; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1); cursor: pointer; border: 1px solid #ffeeba;}
.map-fab:last-child { border-bottom: none; }
.custom-icon-wrapper { border-radius: 50%; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border: 2px solid white; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,0.3);}
.gps-pulse { width: 18px; height: 18px; background: #007aff; border-radius: 50%; border: 3px solid white; box-shadow: 0 0 10px rgba(0,122,255,0.6); pointer-events: none; }

/* Уведомления */
#toast-container { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 8px; width: 90%; max-width: 320px; text-align: center; pointer-events: none;}
.toast { background-color: rgba(28, 28, 30, 0.9); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px; font-weight: 500; animation: fadeIn 0.3s;}
.hidden-overlay { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background: #ff3b30; color: white; padding: 12px 24px; border-radius: 20px; font-weight: bold; display: none; z-index: 9999;}
.mobile-drag-handle { display: none; }
.mobile-bottom-nav { display: none; }

/* ИИ Оверлей */
.traffic-overlay { position:fixed; top:0; left:0; width:100vw; height:100dvh; background:#000; z-index:9999; display:none; flex-direction:column; align-items:center; justify-content:center; }
.camera-feed { width:100%; height:100%; object-fit:cover; position:absolute; top:0; left:0; }
.traffic-info { position:absolute; bottom:120px; background:rgba(0,0,0,0.7); padding:20px; border-radius:20px; text-align:center; width:80%; border:2px solid #ffcc00; backdrop-filter:blur(10px); }
.traffic-icon { font-size:40px; margin-bottom:10px; }
.traffic-text { color:white; font-size:18px; font-weight:700; }
.traffic-close { position:absolute; bottom:40px; background:#ff3b30; color:white; padding:16px 30px; border-radius:24px; font-size:18px; font-weight:bold; border:none; }

/* =========================================
   9. МОБИЛЬНАЯ АДАПТАЦИЯ (Шторка, Таб-бар)
   ========================================= */
@media (max-width: 768px) {
    .wrapper { flex-direction: column; }
    .sidebar-nav { display: none; } /* Скрываем левое меню */

    .mobile-bottom-nav {
        display: flex; position: fixed; bottom: 0; left: 0; width: 100%; height: 70px;
        background: var(--bg-panel); border-top: 1px solid var(--border-color);
        z-index: 1050; justify-content: space-around; align-items: center;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .mob-nav-item { flex: 1; text-align: center; color: var(--text-muted); font-size: 10px; font-weight: 700; text-transform: uppercase; padding: 8px 0; cursor: pointer;}
    .mob-nav-item .icon { font-size: 22px; display: block; margin-bottom: 4px; }
    .mob-nav-item.active { color: var(--primary); }

    .sidebar-content {
        width: 100% !important; min-width: 100% !important;
        position: fixed; top: auto; bottom: 70px; left: 0; height: 145px;
        border-radius: 20px 20px 0 0; border-right: none; box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
        transition: height 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    }
    .sidebar-content.state-collapsed { height: 145px; }
    .sidebar-content.state-half { height: 50dvh; }
    .sidebar-content.state-full { height: 90dvh; }

    .mobile-drag-handle { display: flex; width: 100%; height: 24px; cursor: grab; justify-content: center; align-items: center; }
    .mobile-drag-handle::after { content: ''; width: 36px; height: 5px; background: var(--border-color); border-radius: 3px; }
    .map-controls-right { bottom: 230px; top: auto; transform: none;}
}

/* === КНОПКА ЗАВЕРШЕНИЯ НАВИГАЦИИ === */
.stop-nav-btn {
    display: none; /* Скрыта по умолчанию */
    position: absolute;
    bottom: 40px; /* Висит внизу по центру */
    left: 50%;
    transform: translateX(-50%);
    background: #ff3b30;
    color: white;
    padding: 16px 32px;
    border-radius: 30px;
    font-size: 16px;
    font-weight: 800;
    border: none;
    box-shadow: 0 4px 15px rgba(255, 59, 48, 0.4);
    z-index: 2000;
    cursor: pointer;
    transition: 0.2s;
}
.stop-nav-btn:hover {
    background: #d70015;
    transform: translateX(-50%) scale(1.05);
}

.hidden-overlay {
    display: none;
    transition: opacity 0.3s ease;
}
.form-input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-sizing: border-box;
}