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

html, body {
    height: 100%;
    font-family: sans-serif;
}

.app {
    display: flex;
    height: 100vh;
}

.map-pane {
    flex: 1 1 0;
    min-width: 0;
}

#map {
    width: 100%;
    height: 100%;
}

.sidebar {
    width: 320px;
    flex-shrink: 0;
    background: #f5f5f5;
    border-left: 1px solid #ddd;
    overflow-y: auto;
    padding: 16px;
}

.sidebar-empty {
    color: #999;
    font-size: 13px;
}

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

.sb-title {
    font-size: 14px;
    font-weight: 600;
    color: #222;
}

.sb-desc {
    font-size: 12px;
    color: #555;
}

.sb-btn {
    display: inline-block;
    padding: 6px 14px;
    background: #1565c0;
    color: #fff;
    font-size: 13px;
    text-decoration: none;
    border-radius: 4px;
    align-self: flex-start;
}

.sb-btn:hover { background: #0d47a1; }
.sb-btn-danger { background: #c0392b; }
.sb-btn-danger:hover { background: #96281b; }

.sb-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* Шапка сайдбара с кнопкой закрытия */
.sb-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.sb-close {
    flex-shrink: 0;
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #999;
    line-height: 1;
    padding: 0;
}

.sb-close:hover { color: #333; }

/* Начальный экран сайдбара */
.sb-default { display: flex; flex-direction: column; gap: 12px; }
.sb-default-hint { font-size: 12px; color: #777; line-height: 1.5; }
.sb-default-group { display: flex; flex-direction: column; gap: 6px; }
.sb-default-group-title { font-size: 11px; color: #aaa; text-transform: uppercase; letter-spacing: .5px; }
.sb-add-item {
    padding: 6px 10px;
    background: #f0f4ff;
    border: 1px solid #d0d8f0;
    cursor: pointer;
    font-size: 12px;
    text-align: left;
    color: #1565c0;
}
.sb-add-item:hover { background: #e0eaff; }
.sb-add-sub { padding-left: 20px; }

/* Режим ожидания клика */
.sb-waiting { font-size: 12px; color: #555; line-height: 1.6; }
.sb-waiting b { color: #1565c0; }

/* Режим редактирования маршрута кабеля */
.cable-edit-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cable-edit-hint {
    font-size: 12px;
    color: #555;
    line-height: 1.5;
    padding: 8px 10px;
    background: #fff8e1;
    border-left: 3px solid #f9a825;
}

.cable-edit-points {
    list-style: none;
    margin: 0; padding: 0;
    max-height: 200px;
    overflow-y: auto;
}

.cable-edit-points li {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 4px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 12px;
}

.cable-edit-points li.locked {
    color: #999;
}

.cable-edit-points li .pt-num {
    color: #aaa;
    min-width: 18px;
    font-size: 11px;
}

.cable-edit-points li .pt-label { flex: 1; }

/* Кнопки точек — крупные для тача */
.pt-btn {
    min-width: 32px;
    min-height: 32px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    flex-shrink: 0;
}

.pt-btn-del  { background: #fdecea; color: #c0392b; }
.pt-btn-add  { background: #e8f5e9; color: #2e7d32; }
.pt-btn:disabled { opacity: 0.3; cursor: default; }

/* Маркер точки редактирования на карте */
.edit-pt-marker {
    width: 20px; height: 20px;
    border-radius: 50%;
    border: 3px solid #e67e22;
    background: #fff;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    color: #e67e22;
    box-shadow: 0 1px 4px rgba(0,0,0,.3);
}

.edit-pt-marker.locked {
    border-color: #999;
    color: #999;
    cursor: default;
}

.edit-pt-marker.adding {
    border-color: #2e7d32;
    color: #2e7d32;
    border-style: dashed;
}

/* Таблица волокон типа кабеля */
.fiber-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.fiber-table th { text-align: left; padding: 4px 6px; color: #888; font-weight: normal; border-bottom: 1px solid #eee; }
.fiber-table td { padding: 4px 6px; border-bottom: 1px solid #f5f5f5; vertical-align: middle; }
.fiber-swatch {
    display: inline-block; width: 28px; height: 16px;
    border: 1px solid rgba(0,0,0,.2); border-radius: 2px;
    vertical-align: middle; font-size: 10px; line-height: 16px;
    text-align: center;
}
.fiber-stripe-input { width: 48px; padding: 2px 4px; font-size: 12px; border: 1px solid #ccc; }
.fiber-row-del { background: none; border: none; color: #c0392b; cursor: pointer; font-size: 14px; padding: 0 4px; }
.fiber-add-row { font-size: 12px; color: #1565c0; cursor: pointer; background: none; border: none; padding: 4px 0; }

/* Форма кабеля */
.sb-route-list {
    font-size: 11px; color: #555;
    margin: 4px 0;
    max-height: 120px;
    overflow-y: auto;
}
.sb-route-list li {
    padding: 2px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
}
.sb-route-remove {
    background: none; border: none;
    color: #c0392b; cursor: pointer;
    font-size: 13px; line-height: 1;
    padding: 0 2px; flex-shrink: 0;
}

.sb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 4px;
}

.sb-table td {
    padding: 4px 0;
    vertical-align: top;
    border-bottom: 1px solid #e8e8e8;
}

.sb-table td:first-child {
    color: #888;
    width: 45%;
    padding-right: 8px;
}

/* Строка select + кнопка добавления */
.sb-field-row { display: flex; gap: 4px; align-items: center; }
.sb-field-row select { flex: 1; }
.sb-add-btn {
    flex-shrink: 0;
    width: 24px; height: 24px;
    background: #1565c0; color: #fff;
    border: none; cursor: pointer;
    font-size: 16px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
}
.sb-add-btn:hover { background: #0d47a1; }
.sb-add-btn:disabled { background: #bbb; cursor: default; }

/* Форма добавления дома в сайдбаре */
.sb-form { display: flex; flex-direction: column; gap: 10px; }
.sb-form label { font-size: 11px; color: #666; display: block; margin-bottom: 3px; }
.sb-form select,
.sb-form input[type="text"] {
    width: 100%; padding: 5px 7px; font-size: 12px;
    border: 1px solid #ccc; box-sizing: border-box;
}
.sb-form .sb-form-row { display: flex; gap: 6px; }
.sb-form .sb-form-row > div { flex: 1; }
.sb-form-hint { font-size: 11px; color: #888; }

/* Контекстное меню карты */
.map-ctx-menu {
    position: absolute;
    z-index: 1000;
    background: #fff;
    border: 1px solid #ccc;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
    min-width: 160px;
    font-size: 13px;
}
.map-ctx-menu ul { list-style: none; margin: 0; padding: 4px 0; }
.map-ctx-menu li { padding: 7px 14px; cursor: pointer; }
.map-ctx-menu li:hover { background: #f0f4ff; }

.ctx-has-sub { position: relative; }
.ctx-submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: -4px;
    background: #fff;
    border: 1px solid #ccc;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
    min-width: 160px;
    list-style: none;
    margin: 0; padding: 4px 0;
    z-index: 1001;
}
.ctx-has-sub:hover .ctx-submenu { display: block; }

.sb-hint {
    font-size: 12px; color: #555; padding: 10px;
    background: #fff8e1; border-left: 3px solid #f9a825;
    line-height: 1.5;
}
.sb-hint b { color: #222; }

/* карта в режиме перемещения */
.map-moving { cursor: crosshair !important; }

@media (max-width: 640px) {
    .app { flex-direction: column; }
    .map-pane { flex: 0 0 50vh; }
    .sidebar { width: 100%; flex: 1 1 0; border-left: none; border-top: 1px solid #ddd; }
}

/* Сброс дефолтных стилей Leaflet divIcon */
.leaflet-div-icon {
    background: none !important;
    border: none !important;
}

/* Выделенный маркер — белая обводка */
.mk-selected {
    outline: 2px solid #fff;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px #e53935;
    z-index: 9999 !important;
}

/* ── Map markers ── */
.mk {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,.4);
}

/* krep_node types */
.mk-stolb  { background: #555; }
.mk-truba  { background: #888; border-radius: 2px; }
.mk-anker  { background: #333; width: 6px; height: 6px; border-radius: 0; transform: rotate(45deg); }
.mk-point  { background: #aaa; width: 5px; height: 5px; border: 1px solid #777; }
.mk-kolod  { background: #4a90d9; border-radius: 2px; }

/* box */
.mk-box {
    width: 14px; height: 14px;
    background: #e53935;
    border-radius: 2px;
    border: 2px solid rgba(0,0,0,.35);
}

/* muft */
.mk-muft {
    width: 14px; height: 14px;
    background: #e53935;
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,.35);
}

/* house */
.mk-house {
    width: 14px; height: 14px;
    background: #27ae60;
    border-radius: 2px;
    border: 2px solid rgba(0,0,0,.3);
}
