/* mymatrix web UI — warm "wood" design system.
   Layout: icon rail | list column | detail (+ right drawer). Mobile: list/detail stacked + bottom tabs.
   Tokens drive everything; light by default, dark via [data-theme] / prefers-color-scheme. */

:root {
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px;
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-xl: 18px; --r-full: 999px;
  --fs-xs: 11.5px; --fs-sm: 13px; --fs-md: 14px; --fs-lg: 16px; --fs-xl: 20px; --fs-2xl: 26px; --fs-hero: 44px;
  --ff: 'Manrope', system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;
  --ff-mono: 'SFMono-Regular', ui-monospace, Menlo, Consolas, 'Liberation Mono', monospace;
  --ease: cubic-bezier(.2, .6, .2, 1);
  --rail-w: 56px; --list-w: 288px; --drawer-w: 380px;

  /* light — warm paper + wood */
  --bg: #f8f5ef;
  --list-bg: #efe9df;
  --surface: #fffdf9;
  --surface-2: #f3eee6;
  --border: #e5ddd0;
  --border-strong: #d6cab8;
  --fg: #2a2119;
  --fg-muted: #7a6a58;
  --fg-faint: #a69684;
  --accent: #a5682b;
  --accent-fg: #ffffff;
  --accent-soft: #f4e6d4;
  --agent: #2f8f6a;
  --agent-soft: #e2f1e9;
  --danger: #c4452f;
  --warn: #c98a17;
  --ok: #3c9a5f;
  --wood-1: #d9a35f; --wood-2: #c98f4c; --wood-3: #e3b273; --wood-fg: #3a2612;
  --shadow-1: 0 1px 2px rgba(60, 40, 20, .06), 0 1px 3px rgba(60, 40, 20, .05);
  --shadow-2: 0 4px 14px rgba(60, 40, 20, .10), 0 2px 6px rgba(60, 40, 20, .06);
  --shadow-pop: 0 14px 40px rgba(60, 40, 20, .18);
  --hover: rgba(90, 60, 20, .06);
  --active: rgba(165, 104, 43, .14);
}

:root[data-theme='dark'], :root[data-theme='auto'] { color-scheme: light dark; }
@media (prefers-color-scheme: dark) {
  :root[data-theme='auto'] {
    --bg: #1b1713; --list-bg: #221c17; --surface: #26201a; --surface-2: #2e2720; --border: #3a3129; --border-strong: #4a3f34;
    --fg: #f1e8dc; --fg-muted: #b5a491; --fg-faint: #7f705f;
    --accent: #e3a864; --accent-fg: #24180c; --accent-soft: #3b2c1d;
    --agent: #5cc79b; --agent-soft: #1d3329; --danger: #ff7a62; --warn: #f0b84a; --ok: #6fcf8f;
    --wood-1: #6b4627; --wood-2: #5a3a20; --wood-3: #7a5230; --wood-fg: #f6dfbf;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4); --shadow-2: 0 6px 16px rgba(0,0,0,.5); --shadow-pop: 0 14px 40px rgba(0,0,0,.6);
    --hover: rgba(255,240,220,.06); --active: rgba(227,168,100,.18);
  }
}
:root[data-theme='dark'] {
  --bg: #1b1713; --list-bg: #221c17; --surface: #26201a; --surface-2: #2e2720; --border: #3a3129; --border-strong: #4a3f34;
  --fg: #f1e8dc; --fg-muted: #b5a491; --fg-faint: #7f705f;
  --accent: #e3a864; --accent-fg: #24180c; --accent-soft: #3b2c1d;
  --agent: #5cc79b; --agent-soft: #1d3329; --danger: #ff7a62; --warn: #f0b84a; --ok: #6fcf8f;
  --wood-1: #6b4627; --wood-2: #5a3a20; --wood-3: #7a5230; --wood-fg: #f6dfbf;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4); --shadow-2: 0 6px 16px rgba(0,0,0,.5); --shadow-pop: 0 14px 40px rgba(0,0,0,.6);
  --hover: rgba(255,240,220,.06); --active: rgba(227,168,100,.18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--ff); font-size: var(--fs-md); line-height: 1.5; color: var(--fg);
  background: var(--bg); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
::selection { background: var(--active); }
.scroll::-webkit-scrollbar, .list__body::-webkit-scrollbar, .detail__scroll::-webkit-scrollbar, .messages::-webkit-scrollbar { width: 10px; }
.scroll::-webkit-scrollbar-thumb, .list__body::-webkit-scrollbar-thumb, .detail__scroll::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: var(--r-full); border: 3px solid transparent; background-clip: padding-box;
}
.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ic--sm { width: 15px; height: 15px; }
.ic--lg { width: 22px; height: 22px; }

/* wood texture: layered stripes give a grain */
.wood {
  background-color: var(--wood-1);
  background-image:
    repeating-linear-gradient(92deg, transparent 0 7px, rgba(255,255,255,.07) 7px 8px, transparent 8px 19px),
    repeating-linear-gradient(88deg, rgba(0,0,0,.05) 0 2px, transparent 2px 13px),
    linear-gradient(180deg, var(--wood-3), var(--wood-1) 40%, var(--wood-2));
  color: var(--wood-fg);
}

/* ================= app shell ================= */
.app { height: 100dvh; display: grid; grid-template-columns: var(--rail-w) var(--list-w) minmax(0, 1fr); overflow: hidden; }
.app.has-drawer { grid-template-columns: var(--rail-w) var(--list-w) minmax(0, 1fr) var(--drawer-w); }

/* rail */
.rail { display: flex; flex-direction: column; align-items: center; gap: var(--s1); padding: var(--s3) 0; overflow-y: auto; }
.rail__items { display: flex; flex-direction: column; gap: 2px; margin-top: var(--s3); }
.rail__spacer { flex: 1; }
.rail__btn, .rail__me {
  position: relative; width: 40px; height: 40px; border-radius: var(--r-full); display: grid; place-items: center;
  color: var(--wood-fg); opacity: .85; transition: background .15s var(--ease), opacity .15s;
}
.rail__btn:hover { background: rgba(255,255,255,.22); opacity: 1; }
.rail__btn.is-active { background: rgba(255,250,240,.75); opacity: 1; color: #6b3f12; box-shadow: var(--shadow-1); }
:root[data-theme='dark'] .rail__btn.is-active { background: rgba(255,230,190,.2); color: var(--wood-fg); }
@media (prefers-color-scheme: dark) { :root[data-theme='auto'] .rail__btn.is-active { background: rgba(255,230,190,.2); color: var(--wood-fg); } }
.rail__me { opacity: 1; }
.rail__me .avatar { width: 36px; height: 36px; font-size: 13px; box-shadow: 0 0 0 2px rgba(255,255,255,.6); }
.rail__btn .tip {
  position: absolute; left: 48px; top: 50%; transform: translateY(-50%); white-space: nowrap; pointer-events: none;
  background: var(--fg); color: var(--bg); font-size: var(--fs-xs); font-weight: 600; padding: 3px 8px; border-radius: var(--r-sm);
  opacity: 0; transition: opacity .12s; z-index: 50;
}
.rail__btn:hover .tip { opacity: 1; }
.dot-badge { position: absolute; top: 5px; right: 5px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: var(--r-full);
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; line-height: 16px; text-align: center; }

/* list column */
.list { background: var(--list-bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.list__head { padding: var(--s3) var(--s3) var(--s2); display: flex; flex-direction: column; gap: var(--s2); }
.list__title { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-muted); padding: var(--s1) var(--s2); }
.list__body { flex: 1; overflow-y: auto; padding: 0 var(--s2) var(--s4); }
.list__new {
  display: flex; align-items: center; gap: var(--s2); width: 100%; padding: 9px var(--s3); border-radius: var(--r-md);
  font-weight: 600; color: var(--fg); background: var(--surface); box-shadow: var(--shadow-1);
}
.list__new:hover { background: var(--surface-2); }
.group-label { display: inline-flex; align-items: center; gap: 5px; margin: var(--s3) var(--s2) var(--s1); padding: 1px 8px;
  font-size: var(--fs-xs); font-weight: 700; color: var(--fg-muted); background: var(--surface-2); border-radius: var(--r-full); }
.group-label--attn { color: #fff; background: var(--danger); }
.group-label--pin { color: var(--accent); background: var(--accent-soft); }

.space-switch { display: flex; align-items: center; gap: var(--s2); width: 100%; padding: 6px var(--s2); border-radius: var(--r-md); font-weight: 800; font-size: var(--fs-lg); }
.space-switch:hover { background: var(--hover); }
.space-switch__name { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.space-menu { position: absolute; z-index: 40; left: calc(var(--rail-w) + 10px); top: 52px; width: 260px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-pop); padding: var(--s1); }
.space-menu__item { display: flex; align-items: center; gap: var(--s2); width: 100%; padding: 8px var(--s2); border-radius: var(--r-sm); text-align: left; }
.space-menu__item:hover { background: var(--hover); }
.space-menu__item.is-active { background: var(--active); font-weight: 700; }
.space-menu__divider { height: 1px; background: var(--border); margin: var(--s1) 0; }

/* list rows */
.row { display: flex; gap: var(--s2); align-items: flex-start; width: 100%; padding: 8px var(--s2); border-radius: var(--r-md); text-align: left; position: relative; }
.row:hover { background: var(--hover); }
.row.is-active { background: var(--surface); box-shadow: var(--shadow-1); }
.row__glyph { width: 18px; color: var(--fg-faint); font-weight: 700; flex: none; text-align: center; line-height: 20px; }
.row__main { flex: 1; min-width: 0; }
.row__top { display: flex; align-items: baseline; gap: var(--s2); }
.row__name { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__name.is-unread { font-weight: 800; }
.row__time { font-size: var(--fs-xs); color: var(--fg-faint); flex: none; }
.row__sub { font-size: var(--fs-sm); color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__meta { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.row__count { margin-left: auto; font-size: var(--fs-xs); color: var(--fg-muted); font-weight: 700; }
.row__pin { position: absolute; right: 6px; bottom: 6px; opacity: 0; color: var(--fg-faint); padding: 2px; border-radius: var(--r-sm); }
.row:hover .row__pin, .row__pin.is-on { opacity: 1; }
.row__pin.is-on { color: var(--accent); }
.unread-badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-full); background: var(--accent); color: var(--accent-fg);
  font-size: 11px; font-weight: 800; line-height: 18px; text-align: center; flex: none; }
.unread-badge--attn { background: var(--danger); color: #fff; }
.mini-avatars { display: inline-flex; }
.mini-avatars .avatar { width: 16px; height: 16px; font-size: 8px; margin-left: -4px; box-shadow: 0 0 0 1.5px var(--list-bg); }
.mini-avatars .avatar:first-child { margin-left: 0; }
.sub-row { padding-left: 34px; }
.empty-list { padding: var(--s4) var(--s3); color: var(--fg-muted); font-size: var(--fs-sm); }

/* bars (cpu/mem/quota) */
.bars { display: flex; gap: 8px; flex: none; }
.bar { width: 42px; }
.bar__label { display: flex; justify-content: space-between; font-size: 9.5px; color: var(--fg-muted); line-height: 1.2; }
.bar__label b { color: var(--fg); }
.bar__track { height: 3px; border-radius: 2px; background: var(--border); overflow: hidden; margin-top: 2px; }
.bar__fill { height: 100%; background: var(--fg-muted); }
.bar__fill--ok { background: var(--ok); } .bar__fill--warn { background: var(--warn); } .bar__fill--hot { background: var(--danger); }

/* ================= detail ================= */
.detail { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); position: relative; }
.detail__bar { display: flex; align-items: center; gap: var(--s2); min-height: 52px; padding: var(--s2) var(--s4); border-bottom: 1px solid var(--border); }
.detail__back { display: none; }
.detail__title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.detail__title h1 { margin: 0; font-size: var(--fs-lg); font-weight: 800; display: flex; align-items: center; gap: 6px; min-width: 0; }
.detail__title h1 span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail__topic { font-size: var(--fs-sm); color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail__actions { display: flex; align-items: center; gap: 2px; }
.detail__scroll { flex: 1; overflow-y: auto; }
.page-wrap { max-width: 860px; margin: 0 auto; padding: var(--s6) var(--s6) var(--s10); }
.crumb { font-size: var(--fs-xs); color: var(--fg-muted); font-weight: 600; }
.h-title { font-size: var(--fs-2xl); font-weight: 800; margin: 2px 0 var(--s1); letter-spacing: -.01em; }
.h-sub { color: var(--fg-muted); margin: 0 0 var(--s5); }
.section { margin-top: var(--s6); }
.section__head { display: flex; align-items: center; gap: var(--s2); padding-bottom: var(--s2); border-bottom: 1px solid var(--border); margin-bottom: var(--s3); }
.section__head h2 { margin: 0; font-size: var(--fs-md); font-weight: 800; flex: 1; }
.section__link { font-size: var(--fs-sm); font-weight: 600; color: var(--fg-muted); display: inline-flex; align-items: center; gap: 2px; }
.section__link:hover { color: var(--fg); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px var(--s4); font-size: var(--fs-sm); }
.kv dt { color: var(--fg-muted); }
.kv dd { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4); box-shadow: var(--shadow-1); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--s3); }
.stat__v { font-size: var(--fs-xl); font-weight: 800; }
.stat__l { font-size: var(--fs-xs); color: var(--fg-muted); font-weight: 600; }
.hero { display: flex; align-items: baseline; gap: var(--s3); }
.hero__n { font-size: var(--fs-hero); font-weight: 800; line-height: 1; }
.hero__l { font-size: var(--fs-lg); font-weight: 700; }
.muted { color: var(--fg-muted); }
.faint { color: var(--fg-faint); }
.mono { font-family: var(--ff-mono); font-size: .92em; }
.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.tbl th { text-align: left; font-weight: 700; color: var(--fg-muted); font-size: var(--fs-xs); padding: 6px 8px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl-wrap { overflow-x: auto; }
.res { display: grid; grid-template-columns: 110px 1fr auto; gap: 6px var(--s3); align-items: center; font-size: var(--fs-sm); }
.res .bar__track { height: 6px; }
.res__v { font-weight: 700; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; font-size: var(--fs-xs); font-weight: 600; border-radius: var(--r-full);
  background: var(--surface-2); color: var(--fg-muted); border: 1px solid var(--border); white-space: nowrap; }
.chip--ok { color: var(--ok); } .chip--warn { color: var(--warn); } .chip--danger { color: var(--danger); } .chip--accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-faint); flex: none; display: inline-block; }
.status-dot--on { background: var(--ok); } .status-dot--busy { background: var(--warn); } .status-dot--rest { background: var(--warn); } .status-dot--off { background: var(--border-strong); }
.agent-strip { display: flex; flex-wrap: wrap; gap: var(--s4); }
.agent-pill { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
.sparkbars { display: flex; align-items: flex-end; gap: 3px; height: 60px; }
.sparkbars i { flex: 1; background: var(--accent); opacity: .7; border-radius: 2px 2px 0 0; min-height: 2px; }
.empty-big { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: var(--s2); color: var(--fg-muted); padding: var(--s10) var(--s6); height: 100%; }
.empty-big__ic { width: 44px; height: 44px; border-radius: var(--r-md); background: var(--surface-2); display: grid; place-items: center; color: var(--fg); }
.empty-big__t { font-weight: 800; color: var(--fg); font-size: var(--fs-lg); }
.empty-big p { max-width: 420px; margin: 0; }
.howto { background: var(--surface-2); border-radius: var(--r-md); padding: var(--s3); font-family: var(--ff-mono); font-size: var(--fs-sm); white-space: pre-wrap; word-break: break-all; }

/* buttons */
.icon-btn { width: 34px; height: 34px; border-radius: var(--r-md); display: inline-grid; place-items: center; color: var(--fg-muted); position: relative; flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn.is-on { color: var(--accent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 var(--s3); border-radius: var(--r-md);
  font-weight: 700; font-size: var(--fs-sm); border: 1px solid transparent; transition: background .15s, border-color .15s; white-space: nowrap; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--accent); color: var(--accent-fg); }
.btn--primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn--ghost { background: var(--surface); border-color: var(--border); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn--danger { color: var(--danger); }
.btn--sm { height: 28px; padding: 0 10px; font-size: var(--fs-xs); }
.btn--full { width: 100%; height: 40px; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s2); }

/* forms */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--s3); }
.field__label { font-size: var(--fs-xs); font-weight: 700; color: var(--fg-muted); }
.field__hint { font-size: var(--fs-xs); color: var(--fg-faint); }
.field__input, .field__select, .field__textarea {
  width: 100%; height: 38px; padding: 0 var(--s3); border-radius: var(--r-md); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--fg); outline: none; transition: border-color .15s, box-shadow .15s;
}
.field__textarea { height: auto; padding: var(--s2) var(--s3); resize: vertical; line-height: 1.5; }
.field__input:focus, .field__select:focus, .field__textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--active); }
.switch-row { display: flex; align-items: center; gap: var(--s4); padding: var(--s2) 0; }
.switch-row__txt { flex: 1; }
.switch-row__t { font-weight: 700; }
.switch-row__d { font-size: var(--fs-sm); color: var(--fg-muted); }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; border-radius: var(--r-full); background: var(--border-strong); transition: background .15s; cursor: pointer; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s var(--ease); box-shadow: var(--shadow-1); }
.switch input:checked + i { background: var(--fg); }
.switch input:checked + i::after { transform: translateX(16px); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--r-md); padding: 3px; gap: 2px; }
.seg__btn { padding: 5px 12px; border-radius: var(--r-sm); font-size: var(--fs-sm); font-weight: 600; color: var(--fg-muted); }
.seg__btn.is-active { background: var(--surface); color: var(--fg); box-shadow: var(--shadow-1); }

/* avatar */
.avatar { width: 32px; height: 32px; border-radius: var(--r-full); display: inline-grid; place-items: center; color: #fff; font-weight: 800; font-size: 12px; flex: none; letter-spacing: .02em; }
.avatar--sq { border-radius: 9px; }
.avatar--sm { width: 22px; height: 22px; font-size: 9.5px; }

/* ================= channel view ================= */
.chan { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.goalbar { display: flex; flex-wrap: wrap; gap: var(--s2); padding: var(--s2) var(--s4); border-bottom: 1px solid var(--border); background: var(--surface); }
.goal-chip { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); padding: 3px 10px; border-radius: var(--r-full); background: var(--agent-soft); color: var(--agent); }
.goal-chip b { font-weight: 800; }
.messages { flex: 1; overflow-y: auto; padding: var(--s4) 0 var(--s2); }
.day-sep { display: flex; align-items: center; gap: var(--s3); margin: var(--s3) var(--s5); color: var(--fg-faint); font-size: var(--fs-xs); font-weight: 700; }
.day-sep::before, .day-sep::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.msg { position: relative; display: flex; gap: var(--s3); padding: 6px var(--s5); }
.msg:hover { background: var(--hover); }
.msg.is-hl { background: var(--accent-soft); }
.msg--grouped { padding-top: 1px; }
.msg--grouped .msg__avatar { visibility: hidden; height: 0; }
.msg--grouped .msg__head { display: none; }
.msg__avatar { margin-top: 2px; }
.msg__main { flex: 1; min-width: 0; }
.msg__head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.msg__author { font-weight: 800; }
.msg__time { font-size: var(--fs-xs); color: var(--fg-faint); }
.msg__edited { font-size: var(--fs-xs); color: var(--fg-faint); }
.msg__badge { font-size: 10px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--agent); background: var(--agent-soft); padding: 0 6px; border-radius: var(--r-sm); }
.msg__quote { display: flex; gap: 6px; align-items: center; font-size: var(--fs-sm); color: var(--fg-muted); margin: 2px 0; cursor: pointer; min-width: 0; }
.msg__quote::before { content: ''; width: 14px; height: 9px; border-left: 2px solid var(--border-strong); border-top: 2px solid var(--border-strong); border-top-left-radius: 6px; margin-top: 6px; flex: none; }
.msg__quote b { color: var(--fg); font-weight: 700; flex: none; }
.msg__quote span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg__body { overflow-wrap: anywhere; }
.msg__body p { margin: 0 0 4px; } .msg__body p:last-child { margin-bottom: 0; }
.msg__body pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s2) var(--s3); overflow-x: auto; font-size: 12.5px; }
.msg__body code { font-family: var(--ff-mono); font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.msg__body pre code { background: none; padding: 0; }
.msg__body h1, .msg__body h2, .msg__body h3 { font-size: 1.05em; margin: 6px 0 4px; }
.msg__body ul, .msg__body ol { margin: 2px 0 4px; padding-left: 22px; }
.msg__body table { border-collapse: collapse; margin: 4px 0; font-size: var(--fs-sm); }
.msg__body th, .msg__body td { border: 1px solid var(--border); padding: 3px 8px; }
.msg__body blockquote { margin: 4px 0; padding-left: 10px; border-left: 3px solid var(--border-strong); color: var(--fg-muted); }
.msg__recalled { color: var(--fg-faint); font-style: italic; font-size: var(--fs-sm); }
.mention { color: var(--accent); background: var(--accent-soft); padding: 0 3px; border-radius: 4px; font-weight: 700; }
.mention--agent { color: var(--agent); background: var(--agent-soft); }
.ref-chip { display: inline-flex; align-items: center; gap: 3px; padding: 0 6px; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--border); font-weight: 600; font-size: .92em; cursor: pointer; color: var(--fg); text-decoration: none; }
.msg__reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.react { display: inline-flex; align-items: center; gap: 4px; padding: 0 8px; height: 24px; border-radius: var(--r-full); border: 1px solid var(--border); background: var(--surface); font-size: var(--fs-sm); }
.react.is-mine { border-color: var(--accent); background: var(--accent-soft); }
.react b { font-size: var(--fs-xs); font-weight: 700; color: var(--fg-muted); }
.msg__thread { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; font-size: var(--fs-sm); font-weight: 700; color: var(--accent); }
.msg__tools { position: absolute; right: var(--s4); top: -14px; display: none; gap: 1px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-2); padding: 2px; z-index: 5; }
.msg:hover .msg__tools, .msg__tools.is-open { display: flex; }
.msg__tools .icon-btn { width: 28px; height: 28px; }
.quick-reacts { position: absolute; right: 0; top: 34px; display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-2); padding: 3px; }
.quick-reacts button { width: 30px; height: 30px; border-radius: var(--r-sm); font-size: 17px; }
.quick-reacts button:hover { background: var(--hover); }
.msg-edit textarea { width: 100%; min-height: 60px; }
.atts { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: 6px; }
.att-img img { max-width: 320px; max-height: 240px; border-radius: var(--r-md); border: 1px solid var(--border); display: block; }
.att-file { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); text-decoration: none; color: var(--fg); }
.att-file__name { font-weight: 700; font-size: var(--fs-sm); }
.att-file__size { font-size: var(--fs-xs); color: var(--fg-muted); }
.approval { margin: var(--s2) var(--s5); padding: var(--s3); border: 1px solid var(--warn); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-1); }
.approval__head { display: flex; align-items: center; gap: var(--s2); font-weight: 700; }
.approval__detail { white-space: pre-wrap; font-family: var(--ff-mono); font-size: 12px; background: var(--surface-2); border-radius: var(--r-md); padding: var(--s2); max-height: 200px; overflow: auto; }
.approval__opts { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s2); }
.runbar { display: flex; flex-direction: column; gap: 4px; padding: var(--s2) var(--s4); border-top: 1px solid var(--border); background: var(--surface); }
.run-row { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); }
.run-row__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); animation: pulse 1.4s infinite; }
.run-row__who { font-weight: 800; }
.run-row__meta { color: var(--fg-muted); flex: 1; }
@keyframes pulse { 50% { opacity: .35; } }
.typing { display: flex; align-items: center; gap: var(--s2); padding: 4px var(--s5); color: var(--agent); font-size: var(--fs-sm); font-weight: 600; }
.typing__dots i { display: inline-block; width: 5px; height: 5px; margin-right: 2px; border-radius: 50%; background: currentColor; animation: pulse 1.2s infinite; }
.typing__dots i:nth-child(2) { animation-delay: .2s; } .typing__dots i:nth-child(3) { animation-delay: .4s; }

.composer { padding: var(--s2) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom)); }
.composer__box { position: relative; display: flex; align-items: flex-end; gap: var(--s1); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-xl); padding: 6px; box-shadow: var(--shadow-1); }
.composer__box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--active); }
.composer__reply { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--fg-muted); padding: 2px var(--s3) 6px; }
.composer__reply b { color: var(--fg); }
.composer__input { flex: 1; resize: none; border: 0; outline: none; background: transparent; padding: 7px 6px; max-height: 220px; line-height: 1.45; }
.send-btn { width: 34px; height: 34px; border-radius: var(--r-full); display: grid; place-items: center; background: var(--accent); color: var(--accent-fg); flex: none; }
.send-btn:disabled { background: var(--surface-2); color: var(--fg-faint); cursor: default; }
.attach-strip { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 6px 6px; width: 100%; }
.att-chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: var(--r-full); background: var(--surface-2); font-size: var(--fs-xs); font-weight: 600; }
.att-chip__x { font-size: 14px; line-height: 1; color: var(--fg-muted); }
.pop { position: absolute; left: 6px; right: 6px; bottom: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); padding: 4px; max-height: 300px; overflow-y: auto; z-index: 20; }
.pop__label { font-size: var(--fs-xs); font-weight: 700; color: var(--fg-muted); padding: 4px 8px; }
.pop-item { display: flex; align-items: center; gap: var(--s2); padding: 6px 8px; border-radius: var(--r-sm); cursor: pointer; }
.pop-item.is-active, .pop-item:hover { background: var(--active); }
.pop-item__name { font-weight: 700; }
.pop-item__desc { font-size: var(--fs-xs); color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-item__tag { margin-left: auto; font-size: var(--fs-xs); color: var(--fg-faint); font-family: var(--ff-mono); }

/* drawer (channel details, thread) */
.drawer { background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.drawer__head { display: flex; align-items: center; gap: var(--s2); min-height: 52px; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border); }
.drawer__title { flex: 1; font-weight: 800; }
.drawer__body { flex: 1; overflow-y: auto; padding: var(--s4); }
.drawer .messages { padding-top: var(--s2); }

/* pages */
.doc { max-width: 820px; margin: 0 auto; padding: var(--s5) var(--s6) var(--s10); }
.doc__body { font-size: 15px; line-height: 1.7; }
.doc__body h1 { font-size: 28px; font-weight: 800; margin: var(--s4) 0 var(--s3); }
.doc__body h1::before { content: '# '; color: var(--fg-faint); }
.doc__body h2 { font-size: 20px; font-weight: 800; margin: var(--s6) 0 var(--s2); }
.doc__body h3 { font-size: 16px; font-weight: 800; margin: var(--s5) 0 var(--s2); }
.doc__body pre { background: var(--surface-2); border-radius: var(--r-md); padding: var(--s3); overflow-x: auto; font-size: 13px; }
.doc__body code { font-family: var(--ff-mono); font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.doc__body pre code { background: none; padding: 0; }
.doc__body table { border-collapse: collapse; } .doc__body th, .doc__body td { border: 1px solid var(--border); padding: 4px 10px; }
.sec-h { position: relative; }
.sec-tools { position: absolute; right: 0; top: 50%; transform: translateY(-50%); display: none; gap: 2px; }
.sec-h:hover .sec-tools { display: flex; }
.sec-tools .icon-btn { width: 28px; height: 28px; }
.banner { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-2); margin-bottom: var(--s4); }
.banner__txt { flex: 1; }
.banner__t { font-weight: 800; font-size: var(--fs-sm); }
.banner__d { font-size: var(--fs-xs); color: var(--fg-muted); }
.diff { font-family: var(--ff-mono); font-size: 12.5px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); overflow: auto; max-height: 420px; margin-bottom: var(--s4); }
.diff div { white-space: pre-wrap; padding: 0 var(--s3); }
.diff .add { background: rgba(60,154,95,.14); } .diff .del { background: rgba(196,69,47,.12); text-decoration: line-through; color: var(--fg-muted); }
.doc-edit textarea { width: 100%; min-height: 60vh; font-family: var(--ff-mono); font-size: 13.5px; line-height: 1.6; }
.rev-row { display: flex; gap: var(--s3); align-items: center; width: 100%; padding: var(--s2); border-radius: var(--r-md); text-align: left; }
.rev-row:hover { background: var(--hover); }
.rev-row__n { font-family: var(--ff-mono); font-weight: 700; color: var(--accent); width: 40px; }
.rev-row .btn { flex: none; }
.modal:has(.modal__wide) { width: min(820px, 100%); }
.modal__wide .diff { max-height: 64vh; }
.banner--attn { border-color: var(--accent); background: var(--accent-soft); }
.page-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: 600; color: var(--fg-muted); margin-bottom: var(--s3); }
.page-crumbs a { color: var(--fg-muted); text-decoration: none; }
.page-crumbs a:hover { color: var(--accent); text-decoration: underline; }
.page-crumbs__cur { color: var(--fg); }
.sec-anchor { position: absolute; left: -1.1em; width: 1em; color: var(--fg-faint); text-decoration: none; opacity: 0; font-weight: 700; }
.sec-h:hover .sec-anchor { opacity: 1; }
.sec-h.is-target { background: var(--accent-soft); border-radius: var(--r-sm); }
.sec-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 var(--s2); }
.sec-meta .chip, .page-link { text-decoration: none; cursor: pointer; }
.page-link a { color: inherit; text-decoration: none; }
.page-link__x { margin-left: 2px; color: var(--fg-faint); cursor: pointer; }
.page-link__x:hover { color: var(--danger); }
.sec-discuss { border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--r-md); background: var(--surface); padding: var(--s3); margin: var(--s2) 0 var(--s4); font-size: var(--fs-sm); line-height: 1.5; }
.sec-discuss__head { display: flex; align-items: center; margin-bottom: var(--s2); }
.sec-thread { border-bottom: 1px solid var(--border); padding-bottom: var(--s2); margin-bottom: var(--s2); }
.sec-thread.is-resolved { opacity: .6; }
.sec-thread .btn-row { margin-top: 6px; }
.sec-thread .btn-row .field__input { flex: 1; height: 32px; }
.sec-comment { padding: 4px 0; }
.sec-comment__head { display: flex; gap: var(--s2); align-items: baseline; font-size: var(--fs-xs); }
.sec-comment__del { margin-left: auto; color: var(--fg-faint); cursor: pointer; }
.sec-comment__del:hover { color: var(--danger); }
.page-foot { margin-top: var(--s8); border-top: 1px solid var(--border); padding-top: var(--s3); }
.page-foot .section { margin-top: var(--s4); }
.conflict { margin-bottom: var(--s3); }
.conflict summary { cursor: pointer; font-weight: 700; font-size: var(--fs-sm); margin-bottom: var(--s2); }
.page-row__caret { width: 16px; height: 20px; flex: none; display: grid; place-items: center; color: var(--fg-faint); cursor: pointer; margin-right: -6px; }
.page-row__caret .ic { transition: transform .15s; }
.page-row__caret.is-open .ic { transform: rotate(90deg); }
.page-row__caret.is-leaf { cursor: default; }
.page-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; align-self: center; margin-left: auto; }
.page-row[data-drop=inside] { box-shadow: inset 0 0 0 2px var(--accent); }
.page-row[data-drop=before] { box-shadow: inset 0 2px 0 var(--accent); }
.page-row[data-drop=after] { box-shadow: inset 0 -2px 0 var(--accent); }
.page-tree__root { margin: var(--s1) var(--s2); padding: 4px; font-size: var(--fs-xs); color: var(--fg-faint); text-align: center; border: 1px dashed transparent; border-radius: var(--r-md); }
.page-tree__root.is-over { border-color: var(--accent); color: var(--accent); }
.page-cards { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; max-width: 460px; }
.page-card { display: block; padding: 8px 12px; border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--r-md); background: var(--surface); color: var(--fg); text-decoration: none; }
.page-card:hover { background: var(--hover); }
.page-card__t { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: var(--fs-sm); }
.page-card__d { font-size: var(--fs-xs); color: var(--fg-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* ---- pages, part 2: live co-editing, share/access, claims, authorship, suggestions, public view ---- */
.list__actions { display: flex; gap: var(--s2); }
.list__actions .list__new { flex: 1; min-width: 0; }
.page-flag { font-size: 11px; flex: none; }
.row.is-done .row__name { color: var(--fg-muted); text-decoration: line-through; text-decoration-color: var(--fg-faint); }
.icon-btn.is-on { color: var(--ok); }
.page-flags { margin: 0 0 var(--s2); }
.page-flags a.chip { text-decoration: none; }
.page-summary { font-size: var(--fs-sm); color: var(--fg-muted); margin: 0 0 var(--s3); min-height: 1.5em; overflow-wrap: anywhere; }
.page-summary.is-editable { cursor: text; border-radius: var(--r-sm); }
.page-summary.is-editable:hover { background: var(--hover); }
.page-summary__input { width: 100%; height: 32px; }
.live-peers { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-width: 0; }
.page-peers:empty { display: none; }
.page-peers { margin: 0 0 var(--s3); }
.live-peer { --peer: var(--accent); display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-xs); font-weight: 700; padding: 1px 8px 1px 6px; border-radius: var(--r-full); border: 1px solid var(--border); background: var(--surface); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-peer::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--peer); flex: none; }
.live-peer.is-viewer { font-weight: 500; color: var(--fg-muted); }
.live-peer.is-viewer::before { background: transparent; border: 2px solid var(--peer); width: 6px; height: 6px; }
.live-peer.is-me::before { background: var(--fg-faint); }
.live-head { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s3); }
.live-head__t { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-wrap: anywhere; }
.live-head__t .faint { font-size: var(--fs-xs); }
.live-ed__bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); flex-wrap: wrap; margin-bottom: var(--s2); position: sticky; top: 0; z-index: 3; background: var(--bg); padding: 6px 0; }
.live-status { font-size: var(--fs-xs); color: var(--fg-muted); white-space: nowrap; }
.live-status[data-state=offline] { color: var(--danger); }
.live-status[data-state=saving] { color: var(--warn); }
.live-ed__area { position: relative; }
.live-ed__ta, .live-ed__overlay {
  box-sizing: border-box; width: 100%; margin: 0; font-family: var(--ff-mono); font-size: 13.5px; line-height: 1.6; letter-spacing: normal;
  padding: var(--s2) var(--s3); border-width: 1px; border-style: solid; white-space: pre-wrap; overflow-wrap: break-word; word-break: normal; tab-size: 4;
}
.live-ed__ta { display: block; resize: none; overflow: hidden; min-height: 55vh; }
.live-ed__overlay { position: absolute; inset: 0; border-color: transparent; color: transparent; pointer-events: none; overflow: visible; z-index: 2; }
.live-sel { --peer: var(--accent); background: color-mix(in srgb, var(--peer) 22%, transparent); border-radius: 2px; }
.live-caret { --peer: var(--accent); position: relative; display: inline-block; width: 0; height: 1.25em; vertical-align: text-bottom; border-left: 2px solid var(--peer); margin-left: -1px; }
.live-caret b { position: absolute; left: -2px; bottom: 100%; font: 700 10px/1.4 var(--ff); color: #fff; background: var(--peer); padding: 0 4px; border-radius: 3px 3px 3px 0; white-space: nowrap; }
.blame__row { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: var(--s3); border-top: 1px dashed var(--border); padding-top: 2px; }
.blame__who { font-size: var(--fs-xs); color: var(--fg-muted); padding-top: 6px; display: flex; flex-direction: column; overflow: hidden; }
.blame__who.is-same .blame__name { visibility: hidden; }
.blame__name { font-weight: 700; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.blame__when { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.blame__text { min-width: 0; }
.blame__text > :first-child { margin-top: 4px; }
.page-claim { max-width: 100%; white-space: normal; }
.sugg { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s3); margin-bottom: var(--s3); }
.sugg__head { display: flex; gap: var(--s2); align-items: baseline; flex-wrap: wrap; margin-bottom: var(--s2); }
.sugg .diff { max-height: 260px; margin-bottom: var(--s2); }
.sugg .btn-row { justify-content: flex-end; }
.share-sec { border-top: 1px solid var(--border); padding-top: var(--s3); margin-top: var(--s3); }
.share-sec:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.share-sec__t { font-weight: 800; margin-bottom: var(--s1); }
.share-link { display: flex; gap: var(--s2); margin-bottom: var(--s2); }
.share-link .field__input { flex: 1; min-width: 0; }
.share-members { display: flex; flex-direction: column; gap: 2px; margin: var(--s2) 0; }
.share-member { display: flex; align-items: center; justify-content: space-between; font-size: var(--fs-sm); }
.share-member .icon-btn { width: 28px; height: 28px; }
.pub { display: flex; min-height: 100vh; background: var(--bg); color: var(--fg); }
.pub__nav { width: 240px; flex: none; border-right: 1px solid var(--border); background: var(--list-bg); padding: var(--s4) var(--s2); display: flex; flex-direction: column; gap: 2px; }
.pub__nav[hidden] { display: none; }
.pub__link { display: block; padding: 6px 10px; border-radius: var(--r-md); color: var(--fg); text-decoration: none; font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pub__link:hover { background: var(--hover); }
.pub__link.is-active { background: var(--accent-soft); font-weight: 700; }
.pub__main { flex: 1; min-width: 0; max-width: 820px; margin: 0 auto; padding: var(--s6) var(--s6) var(--s10); }
.pub__crumb { font-size: var(--fs-sm); color: var(--fg-muted); text-decoration: none; }
.pub__title { font-size: 30px; font-weight: 800; margin: var(--s2) 0; overflow-wrap: anywhere; }
.pub__summary { color: var(--fg-muted); margin: 0 0 var(--s2); }
.pub__meta { display: flex; gap: var(--s2); align-items: center; font-size: var(--fs-xs); color: var(--fg-muted); margin-bottom: var(--s5); flex-wrap: wrap; }
.pub__live { display: inline-flex; align-items: center; gap: 4px; color: var(--ok); font-weight: 700; }
.pub__live::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.pub__body { overflow-wrap: anywhere; }
.pub__body pre { max-width: 100%; }
.pub__foot { margin-top: var(--s10); font-size: var(--fs-xs); color: var(--fg-faint); }
@media (max-width: 767px) {
  .pub { flex-direction: column; }
  .pub__nav { width: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: var(--s2); }
  .pub__main { padding: var(--s4); }
  .blame__row { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .blame__who { flex-direction: row; gap: var(--s2); padding-top: 4px; }
  .blame__who.is-same { display: none; }
}
.ref-chip--missing { opacity: .6; cursor: default; border-style: dashed; }

/* mobile tabbar */
.tabbar { display: none; }

/* modal, search, toast */
.modal-host, .search-host { position: fixed; inset: 0; z-index: 100; background: rgba(30, 20, 10, .35); display: grid; place-items: center; padding: var(--s4); }
.search-host { place-items: start center; padding-top: 10vh; }
.modal { width: min(460px, 100%); max-height: 86vh; overflow-y: auto; background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-pop); padding: var(--s5); }
.modal__title { margin: 0 0 var(--s4); font-size: var(--fs-lg); font-weight: 800; }
.modal__hint { font-size: var(--fs-sm); color: var(--fg-muted); margin: 0 0 var(--s3); }
.modal__row { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s4); }
.search { width: min(640px, 100%); background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-pop); overflow: hidden; }
.search__in { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); }
.search__in input { flex: 1; border: 0; outline: none; background: none; font-size: var(--fs-lg); }
.search__res { max-height: 60vh; overflow-y: auto; padding: var(--s2); }
.search__empty { padding: var(--s4); color: var(--fg-muted); font-size: var(--fs-sm); }
.search-item { display: flex; gap: var(--s3); align-items: flex-start; width: 100%; padding: var(--s2); border-radius: var(--r-md); text-align: left; }
.search-item:hover, .search-item.is-active { background: var(--active); }
.search-item__t { font-weight: 700; }
.search-item__s { font-size: var(--fs-sm); color: var(--fg-muted); }
.search-item__s mark { background: var(--accent-soft); color: var(--fg); border-radius: 3px; }
.toasts { position: fixed; bottom: var(--s6); left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: var(--s2); align-items: center; }
.toast { background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: var(--r-md); font-size: var(--fs-sm); font-weight: 600; box-shadow: var(--shadow-pop); }
.toast--err { background: var(--danger); color: #fff; }
.skeleton { display: flex; gap: var(--s3); padding: var(--s2) var(--s5); }
.skeleton__a { width: 32px; height: 32px; border-radius: 50%; }
.skel-line { height: 10px; border-radius: 5px; margin: 6px 0; }
.shimmer { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--s4); background: var(--bg); }
.login__card { width: min(380px, 100%); background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-pop); padding: var(--s8) var(--s6); border-top: 6px solid var(--wood-1); }
.login__brand { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-xl); font-weight: 800; }
.login__logo { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--wood-1); color: var(--wood-fg); }
.login__sub { color: var(--fg-muted); margin: 4px 0 var(--s5); }
.login__seg { margin-bottom: var(--s4); width: 100%; } .login__seg .seg__btn { flex: 1; }
.login__err { color: var(--danger); font-size: var(--fs-sm); }
.login__hint { color: var(--fg-faint); font-size: var(--fs-xs); margin-top: var(--s4); }

/* ================= responsive ================= */
@media (max-width: 1100px) { .app.has-drawer { grid-template-columns: var(--rail-w) var(--list-w) minmax(0, 1fr); }
  .drawer { position: fixed; right: 0; top: 0; bottom: 0; width: min(var(--drawer-w), 92vw); z-index: 60; box-shadow: var(--shadow-pop); } }

@media (max-width: 767px) {
  .app, .app.has-drawer { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .rail { display: none; }
  .list, .detail { grid-column: 1; grid-row: 1; border-right: 0; }
  .app[data-pane='list'] .detail { display: none; }
  .app[data-pane='detail'] .list { display: none; }
  .app[data-pane='detail'] .tabbar { display: none; }
  .detail__back { display: inline-grid; }
  .list__body { padding-bottom: 90px; }
  .tabbar { display: flex; grid-row: 2; justify-content: space-around; gap: 4px; padding: 6px var(--s3) calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border); }
  .tabbar__btn { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 0; border-radius: var(--r-lg); font-size: 11px; font-weight: 700; color: var(--fg-muted); position: relative; }
  .tabbar__btn.is-active { color: var(--fg); background: var(--surface-2); }
  .tabbar__btn .dot-badge { top: 0; right: calc(50% - 22px); }
  .fab { position: fixed; right: var(--s4); bottom: calc(76px + env(safe-area-inset-bottom)); width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; box-shadow: var(--shadow-pop); z-index: 30; }
  .page-wrap, .doc { padding: var(--s4); }
  .kv { grid-template-columns: 110px 1fr; }
  .msg { padding: 6px var(--s3); }
  .msg__tools { right: var(--s2); }
  .att-img img { max-width: 100%; }
  .space-menu { left: 10px; right: 10px; width: auto; }
}
@media (min-width: 768px) { .fab { display: none; } }

@media (max-width: 767px) { .detail__actions .hide-m { display: none; } }
@media (min-width: 768px) { .btn.only-m { display: none; } }
@media (hover: none) { .sec-tools { position: static; transform: none; display: inline-flex; vertical-align: middle; margin-left: 6px; } .sec-anchor { display: none; } }

/* ---------- agent instances & @ syntax help ---------- */
.msg__inst { font-weight: 700; color: var(--fg-muted); font-family: var(--ff-mono); font-size: 0.92em; }
.msg__dispatch { margin-top: 4px; }
.msg__dispatch .chip--danger { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.syntax-pop { max-height: 360px; }
.syntax-pop__row { align-items: flex-start; }
.syntax-pop__code { font-family: var(--ff-mono); font-size: var(--fs-xs); color: var(--accent); background: var(--accent-soft); padding: 1px 6px; border-radius: var(--r-sm); }
.syntax-pop .pop-item__desc { white-space: normal; margin-top: 2px; }

/* ---- team, account, admin console (team.js) ---- */
.avatar--img { background: var(--surface-2) !important; overflow: hidden; }
.avatar__img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.avatar--xl { width: 72px; height: 72px; font-size: 24px; }
.team-tabs { margin-top: var(--s4); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.team-tabs .seg__btn { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.dot-badge--inline { position: static; }
.member-cell { display: flex; align-items: center; gap: 8px; min-width: 0; }
.member-cell__txt { min-width: 0; }
.member-cell__txt > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field__select--inline { height: 30px; width: auto; max-width: 160px; }
.tbl__act { text-align: right; white-space: nowrap; }
.tbl__act .btn + .btn { margin-left: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); column-gap: var(--s3); }
.wrap-row { margin-top: 12px; align-items: center; }
.wrap-row .field { margin-bottom: 0; }
.grow { flex: 1 1 160px; min-width: 0; }
.field--inline { max-width: 220px; }
.invite-once { margin-top: var(--s3); display: grid; gap: var(--s2); border-color: var(--accent); }
.rev-line { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.rev-line__diff { overflow-wrap: anywhere; }
.rev-line del { color: var(--fg-muted); }
.rev-line ins { text-decoration: none; font-weight: 600; }
.activity-row .row__name { white-space: normal; overflow-wrap: anywhere; font-weight: 500; }
.activity-row--bad .row__glyph { color: var(--danger); }
.profile-head { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.composer--locked { opacity: .7; }
.invite-banner { background: var(--accent-soft); border-radius: var(--r-md); padding: var(--s3); margin-bottom: var(--s4); }
.invite-banner__t { font-weight: 700; }
.invite-banner__d { font-size: var(--fs-sm); color: var(--fg-muted); margin-top: 2px; }
.login__alt { margin-top: var(--s3); display: grid; gap: var(--s2); }
.login__links { display: flex; justify-content: space-between; gap: var(--s2); }
.login__link { color: var(--accent); font-size: var(--fs-sm); font-weight: 600; padding: 2px 0; }
.login__info { color: var(--fg-muted); font-size: var(--fs-sm); }
#paneRegister .login__link { margin: -4px 0 var(--s3); }
/* ---- agent runtime (runtime.js): instance state, invocation details, first-message picker, machine management ---- */
.avatar--sleep { filter: grayscale(1); opacity: .55; }
.inst-badge { margin-left: 3px; font-size: .85em; cursor: help; }
.inst-badge--err { color: var(--danger); font-weight: 700; }
.inst-row .row__main { min-width: 0; }
.inst-row .row__sub { overflow-wrap: anywhere; }
.inst-state--sleeping, .inst-state--stopped { color: var(--fg-faint); }
.inst-state--working { color: var(--warn); }
.inst-state--idle { color: var(--ok); }
.inst-state--wake-failed { color: var(--danger); }
.inst-warn { color: var(--danger); font-size: var(--fs-xs); margin-top: 2px; }
.chip--ref { color: var(--fg-muted); border-style: dashed; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv { display: flex; flex-direction: column; gap: var(--s3); min-width: 0; }
.inv-entry { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s3); min-width: 0; }
.inv-entry__head { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; margin-bottom: var(--s2); }
.inv-block { border-top: 1px dashed var(--border); padding-top: var(--s2); margin-top: var(--s2); min-width: 0; }
.inv-block__t { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; font-weight: 700; font-size: var(--fs-sm); margin-bottom: var(--s2); }
.inv .kv { grid-template-columns: 96px minmax(0, 1fr); }
.inv .kv dd { overflow-wrap: anywhere; }
.inv-err { color: var(--danger); font-size: var(--fs-sm); overflow-wrap: anywhere; margin: 4px 0; }
.inv-sub { font-size: var(--fs-xs); font-weight: 700; color: var(--fg-muted); margin: var(--s2) 0 4px; }
.inv-steps { margin: 0; padding-left: 0; list-style: none; font-size: var(--fs-sm); }
.inv-steps li { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 2px var(--s2); padding: 2px 0; }
.inv-steps__ok { color: var(--ok); font-weight: 700; }
.inv-steps li.is-bad .inv-steps__ok, .inv-steps li.is-bad .inv-steps__n { color: var(--danger); }
.inv-steps__d { grid-column: 2 / 4; color: var(--fg-muted); font-size: var(--fs-xs); overflow-wrap: anywhere; }
.inv-trace { margin-top: var(--s2); font-size: var(--fs-sm); }
.inv-trace summary { cursor: pointer; font-weight: 600; color: var(--fg-muted); }
.inv-trace__i { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: var(--s2); padding: 3px 0; border-bottom: 1px solid var(--border); }
.inv-trace__k { font-size: var(--fs-xs); font-weight: 700; color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; }
.inv-trace__t { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--ff-mono); font-size: var(--fs-xs); }
.inv-trace__i--reasoning .inv-trace__t { font-family: var(--ff); font-style: italic; color: var(--fg-muted); }
.inv-trace__i--error .inv-trace__t { color: var(--danger); }
.inv .tbl tr.is-skipped td { color: var(--fg-faint); }
.pick { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s3); }
.pick__btn { display: flex; gap: var(--s2); align-items: center; text-align: left; padding: 8px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); cursor: pointer; color: var(--fg); }
.pick__btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.pick__txt { display: flex; flex-direction: column; min-width: 0; }
.pick__txt .faint { font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-wrap { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s2); background: var(--surface); }
.chart { width: 100%; height: 140px; display: block; }
.chart path { fill: none; stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.chart__grid { stroke: var(--border); stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.chart__cpu { stroke: var(--accent); } .chart__mem { stroke: var(--ok); } .chart__load { stroke: var(--warn); stroke-dasharray: 4 3; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px var(--s3); font-size: var(--fs-xs); margin-top: 4px; }
.chart-key::before { content: ''; display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 4px; vertical-align: middle; background: currentColor; }
.chart-key--cpu { color: var(--accent); } .chart-key--mem { color: var(--ok); } .chart-key--load { color: var(--warn); }
.chart-tabs { margin-top: var(--s2); }
.chart-tabs .chip { cursor: pointer; }
.tbl-ops { white-space: nowrap; text-align: right; }
.tbl-ops .btn + .btn { margin-left: 4px; }
.wt-row .row__main { min-width: 0; }
.wt-path { overflow-wrap: anywhere; word-break: break-all; white-space: normal; }
.ws-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) auto; gap: var(--s2); align-items: center; margin-top: var(--s2); }
@media (max-width: 767px) { .ws-form { grid-template-columns: minmax(0, 1fr); } }
.task { border-bottom: 1px solid var(--border); padding: 6px 0; font-size: var(--fs-sm); }
.task summary { cursor: pointer; }
.task__out { white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--fs-xs); max-height: 220px; overflow: auto; background: var(--bg); padding: var(--s2); border-radius: var(--r-sm); margin: 6px 0 0; }

/* ---- onboarding: add machine, harness install + sign-in, add-agent wizard (web/onboard.js) ---- */
.ob-wiz, .ob-cmd, .ob-login, .ob-install { display: flex; flex-direction: column; gap: var(--s3); min-width: 0; }
.ob-steps { display: flex; gap: 4px; list-style: none; margin: 0 0 var(--s2); padding: 0; counter-reset: ob; }
.ob-steps li { flex: 1; min-width: 0; font-size: var(--fs-xs); color: var(--fg-faint); padding-top: 6px; border-top: 3px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; counter-increment: ob; }
.ob-steps li::before { content: counter(ob) ". "; }
.ob-steps li.is-done { color: var(--fg-muted); border-color: var(--ok); }
.ob-steps li.is-on { color: var(--fg); font-weight: 700; border-color: var(--accent); }
.ob-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--s2); }
.ob-card { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left; padding: var(--s3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); color: var(--fg); min-width: 0; }
.ob-card:hover, .ob-card.is-on { border-color: var(--accent); background: var(--accent-soft); }
.ob-card .faint { font-size: var(--fs-xs); }
.ob-list { display: flex; flex-direction: column; gap: 6px; }
.ob-mrow { display: flex; align-items: center; gap: var(--s2); padding: 10px var(--s3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); color: var(--fg); text-align: left; width: 100%; }
.ob-mrow:hover:not(:disabled) { border-color: var(--accent); }
.ob-mrow.is-off { opacity: .55; cursor: not-allowed; }
.ob-mrow__main { display: flex; flex-direction: column; min-width: 0; }
.ob-mrow__main .faint { font-size: var(--fs-xs); overflow-wrap: anywhere; }
.ob-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-faint); flex: none; }
.ob-dot.is-on { background: var(--ok); }
.ob-row { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.ob-seg { display: flex; flex-wrap: wrap; width: 100%; }
.ob-seg .seg__btn { flex: 1 1 auto; }
.ob-cmd__text { user-select: all; }
.ob-status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ob-note { font-size: var(--fs-xs); }
.ob-wait { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); padding: var(--s3); border-radius: var(--r-md); background: var(--surface-2); }
.ob-wait.is-ok { flex-direction: column; align-items: flex-start; border: 1px solid var(--ok); }
.ob-spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: ob-spin .8s linear infinite; flex: none; }
@keyframes ob-spin { to { transform: rotate(360deg); } }
.ob-task { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }
.ob-task__head { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.ob-task__t { font-weight: 600; flex: 1; min-width: 0; }
.ob-task__hint { margin: 0; }
.ob-links { display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
.ob-links:empty { display: none; }
.ob-link.btn--primary { height: 44px; font-size: var(--fs-md, 15px); }
.ob-url { font-size: var(--fs-xs); color: var(--fg-faint); overflow-wrap: anywhere; word-break: break-all; max-height: 3.2em; overflow: hidden; }
.ob-code { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); padding: var(--s3); border-radius: var(--r-md); background: var(--accent-soft); }
.ob-code__v { font-size: 22px; letter-spacing: .08em; }
.ob-input { display: flex; gap: var(--s2); align-items: center; }
.ob-input .field__input { flex: 1; min-width: 0; }
.ob-out summary { cursor: pointer; font-size: var(--fs-xs); color: var(--fg-muted); }
.ob-more summary { cursor: pointer; font-size: var(--fs-sm); color: var(--fg-muted); }
.ob-more .howto { margin-top: var(--s2); }
