/* --- Сброс и База --- */
body, html { margin: 0; padding: 0; height: 100%; width: 100%; font-family: 'Segoe UI', sans-serif; overflow: hidden; }

/* --- Карта --- */
#map { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; background: #e3e3e3; }

/* СТИЛИ МЕТОК НА КАРТЕ (НОВОЕ) */
.map-label {
    background: transparent;
    border: none;
    box-shadow: none;
    font-weight: bold;
    font-size: 11px; /* Чуть меньше для аккуратности */
    color: #333;
    text-shadow:
        -1px -1px 0 #fff,
        1px -1px 0 #fff,
        -1px 1px 0 #fff,
        1px 1px 0 #fff; /* Белая обводка текста */
    white-space: nowrap;
}

/* Стандартный тултип (при наведении) */
.leaflet-tooltip {
    white-space: pre-wrap;
    max-width: 300px;
}

/* --- Панель управления --- */
.control-panel {
    position: absolute; top: 20px; left: 20px; width: 320px;
    background: rgba(255, 255, 255, 0.95);
    padding: 15px; border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 1000; backdrop-filter: blur(5px);
}

.auth-status { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; color: #666; margin-bottom: 10px; border-bottom: 1px solid #eee; padding-bottom: 5px; }
#logout-btn { background: none; border: none; cursor: pointer; color: #dc3545; }

.input-group { display: flex; gap: 8px; margin-bottom: 10px; }
#kn-input { flex-grow: 1; padding: 8px; border: 1px solid #ccc; border-radius: 6px; outline: none; }

.primary-btn { background: #007bff; color: white; border: none; border-radius: 6px; padding: 0 12px; cursor: pointer; }
.primary-btn:hover { background: #0056b3; }

.secondary-btn { width: 100%; background: #6c757d; color: white; border: none; padding: 8px; border-radius: 6px; cursor: pointer; font-size: 0.9rem; }
.secondary-btn:hover { background: #5a6268; }

/* --- НОВЫЙ ВЫБОР ЦВЕТА (ПАЛИТРА) --- */

.color-dropdown-container {
    position: relative;
    display: flex;
    align-items: center;
}

/* Квадрат-превью (текущий цвет) */
.color-preview {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 2px solid #ccc;
    cursor: pointer;
    background-color: #FFFF00; /* Дефолт */
    transition: transform 0.1s;
}

.color-preview:hover {
    transform: scale(1.05);
    border-color: #999;
}

/* Всплывающее окно с сеткой */
.color-palette {
    position: absolute;
    top: 45px;
    left: 0;
    background: white;
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* 4 колонки */
    gap: 6px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 2000;
    width: 140px; /* Ширина палитры */
}

/* Квадратики внутри палитры */
.palette-item {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid rgba(0,0,0,0.1);
    transition: transform 0.1s;
}

.palette-item:hover {
    transform: scale(1.2);
    z-index: 2;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.palette-item.active {
    border: 2px solid #333;
    transform: scale(1.1);
}

.settings-row { margin-bottom: 10px; font-size: 0.9rem; display: flex; justify-content: space-between; align-items: center; }
.toggle-switch { display: flex; align-items: center; cursor: pointer; }
.toggle-switch input { display: none; }
.slider { width: 36px; height: 20px; background-color: #ccc; border-radius: 34px; position: relative; margin-right: 10px; transition: .4s; }
.slider:before { content: ""; position: absolute; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: white; border-radius: 50%; transition: .4s; }
input:checked + .slider { background-color: #007bff; }
input:checked + .slider:before { transform: translateX(16px); }

.clear-btn { background: none; border: none; color: #dc3545; cursor: pointer; font-size: 1rem; }
.clear-btn:hover { color: #a71d2a; }

.confirm-box { margin-top: 10px; border: 1px solid #ddd; padding: 10px; border-radius: 6px; background: #f8f9fa; }
.file-name { font-weight: bold; font-size: 0.85rem; margin-bottom: 8px; word-break: break-all; }
.process-btn { width: 100%; background: #28a745; color: white; border: none; padding: 8px; border-radius: 6px; cursor: pointer; font-weight: bold; }
.process-btn:hover { background: #218838; }

.status-box { margin-top: 10px; padding: 10px; border-radius: 6px; font-size: 0.9rem; }
.status-box.loading { background: #e2e3e5; color: #383d41; }
.status-box.success { background: #d4edda; color: #155724; }
.status-box.error { background: #f8d7da; color: #721c24; }
.hidden { display: none !important; }

.download-link { display: block; background: #17a2b8; color: white; text-align: center; padding: 6px; border-radius: 6px; text-decoration: none; font-size: 0.85rem; margin-top: 5px; }
.report-link { background: #6f42c1; }

.layer-control { position: absolute; top: 20px; right: 20px; width: 250px; background: white; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); z-index: 1000; overflow: hidden; max-height: 90vh; display: flex; flex-direction: column; }
.layer-header { padding: 12px; background: #f8f9fa; cursor: pointer; font-weight: bold; display: flex; justify-content: space-between; border-bottom: 1px solid #ddd; }
.layer-content { padding: 10px; overflow-y: auto; background: white; }
.layer-control.collapsed .layer-content { display: none; }
.layer-category summary { cursor: pointer; font-weight: 600; padding: 5px 0; list-style: none; }

.drop-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 123, 255, 0.85); z-index: 2000; display: none; flex-direction: column; justify-content: center; align-items: center; color: white; backdrop-filter: blur(3px); pointer-events: none; }
.drop-overlay.active { display: flex; pointer-events: all; }

/* ... (Весь ваш предыдущий код оставляем) ... */

/* --- Стили для списка истории (НОВОЕ) --- */
.history-container {
    margin-top: 15px;
    border-top: 1px solid #eee;
    padding-top: 10px;
}

.history-header {
    font-size: 0.9rem;
    font-weight: bold;
    color: #555;
    margin-bottom: 5px;
}

.history-list {
    max-height: 150px; /* Ограничиваем высоту, чтобы не растягивать панель */
    overflow-y: auto;
    border: 1px solid #eee;
    border-radius: 6px;
    background: #fdfdfd;
    margin-bottom: 8px;
}

.history-item {
    padding: 6px 10px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.history-item:hover {
    background-color: #e9ecef;
}

.history-item:last-child {
    border-bottom: none;
}

.history-item .kn-text {
    font-weight: 500;
}

.history-item .item-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.1);
    margin-left: 8px;
}

.download-all-btn {
    width: 100%;
    background: #17a2b8; /* Cyan */
    color: white;
    border: none;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: bold;
}

.download-all-btn:hover {
    background: #138496;
}

/* --- ИСТОРИЯ И СПИСКИ (ОБНОВЛЕНО) --- */
.history-container {
    margin-top: 15px;
    border-top: 1px solid #eee;
    padding-top: 10px;
    display: flex;
    flex-direction: column;
    max-height: 40vh; /* Ограничение высоты контейнера */
}

.history-header {
    font-size: 0.9rem;
    font-weight: bold;
    color: #555;
    margin-bottom: 5px;
}

.history-list {
    overflow-y: auto;
    border: 1px solid #eee;
    border-radius: 6px;
    background: #fdfdfd;
    margin-bottom: 8px;
    padding: 0;
}

/* Одиночный элемент или строка в списке */
.history-item {
    padding: 6px 10px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    transition: background 0.2s;
}

.history-item:hover {
    background-color: #e9ecef;
}

.history-item:last-child {
    border-bottom: none;
}

/* Кликабельная часть (название) */
.item-label {
    flex-grow: 1;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 10px;
}

.kn-text { font-weight: 500; }

/* Кружок цвета */
.item-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.1);
    margin-right: 8px;
    flex-shrink: 0;
}

/* Кнопка скачивания (справа) */
.download-icon-btn {
    background: none;
    border: none;
    color: #6c757d;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    flex-shrink: 0;
}

.download-icon-btn:hover {
    color: #007bff;
    background-color: rgba(0, 123, 255, 0.1);
}

/* --- СТИЛИ ДЛЯ ПАПОК (ГРУПП) --- */
.history-group {
    border-bottom: 1px solid #f0f0f0;
}

.history-group summary {
    padding: 6px 10px;
    cursor: pointer;
    background-color: #f8f9fa;
    font-size: 0.85rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    list-style: none; /* Убираем стандартный треугольник */
}

/* Кастомная стрелка для summary */
.history-group summary::before {
    content: '►';
    font-size: 0.7rem;
    margin-right: 8px;
    transition: transform 0.2s;
    color: #666;
}
.history-group[open] summary::before {
    transform: rotate(90deg);
}

.group-header-content {
    flex-grow: 1;
    display: flex;
    align-items: center;
}

/* Вложенный список */
.group-items {
    padding-left: 20px; /* Отступ для вложенности */
    background: white;
}

.group-items .history-item {
    border-bottom: 1px solid #f9f9f9;
}


/* Убираем синюю/черную рамку вокруг полигона при клике */
path.leaflet-interactive:focus {
    outline: none;
}