/* ─────────────────────────────────────────
   Design tokens
───────────────────────────────────────── */
:root {
  --bg:           #F5F5F4;
  --surface:      #FFFFFF;
  --header:       #0F0F0F;
  --accent:       #6366F1;
  --accent-h:     #4F46E5;
  --accent-dim:   rgba(99,102,241,.14);
  --text:         #111111;
  --text-2:       #71717A;
  --text-3:       #A1A1AA;
  --border:       #E4E4E7;
  --border-h:     #D4D4D8;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:    0 4px 12px rgba(0,0,0,.10), 0 2px 4px rgba(0,0,0,.06);

  /* note palette */
  --c-yellow-bg: #FEFCE8; --c-yellow-b: #FDE68A;
  --c-green-bg:  #F0FDF4; --c-green-b:  #BBF7D0;
  --c-blue-bg:   #EFF6FF; --c-blue-b:   #BFDBFE;
  --c-purple-bg: #FAF5FF; --c-purple-b: #E9D5FF;
  --c-pink-bg:   #FFF0F3; --c-pink-b:   #FBCFE8;

  /* dot fills */
  --dot-yellow: #FACC15;
  --dot-green:  #22C55E;
  --dot-blue:   #3B82F6;
  --dot-purple: #A855F7;
  --dot-pink:   #EC4899;
}

[data-theme="dark"] {
  --bg:           #111111;
  --surface:      #1C1C1C;
  --header:       #0A0A0A;
  --text:         #E8E8E6;
  --text-2:       #808080;
  --text-3:       #4A4A4A;
  --border:       #2A2A2A;
  --border-h:     #3A3A3A;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.3);
  --shadow-md:    0 4px 12px rgba(0,0,0,.4);

  --c-yellow-bg: #1A1500; --c-yellow-b: #3A2900;
  --c-green-bg:  #001A08; --c-green-b:  #003318;
  --c-blue-bg:   #00091C; --c-blue-b:   #00204D;
  --c-purple-bg: #0D0020; --c-purple-b: #2A0060;
  --c-pink-bg:   #1A0009; --c-pink-b:   #550020;

  --dot-yellow: #CA8A04;
  --dot-green:  #16A34A;
  --dot-blue:   #2563EB;
  --dot-purple: #9333EA;
  --dot-pink:   #DB2777;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, 'Helvetica Neue', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }

/* ─────────────────────────────────────────
   Header
───────────────────────────────────────── */
.app-header {
  background: var(--header);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 50px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
}

.app-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 6px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.app-name {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.2px;
}

.header-search {
  flex: 1;
  max-width: 360px;
  margin: 0 auto;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255,255,255,.3);
  pointer-events: none;
}

.header-search input {
  width: 100%;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 6px;
  color: #fff;
  padding: 6px 12px 6px 32px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: background .15s, border-color .15s;
}
.header-search input::placeholder { color: rgba(255,255,255,.3); }
.header-search input:focus {
  background: rgba(255,255,255,.11);
  border-color: rgba(255,255,255,.22);
}
.header-search input::-webkit-search-cancel-button { filter: invert(1) opacity(.4); }

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

.btn-icon {
  background: none;
  border: none;
  padding: 6px;
  color: rgba(255,255,255,.5);
  display: grid;
  place-items: center;
  border-radius: 6px;
  transition: color .15s, background .15s;
}
.btn-icon:hover { color: #fff; background: rgba(255,255,255,.08); }

/* sun/moon icon toggling */
.btn-icon .icon-sun  { display: none; }
.btn-icon .icon-moon { display: block; }
[data-theme="dark"] .btn-icon .icon-sun  { display: block; }
[data-theme="dark"] .btn-icon .icon-moon { display: none; }

.btn-new {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  transition: background .15s;
  white-space: nowrap;
}
.btn-new:hover  { background: var(--accent-h); }
.btn-new:active { background: #3730A3; }

/* ─────────────────────────────────────────
   Filter bar
───────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: 42px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 50px;
  z-index: 90;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }

.filter-tabs { display: flex; gap: 2px; }

.filter-tab {
  background: none;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 3px 9px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--text-2);
  transition: all .15s;
  white-space: nowrap;
}
.filter-tab:hover  { color: var(--text); border-color: var(--border-h); }
.filter-tab.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.tab-count {
  display: inline-block;
  background: rgba(0,0,0,.07);
  color: inherit;
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 5px;
  margin-left: 3px;
  border-radius: 20px;
  vertical-align: middle;
}
[data-theme="dark"] .tab-count { background: rgba(255,255,255,.09); }
.filter-tab.active .tab-count  { background: rgba(255,255,255,.18); }
[data-theme="dark"] .filter-tab.active .tab-count { background: rgba(0,0,0,.25); }

.bar-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
}

.color-filters {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-shrink: 0;
}

.cfbtn {
  width: 17px;
  height: 17px;
  border: 2px solid transparent;
  border-radius: 50%;
  transition: transform .15s, box-shadow .15s;
  outline: none;
  flex-shrink: 0;
}
.cfbtn:hover  { transform: scale(1.25); }
.cfbtn.active { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--text); }

.cfbtn[data-color="yellow"] { background: var(--dot-yellow); }
.cfbtn[data-color="green"]  { background: var(--dot-green); }
.cfbtn[data-color="blue"]   { background: var(--dot-blue); }
.cfbtn[data-color="purple"] { background: var(--dot-purple); }
.cfbtn[data-color="pink"]   { background: var(--dot-pink); }

/* Active tag chip in filter bar */
.tag-filter-area { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11.5px;
  font-family: 'SFMono-Regular', 'Menlo', 'Consolas', monospace;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.tag-chip:hover { background: rgba(99,102,241,.22); }
.tag-chip .chip-x { font-size: 13px; line-height: 1; opacity: .7; }

/* Sort select */
.bar-right { margin-left: auto; flex-shrink: 0; }

.sort-select {
  background: none;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--text-2);
  font-size: 12px;
  font-family: inherit;
  padding: 3px 6px;
  cursor: pointer;
  outline: none;
  transition: color .15s, border-color .15s;
  -webkit-appearance: none;
  appearance: none;
}
.sort-select:hover { color: var(--text); border-color: var(--border-h); }
.sort-select option { background: var(--surface); color: var(--text); }

/* ─────────────────────────────────────────
   Notes grid (masonry via columns)
───────────────────────────────────────── */
.notes-grid {
  padding: 18px;
  columns: 5;
  column-gap: 14px;
}
@media (max-width: 1400px) { .notes-grid { columns: 4; } }
@media (max-width: 1100px) { .notes-grid { columns: 3; } }
@media (max-width: 780px)  { .notes-grid { columns: 2; } }
@media (max-width: 500px)  { .notes-grid { columns: 1; } }

/* ─────────────────────────────────────────
   Note cards
───────────────────────────────────────── */
.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
  break-inside: avoid;
  cursor: pointer;
  position: relative;
  transition: box-shadow .15s, transform .15s, border-color .15s;
  -webkit-user-select: none;
  user-select: none;
}
.note-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  border-color: var(--border-h);
}
.note-card:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}
.note-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

/* coloured cards */
.note-card.color-yellow { background: var(--c-yellow-bg); border-color: var(--c-yellow-b); }
.note-card.color-green  { background: var(--c-green-bg);  border-color: var(--c-green-b);  }
.note-card.color-blue   { background: var(--c-blue-bg);   border-color: var(--c-blue-b);   }
.note-card.color-purple { background: var(--c-purple-bg); border-color: var(--c-purple-b); }
.note-card.color-pink   { background: var(--c-pink-bg);   border-color: var(--c-pink-b);   }

.card-pin {
  position: absolute;
  top: 11px;
  right: 11px;
  color: var(--accent);
  opacity: .7;
  pointer-events: none;
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 5px;
  word-break: break-word;
  padding-right: 14px;
}

.card-body {
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 9px;
}

.tag {
  display: inline-block;
  font-family: 'SFMono-Regular', 'Menlo', 'Consolas', monospace;
  font-size: 10.5px;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 3px;
  padding: 1px 5px;
  cursor: pointer;
  transition: background .15s;
  line-height: 1.5;
}
.tag:hover { background: rgba(99,102,241,.22); }

.card-meta {
  font-size: 10.5px;
  color: var(--text-3);
  margin-top: 9px;
}

/* ─────────────────────────────────────────
   Empty state
───────────────────────────────────────── */
.empty-state {
  padding: 80px 24px 60px;
  text-align: center;
}
.empty-icon {
  margin-bottom: 16px;
  opacity: .2;
  color: var(--text-2);
}
.empty-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}
.empty-hint {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-2);
}
.empty-hint kbd {
  background: var(--border);
  border: 1px solid var(--border-h);
  padding: 1px 6px;
  font-family: 'SFMono-Regular', 'Menlo', 'Consolas', monospace;
  font-size: 11.5px;
  border-radius: 4px;
}

/* ─────────────────────────────────────────
   Editor overlay
───────────────────────────────────────── */
.editor-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s, visibility .2s;
}
.editor-overlay.show {
  opacity: 1;
  visibility: visible;
}

/* ─────────────────────────────────────────
   Editor panel
───────────────────────────────────────── */
.editor-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 500px;
  max-width: 100vw;
  background: var(--surface);
  z-index: 201;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .22s cubic-bezier(.4,0,.2,1);
  border-left: 1px solid var(--border);
}
.editor-panel.open { transform: translateX(0); }

/* colour variants */
.editor-panel.color-yellow { background: var(--c-yellow-bg); }
.editor-panel.color-green  { background: var(--c-green-bg); }
.editor-panel.color-blue   { background: var(--c-blue-bg); }
.editor-panel.color-purple { background: var(--c-purple-bg); }
.editor-panel.color-pink   { background: var(--c-pink-bg); }

/* toolbar */
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.color-picker {
  display: flex;
  gap: 5px;
  align-items: center;
}

.cpbtn {
  width: 17px;
  height: 17px;
  border: 2px solid var(--border);
  border-radius: 50%;
  transition: transform .15s, border-color .15s;
  background: var(--surface);
  outline: none;
  flex-shrink: 0;
}
.cpbtn:hover  { transform: scale(1.2); }
.cpbtn.active { border-color: var(--text); box-shadow: 0 0 0 1px var(--text); }
.cpbtn[data-color="yellow"] { background: var(--dot-yellow); border-color: var(--c-yellow-b); }
.cpbtn[data-color="green"]  { background: var(--dot-green);  border-color: var(--c-green-b);  }
.cpbtn[data-color="blue"]   { background: var(--dot-blue);   border-color: var(--c-blue-b);   }
.cpbtn[data-color="purple"] { background: var(--dot-purple); border-color: var(--c-purple-b); }
.cpbtn[data-color="pink"]   { background: var(--dot-pink);   border-color: var(--c-pink-b);   }
.cpbtn[data-color="yellow"].active,
.cpbtn[data-color="green"].active,
.cpbtn[data-color="blue"].active,
.cpbtn[data-color="purple"].active,
.cpbtn[data-color="pink"].active { border-color: var(--text); box-shadow: 0 0 0 1px var(--text); }

.editor-btns { display: flex; align-items: center; gap: 1px; }

.ed-btn {
  background: none;
  border: none;
  padding: 6px 7px;
  color: var(--text-2);
  display: grid;
  place-items: center;
  border-radius: 5px;
  transition: color .15s, background .15s;
}
.ed-btn:hover { color: var(--text); background: rgba(0,0,0,.06); }
[data-theme="dark"] .ed-btn:hover { background: rgba(255,255,255,.07); }
.ed-btn.pinned { color: var(--accent); }
.ed-btn-danger:hover { color: #EF4444 !important; background: rgba(239,68,68,.08) !important; }

.ed-close {
  background: none;
  border: none;
  padding: 6px 7px;
  color: var(--text-2);
  display: grid;
  place-items: center;
  border-radius: 5px;
  margin-left: 3px;
  transition: color .15s, background .15s;
}
.ed-close:hover { color: var(--text); background: rgba(0,0,0,.06); }
[data-theme="dark"] .ed-close:hover { background: rgba(255,255,255,.07); }

/* Edit / Preview mode tabs */
.editor-mode-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.etab {
  background: none;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 3px 10px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-2);
  transition: all .15s;
  cursor: pointer;
}
.etab:hover  { color: var(--text); border-color: var(--border-h); }
.etab.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.md-badge {
  margin-left: auto;
  font-family: 'SFMono-Regular', 'Menlo', 'Consolas', monospace;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: 0.5px;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}

/* Edit pane */
.edit-pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.note-title-input {
  border: none;
  outline: none;
  background: transparent;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  padding: 16px 18px 8px;
  width: 100%;
  line-height: 1.3;
  letter-spacing: -0.3px;
  font-family: inherit;
  flex-shrink: 0;
}
.note-title-input::placeholder { color: var(--border-h); }

.note-body-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 13.5px;
  color: var(--text);
  padding: 6px 18px 12px;
  width: 100%;
  resize: none;
  line-height: 1.75;
  font-family: inherit;
  overflow-y: auto;
}
.note-body-input::placeholder { color: var(--text-3); font-size: 13px; }

/* Preview pane */
.preview-pane {
  flex: 1;
  overflow-y: auto;
  padding: 0 18px 16px;
}

.preview-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  padding: 16px 0 10px;
  line-height: 1.3;
  letter-spacing: -0.3px;
  word-break: break-word;
}
.preview-title:empty { display: none; }

/* ─────────────────────────────────────────
   Markdown rendered content
───────────────────────────────────────── */
.md-content {
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--text);
  word-break: break-word;
}
.md-content p { margin-bottom: .8em; }
.md-content p:last-child { margin-bottom: 0; }

.md-content h1, .md-content h2, .md-content h3,
.md-content h4, .md-content h5, .md-content h6 {
  font-weight: 700;
  line-height: 1.3;
  margin: 1.1em 0 .4em;
  letter-spacing: -0.2px;
}
.md-content h1 { font-size: 1.5em; }
.md-content h2 { font-size: 1.25em; }
.md-content h3 { font-size: 1.1em; }
.md-content h4, .md-content h5, .md-content h6 { font-size: 1em; }
.md-content h1:first-child, .md-content h2:first-child { margin-top: .2em; }

.md-content strong { font-weight: 700; }
.md-content em     { font-style: italic; }
.md-content s      { text-decoration: line-through; color: var(--text-2); }

.md-content code {
  font-family: 'SFMono-Regular', 'Menlo', 'Consolas', 'Liberation Mono', monospace;
  font-size: .875em;
  background: rgba(0,0,0,.06);
  border-radius: 3px;
  padding: .1em .35em;
}
[data-theme="dark"] .md-content code { background: rgba(255,255,255,.08); }

.md-content pre {
  background: rgba(0,0,0,.05);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: .8em 0;
}
[data-theme="dark"] .md-content pre { background: rgba(255,255,255,.04); }
.md-content pre code {
  font-family: 'SFMono-Regular', 'Menlo', 'Consolas', 'Liberation Mono', monospace;
  font-size: .84em;
  line-height: 1.6;
  background: none;
  padding: 0;
  border-radius: 0;
}

.md-content blockquote {
  border-left: 3px solid var(--accent);
  padding: .2em .8em;
  color: var(--text-2);
  margin: .8em 0;
  font-style: italic;
}

.md-content ul, .md-content ol {
  padding-left: 1.4em;
  margin: .5em 0;
}
.md-content li { margin-bottom: .2em; }

.md-content ul.md-tasks { list-style: none; padding-left: .2em; }
.md-content ul.md-tasks li { display: flex; align-items: baseline; gap: .4em; }
.md-content ul.md-tasks li .cb { font-size: .9em; flex-shrink: 0; }
.md-content ul.md-tasks li.done { color: var(--text-2); text-decoration: line-through; }

.md-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.2em 0;
}

.md-content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.md-content a:hover { color: var(--accent-h); }

/* ─────────────────────────────────────────
   Editor status bar
───────────────────────────────────────── */
.editor-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 18px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-3);
  flex-shrink: 0;
  letter-spacing: 0.1px;
}

/* ─────────────────────────────────────────
   Scrollbar (webkit)
───────────────────────────────────────── */
::-webkit-scrollbar       { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-h); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ─────────────────────────────────────────
   Mobile tweaks
───────────────────────────────────────── */
@media (max-width: 600px) {
  .app-name    { display: none; }
  .btn-new span { display: none; }
  .header-search { max-width: none; }
  .notes-grid  { padding: 12px; column-gap: 10px; }
  .note-card   { margin-bottom: 10px; }
  .editor-panel { width: 100vw; }
}
