/* ---------- tokens ---------- */
:root {
  --bg: #0F1317;
  --surface: #171C22;
  --surface-raised: #1E252C;
  --border: #2A323B;
  --border-soft: #232A32;
  --text: #E6E9ED;
  --text-muted: #8A93A0;
  --text-faint: #5C6470;
  --accent: #4FB0A8;
  --accent-dim: #2E4644;
  --danger: #C4677A;
  --danger-dim: #3A2A2E;
  --radius: 6px;
  --font-ui: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

input, select, textarea {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 11px;
  width: 100%;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

textarea {
  font-family: var(--font-mono);
  font-size: 13.5px;
  resize: vertical;
  line-height: 1.6;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- layout shell ---------- */
.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-shrink: 0;
}
.brand-mark {
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 600;
  font-size: 16px;
}
.brand-name {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}
.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}
#searchInput {
  padding-left: 34px;
}

.body {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ---------- sidebar ---------- */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border-soft);
  padding: 16px 12px;
  overflow-y: auto;
}
.sidebar-section-label {
  font-size: 12px;
  color: var(--text-faint);
  padding: 0 8px 8px;
}
.category-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.category-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  border: 1px solid transparent;
}
.category-item:hover {
  background: var(--surface-raised);
  color: var(--text);
}
.category-item.active {
  background: var(--surface-raised);
  color: var(--text);
  border-color: var(--border);
}
.category-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.category-item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
}
.category-item-count {
  font-size: 12px;
  color: var(--text-faint);
  font-family: var(--font-mono);
}
.add-category-btn {
  margin-top: 10px;
  margin-left: 8px;
}

.sidebar-scrim {
  display: none;
}

/* ---------- content ---------- */
.content {
  flex: 1;
  min-width: 0;
  padding: 20px 24px 60px;
  overflow-y: auto;
}
.content-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 16px;
}
.content-header h1 {
  font-size: 19px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}
.result-count {
  color: var(--text-faint);
  font-size: 13px;
  font-family: var(--font-mono);
}

.note-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 780px;
}

/* ---------- note card ---------- */
.note-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.note-card-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}
.note-title {
  font-weight: 600;
  font-size: 14.5px;
  flex: 1;
  min-width: 0;
}
.note-card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.note-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.category-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-muted);
  padding: 2px 8px 2px 6px;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.tag-chip {
  font-size: 11.5px;
  color: var(--text-faint);
  font-family: var(--font-mono);
}
.pin-flag {
  color: var(--accent);
  font-size: 11.5px;
}

.note-body p {
  margin: 0 0 8px;
  color: var(--text-muted);
  font-size: 13.5px;
  white-space: pre-wrap;
}
.note-body p:last-child { margin-bottom: 0; }

.code-block {
  position: relative;
  background: #0B0E12;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  margin: 8px 0;
}
.code-block pre {
  margin: 0;
  padding: 12px 44px 12px 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  color: #C9E8E4;
  white-space: pre;
}
.copy-btn {
  position: absolute;
  top: 7px;
  right: 7px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 5px;
  padding: 4px 6px;
  cursor: pointer;
  line-height: 0;
}
.copy-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.copy-btn.copied {
  color: var(--accent);
  border-color: var(--accent);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius);
  padding: 8px 14px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 500;
  font-size: 13.5px;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #0B1412;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-faint); }
.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
}
.btn-danger:hover { filter: brightness(1.15); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius);
  display: inline-flex;
}
.icon-btn:hover { background: var(--surface-raised); color: var(--text); }

.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  padding: 6px 8px;
  text-align: left;
}
.text-btn:hover { text-decoration: underline; }

.menu-toggle { display: none; }

/* ---------- empty state ---------- */
.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-faint);
}
.empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 4px;
}
.empty-sub { margin: 0; font-size: 13.5px; }

/* ---------- editor panel ---------- */
.panel-scrim {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 10, 0.6);
  z-index: 40;
}
.editor-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 520px;
  max-width: 100vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.editor-header h2 { font-size: 16px; margin: 0; font-weight: 600; }
.editor-body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-label {
  font-size: 12px;
  color: var(--text-muted);
  margin: 10px 0 2px;
  display: block;
}
.field-hint { color: var(--text-faint); font-weight: 400; }
.field-row {
  display: flex;
  gap: 12px;
}
.field-col { flex: 1; min-width: 0; }
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}
#noteContent { margin-top: 4px; }
p.field-hint { font-size: 12px; margin: 6px 0 0; }
.preview-label {
  font-size: 12px;
  color: var(--text-muted);
  margin: 14px 0 6px;
}
.preview-box {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-height: 60px;
}
.preview-box .code-block pre { font-size: 12.5px; }
.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-top: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.editor-footer-right { display: flex; gap: 8px; }

/* ---------- category modal ---------- */
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  z-index: 60;
}
.modal h2 { font-size: 15px; margin: 0 0 4px; font-weight: 600; }
.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
}
.color-swatch.selected {
  border-color: var(--text);
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  z-index: 100;
}

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  .menu-toggle { display: inline-flex; }
  .brand-name { display: none; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    z-index: 45;
    padding-top: 60px;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-scrim.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(6,8,10,0.55);
    z-index: 42;
  }

  .content { padding: 16px 14px 50px; }
  .editor-panel { width: 100%; }
  .field-row { flex-direction: column; gap: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
