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

:root {
  --color-bg: #f7f7f8;
  --color-surface: #ffffff;
  --color-border: #e2e2e7;
  --color-text: #1a1a2e;
  --color-text-muted: #6b6b7b;
  --color-primary: #3b5bdb;
  --color-primary-hover: #2f4abf;
  --color-danger: #c92a2a;
  --color-danger-hover: #a61f1f;
  --color-selected-bg: #e8edff;
  --color-selected-text: #3b5bdb;
  --sidebar-width: 280px;
  --radius: 6px;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  height: 100dvh;
  overflow: hidden;
}

/* Layout */
.layout {
  display: flex;
  height: 100dvh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--color-border);
}

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text);
}

.search-wrap {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
}

.search-wrap input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  background: var(--color-bg);
  color: var(--color-text);
}

.search-wrap input:focus {
  border-color: var(--color-primary);
}

.notes-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.notes-list li {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
  transition: background 0.1s;
}

.notes-list li:hover {
  background: var(--color-bg);
}

.notes-list li.selected {
  background: var(--color-selected-bg);
}

.note-item-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notes-list li.selected .note-item-title {
  color: var(--color-selected-text);
}

.note-item-date {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 3px;
}

.empty-state {
  padding: 24px 16px;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-align: center;
}

.hidden {
  display: none !important;
}

/* Main content */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  display: flex;
  flex-direction: column;
}

/* Placeholder */
.placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: 1rem;
}

/* Note view */
.note-view {
  max-width: 760px;
  width: 100%;
}

.note-view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.note-title {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
  flex: 1;
}

.note-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  padding-top: 4px;
}

.note-meta {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: 24px;
}

/* Prose / rendered markdown */
.prose {
  font-size: 1rem;
  line-height: 1.7;
  color: var(--color-text);
}

.prose h1, .prose h2, .prose h3,
.prose h4, .prose h5, .prose h6 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-weight: 700;
  line-height: 1.3;
}

.prose h1 { font-size: 1.6em; }
.prose h2 { font-size: 1.35em; }
.prose h3 { font-size: 1.15em; }

.prose p {
  margin-bottom: 1em;
}

.prose ul, .prose ol {
  margin-left: 1.5em;
  margin-bottom: 1em;
}

.prose li {
  margin-bottom: 0.25em;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: #f0f0f5;
  border-radius: 3px;
  padding: 0.1em 0.35em;
}

.prose pre {
  background: #f0f0f5;
  border-radius: var(--radius);
  padding: 1em;
  overflow-x: auto;
  margin-bottom: 1em;
}

.prose pre code {
  background: none;
  padding: 0;
}

.prose blockquote {
  border-left: 3px solid var(--color-border);
  padding-left: 1em;
  color: var(--color-text-muted);
  margin-bottom: 1em;
}

.prose a {
  color: var(--color-primary);
}

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

/* Note form */
.note-form {
  max-width: 760px;
  width: 100%;
}

.form-heading {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.form-error {
  background: #fff5f5;
  border: 1px solid #ffa8a8;
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--color-danger);
  font-size: 0.875rem;
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
}

.form-group input,
.form-group textarea {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  outline: none;
  resize: vertical;
  background: var(--color-surface);
  color: var(--color-text);
}

.form-group textarea {
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--color-primary);
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

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

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-border);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}

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

/* Responsive: single-column on narrow screens */
@media (max-width: 640px) {
  body {
    overflow: auto;
  }

  .layout {
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    max-height: 50dvh;
  }

  .content {
    padding: 20px 16px;
  }
}
