:root {
  --bg: #eef1f3;
  --surface: #ffffff;
  --surface-alt: #e4e8eb;
  --border: #d3dade;
  --text: #1d2529;
  --text-muted: #5c6a72;
  --accent: #3c5a99;
  --accent-soft: #dce4f2;
  --danger: #b3432b;
  --danger-soft: #f4ddd4;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  --font-mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --font-display: "Inter Variable", "Inter", var(--font-ui);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181b;
    --surface: #1c2226;
    --surface-alt: #242b30;
    --border: #303a40;
    --text: #e7ebec;
    --text-muted: #8b979c;
    --accent: #86a4e3;
    --accent-soft: #26314a;
    --danger: #d97a5f;
    --danger-soft: #3a2620;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
}

button,
input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

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

/* ---------- sidebar ---------- */

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

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 8px;
}

.sidebar-header h1 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.01em;
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logout-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}

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

#new-note-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

#new-note-btn:hover {
  background: var(--accent);
  color: var(--surface);
}

#search {
  margin: 8px 16px 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  outline: none;
}

#search:focus {
  border-color: var(--accent);
}

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
}

.tag-filter:empty {
  padding: 0;
}

.tag-pill {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  line-height: 1.5;
}

.tag-pill:hover {
  border-color: var(--accent);
  color: var(--text);
}

.tag-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

.note-item {
  position: relative;
  padding: 10px 12px 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  border-left: 3px solid transparent;
}

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

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

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

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

.note-item .note-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.note-item .note-tag {
  font-size: 10.5px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 1px 8px;
}

.note-list-empty {
  color: var(--text-muted);
  padding: 12px 16px;
  font-size: 13px;
}

/* ---------- editor area ---------- */

.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

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

.title-input::placeholder {
  color: var(--text-muted);
}

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  flex: 0 0 auto;
}

.mode-btn {
  border: none;
  background: var(--surface);
  padding: 6px 12px;
  cursor: pointer;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
}

.mode-btn:last-child {
  border-right: none;
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
}

.danger {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--danger);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}

.danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.save-status {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 70px;
  text-align: right;
}

.tags-editor {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 3px 6px 3px 12px;
  font-size: 12.5px;
}

.tag-chip button {
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 2px;
  border-radius: 50%;
  opacity: 0.7;
}

.tag-chip button:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.08);
}

.tag-input {
  border: none;
  background: transparent;
  outline: none;
  min-width: 100px;
  flex: 1;
  padding: 4px 2px;
  color: var(--text);
}

.tag-input::placeholder {
  color: var(--text-muted);
}

.panes {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.editor {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  resize: none;
  padding: 24px 28px;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.7;
  background: var(--surface);
  color: var(--text);
  background-image: linear-gradient(to right, transparent 0, transparent calc(100% - 1px), var(--border) calc(100% - 1px));
}

.preview {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 24px 32px;
  background: var(--bg);
  font-family: var(--font-display);
  line-height: 1.7;
}

.preview h1,
.preview h2,
.preview h3 {
  font-family: var(--font-display);
  line-height: 1.3;
}

.preview code,
.preview pre {
  font-family: var(--font-mono);
  font-size: 13px;
}

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

.preview code {
  background: var(--surface-alt);
  padding: 1px 5px;
  border-radius: 4px;
}

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

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

.preview a {
  color: var(--accent);
}

.preview img {
  max-width: 100%;
}

/* view modes */

.panes.mode-edit .preview {
  display: none;
}

.panes.mode-edit .editor {
  background-image: none;
}

.panes.mode-preview .editor {
  display: none;
}

.panes.mode-split .editor,
.panes.mode-split .preview {
  width: 50%;
}

.empty-state {
  flex: 1;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: 16px;
}

.app.no-note .panes,
.app.no-note .editor-toolbar,
.app.no-note .tags-editor {
  display: none;
}

.app.no-note .empty-state {
  display: flex;
}

@media (prefers-reduced-motion: no-preference) {
  .note-item,
  #new-note-btn,
  .mode-btn,
  .danger {
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  }
}

/* ---------- login page ---------- */

.login-body {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 28px;
}

.login-card h1 {
  font-family: var(--font-display);
  font-size: 24px;
  margin: 0 0 24px;
  text-align: center;
}

.login-card form {
  display: flex;
  flex-direction: column;
}

.login-label {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 12px 0 6px;
}

.login-card input[type='text'],
.login-card input[type='password'] {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 8px;
  padding: 9px 11px;
  outline: none;
}

.login-card input[type='text']:focus,
.login-card input[type='password']:focus {
  border-color: var(--accent);
}

.login-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

.login-remember input {
  cursor: pointer;
}

.login-error {
  min-height: 18px;
  margin: 12px 0 0;
  font-size: 12.5px;
  color: var(--danger);
}

.login-card button[type='submit'] {
  margin-top: 8px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 10px;
  font-weight: 600;
  cursor: pointer;
}

.login-card button[type='submit']:disabled {
  opacity: 0.7;
  cursor: default;
}

@media (max-width: 720px) {
  .app {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    width: auto;
    flex: 0 0 auto;
    max-height: 40vh;
  }

  .panes.mode-split {
    flex-direction: column;
  }

  .panes.mode-split .editor,
  .panes.mode-split .preview {
    width: 100%;
  }
}
