* { box-sizing: border-box; }

:root {
  --bg: #1a1b1e;
  --panel: #212226;
  --panel-2: #26272c;
  --border: #34353b;
  --text: #e8e6e3;
  --text-dim: #9a978f;
  --accent: #8b7ff0;
  --accent-dim: #6b5fd0;
  --danger: #e0645a;

  --font-ui: "Inter", -apple-system, sans-serif;
  --font-serif: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
}

.hidden { display: none !important; }
button, input, textarea { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Login ---- */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { margin: 0 0 8px; font-size: 20px; }
.login-card input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 15px;
}
.login-card button {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  padding: 10px 12px;
  color: #16151c;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.error { color: var(--danger); font-size: 13px; min-height: 16px; margin: 0; }

/* ---- App shell ---- */
#app-view {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 280px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 10px;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-header h1 { font-size: 16px; margin: 0; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }
.ghost-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

#search-input, .tags-input, .modal-input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  width: 100%;
}

.new-btn {
  background: var(--panel-2);
  border: 1px dashed var(--border);
  color: var(--accent);
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.new-btn:hover { border-color: var(--accent); background: var(--panel); }

.note-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 -8px;
}
.note-item {
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
}
.note-item:hover { background: var(--panel-2); }
.note-item.active { background: var(--panel-2); }
.note-item .n-title { font-size: 13px; font-weight: 500; }
.note-item .n-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-item .n-snippet {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ---- Editor pane ---- */
.editor-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}

.note-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 32px;
  min-height: 0;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
}
.title-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-serif);
  padding: 4px 0;
}
.toolbar-right { display: flex; align-items: center; gap: 8px; }

.tabs { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12px;
}
.tab-btn.active { background: var(--panel-2); color: var(--text); }

.primary-btn {
  background: var(--accent);
  border: none;
  color: #16151c;
  font-weight: 600;
  border-radius: 6px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 13px;
}
.primary-btn:hover { background: var(--accent-dim); }
.primary-btn.danger { background: var(--danger); }
.primary-btn.danger:hover { filter: brightness(1.1); }

.tags-input {
  margin: 10px 0;
  max-width: 400px;
}

.content-textarea {
  flex: 1;
  min-height: 0;
  resize: none;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.7;
  padding: 4px 0;
}

.preview-pane {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.75;
  padding: 4px 0;
}
.preview-pane h1, .preview-pane h2, .preview-pane h3 { font-family: var(--font-serif); }
.preview-pane a { color: var(--accent); }
.preview-pane a.wikilink-missing { color: var(--text-dim); border-bottom: 1px dashed var(--text-dim); }
.preview-pane code {
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.preview-pane pre {
  background: var(--panel-2);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
}
.preview-pane pre code { background: none; padding: 0; }
.preview-pane blockquote {
  border-left: 3px solid var(--border);
  margin: 0;
  padding-left: 14px;
  color: var(--text-dim);
}

.backlinks-panel {
  flex: none;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-dim);
  max-height: 90px;
  overflow-y: auto;
}
.backlinks-panel .bl-title { font-weight: 600; color: var(--text); margin-bottom: 6px; }
.backlinks-panel a { color: var(--accent); text-decoration: none; margin-right: 12px; }

/* ---- Modals & toast ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  width: 100%;
  max-width: 340px;
}
.modal-box p { margin: 0 0 14px; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--danger);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  max-width: min(90vw, 420px);
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

@media (max-width: 760px) {
  #app-view { flex-direction: column; }
  .sidebar {
    width: auto;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .note-editor { padding: 16px; }

  .editor-toolbar { flex-wrap: wrap; row-gap: 8px; }
  .title-input { flex: 1 1 100%; font-size: 20px; }
  .toolbar-right { flex-wrap: wrap; row-gap: 8px; }
}
