/* ── Design tokens ────────────────────────────────────────── */
:root {
  --brand:           rgb(248, 166, 107);
  --bg:              rgb(255, 255, 255);
  --bg-elevated:     rgb(243, 244, 245);
  --text:            rgb(44,  49,  57);
  --text-muted:      rgb(136, 145, 161);
  --text-very-muted: rgb(193, 199, 208);
  --border:          rgb(236, 238, 240);
  --shadow-color:    rgba(0, 0, 0, 0.08);
  --danger:          rgb(225, 29,  72);
}

body.dark {
  --bg:              rgb(34,  38,  44);
  --bg-elevated:     rgb(44,  49,  57);
  --text:            rgb(193, 199, 208);
  --text-muted:      rgb(136, 145, 161);
  --text-very-muted: rgb(94,  107, 128);
  --border:          rgb(60,  66,  77);
  --shadow-color:    transparent;
}

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

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

/* ── Fixed site header ────────────────────────────────────── */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 6px var(--shadow-color);
}

/* Row 1: logo | centered new | right actions (3-column) */
.header-row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 1rem;
}

.header-logo {
  flex: 1;
  display: flex;
  align-items: center;
  color: var(--text-muted);
  text-decoration: none;
}
.header-logo:hover { color: var(--brand); }

.header-logo-icon {
  width: 26px;
  height: 26px;
  stroke: currentColor;
}

.header-row1-right {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
}

.header-delete-form { display: contents; }

.header-delete-btn {
  padding: 0.35rem 0.5rem;
  color: var(--text-muted);
}
.header-delete-btn:hover { color: var(--danger); border-color: var(--danger); }

/* Spacer to push content below fixed header (height set by JS) */
.header-spacer { height: 52px; /* fallback */ }

/* Note title displayed outside the header */
.note-page-title {
  font-size: 1.8rem;
  font-weight: 700;
  padding: 1.1rem 1rem 0.4rem;
  color: var(--text);
  line-height: 1.3;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  padding: 0.4rem 0.85rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.825rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { opacity: 0.88; }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: 0.88; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--danger); border-color: var(--danger); }

/* ── Main layout ──────────────────────────────────────────── */
.main {
  max-width: 720px;
  margin: 0 auto;
}

.content-area {
  padding: 1.25rem 1rem;
}

/* ── Inline search (home page) ────────────────────────────── */
.content-search {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.search-input {
  flex: 1;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--brand); }
.search-input::placeholder { color: var(--text-very-muted); }

.search-btn {
  flex-shrink: 0;
  padding: 0.5rem 0.75rem;
}

/* ── Note list ────────────────────────────────────────────── */
.note-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.note-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.65rem 0.5rem;
  border-radius: 8px;
  transition: background 0.15s;
}
.note-item:hover { background: var(--bg-elevated); }

.note-title-link {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
}
.note-title-link:hover { color: var(--brand); }

.note-date {
  font-size: 0.7rem;
  color: var(--text-very-muted);
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: 0.5rem;
}

/* ── Note viewer ──────────────────────────────────────────── */
.note-content {
  padding: 1.25rem 1rem;
  line-height: 1.8;
}

/* ── Markdown rendering ───────────────────────────────────── */
.note-content h1 { font-size: 1.65rem; margin: 1.5rem 0 0.75rem; }
.note-content h2 { font-size: 1.3rem;  margin: 1.25rem 0 0.6rem; }
.note-content h3 { font-size: 1.1rem;  margin: 1rem 0 0.5rem; }
.note-content p  { margin-bottom: 1rem; }
.note-content a  { color: var(--brand); }
.note-content code {
  background: var(--bg-elevated);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.875em;
  font-family: ui-monospace, monospace;
}
.note-content pre {
  background: var(--bg-elevated);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  margin-bottom: 1rem;
}
.note-content blockquote {
  border-left: 3px solid var(--brand);
  padding-left: 1rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.note-content ul, .note-content ol { padding-left: 1.5rem; margin-bottom: 1rem; }
.note-content img { max-width: 100%; border-radius: 6px; }
.note-content table { border-collapse: collapse; width: 100%; margin-bottom: 1rem; }
.note-content th, .note-content td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}
.note-content th { background: var(--bg-elevated); font-weight: 600; }

.wikilink { color: var(--brand); text-decoration: underline dotted; }

/* ── Note editor ──────────────────────────────────────────── */
.note-editor-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
}

.editor-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.title-input {
  font-size: 1.4rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-bottom: 2px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 0.25rem 0;
  outline: none;
  width: 100%;
}
.title-input:focus { border-color: var(--brand); }

.content-textarea {
  width: 100%;
  min-height: 70vh;
  padding: 0.75rem 0;
  border: none;
  background: var(--bg);
  color: var(--text);
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  font-size: 0.875rem;
  line-height: 1.7;
  resize: none;
  outline: none;
  border-top: 1px solid var(--border);
}

/* ── Search results page ──────────────────────────────────── */
.search-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1rem;
}

.note-count {
  font-size: 0.75rem;
  color: var(--text-very-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.search-results {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.search-result {
  padding: 0.75rem 0.5rem;
  border-radius: 8px;
  transition: background 0.15s;
}
.search-result:hover { background: var(--bg-elevated); }

.search-snippet {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  line-height: 1.5;
}

b.match {
  background: rgba(248, 166, 107, 0.3);
  color: var(--text);
  border-radius: 2px;
  padding: 0 2px;
  font-weight: 600;
}

/* ── Tags ─────────────────────────────────────────────────── */
.tags { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.3rem; }

.tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.55rem;
  background: var(--brand);
  color: #fff;
  border-radius: 999px;
}

/* ── States ───────────────────────────────────────────────── */
.empty-state { padding: 3rem 1rem; text-align: center; color: var(--text-muted); }
.empty-state p { margin-bottom: 1rem; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 600px) {
  .header-row1 { padding: 0.5rem 0.75rem; }
  .note-page-title { font-size: 1.4rem; padding: 0.9rem 0.75rem 0.3rem; }
  .content-area { padding: 1rem 0.75rem; }
  .note-content { padding: 1rem 0.75rem; }
  .note-editor-form { padding: 0.75rem; }
}
