/* ============================================================================
   kb.css — Knowledge Base feature layer (CR-034 Phase 2)

   Feature-only styling for the KB tab, kept out of the shared foundation
   (components.css / app.css) per the CR-034 caution: "most of this is feature
   CSS, not a design-system upgrade." Every value is a semantic design token, so
   dark mode (Phase 1b) applies for free — no hardcoded colours here.

   The reframe (ux-requirements-3 §6): a calm documentation *library* — a lighter
   folder rail, additive type/status/sort facets, and a scannable row list whose
   secondary actions live in a compact overflow menu instead of cluttering every
   row. No vocabulary fork: empty/loading reuse the shared .empty / .skeleton.
   ============================================================================ */

/* ── Layout: rail + main column ─────────────────────────────────────────── */
.kb-layout {
  display: flex;
  gap: var(--space-6);
  align-items: flex-start;
}
.kb-main { flex: 1; min-width: 0; }

/* ── Folder rail (lighter than the old boxed btn list) ──────────────────── */
.kb-rail {
  flex: 0 0 224px;
  position: sticky;
  top: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.kb-rail-label {
  font-size: var(--fs-label);
  font-weight: var(--fw-label);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding: var(--space-1) var(--space-2);
  margin-top: var(--space-2);
}
.kb-folder-line {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: var(--radius-md);
}
.kb-folder-line:hover { background: var(--color-surface-raised); }
.kb-folder {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2);
  background: transparent;
  border: 0;
  border-radius: var(--radius-md);
  color: var(--color-text-body);
  font-size: var(--fs-body-sm);
  text-align: left;
  cursor: pointer;
  transition: color var(--motion-fast, 120ms) ease;
}
.kb-folder:hover { color: var(--color-text-heading); }
.kb-folder.is-active {
  color: var(--color-text-heading);
  font-weight: 600;
  background: var(--color-surface-raised);
}
.kb-folder-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kb-folder-count {
  margin-left: auto;
  color: var(--color-text-muted);
  font-size: var(--fs-caption);
  font-variant-numeric: tabular-nums;
}
.kb-folder-lock { color: var(--color-warning-text); flex: none; }
/* Per-folder actions (access / rename / delete) reveal on hover — declutter. */
.kb-folder-actions {
  display: flex;
  align-items: center;
  gap: 0;
  opacity: 0;
  transition: opacity var(--motion-fast, 120ms) ease;
}
.kb-folder-line:hover .kb-folder-actions,
.kb-folder-line:focus-within .kb-folder-actions { opacity: 1; }
.kb-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
}
.kb-icon-btn:hover { background: var(--color-border-subtle); color: var(--color-text-heading); }

/* ── Breadcrumb + facet toolbar ─────────────────────────────────────────── */
.kb-crumb {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--fs-caption);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-3);
}
.kb-crumb-current { color: var(--color-text-heading); font-weight: 600; }
.kb-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}
.kb-toolbar .select { height: 32px; font-size: var(--fs-body-sm); }
.kb-toolbar-count {
  margin-left: auto;
  font-size: var(--fs-caption);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── Document list — hairline-divided rows, not boxed cards ──────────────── */
.doc-list { display: flex; flex-direction: column; }
.doc-item + .doc-item { border-top: 1px solid var(--color-border-subtle); }
.doc-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-2);
  border-radius: var(--radius-md);
  transition: background var(--motion-fast, 120ms) ease;
}
.doc-row:hover { background: var(--color-surface-raised); }
.doc-row-main {
  flex: 1;
  min-width: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.doc-row-title {
  font-size: var(--fs-body);
  font-weight: 600;
  color: var(--color-text-heading);
  line-height: var(--lh-body);
}
.doc-row-main:hover .doc-row-title { color: var(--color-text-link); }
.doc-row-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-size: var(--fs-caption);
  color: var(--color-text-muted);
}
.doc-row-meta .badge { flex: none; }
.doc-row-desc {
  font-size: var(--fs-body-sm);
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60ch;
}
.doc-row-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

/* ── Compact overflow (⋯) menu for secondary actions ────────────────────── */
.kb-overflow { position: relative; }
.kb-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  min-width: 208px;
  background: var(--color-surface-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg, var(--shadow-md));
  padding: var(--space-1);
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.kb-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--color-text-body);
  font-size: var(--fs-body-sm);
  text-align: left;
  cursor: pointer;
}
.kb-menu-item:hover { background: var(--color-surface-raised); color: var(--color-text-heading); }
.kb-menu-item.is-danger { color: var(--color-error-text); }
.kb-menu-item.is-danger:hover { background: var(--color-error-subtle, var(--color-surface-raised)); }
.kb-menu-item svg { flex: none; color: var(--color-text-muted); }
.kb-menu-item.is-danger svg { color: var(--color-error-text); }
.kb-menu-sep { height: 1px; background: var(--color-border-subtle); margin: var(--space-1) 0; }
.kb-menu-label {
  font-size: var(--fs-label);
  font-weight: var(--fw-label);
  color: var(--color-text-muted);
  padding: var(--space-1) var(--space-2) 2px;
}
.kb-menu .select { width: 100%; height: 32px; font-size: var(--fs-body-sm); }

/* ── Version history panel (revealed under a row) ───────────────────────── */
.doc-versions {
  padding: 0 var(--space-2) var(--space-4);
  margin-top: calc(-1 * var(--space-1));
}
.doc-versions-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.doc-version {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-raised);
  border-radius: var(--radius-md);
}

/* ============================================================================
   Reader (CR-034 Phase 2b) — a read-first "reading room" (ux-requirements-3 §9.2)
   The body reuses the shared wiki widget mounted read-only; these rules strip the
   editor-pane chrome and widen it for comfortable reading. Specificity is kept
   above the widget's own inline `.wiki-editor .X` rules (which load later in the
   body) by scoping through `.wiki-editor.wiki-reading …`.
   ============================================================================ */
.rd-header { margin-bottom: var(--space-5); }
.rd-crumb-link {
  background: none; border: 0; padding: 0; margin: 0;
  font: inherit; color: var(--color-text-muted); cursor: pointer;
}
.rd-crumb-link:hover { color: var(--color-text-link); }
.rd-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.rd-heading { min-width: 0; }
.rd-title {
  font-size: var(--fs-h1);
  font-weight: var(--fw-h1);
  line-height: var(--lh-h1);
  color: var(--color-text-heading);
  margin: var(--space-2) 0;
  text-wrap: balance;
}
.rd-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-size: var(--fs-caption);
  color: var(--color-text-muted);
}
.rd-tools { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }

/* Report data-freshness banner (generated docs) */
.rd-fresh {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-4);
  background: var(--color-info-subtle, var(--color-surface-raised));
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-body);
  font-size: var(--fs-body-sm);
}
.rd-fresh svg { color: var(--color-info-text, var(--color-text-muted)); flex: none; }
.rd-fresh-text { flex: 1; min-width: 0; }

/* CR-034 §16.6 — offline reading indicator (a saved copy is being shown) */
.rd-offline {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-4);
  background: var(--color-warning-subtle, var(--color-surface-raised));
  border: 1px solid var(--color-warning-border, var(--color-border));
  border-radius: var(--radius-md);
  color: var(--color-text-body);
  font-size: var(--fs-body-sm);
}
.rd-offline svg { color: var(--color-warning-text, var(--color-text-muted)); flex: none; }

/* Mobile authoring boundary — "edit on a larger screen" (§9.3) */
.rd-mobile-note { display: none; margin: var(--space-3) 0 0; font-size: var(--fs-body-sm); color: var(--color-text-muted); }

/* Reading room: strip the editor pane's border/toolbar feel, cap the measure.
   The pane keeps its internal scroll (an ancestor .project-shell is overflow:hidden,
   so page-level sticky/scroll can't be relied on — the widget scrolls in-pane). */
.wiki-editor.wiki-reading .ProseMirror {
  border: none;
  border-radius: 0;
  padding: 0 0 var(--space-8);
  min-height: 0;
  max-width: 74ch;
  margin: 0 auto;
  font-size: var(--fs-body-lg);
  line-height: var(--lh-body-lg);
  color: var(--color-text-body);
}
.wiki-editor.wiki-reading .ProseMirror:focus { border: none; }
/* Scroll-spy: highlight the section currently in view (specificity beats .req). */
.wiki-editor .wiki-nav a.is-active {
  background: var(--color-surface-raised);
  color: var(--color-text-heading);
  font-weight: 600;
  border-left-color: var(--color-primary);
}

/* ── Responsive: rail collapses to a horizontal chip scroller (§9.1) ────── */
@media (max-width: 720px) {
  .kb-layout { flex-direction: column; gap: var(--space-4); }
  .kb-rail {
    flex: none;
    width: 100%;
    position: static;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: var(--space-1);
    padding-bottom: var(--space-1);
  }
  .kb-rail-label { display: none; }
  .kb-folder-line { flex: none; }
  .kb-folder { white-space: nowrap; }
  .kb-folder-actions { display: none; }   /* folder management is desktop-only */
  .doc-row-desc { display: none; }
  .rd-desktop-only { display: none !important; }   /* authoring is desktop-only (§9.3) */
  .rd-mobile-note { display: block; }
}
