/**
 * Основные стили приложения
 */

:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;
    --light-bg: #f8f9fa;
    --border-color: #e0e0e0;
    --text-color: #333;
    --text-muted: #666;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    color: var(--text-color);
    background-color: var(--light-bg);
}

/* Навигация */
.navbar-brand {
    font-weight: 600;
}

/* Карточки */
.card {
    border: none;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.card-header {
    background-color: white;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

/* Кнопки */
.btn {
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-primary:hover {
    background-color: #5568d3;
    border-color: #5568d3;
}

/* Формы */
.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

/* Дерево идей */
.idea-tree-container {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    min-height: 400px;
}

/* jstree кастомизация */
.jstree-default .jstree-node {
    min-height: 32px;
    line-height: 32px;
    margin-left: 0;
    min-width: 32px;
}

.jstree-default .jstree-anchor {
    line-height: 1.4;
    min-height: 32px;
    height: auto;
    padding: 4px 4px 4px 1px;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
    display: inline-block;
    width: 100%;
    box-sizing: border-box;
}

.jstree-default .jstree-icon {
    width: 32px;
    height: 32px;
    line-height: 32px;
}

.jstree-default .jstree-clicked {
    background: rgba(102, 126, 234, 0.1);
    box-shadow: none;
}

.jstree-default .jstree-hovered {
    background: rgba(102, 126, 234, 0.05);
}

/* Улучшенная иерархия дерева */
.jstree-default .jstree-children {
    margin-left: 24px;
    padding-left: 12px;
    border-left: 2px solid rgba(102, 126, 234, 0.2);
    margin-top: 4px;
    margin-bottom: 4px;
}

.jstree-default .jstree-container-ul > .jstree-children {
    margin-left: 0;
    padding-left: 0;
    border-left: none;
}

.jstree-default .jstree-node {
    position: relative;
    margin-bottom: 4px;
}

/* Улучшение отступов для разных уровней */
.jstree-default .jstree-children .jstree-node {
    margin-left: 0;
}

/* AI подсказки */
.ai-suggestion-badge {
    display: inline-block;
    background: var(--info-color);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    margin-left: 8px;
    cursor: pointer;
}

.ai-suggestion-badge:hover {
    background: #2563eb;
}

/* Индикация AI подсказок в дереве */
.jstree-default .jstree-node[data-has-suggestions="true"] > .jstree-anchor {
    position: relative;
}

.jstree-default .jstree-node[data-has-suggestions="true"] > .jstree-anchor::after {
    content: '💡';
    position: absolute;
    right: 5px;
    font-size: 14px;
}

/* AI карточки */
.ai-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.ai-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.ai-card-title {
    font-weight: 600;
    color: var(--text-color);
    margin: 0;
}

.ai-card-actions {
    display: flex;
    gap: 10px;
}

/* Загрузка */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Контекстное меню */
.context-menu {
    position: fixed;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 4px 0;
    z-index: 10000;
    min-width: 200px;
    display: none;
}

.context-menu-item {
    padding: 8px 16px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.context-menu-item:hover {
    background: var(--light-bg);
}

.context-menu-item.disabled {
    color: var(--text-muted);
    cursor: not-allowed;
}

.context-menu-item.disabled:hover {
    background: transparent;
}

.context-menu-item i {
    width: 16px;
    text-align: center;
}

/* Боковая панель идей */
.ideas-sidebar {
    background: white;
    border-radius: 8px;
    padding: 20px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

.idea-item {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

.idea-item:hover {
    background: var(--light-bg);
}

.idea-item.active {
    background: var(--primary-color) !important;
    color: white !important;
    border-left: 3px solid var(--primary-color);
}

.idea-item.active .idea-item-title {
    color: white !important;
    font-weight: 600;
}

.idea-item.active .idea-item-meta {
    color: rgba(255, 255, 255, 0.9) !important;
}

.idea-item.active .badge {
    background-color: rgba(255, 255, 255, 0.2) !important;
    color: white !important;
}

.idea-item-title {
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-color);
}

.idea-item-meta {
    font-size: 12px;
    color: var(--text-muted);
}

/* Адаптивность */
@media (max-width: 768px) {
    .ideas-sidebar {
        margin-bottom: 20px;
        max-height: 300px;
    }
    
    .ai-card-actions {
        flex-direction: column;
    }
    
    .ai-card-actions .btn {
        width: 100%;
        margin-bottom: 5px;
    }
    
    .card-header .btn {
        margin-top: 5px;
    }
}

/* Формы */
.form-label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.form-text {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

/* Утилиты */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.fade-in {
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Индикатор загрузки */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-overlay .spinner-border {
    width: 3rem;
    height: 3rem;
}

/* Улучшения UX */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.card {
    transition: box-shadow 0.2s;
}

.card:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

/* Анимации */
@keyframes slideIn {
    from {
        transform: translateY(-10px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.ai-card {
    animation: slideIn 0.3s;
}

/* Улучшения для настроек */
.settings-section {
    margin-bottom: 2rem;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section h6 {
    color: var(--text-color);
    font-weight: 600;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

/* Улучшения для поля "мысль идеи" */
#idea_thought {
    font-family: inherit;
    line-height: 1.6;
}

#idea_thought:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.15);
}

/* Иконки в навигации */
.nav-link i {
    margin-right: 0.25rem;
}

/* Улучшения карточек */
.card-header .btn-group {
    gap: 0.5rem;
}

.card-header .btn {
    margin: 0;
}

/* Адаптивность для настроек */
@media (max-width: 768px) {
    .settings-section h6 {
        font-size: 1rem;
    }
    
    .form-select,
    .form-control {
        font-size: 0.95rem;
    }
}

/* Информационные блоки для узлов дерева */
.node-info-block {
    margin: 8px 0 8px 40px;
    padding: 12px;
    background: #f8f9fa;
    border-left: 3px solid var(--info-color);
    border-radius: 4px;
    font-size: 0.9rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    max-width: 100%;
    box-sizing: border-box;
}

.node-info-block .info-section {
    margin-bottom: 12px;
}

.node-info-block .info-section:last-child {
    margin-bottom: 0;
}

.node-info-block .info-section strong {
    color: var(--text-color);
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.node-info-block .info-section ul {
    margin: 6px 0;
    padding-left: 20px;
}

.node-info-block .info-section li {
    margin-bottom: 4px;
    line-height: 1.5;
}

.node-info-block .info-section p {
    margin: 6px 0 0 0;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

.node-info-block .info-block-content {
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

.info-toggle-btn {
    margin-left: 8px;
    padding: 2px 6px;
    font-size: 0.75rem;
    vertical-align: middle;
}

.info-toggle-btn:hover {
    background-color: var(--info-color);
    border-color: var(--info-color);
    color: white;
}

/* Улучшение отображения узлов с информационными блоками */
.jstree-default .jstree-anchor {
    position: relative;
}

.jstree-default .jstree-anchor .info-toggle-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
}

/* Стили для модального окна изменений структуры */
.structure-changes-list {
    max-height: 60vh;
    overflow-y: auto;
}

.change-item {
    transition: background-color 0.2s;
}

.change-item:hover {
    background-color: #f8f9fa;
}

.change-item .text-danger del {
    text-decoration: line-through;
    opacity: 0.7;
}

.change-item .text-success {
    font-weight: 500;
}

/* Стили для чата с AI */
#aiChatContainer {
    min-height: 200px;
    max-height: 400px;
}

#aiChatMessages {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#aiChatMessages > div {
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

#aiChatInput:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

/* Стили для ID узлов в дереве */
.node-id-badge {
    display: inline-block;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 6px;
    font-family: 'Courier New', monospace;
    letter-spacing: 0.5px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    vertical-align: middle;
    line-height: 1.4;
}
