:root {
  --bg: #ffffff; --surface: #f6f7f9; --surface-2: #eef0f3; --border: #e3e6ea;
  --text: #11161c; --text-2: #5a636e; --muted: #6b7480;
  --accent: #2f6df6; --accent-soft: #e8f0fe;
  --star: #f5a623; --ok: #2faa5e; --warn: #d9534f;
  --radius: 12px; --radius-sm: 8px;
  --serif: "Iowan Old Style", "Charter", Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14; --surface: #141a22; --surface-2: #1b232d; --border: #232c37;
    --text: #e8edf3; --text-2: #aab4c0; --muted: #8c97a4;
    --accent: #6ea0ff; --accent-soft: #16233c;
    --star: #ffc24b; --ok: #46c178; --warn: #ff6b6b;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; padding-bottom: env(safe-area-inset-bottom);
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--border);
  padding-top: calc(12px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }

main, .login { max-width: 860px; margin: 0 auto; padding: 14px 16px; }
.login { text-align: center; padding-top: 56px; max-width: 420px; }
.login h1 { font-size: 22px; margin: 0 0 4px; }

input, button, select {
  font: inherit; border-radius: var(--radius-sm); border: 1px solid var(--border);
}
input, select { background: var(--surface); color: var(--text); padding: 10px 12px; width: 100%; }
button {
  background: var(--accent); color: #fff; border: none; padding: 10px 16px;
  font-weight: 500; cursor: pointer; border-radius: var(--radius-sm);
}
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button.ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
button.ghost:hover { color: var(--text); border-color: var(--accent); }
button.tiny { padding: 5px 10px; font-size: 13px; }
button.danger:hover { color: var(--warn); border-color: var(--warn); }
.login input { margin: 10px 0; }

.add { display: flex; gap: 8px; }
.add #add-url { flex: 1; min-width: 0; }
.add button { white-space: nowrap; flex: none; }
.note-toggle { padding-left: 12px; padding-right: 12px; }
.add-msg { margin: 8px 2px 0; font-size: 13px; }

/* Note composer */
.note-composer { margin-top: 10px; border: 1px solid var(--accent); border-radius: var(--radius); padding: 12px; background: var(--surface); }
/* font-size 16px on note inputs: iOS zooms a focused input under 16px. */
.note-composer input, .note-composer textarea,
.note-edit-title, .note-edit-body { font-size: 16px; }
.note-composer input { margin-bottom: 8px; }
.note-composer textarea { width: 100%; resize: vertical; line-height: 1.55; min-height: 110px; }
.note-composer-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.note-composer-actions { display: flex; gap: 6px; }

/* Note cards + detail */
.avatar.note-av { font-size: 14px; }
.note-kind { text-transform: uppercase; letter-spacing: .04em; font-size: 11px; }
.card.is-note .title { cursor: pointer; }
.note-detail .note-body { font-family: var(--serif); font-size: 16px; line-height: 1.65; margin: 4px 0 10px; }
.note-detail .note-summary { font-size: 13px; font-style: italic; margin: 0 0 8px; }
.note-edit-title { width: 100%; margin-bottom: 8px; }
.note-edit-body { width: 100%; resize: vertical; line-height: 1.55; min-height: 160px; }
.note-edit-actions { gap: 8px; }

/* Trash */
.trash-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; font-size: 12.5px; }
.trash-card { opacity: .92; }
.trash-actions { display: flex; gap: 6px; align-items: center; }
#trash-toggle.on { color: var(--accent); border-color: var(--accent); }

.note-composer-foot label.note-project-wrap { display: flex; align-items: center; gap: 6px; }
.note-project { width: auto; padding: 5px 8px; font-size: 13px; max-width: 60vw; }
.note-composer-hint { margin: 6px 2px 0; }

/* Projects */
.projects { display: flex; flex-direction: column; gap: 12px; }
.projects-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.projects-head .briefs-intro { flex: 1; min-width: 200px; margin: 0; }
.projects-list { display: flex; flex-direction: column; gap: 10px; }
.proj-card { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 10px; align-items: start; padding: 12px 14px; }
.proj-main { min-width: 0; cursor: pointer; }
.proj-name { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.proj-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.proj-desc { font-size: 13px; margin-top: 4px; line-height: 1.45; }
.proj-meta { font-size: 12px; margin-top: 6px; }
.proj-menu-wrap { position: relative; }
.proj-archived-head { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin: 6px 2px 0; }
.badge.proj-done { color: var(--ok); border-color: var(--ok); }

/* Project banner (open project) */
.project-banner { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--radius); padding: 10px 14px; margin: 4px 0 8px; }
.pb-name { font-weight: 600; font-size: 15px; }
.pb-desc { font-size: 13px; margin-top: 3px; line-height: 1.45; }
.pb-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.detail .proj-select { width: auto; padding: 6px 9px; font-size: 13px; }
.add-msg.ok { color: var(--ok); } .add-msg.warn { color: var(--star); }

/* Ask your library */
.ask { margin-top: 12px; }
.ask-toggle { width: 100%; text-align: left; }
.ask-body { margin-top: 8px; border: 1px solid var(--accent); border-radius: var(--radius); padding: 12px; background: var(--surface); }
.ask-input { display: flex; gap: 8px; }
.ask-input button { white-space: nowrap; }
.ask-note { font-size: 12px; margin: 8px 2px 0; }
.ask-thread { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.qa { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--bg); }
.qa .q { font-weight: 600; margin: 0 0 6px; }
.qa .a { font-family: var(--serif); font-size: 15.5px; line-height: 1.6; white-space: pre-wrap; }
.qa .a.pending { color: var(--muted); font-family: inherit; font-style: italic; }
.qa .sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.qa .src-chip { font-size: 12px; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 999px; text-decoration: none; }
.qa button.src-chip { border: none; font-weight: 400; cursor: pointer; }
.qa .qa-del { float: right; background: transparent; border: none; color: var(--muted); padding: 0 4px; cursor: pointer; }
.shimmer { background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%); background-size: 400% 100%; animation: sh 1.4s ease infinite; border-radius: 4px; height: 12px; margin: 6px 0; }
@keyframes sh { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* Toolbar */
.toolbar { position: sticky; top: 56px; z-index: 10; background: var(--bg); padding: 10px 0 8px; margin-top: 8px; }
.toolbar-row { display: flex; gap: 8px; }
.toolbar-row input { flex: 1; }
.sort { width: auto; flex: none; }
.toolbar-row2 { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.segmented::-webkit-scrollbar { height: 0; }
.seg { background: transparent; color: var(--text-2); border: none; border-radius: 0; padding: 6px 12px; font-size: 13px; white-space: nowrap; flex: none; }
.seg.active { background: var(--accent-soft); color: var(--accent); }
.count { margin-left: auto; font-size: 13px; }
.chiprail { display: flex; gap: 7px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.chiprail::-webkit-scrollbar { height: 0; }
.chip {
  background: var(--surface); color: var(--text-2); border: 1px solid var(--border);
  padding: 5px 11px; border-radius: 999px; font-size: 13px; white-space: nowrap; cursor: pointer; flex: none;
}
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.chip-div { width: 1px; background: var(--border); margin: 2px 2px; flex: none; }

/* Bulk bar */
.bulkbar { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--radius-sm);
  padding: 8px 12px; margin: 4px 0 8px; position: sticky; top: 110px; z-index: 9; flex-wrap: wrap; }
.bulk-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* List + cards */
.list { display: flex; flex-direction: column; gap: 6px; }
.card {
  display: grid; grid-template-columns: 26px minmax(0,1fr) auto; gap: 10px; align-items: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; position: relative;
}
.card.unread { box-shadow: inset 2px 0 0 0 var(--accent); }
.card.sel { outline: 2px solid var(--accent); }
.avatar {
  width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 13px; position: relative; flex: none; user-select: none;
}
.avatar .glyph { position: absolute; right: -3px; bottom: -3px; font-size: 9px; line-height: 1;
  background: var(--bg); border-radius: 4px; padding: 1px 2px; border: 1px solid var(--border); }
.avatar img { width: 26px; height: 26px; border-radius: 7px; object-fit: cover; }

.cmain { min-width: 0; }
.cline1 { display: flex; align-items: center; gap: 7px; }
.title { font-weight: 500; color: var(--text); text-decoration: none; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.title:hover { color: var(--accent); }
.card.read .title { color: var(--text-2); font-weight: 400; }
.cline2 { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 12px; color: var(--muted);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cline2 .sep { opacity: .5; }
.cline2 .catp { color: var(--accent); cursor: pointer; }
.cline2 .tagc { color: var(--text-2); cursor: pointer; }
.cline2 .tagc:hover, .cline2 .catp:hover { text-decoration: underline; }

.badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); flex: none; }
.badge.processing { color: var(--accent); border-color: var(--accent); }
.badge.error { color: var(--warn); border-color: var(--warn); }
.badge.new { color: var(--text-2); }

.rail { display: flex; align-items: center; gap: 2px; }
.iconbtn { background: transparent; border: none; color: var(--muted); padding: 5px; cursor: pointer; font-size: 15px; line-height: 1; border-radius: 6px; min-width: 30px; min-height: 30px; }
.iconbtn:hover { color: var(--text); background: var(--surface-2); }
.iconbtn.on { color: var(--star); }
.iconbtn.read.on { color: var(--ok); }
@media (hover: hover) {
  .rail .iconbtn { opacity: 0; transition: opacity .12s; }
  .card:hover .rail .iconbtn, .card:focus-within .rail .iconbtn, .rail .iconbtn.on { opacity: 1; }
}
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 32px; z-index: 8; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(0,0,0,.18); min-width: 150px; overflow: hidden; }
.menu button { display: block; width: 100%; text-align: left; background: transparent; color: var(--text);
  border: none; border-radius: 0; padding: 9px 12px; font-size: 14px; font-weight: 400; }
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--warn); }

.cbox { width: 18px; height: 18px; margin: 4px 0 0; accent-color: var(--accent); cursor: pointer; }

/* Expanded detail */
.detail { grid-column: 1 / -1; margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--border); display: none; }
.card.open .detail { display: block; }
.detail .summary { font-family: var(--serif); font-size: 16.5px; line-height: 1.7; margin: 0 0 10px; color: var(--text); }
.detail .thumb { max-width: 100%; max-height: 150px; border-radius: var(--radius-sm); margin-bottom: 10px; display: block; }
.detail .alltags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.detail .tag { font-size: 12px; color: var(--text-2); background: var(--bg); border: 1px solid var(--border); padding: 1px 7px; border-radius: 6px; cursor: pointer; }
.detail .notes { width: 100%; min-height: 54px; resize: vertical; margin-bottom: 8px; font-size: 14px; }
.detail .row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.detail select { width: auto; padding: 6px 9px; font-size: 13px; }
.detail .err { color: var(--warn); font-size: 13px; margin: 0 0 8px; }
.detail .lbl { font-size: 12px; color: var(--muted); }

/* Knowledge graph view */
.graph { display: flex; flex-direction: column; gap: 14px; }
.graph-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.graph-insights { display: flex; flex-direction: column; gap: 12px; }
.gcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.gcard h3 { margin: 0 0 9px; font-size: 14px; font-weight: 600; }
.gcard .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.theme { padding: 8px 0; border-top: 1px solid var(--border); }
.theme:first-of-type { border-top: none; padding-top: 0; }
.theme-label { font-weight: 600; font-size: 13.5px; }
.theme-size { color: var(--muted); font-size: 12px; font-weight: 400; }
.theme-samples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.gchip { font-size: 12.5px; color: var(--text-2); background: var(--bg); border: 1px solid var(--border);
  padding: 3px 9px; border-radius: 999px; cursor: pointer; }
.gchip:hover { border-color: var(--accent); color: var(--accent); }
.gchip .n { color: var(--muted); }
.gchip.tag { color: var(--accent); }
.bridge { font-size: 13.5px; margin: 7px 0; line-height: 1.45; }
.bridge b { cursor: pointer; color: var(--accent); }
.qrow { display: flex; align-items: center; gap: 8px; margin: 7px 0; }
.qrow span { flex: 1; font-size: 13.5px; }
.qrow button { white-space: nowrap; }

.graph-explorer { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.graph-explorer-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.graph-explorer-head input { flex: 1; min-width: 140px; }
#cy { width: 100%; height: 62vh; min-height: 380px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.graph-legend { font-size: 11.5px; margin: 8px 0 0; }

/* Research Briefs */
.briefs { display: flex; flex-direction: column; gap: 12px; }
.briefs-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.briefs-head-actions { display: flex; gap: 6px; }
.briefs-picker { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius-sm); padding: 10px 12px; }
.briefs-picker select { width: auto; flex: 1; min-width: 160px; }
.briefs-picker button { white-space: nowrap; }
.briefs-intro { font-size: 12.5px; margin: -2px 2px 0; }
.briefs-list { display: flex; flex-direction: column; gap: 10px; }

.brief { padding: 0; overflow: hidden; }
.brief-headline { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 12px 14px; cursor: pointer; }
.brief-headline:hover { background: var(--surface-2); }
.brief-titles { min-width: 0; }
.brief-theme { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; }
.theme-pill { font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; cursor: pointer;
  color: hsl(var(--h) 60% 38%); background: hsl(var(--h) 60% 92%); border: 1px solid hsl(var(--h) 50% 80%); }
@media (prefers-color-scheme: dark) {
  .theme-pill { color: hsl(var(--h) 70% 78%); background: hsl(var(--h) 45% 20%); border-color: hsl(var(--h) 40% 32%); }
}
.theme-pill:hover { filter: brightness(1.05); text-decoration: underline; }
.brief-req { font-size: 11.5px; }
.conf { font-size: 11px; }
.conf-high { color: var(--ok); } .conf-medium { color: var(--star); } .conf-low { color: var(--muted); }
.brief-title { font-weight: 600; font-size: 15px; line-height: 1.35; display: flex; gap: 7px; align-items: baseline; flex-wrap: wrap; }
.brief-tldr { font-size: 13.5px; color: var(--text-2); margin-top: 4px; line-height: 1.45; }
.brief-meta { font-size: 12px; white-space: nowrap; display: flex; align-items: center; gap: 5px; }
.brief-caret { font-size: 11px; }
.brief-counts { display: block; font-size: 11.5px; padding: 0 14px 10px; margin-top: -4px; }
.brief.open .brief-counts { display: none; }

.brief-body { padding: 4px 14px 14px; border-top: 1px solid var(--border); }
.brief-kp { margin: 12px 0; padding-left: 20px; }
.brief-kp li { margin: 4px 0; font-size: 14px; line-height: 1.5; }
.brief-webnote { font-size: 12.5px; margin: 8px 0; }
.brief-md { font-family: var(--serif); font-size: 16px; line-height: 1.65; margin: 10px 0; }
.brief-md h1, .brief-md h2 { font-family: inherit; font-size: 16.5px; font-weight: 700; margin: 18px 0 7px; }
.brief-md h3, .brief-md h4 { font-size: 15px; font-weight: 700; margin: 14px 0 6px; }
.brief-md p { margin: 8px 0; }
.brief-md ul, .brief-md ol { margin: 8px 0; padding-left: 22px; }
.brief-md li { margin: 4px 0; }
.brief-md a { color: var(--accent); }
.brief-md code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.brief-md pre { background: var(--surface-2); padding: 10px 12px; border-radius: var(--radius-sm); overflow-x: auto; }
.brief-md pre code { background: none; padding: 0; }
.brief-md blockquote { margin: 8px 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--text-2); }

.brief-sec { margin-top: 14px; }
.brief-sec h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.brief-sources { display: flex; flex-wrap: wrap; gap: 6px; }
.brief-sources .src-chip { font-size: 12px; color: var(--accent); background: var(--accent-soft); padding: 3px 9px; border-radius: 999px; text-decoration: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-n { font-weight: 700; }
.brief-suggested { display: flex; flex-direction: column; gap: 8px; }
.sugg { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.sugg-main { min-width: 0; }
.sugg-title { font-weight: 500; color: var(--accent); text-decoration: none; }
.sugg-title:hover { text-decoration: underline; }
.sugg-dom { font-size: 12px; }
.sugg-why { font-size: 12.5px; margin-top: 2px; line-height: 1.4; }
.sugg button, .sugg .btn-link { white-space: nowrap; flex: none; }
.btn-link { display: inline-block; text-decoration: none; padding: 5px 10px; font-size: 13px; }
.brief-related { display: flex; flex-wrap: wrap; gap: 6px; }

.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty button { margin-top: 12px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 90vw; }

@media (max-width: 560px) {
  .toolbar { top: 54px; }
  .detail .summary { font-size: 16px; }
  .sort { font-size: 13px; }
}
