/* =============================================================
   Notes App · vanilla CSS
   ============================================================= */

:root {
  --bg: #0f172a;
  --bg-elev: #1e293b;
  --bg-elev-2: #334155;
  --bg-input: #0b1326;
  --fg: #f1f5f9;
  --fg-muted: #94a3b8;
  --fg-dim: #64748b;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(99, 102, 241, 0.15);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --success: #10b981;
  --border: rgba(148, 163, 184, 0.15);
  --border-strong: rgba(148, 163, 184, 0.3);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-w: 320px;
}

[data-theme="light"] {
  --bg: #f8fafc;
  --bg-elev: #ffffff;
  --bg-elev-2: #e2e8f0;
  --bg-input: #f1f5f9;
  --fg: #0f172a;
  --fg-muted: #475569;
  --fg-dim: #94a3b8;
  --accent-soft: rgba(99, 102, 241, 0.1);
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.2);
  --shadow: 0 20px 50px rgba(15, 23, 42, 0.1);
}

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

html,
body {
  height: 100%;
}

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition), color var(--transition);
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: 280px;
    transform: translateX(-100%);
    transition: transform var(--transition);
  }
  .sidebar.is-open {
    transform: translateX(0);
  }
}

/* ============ Sidebar ============ */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 14px;
  overflow: hidden;
}

.sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar__brand {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar__brand-icon {
  font-size: 1.4rem;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  transition: transform var(--transition), background var(--transition);
}

.icon-btn:hover {
  transform: rotate(15deg);
}

/* ============ Search ============ */
.search {
  position: relative;
  display: flex;
  align-items: center;
}

.search__icon {
  position: absolute;
  left: 12px;
  color: var(--fg-muted);
  pointer-events: none;
}

.search__input {
  width: 100%;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 10px 12px 10px 36px;
  background: var(--bg-input);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ============ Tags filter ============ */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
}

.tag-chip {
  font-size: 0.75rem;
  padding: 4px 10px;
  background: var(--bg-elev-2);
  color: var(--fg-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.tag-chip:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

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

/* ============ New note button ============ */
.new-note-btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background var(--transition), transform var(--transition);
}

.new-note-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.new-note-btn:active {
  transform: translateY(0);
}

.new-note-btn__icon {
  font-size: 1.1rem;
  line-height: 1;
}

/* ============ Notes list ============ */
.notes-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 -8px;
  padding: 0 8px;
}

.notes-list::-webkit-scrollbar {
  width: 6px;
}

.notes-list::-webkit-scrollbar-thumb {
  background: var(--bg-elev-2);
  border-radius: 3px;
}

.note-item {
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.note-item:hover {
  background: var(--bg-elev-2);
  border-color: var(--border-strong);
}

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

.note-item__title {
  font-size: 0.92rem;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item__preview {
  font-size: 0.78rem;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
}

.note-item__meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.note-item__date {
  font-size: 0.7rem;
  color: var(--fg-dim);
}

.note-item__tag {
  font-size: 0.65rem;
  padding: 1px 6px;
  background: var(--bg-elev-2);
  border-radius: 999px;
  color: var(--fg-muted);
}

/* ============ Sidebar footer ============ */
.sidebar__footer {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.sidebar__count {
  font-size: 0.75rem;
  color: var(--fg-muted);
  margin-right: auto;
}

.text-btn {
  font-family: inherit;
  font-size: 0.75rem;
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
}

.text-btn:hover {
  background: var(--bg-elev-2);
  color: var(--fg);
}

/* ============ Editor ============ */
.editor {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor__empty {
  margin: auto;
  text-align: center;
  padding: 32px;
}

.editor__empty-icon {
  font-size: 4rem;
  margin-bottom: 12px;
}

.editor__empty-title {
  font-size: 1.4rem;
  margin-bottom: 8px;
}

.editor__empty-text {
  color: var(--fg-muted);
  margin-bottom: 20px;
}

.primary-btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}

.primary-btn:hover {
  background: var(--accent-hover);
}

.editor__content {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 24px 32px;
  overflow: hidden;
}

.editor__title {
  font-family: inherit;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: transparent;
  border: none;
  outline: none;
  color: var(--fg);
  padding: 6px 0;
  margin-bottom: 12px;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition);
}

.editor__title:focus {
  border-bottom-color: var(--border);
}

.editor__tags-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.editor__tags-label {
  font-size: 0.85rem;
  color: var(--fg-muted);
}

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

.editor__tag {
  font-size: 0.78rem;
  padding: 3px 8px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.editor__tag-remove {
  cursor: pointer;
  opacity: 0.6;
  font-weight: 700;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 0.9rem;
  padding: 0;
  line-height: 1;
}

.editor__tag-remove:hover {
  opacity: 1;
}

.editor__tag-input {
  font-family: inherit;
  font-size: 0.8rem;
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  color: var(--fg);
  padding: 3px 10px;
  outline: none;
  width: 140px;
  transition: border-color var(--transition);
}

.editor__tag-input:focus {
  border-color: var(--accent);
  border-style: solid;
}

.editor__toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.tab-btn {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 6px 12px;
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
}

.tab-btn:hover {
  color: var(--fg);
}

.tab-btn.is-active {
  background: var(--bg-elev-2);
  color: var(--fg);
  border-color: var(--border);
}

.editor__spacer {
  flex: 1;
}

.editor__meta {
  font-size: 0.75rem;
  color: var(--fg-dim);
}

.danger-btn {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 6px 10px;
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--transition);
}

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

.editor__body {
  flex: 1;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.92rem;
  line-height: 1.6;
  background: transparent;
  color: var(--fg);
  border: none;
  outline: none;
  resize: none;
  padding: 8px 0;
  width: 100%;
  height: 100%;
}

.editor__preview {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  font-size: 0.95rem;
  line-height: 1.7;
}

.editor__preview h1,
.editor__preview h2,
.editor__preview h3 {
  margin: 1em 0 0.5em;
  line-height: 1.3;
}

.editor__preview h1 { font-size: 1.6rem; }
.editor__preview h2 { font-size: 1.3rem; }
.editor__preview h3 { font-size: 1.1rem; }

.editor__preview p {
  margin: 0.5em 0;
}

.editor__preview ul,
.editor__preview ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}

.editor__preview li {
  margin: 0.2em 0;
}

.editor__preview code {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85em;
  background: var(--bg-elev-2);
  padding: 2px 6px;
  border-radius: 4px;
}

.editor__preview pre {
  background: var(--bg-elev-2);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5em 0;
}

.editor__preview pre code {
  background: transparent;
  padding: 0;
}

.editor__preview blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 0.5em 0;
  color: var(--fg-muted);
}

.editor__preview a {
  color: var(--accent);
  text-decoration: none;
}

.editor__preview a:hover {
  text-decoration: underline;
}

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

.editor__preview img {
  max-width: 100%;
  border-radius: 8px;
}

.editor__preview table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.5em 0;
}

.editor__preview th,
.editor__preview td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
