/* Knowledge base module (Confluence-style). Uses the theme variables from /static/css/app.css (light + dark). */

/* ---------- space colours ---------- */
.kb-colour-orange { --kb-c: var(--brand); } .kb-colour-red { --kb-c: var(--bad); } .kb-colour-amber { --kb-c: #D48A00; }
.kb-colour-green { --kb-c: var(--ok); } .kb-colour-teal { --kb-c: #11806A; } .kb-colour-blue { --kb-c: var(--blue); }
.kb-colour-purple { --kb-c: var(--purple); } .kb-colour-grey { --kb-c: var(--muted); }
.kb-space-icon { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 6px; background: var(--kb-c, var(--brand)); color: #fff; font-weight: 700; font-size: .85rem; flex: none; letter-spacing: .02em; }
.kb-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--kb-c, var(--brand)); margin-right: .4rem; vertical-align: middle; }

/* ---------- home ---------- */
.kb-search-bar input[type=search] { font-size: 1rem; padding: .65rem .8rem; }
.kb-section-title { margin-top: .5rem; }
.kb-space-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .75rem; margin-bottom: 1.5rem; }
.kb-space-card { display: flex; gap: .8rem; align-items: flex-start; padding: .9rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none !important; }
.kb-space-card:hover { border-color: var(--muted); }
.kb-space-text { display: flex; flex-direction: column; min-width: 0; }
.kb-space-desc { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: .2rem; }
.kb-space-new { align-items: center; justify-content: center; color: var(--brand-strong); font-weight: 600; border-style: dashed; }

/* ---------- page layout ---------- */
.kb-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.kb-sidebar { position: sticky; top: 4.5rem; max-height: calc(100vh - 5.5rem); overflow: auto; padding: .25rem .25rem 1rem 0; border-right: 1px solid var(--line); }
.kb-side-space { display: flex; align-items: center; gap: .6rem; color: var(--ink); text-decoration: none !important; margin-bottom: .75rem; }
.kb-side-space .kb-space-icon { width: 32px; height: 32px; font-size: .75rem; }
.kb-side-create { width: calc(100% - .75rem); justify-content: center; margin-bottom: .75rem; }
.kb-main { min-width: 0; }
.kb-crumbs { margin-bottom: .5rem !important; }
.kb-page-head h1 { font-size: 1.75rem; }
.kb-page-head .head-actions form { margin: 0; }
.kb-tree { list-style: none; margin: 0; padding: 0 0 0 .9rem; font-size: .88rem; }
.kb-tree.kb-tree-root { padding-left: 0; }
.kb-tree li { margin: 0; }
.kb-tree a { display: inline-block; padding: .22rem .4rem; border-radius: 3px; color: var(--ink); text-decoration: none; max-width: 100%; overflow-wrap: anywhere; }
.kb-tree a:hover { background: var(--surface-2); }
.kb-tree a.active { background: var(--surface-2); color: var(--brand-strong); font-weight: 600; box-shadow: inset 3px 0 0 var(--brand); }
.kb-tree li:not(.has-children) > a { margin-left: 1rem; }
.kb-tree summary { cursor: pointer; list-style: none; display: flex; align-items: baseline; gap: .1rem; }
.kb-tree summary::-webkit-details-marker { display: none; }
.kb-tree summary::before { content: '▸'; width: 1rem; flex: none; color: var(--muted); font-size: .8rem; transition: transform .1s; display: inline-block; text-align: center; }
.kb-tree details[open] > summary::before { transform: rotate(90deg); }
.kb-tree .tag { font-size: .65rem; padding: 0 .3rem; }
.kb-banner { padding: .55rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .88rem; font-weight: 500; }
.kb-banner-draft { background: var(--warn-bg); color: var(--warn); }
.kb-banner-old { background: var(--blue-bg); color: var(--blue); }
.kb-labels { display: flex; flex-wrap: wrap; gap: .35rem; margin: 0 0 1rem; }
.kb-results .kb-labels { margin: .35rem 0 0; }
.kb-label { font-size: .75rem; padding: .1rem .5rem; border-radius: 3px; background: var(--blue-bg); color: var(--blue); text-decoration: none; font-weight: 500; }
.kb-label:hover { text-decoration: underline; }
.kb-children { margin: 0; padding-left: 1.2rem; }
.kb-menu { position: relative; }
.kb-menu > summary { list-style: none; }
.kb-menu > summary::-webkit-details-marker { display: none; }
.kb-menu-list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0,0,0,.15); padding: .4rem 0; min-width: 230px; display: flex; flex-direction: column; }
.kb-menu-list a, .kb-menu-list .btn-link { display: block; width: 100%; text-align: left; padding: .45rem .9rem; color: var(--ink); text-decoration: none; font-size: .88rem; }
.kb-menu-list a:hover, .kb-menu-list .btn-link:hover { background: var(--surface-2); }
.kb-menu-list form { margin: 0; }
.kb-danger, .kb-menu-list .kb-danger { color: var(--bad) !important; }
.kb-inline-form { display: inline; margin: 0 0 0 .5rem; }
.kb-inline-search input { width: 200px; padding: .45rem .6rem; }
.kb-space-description { color: var(--muted); max-width: 75ch; }
.kb-archived summary { cursor: pointer; }
.kb-upload-btn { cursor: pointer; }
.kb-comment-form { margin-top: 1rem; }

/* ---------- rendered page content (also used inside the editor) ---------- */
.kb-content { line-height: 1.65; font-size: .98rem; overflow-wrap: anywhere; max-width: 90ch; }
.kb-content-card { padding: 1.5rem 1.8rem; }
.kb-content > :first-child { margin-top: 0; }
.kb-content h2 { font-size: 1.35rem; margin: 1.6rem 0 .6rem; }
.kb-content h3 { font-size: 1.12rem; margin: 1.3rem 0 .5rem; }
.kb-content h4 { font-size: 1rem; margin: 1.1rem 0 .4rem; }
.kb-content p { margin: 0 0 .8rem; }
.kb-content ul, .kb-content ol { margin: 0 0 .9rem; padding-left: 1.6rem; }
.kb-content li { margin: .15rem 0; }
.kb-content li > p { margin: 0; }
.kb-content blockquote { margin: 0 0 1rem; padding: .3rem 1rem; border-left: 4px solid var(--line); color: var(--muted); }
.kb-content pre { background: #1B201F; color: #ECECE8; border: 1px solid var(--line); padding: .9rem 1rem; border-radius: var(--radius); overflow-x: auto; font-size: .85rem; line-height: 1.5; margin: 0 0 1rem; white-space: pre; }
.kb-content pre code { background: none; padding: 0; color: inherit; font-size: inherit; }
.kb-content pre[data-lang]::before { content: attr(data-lang); display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; opacity: .65; margin-bottom: .4rem; font-family: var(--font); }
.kb-content code, .kb-content pre { font-family: Consolas, 'Cascadia Mono', Menlo, monospace; }
.kb-content hr { border: 0; border-top: 2px solid var(--line); margin: 1.5rem 0; }
.kb-content img { max-width: 100%; height: auto; border-radius: 3px; border: 1px solid var(--line); }
.kb-content table { border-collapse: collapse; margin: 0 0 1rem; min-width: 50%; font-size: .92rem; display: block; overflow-x: auto; max-width: 100%; }
.kb-content th, .kb-content td { border: 1px solid var(--line); padding: .45rem .7rem; vertical-align: top; text-align: left; min-width: 4rem; }
.kb-content th { background: var(--surface-2); font-weight: 600; }
.kb-content mark { background: #FFE58A; color: #1B201F; }
.kb-content a.kb-page-link::before { content: '📄 '; font-size: .85em; }
.kb-content a.kb-attachment-link::before { content: '📎 '; font-size: .85em; }

.kb-callout { border-radius: var(--radius); padding: .8rem 1rem .8rem 2.6rem; margin: 0 0 1rem; position: relative; border: 1px solid transparent; }
.kb-callout::before { position: absolute; left: .85rem; top: .8rem; font-weight: 700; width: 1.2rem; height: 1.2rem; border-radius: 50%; display: grid; place-items: center; font-size: .75rem; color: #fff; }
.kb-callout > :last-child { margin-bottom: 0; }
.kb-callout-info { background: var(--blue-bg); border-color: color-mix(in srgb, var(--blue) 30%, transparent); }
.kb-callout-info::before { content: 'i'; background: var(--blue); }
.kb-callout-note { background: var(--purple-bg); border-color: color-mix(in srgb, var(--purple) 30%, transparent); }
.kb-callout-note::before { content: '✎'; background: var(--purple); }
.kb-callout-success { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.kb-callout-success::before { content: '✓'; background: var(--ok); }
.kb-callout-warning { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.kb-callout-warning::before { content: '!'; background: #D48A00; }
.kb-callout-title { margin-bottom: .3rem !important; }
.kb-placeholder { display: inline-block; background: var(--surface-2); border: 1px dashed var(--muted); color: var(--muted); padding: .1rem .5rem; border-radius: 3px; font-size: .85rem; }
div.kb-placeholder { display: block; padding: .6rem .9rem; margin: 0 0 1rem; }
.kb-status { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; padding: .05rem .45rem; border-radius: 3px; letter-spacing: .03em; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.kb-status-red { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.kb-status-yellow { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.kb-status-green { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.kb-status-blue { background: var(--blue-bg); color: var(--blue); border-color: transparent; }
.kb-status-purple { background: var(--purple-bg); color: var(--purple); border-color: transparent; }

.kb-checklist { list-style: none; padding-left: .2rem !important; }
.kb-checklist .kb-task { position: relative; padding-left: 1.8rem; }
.kb-checklist .kb-task::before { content: ''; position: absolute; left: 0; top: .25em; width: 1.05rem; height: 1.05rem; border: 2px solid var(--muted); border-radius: 3px; background: var(--surface); box-sizing: border-box; }
.kb-checklist .kb-task-done::before { content: '✓'; background: var(--ok); border-color: var(--ok); color: #fff; font-size: .75rem; font-weight: 700; display: grid; place-items: center; line-height: 1; }
.kb-checklist .kb-task-done { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }

/* ---------- search ---------- */
.kb-snippet { color: var(--ink); }
.kb-snippet mark, .kb-diff ins, .kb-diff del { padding: 0 .1rem; border-radius: 2px; }
.kb-snippet mark { background: #FFE58A; color: #1B201F; }

/* ---------- templates picker ---------- */
.kb-template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .6rem; }
.form label.kb-template { flex-direction: row; align-items: flex-start; gap: .6rem; border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .85rem; margin: 0; cursor: pointer; background: var(--surface); }
.form label.kb-template:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.kb-template span { display: flex; flex-direction: column; gap: .2rem; }

/* ---------- editor ---------- */
.kb-edit-form { max-width: 1100px; }
.kb-edit-top { display: flex; gap: 1rem; align-items: center; margin-bottom: .75rem; flex-wrap: wrap; }
.form label.kb-title-field { flex: 1 1 400px; margin: 0; }
.kb-title-input { font-size: 1.5rem; font-weight: 600; padding: .45rem .6rem; }
.kb-edit-actions { display: flex; gap: .75rem; align-items: center; }
.kb-edit-actions select { width: auto; }
.kb-toolbar { display: flex; flex-wrap: wrap; gap: .35rem .6rem; align-items: center; padding: .45rem .5rem; background: var(--surface-2); border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; position: sticky; top: 3.6rem; z-index: 4; }
.kb-toolbar[hidden], .kb-editor-area[hidden], [data-kb-table-tools][hidden] { display: none; }
.kb-toolbar select { width: auto; padding: .3rem .4rem; font-size: .85rem; }
.kb-tb-group { display: inline-flex; gap: 2px; border-left: 1px solid var(--line); padding-left: .5rem; }
.kb-toolbar button { font: inherit; font-size: .82rem; padding: .3rem .5rem; min-width: 2rem; border: 1px solid transparent; background: transparent; color: var(--ink); border-radius: 3px; cursor: pointer; }
.kb-toolbar button:hover { background: var(--surface); border-color: var(--line); }
.kb-toolbar button.is-active, .kb-toolbar button[aria-pressed=true] { background: var(--surface); border-color: var(--brand); color: var(--brand-strong); }
.kb-tb-info { color: var(--blue) !important; } .kb-tb-note { color: var(--purple) !important; } .kb-tb-success { color: var(--ok) !important; } .kb-tb-warning { color: var(--warn) !important; }
.kb-editor-area { min-height: 420px; max-width: none; background: var(--surface); border: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); padding: 1.2rem 1.5rem; margin-bottom: 1rem; outline: none; }
.kb-editor-area:focus { border-color: var(--brand); }
.kb-editor-area .kb-task::before { cursor: pointer; }
.kb-editor-area table td, .kb-editor-area table th { min-width: 5rem; }
.kb-editor-area .kb-cell-active { outline: 2px solid var(--brand); outline-offset: -2px; }
.kb-source { font-family: Consolas, 'Cascadia Mono', Menlo, monospace; font-size: .82rem; }
.kb-enhanced .kb-source-label { display: none; }
.kb-enhanced.kb-source-mode .kb-source-label { display: flex; }
.kb-enhanced.kb-source-mode .kb-editor-area { display: none; }
.kb-source-hint { font-weight: 400; color: var(--muted); }
.kb-picker { position: fixed; z-index: 30; top: 18vh; left: 50%; transform: translateX(-50%); width: min(560px, 92vw); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 20px 50px rgba(0,0,0,.3); padding: 1rem 1.1rem; }
.kb-picker[hidden] { display: none; }
.kb-picker ul { list-style: none; margin: .5rem 0; padding: 0; max-height: 50vh; overflow: auto; }
.kb-picker li button { width: 100%; text-align: left; background: none; border: 0; padding: .5rem .6rem; font: inherit; color: var(--ink); cursor: pointer; border-radius: 3px; }
.kb-picker li button:hover, .kb-picker li button:focus { background: var(--surface-2); outline: none; }
.kb-picker li small { color: var(--muted); margin-left: .4rem; }
.kb-att-list { margin: 0; padding-left: 1.2rem; font-size: .9rem; }
.kb-att-list .btn-link { margin-left: .5rem; font-size: .85rem; }

/* ---------- history / diff ---------- */
.kb-diff { font-family: Consolas, 'Cascadia Mono', Menlo, monospace; font-size: .85rem; line-height: 1.55; padding: .6rem 0; }
.kb-diff-line { padding: .05rem 1rem; white-space: pre-wrap; overflow-wrap: anywhere; border-left: 3px solid transparent; }
.kb-diff-line.kb-diff-add { background: var(--ok-bg); border-left-color: var(--ok); }
.kb-diff-line.kb-diff-del { background: var(--bad-bg); border-left-color: var(--bad); }
.kb-diff-line.kb-diff-chg { background: var(--surface-2); border-left-color: var(--warn); }
.kb-diff ins, .kb-diff-key ins { background: var(--ok-bg); color: var(--ok); text-decoration: none; font-weight: 600; }
.kb-diff del, .kb-diff-key del { background: var(--bad-bg); color: var(--bad); }
.kb-diff-summary { display: flex; gap: 1rem; align-items: baseline; flex-wrap: wrap; font-size: .9rem; }
.kb-compare-pick { display: flex; gap: .6rem; align-items: center; }
.kb-compare-pick label { margin: 0; }

/* ---------- import ---------- */
.kb-progress { width: 100%; height: 14px; accent-color: var(--brand); }
.kb-log { white-space: pre-wrap; font-size: .78rem; max-height: 60vh; overflow: auto; background: var(--surface-2); padding: .8rem 1rem; border-radius: var(--radius); margin: 0; }
.kb-remote-spaces { margin-top: 1rem; }

/* ---------- ticket panel ---------- */
.kb-ticket-panel { font-size: .88rem; }
.kb-panel-sub { margin: .3rem 0 .2rem !important; text-transform: uppercase; letter-spacing: .05em; font-size: .7rem !important; }
.kb-panel-list { list-style: none; padding: 0; margin: 0 0 .6rem; }
.kb-panel-list li { padding: .35rem 0; border-bottom: 1px solid var(--line); }
.kb-panel-list li:last-child { border-bottom: 0; }
.kb-panel-actions { display: flex; flex-wrap: wrap; gap: .1rem .7rem; font-size: .8rem; }
.kb-panel-actions .kb-inline-form { margin: 0; }
.kb-link-form { margin-top: .5rem; }
.kb-link-row { display: flex; gap: .4rem; margin-top: .2rem; }
.kb-link-row input { flex: 1; min-width: 0; padding: .4rem .5rem; }
.kb-link-row .btn { padding: .4rem .7rem; }
.kb-toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: .55rem 1rem; border-radius: var(--radius); font-size: .88rem; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.25); }

@media (max-width: 960px) {
  .kb-layout { grid-template-columns: 1fr; }
  .kb-sidebar { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); padding-bottom: .75rem; }
  .kb-content-card { padding: 1.1rem; }
  .kb-toolbar { top: 3.2rem; }
}
@media print {
  .kb-sidebar, .kb-page-head .head-actions, #comments, #attachments, .kb-crumbs { display: none !important; }
  .kb-layout { display: block; }
}
