:root {
  --bg: #121418; --panel: #16191E; --raised: #1E2228; --menu: #20242B;
  --line: #262A31; --line2: #2E333B; --line3: #353B45;
  --text: #E6E8EB; --text2: #C4C9D1; --muted: #9AA1AC; --faint: #8A919C;
  --accent: #5B8CFF; --accent-ink: #0D1220; --accent-soft: #24304A; --accent-line: #34466B; --accent-text: #B7CCFF;
  --sel: #1B2130; --hit: #3A3320; --danger: #E89A9A; --ok: #3FB97A; --warn: #E0B04A;
  --code-bg: #3A2E20; --code-text: #F0B37E;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, "Segoe UI", system-ui, sans-serif; overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.app { height: 100%; display: flex; flex-direction: column; }

/* header */
header { display: flex; align-items: center; gap: 14px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; min-width: 200px; }
.search { flex: 1 1 340px; display: flex; align-items: center; gap: 8px; background: var(--raised); border: 1px solid var(--line2); border-radius: 8px; padding: 7px 10px; color: var(--muted); }
.search input { flex: 1; background: transparent; border: 0; outline: none; color: var(--text); min-width: 0; }
.search kbd { font-size: 11px; color: var(--faint); border: 1px solid var(--line3); border-radius: 4px; padding: 0 5px; }
.select { background: var(--raised); border: 1px solid var(--line2); border-radius: 999px; padding: 5px 10px; color: var(--text2); font-size: 13px; }
.sync { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); background: none; border: 0; padding: 4px 6px; border-radius: 6px; }
.sync:hover { background: var(--raised); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: #E5534B; }
.icon-btn { background: none; border: 0; color: var(--muted); border-radius: 6px; padding: 6px; display: inline-flex; }
.icon-btn:hover { background: var(--raised); color: var(--text); }

/* layout */
.main { flex: 1; display: flex; min-height: 0; }
nav.side { width: 250px; flex: none; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px 8px 24px; }
section.list { width: 400px; flex: none; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
main.reader { flex: 1; min-width: 0; overflow-y: auto; }

/* sidebar */
.side-group { margin-bottom: 16px; }
.side-head { display: flex; justify-content: space-between; align-items: center; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); padding: 0 8px 4px; }
.side-head button { background: none; border: 0; color: var(--faint); font-size: 16px; line-height: 1; padding: 2px 6px; border-radius: 4px; }
.side-head button:hover { background: var(--raised); color: var(--text); }
.nav-item { width: 100%; display: flex; align-items: center; gap: 6px; background: none; border: 0; text-align: left; padding: 6px 8px; border-radius: 6px; color: var(--text2); }
.nav-item:hover { background: var(--raised); }
.nav-item.active { background: var(--accent-soft); color: var(--text); }
.nav-item.drop { background: #2A3550; outline: 1px dashed var(--accent); }
.nav-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count { font-size: 12px; color: var(--faint); }
.nav-item .badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0 7px; font-size: 12px; font-weight: 600; }
.twisty { width: 14px; flex: none; color: var(--faint); font-size: 10px; text-align: center; }
.fdot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.empty-hint { color: var(--faint); font-size: 12px; padding: 4px 8px; }

/* tag colors */
.tag { display: inline-flex; align-items: center; gap: 4px; border: 1px solid; border-radius: 999px; padding: 0 8px; font-size: 12px; line-height: 20px; white-space: nowrap; background: none; }
.c-blue { color: #B7CCFF; border-color: #34466B; } .bg-blue { background: #5B8CFF; }
.c-orange { color: #F0B37E; border-color: #6B4A2A; } .bg-orange { background: #F0A35E; }
.c-green { color: #7FD3A6; border-color: #2E5E46; } .bg-green { background: #3FB97A; }
.c-purple { color: #D2A6E6; border-color: #5A3B66; } .bg-purple { background: #B07CD0; }
.c-red { color: #F0A3A0; border-color: #6B3330; } .bg-red { background: #E5534B; }
.c-teal { color: #86D9D6; border-color: #2A5C5A; } .bg-teal { background: #3BB5B0; }
.c-gray { color: #C4C9D1; border-color: #3A404A; } .bg-gray { background: #8A919C; }
.tag.suggest { border-style: dashed; opacity: .85; cursor: pointer; }
.tag.suggest:hover { opacity: 1; }
.tag .x { background: none; border: 0; padding: 0; color: inherit; opacity: .7; font-size: 13px; line-height: 1; }
.tag .x:hover { opacity: 1; }

/* list */
.list-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); gap: 8px; }
.list-head .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-head .n { color: var(--faint); font-weight: 400; }
.rows { flex: 1; overflow-y: auto; }
.row { padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; border-left: 3px solid transparent; }
.row:hover { background: #171B21; }
.row.sel { background: var(--sel); border-left-color: var(--accent); }
.row.dragging { opacity: .5; }
.row .top { display: flex; justify-content: space-between; gap: 8px; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .date { color: var(--faint); font-size: 12px; white-space: nowrap; }
.row .snip { color: #A9AFB8; font-size: 13px; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
mark { background: var(--hit); color: var(--text); font-weight: 600; border-radius: 2px; }
.row .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 7px; }
.src { border-radius: 4px; padding: 0 6px; font-size: 11px; line-height: 18px; }
.src.web { background: var(--accent-soft); color: var(--accent-text); }
.src.code { background: var(--code-bg); color: var(--code-text); }
.pin { color: var(--warn); font-size: 12px; }
.list-empty { padding: 40px 20px; text-align: center; color: var(--faint); }

/* reader */
.reader-inner { max-width: 900px; padding: 20px 28px 60px; }
.reader-empty { height: 100%; display: flex; align-items: center; justify-content: center; color: var(--faint); text-align: center; padding: 20px; }
.r-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: flex-start; }
.r-title { margin: 0; font-size: 21px; font-weight: 700; cursor: text; }
.r-title-input { font-size: 21px; font-weight: 700; background: var(--raised); border: 1px solid var(--accent); border-radius: 6px; padding: 2px 6px; width: 100%; color: var(--text); }
.r-meta { color: var(--faint); font-size: 13px; margin-top: 5px; }
.r-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { background: var(--raised); color: var(--text); border: 1px solid var(--line2); border-radius: 8px; padding: 7px 13px; font-size: 13px; white-space: nowrap; }
.btn:hover { border-color: var(--line3); background: #242931; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: #7AA2FF; }
.split { display: inline-flex; }
.split .btn:first-child { border-radius: 8px 0 0 8px; }
.split .btn:last-child { border-radius: 0 8px 8px 0; border-left: 1px solid rgba(0,0,0,.25); padding: 7px 9px; }
.r-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; align-items: center; }
.add-tag { background: none; border: 1px dashed #3A404A; color: var(--faint); border-radius: 999px; padding: 0 9px; font-size: 12px; line-height: 20px; }
.note { width: 100%; min-height: 44px; resize: vertical; background: #1C2026; border: 1px solid #2B3038; border-radius: 8px; padding: 9px 12px; color: var(--text2); font-size: 13px; }
.note:focus { border-color: var(--accent-line); outline: none; }
.msgs { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.msg { border-radius: 12px; padding: 11px 14px; max-width: 92%; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent-soft); border-radius: 12px 12px 2px 12px; max-width: 80%; }
.msg.assistant { background: #1A1D22; border: 1px solid var(--line); border-radius: 12px 12px 12px 2px; color: #D4D8DE; }
.msg.tool { background: none; border: 1px dashed var(--line2); color: var(--faint); font-size: 12px; max-width: 100%; }
.msg .who { font-size: 11px; color: var(--faint); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .06em; }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin-bottom: 0; }
.msg code { background: #262A31; padding: 1px 5px; border-radius: 4px; font: 12.5px Consolas, "Cascadia Mono", monospace; }
.msg pre { background: #0F1114; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 8px 0; }
.msg pre code { background: none; padding: 0; }
.more-msgs { align-self: center; }

/* menus and modals */
.menu { position: fixed; z-index: 50; min-width: 210px; max-height: 70vh; overflow-y: auto; background: var(--menu); border: 1px solid var(--line3); border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.5); padding: 5px; }
.menu button { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 16px; text-align: left; background: none; border: 0; border-radius: 6px; padding: 7px 10px; font-size: 13px; color: var(--text); }
.menu button:hover, .menu button.hl { background: #2A3550; }
.menu button.danger { color: var(--danger); }
.menu button:disabled { color: var(--faint); cursor: default; background: none; }
.menu .sep { height: 1px; background: var(--line3); margin: 4px 6px; }
.menu .hint { color: var(--faint); font-size: 12px; }
.menu .check { width: 14px; color: var(--accent-text); }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--line3); border-radius: 12px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.6); }
.modal h2 { margin: 0 0 14px; font-size: 17px; }
.modal h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); }
.modal label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 5px; }
.modal input[type=text], .modal textarea { width: 100%; background: var(--raised); border: 1px solid var(--line2); border-radius: 8px; padding: 8px 10px; color: var(--text); }
.modal .row-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal .help { color: var(--faint); font-size: 12px; margin-top: 5px; }
.radio { display: flex; gap: 8px; }
.radio label { display: flex; align-items: center; gap: 6px; background: var(--raised); border: 1px solid var(--line2); border-radius: 8px; padding: 7px 12px; cursor: pointer; margin: 0; }
.swatches { display: flex; gap: 8px; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; }
.swatch.on { border-color: var(--text); }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text2); margin: 4px 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #2A2F37; border: 1px solid var(--line3); color: var(--text); padding: 9px 16px; border-radius: 8px; z-index: 80; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.toast.err { border-color: #6B3330; color: #F0A3A0; }
.banner { background: #3A2A1C; color: #F3D4B5; border-bottom: 1px solid #6B4A2A; padding: 7px 16px; font-size: 13px; display: flex; gap: 10px; align-items: center; }
.banner button { background: none; border: 1px solid #6B4A2A; color: inherit; border-radius: 6px; padding: 2px 8px; font-size: 12px; }

@media (max-width: 1000px) { section.list { width: 320px; } nav.side { width: 210px; } }

.sec-toggle { display: flex; align-items: center; gap: 2px; background: none; border: 0; padding: 0; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer; }
.sec-toggle:hover { color: var(--text2); }
.hidden-toggle { color: var(--faint); font-size: 13px; }
.side-head .sec-toggle { font-size: 11px; padding: 0; color: var(--faint); }
.side-head .sec-toggle:hover { background: none; color: var(--text2); }
.modal a:not(.btn) { color: var(--accent-text); }
.modal a:not(.btn):hover { color: #DCE6FF; }
