/* ── Google Fonts import (Inter) ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

/* ── Tokens: light mode (GitHub Primer palette) ──────────────────────────── */
:root {
  --bg:             #ffffff;
  --bg-sidebar:     #f6f8fa;
  --bg-toolbar:     #f6f8fa;
  --surface:        #ffffff;
  --border:         #d0d7de;
  --border-subtle:  #eaecef;
  --text:           #1f2328;
  --text-muted:     #57606a;
  --text-dim:       #8c959f;
  --accent:         #0969da;
  --accent-hover:   #0860ca;
  --accent-subtle:  rgba(9, 105, 218, 0.08);
  --accent-text:    #0550ae;
  --green:          #1a7f37;
  --green-bg:       rgba(26, 127, 55, 0.08);
  --red:            #cf222e;
  --red-bg:         rgba(207, 34, 46, 0.08);
  --yellow:         #9a6700;
  --shadow-sm:      0 1px 3px rgba(27,31,36,0.06), 0 1px 2px rgba(27,31,36,0.04);
  --radius:         8px;
  --font:           'Inter', system-ui, -apple-system, sans-serif;
  --mono:           ui-monospace, 'SFMono-Regular', 'SF Mono', Menlo, Consolas, monospace;
}

/* ── Tokens: dark mode (GitHub Dark palette) ─────────────────────────────── */
[data-theme="dark"] {
  --bg:             #0d1117;
  --bg-sidebar:     #161b22;
  --bg-toolbar:     #161b22;
  --surface:        #0d1117;
  --border:         #30363d;
  --border-subtle:  #21262d;
  --text:           #e6edf3;
  --text-muted:     #8b949e;
  --text-dim:       #484f58;
  --accent:         #58a6ff;
  --accent-hover:   #79c0ff;
  --accent-subtle:  rgba(88, 166, 255, 0.1);
  --accent-text:    #79c0ff;
  --green:          #3fb950;
  --green-bg:       rgba(63, 185, 80, 0.08);
  --red:            #f85149;
  --red-bg:         rgba(248, 81, 73, 0.08);
  --yellow:         #d29922;
  --shadow-sm:      0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
}

/* ── Base reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Shell: full-height flex ─────────────────────────────────────────────── */
#shell {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  width: 240px;
  min-width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
}

/* Header */
#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 10px;
  border-bottom: 1px solid var(--border-subtle);
  gap: 6px;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--border-subtle); color: var(--text); }

.new-note-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  font-family: var(--font);
  transition: background 0.15s;
  white-space: nowrap;
}
.new-note-btn:hover { background: var(--accent-hover); }

/* Search */
#sidebar-search {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 8px 10px 4px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: border-color 0.15s;
}
#sidebar-search:focus-within { border-color: var(--accent); }
.search-icon { color: var(--text-dim); flex-shrink: 0; }

#note-search {
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
  outline: none;
  width: 100%;
}
#note-search::placeholder { color: var(--text-dim); }

/* Note list */
#note-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 4px 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#note-list::-webkit-scrollbar { width: 4px; }
#note-list::-webkit-scrollbar-track { background: transparent; }
#note-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

#note-list li {
  padding: 7px 10px;
  cursor: pointer;
  border-radius: 6px;
  margin-bottom: 1px;
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-muted);
  transition: background 0.1s, color 0.1s;
}
#note-list li:hover { background: var(--border-subtle); color: var(--text); }
#note-list li.active {
  background: var(--accent-subtle);
  color: var(--accent-text);
  font-weight: 500;
}

/* Footer */
#sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-subtle);
  color: var(--accent-text);
  font-size: 0.7rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-name {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.logout-btn:hover { background: var(--red-bg); color: var(--red); }

/* ── Main area ───────────────────────────────────────────────────────────── */
#main-area {
  flex: 1;
  display: flex;
  min-width: 0;
  position: relative;
}

/* ── Editor pane ─────────────────────────────────────────────────────────── */
#editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
}

/* Title + actions bar */
#editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#note-title {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  outline: none;
  letter-spacing: -0.01em;
}
#note-title::placeholder { color: var(--text-dim); font-weight: 400; }

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

#save-status {
  font-size: 0.72rem;
  color: var(--text-dim);
  min-width: 38px;
  text-align: right;
  font-weight: 400;
}
#save-status.saving { color: var(--yellow); }
#save-status.saved  { color: var(--green); }
#save-status.error  { color: var(--red); }

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.toolbar-btn:hover { border-color: var(--text-muted); color: var(--text); }
.publish-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-subtle); }
.delete-btn:hover  { border-color: var(--red); color: var(--red); background: var(--red-bg); }

/* ── Format toolbar ───────────────────────────────────────────────────────── */
#format-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 12px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.fmt-group {
  display: flex;
  align-items: center;
  gap: 1px;
}

.fmt-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
  align-self: center;
}

.fmt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.8rem;
  line-height: 1;
  transition: background 0.12s, color 0.12s;
}
.fmt-btn:hover { background: var(--accent-subtle); color: var(--accent); }
.fmt-btn strong { font-weight: 700; }
.fmt-btn em { font-style: italic; }
.fmt-btn del { text-decoration: line-through; }
.fmt-btn sub { font-size: 0.6em; }

.fmt-mono {
  font-family: var(--mono);
  font-size: 0.78rem;
}

/* CodeMirror container */
#codemirror-container {
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
#codemirror-container .cm-editor {
  height: 100%;
  font-family: var(--mono);
  font-size: 0.88rem;
}
#codemirror-container .cm-scroller { overflow: auto; }
#codemirror-container .cm-focused { outline: none; }

/* ── Divider between editor and preview ─────────────────────────────────── */
#divider {
  width: 1px;
  background: var(--border);
  flex-shrink: 0;
}

/* ── Preview pane ────────────────────────────────────────────────────────── */
#preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
}

#preview-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  flex-shrink: 0;
}

#preview-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  color: var(--text);
  line-height: 1.75;
  font-size: 0.9rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#preview-content::-webkit-scrollbar { width: 4px; }
#preview-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Rendered markdown (preview) ─────────────────────────────────────────── */
#preview-content h1,
#preview-content h2,
#preview-content h3,
#preview-content h4 {
  margin: 1.5em 0 0.6em;
  color: var(--text);
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.02em;
}
#preview-content h1:first-child,
#preview-content h2:first-child,
#preview-content h3:first-child { margin-top: 0; }

#preview-content h1 {
  font-size: 1.7em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border);
}
#preview-content h2 {
  font-size: 1.3em;
  padding-bottom: 0.25em;
  border-bottom: 1px solid var(--border-subtle);
}
#preview-content h3 { font-size: 1.08em; }
#preview-content h4 { font-size: 0.95em; color: var(--text-muted); }

#preview-content p { margin: 0.8em 0; }
#preview-content p:first-child { margin-top: 0; }

#preview-content ul,
#preview-content ol { padding-left: 1.8em; margin: 0.6em 0; }
#preview-content li { margin: 0.3em 0; }

#preview-content a { color: var(--accent); text-decoration: none; }
#preview-content a:hover { text-decoration: underline; }

#preview-content strong { font-weight: 600; }
#preview-content em { font-style: italic; }

#preview-content code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--accent-subtle);
  color: var(--accent-text);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

#preview-content pre {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 1em 0;
  padding: 0;
  background: var(--bg-sidebar);
}
#preview-content pre code {
  display: block;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 0.85em;
  line-height: 1.65;
  background: transparent;
  color: var(--text);
  white-space: pre;
}
#preview-content pre code:not(.hljs) {
  background: var(--bg-sidebar);
}
#preview-content pre code.hljs {
  border-radius: calc(var(--radius) - 1px);
}

#preview-content blockquote {
  border-left: 3px solid var(--border);
  margin: 1em 0;
  padding: 4px 16px;
  color: var(--text-muted);
}
#preview-content blockquote p { margin: 0.2em 0; }

#preview-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5em 0;
}

#preview-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 0.88em;
  display: block;
  overflow-x: auto;
}
#preview-content th,
#preview-content td {
  border: 1px solid var(--border);
  padding: 7px 13px;
  text-align: left;
}
#preview-content th {
  background: var(--bg-sidebar);
  font-weight: 600;
  font-size: 0.82em;
}
#preview-content tr:nth-child(even) td { background: rgba(0,0,0,0.02); }
[data-theme="dark"] #preview-content tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

#preview-content img { max-width: 100%; border-radius: var(--radius); }

/* ── Empty state ─────────────────────────────────────────────────────────── */
#empty-state {
  display: none;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--surface);
  color: var(--text-dim);
}

.empty-icon { opacity: 0.2; margin-bottom: 4px; }
.empty-title { font-size: 0.9rem; font-weight: 500; color: var(--text-muted); }
.empty-hint { font-size: 0.78rem; color: var(--text-dim); text-align: center; max-width: 200px; line-height: 1.5; }

/* ── Auth pages ──────────────────────────────────────────────────────────── */
body.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: auto;
  background: var(--bg-sidebar);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 44px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-sm);
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 28px;
}

.auth-logo-icon {
  width: 32px;
  height: 32px;
  background: var(--accent-subtle);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.auth-logo-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.auth-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}
.auth-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.form-field { margin-bottom: 14px; }
.form-field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.form-field input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  padding: 9px 12px;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.field-error { font-size: 0.75rem; color: var(--red); margin-top: 4px; }
.field-help  { font-size: 0.73rem; color: var(--text-dim); margin-top: 4px; line-height: 1.4; }

.auth-error {
  background: var(--red-bg);
  border: 1px solid rgba(207,34,46,0.2);
  color: var(--red);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 0.8rem;
  margin-bottom: 16px;
}

.btn-primary {
  display: block;
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px;
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
  letter-spacing: -0.01em;
}
.btn-primary:hover { background: var(--accent-hover); }

.auth-link {
  text-align: center;
  margin-top: 18px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.auth-link a { color: var(--accent); text-decoration: none; font-weight: 500; }
.auth-link a:hover { text-decoration: underline; }

/* ── Public note ─────────────────────────────────────────────────────────── */
body.public-body {
  overflow: auto;
  background: var(--bg);
}

#public-note-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}

#public-note-header {
  margin-bottom: 36px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: 16px;
}
.brand:hover { color: var(--accent); }

#public-note-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

#public-note-content {
  color: var(--text);
  line-height: 1.8;
  font-size: 0.95rem;
}

/* Reuse markdown styles for public note */
#public-note-content h1,
#public-note-content h2,
#public-note-content h3 { color: var(--text); font-weight: 600; letter-spacing: -0.02em; margin: 1.4em 0 0.5em; }
#public-note-content h1 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
#public-note-content h2 { font-size: 1.2em; border-bottom: 1px solid var(--border-subtle); padding-bottom: 0.2em; }
#public-note-content h3 { font-size: 1.05em; }
#public-note-content p  { margin: 0.7em 0; }
#public-note-content ul, #public-note-content ol { padding-left: 1.6em; margin: 0.5em 0; }
#public-note-content a  { color: var(--accent); }
#public-note-content code {
  font-family: var(--mono);
  background: var(--accent-subtle);
  color: var(--accent-text);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
}
#public-note-content pre {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 1em 0;
  background: var(--bg-sidebar);
}
#public-note-content pre code {
  display: block;
  padding: 14px 16px;
  font-size: 0.85em;
  line-height: 1.6;
  background: transparent;
  color: var(--text);
}
#public-note-content pre code:not(.hljs) { background: var(--bg-sidebar); }
#public-note-content pre code.hljs { border-radius: calc(var(--radius) - 1px); }
#public-note-content blockquote {
  border-left: 3px solid var(--border);
  padding: 4px 16px;
  color: var(--text-muted);
  margin: 1em 0;
}
