:root {
  color: #242424;
  background: #f7f7f5;
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, select { font: inherit; }
button, .button { cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  border-right: 1px solid #dededb;
  background: #f2f2f0;
}

.sidebar-actions { display: flex; gap: 6px; padding: 12px 10px 8px; }
.sidebar-actions form { flex: none; }
.search {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid #cececa;
  border-radius: 4px;
  background: #fff;
  color: inherit;
}
.search:focus, .title-input:focus { outline: 1px solid #777; outline-offset: 1px; }
.new-note, .button {
  display: inline-block;
  padding: 6px 10px;
  border: 1px solid #aaa;
  border-radius: 4px;
  background: #ececea;
  color: #222;
  text-decoration: none;
  white-space: nowrap;
}
.new-note:hover, .button:hover { background: #e2e2df; }
.secondary { background: transparent; }
.danger { color: #642d2d; background: transparent; }
.save-status { min-width: 72px; color: #777; font-size: 12px; text-align: right; }
.save-status.error { color: #742f2f; }

.note-list { flex: 1; overflow-y: auto; padding: 3px 6px; }
.favorites { margin: 0 10px 6px; padding: 2px 0 6px; border-bottom: 1px solid #d4d4cf; }
#favorite-list { max-height: 25vh; overflow-y: auto; }
.favorite-link { display: flex; align-items: center; gap: 5px; padding: 2px 6px; border-radius: 4px; color: #242424; font-size: 12px; text-decoration: none; }
.favorite-badge { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; border-radius: 3px; background: var(--tag-color); color: #fff; font-size: 9px; font-weight: 700; }
.favorite-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.favorite-link:hover, .favorite-link.active { background: #e4e4e1; }
.favorite-link.active { font-weight: 600; }
.favorites-empty { margin: 4px 6px; color: #777; font-size: 11px; }
.library-links { display: flex; gap: 2px; margin: 0 10px 4px; padding: 3px; border: 1px solid #d4d4cf; border-radius: 5px; background: #e9e9e4; }
.library-links .folder-link { flex: 1; display: block; padding: 4px 6px; text-align: center; white-space: nowrap; font-size: 12px; }
.library-links .folder-link.active { background: #fff; box-shadow: 0 1px 2px #00000012; }
.folder-list { padding: 12px 10px 4px; max-height: 40vh; overflow: auto; }
.folder-list > .folder-link, .folder-list > .folder-branch > summary > .folder-link { color: #000080; font-weight: 700; }
.folder-branch > summary { display: flex; align-items: center; gap: 6px; list-style: none; }
.folder-branch > summary::-webkit-details-marker { display: none; }
.folder-branch > summary > .folder-link { flex: 1; min-width: 0; }
.folder-branch > summary::after { content: ''; flex: none; width: 7px; height: 7px; margin: 0 8px; border-right: 1.5px solid #65655e; border-bottom: 1.5px solid #65655e; transform: rotate(-45deg); }
.folder-branch[open] > summary::after { transform: rotate(45deg); }
.folder-link { display: inline-block; color: inherit; text-decoration: none; padding: 4px 6px; border-radius: 4px; overflow-wrap: anywhere; }
.folder-list > .folder-link, .folder-children > .folder-link { display: block; }
.folder-link:hover { background: #e6e6e1; }
.folder-link.active { background: #dededb; font-weight: 600; box-shadow: inset 3px 0 #77776d; }
.folder-children { padding-left: 16px; border-left: 1px solid #d7d7d2; margin-left: 6px; }
summary { cursor: pointer; }
.folder-controls { margin: 6px 16px; font-size: 12px; color: #55554e; }
.folder-controls form { margin: 10px 0; }
.folder-controls label { display: block; margin: 8px 0; }
.folder-controls input, .folder-controls select { width: 100%; padding: 4px; }
.folder-heading { margin-top: 10px; padding: 8px 16px 6px; border-top: 1px solid #deded8; overflow-wrap: anywhere; }
.folder-heading-path { margin-bottom: 3px; color: #65655e; font-size: 12px; }
.folder-heading h2 { margin: 0; color: #282822; font-size: 20px; font-weight: 700; line-height: 1.25; }
.folder-heading + .note-list { padding-top: 8px; }
.note-details { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.note-navigation { display: flex; gap: 4px; }
.note-navigation .button { padding: 3px 10px; }
.note-navigation [aria-disabled="true"] { opacity: .4; cursor: default; }
.note-folder { display: flex; align-items: center; gap: 8px; min-width: 0; color: #666; }
.note-folder select { min-width: 0; max-width: 100%; padding: 4px; }
.note-tags { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.tag-filters { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px; padding: 6px 12px; }
.tag-filters .tag-button { width: 100%; height: 25px; }
.tag-label { color: #666; margin-right: 3px; }
.tag-button { display: inline-flex; align-items: center; justify-content: center; width: 27px; height: 27px; padding: 0; border: 1px solid var(--tag-color); border-radius: 5px; background: var(--tag-tint); color: var(--tag-color); font-size: 12px; font-weight: 700; text-decoration: none; cursor: pointer; }
.tag-1 { --tag-color: #a82e34; --tag-tint: #fbeaec; }
.tag-2 { --tag-color: #a34b12; --tag-tint: #fff0e5; }
.tag-3 { --tag-color: #806000; --tag-tint: #fff6ce; }
.tag-4 { --tag-color: #52701b; --tag-tint: #f0f6dd; }
.tag-5 { --tag-color: #207044; --tag-tint: #e1f4e9; }
.tag-6 { --tag-color: #127476; --tag-tint: #dff4f4; }
.tag-7 { --tag-color: #245fb0; --tag-tint: #e5efff; }
.tag-8 { --tag-color: #5543aa; --tag-tint: #ece9fc; }
.tag-9 { --tag-color: #8b3ea0; --tag-tint: #f5e7fa; }
.tag-10 { --tag-color: #a33370; --tag-tint: #fbe6f0; }
.tag-choice { position: relative; display: inline-flex; }
.tag-choice input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.tag-choice input:checked + .tag-button, .tag-button[aria-pressed="true"] { color: #fff; background: var(--tag-color); box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--tag-color); }
.tag-choice input:focus-visible + .tag-button, .tag-button:focus-visible { outline: 2px solid #222; outline-offset: 3px; }
.tag-choice:hover .tag-button, .tag-button:hover { filter: brightness(.93); }
.note-list-item {
  display: block;
  padding: 8px;
  border-radius: 4px;
  color: inherit;
  text-decoration: none;
}
.note-list-item:hover, .note-list-item.active { background: #e4e4e1; }
.note-list-title, .note-list-preview { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-list-title { font-weight: 600; font-size: 13px; }
.note-list-preview { margin-top: 2px; color: #71716d; font-size: 12px; }
.empty-list { padding: 8px; color: #777; }
.logout { padding: 10px 14px; border-top: 1px solid #dededb; }
.link-button { padding: 0; border: 0; background: transparent; color: #666; }

.note-pane { min-width: 0; padding: 28px 5vw 60px; background: #fff; }
.note-header { display: flex; align-items: center; gap: 20px; max-width: 900px; margin: 0 auto 24px; }
.note-title, .title-input { flex: 1; min-width: 0; margin: 0; font-size: 22px; font-weight: 600; }
.title-input { padding: 5px 2px; border: 0; border-bottom: 1px solid #ccc; background: transparent; }
.note-actions { display: flex; align-items: center; gap: 7px; }
.note-actions form { margin: 0; }
.note-content, #edit-form { max-width: 900px; margin: 0 auto; }
.note-content { font-size: 15px; line-height: 1.65; overflow-wrap: anywhere; }
.note-content h1 { font-size: 1.8em; }
.note-content h2 { font-size: 1.45em; }
.note-content h3 { font-size: 1.2em; }
.note-content a { color: #34516f; }
.empty-state { margin-top: 30vh; text-align: center; color: #888; }

.editor-toolbar.ql-toolbar.ql-snow { border-color: #ccc; border-radius: 4px 4px 0 0; font-family: inherit; }
.editor.ql-container.ql-snow { min-height: 55vh; border-color: #ccc; border-radius: 0 0 4px 4px; font-family: inherit; font-size: 15px; }
.editor pre, .ql-editor .ql-code-block-container {
  margin: 8px 0;
  padding: 10px 12px;
  overflow-x: auto;
  border: 1px solid #dededb;
  border-radius: 3px;
  background: #f4f4f2;
  color: #292929;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: pre;
}
.ql-editor img { display: block; max-width: 100%; height: auto; margin: 12px 0; }
.ql-editor blockquote { border-left: 3px solid #ccc; margin: 8px 0; padding-left: 14px; color: #555; }
.ql-editor table { width: 100%; border-collapse: collapse; }
.ql-editor td, .ql-editor th { padding: 5px 7px; border: 1px solid #ccc; }
.ql-editor code:not(.ql-code-block) { padding: 1px 3px; border-radius: 3px; background: #eee; font-family: ui-monospace, monospace; }
.ql-toolbar button.ql-undo, .ql-toolbar button.ql-redo { font-size: 18px; line-height: 16px; color: #444; }
.manual-save { margin-top: 12px; }

.login-page { min-height: 100vh; display: grid; place-items: center; background: #f4f4f2; }
.login-card { width: min(320px, calc(100% - 32px)); padding: 28px; border: 1px solid #d8d8d4; border-radius: 5px; background: #fff; }
.login-card h1 { margin: 0 0 22px; font-size: 19px; font-weight: 600; }
.login-card label { display: block; margin: 12px 0; color: #555; font-size: 12px; }
.login-card input:not([type=hidden]) { display: block; width: 100%; margin-top: 4px; padding: 7px; border: 1px solid #bbb; border-radius: 3px; }
.login-error { color: #742f2f; }

@media (max-width: 700px) {
  .tag-filters { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .app-shell { grid-template-columns: 180px minmax(0, 1fr); }
  .sidebar-actions { flex-direction: column; }
  .sidebar-actions form, .new-note { width: 100%; }
  .note-pane { padding: 18px 16px 40px; }
  .note-header { align-items: flex-start; flex-direction: column; gap: 10px; }
  .note-actions { align-self: flex-end; }
}
