/* The Knowledge Base: a full page over the city. Layout: a header band, then the tree of repositories and folders
   on the left and the open document on the right (one at a time on phones). Colour: the page's tokens, with the
   Knowledge Base's teal for its own actions and marks. */
:root { --kb: #14606e; --kb-2: #1b8a9c; --kb-ink: #ffffff; --kb-soft: #e3f3f5; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --kb-2: #49b6c7; --kb-soft: #12303a; } }
:root[data-theme="dark"] { --kb-2: #49b6c7; --kb-soft: #12303a; }

.kb-page {
  position: absolute; inset: 0; z-index: 8; background: var(--bg); color: var(--fg); overflow: hidden;   /* under the toast */
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
.kb-frame { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.kb-page .hint { color: var(--muted); font-size: 12.5px; }
.kb-page .pad { padding: 4px 10px; margin: 0; }
.kb-page .pad.in { padding-left: 32px; }
.kb-page code { font-family: var(--font-mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.kb-page .ic { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }

/* ---- header band */
.kb-top {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: end; gap: 12px 20px;
  padding: 14px 20px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.kb-close {
  align-self: start; border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px;
  padding: 7px 12px; font-weight: 600; font-size: 13px; display: inline-flex; gap: 6px; align-items: center;
}
.kb-close span { font-size: 18px; line-height: 0.6; }
.kb-title { display: grid; gap: 6px; min-width: 0; }
.kb-title h1 { margin: 0; font-family: var(--font-display); font-weight: 800; font-size: 40px; line-height: 0.95; letter-spacing: .01em; }
.kb-stats { display: flex; flex-wrap: wrap; gap: 6px; }
.kb-page .pill { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--kb-soft); color: var(--fg); border: 1px solid color-mix(in srgb, var(--kb-2) 35%, var(--line)); font-variant-numeric: tabular-nums; }
.kb-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.kb-actions .btn, .kb-doc-actions .btn { box-shadow: none; }
.btn.kb-primary { background: var(--kb); color: var(--kb-ink); border-color: transparent; }
.btn.kb-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--kb) 85%, #000); }
.readonly-note { font-size: 13px; color: var(--muted); max-width: 32ch; text-align: right; }

/* ---- body: tree and main */
.kb-body { display: grid; grid-template-columns: minmax(240px, 320px) minmax(0, 1fr); min-height: 0; }
.kb-tree { border-right: 1px solid var(--line); background: var(--surface); overflow-y: auto; padding: 12px 8px 24px; display: grid; align-content: start; gap: 4px; }
.kb-filter input {
  width: 100%; box-sizing: border-box; border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px;
  padding: 7px 10px; margin-bottom: 6px;
}
.kb-sec { margin: 12px 10px 4px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.kb-list { list-style: none; margin: 0; padding: 0; }
.kb-list .kb-list { padding-left: 16px; }
.kb-row { display: flex; align-items: center; border-radius: 6px; }
.kb-row:hover { background: var(--surface-2); }
.kb-row.on { background: var(--kb-soft); }
.kb-row.on .kb-name { font-weight: 700; }
.kb-twisty { width: 22px; flex: none; border: 0; background: none; color: var(--muted); padding: 4px 0; font-size: 11px; text-align: center; }
span.kb-twisty { display: inline-block; }
.kb-node {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px; border: 0; background: none; text-align: left;
  padding: 5px 6px 5px 0; color: var(--fg); font-size: 13.5px;
}
.kb-node .ic { color: var(--kb-2); }
.kb-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: grid; }
.kb-name small { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; }
.kb-count { margin-left: auto; color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; padding-right: 6px; }
.kb-host {
  flex: none; width: 22px; height: 18px; border-radius: 4px; display: inline-grid; place-items: center;
  font-size: 9.5px; font-weight: 800; letter-spacing: .02em; color: #fff; background: #24292f;
}
.kb-host-gitlab { background: #c4401d; }
.kb-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; margin-left: auto; }
.kb-card-s .kb-dot, .kb-facts .kb-dot { margin-left: 0; }
.kb-ok { background: var(--ok); }
.kb-bad { background: var(--bad); }
.kb-busy { background: var(--warn); animation: kb-pulse 1.1s ease-in-out infinite; }
@keyframes kb-pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .kb-busy { animation: none; } }

.kb-main { overflow-y: auto; padding: 22px clamp(16px, 4vw, 48px) 48px; display: grid; align-content: start; gap: 22px; outline: none; }
.kb-main > * { max-width: 860px; }
.kb-back { display: none; justify-self: start; border: 0; background: none; color: var(--fg); font-weight: 600; padding: 0; }
.kb-intro h2 { margin: 0 0 6px; font-family: var(--font-display); font-weight: 800; font-size: 28px; line-height: 1; text-wrap: balance; }
.kb-intro p { margin: 0; color: var(--muted); line-height: 1.55; max-width: 68ch; }
.kb-h3 { margin: 0 0 10px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.kb-start { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.kb-big {
  display: grid; gap: 6px; text-align: left; padding: 16px; border-radius: 12px; border: 1px dashed color-mix(in srgb, var(--kb-2) 60%, var(--line));
  background: var(--surface); color: var(--fg);
}
.kb-big .ic { width: 22px; height: 22px; color: var(--kb-2); }
.kb-big b { font-size: 16px; }
.kb-big span { color: var(--muted); font-size: 13px; line-height: 1.45; }
.kb-big:hover { border-style: solid; }
.kb-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.kb-card {
  display: grid; gap: 6px; align-content: start; text-align: left; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg); min-width: 0;
}
.kb-card:hover { border-color: var(--kb-2); }
.kb-card-h { display: flex; align-items: center; gap: 8px; min-width: 0; }
.kb-card-h b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-card-h .ic { color: var(--kb-2); }
.kb-card-s { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.kb-card-p { color: var(--muted); font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px; }

.kb-doc-h { display: grid; gap: 8px; }
.kb-doc-h h2 { margin: 0; font-family: var(--font-display); font-weight: 800; font-size: 34px; line-height: 1; overflow-wrap: anywhere; }
.kb-doc-h p { margin: 0; }
.kb-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.kb-crumbs a, .kb-crumbs .linkish { color: var(--muted); }
.kb-doc-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.kb-facts { margin: 0; display: grid; gap: 8px; }
.kb-facts div { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 12px; }
.kb-facts dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; padding-top: 2px; }
.kb-facts dd { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.kb-files { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.kb-files li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; border-top: 1px solid var(--line); min-width: 0; }
.kb-files li:first-child { border-top: 0; }
.kb-files .linkish { text-align: left; display: inline-flex; gap: 6px; align-items: center; overflow-wrap: anywhere; text-decoration: none; }
.kb-files .linkish:hover { text-decoration: underline; }
.kb-files .ic { color: var(--kb-2); }

.kb-md { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 28px 20px; font-size: 15px; line-height: 1.65; overflow-wrap: anywhere; }
.kb-md h3, .kb-md h4, .kb-md h5 { margin: 18px 0 6px; line-height: 1.25; }
.kb-md h3 { font-size: 22px; } .kb-md h4 { font-size: 17px; } .kb-md h5 { font-size: 15px; color: var(--muted); }
.kb-md p { margin: 10px 0; max-width: 70ch; }
.kb-md ul, .kb-md ol { padding-left: 22px; }
.kb-md pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.kb-md pre code { border: 0; padding: 0; background: none; }
.kb-raw { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; overflow-x: auto; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55; }
.kb-editor {
  width: 100%; box-sizing: border-box; min-height: 60vh; resize: vertical; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); padding: 16px 18px; font-family: var(--font-mono); font-size: 13.5px; line-height: 1.6;
}
.kb-editor:focus { outline: 2px solid var(--kb-2); outline-offset: 1px; }

/* ---- dialogs */
.kb-scrim { position: absolute; inset: 0; z-index: 2; background: rgba(10, 14, 22, .5); display: grid; place-items: center; padding: 16px; }
.kb-dialog {
  width: min(520px, 100%); max-height: calc(100% - 32px); overflow-y: auto; box-sizing: border-box;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 20px 22px; display: grid; gap: 14px;
}
.kb-dialog h2 { margin: 0; font-family: var(--font-display); font-weight: 800; font-size: 26px; line-height: 1; }
.kb-dialog p { margin: 0; line-height: 1.5; }
.kb-dialog .check { display: flex; gap: 8px; align-items: center; font-size: 13px; margin-top: 4px; }

/* ---- phones: the tree, or the open document, one at a time */
@media (max-width: 760px) {
  .kb-top { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 14px; }
  .kb-close { justify-self: start; }
  .kb-title h1 { font-size: 32px; }
  .kb-actions { justify-content: flex-start; }
  .readonly-note { text-align: left; }
  .kb-body { grid-template-columns: minmax(0, 1fr); }
  .kb-tree { border-right: 0; }
  .kb-main { padding: 16px 16px 40px; }
  .kb-frame.detail .kb-tree { display: none; }
  .kb-frame:not(.detail) .kb-main { display: none; }
  .kb-back { display: inline-flex; gap: 6px; }
  .kb-md { padding: 4px 16px 14px; }
  .kb-facts div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
}

/* ---- the Knowledge Base's label in the city */
.tag.kb { background: #14606e; color: #eafcff; border-color: #14606e; }
.tag.kb small { color: #b4e6ee; }
