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

:root {
  /* Canvas — warm cream */
  --bg:       #fdf8f0;
  --surface:  #f5efe3;
  --border:   #e8dfc8;
  --border2:  #d9cdb4;
  --text:     #2c2720;
  --muted:    #7a7060;
  --accent:   #0969da;
  --accent2:  #0550ae;
  --danger:   #cf222e;
  --green:    #1a7f37;
  /* Code block — light gray */
  --code-bg:        #f4f4f5;
  --code-surface:   #ebebec;
  --code-border:    #d4d4d8;
  --code-border2:   #c4c4c8;
  --code-text:      #1e1e1e;
  --code-muted:     #6b7280;
  --code-accent:    #0969da;
  --code-green:     #1a7f37;
  /* Sidebar — light */
  --sidebar-bg:     #fdf8f0;
  --sidebar-border: #e8dfc8;
  --sidebar-text:   #2c2720;
  --sidebar-muted:  #7a7060;
  --sidebar-w: 260px;
  --radius:   6px;
  --font-mono: "Cascadia Code", "Fira Code", "JetBrains Mono", Consolas, monospace;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Layout ── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar (dark) ── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

#brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  color: var(--sidebar-text);
}
#brand svg { color: var(--accent); }

#new-note-btn {
  background: var(--accent2);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
#new-note-btn:hover { background: var(--accent); }

#search-wrap {
  position: relative;
  padding: 10px 12px;
  border-bottom: 1px solid var(--sidebar-border);
}
.search-icon {
  position: absolute;
  left: 22px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--sidebar-muted);
  pointer-events: none;
}
#search-input {
  width: 100%;
  background: #fff;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius);
  color: var(--sidebar-text);
  padding: 6px 10px 6px 28px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--sidebar-muted); }

#notes-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 6px 0;
}
#notes-list::-webkit-scrollbar { width: 4px; }
#notes-list::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 2px; }

.note-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 0;
  border-left: 3px solid transparent;
  transition: background 0.1s;
  position: relative;
}
.note-item:hover { background: rgba(0,0,0,0.04); }
.note-item.active {
  background: rgba(9,105,218,0.07);
  border-left-color: var(--accent);
}

.note-item-body { flex: 1; min-width: 0; }
.note-item-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--sidebar-text);
}
.note-item.active .note-item-title { color: var(--accent); }
.note-item-meta {
  font-size: 11px;
  color: var(--sidebar-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-delete-btn {
  background: none;
  border: none;
  color: var(--sidebar-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.note-item:hover .note-delete-btn { opacity: 1; }
.note-delete-btn:hover { color: var(--danger); }

#notes-empty {
  text-align: center;
  color: var(--sidebar-muted);
  padding: 32px 16px;
  font-size: 13px;
}

/* ── Editor Panel (cream canvas) ── */
#editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* Empty state */
#empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--muted);
}
#empty-state p { font-size: 15px; }
#empty-new-btn {
  background: var(--accent2);
  border: none;
  color: #fff;
  padding: 8px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
#empty-new-btn:hover { background: var(--accent); }

/* Editor wrap */
#editor-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#editor-wrap.hidden { display: none; }
#empty-state.hidden { display: none; }

/* Toolbar */
#editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

#note-title {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
  outline: none;
  min-width: 0;
}
#note-title::placeholder { color: var(--muted); }

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

#save-status {
  font-size: 12px;
  color: var(--green);
  min-width: 60px;
  text-align: right;
}

#preview-toggle, #delete-note-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--muted);
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
#preview-toggle:hover { border-color: var(--accent); color: var(--accent); }
#preview-toggle.active { border-color: var(--accent); color: var(--accent); background: rgba(9,105,218,0.07); }
#delete-note-btn:hover { border-color: var(--danger); color: var(--danger); }

/* Edit / Preview views */
#edit-view { flex: 1; display: flex; overflow: hidden; }
#edit-view.hidden { display: none; }
#preview-view { flex: 1; overflow-y: auto; padding: 24px 32px; }
#preview-view.hidden { display: none; }

#note-content {
  flex: 1;
  background: var(--bg);
  border: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.7;
  padding: 24px 32px;
  resize: none;
  outline: none;
  tab-size: 2;
}
#note-content::placeholder { color: var(--border2); }

/* ── Markdown Preview (cream canvas) ── */
#preview-view { background: var(--bg); color: var(--text); }

#preview-view h1, #preview-view h2, #preview-view h3,
#preview-view h4, #preview-view h5, #preview-view h6 {
  color: var(--text);
  margin: 1.2em 0 0.5em;
  font-weight: 600;
  line-height: 1.3;
}
#preview-view h1 { font-size: 1.9em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
#preview-view h2 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: 0.25em; }
#preview-view h3 { font-size: 1.2em; }
#preview-view p { margin: 0.7em 0; }
#preview-view a { color: var(--accent); text-decoration: none; }
#preview-view a:hover { text-decoration: underline; }
#preview-view ul, #preview-view ol { padding-left: 1.6em; margin: 0.6em 0; }
#preview-view li { margin: 0.2em 0; }
#preview-view blockquote {
  border-left: 3px solid var(--accent2);
  padding: 6px 16px;
  color: var(--muted);
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 0.8em 0;
}
#preview-view hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }
#preview-view table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.8em 0;
}
#preview-view th, #preview-view td {
  border: 1px solid var(--border2);
  padding: 6px 12px;
  text-align: left;
}
#preview-view th { background: var(--surface); font-weight: 600; }

/* Comments */
.md-comment {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.88em;
  color: var(--muted);
  font-style: italic;
  opacity: 0.75;
}

/* Inline code */
#preview-view code {
  font-family: var(--font-mono);
  background: var(--code-surface);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  color: var(--danger);
}

/* ── Code blocks (light gray) ── */
.code-block-wrap {
  position: relative;
  margin: 1em 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--code-border2);
}
.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--code-surface);
  padding: 6px 14px;
  font-size: 12px;
  color: var(--code-muted);
  border-bottom: 1px solid var(--code-border);
}
.code-block-lang {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--code-accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.copy-btn {
  background: none;
  border: 1px solid var(--code-border2);
  color: var(--code-muted);
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  gap: 4px;
}
.copy-btn:hover { border-color: var(--code-accent); color: var(--code-accent); }
.copy-btn.copied { border-color: var(--code-green); color: var(--code-green); }

.code-block-wrap pre {
  margin: 0;
  padding: 0;
  background: var(--code-bg);
  overflow-x: auto;
}
/* Let hljs control token colors; we only set font/size/spacing */
.code-block-wrap pre code.hljs {
  background: var(--code-bg);
  padding: 14px 16px;
  font-size: 13px;
  font-family: var(--font-mono);
  line-height: 1.65;
  border-radius: 0;
}

/* Scrollbars */
#preview-view::-webkit-scrollbar { width: 6px; }
#preview-view::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── Profile card ── */
#profile-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border-top: 1px solid var(--sidebar-border);
  background: var(--sidebar-bg);
  flex-shrink: 0;
}

#profile-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent2);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

#profile-info {
  flex: 1;
  min-width: 0;
}
#profile-username {
  font-size: 13px;
  font-weight: 600;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#profile-email {
  font-size: 11px;
  color: var(--sidebar-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#logout-btn {
  background: none;
  border: 1px solid var(--sidebar-border);
  border-radius: 6px;
  color: var(--sidebar-muted);
  cursor: pointer;
  padding: 5px 6px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
#logout-btn:hover { border-color: var(--danger); color: var(--danger); }

/* Utility */
.hidden { display: none !important; }
