:root {
  color-scheme: dark;
  --app-bg: #090909;
  --app-panel: #0d0d0d;
  --app-panel-soft: #121212;
  --app-line: #2a2a2a;
  --app-line-strong: #3a3a3a;
  --app-muted: #8a8a8a;
  --app-text: #e8e8e8;
  --app-subtle: #b8b8b8;
  --app-invert-bg: #e8e8e8;
  --app-invert-text: #090909;
  --app-sidebar: 390px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--app-bg);
  color: var(--app-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.55;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 48px 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--app-line);
  background: #080808;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  min-width: 0;
  color: var(--app-text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--app-line-strong);
  color: var(--app-text);
  background: var(--app-panel);
  font-size: 12px;
}

.brand strong {
  display: block;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand small {
  display: block;
  margin-top: 1px;
  color: var(--app-muted);
  font-size: 11px;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.select-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--app-muted);
  font-size: 12px;
}

.select-control select,
.icon-button {
  height: 30px;
  color: var(--app-text);
  background: var(--app-panel);
  border: 1px solid var(--app-line-strong);
  border-radius: 0;
}

.select-control select {
  min-width: 180px;
  padding: 0 28px 0 9px;
}

.icon-button {
  width: 30px;
  padding: 0;
}

.select-control select:hover,
.icon-button:hover {
  background: var(--app-panel-soft);
}

.workspace {
  display: grid;
  grid-template-columns: var(--app-sidebar) minmax(0, 1fr);
  min-height: calc(100vh - 48px);
}

.dashboard-panel {
  min-height: 0;
  height: calc(100vh - 48px);
  position: sticky;
  top: 48px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 10px;
  padding: 12px;
  border-right: 1px solid var(--app-line);
  background: var(--app-panel);
}

.search-control {
  height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 9px;
  border: 1px solid var(--app-line-strong);
  background: #080808;
  color: var(--app-muted);
}

.search-control input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--app-text);
  background: transparent;
}

.search-control input::placeholder {
  color: #666;
}

.metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border: 1px solid var(--app-line);
  color: var(--app-muted);
  background: #080808;
}

.metrics span {
  padding: 5px 8px;
  border-right: 1px solid var(--app-line);
  font-size: 11px;
  white-space: nowrap;
}

.metrics span:last-child {
  border-right: 0;
}

.tree-list {
  min-height: 0;
  overflow: auto;
  padding: 4px 0;
  border: 1px solid var(--app-line);
  background: #080808;
}

.tree-row {
  width: 100%;
  min-height: 28px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 0 8px 0 calc(8px + (var(--depth) * 16px));
  border: 0;
  border-left: 2px solid transparent;
  color: var(--app-subtle);
  background: transparent;
  text-align: left;
}

.tree-row:hover {
  color: var(--app-text);
  background: #111;
}

.tree-folder {
  color: var(--app-text);
  font-weight: 700;
}

.tree-folder.is-active {
  border-left-color: var(--app-muted);
  background: #101010;
}

.tree-note {
  grid-template-columns: 28px minmax(0, 1fr);
}

.tree-note.is-active {
  color: var(--app-invert-text);
  background: var(--app-invert-bg);
  border-left-color: var(--app-invert-bg);
}

.tree-glyph {
  color: var(--app-muted);
  font-size: 11px;
}

.tree-note.is-active .tree-glyph {
  color: var(--app-invert-text);
}

.tree-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-count {
  color: var(--app-muted);
  font-size: 11px;
  font-weight: 400;
}

.reader-panel {
  min-width: 0;
  padding: 28px;
}

.reader-toolbar {
  max-width: 920px;
  margin: 0 auto 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: start;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--app-line);
}

.breadcrumb {
  min-height: 18px;
  color: var(--app-muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

#noteTitle {
  margin: 4px 0 0;
  color: var(--app-text);
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.tag-row {
  max-width: 320px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.tag-chip {
  padding: 2px 6px;
  border: 1px solid var(--app-line);
  color: var(--app-muted);
  background: #080808;
  font-size: 11px;
}

.note-body {
  max-width: 920px;
  min-height: 60vh;
  margin: 0 auto;
  padding: 24px 0 48px;
  color: var(--app-subtle);
  background: transparent;
  border: 0;
  box-shadow: none;
}

.note-body :first-child {
  margin-top: 0;
}

.note-body h1,
.note-body h2,
.note-body h3,
.note-body h4,
.note-body h5,
.note-body h6 {
  color: var(--app-text);
  letter-spacing: 0;
  line-height: 1.25;
}

.note-body h1 {
  font-size: 24px;
}

.note-body h2 {
  font-size: 20px;
}

.note-body h3 {
  font-size: 17px;
}

.note-body p,
.note-body li {
  overflow-wrap: anywhere;
}

.note-body a {
  color: var(--app-text);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.note-body blockquote {
  margin: 18px 0;
  padding: 0 0 0 14px;
  border-left: 2px solid var(--app-line-strong);
  color: var(--app-muted);
}

.note-body img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 18px 0;
  border: 1px solid var(--app-line);
  border-radius: 0;
}

.note-body pre {
  overflow-x: auto;
  margin: 18px 0;
  padding: 14px;
  border: 1px solid var(--app-line);
  border-radius: 0;
  background: #050505;
}

.note-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  color: var(--app-text);
}

.note-body table {
  width: 100%;
  margin: 18px 0;
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
}

.note-body th,
.note-body td {
  border: 1px solid var(--app-line);
  padding: 7px 9px;
}

.empty-state {
  margin: 8px;
  padding: 12px;
  border: 1px dashed var(--app-line-strong);
  color: var(--app-muted);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-rows: auto 1fr;
  }

  .topbar {
    min-height: 48px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .dashboard-panel {
    position: static;
    height: auto;
    max-height: 460px;
    border-right: 0;
    border-bottom: 1px solid var(--app-line);
  }

  .tree-list {
    max-height: 330px;
  }

  .reader-toolbar {
    grid-template-columns: 1fr;
  }

  .tag-row {
    justify-content: flex-start;
    max-width: none;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 10px 12px;
  }

  .topbar-controls {
    width: 100%;
  }

  .select-control {
    flex: 1;
  }

  .select-control select {
    min-width: 0;
    width: 100%;
  }

  .reader-panel {
    padding: 18px 14px;
  }

  #noteTitle {
    font-size: 22px;
  }
}
