:root {
  --sidebar-width: 320px;
  --border: #9aa4b2;
  --border-strong: #667085;
  --surface: #eef2f6;
  --surface-raised: #ffffff;
  --surface-editor: #ffffff;
  --surface-preview: #fbfaf5;
  --text-muted: #475467;
}

body {
  margin: 0;
  background: var(--surface);
  color: #1d2939;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--surface);
}

.login-panel {
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 14px;
  padding: 28px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.login-panel h1 {
  font-size: 24px;
  margin: 0 0 8px;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
  border-right: 1px solid var(--border-strong);
  background: var(--surface);
  padding: 12px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  min-width: 0;
}

.toolbar,
.content-header,
.editor-actions,
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tree {
  overflow: auto;
  font-size: 14px;
}

.tree-item {
  padding: 5px 6px;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.tree-item:hover,
.tree-item.active {
  background: #e8edf5;
}

.tree-children {
  margin-left: 16px;
}

.sidebar-links {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 14px;
}

.content {
  min-width: 0;
  overflow: auto;
  padding: 24px;
  height: 100vh;
  background: #f5f7fa;
}

.empty-state {
  height: calc(100vh - 48px);
  display: grid;
  place-items: center;
  color: var(--text-muted);
}

.content-header h1 {
  font-size: 28px;
  margin: 0;
}

.rendered {
  line-height: 1.7;
  max-width: 980px;
}

.rendered img {
  max-width: 100%;
  height: auto;
}

.note-editor {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  height: calc(100vh - 48px);
  min-height: 0;
}

.note-editor > .form-control {
  border-color: var(--border);
  background: var(--surface-raised);
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  min-height: 0;
  overflow: hidden;
}

.editor-grid > * {
  min-width: 0;
  min-height: 0;
}

.editor-grid .EasyMDEContainer {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface-editor);
}

.editor-grid .EasyMDEContainer .CodeMirror {
  height: 100%;
  min-height: 0;
  border: 0;
  border-top: 1px solid var(--border);
  border-bottom-left-radius: 7px;
  border-bottom-right-radius: 7px;
  background: var(--surface-editor);
}

.editor-grid .EasyMDEContainer .CodeMirror-scroll {
  min-height: 0;
}

.editor-grid .editor-toolbar {
  border: 0;
  border-radius: 7px 7px 0 0;
  background: #e8edf3;
  opacity: 1;
}

.editor-grid .editor-toolbar button {
  color: #101828 !important;
}

.editor-grid .editor-toolbar i.separator {
  border-left-color: #98a2b3;
  border-right-color: #f9fafb;
}

.preview {
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 14px;
  overflow: auto;
  max-width: none;
  background: var(--surface-preview);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.65);
}

.rendered mjx-container[jax="CHTML"][display="true"] {
  margin: 1em 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
}

.rendered mjx-merror {
  background: #fff4e5 !important;
  border: 1px solid #f2b66d;
  border-radius: 4px;
  color: #7a2e0e !important;
  padding: 2px 5px;
}

.page-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 16px;
}

.result-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.result-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

@media (max-width: 840px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    max-height: 42vh;
  }

  .editor-grid {
    grid-template-columns: 1fr;
  }
}
