/* Agent Chat. Dark is the default; light follows the OS unless the user picks one in Settings
   (boot.js and ui-helpers.js set data-theme on <html>). No inline styles anywhere: the CSP forbids them. */

:root {
  --bg: #0c0f14;
  --bg-2: #10141b;
  --panel: #151a22;
  --panel-2: #1b212b;
  --panel-3: #232a36;
  --line: #222a36;
  --line-2: #2e3846;
  --text: #eef1f6;
  --text-2: #c3cad6;
  --muted: #8e98a8;
  --accent: #5eead4;
  --accent-2: #2dd4bf;
  --accent-ink: #032420;
  --accent-soft: rgba(94, 234, 212, 0.12);
  --accent-line: rgba(94, 234, 212, 0.38);
  --agent: #b9a8ff;
  --agent-soft: rgba(185, 168, 255, 0.14);
  --human: #fcc94d;
  --human-soft: rgba(252, 201, 77, 0.13);
  --on-human: #1b1203;
  --danger: #ff8080;
  --danger-soft: rgba(255, 128, 128, 0.13);
  --danger-solid: #e5484d;
  --ok: #5ee08a;
  --ok-soft: rgba(94, 224, 138, 0.12);
  --mention: rgba(252, 201, 77, 0.075);
  --scrim: rgba(4, 6, 10, 0.62);
  --avatar-l: 72%;
  --avatar-ink-l: 16%;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 30px 80px -20px rgba(0, 0, 0, 0.7), 0 4px 12px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #ffffff; --bg-2: #f5f6f8; --panel: #ffffff; --panel-2: #f1f3f6; --panel-3: #e8ebf0;
    --line: #e4e8ee; --line-2: #cfd6e0; --text: #0f141b; --text-2: #354152; --muted: #5c6777;
    --accent: #0b7a6f; --accent-2: #0a6a61; --accent-ink: #ffffff; --accent-soft: rgba(11, 122, 111, 0.09); --accent-line: rgba(11, 122, 111, 0.35);
    --agent: #5a3ed6; --agent-soft: rgba(90, 62, 214, 0.08);
    --human: #9a4a00; --human-soft: rgba(176, 90, 0, 0.09); --on-human: #ffffff;
    --danger: #c22a2a; --danger-soft: rgba(194, 42, 42, 0.08); --danger-solid: #d0353a;
    --ok: #12773a; --ok-soft: rgba(18, 119, 58, 0.09);
    --mention: rgba(214, 140, 0, 0.07); --scrim: rgba(15, 20, 27, 0.32);
    --avatar-l: 80%; --avatar-ink-l: 22%;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow: 0 12px 32px -10px rgba(16, 24, 40, 0.18), 0 2px 6px rgba(16, 24, 40, 0.06);
    --shadow-lg: 0 30px 80px -24px rgba(16, 24, 40, 0.3), 0 4px 12px rgba(16, 24, 40, 0.08);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #ffffff; --bg-2: #f5f6f8; --panel: #ffffff; --panel-2: #f1f3f6; --panel-3: #e8ebf0;
  --line: #e4e8ee; --line-2: #cfd6e0; --text: #0f141b; --text-2: #354152; --muted: #5c6777;
  --accent: #0b7a6f; --accent-2: #0a6a61; --accent-ink: #ffffff; --accent-soft: rgba(11, 122, 111, 0.09); --accent-line: rgba(11, 122, 111, 0.35);
  --agent: #5a3ed6; --agent-soft: rgba(90, 62, 214, 0.08);
  --human: #9a4a00; --human-soft: rgba(176, 90, 0, 0.09); --on-human: #ffffff;
  --danger: #c22a2a; --danger-soft: rgba(194, 42, 42, 0.08); --danger-solid: #d0353a;
  --ok: #12773a; --ok-soft: rgba(18, 119, 58, 0.09);
  --mention: rgba(214, 140, 0, 0.07); --scrim: rgba(15, 20, 27, 0.32);
  --avatar-l: 80%; --avatar-ink-l: 22%;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 12px 32px -10px rgba(16, 24, 40, 0.18), 0 2px 6px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 30px 80px -24px rgba(16, 24, 40, 0.3), 0 4px 12px rgba(16, 24, 40, 0.08);
  color-scheme: light;
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.55 var(--sans);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  text-rendering: optimizeLegibility;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); text-underline-offset: 2px; }
h1, h2, h3 { letter-spacing: -0.012em; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }

.app { height: 100vh; height: 100dvh; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.only-mobile { display: none; }

.icon { width: 18px; height: 18px; flex: none; display: block; }

/* Avatars: one hue class per identity (10 degree steps), shape and ring per principal. */
.hue-0 { --h: 0; } .hue-1 { --h: 10; } .hue-2 { --h: 20; } .hue-3 { --h: 30; } .hue-4 { --h: 40; } .hue-5 { --h: 50; }
.hue-6 { --h: 60; } .hue-7 { --h: 70; } .hue-8 { --h: 80; } .hue-9 { --h: 90; } .hue-10 { --h: 100; } .hue-11 { --h: 110; }
.hue-12 { --h: 120; } .hue-13 { --h: 130; } .hue-14 { --h: 140; } .hue-15 { --h: 150; } .hue-16 { --h: 160; } .hue-17 { --h: 170; }
.hue-18 { --h: 180; } .hue-19 { --h: 190; } .hue-20 { --h: 200; } .hue-21 { --h: 210; } .hue-22 { --h: 220; } .hue-23 { --h: 230; }
.hue-24 { --h: 240; } .hue-25 { --h: 250; } .hue-26 { --h: 260; } .hue-27 { --h: 270; } .hue-28 { --h: 280; } .hue-29 { --h: 290; }
.hue-30 { --h: 300; } .hue-31 { --h: 310; } .hue-32 { --h: 320; } .hue-33 { --h: 330; } .hue-34 { --h: 340; } .hue-35 { --h: 350; }

.avatar {
  width: 36px; height: 36px; flex: none; border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px; letter-spacing: 0.02em;
  background: hsl(var(--h) 70% var(--avatar-l));
  color: hsl(var(--h) 60% var(--avatar-ink-l));
  user-select: none;
}
.avatar.agent {
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--agent);
}
.avatar.sm { width: 22px; height: 22px; font-size: 9.5px; border-radius: 6px; }
.avatar.sm.agent { border-radius: 50%; box-shadow: 0 0 0 1.5px var(--bg-2), 0 0 0 2.5px var(--agent); }
.avatar.lg { width: 56px; height: 56px; font-size: 20px; border-radius: 16px; }
.avatar.lg.agent { border-radius: 50%; }

.tag {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 1px 6px; border-radius: 5px; line-height: 16px; white-space: nowrap;
}
.tag.agent { background: var(--agent-soft); color: var(--agent); }
.tag.human { background: var(--human-soft); color: var(--human); }
.tag.warn { background: var(--danger-soft); color: var(--danger); }
.owner { font-size: 12px; color: var(--muted); white-space: nowrap; }

.glyph { width: 22px; height: 22px; display: grid; place-items: center; color: var(--muted); flex: none; }
.glyph .icon { width: 16px; height: 16px; }

.kbd {
  font: 600 10.5px/1 var(--mono); padding: 3px 6px; border-radius: 5px;
  border: 1px solid var(--line-2); color: var(--muted); background: var(--panel); white-space: nowrap;
}
kbd { font: 600 10.5px/1 var(--mono); padding: 2px 5px; border-radius: 4px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text-2); }

.spinner {
  width: 14px; height: 14px; border-radius: 50%; display: inline-block; flex: none; vertical-align: -2px;
  border: 2px solid currentColor; border-right-color: transparent; opacity: 0.75;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons and inputs ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; font-size: 13.5px;
  text-decoration: none; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, filter 0.15s;
}
.btn .icon { width: 16px; height: 16px; }
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.danger.solid { background: var(--danger-solid); border-color: var(--danger-solid); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--panel-2); color: var(--text); }
.btn.ok { color: var(--ok); border-color: var(--ok); }
.btn:disabled, .btn.busy { opacity: 0.65; cursor: default; transform: none; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.xs { padding: 2px 8px; font-size: 11.5px; border-radius: 6px; }
.btn.xs .icon { width: 13px; height: 13px; }

.icon-btn {
  border: 0; background: transparent; color: var(--muted); cursor: pointer; flex: none;
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  transition: background 0.12s, color 0.12s;
}
.icon-btn .icon { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }

.link {
  border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font-weight: 600;
}
.link:hover { text-decoration: underline; text-underline-offset: 2px; }
.link.danger { color: var(--danger); }

.input, .select {
  width: 100%; background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  padding: 9px 12px; outline: 0; transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.8; }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input:disabled { opacity: 0.6; }
textarea.input { resize: vertical; min-height: 84px; line-height: 1.5; }
.input.bare { border: 0; background: transparent; box-shadow: none; padding-left: 0; }
.select { width: auto; padding: 6px 28px 6px 10px; cursor: pointer; appearance: none; font-size: 13px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }

.input-affix { display: flex; align-items: stretch; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--bg); transition: border-color 0.15s, box-shadow 0.15s; }
.input-affix:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-affix .affix { padding: 9px 0 9px 12px; color: var(--muted); font-weight: 600; }
.input-affix .input { border: 0; box-shadow: none; background: transparent; padding-left: 4px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 12.5px; font-weight: 650; color: var(--text-2); }
.help { font-size: 12.5px; color: var(--muted); margin: 0; }

.form-error {
  display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--danger-soft); color: var(--danger); font-size: 13px; font-weight: 500;
}
.form-error .icon { width: 16px; height: 16px; margin-top: 1px; }

.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.seg button {
  border: 0; background: transparent; padding: 5px 12px; cursor: pointer; color: var(--muted);
  border-radius: 7px; font-size: 13px; font-weight: 600; transition: background 0.15s, color 0.15s;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line-2); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }

/* ---------- Brand ---------- */

.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: conic-gradient(from 210deg at 50% 50%, var(--accent), var(--agent), var(--human), var(--accent));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 7px 7px 9px; border-radius: 3px 3px 3px 0;
  background: var(--bg); opacity: 0.88;
}
.brand-mark.big { width: 64px; height: 64px; border-radius: 19px; }
.brand-mark.big::after { inset: 15px 15px 19px; border-radius: 5px 5px 5px 0; }
.brand-mark.pulse { animation: pulse 1.6s var(--ease) infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(0.92); opacity: 0.7; } }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 750; letter-spacing: -0.01em; font-size: 15px; }

/* ---------- Boot ---------- */

.splash { height: 100%; display: grid; place-items: center; align-content: center; gap: 18px; padding: 24px; }
.splash-text { color: var(--muted); margin: 0; }
.boot-failed { width: min(460px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.boot-failed h1 { margin: 0; font-size: 20px; }
.boot-failed .tokenbox { width: 100%; }

/* ---------- Onboarding ---------- */

.onboard {
  height: 100%; overflow-y: auto; display: grid; place-items: center; padding: 32px 20px;
  background:
    radial-gradient(900px 520px at 12% -8%, var(--accent-soft), transparent 62%),
    radial-gradient(700px 480px at 108% 112%, var(--agent-soft), transparent 60%),
    var(--bg);
}
.onboard-grid { width: min(1000px, 100%); display: grid; grid-template-columns: 1.05fr 1fr; gap: 56px; align-items: center; }
.pitch { display: flex; flex-direction: column; gap: 26px; }
.hero { font-size: 40px; line-height: 1.12; font-weight: 800; letter-spacing: -0.03em; margin: 0; }
.points { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 16px; }
.points li { display: flex; gap: 14px; align-items: flex-start; color: var(--text-2); }
.points b { color: var(--text); font-weight: 650; }
.point-icon {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--panel); border: 1px solid var(--line); color: var(--accent);
}
.onboard-card { padding: 30px; display: flex; flex-direction: column; gap: 18px; animation: rise 0.4s var(--ease); }
.card-title { margin: 0; font-size: 22px; font-weight: 750; }
.lede { color: var(--text-2); margin: 0; }
.key-note {
  display: flex; gap: 10px; align-items: flex-start; font-size: 12.5px; color: var(--text-2);
  padding: 10px 12px; border-radius: var(--radius-sm); background: var(--accent-soft);
}
.key-note .icon { color: var(--accent); width: 16px; height: 16px; margin-top: 1px; }
.key-note.offline { background: var(--danger-soft); color: var(--danger); }
.key-note.offline .icon { color: var(--danger); }
.switch { font-size: 13px; color: var(--muted); }
.onboard .btn.primary { padding: 11px 16px; font-size: 14px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Shell ---------- */

.shell { display: grid; grid-template-columns: 276px minmax(0, 1fr); height: 100%; }
.shell.with-side { grid-template-columns: 276px minmax(0, 1fr) minmax(340px, 420px); }
.drawer-scrim { display: none; }

/* ---------- Sidebar ---------- */

.side {
  background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
}
.side-head { display: flex; align-items: center; gap: 8px; padding: 14px 12px 6px 14px; }
.side-head .brand { border: 0; background: none; padding: 4px; margin: -4px; border-radius: 10px; cursor: pointer; text-align: left; min-width: 0; flex: 1; }
.side-head .brand:hover { background: var(--panel-2); }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.brand-server { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; color: var(--muted); padding: 3px 8px 3px 7px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); flex: none; }
.conn-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.conn.on .conn-dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.conn.wait .conn-dot { background: var(--human); animation: blink 1.2s ease-in-out infinite; }
.conn.off { color: var(--danger); border-color: var(--danger-soft); }
.conn.off .conn-dot { background: var(--danger); }
@keyframes blink { 50% { opacity: 0.3; } }

.search-trigger {
  margin: 10px 12px 6px; padding: 8px 10px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  display: flex; align-items: center; gap: 9px; cursor: pointer; text-align: left; font-size: 13.5px;
  transition: border-color 0.15s, color 0.15s;
}
.search-trigger .icon { width: 16px; height: 16px; }
.search-trigger .kbd { margin-left: auto; }
.search-trigger:hover { border-color: var(--line-2); color: var(--text-2); }

.side-scroll { overflow-y: auto; padding: 2px 8px 16px; flex: 1; min-height: 0; }
.section { margin-top: 10px; }
.section-head {
  display: flex; align-items: center; gap: 6px; padding: 6px 6px 4px 8px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.section-head .count { background: var(--human); color: var(--on-human); border-radius: 999px; padding: 0 6px; font-size: 10.5px; letter-spacing: 0; }
.section-actions { margin-left: auto; display: flex; gap: 2px; opacity: 0.85; }
.section-actions .icon-btn { width: 24px; height: 24px; border-radius: 6px; }
.section-actions .icon-btn .icon { width: 15px; height: 15px; }
.section-items { display: flex; flex-direction: column; gap: 1px; }

.conv-item {
  width: 100%; border: 0; background: transparent; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 14px; min-height: 34px;
  transition: background 0.12s, color 0.12s;
}
.conv-item:hover { background: var(--panel-2); color: var(--text); }
.conv-item.active { background: var(--accent-soft); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.conv-item.active .glyph { color: var(--accent); }
.conv-item.unread .conv-title { color: var(--text); font-weight: 650; }
.conv-item.muted { opacity: 0.7; }
.conv-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.badge {
  margin-left: auto; min-width: 20px; padding: 0 6px; height: 19px; border-radius: 999px;
  background: var(--panel-3); color: var(--text); font-size: 11px; font-weight: 700;
  display: grid; place-items: center; flex: none;
}
.badge.hot { background: var(--human); color: var(--on-human); }
.muted-icon { color: var(--muted); }
.alarm-mark { margin-left: auto; display: grid; place-items: center; width: 22px; height: 19px; border-radius: 999px; background: var(--danger-solid); color: #fff; animation: blink 1.6s ease-in-out infinite; }
.alarm-mark .icon { width: 13px; height: 13px; }
.muted-icon .icon, .observe-icon .icon { width: 14px; height: 14px; }
.observe-icon { color: var(--agent); }

.invite-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 8px; border-radius: var(--radius-sm);
  background: var(--human-soft); margin-bottom: 3px; font-size: 14px;
}
.invite-item .btn.ghost { padding: 2px 4px; }

.side-hint { font-size: 12.5px; color: var(--muted); padding: 4px 8px 6px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.side-hint.bad { color: var(--danger); }

.agent-row .chev { display: grid; place-items: center; color: var(--muted); transition: transform 0.18s var(--ease); margin-right: -4px; }
.agent-row .chev .icon { width: 14px; height: 14px; }
.agent-row .chev.open { transform: rotate(90deg); }
.agent-row.revoked .conv-title { text-decoration: line-through; color: var(--muted); }
.agent-convs { margin: 1px 0 6px 21px; padding-left: 8px; border-left: 1px solid var(--line-2); animation: rise 0.2s var(--ease); }
.agent-convs .conv-item { font-size: 13.5px; min-height: 30px; }
.conv-item.observed.active { background: var(--agent-soft); box-shadow: inset 2px 0 0 var(--agent); }
.agent-revoke { font-size: 12px; padding: 4px 8px; }

.me-card {
  border-top: 1px solid var(--line); padding: 10px 10px 10px 14px; display: flex; gap: 10px; align-items: center;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.me-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.me-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-key { color: var(--muted); font-size: 11px; }

/* ---------- Main pane ---------- */

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); position: relative; }

.topbar {
  min-height: 60px; flex: none; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px 10px 22px; border-bottom: 1px solid var(--line);
}
.topbar > .glyph, .topbar > .avatar { width: 32px; height: 32px; border-radius: 10px; background: var(--panel-2); color: var(--text-2); }
.topbar > .avatar { background: hsl(var(--h) 70% var(--avatar-l)); color: hsl(var(--h) 60% var(--avatar-ink-l)); font-size: 12px; }
.topbar > .avatar.agent { border-radius: 50%; }
.topbar > .glyph .icon { width: 17px; height: 17px; }
.topbar-title { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.topbar h1 { font-size: 16.5px; margin: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }
.topbar-sub { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-height: 18px; }
.pill {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; color: var(--muted);
  padding: 1px 7px 1px 5px; border-radius: 999px; background: var(--panel-2); line-height: 17px; white-space: nowrap; flex: none;
}
.pill .icon { width: 12px; height: 12px; }
.pill.e2ee { color: var(--accent); background: var(--accent-soft); }
.pill.ok { color: var(--ok); background: var(--ok-soft); }
.pill.warn { color: var(--danger); background: var(--danger-soft); }
.sub-muted { color: var(--muted); }
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.tb-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text-2); cursor: pointer; font-weight: 600; font-size: 12.5px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.tb-btn .icon { width: 16px; height: 16px; }
.tb-btn:hover { background: var(--panel-2); color: var(--text); }
.tb-btn.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.tb-btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tb-btn.accent:hover { filter: brightness(1.07); }

/* Banners */
.banner {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px 10px 22px; font-size: 13.5px;
  border-bottom: 1px solid var(--line); animation: rise 0.25s var(--ease);
}
.banner > .icon { width: 17px; height: 17px; }
.banner.offline { background: var(--danger-soft); color: var(--danger); }
.banner.key { background: var(--accent-soft); color: var(--text); }
.banner.key > .icon { color: var(--accent); }
.side .banner.key { flex-wrap: wrap; margin: 0 12px 10px; padding: 12px 14px; border-radius: var(--radius, 10px); border: 0; }
.side .banner.key > .grow { flex: 1 1 calc(100% - 40px); }
.banner.observer { background: var(--agent-soft); color: var(--text); }
.banner.observer > .icon { color: var(--agent); }
.banner.observer b, .banner.key b { font-weight: 650; }
.alarms:empty { display: none; }
.banner.alarm {
  background: var(--danger-solid); color: #fff; border-bottom: 0; align-items: flex-start;
  box-shadow: 0 6px 24px -8px rgba(229, 72, 77, 0.6);
}
.banner.alarm .alarm-title { font-weight: 750; }
.banner.alarm .icon-btn { color: #fff; }
.banner.alarm .icon-btn:hover { background: rgba(255, 255, 255, 0.16); }
.banner.alarm .btn { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.4); color: #fff; }

/* Timeline */
.timeline { flex: 1; overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.timeline-inner { padding: 8px 0 14px; min-height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }

.intro { padding: 28px 24px 18px; display: flex; flex-direction: column; gap: 6px; }
.intro h2 { margin: 6px 0 0; font-size: 22px; font-weight: 750; }
.intro p { margin: 0; color: var(--text-2); max-width: 60ch; }
.intro-glyph .glyph, .intro-glyph .avatar { width: 52px; height: 52px; border-radius: 15px; background: var(--panel-2); color: var(--accent); }
.intro-glyph .avatar { background: hsl(var(--h) 70% var(--avatar-l)); color: hsl(var(--h) 60% var(--avatar-ink-l)); font-size: 19px; }
.intro-glyph .avatar.agent { border-radius: 50%; }
.intro-glyph .glyph .icon { width: 26px; height: 26px; }
.intro-empty { color: var(--muted) !important; margin-top: 10px !important; }
.older { display: flex; justify-content: center; align-items: center; padding: 14px; color: var(--muted); gap: 6px; }

.day-sep { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; font-weight: 650; padding: 16px 24px 4px; }
.day-sep::before, .day-sep::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.day-sep span { padding: 2px 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }

.msg {
  display: grid; grid-template-columns: 40px minmax(0, 1fr); column-gap: 12px;
  padding: 3px 24px; position: relative; margin-top: 10px;
  transition: background 0.12s;
}
.msg:focus { outline: none; }
.msg:focus-visible { box-shadow: inset 2px 0 0 var(--accent); }
.msg.cont { margin-top: 0; padding-top: 1px; padding-bottom: 1px; }
.msg:hover { background: var(--bg-2); }
.msg.mentions-me { background: var(--mention); box-shadow: inset 3px 0 0 var(--human); }
.msg.pending .msg-text { opacity: 0.6; }
.msg.failed { box-shadow: inset 3px 0 0 var(--danger); }
.msg.focus { box-shadow: inset 3px 0 0 var(--accent); background: var(--accent-soft); }
.msg.flash { animation: flash 1.8s var(--ease); }
@keyframes flash { 0%, 30% { background: var(--accent-soft); } 100% { background: transparent; } }
.msg-gutter { padding-top: 2px; display: flex; justify-content: center; }
.msg-gutter .avatar { width: 38px; height: 38px; }
.msg-hover-time { font-size: 10.5px; color: var(--muted); opacity: 0; line-height: 22px; font-variant-numeric: tabular-nums; }
.msg:hover .msg-hover-time { opacity: 1; }
.msg-main { min-width: 0; }
.msg-head { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; line-height: 20px; }
.msg-name { font-weight: 680; color: var(--text); }
.msg-time { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.lock-mark { color: var(--accent); display: inline-grid; }
.lock-mark .icon { width: 12px; height: 12px; }
.delivery { display: inline-flex; align-items: center; gap: 3px; font-size: 11.5px; color: var(--muted); }
.delivery .icon { width: 14px; height: 14px; }
.delivery.durable { color: var(--accent); }
.delivery.sending .icon { animation: spin 2s linear infinite; }
.delivery.bad { color: var(--danger); font-weight: 600; }
.msg-foot { margin-top: 2px; }
.msg-topic {
  display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 15.5px; margin: 3px 0 2px; color: var(--text);
}
.msg-topic .icon { width: 16px; height: 16px; color: var(--accent); }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); }
.msg-text code {
  font-family: var(--mono); font-size: 12.5px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px;
}
.msg-text pre {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55; background: var(--bg-2); white-space: pre;
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; overflow-x: auto; margin: 6px 0;
}
.msg-text pre code { border: 0; padding: 0; background: none; }
.msg-text a { word-break: break-all; }
.mention { color: var(--accent); background: var(--accent-soft); border-radius: 4px; padding: 0 2px; font-weight: 600; }
.mention.me { color: var(--human); background: var(--human-soft); box-shadow: inset 0 -1.5px 0 var(--human); font-weight: 700; }
button.mention, .chan-link {
  font: inherit; font-weight: 600; border: 0;
  border-radius: 4px; padding: 0 3px; margin: 0; cursor: pointer; text-decoration: underline;
  text-decoration-color: transparent; text-underline-offset: 2px; transition: text-decoration-color 0.15s var(--ease);
}
.chan-link { color: var(--accent); background: var(--accent-soft); }
button.mention:hover, .chan-link:hover { text-decoration-color: currentColor; }
button.mention:focus-visible, .chan-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.msg-special { display: flex; align-items: flex-start; gap: 7px; line-height: 1.45; color: var(--muted); font-style: italic; font-size: 13.5px; }
.msg-special .icon { width: 15px; height: 15px; margin-top: 2px; }
.msg-special.waiting { color: var(--human); }
.msg-special .reason { font-style: normal; opacity: 0.8; }
.reply-quote {
  display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted);
  margin: 1px 0 3px; min-width: 0;
}
.reply-quote .icon { width: 13px; height: 13px; transform: scaleY(-1); flex: none; }
.rq-name { font-weight: 650; color: var(--text-2); flex: none; }
.rq-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.thread-link {
  margin-top: 5px; display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 4px 10px 4px 8px;
  color: var(--accent); font-size: 12.5px; font-weight: 650; transition: border-color 0.15s, background 0.15s;
}
.thread-link .icon { width: 14px; height: 14px; }
.thread-go { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); font-weight: 500; max-width: 0; overflow: hidden; opacity: 0; transition: max-width 0.25s var(--ease), opacity 0.2s; white-space: nowrap; }
.thread-link:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.thread-link:hover .thread-go { max-width: 120px; opacity: 1; }

.msg-actions {
  position: absolute; right: 18px; top: -14px; display: flex; gap: 1px; z-index: 2;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px; padding: 2px; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(3px); pointer-events: none; transition: opacity 0.12s, transform 0.12s;
}
.msg-actions:empty { display: none; }
.msg-actions .icon-btn { width: 28px; height: 28px; }
.msg-actions .icon-btn .icon { width: 15px; height: 15px; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; transform: none; pointer-events: auto; }

/* Skeletons */
.skel-row { display: flex; gap: 12px; padding: 12px 24px; }
.skel-lines { flex: 1; display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.skel { background: linear-gradient(90deg, var(--panel-2), var(--panel-3), var(--panel-2)); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; border-radius: 6px; }
.avatar-skel { width: 38px; height: 38px; border-radius: 10px; flex: none; }
.skel.line { height: 11px; }
.side-skel { display: flex; align-items: center; gap: 10px; padding: 9px 8px; }
.skel.dot { width: 18px; height: 18px; border-radius: 6px; flex: none; }
.w50 { width: 50%; }
.skel.short { width: 120px; } .w40 { width: 40%; } .w60 { width: 60%; } .w70 { width: 70%; } .w80 { width: 80%; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* Composer */
.composer { padding: 6px 20px 14px; flex: none; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
.composer-box {
  border: 1px solid var(--line-2); background: var(--panel); border-radius: 14px;
  padding: 6px 6px 6px 6px; transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-sm);
}
.composer-box.ghost { height: 50px; }
.composer-box:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer-row { display: flex; gap: 6px; align-items: flex-end; }
.composer textarea {
  border: 0; outline: 0; background: transparent; resize: none; flex: 1; min-width: 0;
  min-height: 24px; max-height: 260px; padding: 5px 2px; line-height: 1.5;
}
.topic-input {
  width: 100%; border: 0; outline: 0; background: transparent; font-weight: 700; font-size: 15px;
  padding: 6px 8px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px;
}
.topic-input::placeholder { color: var(--muted); font-weight: 600; }
.send-btn {
  width: 34px; height: 34px; border-radius: 10px; border: 0; cursor: pointer; flex: none;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  transition: transform 0.12s, opacity 0.15s, background 0.15s;
}
.send-btn .icon { width: 16px; height: 16px; }
.send-btn:hover:not(:disabled) { transform: translateY(-1px); }
.send-btn:disabled { background: var(--panel-3); color: var(--muted); cursor: default; }
.composer-hint { color: var(--muted); font-size: 11.5px; padding: 6px 6px 0; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.hint-e2ee { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; color: var(--accent); }
.hint-e2ee .icon { width: 12px; height: 12px; }
.reply-chip {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2);
  padding: 4px 4px 6px 8px; min-width: 0;
}
.reply-chip > .icon { width: 14px; height: 14px; color: var(--accent); transform: scaleY(-1); }
.reply-chip .rq-text { flex: 1; color: var(--muted); }
.reply-chip .icon-btn { width: 24px; height: 24px; }
.readonly {
  margin: 6px 20px 16px; padding: 12px 14px; border-radius: 12px; display: flex; align-items: center; gap: 10px;
  background: var(--panel-2); color: var(--text-2); font-size: 13.5px; border: 1px dashed var(--line-2);
}
.readonly > .icon { width: 17px; height: 17px; color: var(--muted); }
.invite-bar { background: var(--human-soft); border-style: solid; border-color: transparent; }

/* Home */
.home { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.home-top { padding: 10px 12px; }
.home-inner { margin: auto; padding: 40px 28px; width: min(760px, 100%); display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.home-title { font-size: 30px; margin: 14px 0 0; font-weight: 800; letter-spacing: -0.025em; }
.home-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 22px; width: 100%; }
.home-action {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left; cursor: pointer;
  padding: 16px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line);
  transition: border-color 0.15s, transform 0.15s var(--ease), box-shadow 0.15s;
}
.home-action:hover { border-color: var(--accent-line); transform: translateY(-2px); box-shadow: var(--shadow); }
.home-action-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); margin-bottom: 8px; }
.home-action-title { font-weight: 680; }
.home-action-body { font-size: 12.5px; color: var(--muted); }

/* Empty states */
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 36px 24px; gap: 6px; }
.empty-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--panel-2); color: var(--muted); margin-bottom: 8px; }
.empty-icon .icon { width: 22px; height: 22px; }
.empty-icon.bad { background: var(--danger-soft); color: var(--danger); }
.empty-title { font-weight: 700; font-size: 16px; }
.empty-body { color: var(--muted); margin: 0; max-width: 42ch; font-size: 13.5px; }
.empty-actions { margin-top: 12px; display: flex; gap: 8px; }

/* ---------- Side panels ---------- */

.panel { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg-2); animation: slide-in 0.22s var(--ease); }
@keyframes slide-in { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
.panel-head { min-height: 60px; display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.panel-head h3 { margin: 0; font-size: 15px; flex: 1; }
.panel-icon { color: var(--muted); display: grid; }
.panel-scroll { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: 12px; }
.panel-note { padding: 12px 18px; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 4px; }
.panel-note.bad { color: var(--danger); }
.panel-section { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.panel-section h3 { margin: 0; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.panel-section.actions { flex-direction: row; flex-wrap: wrap; }

.crumbs { display: flex; gap: 2px; align-items: center; font-size: 13px; overflow: hidden; flex: 1; min-width: 0; }
.crumb-conv { color: var(--muted); white-space: nowrap; font-weight: 600; }
.crumb { display: inline-flex; align-items: center; gap: 2px; border: 0; background: transparent; color: var(--accent); cursor: pointer; padding: 2px 4px 2px 0; border-radius: 6px; white-space: nowrap; min-width: 0; font-weight: 600; }
.crumb span { overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.crumb .icon { width: 13px; height: 13px; color: var(--muted); }
.crumb.current { color: var(--text); cursor: default; overflow: hidden; }
.crumb.current span { max-width: none; overflow: hidden; text-overflow: ellipsis; }
button.crumb:hover span { text-decoration: underline; text-underline-offset: 2px; }

.thread-panel .msg { padding-left: 16px; padding-right: 16px; grid-template-columns: 34px minmax(0, 1fr); column-gap: 10px; }
.thread-panel .msg-gutter .avatar { width: 32px; height: 32px; font-size: 12px; }
.thread-panel .msg-actions { right: 10px; }
.thread-panel .composer { padding: 6px 14px 14px; }
.thread-root { padding: 8px 0 6px; border-bottom: 1px solid var(--line); background: var(--bg); }
.thread-root .msg { margin-top: 6px; }
.thread-root.missing { display: flex; gap: 8px; align-items: center; padding: 16px 18px; font-weight: 700; }
.thread-root.missing .icon { color: var(--accent); }
.subthreads { padding: 10px 12px 4px; display: flex; flex-direction: column; gap: 2px; }
.subthreads .label { padding: 0 6px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.replies-sep { display: flex; align-items: center; gap: 10px; padding: 12px 16px 2px; color: var(--muted); font-size: 12px; font-weight: 650; }
.replies-sep::after { content: ""; height: 1px; background: var(--line); flex: 1; }

.thread-list { padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.thread-row {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer;
  border: 0; background: transparent; padding: 10px; border-radius: 10px; color: var(--text-2);
  transition: background 0.12s;
}
.thread-row:hover { background: var(--panel-2); color: var(--text); }
.thread-row > .icon { width: 15px; height: 15px; color: var(--muted); }
.thread-row-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.thread-row-icon .icon { width: 15px; height: 15px; }
.thread-row-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.thread-row-title { font-weight: 650; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-row-meta { font-size: 12px; color: var(--muted); }

.about { padding: 20px 18px 16px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.about-glyph .glyph, .about-glyph .avatar { width: 44px; height: 44px; border-radius: 13px; background: var(--panel-2); color: var(--accent); }
.about-glyph .avatar { background: hsl(var(--h) 70% var(--avatar-l)); color: hsl(var(--h) 60% var(--avatar-ink-l)); font-size: 16px; }
.about-glyph .avatar.agent { border-radius: 50%; }
.about-glyph .glyph .icon { width: 22px; height: 22px; }
.about-title { font-size: 18px; font-weight: 750; }
.about-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; margin-top: 6px; }
.fact { display: flex; flex-direction: column; padding: 8px 10px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }
.fact-k { font-size: 11px; color: var(--muted); font-weight: 600; }
.fact-v { font-weight: 650; font-size: 13.5px; }

.members { display: flex; flex-direction: column; gap: 2px; margin: 0 -8px; }
.member { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; }
.member:hover { background: var(--panel-2); }
.member .avatar.sm { width: 28px; height: 28px; font-size: 11px; border-radius: 8px; }
.member .avatar.sm.agent { border-radius: 50%; }
.member-main { flex: 1; min-width: 0; }
.member-name { display: flex; align-items: center; gap: 6px; font-weight: 600; flex-wrap: wrap; line-height: 1.3; }
.member-name .owner { display: none; }
.member-key { color: var(--muted); font-size: 11px; }
.member.revoked .member-name > span:first-child { text-decoration: line-through; color: var(--muted); }
.you { font-size: 11px; color: var(--muted); font-weight: 500; }
.role { font-size: 11.5px; font-weight: 650; color: var(--text-2); padding: 2px 8px; border-radius: 999px; background: var(--panel-2); }
.role-owner { color: var(--human); background: var(--human-soft); }
.role-admin { color: var(--accent); background: var(--accent-soft); }
.member-actions { display: flex; opacity: 0; transition: opacity 0.12s; }
.member:hover .member-actions, .member:focus-within .member-actions { opacity: 1; }
.member-actions .icon-btn { width: 26px; height: 26px; }
.member-actions .icon-btn .icon { width: 14px; height: 14px; }
.add-member { display: flex; gap: 6px; }
.add-member .input { flex: 1; min-width: 0; padding: 7px 10px; }

/* ---------- Modals ---------- */

.scrim {
  position: fixed; inset: 0; background: var(--scrim); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: grid; place-items: start center; padding: 10vh 16px 16px; z-index: 30; overflow-y: auto;
  animation: fade 0.15s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: min(520px, 100%); background: var(--panel); border: 1px solid var(--line-2);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  animation: pop 0.2s var(--ease);
}
.modal.wide { width: min(640px, 100%); }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.985); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; gap: 12px; align-items: flex-start; padding: 20px 16px 4px 20px; }
.modal-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 720; line-height: 1.3; padding-top: 1px; }
.modal-sub { margin: 3px 0 0; font-size: 13px; color: var(--muted); }
.modal-body { padding: 14px 20px 6px; display: flex; flex-direction: column; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px 18px; }

.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; cursor: pointer;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--bg);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.choice:hover { border-color: var(--muted); }
.choice.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 3px var(--accent-soft); }
.choice-icon { color: var(--accent); margin-bottom: 4px; }
.choice-title { font-weight: 700; }
.choice-body { font-size: 12.5px; color: var(--muted); }

.chips-input {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chips-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chip { display: inline-flex; align-items: center; gap: 2px; padding: 2px 4px 2px 9px; border-radius: 7px; background: var(--accent-soft); color: var(--text); font-weight: 600; font-size: 13px; }
.chip-x { border: 0; background: none; color: var(--muted); cursor: pointer; display: grid; padding: 2px; border-radius: 5px; }
.chip-x:hover { color: var(--text); background: var(--panel-3); }
.chip-x .icon { width: 13px; height: 13px; }
.chips-field { flex: 1; min-width: 140px; border: 0; outline: 0; background: transparent; padding: 4px 6px; }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.two .select { width: 100%; padding: 9px 28px 9px 12px; font-size: 14px; }

.token { display: flex; flex-direction: column; gap: 6px; }
.token-head { display: flex; align-items: center; justify-content: space-between; }
.token-head .btn.ok { color: var(--ok); border-color: var(--ok); }
.tokenbox {
  font: 12px/1.6 var(--mono); background: var(--bg); border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); padding: 10px 12px; word-break: break-all; user-select: all; color: var(--text);
  max-height: 160px; overflow-y: auto;
}
.explain { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--agent-soft); font-size: 13px; color: var(--text-2); }
.explain .icon { color: var(--agent); margin-top: 1px; }

.search-field { display: flex; align-items: center; gap: 8px; padding: 2px 12px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--bg); color: var(--muted); }
.search-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.list-note { color: var(--muted); padding: 18px 4px; display: flex; align-items: center; gap: 6px; }
.channel-list { display: flex; flex-direction: column; gap: 2px; max-height: 46vh; overflow-y: auto; margin: 0 -8px; }
.channel-row { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 10px; }
.channel-row:hover { background: var(--panel-2); }
.channel-row > .glyph { width: 34px; height: 34px; border-radius: 10px; background: var(--panel-2); color: var(--accent); }
.channel-name { font-weight: 650; }
.channel-meta { font-size: 12px; color: var(--muted); }

.identity { display: flex; gap: 14px; align-items: center; }
.identity-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 700; font-size: 17px; }
.identity-server { color: var(--muted); font-size: 13px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; border-top: 1px solid var(--line); }
.setting.col { flex-direction: column; align-items: stretch; }
.setting.col > .btn { align-self: flex-start; }
.setting-text { display: flex; flex-direction: column; gap: 2px; }
.danger-zone .label { color: var(--danger); }

/* Palette */
.palette-scrim { padding-top: 12vh; }
.palette {
  width: min(620px, 100%); background: var(--panel); border: 1px solid var(--line-2);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden; animation: pop 0.18s var(--ease);
}
.palette-input { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); color: var(--muted); }
.palette-input .icon { width: 19px; height: 19px; }
.palette-input input { flex: 1; border: 0; outline: 0; background: transparent; font-size: 16px; color: var(--text); min-width: 0; }
.palette-results { max-height: 52vh; overflow-y: auto; padding: 6px; }
.palette-group { padding: 4px 0; }
.palette-label { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: 6px 10px 4px; }
.palette-item {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
  border: 0; background: transparent; cursor: pointer; text-align: left; color: var(--text-2);
}
.palette-item:hover { background: var(--panel-2); color: var(--text); }
.palette-item.on { background: var(--accent-soft); color: var(--text); }
.palette-item.hit { align-items: flex-start; }
.palette-item.hit .grow { display: flex; flex-direction: column; gap: 1px; }
.hit-conv { font-size: 12px; font-weight: 650; color: var(--muted); }
.hit-snippet { color: var(--text); font-size: 13.5px; }
.hit-snippet mark { background: var(--human-soft); color: var(--text); border-radius: 3px; padding: 0 1px; box-shadow: inset 0 -1px 0 var(--human); }
.palette-note { padding: 14px 12px; color: var(--muted); font-size: 13px; display: flex; gap: 4px; align-items: center; }
.palette-foot { display: flex; gap: 16px; padding: 9px 16px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted); background: var(--bg-2); }
.palette-foot span { display: inline-flex; align-items: center; gap: 5px; }

/* Toasts */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 40; align-items: flex-end; pointer-events: none; }
.toast {
  pointer-events: auto; cursor: pointer; text-align: left;
  display: flex; gap: 10px; align-items: flex-start; max-width: 400px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 12px;
  padding: 10px 14px 10px 12px; box-shadow: var(--shadow); font-size: 13.5px;
  animation: toast-in 0.28s var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.toast-icon { color: var(--ok); display: grid; margin-top: 1px; }
.toast-icon .icon { width: 16px; height: 16px; }
.toast.bad { border-color: var(--danger); }
.toast.bad .toast-icon { color: var(--danger); }
.toast.mentioned { border-color: var(--human); }
.toast.mentioned .toast-icon { color: var(--human); }

/* ---------- Narrow screens ---------- */

@media (max-width: 1100px) {
  .home-grid { grid-template-columns: repeat(2, 1fr); }
  .shell.with-side { grid-template-columns: 248px minmax(0, 1fr) minmax(320px, 380px); }
}

@media (max-width: 860px) {
  .only-mobile { display: block; }
  .hide-narrow { display: none; }
  .shell, .shell.with-side { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: fixed; inset: 0 auto 0 0; width: min(320px, 86vw); z-index: 20;
    transform: translateX(-102%); transition: transform 0.25s var(--ease); box-shadow: var(--shadow-lg);
  }
  .shell.drawer-open .side { transform: none; }
  .shell.drawer-open .drawer-scrim { display: block; position: fixed; inset: 0; z-index: 15; border: 0; background: var(--scrim); animation: fade 0.2s; }
  .shell.at-home .side { position: static; width: auto; transform: none; box-shadow: none; border-right: 0; }
  .shell.at-home .main { display: none; }
  .panel { position: fixed; inset: 0; z-index: 18; border-left: 0; background: var(--bg); }
  .topbar { padding: 8px 10px 8px 8px; gap: 8px; }
  .topbar-sub .sub-muted, .topbar-sub .pill.ok { display: none; }
  .topbar-sub { flex-wrap: nowrap; overflow: hidden; }
  .tb-btn { padding: 0 8px; }
  .msg { padding-left: 14px; padding-right: 14px; column-gap: 10px; grid-template-columns: 34px minmax(0, 1fr); }
  .msg-gutter .avatar { width: 34px; height: 34px; }
  .msg-actions { right: 8px; }
  .composer { padding: 6px 10px 10px; }
  .composer-hint span:not(.hint-e2ee) { display: none; }
  .banner { padding-left: 14px; }
  .day-sep { padding-left: 14px; padding-right: 14px; }
  .intro { padding-left: 16px; padding-right: 16px; }
  .home-grid { grid-template-columns: 1fr; }
  .onboard-grid { grid-template-columns: 1fr; gap: 28px; }
  .hero { font-size: 28px; }
  .points { display: none; }
  .scrim { padding-top: 6vh; }
  .choice-grid, .two { grid-template-columns: 1fr; }
  .toasts { left: 12px; right: 12px; bottom: 12px; align-items: stretch; }
  .toast { max-width: none; }
}

@media (hover: none) {
  .msg:hover .msg-actions { opacity: 0; pointer-events: none; }
  .msg:focus-within .msg-actions { opacity: 1; transform: none; pointer-events: auto; }
  .msg-actions .icon-btn { width: 36px; height: 34px; }
  .member-actions { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
