:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #15181d;
  --muted: #5b6370;
  --line: #dde1e7;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --accent-soft: #e6edff;
  --danger: #b42318;
  --warn: #9a5b00;
  --ok: #1a7f37;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --line: #2b313b;
    --accent: #7aa2ff;
    --accent-ink: #0b1020;
    --accent-soft: #1d2a4d;
    --danger: #ff8a80;
    --warn: #f0b860;
    --ok: #6ad48a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
code, .mono, pre { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.4rem; }
.sr, .offscreen { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.err { color: var(--danger); min-height: 1.2em; margin: 0.5rem 0 0; }

button, input, textarea {
  font: inherit;
  color: inherit;
}
button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  min-height: 36px;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
button.link { border: 0; background: none; color: var(--accent); padding: 0.2rem 0.35rem; min-height: 0; }
button.link:hover { text-decoration: underline; background: none; }
button.danger, .danger { color: var(--danger); }
button.icon { padding: 0.15rem 0.5rem; min-height: 30px; min-width: 32px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="password"], input[type="search"], input:not([type]), input[inputmode], textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
}
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
label { display: block; font-weight: 600; margin: 0.6rem 0 0.3rem; }
label.check { display: inline-flex; align-items: center; gap: 0.45rem; font-weight: 500; margin: 0.6rem 0; cursor: pointer; }

.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.narrow { width: 100%; max-width: 420px; }
.narrow button.primary { width: 100%; margin-top: 0.8rem; }
.qr { display: block; margin: 0.5rem auto; background: #fff; padding: 8px; border-radius: 8px; max-width: 100%; height: auto; }
.key { font-size: 1.05rem; letter-spacing: 0.04em; text-align: center; word-break: break-all; }
.codes { background: var(--surface-2); padding: 0.8rem; border-radius: 8px; font-size: 1.05rem; line-height: 1.8; text-align: center; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin: 0.5rem 0; }
.row input { width: auto; flex: 0 1 140px; }

/* shell */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.6rem 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; }
.tabs { display: flex; gap: 0.25rem; flex: 1; overflow-x: auto; }
.tab { border: 0; background: none; border-radius: 999px; padding: 0.35rem 0.85rem; white-space: nowrap; }
.tab.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.page { max-width: 1100px; margin: 0 auto; padding: 16px 16px 120px; }

.capture { display: flex; gap: 0.5rem; align-items: stretch; margin-bottom: 0.75rem; }
.capture textarea { resize: vertical; min-height: 44px; }
.toolbar { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.toolbar input[type="search"] { flex: 1 1 220px; width: auto; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }

/* inbox */
.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 0.75rem; box-shadow: var(--shadow); overflow: hidden; }
.ghead { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.15rem 0.85rem; background: var(--surface-2); border-bottom: 1px solid var(--line); font-weight: 600; }
.ghead .check { margin: 0.35rem 0; }
.item { display: grid; grid-template-columns: 28px 1fr; gap: 0.5rem; padding: 0.7rem 0.85rem; border-top: 1px solid var(--line); }
.ghead + .item { border-top: 0; }
.item.reply { padding-left: calc(0.85rem + 1.4rem); }
.item[data-depth="2"] { padding-left: calc(0.85rem + 2.8rem); }
.item[data-depth="3"] { padding-left: calc(0.85rem + 4.2rem); }
.item[data-depth="4"], .item[data-depth="5"], .item[data-depth="6"] { padding-left: calc(0.85rem + 5.6rem); }
.item.thread { padding-left: calc(0.85rem + 0.7rem); border-left: 3px solid var(--accent-soft); }
.item.unsaved { opacity: 0.72; }
.pick { padding-top: 0.15rem; }
.body { min-width: 0; }
.meta { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; font-size: 0.88rem; }
.title { font-weight: 700; margin-top: 0.15rem; }
.text { margin: 0.25rem 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.clamp { display: -webkit-box; -webkit-line-clamp: 5; line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.quote { margin: 0.35rem 0; padding: 0.35rem 0.6rem; border-left: 3px solid var(--line); color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.acts { display: flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; font-size: 0.88rem; }
.acts a { padding: 0.2rem 0.35rem; }
.badge { font-size: 0.72rem; padding: 0.05rem 0.45rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-weight: 600; }
.badge.art { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.ctx { border-style: dashed; }
.badge.warn { color: var(--warn); }
.badge.bad { color: var(--danger); }
.badge.wait { color: var(--accent); }

.mergebar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; justify-content: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 0.45rem 0.6rem 0.45rem 1rem;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18); max-width: calc(100vw - 32px); z-index: 6;
}

/* merge */
.mhead { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.mhead label { margin: 0; }
.mhead #title { flex: 1 1 260px; width: auto; font-weight: 600; }
.slug { font-size: 0.88rem; color: var(--muted); }
.mgrid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.mgroup { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 0.75rem; overflow: hidden; }
.mgroup > p { margin: 0.5rem 0.85rem 0; }
.mfixed, .mitem { display: flex; gap: 0.5rem; align-items: center; padding: 0.5rem 0.85rem; border-top: 1px solid var(--line); }
.ghead + .mfixed { border-top: 0; }
.replies { list-style: none; margin: 0.4rem 0 0; padding: 0; }
.mitem { background: var(--surface); cursor: grab; }
.mitem.dragging { opacity: 0.5; }
.mitem.over { box-shadow: inset 0 2px 0 var(--accent); }
.grip { color: var(--muted); letter-spacing: -2px; }
.num { font-weight: 700; white-space: nowrap; font-size: 0.85rem; }
.who { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.snip { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9rem; }
.mbtns { display: inline-flex; gap: 0.25rem; }
.pcol { position: sticky; top: 64px; }
.pbar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.preview {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.85rem; margin: 0.5rem 0 0; max-height: calc(100vh - 210px); overflow: auto;
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.85rem; line-height: 1.55;
}

/* bundles */
.blist { display: grid; gap: 0.6rem; }
.bcard { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.85rem 1rem; box-shadow: var(--shadow); }

/* security */
table { width: 100%; border-collapse: collapse; margin-top: 0.6rem; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.4rem 0.5rem; border-top: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
th { color: var(--muted); font-weight: 600; border-top: 0; }
tr.gone td { color: var(--muted); text-decoration: line-through; }
tr.badrow td:nth-child(2) { color: var(--danger); }
.paircode { font-size: 2rem; font-weight: 700; letter-spacing: 0.15em; margin: 0.3rem 0; }

#toast {
  position: fixed; left: 50%; top: 16px; transform: translate(-50%, -150%);
  background: var(--text); color: var(--bg); padding: 0.55rem 1rem; border-radius: 999px;
  transition: transform 0.2s ease; z-index: 20; max-width: calc(100vw - 32px); font-weight: 600;
}
#toast.show { transform: translate(-50%, 0); }
#toast.bad { background: var(--danger); color: #fff; }

@media (max-width: 760px) {
  .mgrid { grid-template-columns: 1fr; }
  .pcol { position: static; }
  .item.reply, .item[data-depth] { padding-left: calc(0.85rem + 0.8rem); }
  .capture { flex-direction: column; }
  table.log td:nth-child(3) { display: none; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

.badge.linkish { cursor: pointer; font: inherit; font-size: 0.72rem; min-height: 0; padding: 0.05rem 0.45rem; }
.badge.linkish:hover { color: var(--accent); }
.gright { display: inline-flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
button.small-btn { min-height: 28px; padding: 0.15rem 0.6rem; font-size: 0.85rem; }
.mergebar select { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; padding: 0.4rem 0.5rem; font: inherit; max-width: 220px; }


/* ---- sidebar layout ---- */
.top .spacer { flex: 1; }
.layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); align-items: start; }
.side {
  position: sticky; top: 49px; height: calc(100vh - 49px); overflow-y: auto;
  border-right: 1px solid var(--line); background: var(--surface); padding: 12px 10px 24px;
  display: flex; flex-direction: column; gap: 2px;
}
.side nav { display: flex; flex-direction: column; gap: 2px; }
.navbtn {
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; width: 100%;
  border: 0; background: none; border-radius: 8px; padding: 0.4rem 0.6rem; min-height: 34px; text-align: left;
}
.navbtn:hover { background: var(--surface-2); }
.navbtn.on, .navrow.on > .navbtn { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.navrow { display: flex; align-items: center; gap: 2px; }
.navrow > .navbtn { flex: 1; min-width: 0; }
.navrow > .navbtn span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rowacts { display: none; gap: 2px; }
.navrow:hover .rowacts, .navrow:focus-within .rowacts { display: inline-flex; }
button.icon.tiny { min-width: 24px; min-height: 24px; padding: 0 0.3rem; font-size: 0.8rem; }
.count { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.sidehead { display: flex; justify-content: space-between; align-items: center; margin: 14px 0.6rem 4px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.sidehead .link { text-transform: none; letter-spacing: 0; font-weight: 600; }
.sidesel, .mergebar select, .orgrow select { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; padding: 0.35rem 0.5rem; font: inherit; }
.sidesel { margin: 0 0.4rem; }
.sidefoot { margin-top: auto; padding-top: 16px; }
.tagcloud { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 0.4rem; }
button.tag { border: 1px solid var(--line); border-radius: 999px; padding: 0.1rem 0.55rem; min-height: 26px; font-size: 0.82rem; background: var(--surface); }
button.tag.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin: -0.25rem 0 0.75rem; }
button.chip { border-radius: 999px; padding: 0.1rem 0.6rem; min-height: 28px; font-size: 0.85rem; background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.metaline { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; margin-top: 0.35rem; }
.prio { font-size: 0.72rem; font-weight: 700; padding: 0.05rem 0.45rem; border-radius: 999px; border: 1px solid var(--line); }
.prio.p3 { color: var(--danger); border-color: currentColor; }
.prio.p2 { color: var(--warn); border-color: currentColor; }
.prio.p1 { color: var(--muted); }
.catpill { font-size: 0.75rem; font-weight: 600; padding: 0.05rem 0.5rem; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); }
.tagchip { display: inline-flex; align-items: center; gap: 2px; font-size: 0.78rem; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 0 0.15rem 0 0.5rem; }
button.tagx { border: 0; background: none; color: inherit; min-height: 0; padding: 0 0.3rem; font-size: 0.85rem; line-height: 1.4; }
.orgrow { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; margin-bottom: 0.25rem; }
label.inline, span.inline { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0; font-weight: 600; font-size: 0.9rem; flex-wrap: wrap; }
.page { margin: 0; max-width: 1100px; width: 100%; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .rowacts { display: inline-flex; }
}

.toastbtn { margin-left: 0.75rem; background: transparent; color: inherit; border: 1px solid currentColor; border-radius: 999px; min-height: 26px; padding: 0 0.7rem; font-weight: 700; }
#toast { display: flex; align-items: center; }
.nopick { display: inline-block; width: 18px; }

