:root {
  --side-bg: #3f0e40;
  --side-hover: #350d36;
  --side-text: #d9cdd9;
  --side-muted: #a58fa6;
  --side-line: #5b2a5c;
  --side-active: #1164a3;

  --bg: #ffffff;
  --bg-alt: #f8f8f8;
  --line: #e4e4e4;
  --text: #1d1c1d;
  --muted: #616061;
  --link: #1264a3;
  --hover: #f6f6f6;
  --mention-bg: #e8f5fa;
  --mention-text: #1264a3;
  --ok: #007a5a;
  --ok-bg: #e6f4ef;
  --warn: #b37400;
  --warn-bg: #fdf3dc;
  --bad: #c0173d;
  --bad-bg: #fdeaf0;
  --info: #1264a3;
  --info-bg: #e8f1fa;
  --violet: #6b3aa5;
  --violet-bg: #f0e9f9;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}
@media (prefers-color-scheme: dark) {
  :root {
    --side-bg: #2b0c2c;
    --side-hover: #24091f;
    --bg: #1a1d21;
    --bg-alt: #222529;
    --line: #363a40;
    --text: #d1d2d3;
    --muted: #ababad;
    --link: #4fb3e8;
    --hover: #222529;
    --mention-bg: #1b3a4b;
    --mention-text: #7cc7ee;
    --ok: #4cc79f;
    --ok-bg: #163a2f;
    --warn: #f0bd4f;
    --warn-bg: #3f3214;
    --bad: #ff7a9c;
    --bad-bg: #4a1a28;
    --info: #6cbcf0;
    --info-bg: #17324a;
    --violet: #c4a1f2;
    --violet-bg: #322447;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.46 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2 { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--info); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
a { color: var(--link); }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.4em; margin: 0; font-size: 13px; }

.btn { border: 1px solid var(--line); background: var(--bg); border-radius: 6px; padding: 7px 14px; font-weight: 600; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.good { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn { background: none; border: 0; font-size: 22px; line-height: 1; padding: 4px 8px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: var(--side-bg); }
.login-card { background: var(--bg); border-radius: 12px; padding: 32px; width: min(380px, 100%); display: grid; gap: 12px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 22px; }
.login-card p { margin: 0; }
.logo { width: 44px; height: 44px; border-radius: 10px; background: var(--side-bg); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 22px; }

/* ---------- shell ---------- */
.app { height: 100%; display: flex; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }

/* ---------- sidebar ---------- */
.sidebar { width: 260px; flex: none; background: var(--side-bg); color: var(--side-text); display: flex; flex-direction: column; }
.ws { padding: 14px 16px; border-bottom: 1px solid var(--side-line); }
.ws-name { font-weight: 800; font-size: 18px; color: #fff; }
.ws-status { font-size: 12px; color: var(--side-muted); margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.side-scroll { flex: 1; overflow-y: auto; padding: 10px 0; }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px 4px; font-size: 13px; font-weight: 700; color: var(--side-muted); }
.side-btn { background: none; border: 0; color: var(--side-muted); font-size: 18px; line-height: 1; border-radius: 4px; padding: 0 6px; }
.side-btn:hover { background: var(--side-hover); color: #fff; }
.side-list { list-style: none; margin: 0; padding: 0; }
.side-item { display: flex; align-items: center; gap: 8px; padding: 4px 16px; cursor: pointer; color: var(--side-text); min-height: 28px; }
.side-item:hover { background: var(--side-hover); }
.side-item.active { background: var(--side-active); color: #fff; }
.side-item.unread { color: #fff; font-weight: 700; }
.side-item .hash { width: 16px; text-align: center; opacity: 0.75; }
.side-item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .tag { font-size: 10px; color: var(--side-muted); }
.side-item.off { opacity: 0.55; }
.side-ico { width: 16px; text-align: center; opacity: 0.75; }
.side-foot { padding: 10px 16px; border-top: 1px solid var(--side-line); }
.side-link { background: none; border: 0; padding: 0; color: var(--side-muted); text-decoration: underline; font-size: 13px; }
.side-link:hover { color: #fff; }
.dot { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--side-muted); display: inline-block; flex: none; }
.dot.on { background: #2bac76; border-color: #2bac76; }

/* ---------- channel header + tabs ---------- */
.chan-head { display: flex; align-items: center; gap: 8px; padding: 10px 20px; border-bottom: 1px solid var(--line); min-height: 56px; }
.chan-titles { min-width: 0; }
.chan-head h1 { font-size: 18px; font-weight: 800; }
.topic { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { display: none; }
.members-btn { margin-left: auto; white-space: nowrap; }
.no-channel .members-btn { display: none; }
.member { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-radius: 6px; font-weight: 400; cursor: pointer; }
.member:hover { background: var(--hover); }
.member input { width: auto; }
.member .hint { color: var(--muted); font-size: 12px; }
.tabs { display: flex; align-items: center; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.tab, .tabs-action { white-space: nowrap; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 10px; color: var(--muted); font-weight: 600; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--ok); }
.tabs-action { margin-left: auto; }
.count { background: var(--bg-alt); border: 1px solid var(--line); border-radius: 10px; padding: 0 6px; font-size: 11px; color: var(--muted); }
.count:empty { display: none; }
.no-channel .tabs, .no-channel .composer { display: none; }

.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pane.scroll { overflow-y: auto; padding: 16px 20px; }

/* ---------- messages ---------- */
.feed { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 0 12px; }
.day { display: flex; align-items: center; gap: 12px; margin: 14px 20px 8px; color: var(--muted); font-size: 12px; font-weight: 700; }
.day::before, .day::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.sys { padding: 2px 20px 2px 68px; color: var(--muted); font-size: 12.5px; }
.msg { position: relative; display: flex; gap: 10px; padding: 4px 20px; }
.msg:hover { background: var(--hover); }
.msg.grouped { padding-top: 0; padding-bottom: 0; }
.msg .gutter { width: 36px; flex: none; font-size: 10px; color: var(--muted); text-align: right; padding-top: 5px; visibility: hidden; }
.msg.grouped:hover .gutter { visibility: visible; }
.msg .content { min-width: 0; flex: 1; }
.meta { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.meta .name { font-weight: 800; }
.meta .time { font-size: 12px; color: var(--muted); }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.mention { background: var(--mention-bg); color: var(--mention-text); border-radius: 4px; padding: 0 2px; font-weight: 500; }
.app-badge { font-size: 10px; font-weight: 700; background: var(--bg-alt); border: 1px solid var(--line); color: var(--muted); border-radius: 4px; padding: 0 4px; letter-spacing: 0.03em; }
.chip { font-size: 11px; font-weight: 700; border-radius: 4px; padding: 0 6px; text-transform: uppercase; letter-spacing: 0.03em; }
.chip.question { background: var(--info-bg); color: var(--info); }
.chip.report { background: var(--info-bg); color: var(--info); }
.chip.evidence { background: var(--violet-bg); color: var(--violet); }
.chip.verdict { background: var(--warn-bg); color: var(--warn); }
.chip.action { background: var(--warn-bg); color: var(--warn); }
.chip.result { background: var(--ok-bg); color: var(--ok); }
.chip.approval { background: var(--ok-bg); color: var(--ok); }
.chip.handoff { background: var(--violet-bg); color: var(--violet); }
.avatar { width: 36px; height: 36px; border-radius: 6px; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px; }
.avatar.sm { width: 22px; height: 22px; font-size: 11px; border-radius: 4px; }
.avatar.xs { width: 18px; height: 18px; font-size: 10px; border-radius: 4px; }
.msg-tools { position: absolute; right: 16px; top: -12px; display: none; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1); }
.msg:hover .msg-tools { display: flex; }
.msg-tools button { background: none; border: 0; padding: 4px 10px; font-size: 13px; color: var(--muted); }
.msg-tools button:hover { color: var(--text); background: var(--hover); }
.payload { margin-top: 4px; }
.payload summary { cursor: pointer; color: var(--link); font-size: 13px; }
.payload pre { background: var(--bg-alt); border: 1px solid var(--line); border-radius: 6px; padding: 8px; overflow: auto; font-size: 12px; margin: 4px 0 0; }
.decision { margin-top: 6px; font-weight: 700; font-size: 13px; }
.decision.ok { color: var(--ok); }
.decision.bad { color: var(--bad); }
.btn-row { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; align-items: center; }

.replies { display: inline-flex; align-items: center; gap: 8px; margin-top: 4px; padding: 3px 8px 3px 4px; border: 1px solid transparent; border-radius: 6px; cursor: pointer; background: none; color: var(--link); font-size: 13px; }
.replies:hover { border-color: var(--line); background: var(--bg); }
.replies .avs { display: flex; gap: 2px; }
.replies .when { color: var(--muted); }

.intro { padding: 32px 20px; }
.intro h2 { font-size: 22px; margin-bottom: 6px; }
.intro p { color: var(--muted); margin: 0 0 12px; max-width: 520px; }

/* ---------- task cards ---------- */
.task-card { border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: 8px; padding: 10px 12px; margin-top: 4px; background: var(--bg); max-width: 640px; }
.task-card.open { border-left-color: var(--warn); }
.task-card.claimed { border-left-color: var(--info); }
.task-card.done { border-left-color: var(--ok); }
.task-card.cancelled { border-left-color: var(--muted); opacity: 0.8; }
.tc-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.tc-id { color: var(--muted); font-weight: 700; }
.tc-title { font-weight: 800; flex: 1 1 12ch; min-width: 0; overflow-wrap: anywhere; }
.pill { font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 8px; text-transform: uppercase; letter-spacing: 0.03em; }
.pill.open { background: var(--warn-bg); color: var(--warn); }
.pill.claimed { background: var(--info-bg); color: var(--info); }
.pill.done { background: var(--ok-bg); color: var(--ok); }
.pill.cancelled { background: var(--bg-alt); color: var(--muted); }
.tc-desc { margin-top: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
.tc-desc.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tc-role { margin-top: 6px; font-size: 13px; color: var(--muted); }
.tc-role b { color: var(--text); }
.tc-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.tc-foot .who { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.tc-foot select { width: auto; padding: 3px 8px; font-size: 13px; }

/* ---------- panes ---------- */
.group-title { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 18px 0 6px; }
.group-title:first-child { margin-top: 0; }
.handoff-card { border: 1px solid var(--line); border-left: 4px solid var(--violet); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; max-width: 640px; }
.handoff-card .flow { display: flex; align-items: center; gap: 6px; font-weight: 700; flex-wrap: wrap; }
.empty { color: var(--muted); padding: 12px 0; }

/* ---------- composer ---------- */
.composer { padding: 0 20px 16px; position: relative; }
.composer-box { border: 1px solid #868686; border-radius: 8px; background: var(--bg); position: relative; }
.composer-box:focus-within { border-color: var(--info); box-shadow: 0 0 0 1px var(--info); }
.composer-box textarea { border: 0; border-radius: 8px 8px 0 0; resize: none; max-height: 200px; min-height: 44px; padding: 10px 12px 4px; outline: none; box-shadow: none; }
.composer-bar { display: flex; align-items: center; gap: 8px; padding: 4px 8px 6px; }
.composer-bar select { width: auto; border: 0; background: var(--bg-alt); border-radius: 4px; padding: 3px 6px; font-size: 13px; }
.composer-bar select:focus { outline: none; }
.composer-bar .hint { flex: 1; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.send { background: var(--ok); color: #fff; border: 0; border-radius: 6px; padding: 5px 14px; font-weight: 700; }
.send:disabled { background: var(--bg-alt); color: var(--muted); cursor: default; }
.mention-pop { position: absolute; bottom: calc(100% + 4px); left: 0; min-width: 220px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; z-index: 5; }
.mp-item { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.mp-item.on, .mp-item:hover { background: var(--side-active); color: #fff; }
.mp-item.on .app-badge { background: transparent; color: #fff; border-color: #fff; }

/* ---------- thread panel ---------- */
.thread { width: 420px; flex: none; border-left: 1px solid var(--line); display: flex; flex-direction: column; background: var(--bg); }
.thread-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); min-height: 56px; }
.thread .msg { padding-left: 16px; padding-right: 16px; }
.thread .sys { padding-left: 62px; }
.thread .composer { padding: 0 16px 16px; }

/* ---------- dialog / toast ---------- */
dialog { border: 0; border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--bg); color: var(--text); box-shadow: var(--shadow); }
dialog.wide { width: min(820px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; }
.dlg-head h2 { font-size: 20px; }
.dlg-body { padding: 12px 20px 20px; display: grid; gap: 12px; max-height: 75vh; overflow-y: auto; }
.field { display: grid; gap: 4px; }
.field > label { font-weight: 700; font-size: 14px; }
.field .hint { font-size: 12px; color: var(--muted); }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; }
.checks input { width: auto; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.code { font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg-alt); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; word-break: break-all; }
.token-warn { background: var(--warn-bg); color: var(--warn); border-radius: 6px; padding: 8px 10px; font-size: 13px; font-weight: 600; }
table.audit { width: 100%; border-collapse: collapse; font-size: 13px; }
table.audit th, table.audit td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.audit th { color: var(--muted); font-size: 12px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1d1c1d; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 20; max-width: min(520px, 90vw); }
.toast.error { background: var(--bad); }

/* ---------- responsive ---------- */
.scrim { display: none; }
@media (max-width: 1180px) {
  .thread { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100%); z-index: 15; box-shadow: var(--shadow); }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; transform: translateX(-100%); transition: transform 0.15s; }
  .nav-open .sidebar { transform: none; }
  .nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 25; }
  .menu-btn { display: block; }
  .thread { position: fixed; inset: 0; width: auto; z-index: 15; border-left: 0; }
  .chan-head, .tabs, .pane.scroll { padding-left: 12px; padding-right: 12px; }
  .composer { padding: 0 12px 12px; }
}
