/* Worknest — app styles */
:root {
  --bg: #f6f6f8;
  --panel: #ffffff;
  --panel-2: #fafafb;
  --hover: #f1f1f5;
  --border: #e6e6ec;
  --border-strong: #d6d6de;
  --text: #1c1c26;
  --muted: #6b6b7c;
  --faint: #a2a2b0;
  --accent: #5b5bd6;
  --accent-hover: #4b4bc4;
  --accent-soft: #eeeefc;
  --accent-text: #4343b8;
  --danger: #d14343;
  --danger-soft: #fdeeee;
  --success: #2c9a66;
  --success-soft: #e8f6ef;
  --warn: #c97a1e;
  --warn-soft: #fdf3e6;
  --ai: #8b5cf6;
  --ai-soft: #f3eefe;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 40, .06);
  --shadow: 0 4px 16px rgba(20, 20, 40, .08), 0 1px 3px rgba(20, 20, 40, .06);
  --shadow-lg: 0 18px 50px rgba(20, 20, 40, .18), 0 2px 8px rgba(20, 20, 40, .08);
  --sidebar-w: 252px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #111117;
  --panel: #18181f;
  --panel-2: #1c1c24;
  --hover: #23232d;
  --border: #2a2a35;
  --border-strong: #383846;
  --text: #ebebf2;
  --muted: #a3a3b5;
  --faint: #6c6c7e;
  --accent: #7b7bf2;
  --accent-hover: #8d8df6;
  --accent-soft: #25254a;
  --accent-text: #a9a9ff;
  --danger: #ef6b6b;
  --danger-soft: #3a1f22;
  --success: #4cc28a;
  --success-soft: #1a3328;
  --warn: #e6a050;
  --warn-soft: #3a2b18;
  --ai: #a78bfa;
  --ai-soft: #2b2244;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 4px 18px rgba(0, 0, 0, .35);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 14.5px; line-height: 1.45; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
svg.i.sm { width: 15px; height: 15px; }
svg.i.lg { width: 22px; height: 22px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
kbd { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; color: var(--muted); background: var(--panel); }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--panel); color: var(--text);
  cursor: pointer; font-weight: 500; white-space: nowrap; transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ai { background: linear-gradient(135deg, #7c5cf6, #5b5bd6); border-color: transparent; color: #fff; }
.btn.ai:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 36px; padding: 0; }
.btn.icon.sm { width: 30px; }
.btn.block { width: 100%; }
.btn .spinner { width: 14px; height: 14px; }

.input, select.input, textarea.input {
  width: 100%; height: 38px; padding: 0 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--panel); outline: none; transition: border-color .12s, box-shadow .12s;
}
textarea.input { height: auto; min-height: 90px; padding: 9px 11px; resize: vertical; line-height: 1.5; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select.input { padding-right: 28px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.input.sm { height: 32px; font-size: 13px; }
.field { display: flex; flex-direction: column; align-items: stretch; gap: 5px; font-size: 13px; font-weight: 500; color: var(--muted); }
.field > span { color: var(--muted); display: flex; align-items: center; gap: 5px; }
.field > .seg { align-self: flex-start; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--accent-text); cursor: pointer; font: inherit; }
.linkbtn:hover { text-decoration: underline; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 14px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: transparent; padding: 6px 11px; cursor: pointer; font-size: 13px; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }

.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; opacity: .8; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100vh; height: 100dvh; }
.sidebar {
  background: var(--panel-2); border-right: 1px solid var(--border); display: flex; flex-direction: column;
  overflow: hidden; min-height: 0;
}
.sb-head { display: flex; align-items: center; gap: 10px; padding: 16px 14px 10px; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, #7c5cf6, #5b5bd6); display: grid; place-items: center; color: #fff; box-shadow: 0 2px 8px rgba(91, 91, 214, .35); }
.logo svg { width: 18px; height: 18px; }
.brand { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.sb-search {
  margin: 4px 12px 8px; display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--panel); color: var(--faint); cursor: pointer; font-size: 13.5px; white-space: nowrap; overflow: hidden;
}
.sb-search span { overflow: hidden; text-overflow: ellipsis; }
.sb-search:hover { border-color: var(--border-strong); }
.sb-search kbd { margin-left: auto; }
.sb-scroll { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.sb-section { margin-top: 14px; }
.sb-title { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px; font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); }
.sb-title button { border: 0; background: transparent; color: var(--faint); cursor: pointer; padding: 2px; border-radius: 5px; display: grid; }
.sb-title button:hover { background: var(--hover); color: var(--text); }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 9px; border-radius: var(--radius-sm); color: var(--text);
  cursor: pointer; font-size: 14px; position: relative; text-decoration: none !important; user-select: none;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-item .count { margin-left: auto; font-size: 12px; color: var(--faint); font-weight: 500; }
.nav-item .count.alert { color: #fff; background: var(--danger); border-radius: 10px; padding: 0 6px; min-width: 18px; text-align: center; line-height: 18px; }
.nav-item .dot { width: 9px; height: 9px; border-radius: 3px; background: var(--faint); margin: 0 4px 0 4px; flex-shrink: 0; }
.nav-item .more { display: none; margin-left: 4px; border: 0; background: transparent; color: var(--faint); cursor: pointer; padding: 0; border-radius: 4px; }
.nav-item:hover .more { display: grid; }
.nav-item:hover .more + .count, .nav-item:hover .count:has(+ .more) { display: none; }
.nav-sub { padding-left: 18px; }
.sb-foot { border-top: 1px solid var(--border); padding: 8px; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 5px; padding: 4px 8px; }

.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.topbar { display: none; }
.view { flex: 1; min-height: 0; overflow: hidden; display: flex; }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Page header ---------- */
.page { flex: 1; overflow-y: auto; }
.page-inner { max-width: 1080px; margin: 0 auto; padding: 28px 32px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; letter-spacing: -.02em; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 14px; }

/* ---------- Chips / badges ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 20px; font-size: 12px; background: var(--hover); color: var(--muted); white-space: nowrap; line-height: 20px; border: 0; cursor: default; }
.chip.click { cursor: pointer; }
.chip.click:hover { background: var(--border); }
.chip.accent { background: var(--accent-soft); color: var(--accent-text); }
.chip.ai { background: var(--ai-soft); color: var(--ai); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.success { background: var(--success-soft); color: var(--success); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip svg.i { width: 12px; height: 12px; }

/* Color palette for notebooks/projects/notes */
.c-red { --c: #e5484d; } .c-orange { --c: #f76b15; } .c-yellow { --c: #e2a300; } .c-green { --c: #30a46c; }
.c-teal { --c: #12a594; } .c-blue { --c: #0090ff; } .c-purple { --c: #8e4ec6; } .c-pink { --c: #d6409f; } .c-gray { --c: #8b8d98; }
.dot[class*="c-"] { background: var(--c) !important; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; background: var(--c, var(--hover)); cursor: pointer; outline: 1px solid var(--border); }
.swatch.on { border-color: var(--panel); outline: 2px solid var(--text); }

/* ---------- Cards ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.card h3 { margin: 0 0 10px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card h3 .sp { margin-left: auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; transition: border-color .12s, transform .12s; }
.stat:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.stat .n { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat .l { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat.danger .n { color: var(--danger); }
.ai-card { background: linear-gradient(135deg, var(--ai-soft), var(--accent-soft)); border-color: transparent; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty svg.i { width: 34px; height: 34px; color: var(--faint); margin-bottom: 8px; }
.empty h4 { margin: 4px 0; color: var(--text); font-size: 15px; }

/* ---------- Notes layout ---------- */
.notes-layout { display: grid; grid-template-columns: 340px 1fr; flex: 1; min-width: 0; min-height: 0; }
.list-pane { border-right: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 16px 14px 10px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.list-head .title-row { display: flex; align-items: center; gap: 8px; }
.list-head h2 { margin: 0; font-size: 18px; letter-spacing: -.01em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-box { position: relative; }
.search-box svg.i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search-box .input { padding-left: 34px; height: 34px; background: var(--panel-2); }
.list-body { flex: 1; overflow-y: auto; }
.note-item { padding: 12px 14px 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; position: relative; }
.note-item:hover { background: var(--hover); }
.note-item.active { background: var(--accent-soft); }
.note-item.active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.note-item .nt { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.note-item .nt .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.note-item .ns { color: var(--muted); font-size: 13px; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.note-item .nm { display: flex; align-items: center; gap: 6px; margin-top: 7px; font-size: 12px; color: var(--faint); flex-wrap: wrap; }
.note-item .cbar { position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--c); }

.editor-pane { display: flex; min-width: 0; min-height: 0; background: var(--panel); }
.editor-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.editor-bar { display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--border); min-height: 52px; flex-wrap: nowrap; }
.editor-bar .save-state { font-size: 12px; color: var(--faint); margin-right: 4px; white-space: nowrap; }
.editor-bar select.input { width: auto; max-width: 170px; height: 32px; font-size: 13px; }
.editor-scroll { flex: 1; overflow-y: auto; }
.editor-doc { max-width: 820px; margin: 0 auto; padding: 22px 36px 80px; }
.title-input { width: 100%; border: 0; outline: 0; background: transparent; font-size: 28px; font-weight: 700; letter-spacing: -.02em; padding: 4px 0; resize: none; overflow: hidden; line-height: 1.25; display: block; font-family: inherit; color: var(--text); }
.title-input::placeholder { color: var(--faint); }
.note-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0 12px; color: var(--faint); font-size: 12.5px; }
.tags-input { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.tags-input input { border: 0; outline: 0; background: transparent; font-size: 12.5px; min-width: 90px; padding: 2px 0; }
.tag { display: inline-flex; align-items: center; gap: 3px; background: var(--accent-soft); color: var(--accent-text); padding: 0 4px 0 8px; border-radius: 20px; font-size: 12px; line-height: 21px; }
.tag button { border: 0; background: transparent; color: inherit; cursor: pointer; padding: 0 3px; opacity: .65; font-size: 14px; line-height: 1; }
.tag button:hover { opacity: 1; }

/* Quill overrides */
.ql-toolbar.ql-snow { border: 0 !important; border-bottom: 1px solid var(--border) !important; padding: 6px 10px !important; position: sticky; top: 0; background: var(--panel); z-index: 5; font-family: var(--font) !important; }
.ql-container.ql-snow { border: 0 !important; font-family: var(--font) !important; font-size: 15.5px !important; }
.ql-editor { padding: 6px 0 40px !important; line-height: 1.65 !important; min-height: 300px; color: var(--text); }
.ql-editor.ql-blank::before { left: 0 !important; color: var(--faint) !important; font-style: normal !important; }
.ql-editor h1 { font-size: 1.7em; letter-spacing: -.02em; margin: .8em 0 .3em; }
.ql-editor h2 { font-size: 1.35em; letter-spacing: -.01em; margin: .8em 0 .3em; }
.ql-editor h3 { font-size: 1.12em; margin: .8em 0 .25em; }
.ql-editor blockquote { border-left: 3px solid var(--accent) !important; color: var(--muted); padding-left: 14px !important; }
.ql-editor .ql-code-block-container, .ql-editor pre { background: var(--panel-2) !important; color: var(--text) !important; border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px !important; font-family: var(--mono); font-size: 13.5px; }
.ql-editor li[data-list="checked"] { color: var(--faint); text-decoration: line-through; }
.ql-editor li[data-list=checked] > .ql-ui, .ql-editor li[data-list=unchecked] > .ql-ui { color: var(--accent); }
.ql-editor img { max-width: 100%; border-radius: 8px; }
.ql-editor a { color: var(--accent-text); }
.ql-editor hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.ql-snow .ql-stroke { stroke: var(--muted) !important; }
.ql-snow .ql-fill { fill: var(--muted) !important; }
.ql-snow .ql-picker { color: var(--muted) !important; }
.ql-snow.ql-toolbar button:hover .ql-stroke, .ql-snow.ql-toolbar button.ql-active .ql-stroke, .ql-snow .ql-picker-label:hover .ql-stroke, .ql-snow .ql-picker-label.ql-active .ql-stroke { stroke: var(--accent) !important; }
.ql-snow.ql-toolbar button:hover .ql-fill, .ql-snow.ql-toolbar button.ql-active .ql-fill { fill: var(--accent) !important; }
.ql-snow .ql-picker-options { background: var(--panel) !important; border-color: var(--border) !important; box-shadow: var(--shadow) !important; border-radius: 8px; }
.ql-snow .ql-tooltip { background: var(--panel) !important; color: var(--text) !important; border-color: var(--border) !important; box-shadow: var(--shadow) !important; border-radius: 8px; z-index: 20; }
.ql-snow .ql-tooltip input[type=text] { background: var(--panel-2); color: var(--text); border-color: var(--border) !important; border-radius: 5px; }
.ql-toolbar .ql-maketask { width: auto !important; padding: 2px 6px !important; display: inline-flex !important; align-items: center; gap: 4px; color: var(--accent-text); font-size: 12.5px; font-weight: 600; }
.ql-toolbar .ql-maketask svg.i { width: 15px; height: 15px; stroke: var(--accent-text); }
.ql-formats { margin-right: 10px !important; }

/* Note side panel (linked tasks + AI) */
.note-side { width: 360px; border-left: 1px solid var(--border); background: var(--panel-2); display: flex; flex-direction: column; min-height: 0; }
.note-side .side-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 600; }
.note-side .side-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.side-sec h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); display: flex; align-items: center; gap: 6px; }
.ai-sum { font-size: 14px; line-height: 1.55; }
.ai-sum ul { margin: 4px 0 10px; padding-left: 18px; }
.ai-sum li { margin: 3px 0; }
.ai-sum .lbl { font-weight: 600; font-size: 13px; margin-top: 8px; }

/* ---------- Tasks ---------- */
.tasks-layout { display: grid; grid-template-columns: 1fr; flex: 1; min-width: 0; min-height: 0; }
.tasks-layout.with-detail { grid-template-columns: 1fr 400px; }
.tasks-main { overflow-y: auto; min-height: 0; }
.tasks-inner { max-width: 860px; margin: 0 auto; padding: 26px 30px 80px; }
.quick-add { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 6px 6px 6px 12px; display: flex; align-items: center; gap: 8px; transition: border-color .12s, box-shadow .12s; }
.quick-add:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.quick-add input { flex: 1; border: 0; outline: 0; background: transparent; height: 36px; font-size: 15px; min-width: 0; }
.quick-add > svg.i { color: var(--accent); }
.qa-preview { display: flex; gap: 6px; flex-wrap: wrap; padding: 6px 4px 0; min-height: 0; }
.group { margin-top: 22px; }
.group-title { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); padding: 0 4px 6px; border-bottom: 1px solid var(--border); }
.group-title.danger { color: var(--danger); }
.group-title .n { color: var(--faint); font-weight: 500; }
.task { display: flex; align-items: flex-start; gap: 10px; padding: 9px 6px; border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 6px; transition: background .1s; }
.task:hover { background: var(--hover); }
.task.active { background: var(--accent-soft); }
.task .tb { flex: 1; min-width: 0; }
.task .tt { word-wrap: break-word; }
.task.done .tt { color: var(--faint); text-decoration: line-through; }
.task .tm { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 3px; font-size: 12.5px; color: var(--muted); }
.task .tm .due { display: inline-flex; align-items: center; gap: 3px; }
.task .tm .due.over { color: var(--danger); font-weight: 500; }
.task .tm .due.today { color: var(--accent-text); font-weight: 500; }
.task .tm svg.i { width: 13px; height: 13px; }
.cb {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border-strong); background: transparent; cursor: pointer;
  flex-shrink: 0; margin-top: 1px; display: grid; place-items: center; transition: all .12s; padding: 0;
}
.cb:hover { border-color: var(--accent); background: var(--accent-soft); }
.cb.p3 { border-color: var(--danger); } .cb.p3:hover { background: var(--danger-soft); }
.cb.p2 { border-color: var(--warn); } .cb.p2:hover { background: var(--warn-soft); }
.cb.p1 { border-color: #3b82f6; }
.cb.on { background: var(--success); border-color: var(--success); }
.cb.on::after { content: ""; width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.task.pop .cb { animation: pop .3s ease; }
@keyframes pop { 50% { transform: scale(1.25); } }

.detail { border-left: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.detail-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.detail-body { flex: 1; overflow-y: auto; padding: 16px 18px 40px; display: flex; flex-direction: column; gap: 14px; }
.detail .title-area { min-height: 28px; width: 100%; border: 0; outline: 0; resize: none; background: transparent; font-size: 19px; font-weight: 600; line-height: 1.35; padding: 0; overflow: hidden; }
.detail .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.detail-foot { font-size: 12px; color: var(--faint); }

/* ---------- Modal / sheet ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 15, 30, .42); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; animation: fade .14s ease; }
:root[data-theme="dark"] .overlay { background: rgba(0, 0, 0, .6); }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: 84vh; display: flex; flex-direction: column; animation: rise .18s ease; border: 1px solid var(--border); }
.modal.wide { max-width: 760px; }
@keyframes rise { from { transform: translateY(10px) scale(.98); opacity: 0; } }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 10px; }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; display: flex; align-items: center; gap: 8px; }
.modal-body { padding: 6px 18px 16px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }

.menu { position: fixed; z-index: 120; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 5px; min-width: 210px; animation: fade .1s ease; max-height: 70vh; overflow-y: auto; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; border: 0; background: transparent; padding: 8px 10px; border-radius: 6px; cursor: pointer; text-align: left; font-size: 14px; }
.menu button:hover, .menu button.sel { background: var(--hover); }
.menu button.danger { color: var(--danger); }
.menu button .hint { margin-left: auto; color: var(--faint); font-size: 12px; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.menu .mlabel { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); padding: 6px 10px 3px; font-weight: 600; }

/* Command palette */
.palette { max-width: 600px; }
.palette .pinput { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.palette .pinput input { flex: 1; border: 0; outline: 0; background: transparent; font-size: 16px; }
.palette .presults { overflow-y: auto; padding: 6px; max-height: 55vh; }
.palette .pgroup { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); padding: 8px 10px 4px; font-weight: 600; }
.palette .pitem { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.palette .pitem.sel { background: var(--accent-soft); }
.palette .pitem .ps { color: var(--faint); font-size: 12.5px; margin-left: auto; max-width: 45%; }

/* Toast */
.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #1f1f2b; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 14px; display: flex; align-items: center; gap: 10px; pointer-events: auto; animation: rise .2s ease; max-width: 90vw; }
.toast.err { background: var(--danger); }
.toast button { background: transparent; border: 0; color: #a9a9ff; font-weight: 600; cursor: pointer; padding: 0 0 0 6px; }

/* AI review list */
.ai-items { display: flex; flex-direction: column; gap: 8px; }
.ai-item { display: grid; grid-template-columns: 22px 1fr; gap: 8px; padding: 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); }
.ai-item.off { opacity: .5; }
.ai-item .fields { display: grid; grid-template-columns: 1fr 140px 110px; gap: 6px; margin-top: 6px; }
.ai-item .fields .input { height: 30px; font-size: 13px; }
.ai-item .tinput { width: 100%; border: 0; outline: 0; background: transparent; font-weight: 500; font-size: 14px; padding: 0; }
.ai-loading { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px 10px; color: var(--muted); text-align: center; }
.ai-loading .spinner { width: 28px; height: 28px; color: var(--ai); }
.shimmer { background: linear-gradient(90deg, var(--ai), var(--accent), var(--ai)); background-size: 200% auto; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shim 2s linear infinite; font-weight: 600; }
@keyframes shim { to { background-position: 200% center; } }

/* Settings */
.settings-grid { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 28px; }
.settings-nav .nav-item { border: 0; background: transparent; width: 100%; text-align: left; font: inherit; }
.settings-nav { position: sticky; top: 0; align-self: start; display: flex; flex-direction: column; gap: 2px; }
.settings-sec { margin-bottom: 22px; }
.settings-sec .card { display: flex; flex-direction: column; gap: 14px; }
.settings-sec h2 { font-size: 17px; margin: 0 0 10px; }
.help { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.help code { font-family: var(--mono); font-size: 12px; background: var(--hover); padding: 1px 5px; border-radius: 4px; }
.device { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.device:last-child { border-bottom: 0; }
.log-row { display: flex; gap: 8px; font-size: 12.5px; padding: 5px 0; border-bottom: 1px dashed var(--border); align-items: baseline; }
.channel-block { border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.channel-block .ch-head { display: flex; align-items: center; gap: 8px; font-weight: 600; }

/* ---------- Login / install ---------- */
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent), radial-gradient(800px 500px at 110% 110%, var(--ai-soft), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 30px 28px; }
.auth-card .logo { width: 44px; height: 44px; border-radius: 13px; margin-bottom: 14px; }
.auth-card .logo svg { width: 24px; height: 24px; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.02em; }
.auth-card p.sub { margin: 0 0 22px; color: var(--muted); }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 13.5px; }
.alert.err { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--success-soft); color: var(--success); }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 60px; }
.pw-wrap button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 12.5px; padding: 6px; }

/* ---------- Mobile ---------- */
.tabbar { display: none; }
.sb-backdrop { display: none; }
.back-btn { display: none !important; }

@media (max-width: 1250px) {
  .note-side { position: absolute; right: 0; top: 0; bottom: 0; z-index: 30; box-shadow: var(--shadow-lg); }
  .editor-pane { position: relative; }
}
@media (max-width: 1100px) {
  .notes-layout { grid-template-columns: 290px 1fr; }
  .tasks-layout.with-detail { grid-template-columns: 1fr 360px; }
}
@media (max-width: 900px) {
  body { font-size: 15px; }
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); z-index: 90; transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow-lg); }
  .app.sb-open .sidebar { transform: none; }
  .app.sb-open .sb-backdrop { display: block; position: fixed; inset: 0; z-index: 80; background: rgba(10, 10, 25, .4); }
  .main { padding-bottom: calc(var(--tabbar-h) + var(--safe-b)); }
  .topbar { display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--border); min-height: 54px; }
  .topbar .tb-title { flex: 1; font-weight: 700; font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 70; height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--border);
  }
  .tabbar button { border: 0; background: none; font: inherit; cursor: pointer; padding: 0; }
  .tabbar a, .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--faint); font-size: 11px; font-weight: 500; text-decoration: none !important; position: relative; }
  .tabbar a.active { color: var(--accent-text); }
  .tabbar svg.i { width: 23px; height: 23px; }
  .tabbar .fab { flex: 0 0 76px; }
  .tabbar .fab span { width: 50px; height: 50px; border-radius: 16px; background: linear-gradient(135deg, #7c5cf6, #5b5bd6); color: #fff; display: grid; place-items: center; box-shadow: 0 6px 18px rgba(91, 91, 214, .45); margin-top: -18px; }
  .tabbar .fab svg.i { width: 26px; height: 26px; }
  .tabbar .badge { position: absolute; top: 6px; left: 50%; margin-left: 6px; background: var(--danger); color: #fff; font-size: 10px; border-radius: 9px; padding: 0 5px; line-height: 16px; min-width: 16px; text-align: center; }

  .page-inner, .tasks-inner { padding: 16px 14px 40px; }
  .page-head h1 { font-size: 21px; }
  .page-head > .grow { flex-basis: 100%; }
  .tasks-inner .page-head h1 { display: none; }
  .tasks-inner .page-head > .grow { flex-basis: auto; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .notes-layout { grid-template-columns: 1fr; }
  .notes-layout .editor-pane { display: none; }
  .notes-layout.show-editor .list-pane { display: none; }
  .notes-layout.show-editor .editor-pane { display: flex; }
  .list-pane { border-right: 0; }
  .list-head h2 { display: none; }
  .back-btn { display: inline-flex !important; }
  .editor-doc { padding: 14px 16px 60px; }
  .title-input { font-size: 23px; }
  .editor-bar { padding: 6px 8px; gap: 4px; overflow-x: auto; }
  .editor-bar .hide-m { display: none; }
  .ql-toolbar.ql-snow { overflow-x: auto; white-space: nowrap; padding: 4px 6px !important; -webkit-overflow-scrolling: touch; }
  .ql-toolbar .ql-formats { display: inline-flex !important; vertical-align: middle; }
  .note-side { position: fixed; inset: 0; width: auto; z-index: 95; }
  .tasks-layout.with-detail { grid-template-columns: 1fr; }
  .tasks-layout.with-detail .tasks-main { display: none; }
  .detail { border-left: 0; }
  .task { padding: 11px 4px; }
  .cb { width: 22px; height: 22px; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-nav { display: none; }
  .overlay { padding: 0; align-items: flex-end; }
  .modal { max-width: none !important; border-radius: 18px 18px 0 0; max-height: 92vh; padding-bottom: var(--safe-b); animation: sheet .22s ease; }
  @keyframes sheet { from { transform: translateY(40px); opacity: 0; } }
  .ai-item .fields { grid-template-columns: 1fr 1fr; }
  .ai-item .fields .proj { grid-column: span 2; }
  .toasts { bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); }
  .input, select.input, textarea.input, .quick-add input { font-size: 16px; } /* prevents iOS zoom */
}

@media print {
  .sidebar, .topbar, .tabbar, .list-pane, .editor-bar, .ql-toolbar, .note-side { display: none !important; }
  .app, .notes-layout { display: block; height: auto; }
  .editor-scroll, .view, .main { overflow: visible !important; }
}
