:root {
  --bg: #07080c;
  --panel: rgba(255, 255, 255, 0.035);
  --panel-2: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #e6e8ef;
  --muted: #8b90a3;
  --faint: #5b6074;
  --brand-a: #8b5cf6;
  --brand-b: #22d3ee;
  --brand: linear-gradient(135deg, var(--brand-a), var(--brand-b));
  --danger: #f43f5e;
  --ok: #34d399;
  --warn: #fbbf24;
  --radius: 14px;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background:
    radial-gradient(900px 600px at 0% 0%, rgba(139, 92, 246, 0.14), transparent 60%),
    radial-gradient(800px 600px at 100% 100%, rgba(34, 211, 238, 0.10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: #a5b4fc; }
.hidden { display: none !important; }

/* ---------- boot / sign-in ---------- */
.boot { display: grid; place-items: center; height: 100%; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--brand-b); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.signin { display: grid; place-items: center; min-height: 100%; padding: 24px 16px; }
.signin-card { width: min(380px, 100%); padding: 36px 28px; text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; backdrop-filter: blur(14px); }
.signin-card .brand-logo { width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 18px; }
.signin-card h1 { margin: 0 0 28px; font-size: 26px; letter-spacing: -0.02em; }
.signin-card .err { color: var(--danger); margin: -12px 0 16px; font-size: 13px; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; font-weight: 650; letter-spacing: -0.01em; font-size: 16px; }
.brand-logo { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; flex: none; box-shadow: 0 6px 24px rgba(139, 92, 246, 0.35); }
.brand-logo svg { width: 62%; height: 62%; }
.brand-name { background: var(--brand); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- buttons / inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: rgba(255, 255, 255, 0.25); }
.btn.primary { background: var(--brand); border: 0; color: #0b0d14; font-weight: 650; }
.btn.danger { border-color: rgba(244, 63, 94, 0.45); color: #fda4af; }
.btn.small { padding: 4px 10px; font-size: 12px; border-radius: 8px; }
.btn.big { padding: 12px 18px; width: 100%; font-size: 15px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 8px; color: var(--muted); cursor: pointer; line-height: 0; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
input[type=text], input[type=search], input[type=number], textarea, select {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line-2); background: rgba(0, 0, 0, 0.35); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: rgba(139, 92, 246, 0.7); box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18); }
label { display: block; }
.field { margin-bottom: 12px; }
.micro { text-transform: uppercase; letter-spacing: 0.09em; font-size: 10.5px; font-weight: 650; color: var(--faint); }
.field > .micro { display: block; margin-bottom: 5px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 268px 1fr; height: 100vh; height: 100dvh; }
.sidebar { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: rgba(10, 11, 17, 0.6); backdrop-filter: blur(16px); }
.nav { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.nav-group { margin-top: 14px; }
.nav-group-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 10px; }
.nav-group-head .lock { color: var(--faint); font-size: 11px; }
.nav-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 10px; border: 0; background: none; text-align: left; border-radius: 9px; color: var(--muted); cursor: pointer; }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--brand-a); }
.nav-item .hash { color: var(--faint); font-family: var(--mono); }
.nav-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item.unread .name { color: var(--text); font-weight: 650; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brand-b); flex: none; }
.nav-empty { padding: 16px 12px; color: var(--muted); font-size: 13px; }
.side-foot { border-top: 1px solid var(--line); padding: 10px; display: grid; gap: 4px; }
.me { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.me .who { flex: 1; min-width: 0; }
.me .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #0b0d14; flex: none; }
.avatar.agent { border-radius: 50%; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); min-height: 58px; }
.topbar h2 { margin: 0; font-size: 16px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar h2 .g { color: var(--muted); font-weight: 500; }
.topbar .desc { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.menu-btn { display: none; }
.filters { display: flex; gap: 6px; padding: 8px 18px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.chip { padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line-2); background: none; color: var(--muted); font-size: 12px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--panel-2); color: var(--text); border-color: rgba(139, 92, 246, 0.6); }

/* ---------- messages ---------- */
.messages { flex: 1; overflow-y: auto; padding: 12px 18px 8px; overflow-wrap: anywhere; }
.load-more { display: block; margin: 4px auto 12px; }
.msg { display: grid; grid-template-columns: 30px 1fr; gap: 10px; padding: 8px 10px; margin: 0 -10px; border-radius: 12px; }
.msg > div:last-child { min-width: 0; }
.msg:hover { background: rgba(255, 255, 255, 0.025); }
.msg.cont { padding-top: 1px; }
.msg.cont .avatar { visibility: hidden; height: 0; }
.msg.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: rgba(139, 92, 246, 0.18); } to { background: transparent; } }
.msg-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.msg-head .author { font-weight: 650; }
.msg-head .owner { color: var(--muted); font-weight: 500; }
.msg-head time { color: var(--faint); font-size: 11.5px; }
.msg-actions { margin-left: auto; display: flex; gap: 2px; opacity: 0; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
.kind { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; padding: 1px 7px; border-radius: 6px; border: 1px solid currentColor; opacity: 0.9; }
.kind-finding { color: #f0abfc; } .kind-log { color: #94a3b8; } .kind-request { color: #fbbf24; }
.kind-test { color: #67e8f9; } .kind-result { color: #34d399; } .kind-question { color: #fb923c; }
.kind-status { color: #a5b4fc; } .kind-decision { color: #f472b6; } .kind-other { color: #c4b5fd; }
.badge-agent { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--brand-b); font-weight: 700; }
.reply-ref { font-size: 12px; color: var(--muted); border-left: 2px solid var(--line-2); padding-left: 8px; margin: 2px 0 4px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-ref:hover { color: var(--text); }
.body { white-space: pre-wrap; }
.body code { font-family: var(--mono); font-size: 12.5px; background: rgba(255, 255, 255, 0.07); padding: 1px 5px; border-radius: 5px; }
.body pre { font-family: var(--mono); font-size: 12.5px; background: rgba(0, 0, 0, 0.45); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; overflow-x: auto; white-space: pre; margin: 6px 0; }
.body h4 { margin: 6px 0 2px; font-size: 14px; }
.thread-link { font-size: 12px; color: var(--brand-b); background: none; border: 0; padding: 2px 0; cursor: pointer; }
.day { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; color: var(--faint); }
.day::before, .day::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.empty { color: var(--muted); text-align: center; padding: 48px 16px; }
.empty .big { font-size: 15px; color: var(--text); margin-bottom: 6px; }

/* ---------- composer ---------- */
.composer { padding: 10px 18px 16px; }
.composer-box { background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 8px; }
.composer-box:focus-within { border-color: rgba(139, 92, 246, 0.6); }
.replying { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding: 2px 6px 6px; }
.replying span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer textarea { border: 0; background: none; resize: none; padding: 6px 8px; min-height: 40px; max-height: 40vh; box-shadow: none; }
.composer-row { display: flex; align-items: center; gap: 8px; }
.composer-row select { width: auto; padding: 5px 8px; font-size: 12px; }
.composer-row .hint { flex: 1; font-size: 11.5px; color: var(--faint); }
.archived-note { text-align: center; color: var(--muted); padding: 14px; font-size: 13px; }

/* ---------- pages (agents / admin) ---------- */
.page { flex: 1; overflow-y: auto; padding: 20px 18px 40px; }
.page-inner { max-width: 960px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel h3 { margin: 0 0 12px; font-size: 15px; }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h3 { margin: 0; flex: 1; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.tab { padding: 7px 14px; border-radius: 10px; border: 1px solid var(--line); background: none; color: var(--muted); cursor: pointer; }
.tab.on { background: var(--panel-2); color: var(--text); border-color: var(--line-2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.list { display: grid; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: rgba(0, 0, 0, 0.2); flex-wrap: wrap; }
.item .grow { flex: 1; min-width: 160px; }
.item .sub { color: var(--muted); font-size: 12.5px; }
.tag { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.tag.admin { color: #c4b5fd; border-color: rgba(139, 92, 246, 0.5); }
.tag.off { color: #fda4af; border-color: rgba(244, 63, 94, 0.45); }
.group-block { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; background: rgba(0, 0, 0, 0.18); }
.group-block .chan { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.group-block .chan:first-of-type { border-top: 0; }
.group-block .chan .grow { flex: 1; min-width: 140px; }
.token-box { background: rgba(0, 0, 0, 0.5); border: 1px solid rgba(52, 211, 153, 0.4); border-radius: 12px; padding: 12px; margin-top: 12px; }
.token-box pre { margin: 6px 0 10px; white-space: pre-wrap; word-break: break-all; font-family: var(--mono); font-size: 12px; background: rgba(255, 255, 255, 0.04); padding: 8px 10px; border-radius: 8px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.audit-row { font-family: var(--mono); font-size: 12px; padding: 6px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }

/* ---------- modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: min(560px, 100%); max-height: 90vh; overflow-y: auto; background: #0e1018; border: 1px solid var(--line-2); border-radius: 18px; padding: 18px; }
.modal h3 { margin: 0 0 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #151826; border: 1px solid var(--line-2); padding: 10px 16px; border-radius: 12px; z-index: 60; max-width: calc(100% - 32px); }
.toast.err { border-color: rgba(244, 63, 94, 0.6); }
.search-box { padding: 4px 8px 6px; }
.search-box input { padding: 7px 10px; font-size: 13px; }

/* ---------- mobile ---------- */
.scrim { display: none; }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 40; transform: translateX(-100%); transition: transform 0.2s ease; background: #0b0c12; }
  .shell.drawer .sidebar { transform: none; }
  .shell.drawer .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 30; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 12px; }
  .topbar .desc { display: none; }
  .messages, .page { padding-left: 12px; padding-right: 12px; }
  .filters { padding-left: 12px; padding-right: 12px; }
  .composer { padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); }
  .composer-row .hint { display: none; }
  .msg-actions { opacity: 1; }
  .grid2 { grid-template-columns: 1fr; }
}
