body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 20px; background: #f0f2f5; }
.container { max-width: 1400px; margin: 0 auto; }
.toolbar { margin-bottom: 20px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
button { padding: 8px 16px; background: #2c3e50; color: white; border: none; border-radius: 6px; cursor: pointer; }
button:hover { background: #1e2b37; }
button:disabled { background: #95a5a6; cursor: not-allowed; }
#fileInput { display: none; }
.status { padding: 10px 15px; background: #fff8e5; border-left: 5px solid #f1c40f; margin-bottom: 20px; }
.info-panels { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.panel { background: white; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); overflow: hidden; }
.panel-header { background: #e9ecef; padding: 10px 15px; font-weight: 600; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.panel-header:hover { background: #dee2e6; }
.panel-header .toggle-icon { font-size: 1.2em; }
.panel-content { padding: 15px; border-top: 1px solid #ddd; display: none; }
.panel-content.visible { display: block; }
.photos-grid { display: flex; gap: 15px; flex-wrap: wrap; align-items: flex-start; }
.photo-item { text-align: center; }
.photo-item img { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; border: 2px solid #ccc; background: #f8f9fa; display: block; }
.photo-item .path { font-family: monospace; font-size: 11px; margin-top: 4px; color: #495057; max-width: 80px; word-break: break-all; }
.dot-code { background: #f8f9fa; padding: 10px; border-radius: 6px; font-family: 'Courier New', monospace; font-size: 13px; white-space: pre-wrap; border: 1px solid #ced4da; width: 100%; box-sizing: border-box; min-height: 100px; resize: vertical; }
.dot-code-find-replace { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; padding: 8px; background: #f0f2f5; border-radius: 6px; border: 1px solid #ced4da; }
.dot-find-input { padding: 6px 10px; border: 1px solid #ced4da; border-radius: 4px; font-family: 'Courier New', monospace; font-size: 13px; width: 100%; box-sizing: border-box; }
.dot-find-buttons { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.dot-find-buttons button { padding: 5px 10px; font-size: 12px; }
.dot-find-status { font-size: 12px; color: #e74c3c; font-style: italic; }
.dot-code-toolbar { display: flex; gap: 10px; margin-top: 8px; align-items: center; }
.link-box { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.link-box input { flex: 1; min-width: 300px; padding: 8px; border: 1px solid #ced4da; border-radius: 4px; font-family: monospace; font-size: 13px; background: #f8f9fa; }
.link-box button { padding: 6px 12px; font-size: 13px; }
footer { margin-top: 25px; text-align: center; color: #5d6d7e; font-size: 0.9rem; }

/* Diagram panel */
.diagram-panel { background: white; border-radius: 8px; box-shadow: 0 5px 20px rgba(0,0,0,0.1); overflow: hidden; margin-bottom: 20px; display: flex; flex-direction: column; }
.diagram-panel-header { background: #e9ecef; padding: 10px 15px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.diagram-panel-title { font-size: 1.05em; }

/* Zoom container */
.zoom-container {
    position: relative;
    overflow: auto;
    min-height: 500px;
    max-height: 80vh;
    background: white;
    padding: 10px;
    flex: 1;
}
.zoom-content {
    transform-origin: top left;
    transition: transform 0.15s ease;
    display: inline-block;
}
.zoom-content svg {
    display: block;
}

/* Zoom controls — at the bottom of diagram panel */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 15px;
    background: #f5f5f5;
    border-top: 1px solid #ddd;
}
.zoom-controls button {
    padding: 5px 12px;
    font-size: 14px;
    background: #607D8B;
}
.zoom-controls button:hover { background: #455A64; }
.zoom-controls button:disabled { background: #95a5a6; cursor: not-allowed; }
.zoom-controls span {
    min-width: 50px;
    text-align: center;
    font-weight: bold;
    color: #333;
    font-size: 13px;
}
.zoom-controls .zoom-separator {
    width: 1px;
    height: 20px;
    background: #ccc;
    margin: 0 8px;
    min-width: 1px;
}

/* Properties panel (Свойство объекта диаграммы) */
#properties-panels-container {
    position: fixed;
    top: 0; left: 0;
    width: 0; height: 0;
    pointer-events: none;
    z-index: 2000;
}
.properties-panel {
    position: fixed;
    background: white;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    min-width: 280px;
    max-width: 400px;
    pointer-events: all;
    z-index: 2000;
}
.properties-panel.visible { display: block; }
.properties-header {
    background: #2c3e50;
    color: white;
    padding: 10px 12px;
    border-radius: 8px 8px 0 0;
    cursor: move;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}
.properties-header-content { flex: 1; }
.properties-header-title { font-size: 11px; opacity: 0.8; margin-bottom: 4px; }
.properties-header h3 { margin: 0; font-size: 14px; font-weight: 600; }
.properties-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.8;
}
.properties-close-btn:hover { opacity: 1; background: none; }
.properties-content {
    padding: 12px;
    max-height: 400px;
    overflow-y: auto;
}
.property-item { margin-bottom: 8px; }
.property-predicate { font-size: 11px; color: #666; text-transform: uppercase; margin-bottom: 2px; }
.property-value { font-size: 13px; color: #333; word-break: break-all; }
.property-value.photo { margin-top: 6px; }
.property-value.photo img { width: 80px; height: 80px; object-fit: cover; border-radius: 6px; border: 2px solid #ccc; }
.properties-empty { color: #888; font-style: italic; font-size: 13px; }
.properties-copy-btn {
    background: #607D8B;
    padding: 3px 8px;
    font-size: 11px;
    border-radius: 4px;
    margin-top: 4px;
    cursor: pointer;
}
.properties-copy-btn:hover { background: #455A64; }

/* Node hover/selected style */
.node { cursor: pointer; }
.node:hover polygon, .node:hover ellipse, .node:hover path, .node:hover rect {
    stroke-width: 3 !important;
    stroke: #e67e22 !important;
}
.node.selected polygon, .node.selected ellipse, .node.selected path, .node.selected rect {
    stroke-width: 5 !important; /* Увеличена толщина линии фокуса */
    stroke: #e74c3c !important;
}

/* Cluster hover style (кластеры браков) */
.cluster { cursor: pointer; }
/* Белый фоновый polygon внутри кластера не должен перехватывать клики —
   иначе клик по кластеру не доходит до родительского g.cluster */
.cluster polygon[fill="white"] { pointer-events: none; }
.cluster:hover polygon, .cluster:hover path, .cluster:hover rect {
    stroke-width: 2 !important;
    stroke: #8e44ad !important;
}

/* Контейнер кнопок в заголовке панели свойств (Копировать + foto_*) */
.properties-header-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 4px;
    align-items: center;
}

/* Кнопка foto_family в панели свойств семьи */
.foto-family-btn {
    background: #27ae60;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 11px;
}
.foto-family-btn:hover { background: #1e8449; }

/* Кнопка foto_person в панели свойств персоны */
.foto-person-btn {
    background: #2980b9;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 11px;
}
.foto-person-btn:hover { background: #1a5276; }

/* Галерея foto_family */
.fg-family-id {
    font-size: 12px;
    color: #cce;
    margin-bottom: 4px;
    word-break: break-all;
}
.fg-thumbs-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 4px 0;
}
.fg-thumb {
    text-align: center;
    cursor: pointer;
    max-width: 110px;
}
.fg-thumb img {
    width: 100px;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid #bbb;
    display: block;
    transition: border-color 0.15s;
}
.fg-thumb:hover img { border-color: #27ae60; }
.fg-thumb-label {
    font-size: 11px;
    color: #555;
    margin-top: 3px;
    word-break: break-word;
    max-width: 100px;
}
.fg-empty {
    color: #888;
    font-style: italic;
    font-size: 13px;
    padding: 8px 0;
}

/* Кнопка foto_location в панели свойств персоны и семьи */
.foto-location-btn {
    background: #e67e22;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 11px;
}
.foto-location-btn:hover { background: #ca6f1e; }

/* Кнопка Event в панели свойств персоны */
.event-btn {
    background: #8e44ad;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 11px;
}
.event-btn:hover { background: #6c3483; }

/* Выпадающий список FotoList в панели событий */
.event-fotolist-select {
    background: #2c3e50;
    color: white;
    border: 1px solid #7f8c8d;
    border-radius: 4px;
    padding: 3px 6px;
    font-size: 11px;
    cursor: pointer;
    margin-top: 4px;
}
.event-fotolist-select:focus { outline: none; border-color: #aaa; }

/* Строка события в панели событий */
.event-item {
    border-left: 3px solid #8e44ad;
    padding-left: 8px;
    margin-bottom: 10px;
}

/* Разделитель между событиями */
hr.event-separator {
    border: none;
    border-top: 1px solid #ddd;
    margin: 6px 0;
}

/* ================================================================
   TreeView panel (Панель дерева)
   ================================================================ */

/* Контейнер всей страницы с деревом слева и диаграммой справа */
.main-layout {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 20px;
}

/* Панель дерева (treeview) */
.treeview-panel {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    width: 280px;
    min-width: 200px;
    max-width: 320px;
    flex-shrink: 0;
    overflow: hidden;
}

/* Заголовок панели дерева */
.treeview-panel-header {
    background: #e9ecef;
    padding: 8px 12px;
    font-weight: 600;
    font-size: 0.95em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ddd;
    flex-wrap: wrap;
    gap: 6px;
}

.treeview-panel-title {
    font-size: 1em;
    white-space: nowrap;
}

/* Кнопки панели дерева */
.tv-header-buttons {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-wrap: wrap;
}

.tv-btn {
    padding: 4px 9px;
    font-size: 12px;
    background: #607D8B;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1.3;
}

.tv-btn:hover { background: #455A64; }

/* Активная кнопка режима (мужской / женский) */
.tv-btn.tv-btn-active {
    background: #2c3e50;
    box-shadow: inset 0 0 0 2px #aed6f1;
}

/* Строка поиска */
.treeview-search-row {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 6px 10px;
    background: #f5f5f5;
    border-bottom: 1px solid #ddd;
    flex-wrap: wrap;
}

.tv-search-input {
    flex: 1;
    min-width: 80px;
    padding: 4px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 12px;
}

.tv-search-status {
    font-size: 11px;
    color: #888;
    min-width: 40px;
    text-align: right;
}

/* Область содержимого дерева (прокрутка) */
.treeview-content {
    overflow-y: auto;
    max-height: calc(80vh - 90px);
    min-height: 200px;
    padding: 6px 0;
    flex: 1;
}

/* Сообщение «пусто» */
.tv-empty {
    padding: 12px;
    color: #888;
    font-style: italic;
    font-size: 13px;
}

/* Корневой список */
ul.tv-root-list {
    list-style: none;
    margin: 0;
    padding: 0 0 0 4px;
}

/* Вложенные списки */
ul.tv-children {
    list-style: none;
    margin: 0;
    padding: 0 0 0 16px;
}

/* Свёрнутый список */
ul.tv-children.tv-collapsed {
    display: none;
}

/* Элемент списка */
li.tv-item {
    margin: 0;
    padding: 0;
}

/* Строка элемента (иконка + метка) */
.tv-row {
    display: flex;
    align-items: center;
    padding: 2px 6px 2px 4px;
    cursor: default;
    border-radius: 3px;
    user-select: none;
}

.tv-row:hover {
    background: #e8f4fd;
}

/* Иконка раскрытия/сворачивания */
.tv-toggle {
    display: inline-block;
    width: 16px;
    min-width: 16px;
    text-align: center;
    font-size: 10px;
    color: #607D8B;
    cursor: pointer;
    margin-right: 2px;
    flex-shrink: 0;
}

.tv-toggle:hover { color: #2c3e50; }

/* Пустая иконка (нет детей) */
.tv-toggle-empty {
    cursor: default;
    color: transparent;
}

/* Метка персоны */
.tv-label {
    font-size: 13px;
    color: #2c3e50;
    cursor: pointer;
    word-break: break-word;
    line-height: 1.4;
}

.tv-label:hover { color: #2980b9; text-decoration: underline; }

/* Выделенная строка treeview (по клику) */
.tv-row.tv-row-selected {
    background: #d6eaf8;
}

.tv-row.tv-row-selected .tv-label {
    font-weight: 600;
    color: #1a5276;
}

/* Подсветка найденной строки при поиске */
.tv-row.tv-search-highlight {
    background: #fef9c3;
    border-left: 3px solid #f1c40f;
}

.tv-row.tv-search-highlight .tv-label {
    color: #7d6608;
}

/* Диаграмма занимает оставшееся место */
.main-layout .diagram-panel {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

/* ================================================================
   Левая колонка: Дерево + Фото
   ================================================================ */
.left-panels-column {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 280px;
    min-width: 200px;
    max-width: 320px;
    flex-shrink: 0;
}

.left-panels-column .treeview-panel {
    width: 100%;
    min-width: unset;
    max-width: unset;
    max-height: 60vh; /* Увеличено на треть: 45vh -> 60vh */
}

.left-panels-column .treeview-panel .treeview-content {
    max-height: calc(60vh - 90px); /* Увеличено на треть */
}

/* ================================================================
   Панель Фото (PhotoTreeView)
   ================================================================ */
.phototree-panel {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    width: 100%;
    overflow: hidden;
    max-height: 35vh;
}

.phototree-panel-header {
    background: #f5e6c8;
    padding: 8px 12px;
    font-weight: 600;
    font-size: 0.95em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e6d5b8;
    flex-wrap: wrap;
    gap: 6px;
}

.phototree-panel-title {
    font-size: 1em;
    white-space: nowrap;
    color: #8b6914;
}

.pt-header-buttons {
    display: flex;
    gap: 5px;
    align-items: center;
}

.phototree-content {
    overflow-y: auto;
    max-height: calc(35vh - 50px);
    min-height: 100px;
    padding: 6px 0;
    flex: 1;
}

/* Стили дерева фото (переиспользуем tv-* классы) */
.phototree-content ul.pt-root-list {
    list-style: none;
    margin: 0;
    padding: 0 0 0 4px;
}

.phototree-content ul.pt-children {
    list-style: none;
    margin: 0;
    padding: 0 0 0 16px;
}

.phototree-content ul.pt-collapsed {
    display: none;
}

.phototree-content li.pt-item {
    margin: 0;
    padding: 0;
}

.phototree-content .pt-row {
    display: flex;
    align-items: center;
    padding: 2px 6px 2px 4px;
    cursor: default;
    border-radius: 3px;
    user-select: none;
}

.phototree-content .pt-row:hover {
    background: #fef3c7;
}

.phototree-content .pt-toggle {
    display: inline-block;
    width: 16px;
    min-width: 16px;
    text-align: center;
    font-size: 10px;
    color: #8b6914;
    cursor: pointer;
    margin-right: 2px;
    flex-shrink: 0;
}

.phototree-content .pt-toggle:hover { color: #6b5714; }

.phototree-content .pt-toggle-empty {
    cursor: default;
    color: transparent;
}

.phototree-content .pt-label {
    font-size: 13px;
    color: #5d4e37;
    cursor: pointer;
    word-break: break-word;
    line-height: 1.4;
}

.phototree-content .pt-label:hover { color: #8b6914; text-decoration: underline; }

/* Иконка папки */
.phototree-content .pt-folder-icon {
    margin-right: 4px;
    font-size: 12px;
}

/* Иконка файла фото */
.phototree-content .pt-file-icon {
    margin-right: 4px;
    font-size: 11px;
    color: #999;
}
