.view {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

/* ─── Topbar — matches programs page pattern ─────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  height: 64px;
  box-sizing: border-box;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-bright);
  flex-shrink: 0;
}

.headerStats {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.statChip {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

/* ─── Tab bar ─────────────────────────────────────────── */
/* Tabs occupy row 1 column 1 of .layout grid (240px column).
   Editor in column 2 spans both rows so it starts right under the topbar. */
.tabBar {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  gap: 2px;
  padding: 8px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  box-sizing: border-box;
}

.tabBtn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 8px;
  font-size: 14px;
  font-weight: 400;
  line-height: 1;
  text-align: center;
  color: var(--nav-color);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  outline: none;
  transition: background 0.1s, color 0.1s;
}

.tabBtn:focus { outline: none; }
.tabBtn:focus-visible {
  box-shadow: 0 0 0 1.5px var(--accent-blue);
}

.tabBtn:hover {
  background: var(--bg-hover);
  color: var(--nav-color-hover);
}

.tabBtnActive {
  background: var(--bg-tertiary);
  color: var(--nav-color-hover);
}

/* ─── Main layout ─────────────────────────────────────── */
.body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.layout {
  display: grid;
  grid-template-columns: calc(var(--sidebar-width) - 1px) 1fr;
  grid-template-rows: auto 1fr;
  height: 100%;
  min-height: 0;
}

/* ─── File tree (left col, row 2) ─────────────────────── */
.tree {
  grid-column: 1;
  grid-row: 2;
  border-right: 1px solid var(--border);
  background: var(--bg-secondary);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Right column spans both rows so editor starts at top of body, not below tabBar */
.rightPane {
  grid-column: 2;
  grid-row: 1 / -1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.treeContent {
  padding: 6px 0;
}

.treeLoading {
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skeleton {
  height: 14px;
  border-radius: 4px;
  background: var(--bg-tertiary);
  width: 100%;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.emptyState {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 40px 16px;
  text-align: center;
  color: var(--text-primary);
}

.emptyState p {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.emptyState span {
  font-size: 12px;
  line-height: 1.5;
}

/* Folder row */
.folderRow {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-primary);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: color 0.1s;
}

.folderRow:hover {
  color: var(--text-bright);
}

.chevron {
  transition: transform 0.15s;
  flex-shrink: 0;
}

.chevronOpen {
  transform: rotate(0deg);
}

.chevron:not(.chevronOpen) {
  transform: rotate(-90deg);
}

.folderName {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folderCount {
  font-size: 12px;
  padding: 0 5px;
  border-radius: 8px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  flex-shrink: 0;
}

.folderChildren {
  padding-left: 14px;
}

/* File row */
.fileRow {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 10px;
  font-size: 14px;
  color: var(--text-primary);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s, color 0.1s;
  border-radius: 0;
}

.fileRow:hover {
  background: var(--bg-hover);
  color: var(--text-bright);
}

.fileRowActive {
  background: rgba(99, 155, 255, 0.12) !important;
  color: var(--text-bright) !important;
}

.fileIcon {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  /* color inherits from parent row → primary default, bright on hover/active */
}

.fileName {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.fileMeta {
  font-size: 12px;
  color: var(--text-primary);
  flex-shrink: 0;
  white-space: nowrap;
}

/* Type badge */
.typeBadge {
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid;
  flex-shrink: 0;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Session row */
.sessionRow {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  font-size: 14px;
  color: var(--text-primary);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}

.sessionRow:hover {
  background: var(--bg-hover);
}

.sessionInfo {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}

/* ─── Editor panel (right) ────────────────────────────── */
.editor {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-primary);
}

.editorHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

.editorHeaderLeft {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.editorTitle {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-bright);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editorActions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* SegmentedControl — sidebar-style font (14px / 400), high-contrast
   active fill via --bg-selected. */
.modeSwitcher {
  display: inline-flex;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
  overflow: hidden;
}

.modeBtn {
  padding: 0 14px;
  font-size: 14px;
  font-weight: 400;
  font-family: inherit;
  color: var(--text-primary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}

.modeBtn + .modeBtn {
  border-left: 1px solid var(--border);
}

.modeBtn:hover:not(.modeBtnActive) {
  color: var(--text-bright);
  background: var(--bg-tertiary);
}

.modeBtnActive {
  background: var(--bg-selected);
  color: var(--text-bright);
}

.saveOk {
  font-size: 12px;
  color: #4caf50;
}

.saveErr {
  font-size: 12px;
  color: #f44336;
}

.saveBtn {
  padding: 4px 14px;
  font-size: 14px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-bright);
  cursor: pointer;
  transition: background 0.1s;
}

.saveBtn:hover:not(:disabled) {
  background: var(--bg-hover);
}

.saveBtn:disabled {
  opacity: 0.5;
  cursor: default;
}

.editorMeta {
  display: flex;
  gap: 12px;
  padding: 5px 18px;
  font-size: 12px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: "JetBrains Mono", "Fira Code", "Menlo", monospace;
  font-size: 12px;
  line-height: 1.7;
  padding: 20px 24px;
  min-height: 0;
  tab-size: 2;
}

.preview {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.previewContent {
  padding: 20px 24px;
  font-family: "JetBrains Mono", "Fira Code", "Menlo", monospace;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.previewEmpty {
  color: var(--text-primary);
  font-style: italic;
}

.viewer {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  font-family: "JetBrains Mono", "Fira Code", "Menlo", monospace;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  min-height: 0;
}

/* ─── Placeholder ─────────────────────────────────────── */
.placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  background: var(--bg-primary);
}

.placeholder p {
  margin: 0;
  font-size: 14px;
  color: var(--text-primary);
}

/* System section in wiki tree */
.sysSection {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 4px;
}

/* Core tab */
/* Core tab — left-right layout shares .layout grid with Wiki/Journal.
   The .tree column hosts a sidebar info card (.coreSidebar). */
.coreSidebar {
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.coreInfoIcon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--nav-color);
}

.coreInfoIcon svg {
  width: 18px;
  height: 18px;
}

.coreInfoTitle {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-bright);
}

.coreInfoDesc {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.55;
}

.coreInfoMeta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-primary);
}

.metaOk {
  color: #4caf50;
}

.metaWarn {
  color: #f59e0b;
}


/* ─── Tree toolbar (search + refresh) ─────────────────── */
.treeToolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.searchWrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  transition: border-color 0.15s;
}

.searchWrap:focus-within {
  border-color: var(--accent-blue);
}

.searchInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  min-width: 0;
}

.searchInput::placeholder {
  color: var(--text-muted);
}

.searchClear {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 12px;
  padding: 0 2px;
  line-height: 1;
}

.searchClear:hover {
  color: var(--text-bright);
}

.iconBtn {
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.1s, color 0.1s;
}

.iconBtn:hover {
  background: var(--bg-hover);
  color: var(--text-bright);
}

/* ─── Editor: delete + footer + frontmatter + markdown ─── */
.dangerBtn {
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}

.dangerBtn:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.35);
}

.editorFooter {
  display: flex;
  gap: 14px;
  padding: 5px 18px;
  font-size: 12px;
  color: var(--text-primary);
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.frontmatter {
  padding: 12px 24px;
  margin: 0 0 4px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 14px;
  font-size: 12px;
}

.fmRow {
  display: contents;
}

.fmKey {
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.fmVal {
  color: var(--text-primary);
  font-family: "JetBrains Mono", monospace;
  word-break: break-all;
}

/* Markdown rendered preview */
.markdown {
  padding: 20px 28px;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.65;
}

.markdown h1, .markdown h2, .markdown h3, .markdown h4 {
  color: var(--text-bright);
  font-weight: 600;
  margin: 18px 0 8px;
  line-height: 1.3;
}
.markdown h1 { font-size: 18px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.markdown h2 { font-size: 16px; }
.markdown h3 { font-size: 16px; }
.markdown h4 { font-size: 14px; }
.markdown h1:first-child, .markdown h2:first-child, .markdown h3:first-child { margin-top: 0; }

.markdown p { margin: 8px 0; }

.markdown a {
  color: var(--accent-blue);
  text-decoration: none;
}
.markdown a:hover { text-decoration: underline; }

.markdown a.wikilink {
  color: #7c6fcd;
  background: rgba(124, 111, 205, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid rgba(124, 111, 205, 0.2);
  font-size: 0.95em;
}
.markdown a.wikilink:hover {
  background: rgba(124, 111, 205, 0.18);
  text-decoration: none;
}

.markdown code {
  background: var(--bg-tertiary);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9em;
  color: var(--text-bright);
}

.markdown pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 12px;
  line-height: 1.55;
}

.markdown pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

.markdown ul, .markdown ol {
  margin: 8px 0;
  padding-left: 24px;
}
.markdown li { margin: 3px 0; }

.markdown blockquote {
  border-left: 3px solid var(--border);
  margin: 10px 0;
  padding: 2px 14px;
  color: var(--text-primary);
  background: var(--bg-secondary);
}

.markdown table {
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 12px;
}
.markdown th, .markdown td {
  border: 1px solid var(--border);
  padding: 5px 10px;
  text-align: left;
}
.markdown th {
  background: var(--bg-tertiary);
  font-weight: 600;
}

.markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}
