/* ===== Notesnook Lite ===== */
:root {
  --bg: #1d1d26;
  --bg2: #232330;
  --bg3: #2b2b3a;
  --panel: #262633;
  --border: #353548;
  --text: #e9e9f0;
  --text2: #9d9db0;
  --accent: #ffd11a;
  --accent-ink: #1d1d26;
  --primary: #67b0f4;
  --danger: #e05a5a;
  --radius: 10px;
}
html[data-theme="light"] {
  --bg: #f4f4f8;
  --bg2: #ffffff;
  --bg3: #ececf2;
  --panel: #ffffff;
  --border: #dcdce6;
  --text: #23232d;
  --text2: #6d6d80;
  --accent: #f5c400;
  --primary: #2e7cd6;
  --danger: #d24a4a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); }
.hidden { display: none !important; }

/* ---- Layout ---- */
.app {
  display: grid;
  grid-template-columns: 240px 320px 1fr;
  height: 100dvh;
}

/* ---- Sidebar ---- */
.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  gap: 8px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; padding: 4px 8px 14px; }
.brand em { color: var(--accent); font-style: normal; }
.brand-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px; color: var(--text2); text-align: left; font-size: 14px;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--bg3); color: var(--text); font-weight: 600; }
.count { font-size: 12px; color: var(--text2); }
.section-title {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text2); padding: 14px 10px 4px;
}
.nb-item { display: flex; align-items: center; gap: 8px; }
.nb-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.tag-chip-nav { font-size: 12px; background: var(--bg3); border-radius: 6px; padding: 2px 8px; }
.sidebar-footer { margin-top: auto; padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.e2e-badge { font-size: 11px; color: var(--text2); text-align: center; padding: 4px; }

/* ---- Buttons ---- */
.btn { padding: 8px 14px; border-radius: 8px; background: var(--bg3); font-size: 14px; }
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--primary); color: #fff; font-weight: 600; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn.full { width: 100%; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row.end { justify-content: flex-end; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; display: inline-flex;
  align-items: center; justify-content: center; color: var(--text2); font-size: 13px; flex: none;
}
.icon-btn:hover { background: var(--bg3); color: var(--text); }

/* ---- Note list ---- */
.notelist {
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-width: 0;
}
.notelist-header { display: flex; gap: 8px; padding: 12px; align-items: center; }
#search {
  flex: 1; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; font-size: 14px; outline: none; min-width: 0;
}
#search:focus { border-color: var(--primary); }
.view-title { padding: 4px 16px 8px; font-size: 20px; font-weight: 700; }
.notes { overflow-y: auto; flex: 1; padding: 4px 8px 24px; display: flex; flex-direction: column; gap: 6px; }
.note-card {
  background: var(--bg2); border: 1px solid var(--border); border-left: 3px solid transparent;
  border-radius: var(--radius); padding: 10px 12px; cursor: pointer;
}
.note-card:hover { border-color: var(--primary); }
.note-card.active { border-color: var(--primary); }
.note-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; display: flex; gap: 6px; align-items: center; min-width: 0; }
.note-card h3 span.ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-card p { font-size: 12.5px; color: var(--text2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.note-card .meta { font-size: 11px; color: var(--text2); margin-top: 6px; display: flex; gap: 8px; align-items: center; }
.note-card .badges { margin-left: auto; display: flex; gap: 4px; font-size: 11px; }
.note-card.color-red { border-left-color: #e05a5a; }
.note-card.color-orange { border-left-color: #e5924a; }
.note-card.color-yellow { border-left-color: var(--accent); }
.note-card.color-green { border-left-color: #5fc26d; }
.note-card.color-blue { border-left-color: var(--primary); }
.note-card.color-purple { border-left-color: #a06ee0; }
.empty-list { color: var(--text2); text-align: center; padding: 40px 10px; font-size: 14px; }

/* ---- Editor ---- */
.editor { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.editor-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--text2); }
.empty-illustration { font-size: 44px; }
.editor-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.editor-header { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.editor-tools { display: flex; gap: 2px; flex-wrap: wrap; }
.editor-tools .icon-btn.active { background: var(--bg3); color: var(--accent); }
.editor-actions { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.color-select, .notebook-select {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 6px; font-size: 12.5px; outline: none; max-width: 130px;
}
.editor-meta {
  display: flex; align-items: center; gap: 6px; padding: 8px 16px 0; flex-wrap: wrap;
}
.editor-meta .tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-chip {
  font-size: 12px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 6px; display: inline-flex; gap: 5px; align-items: center;
}
.tag-chip button { color: var(--text2); font-size: 11px; }
#tag-input {
  background: transparent; border: none; outline: none; font-size: 12px;
  color: var(--text2); width: 90px;
}
.save-state { margin-left: auto; font-size: 11px; color: var(--text2); }
#note-title {
  background: transparent; border: none; outline: none;
  font-size: 26px; font-weight: 700; padding: 14px 16px 6px; width: 100%;
}
/* ---- TipTap / ProseMirror editor, themed ---- */
.editor-container { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
#editor-container { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#editor-container .tiptap {
  flex: 1; outline: none; font-size: 15.5px; line-height: 1.65;
  padding: 6px 18px 40px; color: var(--text); min-height: 160px;
  font-family: inherit; caret-color: var(--accent);
}
#editor-container .tiptap p.is-editor-empty:first-child::before {
  content: attr(data-placeholder); color: var(--text2);
  float: left; height: 0; pointer-events: none;
}
#editor-container .tiptap h1 { font-size: 24px; margin: 14px 0 6px; line-height: 1.3; }
#editor-container .tiptap h2 { font-size: 19px; margin: 12px 0 5px; line-height: 1.35; }
#editor-container .tiptap p { margin: 4px 0; }
#editor-container .tiptap blockquote {
  border-left: 3px solid var(--accent); padding-left: 12px; color: var(--text2); margin: 8px 0;
}
#editor-container .tiptap ul, #editor-container .tiptap ol { padding-left: 26px; margin: 6px 0; }
#editor-container .tiptap code {
  background: var(--bg3); border-radius: 4px; padding: 1px 5px; font-size: 13.5px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
#editor-container .tiptap pre {
  background: var(--bg3); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 8px 0;
}
#editor-container .tiptap pre code { background: none; padding: 0; }
#editor-container .tiptap a { color: var(--primary); }
#editor-container .tiptap s { color: var(--text2); }
.editor-footer { padding: 6px 16px 10px; font-size: 11px; color: var(--text2); }

/* ---- Modals ---- */
.modal {
  background: var(--bg2); color: var(--text); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px; width: min(440px, calc(100vw - 32px));
}
.modal::backdrop { background: rgba(0,0,0,.55); }
.modal h2 { font-size: 17px; margin-bottom: 14px; }
.modal input[type="text"], .modal input[type="password"], .modal select {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; font-size: 14px; outline: none;
}
.modal input:focus { border-color: var(--primary); }
.setting-row { padding: 12px 0; border-top: 1px solid var(--border); }
.setting-row:first-of-type { border-top: none; }
.setting-row > label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.setting-row select { width: auto; }
.vault-form { display: flex; gap: 8px; margin-top: 8px; }
.hint { font-size: 12px; color: var(--text2); margin-top: 8px; line-height: 1.5; }
.about { font-size: 12.5px; color: var(--text2); }
.about a { color: var(--primary); }
.color-picker { display: flex; gap: 10px; margin: 12px 0 4px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; }
.swatch.active { border-color: var(--text); }
.swatch.blue { background: var(--primary); }
.swatch.red { background: #e05a5a; }
.swatch.green { background: #5fc26d; }
.swatch.purple { background: #a06ee0; }
.swatch.orange { background: #e5924a; }

/* ---- Lock screen ---- */
.lockscreen {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.lock-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 16px;
  padding: 34px 30px; width: min(380px, 100%); text-align: center; display: flex; flex-direction: column; gap: 12px;
}
.lock-logo { font-size: 40px; }
.lock-card h1 { font-size: 20px; }
.lock-card p { font-size: 13px; color: var(--text2); }
.lock-card input {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 15px; outline: none; text-align: center;
}
.error { color: var(--danger); font-size: 13px; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 10px; font-size: 13.5px; z-index: 60;
  box-shadow: 0 6px 24px rgba(0,0,0,.35);
}

/* ---- Responsive / PWA ---- */
.mobile-only { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .notelist { border-right: none; }
  .mobile-only { display: inline-flex; }
  body.show-editor .notelist { display: none; }
  body.show-editor .sidebar { display: none; }
  body:not(.show-editor) .editor { display: none; }
  body:not(.show-editor) .notelist { width: 100%; }
}
@media (min-width: 901px) {
  #menu-btn, #back-btn { display: none; }
}
