/*
 * Knowledgebase view styles (Wave 1c).
 * (c) Adrian Ranta. All rights reserved. Unauthorised use, reproduction and or distribution is strictly prohibited.
 */

#knowledgebaseView {
    padding: 16px 20px;
}

.kb-toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.kb-search {
    flex: 1 1 240px;
    min-width: 200px;
    padding: 8px 12px;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    font-size: 14px;
}

.kb-category-filter {
    padding: 8px 10px;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    font-size: 14px;
}

/* Browse account selector — account-less super_admin only. Wider than the
   category filter since account names are longer. */
.kb-account-filter {
    min-width: 200px;
    max-width: 280px;
    padding: 8px 10px;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    font-size: 14px;
}

.kb-layout {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    min-height: 0;
    flex: 1 1 auto;
}

.kb-list-pane {
    flex: 0 0 320px;
    max-width: 320px;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
}

.kb-detail-pane {
    flex: 1 1 auto;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    padding: 20px 24px;
}

.kb-article-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.kb-article-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    border-bottom: 1px solid #f0f2f5;
    cursor: pointer;
}

.kb-article-item:hover {
    background: #f6f8fa;
}

.kb-article-title {
    font-weight: 600;
    color: #1f2937;
}

.kb-article-cat {
    font-size: 12px;
    color: #6b7280;
}

.kb-badge {
    display: inline-block;
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 10px;
    margin-left: 6px;
    vertical-align: middle;
}

.kb-badge-draft {
    background: #fef3c7;
    color: #92400e;
}

.kb-empty,
.kb-detail-empty {
    padding: 24px;
    color: #6b7280;
    text-align: center;
}

/* "Select an account to browse its knowledgebase" — shown to the account-less
   super_admin before they pick a browse account (instead of the cross-account
   wall). Slightly stronger than a plain empty state so it reads as a call to
   action, not a no-results message. */
.kb-scope-prompt {
    color: #374151;
    font-size: 15px;
}

.kb-detail-title {
    margin: 0 0 8px 0;
    font-size: 22px;
    color: #111827;
}

.kb-detail-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 14px;
    font-size: 13px;
    color: #6b7280;
}

.kb-detail-admin {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.kb-detail-body {
    line-height: 1.6;
    color: #1f2937;
}

.kb-detail-body h1,
.kb-detail-body h2,
.kb-detail-body h3 {
    margin-top: 1.2em;
    margin-bottom: 0.4em;
}

.kb-detail-body pre,
.kb-detail-body code {
    background: #f3f4f6;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
}

.kb-detail-body pre {
    padding: 12px;
    overflow-x: auto;
}

.kb-detail-body code {
    padding: 1px 5px;
}

/* Bordered Markdown tables. Scoped strictly to the rendered article body so
   no app-wide <table> is affected. Colours use the theme tokens where present,
   falling back to literals (this file is otherwise literal-keyed). */
.kb-detail-body table {
    border-collapse: collapse;
    width: auto;
    margin: 1em 0;
}

.kb-detail-body th,
.kb-detail-body td {
    border: 1px solid var(--border-color, #d0d5dd);
    padding: 6px 10px;
    text-align: left;
    vertical-align: top;
}

.kb-detail-body th {
    background: var(--surface-2, #f5f6f8);
    font-weight: 600;
}

.kb-detail-body tbody tr:nth-child(even) td {
    background: var(--surface-1, #fafbfc);
}

/* Clickable people: the author byline + in-body #user/ links. Styled like an
   inline link without altering the editor's own anchors elsewhere. */
.kb-user-link {
    color: #2563eb;
    cursor: pointer;
    text-decoration: none;
}

.kb-user-link:hover {
    text-decoration: underline;
}

/* Shared contact card (KbUserCard). Fixed, centred, dismissible. */
.kb-user-card {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 11200;
    min-width: 240px;
    max-width: 320px;
    background: #fff;
    color: #1f2937;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    padding: 16px 18px 18px;
}

.kb-user-card-close {
    position: absolute;
    top: 8px;
    right: 10px;
    border: none;
    background: none;
    font-size: 18px;
    line-height: 1;
    color: #9ca3af;
    cursor: pointer;
}

.kb-user-card-close:hover {
    color: #4b5563;
}

.kb-user-card-name {
    margin: 0 18px 4px 0;
    font-size: 16px;
    font-weight: 600;
    color: #111827;
}

.kb-user-card-role {
    margin: 0 0 10px 0;
    font-size: 13px;
    color: #6b7280;
}

.kb-user-card-row {
    display: block;
    font-size: 13px;
    margin-top: 6px;
}

.kb-user-card-row a {
    color: #2563eb;
    text-decoration: none;
}

.kb-user-card-row a:hover {
    text-decoration: underline;
}

.kb-user-card-empty {
    font-size: 13px;
    color: #6b7280;
}

.kb-plain {
    white-space: pre-wrap;
    word-break: break-word;
}

/* Admin forms */
.kb-form {
    max-width: 760px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 20px 24px;
}

.kb-markdown-input {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
    width: 100%;
}

.kb-status-toggle label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* Inline validation message (e.g. "Select an account to author this article"). */
.kb-form-error {
    margin-top: 6px;
    font-size: 13px;
    color: #b91c1c;
}

.kb-cat-list {
    list-style: none;
    margin: 0 0 16px 0;
    padding: 0;
}

.kb-cat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #f0f2f5;
}

/* Dark mode parity with the rest of the SPA */
body.dark-mode .kb-list-pane,
body.dark-mode .kb-detail-pane,
body.dark-mode .kb-form {
    background: #1f2430;
    border-color: #2d3340;
}

body.dark-mode .kb-article-item:hover {
    background: #262c3a;
}

body.dark-mode .kb-article-title,
body.dark-mode .kb-detail-title,
body.dark-mode .kb-detail-body {
    color: #e5e7eb;
}

body.dark-mode .kb-scope-prompt {
    color: #cbd5e1;
}

body.dark-mode .kb-detail-body pre,
body.dark-mode .kb-detail-body code {
    background: #11151d;
    color: #e5e7eb;
}

body.dark-mode .kb-form-error {
    color: #f87171;
}

/* Dark-mode parity for the Phase 4a additions: bordered tables + contact card. */
body.dark-mode .kb-detail-body th,
body.dark-mode .kb-detail-body td {
    border-color: var(--border-color, #2d3340);
}

body.dark-mode .kb-detail-body th {
    background: var(--surface-2, #262c3a);
}

body.dark-mode .kb-detail-body tbody tr:nth-child(even) td {
    background: var(--surface-1, #232936);
}

body.dark-mode .kb-user-card {
    background: #1f2430;
    color: #e5e7eb;
    border-color: #2d3340;
}

body.dark-mode .kb-user-card-name {
    color: #f3f4f6;
}

body.dark-mode .kb-user-card-role,
body.dark-mode .kb-user-card-empty {
    color: #9ca3af;
}

/* -----------------------------------------------------------------------------
   Phase 4b — collaboration panel (watchers / maintainers / contributors).
   Mounted as a footer inside .kb-detail; each section is a labelled block. The
   watch toggle reflects is_watching, the maintainers list carries an inline
   add + per-row remove for the author/admin, contributors are read-only.
   ----------------------------------------------------------------------------- */
.kb-collab {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.kb-collab-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.kb-collab-section-head {
    display: flex;
    align-items: center;
    gap: 10px;
}

.kb-collab-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6b7280;
}

.kb-collab-watch {
    display: flex;
    align-items: center;
    gap: 10px;
}

.kb-collab-watch-btn[data-watching="1"] {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.kb-collab-watch-count {
    font-size: 13px;
    color: #6b7280;
}

.kb-collab-people {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.kb-collab-person {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f3f4f6;
    border-radius: 14px;
    padding: 4px 10px;
    font-size: 13px;
}

.kb-collab-remove {
    border: none;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
}

.kb-collab-remove:hover {
    color: #dc2626;
}

.kb-collab-empty {
    margin: 0;
    font-size: 13px;
    color: #9ca3af;
}

body.dark-mode .kb-collab {
    border-top-color: #2d3340;
}

body.dark-mode .kb-collab-label {
    color: #9ca3af;
}

body.dark-mode .kb-collab-person {
    background: #2a2f3a;
    color: #e5e7eb;
}

body.dark-mode .kb-collab-watch-count,
body.dark-mode .kb-collab-empty {
    color: #9ca3af;
}
