/* -------------------------------------------------------------------
   StreamersForge - Knowledge Base Styles
   ------------------------------------------------------------------- */

/* --- Layout -------------------------------------------------------- */
.kb-layout {
    display: flex;
    height: calc(100vh - 56px);
    overflow: hidden;
}

/* --- Sidebar (Index) ----------------------------------------------- */
.kb-sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.kb-search-wrap {
    padding: 16px 14px 12px;
    position: relative;
}

.kb-search {
    width: 100%;
    padding: 9px 12px 9px 36px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    outline: none;
    transition: border-color var(--transition-fast);
}

.kb-search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-muted);
}

.kb-search-icon {
    position: absolute;
    left: 26px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.kb-search-icon svg {
    width: 15px;
    height: 15px;
}

/* --- Autocomplete -------------------------------------------------- */
.kb-autocomplete {
    position: absolute;
    top: 100%;
    left: 14px;
    right: 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    max-height: 240px;
    overflow-y: auto;
    display: none;
}

.kb-autocomplete.visible {
    display: block;
}

.kb-autocomplete-item {
    padding: 8px 12px;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background var(--transition-fast);
}

.kb-autocomplete-item:hover,
.kb-autocomplete-item.active {
    background: var(--accent-muted);
    color: var(--text-primary);
}

.kb-autocomplete-item .kb-ac-icon {
    color: var(--accent-light);
    flex-shrink: 0;
}

.kb-autocomplete-item .kb-ac-icon svg {
    width: 14px;
    height: 14px;
}

.kb-autocomplete-item .kb-ac-parent {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-left: auto;
    flex-shrink: 0;
}

/* --- Tree ---------------------------------------------------------- */
.kb-tree {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 16px;
}

.kb-tree::-webkit-scrollbar {
    width: 5px;
}

.kb-tree::-webkit-scrollbar-track {
    background: transparent;
}

.kb-tree::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 3px;
}

.kb-tree-group {
    margin-bottom: 4px;
}

.kb-tree-category {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border-radius: var(--radius-sm);
    user-select: none;
    transition: color var(--transition-fast);
}

.kb-tree-category:hover {
    color: var(--text-secondary);
}

.kb-tree-category .kb-cat-chevron {
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}

.kb-tree-category .kb-cat-chevron svg {
    width: 13px;
    height: 13px;
}

.kb-tree-category.collapsed .kb-cat-chevron {
    transform: rotate(-90deg);
}

.kb-tree-category .kb-cat-icon {
    color: var(--accent-light);
    flex-shrink: 0;
}

.kb-tree-category .kb-cat-icon svg {
    width: 14px;
    height: 14px;
}

.kb-tree-children {
    padding-left: 10px;
    overflow: hidden;
}

.kb-tree-category.collapsed+.kb-tree-children {
    display: none;
}

.kb-tree-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px 6px 20px;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    user-select: none;
    position: relative;
}

.kb-tree-item::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 6px;
    bottom: 6px;
    width: 1px;
    background: var(--border-subtle);
}

.kb-tree-item:hover {
    background: var(--accent-muted);
    color: var(--text-primary);
}

.kb-tree-item.active {
    background: var(--accent-muted);
    color: var(--accent-light);
    font-weight: 500;
}

.kb-tree-item.active::before {
    background: var(--accent);
    width: 2px;
    border-radius: 1px;
}

.kb-tree-item .kb-item-icon {
    flex-shrink: 0;
    opacity: 0.6;
}

.kb-tree-item .kb-item-icon svg {
    width: 13px;
    height: 13px;
}

/* --- Admin: Add Page Button ---------------------------------------- */
.kb-sidebar-footer {
    padding: 10px 14px;
    border-top: 1px solid var(--border-subtle);
    display: none;
}

.kb-sidebar-footer.visible {
    display: block;
}

.kb-add-page-btn {
    width: 100%;
    padding: 7px 12px;
    background: transparent;
    border: 1px dashed var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all var(--transition-fast);
}

.kb-add-page-btn:hover {
    border-color: var(--accent);
    color: var(--accent-light);
    background: var(--accent-muted);
}

.kb-add-page-btn svg {
    width: 14px;
    height: 14px;
}

/* --- Content Area -------------------------------------------------- */
.kb-content {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.kb-content::-webkit-scrollbar {
    width: 6px;
}

.kb-content::-webkit-scrollbar-track {
    background: transparent;
}

.kb-content::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 3px;
}

/* --- Article View -------------------------------------------------- */
.kb-article {
    max-width: 780px;
    margin: 0 auto;
    padding: 40px 48px 60px;
    width: 100%;
}

.kb-article-header {
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.kb-article-breadcrumb {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.kb-article-breadcrumb span {
    cursor: pointer;
    transition: color var(--transition-fast);
}

.kb-article-breadcrumb span:hover {
    color: var(--accent-light);
}

.kb-article-breadcrumb .kb-bc-sep {
    cursor: default;
    color: var(--text-disabled);
}

.kb-article-breadcrumb .kb-bc-sep:hover {
    color: var(--text-disabled);
}

.kb-article-title {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.3;
}

.kb-article-meta {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 8px;
}

/* --- Admin Toolbar ------------------------------------------------- */
.kb-admin-toolbar {
    display: none;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
}

.kb-admin-toolbar.visible {
    display: flex;
}

.kb-admin-btn {
    padding: 5px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-family: var(--font-sans);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all var(--transition-fast);
}

.kb-admin-btn:hover {
    border-color: var(--accent);
    color: var(--accent-light);
    background: var(--accent-muted);
}

.kb-admin-btn.danger:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: var(--danger-muted);
}

.kb-admin-btn svg {
    width: 13px;
    height: 13px;
}

/* --- Article Body Content ------------------------------------------ */
.kb-article-body {
    font-size: var(--text-base);
    color: var(--text-secondary);
    line-height: 1.75;
}

.kb-article-body h2 {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-primary);
    margin: 28px 0 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-subtle);
}

.kb-article-body h3 {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text-primary);
    margin: 22px 0 8px;
}

.kb-article-body p {
    margin: 0 0 14px;
}

.kb-article-body ul,
.kb-article-body ol {
    margin: 0 0 14px;
    padding-left: 24px;
}

.kb-article-body li {
    margin-bottom: 6px;
}

.kb-article-body code {
    background: var(--bg-elevated);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.85em;
    color: var(--accent-light);
}

.kb-article-body pre {
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 16px;
    overflow-x: auto;
    margin: 0 0 14px;
}

.kb-article-body pre code {
    background: none;
    padding: 0;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.kb-article-body blockquote {
    border-left: 3px solid var(--accent);
    margin: 0 0 14px;
    padding: 10px 16px;
    background: var(--accent-muted);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    color: var(--text-secondary);
}

.kb-article-body strong {
    color: var(--text-primary);
    font-weight: 600;
}

.kb-article-body a {
    color: var(--accent-light);
    text-decoration: none;
}

.kb-article-body a:hover {
    text-decoration: underline;
}

.kb-article-body img {
    max-width: 100%;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    margin: 8px 0;
}

.kb-article-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 14px;
    font-size: var(--text-sm);
}

.kb-article-body th,
.kb-article-body td {
    padding: 8px 12px;
    border: 1px solid var(--border-subtle);
    text-align: left;
}

.kb-article-body th {
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-weight: 600;
}

/* --- Callout boxes ------------------------------------------------- */
.kb-callout {
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin: 0 0 14px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: var(--text-sm);
}

.kb-callout-icon {
    flex-shrink: 0;
    margin-top: 1px;
}

.kb-callout-icon svg {
    width: 16px;
    height: 16px;
}

.kb-callout.tip {
    background: var(--success-muted);
    border: 1px solid rgba(34, 197, 94, 0.2);
    color: #86efac;
}

.kb-callout.tip .kb-callout-icon {
    color: var(--success);
}

.kb-callout.info {
    background: var(--info-muted);
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

.kb-callout.info .kb-callout-icon {
    color: var(--info);
}

.kb-callout.warning {
    background: var(--warning-muted);
    border: 1px solid rgba(245, 158, 11, 0.2);
    color: #fcd34d;
}

.kb-callout.warning .kb-callout-icon {
    color: var(--warning);
}

/* --- WYSIWYG Editor ------------------------------------------------ */
.kb-editor-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.kb-editor-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    width: 90vw;
    max-width: 900px;
    height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
}

.kb-editor-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 12px;
}

.kb-editor-header input {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--text-md);
    font-weight: 600;
    font-family: var(--font-sans);
    outline: none;
}

.kb-editor-header input:focus {
    border-color: var(--accent);
}

.kb-editor-parent-select {
    padding: 8px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    outline: none;
    max-width: 200px;
}

.kb-editor-toolbar {
    padding: 8px 20px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    background: var(--bg-tertiary);
}

.kb-toolbar-btn {
    padding: 5px 8px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    min-width: 30px;
    font-size: var(--text-sm);
    font-family: var(--font-sans);
}

.kb-toolbar-btn:hover {
    background: var(--accent-muted);
    color: var(--text-primary);
}

.kb-toolbar-btn.active {
    background: var(--accent-muted);
    color: var(--accent-light);
}

.kb-toolbar-btn svg {
    width: 15px;
    height: 15px;
}

.kb-toolbar-sep {
    width: 1px;
    background: var(--border-subtle);
    margin: 2px 6px;
    align-self: stretch;
}

.kb-editor-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.kb-editor-body [contenteditable] {
    outline: none;
    min-height: 100%;
    font-size: var(--text-base);
    color: var(--text-secondary);
    line-height: 1.75;
    font-family: var(--font-sans);
}

.kb-editor-body [contenteditable]:focus {
    outline: none;
}

.kb-editor-body [contenteditable] h2 {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-primary);
    margin: 20px 0 10px;
}

.kb-editor-body [contenteditable] h3 {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text-primary);
    margin: 16px 0 8px;
}

.kb-editor-body [contenteditable] p {
    margin: 0 0 12px;
}

.kb-editor-body [contenteditable] ul,
.kb-editor-body [contenteditable] ol {
    padding-left: 24px;
    margin: 0 0 12px;
}

.kb-editor-body [contenteditable] blockquote {
    border-left: 3px solid var(--accent);
    margin: 0 0 12px;
    padding: 8px 14px;
    background: var(--accent-muted);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.kb-editor-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* --- Welcome State ------------------------------------------------- */
.kb-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 48px;
    color: var(--text-muted);
}

.kb-welcome-icon {
    color: var(--accent-light);
    opacity: 0.3;
    margin-bottom: 16px;
}

.kb-welcome-icon svg {
    width: 56px;
    height: 56px;
}

.kb-welcome h3 {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 6px;
}

.kb-welcome p {
    font-size: var(--text-sm);
    max-width: 340px;
    margin: 0;
}

/* --- Add Article Modal --------------------------------------------- */
.kb-add-modal-body {
    padding: 20px;
}

.kb-add-modal-body .form-group {
    margin-bottom: 14px;
}

.kb-add-modal-body .form-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
    display: block;
}

/* --- Mobile -------------------------------------------------------- */
@media (max-width: 768px) {
    .kb-layout {
        flex-direction: column;
        height: auto;
    }

    .kb-sidebar {
        width: 100%;
        min-width: unset;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border-subtle);
    }

    .kb-article {
        padding: 24px 20px 40px;
    }
}

/* --- Drag-and-Drop Landing Zones ------------------------------------- */
.kb-tree-item[draggable=true] {
    cursor: grab;
}

.kb-tree-item[draggable=true]:active {
    cursor: grabbing;
}

.kb-tree-item.kb-dragging {
    opacity: 0.25;
    pointer-events: none;
}

/* Zones start collapsed - invisible until cursor approaches */
.kb-drop-zone {
    position: relative;
    height: 0;
    overflow: hidden;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: default;
    transition: height 0.15s ease, opacity 0.15s ease, background 0.15s ease;
    opacity: 0;
    pointer-events: none;
}

/* Revealed when cursor is near (proximity) */
.kb-drop-zone.kb-zone-near {
    height: 28px;
    opacity: 0.6;
    margin: 2px 0;
    pointer-events: auto;
}

/* Highlighted when directly hovered / dragover */
.kb-drop-zone.kb-drop-zone-active {
    height: 28px;
    opacity: 1;
    margin: 2px 0;
    background: var(--accent-muted);
    pointer-events: auto;
}

.kb-drop-zone-line {
    flex: 1;
    height: 2px;
    background: var(--accent);
    border-radius: 1px;
    transition: all 0.15s ease;
}

.kb-drop-zone-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent-light);
    white-space: nowrap;
    padding-right: 8px;
    transition: opacity 0.15s ease;
}

.kb-drop-zone.kb-drop-zone-active .kb-drop-zone-line {
    height: 3px;
    box-shadow: 0 0 8px var(--accent-muted);
}

.kb-drop-zone-nested {
    margin-left: 12px;
}

.kb-drop-zone-nested .kb-drop-zone-line {
    background: var(--accent-light);
}