:root {
  --bg: #08090b;
  --panel: #0f1013;
  --panel-2: #15161a;
  --line: #1f2126;
  --line-soft: #191b1f;
  --text: #f3f4f6;
  --muted: #8b8f98;
  --muted-2: #62666e;
  --accent: #6ee7b7;
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

/* ---------- gate ---------- */
#gate {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, #12141a 0%, #08090b 60%);
  z-index: 50;
}
#gate.hidden { display: none; }
.gate-card { width: 100%; max-width: 340px; text-align: center; }
.gate-card .mark { width: 64px; height: 64px; margin: 0 auto 18px; }
.gate-card h1 { font-size: 19px; font-weight: 600; margin: 0 0 6px; letter-spacing: -0.01em; }
.gate-card p { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }
.gate-card input {
  width: 100%; padding: 13px 15px; border-radius: 14px; background: var(--panel-2);
  border: 1px solid var(--line); outline: none; text-align: center; letter-spacing: 0.12em;
}
.gate-card input:focus { border-color: #343841; }
.gate-card button {
  width: 100%; margin-top: 10px; padding: 13px; border-radius: 14px;
  background: var(--text); color: #0a0a0b; font-weight: 600;
}
.gate-err { color: #f87171; font-size: 13px; height: 18px; margin-top: 10px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 272px minmax(0, 1fr) 296px; height: 100dvh; }
.shell.no-pane { grid-template-columns: 272px minmax(0, 1fr) 0; }

/* ---------- roster ---------- */
.roster {
  background: var(--panel); border-right: 1px solid var(--line-soft);
  display: flex; flex-direction: column; min-height: 0;
}
.roster-top { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 10px; }
.brand { font-size: 17px; font-weight: 650; letter-spacing: -0.02em; }
.roster-top .add {
  width: 28px; height: 28px; border-radius: 9px; background: var(--panel-2);
  border: 1px solid var(--line); color: var(--muted); font-size: 17px; line-height: 1;
  display: grid; place-items: center;
}
.roster-top .add:hover { color: var(--text); border-color: #2c2f36; }
.search { padding: 2px 12px 10px; }
.search input {
  width: 100%; padding: 9px 12px; border-radius: 11px; background: var(--panel-2);
  border: 1px solid transparent; outline: none; font-size: 13.5px;
}
.search input::placeholder { color: var(--muted-2); }
.search input:focus { border-color: var(--line); }
.bot-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.bot {
  display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; gap: 11px;
  align-items: center; padding: 9px 10px; border-radius: 13px; cursor: pointer;
  transition: background 0.12s ease;
}
.bot:hover { background: #14151a; }
.bot.active { background: #1a1c21; }
.bot .avatar { width: 38px; height: 38px; }
.bot-meta { min-width: 0; }
.bot-name { font-size: 14px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bot-line { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bot-right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.bot-time { font-size: 11px; color: var(--muted-2); }
.unread { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.working-dot { width: 7px; height: 7px; border-radius: 50%; background: #fbbf24; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { opacity: 0.35; } 50% { opacity: 1; } }
.roster-foot {
  border-top: 1px solid var(--line-soft); padding: 13px 18px; font-size: 13px; color: var(--muted);
  display: flex; align-items: center; gap: 9px;
}
.roster-foot .me { width: 24px; height: 24px; border-radius: 50%; background: #2a2d34; display: grid; place-items: center; font-size: 11px; color: #cfd3da; }

/* ---------- avatar ---------- */
.avatar { flex: none; display: block; }
.avatar bounce, .bot.busy .avatar { animation: bounce 0.9s ease-in-out infinite; }
@keyframes bounce { 0%,100% { transform: translateY(0) scale(1); } 45% { transform: translateY(-4px) scale(1.04); } }

/* ---------- thread ---------- */
.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.thread-head {
  display: flex; align-items: center; gap: 12px; padding: 13px 20px;
  border-bottom: 1px solid var(--line-soft); background: rgba(8,9,11,0.86);
  backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 5;
}
.thread-head .avatar { width: 34px; height: 34px; }
.th-meta { min-width: 0; flex: 1; }
.th-name { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.th-label { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-head .icon { width: 32px; height: 32px; border-radius: 9px; color: var(--muted); display: grid; place-items: center; }
.thread-head .icon:hover { background: var(--panel-2); color: var(--text); }
.back { display: none; width: 30px; height: 30px; border-radius: 9px; color: var(--muted); font-size: 20px; line-height: 1; }

.transcript { flex: 1; overflow-y: auto; padding: 26px 22px 8px; scroll-behavior: smooth; display: flex; flex-direction: column; }
.transcript-inner { max-width: 720px; width: 100%; margin: auto auto 0; display: flex; flex-direction: column; gap: 4px; }
.day { text-align: center; font-size: 11.5px; color: var(--muted-2); margin: 14px 0 12px; letter-spacing: 0.02em; }
.msg { display: flex; flex-direction: column; max-width: 100%; width: 100%; }
.msg.user { align-items: flex-end; }
.msg.bot { align-items: flex-start; }
.msg.bot .bubble { width: fit-content; max-width: 100%; margin-right: auto; text-align: left; }
.bubble {
  padding: 10px 14px; border-radius: var(--radius); font-size: 14.5px;
  max-width: min(600px, 82%); word-wrap: break-word; overflow-wrap: anywhere;
  margin: 3px 0; white-space: pre-wrap;
}
.msg.user .bubble { background: #23262c; border-bottom-right-radius: 7px; }
.msg.bot .bubble { background: transparent; padding-left: 0; padding-right: 0; border-radius: 0; max-width: 100%; }
.msg.bot .bubble + .bubble { margin-top: 8px; }
.bubble a { color: var(--accent); text-decoration: none; }
.bubble a:hover { text-decoration: underline; }
.bubble code { background: #1b1d22; padding: 1.5px 5px; border-radius: 5px; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.bubble pre {
  background: #101216; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  overflow-x: auto; font-size: 12.5px; line-height: 1.55; margin: 8px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bubble ul { margin: 6px 0; padding-left: 18px; }
.bubble li { margin: 2px 0; }
.msg-time { font-size: 10.5px; color: var(--muted-2); margin: 2px 2px 10px; }
.sender { font-size: 11.5px; color: var(--muted); margin: 10px 0 2px; }

.status[hidden] { display: none; }
.status[hidden] { display: none !important; }
.status {
  display: flex; align-items: center; gap: 8px; padding: 0 24px 6px;
  font-size: 12.5px; color: var(--muted);
}
.status .dot { width: 6px; height: 6px; border-radius: 50%; background: #fbbf24; animation: pulse 1.4s infinite; }

.composer { padding: 8px 22px 20px; }
.composer-inner {
  max-width: 720px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 20px; padding: 8px 8px 8px 16px;
  transition: border-color 0.15s ease;
}
.composer-inner:focus-within { border-color: #33373f; }
.composer textarea {
  flex: 1; background: none; border: 0; outline: none; resize: none; font-size: 14.5px;
  line-height: 1.5; max-height: 160px; padding: 6px 0;
}
.composer textarea::placeholder { color: var(--muted-2); }
.send {
  width: 32px; height: 32px; border-radius: 50%; background: var(--text); color: #08090b;
  display: grid; place-items: center; font-size: 15px; font-weight: 700; flex: none;
}
.send:disabled { opacity: 0.35; }
.hint { max-width: 720px; margin: 8px auto 0; font-size: 11px; color: var(--muted-2); text-align: center; }

/* ---------- right pane ---------- */
.pane {
  background: var(--panel); border-left: 1px solid var(--line-soft);
  padding: 18px 16px; overflow-y: auto; min-width: 0;
}
.pane.hidden { display: none; }
.pane h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted-2); margin: 0 0 10px; font-weight: 600; }
.pane section { margin-bottom: 26px; }
.routine {
  display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px;
  border-radius: 12px; background: var(--panel-2); margin-bottom: 7px; font-size: 13px;
}
.routine .when { color: var(--muted); font-size: 11.5px; }
.muted { color: var(--muted); font-size: 12.5px; line-height: 1.55; margin: 0; }

/* ---------- mobile ---------- */
@media (max-width: 1000px) {
  .shell { grid-template-columns: 272px minmax(0, 1fr); }
  .pane { display: none; }
  .pane.mobile { display: block; position: fixed; inset: 0; z-index: 30; border: 0; padding: 70px 18px 18px; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .roster { border: 0; }
  .thread {
    position: fixed; inset: 0; z-index: 20; transform: translateX(100%);
    transition: transform 0.22s ease; background: var(--bg);
  }
  .thread.open { transform: translateX(0); }
  .back { display: grid; place-items: center; }
  .thread-head { padding: 12px 14px; }
  .transcript { padding: 18px 16px 8px; }
  .bubble { max-width: 100%; }
  .msg.user .bubble { max-width: 84%; }
  .composer { padding: 8px 14px 16px; }
  .hint { display: none; }
}
@media (min-width: 861px) {
  .thread.open .back { display: none; }
}

/* ---------- v2: groups, attachments, approvals, sheets ---------- */
.chips { display: flex; gap: 7px; padding: 9px 20px; overflow-x: auto; border-bottom: 1px solid var(--line-soft); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px 5px 6px;
  border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line);
  font-size: 12.5px; color: var(--muted); white-space: nowrap;
}
.chip.on { color: var(--text); border-color: #3a3f49; background: #1c1f25; }
.chip .avatar { border-radius: 50%; }

.tool {
  width: 30px; height: 30px; border-radius: 50%; color: var(--muted); font-size: 15px;
  display: grid; place-items: center; flex: none;
}
.tool:hover { background: #22242a; color: var(--text); }
.tool.rec { background: #7f1d1d; color: #fff; animation: pulse 1.2s infinite; }

.tray { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 22px 8px; }
.tray[hidden] { display: none; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 8px 5px 10px;
  border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); font-size: 12.5px;
}
.pill img { width: 26px; height: 26px; border-radius: 7px; object-fit: cover; }
.pill button { color: var(--muted-2); font-size: 12px; padding: 0 2px; }
.pill button:hover { color: var(--text); }

.thumb { display: block; max-width: 220px; max-height: 220px; border-radius: 14px; margin: 6px 0 2px; }
.filechip {
  display: inline-block; padding: 7px 11px; border-radius: 11px; background: var(--panel-2);
  border: 1px solid var(--line); font-size: 12.5px; color: var(--muted); margin: 6px 0 2px;
}

.approval {
  border: 1px solid #3b3320; background: #191510; border-radius: 14px;
  padding: 12px 14px; margin: 8px 0; max-width: 560px;
}
.ap-head { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; color: #d6a545; margin-bottom: 6px; font-weight: 600; }
.ap-cmd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
  color: #e8e2d5; background: #100e0a; border: 1px solid #2a2418; border-radius: 9px;
  padding: 9px 11px; overflow-x: auto; white-space: pre-wrap; word-break: break-all;
}
.ap-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.ap-actions button {
  padding: 7px 13px; border-radius: 10px; background: #26232180; border: 1px solid #3b3320;
  font-size: 12.5px; color: #efe7d6;
}
.ap-actions button:hover { background: #302a20; }
.ap-actions button.deny { color: #f0a3a3; border-color: #4a2323; }
.ap-actions button:disabled { opacity: 0.5; }

.sheet {
  position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,0.55);
  display: grid; place-items: center; padding: 18px; backdrop-filter: blur(4px);
}
.sheet[hidden] { display: none; }
.sheet-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 16px; display: flex; flex-direction: column; gap: 9px;
}
.sheet-card h2 { font-size: 16px; font-weight: 620; margin: 2px 2px 0; letter-spacing: -0.01em; }
.sheet-card p { margin: 0 2px 6px; }
.sheet-card > button {
  padding: 12px 14px; border-radius: 13px; background: var(--panel-2); border: 1px solid var(--line);
  text-align: left; font-size: 14px;
}
.sheet-card > button:hover { background: #1b1d22; }
.sheet-card > button.primary { background: var(--text); color: #08090b; font-weight: 600; text-align: center; border-color: transparent; }
.sheet-card > button.dim { color: var(--muted); text-align: center; background: none; border-color: transparent; }
.sheet-card input {
  padding: 12px 14px; border-radius: 13px; background: var(--panel-2);
  border: 1px solid var(--line); outline: none; font-size: 14px;
}
.sheet-card input:focus { border-color: #343841; }
.pick { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.pickrow {
  display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: 11px;
  background: var(--panel-2); font-size: 13.5px; cursor: pointer;
}
.pickrow input { accent-color: #6ee7b7; }
@media (max-width: 860px) {
  .chips { padding: 8px 14px; }
  .tray { padding: 0 14px 8px; }
  .ap-cmd { font-size: 12px; }
}

.pane-close { display: none; }
.pane { position: relative; }
.top-actions { display: flex; gap: 6px; align-items: center; }
.roster-top .add { width: 34px; height: 34px; font-size: 16px; }
.thread-head .pane-btn { color: var(--text); background: var(--panel-2); border: 1px solid var(--line); width: 36px; height: 36px; font-size: 15px; }
@media (max-width: 1000px) {
  .pane.mobile { z-index: 35; background: var(--panel); }
  .pane.mobile .pane-close {
    display: block; width: 100%; padding: 12px; margin-bottom: 16px; border-radius: 13px;
    background: var(--panel-2); border: 1px solid var(--line); text-align: center; font-size: 14px; color: var(--text);
  }
}

.sender-name { font-size: 11.5px; color: var(--muted-2); margin: 12px 0 0; }
