/* ===================================================================
   SPT Internal Portal — Styles
   =================================================================== */

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #242836;
  --text-primary: #e4e6ef;
  --text-secondary: #9ca0b0;
  --text-muted: #6b7084;
  --accent: #6c8cff;
  --accent-hover: #8ba3ff;
  --accent-dim: rgba(108, 140, 255, 0.12);
  --border: #2a2e3d;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius: 8px;
  --sidebar-width: 280px;
  --nav-height: 56px;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.65;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ---- Accessibility primitives (portal-wide) ---- */
.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  z-index: 200;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: #04101f;
  border-radius: 0 0 var(--radius) 0;
  font-size: 0.85rem;
  font-weight: 600;
}
.skip-link:focus { left: 0; }

.page-wrapper:focus { outline: none; }

a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--accent-hover);
  outline-offset: 2px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Top Nav ---- */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--nav-height);
  padding: 0 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.nav-left, .nav-right { display: flex; align-items: center; gap: 1rem; }

.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-primary);
  margin-right: 0.5rem;
}

.nav-link {
  font-size: 0.875rem;
  color: var(--text-secondary);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.user-menu { display: flex; align-items: center; gap: 0.6rem; }
.avatar { width: 28px; height: 28px; border-radius: 50%; }
.username { font-size: 0.85rem; color: var(--text-secondary); }
.logout { font-size: 0.8rem; opacity: 0.6; }

/* ---- Search ---- */
.search-wrapper { position: relative; }
#search-input {
  width: 240px;
  padding: 0.45rem 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s;
}
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--text-muted); }

.search-results {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  width: 360px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 0.35rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.search-results.active { display: block; }
.search-result-item {
  display: block;
  padding: 0.65rem 1rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}
.search-result-item:hover { background: var(--accent-dim); }

/* ---- Layout ---- */
.page-wrapper { min-height: calc(100vh - var(--nav-height) - 48px); }

.content-layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  padding: 1.5rem 1rem;
  border-right: 1px solid var(--border);
  position: sticky;
  top: var(--nav-height);
  height: calc(100vh - var(--nav-height));
  overflow-y: auto;
}

.sidebar-header {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.5rem 0.75rem;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-link {
  display: block;
  padding: 0.45rem 0.75rem;
  font-size: 0.84rem;
  color: var(--text-secondary);
  border-radius: 6px;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-link:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.sidebar-link.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 500;
}

/* ---- Main Content ---- */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 2rem 3rem;
}

.breadcrumb {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.breadcrumb a { color: var(--text-secondary); }

.main-content h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  line-height: 1.3;
}

/* ---- Sections Grid ---- */
.sections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 2rem;
}

.section-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1.25rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, transform 0.1s;
  color: var(--text-primary);
}
.section-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.section-card.compact {
  flex-direction: row;
  align-items: center;
  padding: 0.85rem 1rem;
}

.section-icon { font-size: 1.5rem; }
.section-title { font-weight: 600; font-size: 0.95rem; }
.section-desc { font-size: 0.82rem; color: var(--text-secondary); }

/* ---- Notion Content ---- */
.notion-content { max-width: 800px; }
.notion-content p { margin-bottom: 1rem; color: var(--text-secondary); }
.notion-content h2 { font-size: 1.5rem; margin: 2rem 0 0.75rem; color: var(--text-primary); }
.notion-content h3 { font-size: 1.25rem; margin: 1.75rem 0 0.6rem; color: var(--text-primary); }
.notion-content h4 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; color: var(--text-primary); }
.notion-content ul, .notion-content ol { margin: 0.5rem 0 1rem 1.5rem; color: var(--text-secondary); }
.notion-content li { margin-bottom: 0.35rem; }
.notion-content strong { color: var(--text-primary); }
.notion-content code {
  background: var(--bg-tertiary);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.88em;
}
.notion-content pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
  margin: 1rem 0;
}
.notion-content pre code { background: none; padding: 0; }
.notion-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  background: var(--accent-dim);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.notion-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}
.notion-content details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 0.75rem 0;
  background: var(--bg-secondary);
}
.notion-content summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-primary);
}

.callout {
  display: flex;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 1rem 0;
}
.callout-icon { font-size: 1.2rem; flex-shrink: 0; }

.table-wrapper { overflow-x: auto; margin: 1rem 0; }
.notion-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.notion-content td, .notion-content th {
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  text-align: left;
}
.notion-content tr:first-child td { background: var(--bg-tertiary); font-weight: 600; }

.notion-content figure { margin: 1.5rem 0; }
.notion-content img { max-width: 100%; border-radius: var(--radius); }
.notion-content figcaption { font-size: 0.82rem; color: var(--text-muted); margin-top: 0.5rem; text-align: center; }

.child-page-link {
  padding: 0.5rem 0;
}
.child-page-link a {
  color: var(--accent);
  font-weight: 500;
}

.columns { display: flex; gap: 1.5rem; }
.column { flex: 1; min-width: 0; }

/* ---- File list ---- */
.file-list { display: flex; flex-direction: column; gap: 4px; margin-top: 1rem; }
.file-item {
  display: block;
  padding: 0.6rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.875rem;
}
.file-item:hover { border-color: var(--accent); }

/* ---- Child pages ---- */
.child-pages { margin-top: 2rem; }
.child-pages h3 { margin-bottom: 0.75rem; }

/* ---- Login ---- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-primary);
}

.login-card {
  text-align: center;
  padding: 3rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 420px;
  width: 100%;
}

.login-logo { font-size: 3rem; margin-bottom: 1rem; }
.login-card h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.login-subtitle { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.5rem; }
.login-note { color: var(--text-muted); font-size: 0.82rem; margin-bottom: 2rem; }

.btn-github {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1.75rem;
  background: #24292f;
  color: #fff;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid #444;
  transition: background 0.15s;
}
.btn-github:hover { background: #32383f; color: #fff; }

/* ---- Footer ---- */
.site-footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ---- Todo items ---- */
.todo-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0; }

/* ---- Knowledge Graph ---- */
:root {
  --inspector-width: 320px;
  --chat-height: 180px;
}

.kg-main { position: relative; }
.kg-subtitle { color: var(--text-secondary); margin-bottom: 1.5rem; }
.kg-subtitle code { font-size: 0.85em; }

.kg-stats { padding: 0.5rem 0.75rem; display: flex; gap: 1.5rem; }
.kg-stat { display: flex; flex-direction: column; }
.kg-stat-num { font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.kg-stat-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.kg-type-filters { padding: 0 0.75rem; display: flex; flex-direction: column; gap: 4px; }
.kg-filter-label { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--text-secondary); cursor: pointer; }
.kg-filter-label input { accent-color: var(--accent); }

.kg-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* Full-viewport knowledge layout */
.kg-layout { max-width: 100%; width: 100%; }
.kg-layout .kg-sidebar { transition: margin-left 0.3s ease, opacity 0.3s ease; }
.kg-layout .kg-sidebar.collapsed { margin-left: calc(var(--sidebar-width) * -1); opacity: 0; pointer-events: none; }

.kg-main-fullvp { padding: 0; overflow: hidden; display: flex; flex-direction: column; height: calc(100vh - var(--nav-height)); }

/* Split-pane layout */
.kg-split-pane {
  display: grid;
  grid-template-columns: 1fr 4px var(--inspector-width);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.kg-split-left {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.kg-graph-container { position: relative; background: #0a0c10; overflow: hidden; margin-bottom: 0; }

.kg-graph-fullvp {
  flex: 1;
  min-height: 0;
  contain: layout size style;
}

.kg-canvas-3d { width: 100%; height: 100%; position: relative; }
.kg-canvas-3d canvas { display: block; width: 100% !important; height: 100% !important; }

/* Drag handles */
.kg-drag-handle { background: var(--border); transition: background 0.15s; flex-shrink: 0; z-index: 5; }
.kg-drag-handle:hover { background: var(--accent); }
.kg-drag-handle-v { cursor: col-resize; width: 4px; }
.kg-drag-handle-h { cursor: row-resize; height: 4px; }

/* Floating toolbar — bottom right */
.kg-toolbar-float { position: absolute; bottom: 16px; right: 16px; z-index: 10; display: flex; flex-direction: column; gap: 6px; }
.kg-btn { padding: 6px 12px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 6px; color: var(--text-primary); font-size: 0.8rem; cursor: pointer; transition: background 0.12s; }
.kg-btn:hover { background: var(--bg-primary); }
.kg-btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.kg-btn-primary:hover { background: var(--accent-hover); }
.kg-btn-sm { padding: 4px 10px; font-size: 0.75rem; }
.kg-btn-close { background: none; border: none; color: var(--text-muted); font-size: 1.4rem; cursor: pointer; line-height: 1; }
.kg-btn-close:hover { color: var(--text-primary); }
.kg-select { padding: 6px 10px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 6px; color: var(--text-primary); font-size: 0.8rem; }

/* Persona selector */
.kg-persona-select { min-width: 110px; cursor: pointer; transition: border-color 0.15s; outline: none; -webkit-appearance: none; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239ca0b0'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; padding-right: 24px; }
.kg-persona-select:hover { border-color: var(--accent); }
.kg-persona-select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.kg-persona-select option { background: var(--bg-secondary); color: var(--text-primary); }

/* Semantic zoom level indicators */
.kg-3d-label-galaxy { font-weight: 700; font-size: 14px; text-shadow: 0 0 8px currentColor, 0 1px 6px rgba(0,0,0,0.9); }
.kg-3d-label-city { font-weight: 600; font-size: 12px; }
.kg-3d-label-street { font-weight: 500; font-size: 13px; padding: 3px 8px; background: rgba(10,12,16,0.8); border-radius: 4px; border: 1px solid rgba(255,255,255,0.08); }

/* Persona-specific label styles */
.kg-3d-label-persona-executive { font-size: 14px; font-weight: 700; }
.kg-3d-label-persona-newcomer { font-size: 15px; font-weight: 600; }
.kg-3d-label-persona-security { font-size: 12px; font-family: var(--font-mono); }

/* Health aggregate badge on labels */
.kg-health-dot-inline { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-left: 4px; vertical-align: middle; }
.kg-health-dot-green { background: var(--success); }
.kg-health-dot-amber { background: var(--warning); }
.kg-health-dot-red { background: var(--danger); }

/* Breadcrumb bar */
.kg-breadcrumb-bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--bg-secondary); border-bottom: 1px solid var(--border); flex-shrink: 0; min-height: 40px; }
.kg-breadcrumb { display: flex; align-items: center; gap: 4px; font-size: 0.82rem; color: var(--text-muted); flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; }
.kg-breadcrumb-link { color: var(--accent); font-size: 0.82rem; }
.kg-breadcrumb-link:hover { text-decoration: underline; }
.kg-breadcrumb-sep { color: var(--text-muted); font-size: 0.82rem; }

/* Sidebar toggle */
.kg-sidebar-toggle { display: flex; align-items: center; justify-content: center; width: 32px; height: 28px; padding: 0; flex-shrink: 0; }
.kg-hamburger { display: block; width: 16px; height: 2px; background: var(--text-primary); position: relative; }
.kg-hamburger::before, .kg-hamburger::after { content: ''; position: absolute; width: 16px; height: 2px; background: var(--text-primary); left: 0; }
.kg-hamburger::before { top: -5px; }
.kg-hamburger::after { top: 5px; }

/* Search overlay on graph */
.kg-search-overlay { flex-shrink: 0; }
.kg-graph-search-input { width: 200px; padding: 5px 10px; background: rgba(26, 29, 39, 0.85); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border: 1px solid var(--border); border-radius: 6px; color: var(--text-primary); font-size: 0.82rem; outline: none; transition: border-color 0.15s, width 0.3s ease; }
.kg-graph-search-input:focus { border-color: var(--accent); width: 280px; }
.kg-graph-search-input::placeholder { color: var(--text-muted); }

/* Tooltip (hover preview) */
.kg-tooltip {
  position: absolute;
  z-index: 25;
  background: rgba(26, 29, 39, 0.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--text-primary);
  pointer-events: none;
  white-space: nowrap;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: opacity 0.15s ease;
}
.kg-tooltip .kg-tooltip-type {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-left: 6px;
  opacity: 0.7;
}

/* Inspector panel (right) */
.kg-inspector-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  overflow: hidden;
  min-width: 0;
  transition: min-width 0.3s ease, opacity 0.3s ease;
}
.kg-inspector-panel.collapsed {
  min-width: 0;
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  border: none;
}
.kg-inspector-panel.collapsed + .kg-drag-handle-v { display: none; }

.kg-inspector-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 40px;
}
.kg-inspector-title {
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.kg-inspector-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.kg-inspector-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

/* Inspector sections */
.insp-section { margin-bottom: 8px; }
.insp-section-header {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 6px 0;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.insp-section-header::before {
  content: '';
  display: inline-block;
  width: 0; height: 0;
  border-left: 4px solid var(--text-muted);
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
  transition: transform 0.2s ease;
  transform: rotate(90deg);
}
.insp-section-header.collapsed::before { transform: rotate(0deg); }
.insp-section-body { transition: max-height 0.3s ease, opacity 0.3s ease; overflow: hidden; }
.insp-section-body.collapsed { max-height: 0 !important; opacity: 0; padding: 0; }

.insp-conn-group { margin-bottom: 8px; }
.insp-conn-dir { font-size: 0.72rem; color: var(--text-muted); }
.insp-conn-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; padding-left: 8px; }
.insp-conn-list .kg-node-link { font-size: 0.82rem; }

.insp-stat { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 4px; }
.insp-expand-btn { margin-top: 8px; }
.insp-empty { color: var(--text-muted); font-size: 0.85rem; text-align: center; padding: 2rem 1rem; }
.insp-code-placeholder { color: var(--text-muted); font-size: 0.82rem; font-style: italic; padding: 8px; background: var(--bg-tertiary); border-radius: 4px; text-align: center; }

/* Health badges */
.health-badges { display: flex; gap: 12px; margin-bottom: 8px; }
.health-badge { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.health-badge-dots { display: flex; gap: 3px; }
.health-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; border: 1px solid currentColor; }
.health-dot.filled { background: currentColor; }
.health-dot.empty { background: transparent; }
.health-badge-label { font-size: 0.68rem; color: var(--text-muted); text-align: center; white-space: nowrap; }
.health-loading { font-size: 0.82rem; color: var(--text-muted); font-style: italic; }
.health-unavailable { font-size: 0.82rem; color: var(--text-muted); font-style: italic; }
.health-bugs { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--danger); margin-top: 6px; }
.health-bug-indicator { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: health-pulse 1.5s ease-in-out infinite; }
.health-examples { font-size: 0.82rem; color: var(--text-secondary); margin-top: 4px; }
.health-estimated { font-size: 0.68rem; color: var(--text-muted); font-style: italic; margin-top: 6px; }
@keyframes health-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}

/* Chat panel (bottom) */
.kg-chat-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  height: var(--chat-height);
  min-height: 48px;
  max-height: 50vh;
  overflow: hidden;
  transition: height 0.3s ease;
}
.kg-chat-panel.collapsed {
  height: 48px;
  min-height: 48px;
}
.kg-chat-panel.collapsed .kg-chat-messages { display: none; }

.kg-chat-header {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.kg-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.kg-chat-input-row {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.kg-chat-input {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s;
}
.kg-chat-input:focus { border-color: var(--accent); }
.kg-chat-input::placeholder { color: var(--text-muted); }
.kg-chat-send { flex-shrink: 0; }

/* Chat messages */
.chat-msg { display: flex; }
.chat-msg-user { justify-content: flex-end; }
.chat-msg-system { justify-content: flex-start; }

.chat-bubble {
  max-width: 80%;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.4;
  word-break: break-word;
}
.chat-msg-user .chat-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 2px; }
.chat-msg-system .chat-bubble { background: var(--bg-tertiary); color: var(--text-secondary); border-bottom-left-radius: 2px; }

.chat-node-count {
  font-size: 0.72rem;
  color: var(--accent);
  cursor: pointer;
  margin-top: 2px;
  padding-left: 4px;
}
.chat-node-count:hover { text-decoration: underline; }

.chat-examples { padding: 8px 0; }
.chat-examples-title { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 6px; }
.chat-example-chip {
  display: inline-block;
  padding: 4px 8px;
  margin: 2px 4px 2px 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.chat-example-chip:hover { border-color: var(--accent); color: var(--accent); }

/* Typing indicator */
.chat-typing-dots { display: inline-flex; gap: 3px; align-items: center; height: 16px; }
.chat-typing-dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: chat-bounce 1.2s ease-in-out infinite;
}
.chat-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Detail meta (shared between inspector and old detail panel) */
.kg-detail-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 0.75rem; }
.kg-detail-summary { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.75rem; }
.kg-detail-file { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.kg-detail-file code { font-family: var(--font-mono); background: var(--bg-tertiary); padding: 2px 6px; border-radius: 4px; }
.kg-detail-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 0.75rem; }

.kg-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.72rem; font-weight: 600; background: var(--accent-dim); color: var(--accent); text-transform: uppercase; letter-spacing: 0.04em; }
.kg-badge-layer { background: rgba(139, 92, 246, 0.12); color: #8B5CF6; }
.kg-badge-complexity { background: rgba(245, 158, 11, 0.12); color: #F59E0B; }
.kg-badge-edge { background: rgba(16, 185, 129, 0.12); color: #10B981; }

.kg-tag { display: inline-block; padding: 2px 6px; border-radius: 3px; font-size: 0.72rem; background: var(--bg-tertiary); color: var(--text-muted); }

.kg-edge-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 0.75rem; }
.kg-edge-item { font-size: 0.85rem; display: flex; align-items: center; gap: 6px; }
.kg-edge-item .kg-badge { flex-shrink: 0; }
.kg-node-link { color: var(--accent); cursor: pointer; }
.kg-node-link:hover { text-decoration: underline; }

.kg-detail-panel h4 { font-size: 0.85rem; color: var(--text-muted); margin: 1rem 0 0.5rem; text-transform: uppercase; letter-spacing: 0.06em; }

/* Loading spinner */
.kg-loading { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--text-muted); font-size: 0.85rem; z-index: 15; }
.kg-spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: kg-spin 0.8s linear infinite; }
@keyframes kg-spin { to { transform: rotate(360deg); } }

/* Error state */
.kg-error { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: flex; align-items: center; gap: 10px; color: var(--danger); font-size: 0.9rem; z-index: 15; background: rgba(15, 17, 23, 0.9); padding: 12px 20px; border-radius: var(--radius); border: 1px solid var(--danger); }
.kg-error-icon { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; background: var(--danger); color: #fff; font-size: 0.8rem; font-weight: 700; flex-shrink: 0; }

/* Context menu */
.kg-context-menu { position: fixed; z-index: 1000; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5); padding: 4px 0; min-width: 160px; }
.kg-context-item { display: block; width: 100%; padding: 8px 16px; background: none; border: none; color: var(--text-primary); font-size: 0.85rem; text-align: left; cursor: pointer; transition: background 0.1s; }
.kg-context-item:hover { background: var(--accent-dim); color: var(--accent); }

/* 3D labels (CSS2DRenderer) */
.kg-3d-label { font-size: 11px; color: var(--text-secondary); font-family: var(--font-sans); text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8), 0 0 2px rgba(0,0,0,0.9); pointer-events: none; white-space: nowrap; transition: opacity 0.2s ease; }
.kg-3d-label-cluster { font-weight: 600; font-size: 13px; text-shadow: 0 0 6px currentColor, 0 1px 4px rgba(0,0,0,0.8); }
.kg-3d-label-detail { font-weight: 500; font-size: 14px; padding: 2px 6px; background: rgba(10,12,16,0.7); border-radius: 4px; border: 1px solid rgba(255,255,255,0.1); }
.kg-3d-label-hover { font-weight: 600; font-size: 14px; text-shadow: 0 0 10px currentColor; }
.kg-3d-label-selected { font-weight: 700; font-size: 15px; text-shadow: 0 0 12px currentColor, 0 0 24px currentColor; }

/* ---- Code Q&A ---- */
.kg-search-box { margin-bottom: 2rem; }
.kg-search-input { width: 100%; padding: 0.75rem 1rem; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-primary); font-size: 0.95rem; outline: none; margin-bottom: 0.75rem; transition: border-color 0.15s; }
.kg-search-input:focus { border-color: var(--accent); }
.kg-search-input::placeholder { color: var(--text-muted); }
.kg-search-filters { display: flex; gap: 0.5rem; align-items: center; }

.kg-results-count { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1rem; }

.kg-result-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 0.75rem; transition: border-color 0.15s; }
.kg-result-card:hover { border-color: var(--accent); }
.kg-result-header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 0.5rem; }
.kg-result-name { font-weight: 600; font-size: 1rem; color: var(--text-primary); }
.kg-result-name:hover { color: var(--accent); }
.kg-result-summary { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.5rem; }
.kg-result-actions { display: flex; gap: 6px; margin-top: 0.75rem; flex-wrap: wrap; }
.kg-score { font-size: 0.72rem; color: var(--text-muted); margin-left: auto; }

.kg-sub-results { margin-top: 1.5rem; padding: 1rem; background: var(--bg-tertiary); border-radius: var(--radius); border: 1px solid var(--border); }
.kg-sub-results h3 { font-size: 0.95rem; margin-bottom: 0.75rem; }
.kg-dep-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.kg-dep-list li { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; }

/* Q&A detail panel (non-overlay variant) */
.kg-node-detail-panel { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-top: 1rem; }
.kg-node-detail-panel h2 { display: flex; align-items: center; gap: 8px; font-size: 1.2rem; }
.kg-detail-close-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }

/* ---- Responsive ---- */

/* Desktop (>1200px) — sidebar visible, graph fills remaining */
@media (min-width: 1201px) {
  .kg-layout .kg-sidebar { display: block; }
}

/* Tablet (768-1200px) — sidebar collapsed by default, inspector narrower */
@media (max-width: 1200px) and (min-width: 769px) {
  .kg-layout .kg-sidebar { position: fixed; top: var(--nav-height); left: 0; z-index: 50; height: calc(100vh - var(--nav-height)); background: var(--bg-secondary); box-shadow: 4px 0 20px rgba(0, 0, 0, 0.4); margin-left: calc(var(--sidebar-width) * -1); opacity: 0; pointer-events: none; }
  .kg-layout .kg-sidebar.collapsed { margin-left: 0; opacity: 1; pointer-events: auto; }
  .kg-graph-search-input { width: 160px; }
  .kg-graph-search-input:focus { width: 220px; }
  :root { --inspector-width: 280px; }
}

/* Mobile (<768px) — inspector becomes bottom sheet, single column */
@media (max-width: 768px) {
  .sidebar:not(.kg-sidebar) { display: none; }
  .kg-layout .kg-sidebar { position: fixed; top: auto; bottom: 0; left: 0; right: 0; z-index: 50; width: 100%; min-width: 100%; height: 50vh; max-height: 50vh; overflow-y: auto; border-right: none; border-top: 1px solid var(--border); background: var(--bg-secondary); box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4); transform: translateY(100%); transition: transform 0.3s ease; }
  .kg-layout .kg-sidebar.collapsed { transform: translateY(0); }
  .main-content:not(.kg-main-fullvp) { padding: 1.5rem; }
  .kg-main-fullvp { height: calc(100vh - var(--nav-height)); }
  .sections-grid { grid-template-columns: 1fr; }
  #search-input { width: 160px; }
  .columns { flex-direction: column; }
  .kg-toolbar-float { bottom: 12px; right: 12px; }
  .kg-graph-search-input { width: 120px; }
  .kg-graph-search-input:focus { width: 180px; }
  .kg-breadcrumb-bar { padding: 6px 8px; gap: 8px; }

  /* Split pane goes vertical on mobile */
  .kg-split-pane {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto auto;
  }
  .kg-drag-handle-v { display: none; }
  .kg-inspector-panel {
    max-height: 40vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .kg-inspector-panel.collapsed { max-height: 0; }
  .kg-chat-panel { max-height: 30vh; }
}
