@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #13111a;
  --surface:   #1e1b2e;
  --surface2:  #252238;
  --border:    #2e2a45;
  --accent:    #7c6af7;
  --accent2:   #a78bfa;
  --accent-dim:#3d3580;
  --text:      #f0eaff;
  --muted:     #8b82b0;
  --danger:    #f06a6a;
  --tag1: #4f46e5; --tag2: #0891b2; --tag3: #059669;
  --tag4: #d97706; --tag5: #db2777; --tag6: #7c3aed;
  --radius: 12px;
  --transition: 0.18s ease;
}

html, body {
  height: 100%;
  font-family: 'Syne', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── LAYOUT ─────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: 100vh;
  height: 100vh;
}

/* ── SIDEBAR ─────────────────────────────────── */
#sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

#sidebar-header h1 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

#btn-new {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--accent);
  border: none; cursor: pointer; color: #fff;
  font-size: 1.3rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}
#btn-new:hover { background: var(--accent2); transform: scale(1.08); }

/* Search */
#search-wrap {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
#search-wrap svg { position: absolute; left: 24px; top: 50%; transform: translateY(-50%); opacity: .45; pointer-events: none; }
#search {
  width: 100%; padding: 8px 10px 8px 34px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-family: inherit;
  font-size: 0.82rem; outline: none; transition: var(--transition);
}
#search::placeholder { color: var(--muted); }
#search:focus { border-color: var(--accent); }

/* Tags filter */
#tags-filter {
  padding: 10px 14px;
  display: flex; flex-wrap: wrap; gap: 6px;
  border-bottom: 1px solid var(--border);
  min-height: 0;
}
.tag-chip {
  padding: 3px 10px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 600; cursor: pointer;
  border: 1.5px solid transparent; transition: var(--transition);
  background: var(--surface2); color: var(--muted);
}
.tag-chip:hover { color: var(--text); border-color: var(--accent-dim); }
.tag-chip.active { background: var(--accent-dim); color: var(--accent2); border-color: var(--accent); }

/* Notes list */
#notes-list {
  flex: 1; overflow-y: auto; padding: 8px;
}
#notes-list::-webkit-scrollbar { width: 4px; }
#notes-list::-webkit-scrollbar-track { background: transparent; }
#notes-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.note-item {
  padding: 12px 14px; border-radius: var(--radius);
  cursor: pointer; transition: var(--transition);
  border: 1px solid transparent;
  margin-bottom: 4px; position: relative;
}
.note-item:hover { background: var(--surface2); }
.note-item.active { background: var(--surface2); border-color: var(--accent); }
.note-item .note-title {
  font-size: 0.88rem; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 4px;
}
.note-item .note-preview {
  font-size: 0.75rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: 'JetBrains Mono', monospace;
}
.note-item .note-date {
  font-size: 0.68rem; color: var(--muted); margin-top: 6px;
  opacity: 0.7;
}
.note-item .note-tags { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.note-tag {
  padding: 1px 7px; border-radius: 20px;
  font-size: 0.65rem; font-weight: 600;
  color: #fff; opacity: 0.85;
}

.empty-list {
  text-align: center; color: var(--muted);
  padding: 40px 20px; font-size: 0.85rem; line-height: 1.7;
}
.empty-list span { font-size: 2rem; display: block; margin-bottom: 8px; }

/* ── MAIN EDITOR ─────────────────────────────── */
#main {
  display: flex; flex-direction: column; overflow: hidden;
  position: relative;
}

/* Welcome / empty state */
#welcome {
  flex: 1; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px; color: var(--muted);
}
#welcome .big { font-size: 3.5rem; }
#welcome h2 { font-size: 1.3rem; font-weight: 700; color: var(--text); }
#welcome p { font-size: 0.85rem; }

/* Editor area */
#editor-wrap {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}

#editor-toolbar {
  padding: 14px 24px 10px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
}

#note-title-input {
  flex: 1; min-width: 180px;
  background: transparent; border: none;
  font-family: 'Syne', sans-serif; font-size: 1.3rem; font-weight: 800;
  color: var(--text); outline: none;
  letter-spacing: -0.02em;
}
#note-title-input::placeholder { color: var(--muted); }

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

.tb-btn {
  padding: 5px 10px; border-radius: 7px;
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; font-size: 0.75rem;
  font-family: 'Syne', sans-serif; font-weight: 600;
  transition: var(--transition); display: flex; align-items: center; gap: 5px;
  white-space: nowrap;
}
.tb-btn:hover { background: var(--surface2); color: var(--text); border-color: var(--accent); }
.tb-btn.danger:hover { color: var(--danger); border-color: var(--danger); background: #f06a6a12; }
.tb-btn svg { flex-shrink: 0; }

/* Tag editor inside toolbar */
#tag-editor-wrap { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.editor-tag {
  padding: 2px 8px 2px 10px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 600; color: #fff;
  display: flex; align-items: center; gap: 4px; cursor: default;
}
.editor-tag button {
  background: none; border: none; color: inherit; cursor: pointer;
  font-size: 0.8rem; line-height: 1; opacity: 0.7; padding: 0;
}
.editor-tag button:hover { opacity: 1; }
#tag-input-inline {
  background: transparent; border: none; border-bottom: 1px solid var(--border);
  color: var(--text); font-family: 'Syne', sans-serif; font-size: 0.8rem;
  outline: none; width: 90px; padding: 2px 4px;
}
#tag-input-inline::placeholder { color: var(--muted); }

/* Format bar */
#format-bar {
  padding: 6px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; gap: 4px; align-items: center;
}
.fmt-btn {
  width: 28px; height: 28px; border-radius: 6px;
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-family: 'Syne', sans-serif; font-weight: 700;
  font-size: 0.85rem; transition: var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.fmt-btn:hover { background: var(--surface2); color: var(--text); }

/* The actual editor */
#note-body {
  flex: 1; padding: 24px 28px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem; line-height: 1.85;
  color: var(--text); background: transparent;
  border: none; outline: none; resize: none;
  overflow-y: auto;
}
#note-body::-webkit-scrollbar { width: 4px; }
#note-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
#note-body::placeholder { color: var(--muted); }

/* Status bar */
#status-bar {
  padding: 6px 28px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  font-size: 0.72rem; color: var(--muted);
}
#status-bar .save-status { margin-left: auto; display: flex; align-items: center; gap: 5px; }
#status-bar .save-status span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); display: inline-block; transition: var(--transition); }
#status-bar .save-status.saved span { background: #4ade80; }

/* ── MODAL ───────────────────────────────────── */
#modal-overlay {
  display: none; position: fixed; inset: 0;
  background: #00000080; backdrop-filter: blur(4px);
  z-index: 100; align-items: center; justify-content: center;
}
#modal-overlay.show { display: flex; }
#modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; width: 360px; max-width: 90vw;
  animation: popIn 0.18s ease;
}
@keyframes popIn { from { transform: scale(0.93); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#modal h3 { font-size: 1.1rem; margin-bottom: 8px; font-weight: 800; }
#modal p { font-size: 0.84rem; color: var(--muted); margin-bottom: 20px; line-height: 1.5; }
#modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.btn { padding: 8px 18px; border-radius: 8px; font-family: 'Syne', sans-serif; font-weight: 700; font-size: 0.85rem; cursor: pointer; border: none; transition: var(--transition); }
.btn-ghost { background: var(--surface2); color: var(--muted); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

/* ── TOAST ───────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 18px; border-radius: 10px;
  font-size: 0.82rem; font-weight: 600; z-index: 200;
  transform: translateY(20px); opacity: 0;
  transition: all 0.25s ease; pointer-events: none;
}
#toast.show { transform: translateY(0); opacity: 1; }

/* ── MOBILE ──────────────────────────────────── */
#mobile-back { display: none; }

@media (max-width: 680px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { position: fixed; inset: 0; z-index: 10; transform: translateX(0); transition: transform 0.25s ease; }
  #sidebar.hidden { transform: translateX(-100%); }
  #main { display: none; }
  #main.show { display: flex; }
  #mobile-back { display: flex; }
}
