/* ===== ОСНОВНЫЕ СТИЛИ И СБРОС ===== */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f5f7fa;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #333;
    transition: all 0.3s ease;
}

.divider {
    border: none;
    height: 1px;
    background-color: #ccc;
    margin: 20px 0;
}

/* ===== ШАПКА ПРИЛОЖЕНИЯ ===== */
.header {
    background: linear-gradient(135deg, #1e5799, #207cca);
    color: white;
    padding: 15px 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    position: relative;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.header h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    flex: 1;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Кнопки управления */
.panel-toggle {
    background: #f0f4f8;
    border: none;
    border-radius: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    font-size: 18px;
}

.panel-toggle:hover {
    background: #e0e8f0;
}

.location-button {
    background: #fff;
    border: none;
    border-radius: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: all 0.2s;
}

.navigate-button {
    background: linear-gradient(to right, #ff9800, #ff5722);
    border: none;
    border-radius: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
}

.export-button,
.import-button {
    background: #fff;
    border: none;
    border-radius: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: all 0.2s;
    color: #333;
    font-size: 18px;
}

.export-button:hover,
.import-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}


.mock-location-button {
    background: #6c757d;
    border: none;
    border-radius: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: all 0.2s;
    color: white;
}

.mock-location-button.active {
    background: #007bff;
    box-shadow: 0 0 15px rgba(0, 123, 255, 0.5);
}

.mock-location-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.mock-location-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.location-button:hover, .navigate-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.location-button .icon, .navigate-button .icon, .mock-location-button .icon {
    font-size: 18px;
}

/* ===== ОСНОВНОЙ КОНТЕЙНЕР (КАРТА + ПАНЕЛЬ) ===== */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden; /* предотвращает выход содержимого */
    background: #f5f7fa;
}

/* ===== КОНТЕЙНЕР КАРТЫ ===== */
#map-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    height: 100%;
    min-width: 0; /* необходимо для flex */
    border: none;
}

#map {
    width: 100%;
    height: 100%;
}

/* Вспомогательные элементы карты */
.back-button {
    display: none;
    position: absolute;
    top: 15px;
    left: 15px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 20px;
    z-index: 100;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.map-overlay {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 99;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    display: none;
    max-width: 80%;
}

/* Индикаторы загрузки и ошибок */
.location-loading {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    background: rgba(255, 255, 255, 0.9);
    padding: 15px 25px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    text-align: center;
    font-weight: 500;
}

.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 10px;
    border: 4px solid rgba(30, 87, 153, 0.2);
    border-radius: 50%;
    border-top: 4px solid #1e5799;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.location-error {
    display: none;
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: #ffebee;
    color: #c62828;
    padding: 10px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    font-weight: 500;
    max-width: 90%;
    text-align: center;
}

/* ===== ПАНЕЛЬ УПРАВЛЕНИЯ ===== */
.controls-panel {
    width: 25%;               /* 25% ширины (можно настроить) */
    max-width: 400px;         /* ограничим максимальную ширину */
    background: white;
    border-left: 1px solid #ddd;
    overflow-y: auto;
    height: 100%;
    padding: 15px;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    transition: width 0.3s ease, padding 0.3s ease, border 0.3s ease;
    /* сбрасываем мобильные ограничения */
    max-height: none;
    border-top: none;
}

/* Свернутая панель */
.controls-panel.collapsed {
    width: 0;
    padding: 0;
    overflow: hidden;
    border-left: none;
}

/* Вкладки */
.tab-controls {
    display: flex;
    margin-bottom: 15px;
    background: #f0f4f8;
    border-radius: 50px;
    padding: 3px;
}

.tab-button {
    flex: 1;
    text-align: center;
    padding: 12px;
    background: transparent;
    border: none;
    font-size: 15px;
    font-weight: 500;
    color: #666;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s;
}

.tab-button.active {
    background: white;
    color: #1e5799;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    font-weight: 600;
}

/* ===== СПИСОК АДРЕСОВ ===== */
.address-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.address-list-header h3 {
    margin: 0;
    font-size: 18px;
    color: #2c3e50;
}

.counter-badge {
    background: #e74c3c;
    color: white;
    font-size: 14px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
}

/* Чекбокс режима выделения */
.selection-mode-option {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    background: #e8f4fd;
    padding: 8px 12px;
    border-radius: 8px;
}

.selection-mode-option input {
    margin-right: 10px;
}

.selection-mode-option label {
    font-size: 14px;
    font-weight: 500;
    color: #2c3e50;
}

#address-list {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    max-height: 100%;
    overflow-y: auto;
    margin-bottom: 15px;
}

.address-item {
    padding: 15px;
    border-bottom: 1px solid #f0f4f8;
    display: flex;
    align-items: center;
    transition: background 0.2s;
    position: relative;
    padding-right: 130px;
}

.address-item:last-child {
    border-bottom: none;
}

.address-item:active {
    background-color: #f5f9ff;
}

/* Выделение в режиме выделения */
.address-item.selection-highlight {
    background-color: #c8e6c9 !important;
    border-left: 4px solid #4caf50;
}

.address-number {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #3498db;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    margin-right: 15px;
    flex-shrink: 0;
}

.address-text {
    flex: 1;
    font-size: 15px;
    line-height: 1.4;
}

.remove-item {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #e74c3c;
    font-size: 22px;
    flex-shrink: 0;
}

/* Контейнер для кнопок выбора маршрута */
.route-selectors-container {
    position: absolute;
    right: 50px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 5px;
    background: rgba(255, 255, 255, 0.9);
    padding: 5px;
    border-radius: 20px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.address-item.selected {
    background-color: #e3f2fd;
    border-left: 4px solid #2196f3;
    animation: none !important;
}

/* Анимации */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.address-item {
    animation: fadeIn 0.3s ease-out;
}

#address-list::-webkit-scrollbar {
    width: 6px;
}

#address-list::-webkit-scrollbar-thumb {
    background: #c0c0c0;
    border-radius: 3px;
}

/* ===== УПРАВЛЕНИЕ МАРШРУТОМ ===== */
.route-controls {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.route-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.route-header h3 {
    margin: 0;
    font-size: 16px;
    color: #2c3e50;
}

.route-header h4 {
    margin-left: 10px;
    font-size: 16px;
    color: #2c3e50;
    font-weight: 500;
}

.route-points {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.route-point {
    display: flex;
    align-items: center;
    padding: 10px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.route-point-content {
    flex: 1;
}

.address-header {
    justify-content: space-between;
    flex-direction: column;
    align-items: center;
    margin-bottom: 8px;
}

.address-controls {
    display: flex;
    justify-content: flex-end;
    gap: 5px;
    margin-left: 10px;
    margin-top: 15px;
}

.address-icon-container {
    display: flex;
    align-items: center;
}

.point-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    flex-shrink: 0;
    font-weight: bold;
}

.start-icon {
    background: #2ecc71;
    color: white;
}

.end-icon {
    background: #e74c3c;
    color: white;
}

.home-icon {
    background: #9b59b6;
    color: white;
}

.work-icon {
    background: #f1c40f;
    color: white;
}

.waypoint-icon {
    background: #f39c12;
    color: white;
}

.route-buttons {
    display: flex;
    gap: 10px;
}

.route-info {
    background: #e8f4fd;
    border-left: 4px solid #3498db;
    padding: 10px;
    border-radius: 0 8px 8px 0;
    margin-top: 10px;
    font-size: 14px;
    display: none;
}

.route-info-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.route-info-title {
    font-weight: 600;
    color: #2c3e50;
}

.route-info-value {
    color: #3498db;
}

.route-points-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.route-point-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.route-point-number {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #3498db;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-right: 10px;
    flex-shrink: 0;
}

.route-point-address {
    flex: 1;
    font-size: 14px;
}

.route-point-remove {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #e74c3c;
    font-size: 18px;
    cursor: pointer;
    margin-left: 5px;
}

.optimization-option {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    background: #e3f2fd;
    padding: 10px;
    border-radius: 8px;
}

.optimization-option input {
    margin-right: 10px;
}

.optimization-option label {
    font-size: 14px;
    font-weight: 500;
    color: #2c3e50;
}

.nested-catalogs-option {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    background: #e3f2fd;
    padding: 10px;
    border-radius: 8px;
}

.nested-catalogs-option input {
    margin-right: 10px;
}

.nested-catalogs-option label {
    font-size: 14px;
    font-weight: 500;
    color: #2c3e50;
}

/* ===== КНОПКИ УПРАВЛЕНИЯ ===== */
.buttons-container {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.catalog-controls {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    margin-bottom: 0;
}


/* Унифицированные кнопки */
.unified-button {
    padding: 15px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    color: white;
    cursor: pointer;
    transition: transform 0.2s, background 0.3s;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
    text-align: center;
    flex: 1;
}

.unified-button:active {
    transform: translateY(2px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.green-button {
    background: linear-gradient(to right, #00b09b, #96c93d);
}

.red-button {
    background: linear-gradient(to right, #ff416c, #ff4b2b);
}

.blue-button {
    background: linear-gradient(to right, #4b6cb7, #182848);
}

/* Унифицированные иконки управления */
.control-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    margin-right: 8px;
    transition: all 0.2s;
}

.control-icon:hover {
    transform: scale(1.1);
}

.location-icon {
    background: #3498db;
    color: white;
    border: 2px solid #2980b9;
}

.start-icon-btn {
    background: #2ecc71;
    color: white;
    border: 2px solid #27ae60;
}

.end-icon-btn {
    background: #e74c3c;
    color: white;
    border: 2px solid #c0392b;
}

.waypoint-icon-btn {
    background: #f39c12;
    color: white;
    border: 2px solid #d35400;
}

.route-icon-btn {
    background: #ff98aa;
    color: white;
    border: 2px solid #f57c00;
}

.edit-icon {
    background: #9b59b6;
    color: white;
    border: 2px solid #8e44ad;
}

.remove-icon {
    background: #f8f9fa;
    color: #e74c3c;
    border: 2px solid #e0e0e0;
    font-weight: bold;
    font-size: 18px;
}

.control-icon.selected {
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.5);
}

/* ===== КОНТЕКСТНОЕ МЕНЮ ===== */
.context-menu {
    position: absolute;
    z-index: 1000;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    width: 220px;
    display: none;
    overflow: hidden;
}

.menu-title {
    padding: 12px 15px;
    background: #f8f9fa;
    font-weight: 600;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
}

.menu-title .icon {
    margin-right: 10px;
    font-size: 18px;
}

.menu-item {
    padding: 12px 15px;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid #f5f5f5;
}

.menu-item:last-child {
    border-bottom: none;
}

.menu-item:hover {
    background: #f0f7ff;
}

.menu-item .icon {
    margin-right: 10px;
    font-size: 18px;
    width: 20px;
    text-align: center;
}

/* ===== МОДАЛЬНЫЕ ОКНА ===== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 20px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 15px;
    color: #2c3e50;
}

.modal-input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 15px;
}

#bulk-address-input {
    width: 100%;
    padding: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    min-height: 120px;
    font-size: 16px;
    margin-bottom: 15px;
    background: #f9fbfd;
}

.modal-buttons {
    display: flex;
    gap: 10px;
}

.modal-button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.modal-confirm {
    background: linear-gradient(to right, #00b09b, #96c93d);
    color: white;
}

.modal-cancel {
    background: linear-gradient(to right, #ff416c, #ff4b2b);
    color: white;
}

/* ===== КАТАЛОГИ АДРЕСОВ ===== */
.catalog-tree {
    margin-bottom: 15px;
    max-height: 100%;
    overflow-y: auto;
}

.catalog-item {
    padding: 10px 15px;
    cursor: pointer;
    border-radius: 6px;
    margin-bottom: 5px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
}

.catalog-item:hover {
    background-color: #f0f7ff;
}

.catalog-item.selected {
    background-color: #e3f2fd;
    font-weight: 600;
}

.catalog-icon {
    margin-right: 10px;
    font-size: 18px;
}

.subcatalogs {
    padding-left: 20px;
    margin-top: 5px;
    border-left: 2px solid #e0e0e0;
}

.empty-catalog {
    text-align: center;
    padding: 20px;
    color: #777;
    font-style: italic;
}

/* ===== АДАПТАЦИЯ ДЛЯ МОБИЛЬНЫХ УСТРОЙСТВ ===== */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    #map-container {
        height: 50vh;          /* как в мобильной версии */
        min-height: 0;
    }

    .controls-panel {
        width: 100%;
        max-width: none;
        border-left: none;
        border-top: 1px solid #ddd;
        max-height: 50vh;
        overflow-y: auto;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    }

    .controls-panel.collapsed {
        max-height: 0;
        width: 100%;
        padding: 0;
        border-top: none;
    }
}