:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --border: #e2e6ec;
  --text: #1c2430;
  --muted: #667385;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --active: #eef4ff;
  --code-bg: #f1f5f9;
}

:root[data-theme="dark"] {
  --bg: #0f141c;
  --panel: #161d28;
  --border: #273244;
  --text: #e6edf6;
  --muted: #93a2b8;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --danger: #f87171;
  --active: #1e2a3d;
  --code-bg: #1e2736;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 280px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.brand {
  padding: 18px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

.sidebar-controls {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.search-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.88rem;
}

.note-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}

.note-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  border: 1px solid transparent;
}

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

.note-item.active {
  background: var(--active);
  border-color: var(--border);
}

.note-item-title {
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.title-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 600;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn.primary:hover {
  background: var(--accent-hover);
}

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

.btn.danger {
  color: var(--danger);
}

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

.editor-area {
  flex: 1;
  display: flex;
  min-height: 0;
  padding: 18px 22px;
}

.editor, .preview {
  width: 100%;
  height: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
  color: var(--text);
  overflow-y: auto;
}

.editor {
  resize: none;
  outline: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.94rem;
  line-height: 1.65;
}

.preview h1, .preview h2, .preview h3 {
  margin-top: 1.1em;
  margin-bottom: 0.5em;
}

.preview p {
  margin: 0.6em 0;
}

.preview code {
  background: var(--code-bg);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
}

.preview pre {
  background: var(--code-bg);
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
}

.preview pre code {
  padding: 0;
  background: transparent;
}

.preview blockquote {
  margin: 0.8em 0;
  padding: 4px 14px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.hidden {
  display: none;
}

.statusbar {
  display: flex;
  justify-content: space-between;
  padding: 8px 22px;
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--panel);
  border-top: 1px solid var(--border);
}

@media (max-width: 760px) {
  .app {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: 220px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}
