:root {
  --bg: #f7f4ee;
  --panel: #fffdf8;
  --border: #e2ddd3;
  --text: #2b2b2b;
  --muted: #7a7062;
  --accent: #3a5a78;
  --accent-hover: #2c4459;
  --active-bg: #eae4d8;
  --warn: #b8860b;
  --warn-bg: #fff4d6;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* Баннер */
.banner {
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn);
  padding: 8px 16px;
  display: flex; align-items: center; gap: 12px;
  font-size: 13px; color: #6b4d00;
}
.banner-text { flex: 1; }
.banner button {
  border: 1px solid var(--warn);
  background: #fff; color: #6b4d00;
  padding: 4px 10px; font-size: 12px;
}

.app {
  display: grid;
  grid-template-columns: 250px 300px 1fr;
  height: calc(100vh - 0px);
}
.banner:not([style*="display:none"]) ~ .app { height: calc(100vh - 38px); }

/* Сайдбар */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  overflow-y: auto;
}
.sidebar h1 {
  font-family: Georgia, serif; font-size: 22px;
  margin: 0 0 4px; color: var(--accent);
}
.sidebar-status {
  font-size: 11px; color: var(--muted);
  padding: 4px 6px; border-radius: 4px;
  background: var(--active-bg);
}
#sections { list-style: none; padding: 0; margin: 0; }
#sections li {
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  gap: 6px; font-size: 14px;
}
#sections li:hover { background: var(--active-bg); }
#sections li.active { background: var(--accent); color: #fff; }
.sec-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sec-count {
  font-size: 11px; background: var(--active-bg);
  padding: 1px 6px; border-radius: 10px; color: var(--muted);
}
#sections li.active .sec-count { background: rgba(255,255,255,.25); color: #fff; }
.del-sec {
  border: none; background: transparent; cursor: pointer;
  font-size: 16px; padding: 0 4px; display: none; color: var(--muted);
}
#sections li:hover .del-sec { display: inline; }
#sections li.active .del-sec { color: rgba(255,255,255,.7); }
.del-sec:hover { color: #b4453b; }

.sidebar-group {
  display: flex; flex-direction: column; gap: 6px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.group-title {
  font-size: 11px; text-transform: uppercase;
  color: var(--muted); letter-spacing: .5px;
}

/* Кнопки */
button {
  font-family: inherit; font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--panel); color: var(--text);
  border-radius: 6px; cursor: pointer;
  transition: background .15s;
}
button:hover { background: var(--active-bg); }
#add-section, #add-note {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
#add-section:hover, #add-note:hover { background: var(--accent-hover); }

/* Список заметок */
.list {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.list-header {
  padding: 16px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.list-header h2 {
  margin: 0; font-family: Georgia, serif; font-size: 18px; color: var(--accent);
}
#notes { list-style: none; padding: 0; margin: 0; overflow-y: auto; flex: 1; }
#notes li {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
#notes li:hover { background: var(--active-bg); }
#notes li.active {
  background: var(--active-bg);
  border-left: 3px solid var(--accent);
  padding-left: 13px;
}
#notes li.empty {
  color: var(--muted); font-size: 13px;
  cursor: default; text-align: center; padding: 24px;
}
.note-title { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.note-preview {
  font-size: 12px; color: var(--muted); margin-bottom: 4px;
  line-height: 1.3; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.note-date { font-size: 11px; color: var(--muted); }

/* Редактор */
.editor {
  padding: 16px 24px;
  display: flex; flex-direction: column; overflow: hidden;
}
#note-title {
  font-family: Georgia, serif; font-size: 22px;
  padding: 8px 0;
  border: none; border-bottom: 1px solid var(--border);
  background: transparent; outline: none;
  color: var(--text); width: 100%;
}
.toolbar {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  align-items: center;
}
.toolbar button { padding: 4px 10px; font-size: 13px; }
.toolbar select {
  padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px;
  font-family: inherit; background: var(--panel); color: var(--text); font-size: 13px;
}
.backup-version-btn {
  margin-top: 8px;
  padding: 6px 10px; font-size: 12px;
  background: var(--warn-bg);
  border: 1px solid var(--warn);
  color: #6b4d00;
}
#editor {
  flex: 1; overflow-y: auto;
  padding: 16px; margin-top: 8px;
  outline: none;
  font-family: Georgia, serif; font-size: 15px; line-height: 1.6;
  background: var(--panel);
  border-radius: 8px; border: 1px solid var(--border);
  min-height: 200px;
}
#editor:empty::before { content: 'Начните писать…'; color: var(--muted); }
#editor h1 { font-size: 24px; margin: 12px 0 8px; }
#editor h2 { font-size: 19px; margin: 10px 0 6px; }
#editor h3 { font-size: 16px; margin: 8px 0 4px; }
#editor blockquote {
  border-left: 3px solid var(--accent);
  margin: 8px 0; padding-left: 12px;
  color: var(--muted); font-style: italic;
}
#editor table { border-collapse: collapse; margin: 8px 0; width: 100%; }
#editor td, #editor th {
  border: 1px solid var(--border); padding: 6px 8px;
  min-width: 40px; vertical-align: top;
}
#editor ul, #editor ol { padding-left: 24px; }

.reminder-bar {
  padding: 10px 0 0;
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  font-size: 13px; color: var(--muted);
}
.reminder-bar input[type="datetime-local"] {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  font-family: inherit; font-size: 13px;
}
#save-status { margin-left: auto; font-size: 12px; color: var(--muted); }

/* Модалки */
.modal {
  position: fixed; inset: 0;
  background: rgba(43,43,43,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal-content {
  background: var(--panel);
  border-radius: 10px;
  padding: 20px;
  max-width: 460px; width: 100%;
  max-height: 80vh; overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.modal-content h3 {
  margin: 0 0 12px;
  font-family: Georgia, serif; color: var(--accent);
}
.modal-actions {
  display: flex; flex-direction: column; gap: 8px;
  margin: 12px 0;
}
.modal-actions.column { flex-direction: column; }
.modal-actions button { text-align: left; padding: 10px 14px; }
.modal-actions small { color: var(--muted); font-size: 12px; }
.modal-close {
  margin-top: 12px;
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); width: 100%;
}
#snapshots-list { max-height: 50vh; overflow-y: auto; }
.snapshot-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border); gap: 8px;
  font-size: 13px;
}
.snapshot-item button { padding: 4px 8px; font-size: 12px; }

/* Адаптив */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .sidebar, .list, .editor {
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .editor { min-height: 60vh; }
}