:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-alt: #f4f4f5;
  --border: #e4e4e7;
  --text: #18181b;
  --muted: #52525b;
  --accent: #0f766e;
  --accent-hover: #0d625b;
  --accent-soft: #ccfbf1;
  --accent-ink: #115e59;
  --warn-soft: #fef3c7;
  --warn-ink: #92400e;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(24, 24, 27, 0.04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.mono { font-family: var(--mono); font-size: 0.9em; }
.hidden { display: none !important; }

.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 66px;
  flex-wrap: wrap;
  padding-top: 8px;
  padding-bottom: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: inherit;
}

.brand-badge {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 1.05rem;
  display: grid;
  place-items: center;
}

.brand-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.brand-meta strong { font-size: 1rem; color: var(--text); }
.brand-meta span { font-size: 0.78rem; color: var(--muted); }

.cat-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-alt);
  padding: 4px;
  border-radius: 10px;
}

.cat-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.cat-tab:hover { color: var(--text); }
.cat-tab.active {
  background: var(--surface);
  color: var(--accent-ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  padding: 8px 14px;
}
.btn-sm { padding: 6px 12px; font-size: 0.83rem; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }

.input, .textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  padding: 9px 12px;
}
.input:focus, .textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.22);
  border-color: var(--accent);
}
.textarea { font-family: var(--mono); font-size: 0.88rem; line-height: 1.55; resize: vertical; }
.field-label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }

/* Main Content */
.main-shell { flex: 1; padding-top: 24px; padding-bottom: 48px; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.search-box {
  flex: 1;
  min-width: 240px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
}
.search-box svg { color: var(--muted); flex-shrink: 0; }
.search-box input {
  border: 0;
  outline: none;
  background: transparent;
  width: 100%;
  padding: 10px 0;
  font: inherit;
  font-size: 0.92rem;
  color: var(--text);
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.vis-pills {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}
.vis-pill {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.vis-pill.active { background: var(--accent-soft); color: var(--accent-ink); }

.count-label { font-size: 0.85rem; color: var(--muted); font-weight: 500; }

.tag-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
.tag-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 0.79rem;
  font-weight: 600;
  cursor: pointer;
}
.tag-pill:hover { border-color: var(--accent); color: var(--accent-ink); }
.tag-pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Notes Grid */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
}
.note-card:hover { transform: translateY(-2px); border-color: var(--accent); }

.card-badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-cat { background: var(--surface-alt); color: var(--text); }
.badge-pin { background: var(--accent-soft); color: var(--accent-ink); }
.badge-priv { background: var(--warn-soft); color: var(--warn-ink); }

.note-card h3 {
  margin: 0;
  font-size: 1.07rem;
  line-height: 1.38;
  color: var(--text);
}
.note-summary {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.note-foot {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--surface-alt);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}
.card-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.card-tag { background: var(--surface-alt); padding: 1px 7px; border-radius: 5px; font-family: var(--mono); font-size: 0.74rem; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  color: var(--muted);
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 24, 27, 0.45);
}
.modal-panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
  padding: 22px 24px;
}
.modal-reader { max-width: 820px; }
.modal-editor { max-width: 860px; }
.modal-login { max-width: 420px; }

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.modal-head h2 { margin: 4px 0 0; font-size: 1.35rem; line-height: 1.3; }
.modal-head-actions { display: flex; gap: 8px; flex-shrink: 0; }
.reader-meta { margin: 6px 0 0; font-size: 0.84rem; color: var(--muted); }

/* Markdown Body */
.markdown-body { font-size: 0.96rem; line-height: 1.72; color: var(--text); }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 {
  margin: 1.25em 0 0.5em;
  line-height: 1.3;
}
.markdown-body h1:first-child, .markdown-body h2:first-child { margin-top: 0; }
.markdown-body p { margin: 0.75em 0; }
.markdown-body ul, .markdown-body ol { padding-left: 1.4em; margin: 0.65em 0; }
.markdown-body li.md-task { list-style: none; margin-left: -1.2em; display: flex; align-items: baseline; gap: 8px; }
.markdown-body blockquote {
  margin: 0.9em 0;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  background: var(--surface-alt);
  color: var(--muted);
  border-radius: 0 8px 8px 0;
}
.markdown-body code {
  font-family: var(--mono);
  background: var(--surface-alt);
  padding: 2px 5px;
  border-radius: 5px;
  font-size: 0.87em;
}
.md-code-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin: 1em 0;
  background: #18181b;
  color: #f4f4f5;
}
.md-code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: #27272a;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: #a1a1aa;
}
.copy-code-btn {
  border: 1px solid #3f3f46;
  background: transparent;
  color: #e4e4e7;
  border-radius: 6px;
  font-size: 0.74rem;
  padding: 2px 8px;
  cursor: pointer;
}
.copy-code-btn:hover { background: #3f3f46; }
.md-code-block pre { margin: 0; padding: 12px 14px; overflow-x: auto; font-size: 0.86rem; line-height: 1.5; }
.md-code-block pre code { background: transparent; padding: 0; color: inherit; }

.md-table-wrap { overflow-x: auto; margin: 1em 0; }
.markdown-body table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
}
.markdown-body th { background: var(--surface-alt); font-weight: 600; }
.markdown-body hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }
.markdown-body a { color: var(--accent-ink); font-weight: 500; }

/* Editor Form */
.editor-form { display: flex; flex-direction: column; gap: 14px; }
.editor-row { display: flex; gap: 12px; }
.editor-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1.2fr; gap: 12px; }
.editor-md-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.editor-mode-tabs { display: inline-flex; background: var(--surface-alt); padding: 3px; border-radius: 8px; }
.mode-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.mode-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.editor-preview {
  min-height: 240px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: var(--bg);
}
.editor-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.editor-footer-actions { display: flex; gap: 8px; align-items: center; }
.pin-check { display: inline-flex; align-items: center; gap: 7px; font-size: 0.88rem; cursor: pointer; }
.login-error { margin: 0; color: var(--danger); font-size: 0.86rem; font-weight: 600; }

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 16px 0;
  font-size: 0.84rem;
  color: var(--muted);
}
.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.footer-links { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.footer-links a { color: var(--accent-ink); text-decoration: none; font-weight: 600; }
.footer-links a:hover { text-decoration: underline; }
.health-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-alt);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
}
.health-dot { width: 8px; height: 8px; border-radius: 50%; background: #16a34a; }
.health-dot.offline { background: var(--danger); }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  background: #18181b;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

@media (max-width: 760px) {
  .editor-grid-3 { grid-template-columns: 1fr; }
  .cat-tabs { order: 3; width: 100%; overflow-x: auto; }
}
