:root {
  --bg: #f3f6fb;
  --bg-soft: #edf3fa;
  --panel: rgba(255,255,255,0.82);
  --panel-strong: #ffffff;
  --sidebar: #f8fafc;
  --line: #e3eaf4;
  --ink: #1d2433;
  --muted: #6c7a8d;
  --green: #1d8b69;
  --green-soft: #dff7ee;
  --orange: #f7a85c;
  --shadow: 0 20px 55px rgba(30, 41, 59, 0.12);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: 'DM Sans', sans-serif;
  background:
    radial-gradient(circle at top left, rgba(141, 197, 255, 0.22), transparent 28%),
    linear-gradient(180deg, #f8fafc 0%, #eef4fa 100%);
  color: var(--ink);
}

body {
  min-height: 100vh;
}

button, input, textarea {
  font: inherit;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  padding: 22px;
  gap: 20px;
}

.sidebar {
  width: 290px;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(227,234,244,0.9);
  backdrop-filter: blur(10px);
  border-radius: 26px;
  padding: 24px 18px 18px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: -0.04em;
  margin: 4px 12px 22px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 11px 11px 11px 4px;
  background: linear-gradient(135deg, #1f2532, #2d3d4d);
  color: #dffaf0;
  font-family: 'Fraunces', serif;
  font-size: 1.45rem;
}

.new-note {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 18px;
  border-radius: 14px;
  color: white;
  text-decoration: none;
  background: linear-gradient(135deg, #1d2433, #24364d);
  font-weight: 700;
  box-shadow: 0 14px 28px rgba(30,41,59,0.18);
  transition: transform .18s ease, box-shadow .18s ease;
}

.new-note:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 32px rgba(30,41,59,0.2);
}

.new-note span {
  font-size: 1.7rem;
  line-height: 1;
}

.new-note.small {
  margin-top: 16px;
  padding: 10px 14px;
  font-size: 0.84rem;
}

.nav-list, .category-list {
  display: grid;
  gap: 8px;
}

.nav-item, .category-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 12px;
  padding: 10px 12px;
  color: #536173;
  text-decoration: none;
  font-weight: 600;
  transition: background .18s ease, transform .18s ease, color .18s ease;
}

.nav-item:hover, .category-item:hover {
  background: rgba(38, 59, 83, 0.04);
  transform: translateX(2px);
}

.nav-item.active, .category-item.active {
  background: var(--green-soft);
  color: var(--green);
}

.nav-item strong, .category-item strong {
  margin-left: auto;
  color: #99a6b6;
  font-size: 0.76rem;
}

.nav-item.active strong, .category-item.active strong {
  color: var(--green);
}

.nav-icon {
  width: 20px;
  text-align: center;
  font-size: 1.1rem;
}

.nav-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 26px 8px 8px;
  color: #94a1b0;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
}

.nav-heading a {
  color: #596a7d;
  font-size: 1.55rem;
  text-decoration: none;
}

.category-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8ad4b5, #2c9f7a);
  box-shadow: 0 0 0 4px rgba(29,139,105,0.08);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px 0;
  border-top: 1px solid var(--line);
  color: var(--ink);
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #afc5ff, #edf2ff);
  font-weight: 800;
}

.sidebar-footer b {
  display: block;
  font-size: 0.94rem;
}

.sidebar-footer small {
  color: var(--muted);
}

.more {
  margin-left: auto;
  color: #8d99a8;
  font-size: 1.2rem;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(227,234,244,0.9);
  backdrop-filter: blur(10px);
  border-radius: 22px;
  padding: 18px 22px;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 2vw, 2.5rem);
  letter-spacing: -0.05em;
}

.search {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: min(430px, 48vw);
  background: rgba(246,248,252,0.95);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
}

.search span {
  color: var(--muted);
  font-size: 1.25rem;
}

.search input {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 0.98rem;
}

.search kbd {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 7px;
  color: var(--muted);
  background: rgba(255,255,255,0.7);
  font-size: 0.72rem;
}

.flash {
  border-radius: 14px;
  padding: 11px 14px;
  border: 1px solid transparent;
  font-weight: 600;
}

.flash.success {
  background: rgba(36, 193, 143, 0.08);
  border-color: rgba(36, 193, 143, 0.2);
  color: var(--green);
}

.flash.error {
  background: rgba(255, 130, 92, 0.08);
  border-color: rgba(255, 130, 92, 0.2);
  color: #c96238;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
  gap: 20px;
  min-height: 0;
  flex: 1;
}

.notes-column, .editor-panel {
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(227,234,244,0.9);
  backdrop-filter: blur(12px);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.notes-column {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.section-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.section-toolbar b {
  font-size: 1.02rem;
}

.muted {
  color: var(--muted);
  font-size: 0.8rem;
  margin-left: 8px;
}

.sort-link {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.8rem;
}

.notes-list {
  padding: 16px;
  display: grid;
  gap: 12px;
  overflow: auto;
}

.note-card {
  display: block;
  text-decoration: none;
  color: var(--ink);
  background: rgba(246,248,252,0.76);
  border: 1px solid rgba(227,234,244,0.9);
  border-radius: 16px;
  padding: 16px 16px 14px;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.note-card:hover {
  transform: translateY(-2px);
  border-color: rgba(29,139,105,0.28);
  box-shadow: 0 12px 26px rgba(29, 39, 52, 0.06);
}

.note-card.selected {
  border-color: rgba(29,139,105,0.45);
  background: rgba(223,247,238,0.8);
}

.note-card.highlight {
  animation: highlightPulse 1.3s ease;
}

@keyframes highlightPulse {
  0%   { box-shadow: 0 0 0 rgba(29,139,105,0.1); transform: scale(1); }
  30%  { box-shadow: 0 0 0 14px rgba(29,139,105,0.12); transform: scale(1.01); }
  100% { box-shadow: 0 0 0 rgba(29,139,105,0.02); transform: scale(1); }
}

.note-card-top,
.note-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.note-card-top {
  margin-bottom: 8px;
}

.note-category {
  font-size: 0.72rem;
  color: var(--green);
  background: rgba(29,139,105,0.12);
  padding: 5px 8px;
  border-radius: 999px;
  font-weight: 700;
}

.star {
  color: #d9dfe8;
  font-size: 1.1rem;
}

.star.favorite {
  color: #f7b84b;
}

.note-card h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
  line-height: 1.18;
}

.note-card p {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-meta {
  color: var(--muted);
  font-size: 0.72rem;
}

.tag-preview {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(29,157,163,0.08);
  color: #17788b;
}

.empty-state {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 34px 20px;
  border: 1px dashed rgba(108,122,141,0.35);
  border-radius: 18px;
  background: rgba(246,248,252,0.9);
}

.empty-state span {
  font-size: 3rem;
  color: rgba(29,139,105,0.4);
}

.empty-state h2 {
  margin: 12px 0 6px;
  font-size: 1.5rem;
}

.empty-state p {
  margin: 0 0 2px;
  color: var(--muted);
}

.editor-panel {
  padding: 18px;
}

.editor-panel:not(.visible) {
  display: none;
}

.editor-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100%;
}

.editor-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.save-status {
  font-weight: 700;
  color: var(--green);
  font-size: 0.9rem;
}

.save-status[data-state="saving"] { color: #c47a18; }
.save-status[data-state="error"] { color: #c95252; }
.save-status[data-state="pending"] { color: #66768a; }

.last-saved {
  color: var(--muted);
  font-size: 0.8rem;
}

.editor-actions > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(246,248,252,0.8);
  color: var(--ink);
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform .18s ease, background .18s ease, border-color .18s ease;
}

.icon-button:hover {
  transform: translateY(-1px);
  background: rgba(29,139,105,0.06);
}

.icon-button.favorite {
  background: rgba(247,184,75,0.12);
  color: #d58f1d;
  border-color: rgba(247,184,75,0.25);
}

.icon-button.danger {
  color: #d65757;
}

.title-input,
.editor-details input,
.content-input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(246,248,252,0.74);
  border-radius: 14px;
  color: var(--ink);
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}

.title-input:focus,
.editor-details input:focus,
.content-input:focus {
  border-color: rgba(29,139,105,0.5);
  box-shadow: 0 0 0 4px rgba(29,139,105,0.08);
}

.title-input {
  padding: 16px 16px;
  font-size: clamp(1.2rem, 2vw, 1.8rem);
  font-weight: 700;
  letter-spacing: -0.04em;
}

.editor-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.editor-details label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.editor-details input {
  padding: 12px 14px;
  font-size: 0.96rem;
}

.content-input {
  min-height: 360px;
  resize: vertical;
  padding: 16px 18px;
  line-height: 1.7;
  font-size: 1rem;
}

.editor-mode-switch {
  display: inline-flex;
  align-self: flex-start;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(246,248,252,0.8);
}

.editor-mode {
  border: 0;
  border-radius: 8px;
  padding: 7px 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
}

.editor-mode.active {
  background: var(--panel-strong);
  color: var(--green);
  box-shadow: 0 2px 8px rgba(30, 41, 59, 0.08);
}

.markdown-preview {
  min-height: 360px;
  overflow: auto;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(246,248,252,0.74);
  line-height: 1.7;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3 {
  margin: 0 0 10px;
  line-height: 1.25;
}

.markdown-preview p {
  margin: 0 0 12px;
}

.markdown-preview code {
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(29,139,105,0.1);
  color: var(--green);
  font-family: monospace;
}

.markdown-preview pre {
  overflow: auto;
  padding: 14px;
  border-radius: 10px;
  background: #1d2433;
  color: #e7edf5;
}

.markdown-preview pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.markdown-preview a {
  color: var(--green);
  font-weight: 700;
}

.preview-empty {
  color: var(--muted);
}

.editor-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--line);
}

.editor-placeholder {
  min-height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 32px 18px;
  color: var(--muted);
}

.placeholder-icon {
  display: grid;
  place-items: center;
  width: 70px;
  height: 70px;
  margin: 0 auto 10px;
  background: rgba(29,139,105,0.08);
  border-radius: 18px;
  color: var(--green);
  font-size: 2rem;
}

.editor-placeholder h2 {
  margin: 0 0 10px;
  color: var(--ink);
}

.text-link {
  color: var(--green);
  text-decoration: none;
  font-weight: 700;
}

.command-palette[hidden] { display: none; }
.command-palette { position: fixed; inset: 0; z-index: 20; display: grid; place-items: start center; padding-top: 12vh; }
.command-palette-backdrop { position: absolute; inset: 0; background: rgba(29,36,51,0.36); backdrop-filter: blur(5px); }
.command-palette-panel { position: relative; width: min(560px, calc(100vw - 32px)); padding: 18px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel-strong); box-shadow: 0 24px 70px rgba(29,36,51,0.25); }
.command-palette-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-weight: 800; }
.palette-input { width: 100%; padding: 14px; border: 1px solid var(--line); border-radius: 12px; outline: none; background: var(--bg-soft); color: var(--ink); }
.palette-input:focus { border-color: rgba(29,139,105,0.5); box-shadow: 0 0 0 4px rgba(29,139,105,0.08); }
.palette-hint { margin: 10px 0 0; color: var(--muted); font-size: 0.8rem; }

@media (max-width: 980px) {
  .app-shell {
    flex-direction: column;
    padding: 16px;
  }

  .sidebar {
    width: 100%;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .search {
    min-width: 0;
    width: 100%;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
}
