/* ─────────────────────────── design tokens ─────────────────────────── */
:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 14px; --radius-sm: 10px; --radius-lg: 20px;
  --accent: #6d4cf2; --accent-2: #8f74ff; --accent-soft: rgba(109,76,242,.12); --accent-ring: rgba(109,76,242,.22);
  --success: #16a34a; --success-soft: rgba(22,163,74,.12);
  --danger: #e5484d; --danger-soft: rgba(229,72,77,.12);
  --warn: #f59e0b;
  --ease: cubic-bezier(.2,.8,.2,1);
}
/* light */
:root, :root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5fa; --bg-glow-1: rgba(109,76,242,.10); --bg-glow-2: rgba(16,185,129,.08);
  --surface: #ffffff; --surface-2: #f7f8fc; --surface-3: #eef0f6; --surface-glass: rgba(255,255,255,.78);
  --line: rgba(17,24,39,.08); --line-2: rgba(17,24,39,.14);
  --text: #111827; --text-2: #4b5563; --text-3: #8b93a7;
  --bubble-bot: #ffffff; --bubble-bot-line: rgba(17,24,39,.08); --bubble-user: linear-gradient(135deg, #6d4cf2, #8f74ff);
  --code-bg: #f1f2f7; --code-text: #1f2937; --pre-bg: #0f1220; --pre-text: #d7dbea;
  --shadow: 0 10px 30px rgba(17,24,39,.08), 0 1px 2px rgba(17,24,39,.06);
  --shadow-lg: 0 24px 60px rgba(17,24,39,.16);
  --btn-bg: #f1f2f7; --btn-bg-hover: #e8eaf2;
  --kb-bg: rgba(109,76,242,.08); --kb-line: rgba(109,76,242,.25); --kb-hover: rgba(109,76,242,.16);
  --scrollbar: rgba(17,24,39,.18);
}
/* dark */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { color-scheme: dark;
  --bg: #0b0d14; --bg-glow-1: rgba(124,92,255,.18); --bg-glow-2: rgba(0,194,168,.10);
  --surface: #12151f; --surface-2: #171b28; --surface-3: #1e2333; --surface-glass: rgba(16,19,29,.78);
  --line: rgba(255,255,255,.07); --line-2: rgba(255,255,255,.13);
  --text: #e8eaf2; --text-2: #a4a9ba; --text-3: #6b7085;
  --bubble-bot: #1a1f2e; --bubble-bot-line: rgba(255,255,255,.07); --bubble-user: linear-gradient(135deg, #6d4cf2, #8f74ff);
  --code-bg: rgba(255,255,255,.08); --code-text: #e8eaf2; --pre-bg: #0a0c13; --pre-text: #cfd3e3;
  --shadow: 0 10px 40px rgba(0,0,0,.45); --shadow-lg: 0 30px 80px rgba(0,0,0,.6);
  --btn-bg: #1b2030; --btn-bg-hover: #232a3d;
  --kb-bg: rgba(124,92,255,.14); --kb-line: rgba(124,92,255,.35); --kb-hover: rgba(124,92,255,.26);
  --scrollbar: rgba(255,255,255,.14);
} }
:root[data-theme="dark"] { color-scheme: dark;
  --bg: #0b0d14; --bg-glow-1: rgba(124,92,255,.18); --bg-glow-2: rgba(0,194,168,.10);
  --surface: #12151f; --surface-2: #171b28; --surface-3: #1e2333; --surface-glass: rgba(16,19,29,.78);
  --line: rgba(255,255,255,.07); --line-2: rgba(255,255,255,.13);
  --text: #e8eaf2; --text-2: #a4a9ba; --text-3: #6b7085;
  --bubble-bot: #1a1f2e; --bubble-bot-line: rgba(255,255,255,.07); --bubble-user: linear-gradient(135deg, #6d4cf2, #8f74ff);
  --code-bg: rgba(255,255,255,.08); --code-text: #e8eaf2; --pre-bg: #0a0c13; --pre-text: #cfd3e3;
  --shadow: 0 10px 40px rgba(0,0,0,.45); --shadow-lg: 0 30px 80px rgba(0,0,0,.6);
  --btn-bg: #1b2030; --btn-bg-hover: #232a3d;
  --kb-bg: rgba(124,92,255,.14); --kb-line: rgba(124,92,255,.35); --kb-hover: rgba(124,92,255,.26);
  --scrollbar: rgba(255,255,255,.14);
}

/* ─────────────────────────── base ─────────────────────────── */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: var(--font); color: var(--text); background: var(--bg);
  background-image: radial-gradient(1100px 600px at 8% -10%, var(--bg-glow-1), transparent 60%), radial-gradient(900px 500px at 108% 110%, var(--bg-glow-2), transparent 60%);
  -webkit-font-smoothing: antialiased; font-size: 14px; line-height: 1.45; transition: background-color .25s, color .25s;
}
a { color: var(--accent); text-decoration: none; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--text-3); font-weight: 400; font-size: 12px; }
.hint { color: var(--text-3); font-size: 12px; margin: 0 0 8px; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.mobile-only { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ─────────────────────────── layout ─────────────────────────── */
/* While booting: no transitions, no entry animations, main area stays blank until the saved bot is loaded. */
.app.booting *, .app.booting *::before, .app.booting *::after { transition: none !important; animation: none !important; }
.app.booting .main > * { visibility: hidden; }
.app { display: grid; grid-template-columns: 300px minmax(0,1fr) auto; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--line); background: var(--surface-glass); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.main { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.panel { width: 390px; min-height: 0; border-left: 1px solid var(--line); background: var(--surface-glass); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); display: flex; flex-direction: column; }

/* ─────────────────────────── sidebar ─────────────────────────── */
.brand { display: flex; gap: 12px; align-items: center; padding: 18px 16px 12px; }
.brand > div:nth-child(2) { flex: 1; min-width: 0; }
.brand-logo { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; font-weight: 700; color: #fff; background: linear-gradient(135deg, #6d4cf2, #ff5c8a); box-shadow: 0 8px 24px rgba(109,76,242,.35); flex: none; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { color: var(--text-3); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); display: inline-block; box-shadow: 0 0 0 3px rgba(245,158,11,.18); }
.dot.on { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.dot.off { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.theme-toggle { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line-2); background: transparent; cursor: pointer; display: grid; place-items: center; color: var(--text-2); transition: background .15s, transform .15s; flex: none; }
.theme-toggle:hover { background: var(--surface-3); color: var(--text); }
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .sun { display: none; }
.sound-toggle .bell-off { display: none; }
.sound-toggle.muted .bell { display: none; } .sound-toggle.muted .bell-off { display: block; }
.sound-toggle.muted { color: var(--danger); border-color: rgba(229,72,77,.35); background: var(--danger-soft); }   /* clearly off */
.sound-toggle.ring svg { animation: ring .6s var(--ease); transform-origin: 50% 10%; }
@keyframes ring { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(16deg); } 40% { transform: rotate(-14deg); } 60% { transform: rotate(8deg); } 80% { transform: rotate(-4deg); } }
.brand .theme-toggle + .theme-toggle { margin-left: -4px; }   /* bell and theme buttons sit as a pair */
:root[data-theme="dark"] .theme-toggle .sun { display: block; } :root[data-theme="dark"] .theme-toggle .moon { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .theme-toggle .sun { display: block; } :root:not([data-theme="light"]) .theme-toggle .moon { display: none; } }
.sidebar-tools { display: flex; gap: 8px; padding: 6px 14px 12px; }
.search { flex: 1; background: var(--surface-3); border: 1px solid transparent; color: var(--text); border-radius: 10px; padding: 9px 12px; outline: none; min-width: 0; transition: border-color .15s, box-shadow .15s; }
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); background: var(--surface); }
.bot-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 10px 12px; }
.bot-item { display: flex; gap: 12px; align-items: center; padding: 10px 10px; border-radius: 12px; cursor: pointer; transition: background .15s; }
.bot-item:hover { background: var(--surface-3); }
.bot-item.active { background: var(--accent-soft); }
.bot-item .meta { min-width: 0; flex: 1; }
.bot-item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bot-item .sub { color: var(--text-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: #fff; font-size: 11px; font-weight: 600; border-radius: 999px; padding: 2px 7px; min-width: 20px; text-align: center; }
.avatar { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; position: relative; font-size: 15px; letter-spacing: .02em; }
.avatar .presence { position: absolute; right: -3px; bottom: -3px; width: 11px; height: 11px; border-radius: 50%; background: var(--text-3); border: 2px solid var(--surface); }
.avatar .presence.on { background: var(--success); }
.sidebar-foot { position: relative; padding: 8px 10px; border-top: 1px solid var(--line); }
.me-avatar { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none; font-size: 11.5px; font-weight: 700; color: #fff; background: linear-gradient(135deg, #6d4cf2, #ff5c8a); text-transform: uppercase; }
.me-avatar.lg { width: 38px; height: 38px; border-radius: 11px; font-size: 13px; }
/* The account row: the email gets the whole width; Log out and the API link live in the menu above it. */
.account { width: 100%; display: flex; align-items: center; gap: 10px; padding: 7px 8px; border: 0; border-radius: 12px; background: transparent; cursor: pointer; text-align: left; color: var(--text); transition: background .15s; }
.account:hover, .account[aria-expanded="true"] { background: var(--surface-3); }
.account .me-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.account .me-name { font-weight: 600; font-size: 13px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }   /* long emails wrap (before the @), never cut */
.account .me-sub { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account .chev { width: 16px; height: 16px; color: var(--text-3); flex: none; transition: transform .2s var(--ease); }
.account[aria-expanded="true"] .chev { transform: rotate(180deg); }
.account-menu { position: absolute; left: 10px; right: 10px; bottom: calc(100% + 6px); z-index: 20; background: var(--surface); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 6px; animation: pop .16s var(--ease); }
.account-menu .menu-head { display: flex; align-items: center; gap: 10px; padding: 8px 8px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.account-menu .menu-who { min-width: 0; }
.account-menu .menu-email { font-weight: 600; font-size: 13px; color: var(--text); overflow-wrap: break-word; word-break: normal; line-height: 1.3; }
.account-menu .menu-meta { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.account-menu .menu-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 0; border-radius: 9px; background: none; color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer; text-align: left; text-decoration: none; }
.account-menu .menu-item svg { width: 16px; height: 16px; color: var(--text-3); flex: none; }
.account-menu .menu-item:hover { background: var(--surface-3); }
.account-menu .menu-item.danger { color: var(--danger); }
.account-menu .menu-item.danger svg { color: var(--danger); }
.account-menu .menu-item.danger:hover { background: var(--danger-soft); }
.list-empty { color: var(--text-3); text-align: center; padding: 30px 10px; font-size: 13px; }

/* ─────────────────────────── buttons ─────────────────────────── */
.btn { font-weight: 600; border: 1px solid transparent; border-radius: var(--radius-sm); padding: 9px 14px; cursor: pointer; color: var(--text); background: var(--btn-bg); transition: transform .08s, background .15s, border-color .15s, filter .15s; display: inline-flex; align-items: center; gap: 6px; justify-content: center; white-space: nowrap; }
.btn:hover { background: var(--btn-bg-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, #6d4cf2, #8f74ff); color: #fff; box-shadow: 0 6px 18px rgba(109,76,242,.3); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: var(--line-2); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(229,72,77,.3); }
.btn.danger:hover { background: rgba(229,72,77,.2); }
.btn.sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn.lg { padding: 13px 22px; font-size: 15px; border-radius: 12px; }
.btn.icon-btn { width: 38px; padding: 0; height: 38px; }

/* ─────────────────────────── empty state ─────────────────────────── */
.empty-state { flex: 1; display: grid; place-items: center; padding: 30px 20px; overflow: auto; }
.empty-card { max-width: 540px; text-align: center; padding: 48px 40px; border-radius: 26px; background: var(--surface-glass); border: 1px solid var(--line); box-shadow: var(--shadow); backdrop-filter: blur(20px); }
.empty-glyph { width: 72px; height: 72px; margin: 0 auto 20px; border-radius: 22px; display: grid; place-items: center; font-size: 34px; font-weight: 700; color: #fff; background: linear-gradient(135deg, #6d4cf2, #ff5c8a); box-shadow: 0 14px 40px rgba(109,76,242,.4); }
.empty-card h1 { margin: 0 0 10px; font-size: 26px; letter-spacing: -.02em; }
.empty-card p { color: var(--text-2); margin: 0 0 24px; }
.empty-card code { background: var(--code-bg); padding: 1px 6px; border-radius: 6px; }

/* ─────────────────────────── chat ─────────────────────────── */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header { display: flex; align-items: center; gap: 14px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--surface-glass); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.chat-peer { display: flex; gap: 12px; align-items: center; min-width: 0; flex: 1; }
.chat-peer > div:last-child { min-width: 0; }
.chat-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status { color: var(--text-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status.on { color: var(--success); }

/* The conversation uses the full width: bot messages hug the left edge, your messages the right, with an edge gap that grows with the window. */
.messages { --edge: clamp(16px, 3vw, 56px); flex: 1; overflow-y: auto; padding: 24px var(--edge) 12px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; container-type: inline-size; container-name: chat; }
.load-older { align-self: center; margin: 4px 0 8px; }
.day-sep { align-self: center; color: var(--text-3); font-size: 11.5px; background: var(--surface-3); padding: 3px 10px; border-radius: 999px; margin: 6px 0; }
.msg { display: flex; flex-direction: column; max-width: min(680px, 78%); animation: pop .22s var(--ease); }
/* Messages carrying buttons or a form get one consistent card width so keyboards line up and have room. */
.msg.rich { width: min(560px, 100%); max-width: 100%; }
.msg.rich .bubble { align-self: stretch; }
@container chat (max-width: 560px) { .msg { max-width: 92%; } .msg.rich { width: 100%; } }
@container chat (min-width: 900px) { .msg.rich { width: 600px; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.msg.static { animation: none; }
.msg.bot { align-self: flex-start; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 10px 14px; border-radius: 16px; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.5; position: relative; }
.msg.bot .bubble { background: var(--bubble-bot); border: 1px solid var(--bubble-bot-line); border-bottom-left-radius: 6px; box-shadow: 0 1px 2px rgba(17,24,39,.04); }
.msg.user .bubble { background: var(--bubble-user); color: #fff; border-bottom-right-radius: 6px; box-shadow: 0 6px 18px rgba(109,76,242,.25); }
.bubble pre { background: var(--pre-bg); color: var(--pre-text); padding: 10px 12px; border-radius: 8px; overflow-x: auto; margin: 6px 0; }
.bubble code { background: var(--code-bg); color: var(--code-text); padding: 1px 5px; border-radius: 5px; }
.msg.user .bubble code { background: rgba(255,255,255,.18); color: #fff; }
.bubble pre code { background: none; color: inherit; padding: 0; }
.bubble blockquote { margin: 6px 0; padding: 4px 10px; border-left: 3px solid var(--accent); color: var(--text-2); }
.bubble .spoiler { background: var(--text-2); color: transparent; border-radius: 4px; cursor: pointer; transition: .2s; }
.bubble .spoiler.revealed { background: var(--code-bg); color: inherit; }
.msg-meta { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 11px; margin-top: 4px; padding: 0 4px; }
.msg.user .msg-meta { justify-content: flex-end; }
/* Time · #id in the bubble's top-right corner; the text wraps around it. */
.bubble .stamp { float: right; margin: 1px 0 2px 14px; font-size: 11px; line-height: 1.6; color: var(--text-3); white-space: nowrap; user-select: none; }
.bubble .stamp .mid { opacity: .75; }
.msg.user .bubble .stamp { color: rgba(255,255,255,.72); }
.msg-meta .edited { font-style: italic; }
.bubble { position: relative; }
/* Floating action toolbar: appears on the bubble's top corner on hover (or tap on touch screens). */
.msg-actions { position: absolute; top: 4px; left: calc(100% + 8px); z-index: 3; display: flex; gap: 2px; padding: 3px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: 0 4px 14px rgba(17,24,39,.12); opacity: 0; transform: translateX(-4px); pointer-events: none; transition: opacity .14s, transform .14s var(--ease); }
.msg.user .msg-actions { left: auto; right: calc(100% + 8px); transform: translateX(4px); }
/* invisible bridge, so moving the pointer from the bubble to the toolbar keeps it open */
.msg-actions::before { content: ''; position: absolute; top: -6px; bottom: -6px; left: -12px; right: -6px; }
.msg.user .msg-actions::before { left: -6px; right: -12px; }
/* Narrow chats have no room beside the bubble: the toolbar sits on the bubble's top corner instead. */
@container chat (max-width: 640px) {
  .msg-actions { top: -30px; left: auto; right: 6px; transform: translateY(4px); }
  .msg.user .msg-actions { right: auto; left: 8px; transform: translateY(4px); }
}
.msg:hover .msg-actions, .msg:focus-within .msg-actions, .msg.actions-open .msg-actions { opacity: 1; transform: none; pointer-events: auto; }
.msg-actions .act { position: relative; width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: var(--text-2); cursor: pointer; transition: background .12s, color .12s; }
.msg-actions .act svg { width: 15px; height: 15px; }
.msg-actions .act:hover { background: var(--surface-3); color: var(--accent); }
.msg-actions .act.danger:hover { background: var(--danger-soft); color: var(--danger); }
.msg-actions .act:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
/* Tooltip */
.msg-actions .act::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 7px); left: 50%; transform: translateX(-50%); padding: 3px 7px; border-radius: 6px; background: var(--text); color: var(--surface); font-size: 11px; font-weight: 600; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s; }
.msg-actions .act:hover::after { opacity: 1; transition-delay: .25s; }
.msg:hover .bubble, .msg.actions-open .bubble { box-shadow: 0 0 0 1px var(--line-2), 0 2px 8px rgba(17,24,39,.06); }
.msg.user:hover .bubble { box-shadow: 0 6px 18px rgba(109,76,242,.32); }
/* Reply quote inside a bubble */
.bubble .quote { display: flex; flex-direction: column; gap: 1px; font-size: 12px; line-height: 1.35; border-left: 3px solid currentColor; padding: 4px 9px; margin: 0 0 7px; border-radius: 6px; background: rgba(255,255,255,.14); }
.msg.bot .bubble .quote { background: var(--accent-soft); border-color: var(--accent); }
.bubble .quote .quote-who { font-weight: 700; font-size: 11px; opacity: .9; }
.bubble .quote .quote-text { opacity: .85; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
/* Reply bar above the composer */
.reply-bar { display: flex; align-items: center; gap: 10px; margin: 8px clamp(16px, 3vw, 56px) -4px; padding: 8px 8px 8px 12px; background: var(--surface); border: 1px solid var(--line-2); border-left: 3px solid var(--accent); border-radius: 12px; box-shadow: 0 2px 10px rgba(17,24,39,.06); animation: pop .16s var(--ease); }
.reply-bar .reply-icon { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-weight: 700; flex: none; }
.reply-bar .reply-info { flex: 1; min-width: 0; line-height: 1.35; }
.reply-bar .reply-title { font-size: 12px; font-weight: 700; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar .reply-text { font-size: 12.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar .icon-btn { width: 28px; height: 28px; border-radius: 8px; }
.msg-meta .session { display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 10.5px; color: var(--text-3); padding: 1px 7px 1px 5px; border-radius: 999px; background: var(--surface-3); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-meta .session::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }

/* inline keyboard */
.keyboard { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; width: 100%; }
.kb-row { display: flex; flex-wrap: wrap; gap: 6px; }
/* Buttons share a row evenly, wrap to a new line below ~96px, and wrap their label instead of cutting it off. */
.kb-btn { flex: 1 1 96px; font-weight: 600; font-size: 13px; line-height: 1.25; padding: 9px 12px; min-height: 38px; border-radius: 10px; cursor: pointer; color: var(--text); background: var(--kb-bg); border: 1px solid var(--kb-line); transition: background .15s, transform .08s; min-width: 0; white-space: normal; overflow-wrap: anywhere; text-align: center; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.kb-btn:hover { background: var(--kb-hover); }
.kb-btn:active { transform: scale(.98); }
.kb-btn.pressed { animation: pressed .5s ease-out; }
@keyframes pressed { 0% { box-shadow: 0 0 0 0 rgba(109,76,242,.6); } 100% { box-shadow: 0 0 0 10px rgba(109,76,242,0); } }
.kb-btn.primary { background: linear-gradient(135deg, #6d4cf2, #8f74ff); border-color: transparent; color: #fff; }
.kb-btn.success { background: var(--success-soft); border-color: rgba(22,163,74,.4); color: var(--success); }
.kb-btn.danger { background: var(--danger-soft); border-color: rgba(229,72,77,.4); color: var(--danger); }
.kb-btn.url::after { content: ' ↗'; opacity: .6; }
/* The pressed button: solid colour with a check mark; the other buttons on that message step back. */
.kb-btn.selected { background: linear-gradient(135deg, #6d4cf2, #8f74ff); border-color: transparent; color: #fff; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px rgba(109,76,242,.45); }
.kb-btn.selected::before { content: '✓'; font-weight: 800; margin-right: 6px; }
.kb-btn.selected.no-tick::before { content: none; }
.kb-btn.success.selected { background: #16a34a; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px rgba(22,163,74,.45); }
.kb-btn.danger.selected { background: #e5484d; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px rgba(229,72,77,.45); }
.keyboard.has-selection .kb-btn:not(.selected):not(.url) { opacity: .55; }
.keyboard.has-selection .kb-btn:not(.selected):not(.url):hover { opacity: 1; }
.kb-btn.busy { opacity: .6; pointer-events: none; }

/* input form */
.inform { margin-top: 8px; width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 1px 2px rgba(17,24,39,.04); }
.inform label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); font-weight: 500; }
.inform input, .inform select, .inform textarea, .composer textarea, .playground textarea, .playground select, .modal input {
  color: var(--text); background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 9px; padding: 9px 11px; outline: none; width: 100%; transition: border-color .15s, box-shadow .15s;
}
.inform input:focus, .inform select:focus, .inform textarea:focus, .composer textarea:focus, .playground textarea:focus, .playground select:focus, .modal input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.inform .req { color: var(--danger); }
.inform .submit { align-self: flex-end; }
.inform.locked { background: var(--success-soft); border-color: rgba(22,163,74,.25); }
.answer { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; margin: 0; }
.answer dt { color: var(--text-3); }
.answer dd { margin: 0; font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
.answer-head { color: var(--success); font-size: 12px; font-weight: 600; display: flex; gap: 6px; align-items: center; }

/* typing */
.typing { display: flex; gap: 4px; padding: 0 28px 8px; height: 20px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* composer */
.composer { display: flex; gap: 10px; padding: 12px clamp(16px, 3vw, 56px) calc(16px + env(safe-area-inset-bottom)); align-items: flex-end; border-top: 1px solid var(--line); background: var(--surface-glass); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.composer textarea { resize: none; max-height: 160px; line-height: 1.45; border-radius: 14px; padding: 11px 14px; background: var(--surface); }
.composer .send { width: 44px; height: 44px; padding: 0; border-radius: 13px; font-size: 16px; flex: none; }

/* ─────────────────────────── panel ─────────────────────────── */
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-body { overflow-y: auto; padding: 6px 18px 24px; }
.panel-section { padding: 16px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.panel-section:last-child { border-bottom: 0; }
.panel-section h3 { margin: 0 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-2); display: flex; gap: 8px; align-items: baseline; }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--text-2); }
.kv code { color: var(--text); background: var(--code-bg); padding: 2px 7px; border-radius: 6px; }
.field-label { font-size: 12px; color: var(--text-3); margin-top: 6px; }
.token-row { display: flex; gap: 6px; align-items: center; }
.token { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: var(--code-bg); padding: 7px 10px; border-radius: 8px; }
.token-big { display: block; background: var(--accent-soft); border: 1px dashed var(--accent); border-radius: 10px; padding: 12px; word-break: break-all; margin: 12px 0; font-size: 13px; }
.code-block { background: var(--pre-bg); color: var(--pre-text); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow: auto; margin: 0; max-height: 320px; line-height: 1.55; white-space: pre; }
.code-block.small { font-size: 11.5px; max-height: 220px; }
.snippet-tabs { display: flex; gap: 4px; background: var(--surface-3); padding: 3px; border-radius: 9px; width: fit-content; }
.snippet-tabs .tab { font-size: 12px; font-weight: 600; background: transparent; color: var(--text-2); border: none; border-radius: 7px; padding: 5px 10px; cursor: pointer; }
.snippet-tabs .tab.active { background: var(--accent); color: #fff; }
.playground { display: flex; flex-direction: column; gap: 8px; }
.playground textarea { resize: vertical; }
.playground select { flex: 1; min-width: 0; }
.pg-result { font-size: 12px; color: var(--text-3); font-family: var(--mono); white-space: pre-wrap; }
.pg-result.err { color: var(--danger); }
.pg-result.ok { color: var(--success); }

/* ─────────────────────────── modals ─────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(5,6,10,.45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; animation: fade .15s; padding: 16px; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(460px, 100%); background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius-lg); padding: 26px; box-shadow: var(--shadow-lg); animation: pop .2s var(--ease); max-height: 90vh; overflow: auto; }
.modal.small { width: min(380px, 100%); }
.modal.wide { width: min(820px, 100%); }
.modal h2 { margin: 0 0 14px; font-size: 18px; letter-spacing: -.01em; }
.modal p { color: var(--text-2); }
.modal form { display: flex; flex-direction: column; gap: 12px; }
.modal label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 9px; cursor: pointer; border: 2px solid transparent; transition: transform .1s; }
.swatch:hover { transform: scale(1.1); }
.swatch.active { border-color: var(--surface); box-shadow: 0 0 0 2px var(--text); }

/* docs */
.docs { color: var(--text-2); font-size: 13.5px; }
.docs h3 { color: var(--text); margin: 22px 0 6px; font-size: 14px; }
.docs h3 code { color: var(--accent); }
.docs code { background: var(--code-bg); color: var(--code-text); padding: 1px 6px; border-radius: 5px; }
.docs pre { background: var(--pre-bg); color: var(--pre-text); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow: auto; }
.docs pre code { background: none; color: inherit; padding: 0; }
.docs table { width: 100%; border-collapse: collapse; margin: 6px 0; }
.docs td, .docs th { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.docs th { color: var(--text-3); font-weight: 600; font-size: 12px; }

/* toasts */
.toasts { position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--surface); color: var(--text); border: 1px solid var(--line-2); border-radius: 12px; padding: 10px 16px; box-shadow: var(--shadow-lg); animation: pop .2s var(--ease); font-weight: 500; display: flex; gap: 10px; align-items: center; }
.toast.err { border-color: var(--danger); }
.toast.ok { border-color: var(--success); }
.toast .who { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; flex: none; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }

/* ─────────────────────────── responsive ─────────────────────────── */
@media (max-width: 1180px) {
  .app { grid-template-columns: 280px minmax(0,1fr); }
  .panel { position: fixed; right: 0; top: 0; bottom: 0; z-index: 40; box-shadow: var(--shadow-lg); width: min(390px, 100vw); }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .mobile-only { display: inline-flex !important; }
  .sidebar { position: fixed; inset: 0; z-index: 30; transform: translateX(0); transition: transform .3s var(--ease); background: var(--bg); }
  .app.view-chat .sidebar { transform: translateX(-100%); }
  .chat-header { padding: 10px 12px; gap: 10px; }
  .chat-peer { flex: 1; }
  .chat-peer .avatar { width: 36px; height: 36px; font-size: 13px; }
  .chat-actions .btn { padding: 0; width: 36px; height: 36px; }
  .chat-actions .label { display: none; }
  .messages { padding: 16px 12px 8px; }
  .msg.rich { width: 100%; }
  .reply-bar { margin: 0 12px; }
  .msg { max-width: 90%; }
  .composer { padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); }
  .panel { width: 100vw; }
  .empty-card { padding: 36px 24px; }
  .empty-card h1 { font-size: 22px; }
  .modal { padding: 20px; }
}
