:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-soft: #eef2f3;
  --text: #162026;
  --muted: #667680;
  --line: #dce3e7;
  --accent: #146c67;
  --accent-strong: #0f4f4c;
  --mark: #fff1a8;
  --shadow: 0 8px 28px rgba(31, 45, 52, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
  padding: 24px 18px;
  background: #ffffff;
  border-right: 1px solid var(--line);
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  color: #40505a;
  font-size: 13px;
  font-weight: 650;
}

.search-input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.search-input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 108, 103, 0.14);
}

.directory-tree {
  overflow: auto;
  padding-top: 4px;
}

.tree-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 34px;
  margin: 2px 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #25323a;
  padding: 0 9px;
  text-align: left;
  cursor: pointer;
}

.tree-button:hover,
.tree-button.active {
  background: var(--panel-soft);
}

.tree-count {
  color: var(--muted);
  font-size: 12px;
}

.tree-children {
  margin-left: 12px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.content-area {
  display: grid;
  grid-template-columns: minmax(320px, 410px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
  min-width: 0;
}

.results-panel,
.reader {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.results-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 36px);
}

.results-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.results-header h2 {
  margin: 0;
  font-size: 18px;
}

.results-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.ghost-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #33424a;
  padding: 0 10px;
  cursor: pointer;
}

.ghost-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.results-list {
  overflow: auto;
  padding: 8px;
}

.result-item {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.result-item:hover,
.result-item.active {
  background: var(--panel-soft);
}

.result-title {
  display: block;
  font-weight: 720;
  line-height: 1.25;
}

.result-summary {
  margin: 7px 0;
  color: #4f5e66;
  font-size: 13px;
  line-height: 1.45;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.reader {
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 26px min(5vw, 58px);
}

.empty-state {
  display: grid;
  place-content: center;
  min-height: 70vh;
  color: var(--muted);
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 8px;
  color: var(--text);
}

.reader-meta {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.hidden {
  display: none;
}

.markdown-body {
  max-width: 860px;
  line-height: 1.72;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  line-height: 1.25;
  margin: 1.5em 0 0.55em;
}

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

.markdown-body h1 {
  font-size: 32px;
}

.markdown-body h2 {
  font-size: 22px;
}

.markdown-body h3 {
  font-size: 18px;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body pre,
.markdown-body blockquote {
  margin: 0.85em 0;
}

.markdown-body code {
  border-radius: 5px;
  background: #edf1f2;
  padding: 2px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.markdown-body pre {
  overflow: auto;
  border-radius: 8px;
  background: #152027;
  color: #eef6f6;
  padding: 14px;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
}

.markdown-body blockquote {
  border-left: 4px solid var(--accent);
  margin-left: 0;
  padding-left: 14px;
  color: #4f5e66;
}

.markdown-body a {
  color: var(--accent-strong);
}

.markdown-body mjx-container {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.markdown-body mjx-container[display="true"] {
  padding: 8px 0;
}

mark {
  background: var(--mark);
  padding: 0 2px;
}

@media (max-width: 980px) {
  .app-shell,
  .content-area {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .content-area {
    padding: 12px;
  }

  .results-panel,
  .reader {
    max-height: none;
  }
}
