/* Model Tree - Tree View, Node Details, Vocabulary */

/* Vocabulary */
.vocabulary-categories { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 15px; }
.vocabulary-category { background: var(--light-bg); border-radius: 12px; border: 1px solid var(--light-border); overflow: hidden; }
.vocabulary-category-header { display: flex; align-items: center; padding: 14px 16px; cursor: pointer; transition: background 0.2s; gap: 10px; background: var(--light-card); }
.vocabulary-category-header:hover { background: var(--light-bg); }
.vocabulary-category-header .expand-icon { transition: transform 0.2s; color: var(--text-muted); }
.vocabulary-category-header.expanded .expand-icon { transform: rotate(90deg); }
.vocabulary-category-name { flex: 1; font-weight: 600; color: var(--text-primary); }
.vocabulary-category-count { font-size: 0.8em; padding: 3px 10px; background: var(--primary-light); color: var(--primary); border-radius: 20px; font-weight: 600; }
.vocabulary-originals { display: none; padding: 12px 16px; border-top: 1px solid var(--light-border); background: var(--light-card); }
.vocabulary-originals.expanded { display: block; }
.vocabulary-original { font-size: 0.85em; padding: 5px 10px; margin: 3px; display: inline-block; background: var(--light-bg); border-radius: 6px; color: var(--text-secondary); border: 1px solid var(--light-border); }

/* Model Tree Search */
.model-tree-search {
    position: sticky;
    top: -16px;
    z-index: 10;
    background: var(--light-card);
    margin: -16px -16px 12px -16px;
    padding: 16px 16px 8px 16px;
}
.model-tree-search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--light-border);
    border-radius: 8px;
    font-size: 13px;
    background: var(--light-card);
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.model-tree-search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(119,95,255,0.15);
}
.model-tree-search-input::placeholder {
    color: var(--text-muted);
}
.model-tree-search-results {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    padding-left: 4px;
}

/* Highlight matching text */
.model-tree-name mark {
    background: rgba(245, 158, 11, 0.4);
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}
.model-tree-node.search-match > .model-tree-item {
    background: rgba(245, 158, 11, 0.1);
}
.model-tree-node.search-hidden {
    display: none;
}

/* Model Tree - File Explorer Style */
.model-tree {
    background: var(--light-bg);
    border-radius: 12px;
    padding: 12px;
    min-height: 200px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, monospace;
}
.model-tree-node {
    position: relative;
}
.model-tree-item {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: default;
    gap: 6px;
    transition: background 0.1s;
    margin-left: 4px;
}
.model-tree-item:hover { background: rgba(119,95,255,0.08); }
.model-tree-item.selected { background: rgba(119,95,255,0.15); }
.model-tree-chevron {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    cursor: pointer;
    color: var(--text-muted);
    transition: transform 0.15s;
    flex-shrink: 0;
    border-radius: 3px;
}
.model-tree-chevron:hover { background: rgba(0,0,0,0.08); }
.model-tree-chevron.expanded { transform: rotate(90deg); }
.model-tree-chevron.hidden { visibility: hidden; }
.model-tree-icon { font-size: 15px; flex-shrink: 0; }
.model-tree-name {
    flex: 1;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
    color: var(--text-primary);
}
.model-tree-name:hover { text-decoration: underline; color: var(--primary); }
.model-tree-badges { display: flex; gap: 4px; flex-shrink: 0; margin-left: auto; }
.model-tree-badge { font-size: 10px; padding: 2px 6px; border-radius: 10px; font-weight: 600; }
.model-tree-badge.docs { background: rgba(119,95,255,0.12); color: var(--primary); }
.model-tree-badge.sections { background: rgba(16,185,129,0.12); color: var(--success); }
.model-tree-badge.locked { background: rgba(245,158,11,0.12); color: var(--warning); }
.model-tree-children {
    margin-left: 12px;
    padding-left: 12px;
    border-left: 1px solid var(--light-border);
    overflow: hidden;
}
.model-tree-children.collapsed { display: none; }
/* Tree guide lines on hover */
.model-tree-node:hover > .model-tree-children { border-left-color: var(--primary); }

/* Linked Content Tree (Model Node -> Documents/Sections) */
.linked-content-tree {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, monospace;
}
.linked-tree-group {
    margin-bottom: 16px;
}
.linked-tree-header {
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--light-border);
}
.linked-tree-items {
    padding-left: 4px;
    max-height: 250px;
    overflow-y: auto;
}
.linked-tree-items::-webkit-scrollbar {
    width: 6px;
}
.linked-tree-items::-webkit-scrollbar-track {
    background: transparent;
}
.linked-tree-items::-webkit-scrollbar-thumb {
    background: var(--light-border);
    border-radius: 3px;
}
.linked-tree-items::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
.linked-tree-item {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 6px 8px;
    margin-bottom: 2px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}
.linked-tree-item:hover {
    background: rgba(119,95,255,0.08);
}
.linked-tree-item .tree-connector {
    font-family: monospace;
    color: var(--light-border);
    font-size: 12px;
    line-height: 1.4;
    flex-shrink: 0;
}
.linked-tree-item .tree-icon {
    font-size: 14px;
    flex-shrink: 0;
}
.linked-tree-item .tree-item-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.linked-tree-item .tree-item-title {
    font-weight: 500;
    font-size: 12px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.linked-tree-item .tree-item-meta {
    font-size: 10px;
    color: var(--text-muted);
}
.linked-tree-item .tree-item-category {
    font-size: 10px;
    color: var(--primary);
}
.linked-tree-item .tree-item-restriction {
    font-size: 10px;
    color: var(--success);
}
.linked-tree-item .tree-arrow {
    color: var(--primary);
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}
.linked-tree-item:hover .tree-arrow {
    opacity: 1;
}

/* Link to Node Modal Tree */
.link-tree-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s;
    border: 1px solid transparent;
}
.link-tree-item:hover {
    background: rgba(119,95,255,0.08);
}
.link-tree-item.selected {
    background: rgba(119,95,255,0.15);
    border-color: var(--primary-light);
}
.link-tree-icon {
    font-size: 14px;
    flex-shrink: 0;
}
.link-tree-name {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.link-tree-type {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    padding: 2px 6px;
    background: var(--light-bg);
    border-radius: 4px;
    flex-shrink: 0;
}

/* Instructions Previews */
.instructions-previews-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.instruction-preview-card { background: var(--light-bg); border-radius: 12px; border: 1px solid var(--light-border); padding: 14px; }
.instruction-preview-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.instruction-preview-title { font-weight: 600; color: var(--text-primary); font-size: 0.9em; }
.instruction-preview-text { font-size: 0.85em; color: var(--text-secondary); line-height: 1.4; max-height: 60px; overflow: hidden; text-overflow: ellipsis; }
.instruction-preview-text.empty { color: var(--text-muted); font-style: italic; opacity: 0.7; }

/* Instructions Modal */
.instructions-modal { max-width: 700px; width: 90vw; max-height: 85vh; display: flex; flex-direction: column; }
.instructions-modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px solid var(--light-border); }
.instructions-modal-header h3 { margin: 0; }
.instructions-modal-tabs { display: flex; gap: 5px; }
.tab-btn { padding: 8px 18px; border-radius: 8px; font-size: 0.9em; background: var(--light-bg); color: var(--text-secondary); border: 1px solid var(--light-border); font-weight: 500; }
.tab-btn:hover { background: var(--light-bg); color: var(--text-primary); box-shadow: none; transform: none; }
.tab-btn.active { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: white; border-color: var(--primary); }
.instructions-content { flex: 1; overflow-y: auto; min-height: 300px; max-height: 50vh; }
#instructionsEditor { width: 100%; min-height: 300px; font-family: 'JetBrains Mono', 'Consolas', monospace; font-size: 0.9em; padding: 14px; border: 1px solid var(--light-border); border-radius: 10px; resize: vertical; background: var(--light-bg); }
#instructionsEditor:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(119,95,255,0.15); }

/* Markdown Rendered Content */
.markdown-body { padding: 16px; background: var(--light-card); border-radius: 10px; border: 1px solid var(--light-border); }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 { color: var(--text-primary); margin-top: 1em; margin-bottom: 0.5em; }
.markdown-body h1 { font-size: 1.5em; border-bottom: 1px solid var(--light-border); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.3em; }
.markdown-body h3 { font-size: 1.1em; }
.markdown-body p { margin: 0.8em 0; line-height: 1.6; }
.markdown-body ul, .markdown-body ol { margin: 0.8em 0; padding-left: 2em; }
.markdown-body li { margin: 0.3em 0; }
.markdown-body code { background: var(--light-bg); padding: 2px 6px; border-radius: 4px; font-family: 'JetBrains Mono', monospace; font-size: 0.9em; }
.markdown-body pre { background: var(--dark-navy); color: #d4d4d4; padding: 14px; border-radius: 10px; overflow-x: auto; margin: 1em 0; }
.markdown-body pre code { background: none; padding: 0; color: inherit; }
.markdown-body blockquote { border-left: 4px solid var(--primary-light); padding-left: 1em; margin: 1em 0; color: var(--text-secondary); }
.markdown-body table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.markdown-body th, .markdown-body td { border: 1px solid var(--light-border); padding: 10px 14px; text-align: left; }
.markdown-body th { background: var(--light-bg); font-weight: 600; }
.markdown-body a { color: var(--primary); }
.empty-instructions { color: var(--text-muted); font-style: italic; text-align: center; padding: 40px 20px; }

/* Model Node Details Panel */
.node-detail-panel {
    flex: 1;
    min-width: 350px;
    max-width: 450px;
    background: var(--light-card);
    border-radius: 12px;
    border: 1px solid var(--light-border);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 200px);
    overflow: hidden;
}
.node-detail-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--light-border);
    background: var(--light-bg);
}
.node-detail-header h3 {
    margin: 0 0 4px;
    font-size: 16px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.node-detail-header .node-type {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: normal;
}
.node-detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}
.node-detail-section {
    margin-bottom: 20px;
}
.node-detail-section:last-child {
    margin-bottom: 0;
}
.node-detail-section h4 {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 8px;
}
.node-detail-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.node-detail-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 40px 20px;
}
.node-detail-empty-icon {
    font-size: 48px;
    opacity: 0.3;
    margin-bottom: 12px;
}

/* Linked Items List */
.linked-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.linked-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--light-bg);
    border-radius: 6px;
    font-size: 12px;
    transition: all 0.15s;
    cursor: pointer;
}
.linked-item:hover {
    background: rgba(119,95,255,0.08);
}
.linked-item-icon {
    font-size: 14px;
    flex-shrink: 0;
}
.linked-item-name {
    flex: 1;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.linked-item-meta {
    font-size: 10px;
    color: var(--text-muted);
    flex-shrink: 0;
}
.linked-items-empty {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    padding: 8px;
}

/* ========== Vocabulary Tab ========== */
.vocabulary-content {
    padding: 24px;
    max-width: 900px;
}
.vocabulary-section {
    margin-bottom: 16px;
    background: var(--light-card);
    border: 1px solid var(--light-border);
    border-radius: 10px;
    overflow: hidden;
}
.vocabulary-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    cursor: pointer;
    transition: background 0.15s;
}
.vocabulary-section-header:hover {
    background: var(--light-bg);
}
.vocabulary-section.expanded .vocabulary-section-header {
    background: var(--light-bg);
    border-bottom: 1px solid var(--light-border);
}
.vocabulary-section-header h3 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.vocabulary-section-badge {
    display: flex;
    align-items: center;
    gap: 10px;
}
.vocabulary-section-header .count {
    font-size: 0.75rem;
    background: var(--primary);
    color: white;
    padding: 3px 10px;
    border-radius: 12px;
}
.vocabulary-section-chevron {
    color: var(--text-muted);
    transition: transform 0.2s;
    font-size: 0.8rem;
}
.vocabulary-section.expanded .vocabulary-section-chevron {
    transform: rotate(180deg);
}
.vocabulary-section-content {
    display: none;
    padding: 16px 18px;
}
.vocabulary-section.expanded .vocabulary-section-content {
    display: block;
}
.vocabulary-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.vocabulary-item {
    background: var(--light-bg);
    border: 1px solid var(--light-border);
    border-radius: 8px;
    overflow: hidden;
}
.vocabulary-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s;
}
.vocabulary-item-header:hover {
    background: var(--light-bg);
}
.vocabulary-item.expanded .vocabulary-item-header {
    background: var(--light-bg);
    border-bottom: 1px solid var(--light-border);
}
.vocabulary-item-name {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
}
.vocabulary-item-badge {
    display: flex;
    align-items: center;
    gap: 8px;
}
.vocabulary-item-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--light-bg);
    padding: 2px 8px;
    border-radius: 10px;
}
.vocabulary-item.expanded .vocabulary-item-count {
    background: var(--light-card);
}
.vocabulary-item-chevron {
    color: var(--text-muted);
    transition: transform 0.2s;
}
.vocabulary-item.expanded .vocabulary-item-chevron {
    transform: rotate(180deg);
}
.vocabulary-item-sources {
    display: none;
    padding: 12px 16px;
    background: var(--light-bg);
}
.vocabulary-item.expanded .vocabulary-item-sources {
    display: block;
}
.vocabulary-source {
    display: inline-block;
    background: var(--light-card);
    border: 1px solid var(--light-border);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 3px 4px 3px 0;
}
.vocabulary-no-sources {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-style: italic;
}
.vocabulary-footer {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--light-border);
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Vocabulary item editing */
.vocabulary-item-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-right: 8px;
}
.vocab-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s, transform 0.1s;
    opacity: 0.7;
}
.vocab-btn:hover {
    opacity: 1;
    background: var(--light-bg);
}
.vocab-btn:active {
    transform: scale(0.95);
}
.vocab-btn-edit:hover {
    background: rgba(117, 95, 255, 0.1);
}
.vocab-btn-lock:hover {
    background: rgba(251, 188, 4, 0.15);
}
.vocab-btn-unlock:hover {
    background: rgba(52, 168, 83, 0.15);
}
.vocab-btn-delete:hover {
    background: rgba(234, 67, 53, 0.1);
}
.vocabulary-item-name.locked {
    display: flex;
    align-items: center;
    gap: 6px;
}
.locked-indicator {
    color: var(--brand-color);
    font-size: 12px;
}
.vocabulary-item.is-locked {
    border-left: 3px solid var(--brand-color);
}
.vocabulary-summary {
    display: flex;
    gap: 16px;
    align-items: center;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--light-bg);
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.vocab-locked-count {
    color: var(--brand-color);
    font-weight: 500;
}

/* Locked badge in section header */
.vocab-locked-badge {
    font-size: 0.75rem;
    background: rgba(245, 158, 11, 0.15);
    color: #b45309;
    padding: 3px 8px;
    border-radius: 10px;
    font-weight: 500;
}

/* Locked label on item name */
.locked-label {
    color: #9ca3af;
    font-weight: 400;
    font-size: 0.85em;
}

/* Locked item styling */
.vocabulary-item.is-locked {
    border-left: 3px solid #f59e0b;
    background: rgba(245, 158, 11, 0.04);
}
.vocabulary-item.is-locked .vocabulary-item-header {
    background: rgba(245, 158, 11, 0.06);
}

/* ========== Mobile Responsive ========== */
@media (max-width: 768px) {
    /* Model tree container */
    .model-tree {
        padding: 8px;
        font-size: 12px;
    }
    .model-tree-item {
        padding: 3px 6px;
        gap: 4px;
    }
    .model-tree-name {
        font-size: 12px;
    }
    .model-tree-badge {
        font-size: 9px;
        padding: 1px 4px;
    }
    .model-tree-children {
        margin-left: 8px;
        padding-left: 8px;
    }

    /* Search */
    .model-tree-search-input {
        padding: 6px 10px 6px 28px;
        font-size: 12px;
    }
    .model-tree-search-icon {
        left: 8px;
        top: 7px;
    }
    .model-tree-search-icon svg {
        width: 12px;
        height: 12px;
    }
    .model-tree-search-clear {
        top: 4px;
        right: 6px;
        font-size: 12px;
    }

    /* Node detail panel - foldable on mobile */
    .node-detail-panel {
        min-width: auto;
        max-width: none;
        width: 100%;
        max-height: none;
        overflow: hidden;
    }
    .node-detail-header {
        padding: 12px 14px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: space-between;
        -webkit-tap-highlight-color: transparent;
    }
    .node-detail-header::after {
        content: '';
        width: 0;
        height: 0;
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
        border-top: 6px solid var(--text-muted);
        transition: transform 0.2s;
        flex-shrink: 0;
        margin-left: 8px;
    }
    .node-detail-panel.folded .node-detail-header::after {
        transform: rotate(-90deg);
    }
    .node-detail-header h3 {
        font-size: 14px;
        margin: 0;
    }
    .node-detail-body {
        padding: 12px 14px;
        transition: max-height 0.3s ease, padding 0.3s ease;
    }
    .node-detail-panel.folded .node-detail-body {
        max-height: 0;
        padding-top: 0;
        padding-bottom: 0;
        overflow: hidden;
    }
    .node-detail-actions {
        flex-wrap: wrap;
    }
    .node-detail-actions .btn {
        font-size: 11px;
        padding: 4px 8px;
    }

    /* Linked items */
    .linked-tree-items {
        max-height: 200px;
    }
    .linked-tree-item {
        padding: 5px 6px;
        font-size: 11px;
    }
    .linked-tree-header {
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .model-tree {
        padding: 6px;
    }
    .model-tree-item {
        padding: 2px 4px;
    }
    .model-tree-name {
        font-size: 11px;
    }
    .model-tree-badges {
        display: none;
    }
    .model-tree-children {
        margin-left: 6px;
        padding-left: 6px;
    }
}
