:root {
  color-scheme: light;
  --bg: #f3f5ef; --paper: #fff; --edge: #dce3db; --ink: #172b26; --soft: #52635b;
  --sidebar: #172b26; --side-text: #eaf3ea; --side-muted: #b8cdbf;
  --accent: #c0eeac; --accent-ink: #182b21; --hover: #e9efe6; --ring: #36734b;
  --danger: #a12e38; --waiting: #826214; --good: #287044;
  --shadow: 0 2px 3px #14272008, 0 8px 25px #14272008;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151d1a; --paper: #202c26; --edge: #37473e; --ink: #eff8ee; --soft: #b2c4b8;
  --sidebar: #101914; --side-text: #eaf3ea; --side-muted: #b8cdbf;
  --hover: #2b3b32; --ring: #a9e3a8; --danger: #ffa9af; --waiting: #e9ca79; --good: #9cdda8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #151d1a; --paper: #202c26; --edge: #37473e; --ink: #eff8ee; --soft: #b2c4b8;
    --sidebar: #101914; --side-text: #eaf3ea; --side-muted: #b8cdbf;
    --hover: #2b3b32; --ring: #a9e3a8; --danger: #ffa9af; --waiting: #e9ca79; --good: #9cdda8;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); min-width: 280px; }
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; color: inherit; }
button:disabled { opacity: .43; cursor: default; }
a { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, label:has(input:focus-visible) {
  outline: 2px solid var(--ring); outline-offset: 3px;
}
main:focus { outline: none; }
svg { inline-size: 1.25rem; block-size: 1.25rem; flex: none; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(2.15rem, 3.9vw, 3.85rem); line-height: 1.04; letter-spacing: -.06em; font-weight: 720; overflow-wrap: anywhere; }
h2 { font-size: 1.2rem; line-height: 1.25; letter-spacing: -.025em; overflow-wrap: anywhere; }
.loading { padding: 2rem; }
.layout { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100dvh; }
.sidebar { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; padding: 22px 15px 16px; background: var(--sidebar); color: var(--side-text); z-index: 3; }
.sidebar nav { display: grid; gap: 3px; }
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; font-weight: 730; font-size: 1.27rem; letter-spacing: -.045em; }
.brand svg { box-sizing: content-box; padding: 9px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); }
.sidebar-heading { display: flex; justify-content: space-between; align-items: center; gap: 5px; margin: 0 7px 25px; }
.drawer-close { display: none; }
.nav-link { display: flex; width: 100%; gap: 11px; align-items: center; text-align: left; min-height: 46px; padding: 8px 10px; text-decoration: none; border: 0; border-radius: 9px; background: transparent; font-size: .92rem; color: var(--side-text); }
.nav-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-link svg { color: var(--side-muted); }
.nav-link:hover, .sidebar button:hover { background: #ffffff12; }
.nav-link[aria-current] { color: var(--accent-ink); background: var(--accent); font-weight: 680; }
.nav-link[aria-current] svg { color: inherit; }
.sidebar :focus-visible { outline-color: var(--accent); }
.category-header { display: flex; align-items: center; justify-content: space-between; padding-left: 10px; margin-top: 21px; border-top: 1px solid #ffffff24; color: var(--side-muted); font-weight: 660; font-size: .88rem; }
.category-nav { overflow-y: auto; align-content: start; min-height: 0; }
.add-category { color: var(--side-muted); }
.sidebar-footer { margin-top: auto; padding-top: 10px; }
.workspace { min-width: 0; }
.topbar { min-height: 76px; padding: 10px clamp(22px, 4vw, 66px); display: flex; align-items: center; justify-content: flex-end; border-bottom: 1px solid var(--edge); }
.mobile-brand, .scrim { display: none; }
.sync { background: var(--paper); border: 1px solid var(--edge); border-radius: 999px; padding: 8px 12px; min-height: 44px; display: inline-flex; align-items: center; gap: 8px; color: var(--soft); font-size: .86rem; font-weight: 620; }
.sync:hover { background: var(--hover); }
.sync i { inline-size: 8px; block-size: 8px; border-radius: 50%; background: var(--good); }
.sync.pending i { background: var(--waiting); }
.sync.attention i { background: var(--danger); }
#main { padding: clamp(28px, 4vw, 65px); max-width: 1840px; margin: 0 auto; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
.page-heading > div:first-child { min-width: 0; }
.page-heading p { color: var(--soft); margin-top: 9px; }
.primary, .quiet, .solid, .menu-action, .icon-button, .completed-toggle { display: inline-flex; justify-content: center; align-items: center; gap: 8px; min-height: 46px; border: 1px solid transparent; border-radius: 10px; padding: 8px 13px; font-size: .94rem; font-weight: 680; background: transparent; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: #6ea26b66; flex-shrink: 0; }
.primary:hover { background: #aee198; }
.icon-button { padding: 8px; width: 46px; flex: none; }
.icon-button:hover, .quiet:hover, .completed-toggle:hover, .menu-action:hover { background: var(--hover); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 16px; }
.card { display: flex; flex-direction: column; background: var(--paper); border: 1px solid var(--edge); padding: 19px; min-height: 184px; border-radius: 15px; box-shadow: var(--shadow); text-decoration: none; }
.card:hover { border-color: var(--ring); }
.card-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 12px; }
.pin { color: var(--good); }
.pin svg { inline-size: 1rem; block-size: 1rem; }
.preview { display: grid; grid-template-columns: minmax(0, 1fr); gap: 7px; color: var(--soft); font-size: .93rem; }
.preview-row { display: flex; align-items: center; gap: 8px; }
.preview-row i { display: grid; place-items: center; width: 14px; height: 14px; border: 1px solid var(--soft); border-radius: 4px; flex: none; }
.preview-row i svg { width: 11px; height: 11px; }
.preview-row span { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.card-footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--soft); font-size: .88rem; padding-top: 12px; margin-top: auto; }
.card-footer span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-footer span:last-child { white-space: nowrap; }
.empty { padding: clamp(28px, 6vw, 70px) 15px; border: 1px dashed var(--edge); border-radius: 15px; color: var(--soft); text-align: center; }
.empty svg { width: 32px; height: 32px; margin-bottom: 10px; }
.empty p { margin-top: 8px; }
.empty a { display: inline-block; padding: 12px; }
.detail { max-width: 900px; margin-inline: auto; }
.breadcrumb { display: inline-flex; align-items: center; min-height: 44px; color: var(--soft); font-size: .93rem; margin-bottom: 9px; text-underline-offset: 4px; }
.heading-actions { display: flex; gap: 5px; }
.heading-actions button, .mobile-brand button { background: var(--paper); border-color: var(--edge); }
.heading-actions button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.sheet { background: var(--paper); border: 1px solid var(--edge); border-radius: 16px; box-shadow: var(--shadow); }
.composer { display: flex; gap: 8px; padding: 14px; border-bottom: 1px solid var(--edge); }
input:not([type="checkbox"]), select { display: block; min-width: 0; width: 100%; border: 1px solid var(--edge); padding: 10px 12px; min-height: 46px; border-radius: 9px; background: var(--bg); color: var(--ink); }
select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--soft) 50%), linear-gradient(135deg, var(--soft) 50%, transparent 50%); background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.items { padding: 0; margin: 0; list-style: none; }
.item { display: flex; align-items: center; padding-right: 9px; border-bottom: 1px solid var(--edge); min-height: 60px; }
.items:last-child .item:last-child { border-bottom: 0; }
.item-label { display: flex; align-items: center; align-self: stretch; gap: 14px; min-width: 0; flex: 1; cursor: pointer; padding: 12px 9px 12px 17px; }
.item-label span { overflow-wrap: anywhere; }
.item-label:hover { background: var(--hover); }
input[type="checkbox"] { width: 24px; height: 24px; margin: 0; flex: none; accent-color: var(--good); cursor: pointer; }
.done .item-label span, .done.preview-row span { text-decoration: line-through; color: var(--soft); }
.items-empty { padding: 18px; color: var(--soft); }
.completed { border-top: 1px solid var(--edge); }
.completed-toggle { margin: 4px; justify-content: flex-start; color: var(--soft); }
.chevron { width: 8px; height: 8px; border-right: 2px solid; border-bottom: 2px solid; transform: rotate(-45deg); }
[aria-expanded="true"] > .chevron { transform: rotate(45deg); }
.count { font-size: .86rem; padding: 2px 7px; border-radius: 10px; background: var(--hover); }
.move-controls, .category-actions { display: flex; align-items: center; gap: 2px; }
.move-controls button { padding-inline: 8px; }
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-panel { width: min(100%, 410px); padding: clamp(23px, 5vw, 36px); border: 1px solid var(--edge); background: var(--paper); box-shadow: var(--shadow); border-radius: 19px; }
.login-panel h1 { margin: 25px 0 20px; font-size: 2.45rem; }
.login form, dialog form { display: grid; gap: 13px; }
.login label, dialog label { display: grid; gap: 6px; font-weight: 600; font-size: .94rem; }
.login form button { margin-top: 6px; }
.form-error { color: var(--danger); margin-bottom: 10px; overflow-wrap: anywhere; }
dialog { width: min(520px, calc(100% - 24px)); max-height: calc(100dvh - 24px); margin: auto; border: 1px solid var(--edge); background: var(--paper); color: var(--ink); border-radius: 16px; padding: 0; box-shadow: 0 24px 70px #0005; }
dialog::backdrop { background: #101b16aa; }
.dialog-body { padding: 18px; overflow-wrap: anywhere; }
.dialog-heading, .dialog-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dialog-heading { margin-bottom: 12px; }
.dialog-heading h2 { font-size: 1.42rem; }
.dialog-actions { justify-content: flex-end; flex-wrap: wrap; margin-top: 10px; }
.dialog-error:not([hidden]) { margin-top: 10px; }
dialog label.inline { display: flex; min-height: 44px; align-items: center; gap: 9px; }
.menu-actions { display: grid; gap: 2px; }
.menu-action { justify-content: flex-start; }
.danger { color: var(--danger); }
.solid { border-color: currentColor; }
.managed-category, .failed { padding: 9px 0; border-bottom: 1px solid var(--edge); }
.manage-categories:not(:empty) { margin-bottom: 14px; }
.category-actions { flex-wrap: wrap; }
.failed + button { margin-top: 10px; }
@media (max-width: 760px) {
  .layout { display: block; }
  .sidebar { display: none; position: fixed; inset: 0 auto 0 0; width: min(290px, 86vw); padding-top: max(15px, env(safe-area-inset-top)); }
  .sidebar.menu-open { display: flex; }
  .drawer-close { display: block; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 2; border: 0; background: #10201899; }
  .topbar { justify-content: space-between; min-height: 62px; padding: max(6px, env(safe-area-inset-top)) 12px 6px; gap: 6px; }
  .mobile-brand { display: flex; align-items: center; gap: 8px; font-weight: 730; letter-spacing: -.035em; white-space: nowrap; }
  .sync { padding-inline: 8px; font-size: .8rem; }
  #main { padding: 19px 12px max(26px, env(safe-area-inset-bottom)); }
  .page-heading { margin-bottom: 17px; align-items: center; gap: 8px; }
  .page-heading .primary { padding-inline: 9px; }
  .cards { gap: 10px; }
  .card { min-height: 145px; padding: 14px; }
  .breadcrumb { margin: -7px 0 5px; }
  .heading-actions { gap: 3px; }
  .sheet { display: flex; flex-direction: column; }
  .composer { order: 2; position: sticky; bottom: 0; background: var(--paper); z-index: 1; padding: 9px; padding-bottom: max(9px, env(safe-area-inset-bottom)); border: 0; border-top: 1px solid var(--edge); border-radius: 0 0 15px 15px; }
  .item { min-height: 64px; padding-right: 4px; }
  .item-label { padding-left: 12px; gap: 11px; }
  .item-label input { width: 27px; height: 27px; }
  .move-controls { gap: 0; }
  .move-controls button { padding-inline: 5px; font-size: .85rem; }
}
@media (max-width: 350px) {
  .mobile-brand span { display: none; }
  .composer button { padding-inline: 8px; }
}

.new-types { display: grid; gap: 8px; }
.type-choice { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; align-items: center; padding: 12px; text-align: left; background: var(--bg); border: 1px solid var(--edge); border-radius: 10px; }
.type-choice:hover { background: var(--hover); border-color: var(--ring); }
.type-choice svg { grid-row: span 2; }
.type-choice span { color: var(--soft); font-size: .9rem; }
.note-preview { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; overflow-wrap: anywhere; }
.note-nav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.note-nav .breadcrumb { margin: 0; }
.note-sheet { display: block; }
.note-title-label { display: grid; gap: 5px; padding: 15px 20px; font-size: .9rem; font-weight: 650; color: var(--soft); }
.note-sheet .note-title { border: 0; background: transparent; padding: 4px 0; font-size: clamp(1.5rem, 3vw, 2.4rem); font-weight: 700; }
.note-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 3px; padding: 5px 10px; position: sticky; top: 0; z-index: 1; background: var(--paper); border-block: 1px solid var(--edge); }
.note-toolbar select { width: auto; margin-right: 5px; }
.note-toolbar button { min-width: 44px; padding-inline: 5px; }
.note-toolbar button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.note-content { padding: 16px 20px; min-height: 45vh; line-height: 1.65; overflow-wrap: anywhere; }
.note-content .ProseMirror { min-height: 40vh; position: relative; white-space: pre-wrap; word-wrap: break-word; outline: none; }
.note-content .ProseMirror:focus-visible { outline: none; }
.note-content h2, .note-content h3 { margin: .55em 0 .22em; line-height: 1.2; }
.note-content h2 { font-size: 1.5rem; }
.note-content h3 { font-size: 1.2rem; }
.note-content ul, .note-content ol { margin: .35em 0; padding-inline-start: 1.55em; }
.note-content p { min-height: 1.65em; }
@media (max-width: 760px) {
  .note-title-label, .note-content { padding-inline: 12px; }
}

.note-content a { color: var(--good); text-underline-offset: .15em; cursor: pointer; }

.topbar-actions { display: flex; align-items: center; gap: 6px; }
.topbar-actions > .icon-button { background: var(--paper); border-color: var(--edge); }
.card h2 a { text-decoration: none; }
.card h2 a:hover { text-decoration: underline; }
.card-check { cursor: pointer; min-height: 44px; }
.card-check input { width: 21px; height: 21px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 4px; padding: 5px 12px; border-bottom: 1px solid var(--edge); }
.suggestions[hidden] { display: none; }
.template-copy, .import-labels { margin-bottom: 12px; }
.import-labels { color: var(--soft); }
.search-results, .keep-preview { display: grid; gap: 7px; margin-block: 10px; }
.search-results a, .keep-preview article { display: grid; gap: 5px; background: var(--bg); padding: 10px; border-radius: 8px; overflow-wrap: anywhere; }
.search-results a { text-decoration: none; min-height: 44px; }
.search-results a:hover { background: var(--hover); }
.search-results span, .keep-preview article p { color: var(--soft); white-space: pre-wrap; }
.keep-preview { max-height: 44dvh; overflow-y: auto; }
.keep-preview ul { margin-block: 4px; }
dialog textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--edge); border-radius: 9px; padding: 10px; resize: vertical; width: 100%; }
.undo-clean { display: flex; gap: 8px; align-items: center; justify-content: space-between; position: fixed; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 4; width: max-content; max-width: calc(100vw - 24px); background: var(--paper); padding: 6px 10px; border: 1px solid var(--edge); border-radius: 12px; box-shadow: var(--shadow); }
@media (max-width: 760px) {
  .composer-area { order: 2; position: sticky; bottom: 0; z-index: 1; background: var(--paper); border-radius: 0 0 15px 15px; }
  .composer { position: static; }
  .undo-clean { bottom: max(72px, env(safe-area-inset-bottom)); }
}
@media (max-width: 390px) {
  .composer > .primary span { position: absolute; clip-path: inset(50%); }
  .mobile-brand span { display: none; }
}
