:root {
  --bg: #0d0f12; --panel: #14171c; --panel2: #1b1f26; --border: #262b33;
  --text: #e6e8eb; --muted: #8b93a0; --accent: #4dd9a6; --accent-d: #2fae80;
  --user: #1f3a30; --danger: #ff6b6b;
  --safe-top: env(safe-area-inset-top); --safe-bot: env(safe-area-inset-bottom);
}
#clientError { color: var(--danger); font-size: 12px; overflow-wrap: anywhere; margin-top: 6px; max-height: 100px; overflow-y: auto; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

.logo { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #3a8dde); color: #08110d; font-weight: 800; font-size: 22px; }
.logo.sm { width: 26px; height: 26px; font-size: 14px; border-radius: 7px; }
.logo.lg { width: 64px; height: 64px; font-size: 32px; border-radius: 18px; }

.app { display: flex; height: 100dvh; overflow: hidden; }
.sidebar { width: 280px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding-top: var(--safe-top); }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 6px; }
.brand { display: flex; gap: 8px; align-items: center; font-weight: 700; }
.icon-btn { background: none; border: none; font-size: 20px; padding: 6px 10px; border-radius: 8px; color: var(--muted); }
.icon-btn:active, .icon-btn:hover { background: var(--panel2); color: var(--text); }
.new-chat { margin: 6px 12px 10px; padding: 10px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel2); text-align: left; }
.new-chat:hover { border-color: var(--accent); }
.chat-list { flex: 1; overflow-y: auto; padding: 0 8px; }
.chat-item { display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 8px; cursor: pointer; }
.chat-item:hover { background: var(--panel2); }
.chat-item.active { background: #222833; }
.chat-item .t { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.chat-item .del { opacity: 0; background: none; border: none; color: var(--muted); padding: 2px 6px; }
.chat-item:hover .del, .chat-item.active .del { opacity: 1; }
.chat-item .del:hover { color: var(--danger); }
.group-label { color: var(--muted); font-size: 12px; padding: 12px 10px 4px; }
.side-foot { padding: 10px 12px calc(10px + var(--safe-bot)); border-top: 1px solid var(--border); }
.link-btn { background: none; border: none; color: var(--muted); padding: 4px 0; font-size: 13px; }
.link-btn:hover { color: var(--text); }
.conn { font-size: 12px; color: var(--muted); margin-top: 4px; }
.conn.ok { color: var(--accent); }
.conn.bad { color: var(--danger); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.top { display: flex; align-items: center; gap: 6px; padding: calc(8px + var(--safe-top)) 10px 8px;
  border-bottom: 1px solid var(--border); background: rgba(13,15,18,.9); backdrop-filter: blur(8px); }
.top .menu { display: none; }
.top-title { flex: 1; min-width: 0; }
#title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.messages { flex: 1; overflow-y: auto; padding: 16px max(12px, calc((100% - 820px)/2)); -webkit-overflow-scrolling: touch; }
.empty { height: 100%; display: grid; place-content: center; text-align: center; color: var(--muted); gap: 8px; justify-items: center; }
.msg { margin: 10px 0; max-width: 100%; overflow-wrap: anywhere; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--user); padding: 9px 13px; border-radius: 16px 16px 4px 16px; max-width: 85%; white-space: pre-wrap; }
.msg.assistant .bubble { padding: 2px 2px; }
.bubble p { margin: .4em 0; }
.bubble pre { background: #0a0c0f; border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow-x: auto; font-size: 13px; }
.bubble code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .9em; }
.bubble :not(pre) > code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; }
.bubble a { color: var(--accent); }
.bubble table { border-collapse: collapse; display: block; overflow-x: auto; }
.bubble td, .bubble th { border: 1px solid var(--border); padding: 4px 8px; }
.reasoning { color: var(--muted); font-size: 13px; font-style: italic; margin: 6px 0; }
.reasoning summary { cursor: pointer; }
.reasoning div { white-space: pre-wrap; padding-left: 10px; border-left: 2px solid var(--border); }
.tool { border: 1px solid var(--border); background: var(--panel); border-radius: 10px; margin: 8px 0; font-size: 13px; }
.tool summary { padding: 8px 10px; cursor: pointer; display: flex; gap: 8px; align-items: center; list-style: none; }
.tool summary::-webkit-details-marker { display: none; }
.tool .st { width: 16px; text-align: center; }
.tool .st.run { color: var(--accent); animation: pulse 1s infinite; }
.tool .st.ok { color: var(--accent); }
.tool .st.err { color: var(--danger); }
.tool .nm { font-family: ui-monospace, monospace; font-weight: 600; }
.tool .pv { color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; flex: 1; font-family: ui-monospace, monospace; }
.tool pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--border); max-height: 320px; overflow: auto; white-space: pre-wrap; font-size: 12px; }
.status-line { color: var(--muted); font-size: 13px; margin: 8px 0; display: flex; gap: 8px; align-items: center; }
.spinner { width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.err-line { color: var(--danger); font-size: 13px; margin: 8px 0; }
.meta { color: var(--muted); font-size: 11px; margin-top: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .3; } }

.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px max(10px, calc((100% - 820px)/2)) calc(10px + var(--safe-bot));
  border-top: 1px solid var(--border); background: var(--bg); }
.composer textarea { flex: 1; resize: none; max-height: 40vh; background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 20px; padding: 10px 14px; font: inherit; font-size: 16px; outline: none; }
.composer textarea:focus { border-color: var(--accent-d); }
.send, .stop { width: 42px; height: 42px; border-radius: 50%; border: none; font-size: 20px; flex-shrink: 0; }
.send { background: var(--accent); color: #08110d; font-weight: 800; }
.send:disabled { opacity: .35; }
.stop { background: var(--panel2); color: var(--text); border: 1px solid var(--border); font-size: 14px; }

.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; }
.login-card { width: min(340px, 90vw); text-align: center; display: grid; gap: 12px; justify-items: center; }
.login-card input, .login-card button { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel2); color: var(--text); font-size: 16px; }
.login-card button { background: var(--accent); color: #08110d; font-weight: 700; border: none; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 14px; width: min(520px, 92vw); max-height: 80vh; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog button { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel2); }
.import-list { max-height: 55vh; overflow-y: auto; margin-bottom: 12px; }
.import-item { padding: 10px; border-radius: 8px; cursor: pointer; border-bottom: 1px solid var(--border); }
.import-item:hover { background: var(--panel2); }
.import-item small { color: var(--muted); display: block; }

.backdrop { display: none; }
@media (max-width: 760px) {
  .sidebar { position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: 82vw; max-width: 320px; transform: translateX(-100%); transition: transform .22s ease; }
  .app.open .sidebar { transform: none; }
  .app.open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 10; }
  .top .menu { display: block; }
  .chat-item .del { opacity: 1; }
}

.search { margin: 0 12px 8px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 16px; outline: none; }
.search:focus { border-color: var(--accent-d); }
.chat-item .term { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 0 4px; }
.chat-item .sub2 { display: block; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .tw { flex: 1; min-width: 0; }
.chat-item .tw .t { display: block; }
.head-actions { display: flex; align-items: center; gap: 2px; }
.text-btn { background: none; border: none; color: var(--accent); font-size: 14px; padding: 6px 8px; border-radius: 8px; }
.text-btn:hover { background: var(--panel2); }
.danger-btn { background: var(--danger); color: #1a0606; border: none; border-radius: 9px; padding: 8px 14px; font-weight: 700; }
.danger-btn:disabled { opacity: .35; }
.bulk-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--panel2); }
.bulk-bar span { flex: 1; font-size: 13px; color: var(--muted); }
.chat-item .cb { width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--muted); flex-shrink: 0; display: grid; place-items: center; font-size: 13px; color: #08110d; }
.chat-item.sel { background: #1d2b26; }
.chat-item.sel .cb { background: var(--accent); border-color: var(--accent); }
.selecting .chat-item .del { display: none; }
.badge { flex-shrink: 0; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.badge.working { color: #f5c451; background: rgba(245,196,81,.12); }
.badge.working::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #f5c451; animation: pulse 1s infinite; }
.badge.complete { color: var(--accent); background: rgba(77,217,166,.12); }
.badge.complete.seen { background: none; opacity: .75; }
.badge.error { color: var(--danger); background: rgba(255,107,107,.12); }
.badge.stopped { color: var(--muted); background: var(--panel2); }
.dlg-actions { display: flex; justify-content: space-between; gap: 8px; }
.status-pill { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font: 12px ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted);
  padding: 6px max(14px, calc((100% - 820px)/2 + 4px)) 0; }
.status-pill > span { display: inline-flex; align-items: center; gap: 6px; }
.sp-ctx .bar { width: 54px; height: 6px; border-radius: 3px; background: var(--panel2); overflow: hidden; border: 1px solid var(--border); }
.sp-ctx .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.sp-ctx.warn .bar i { background: #f5c451; } .sp-ctx.crit .bar i { background: var(--danger); }
.sp-live { color: #f5c451; gap: 10px !important; }
.sp-live span + span::before { content: "·"; margin-right: 10px; color: var(--muted); }
.sp-model { margin-left: auto; opacity: .8; }
.composer { position: relative; }
.slash-menu { position: absolute; left: max(10px, calc((100% - 820px)/2)); right: max(10px, calc((100% - 820px)/2)); bottom: calc(100% + 6px);
  max-height: min(46vh, 380px); overflow-y: auto; background: #0b0d10; border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,.6); z-index: 30; padding: 4px 0; -webkit-overflow-scrolling: touch; }
.slash-menu .sm-h { font-size: 11px; letter-spacing: .08em; color: var(--muted); padding: 8px 14px 4px; text-transform: uppercase; }
.slash-menu .sm-i { display: flex; align-items: baseline; gap: 10px; padding: 9px 14px; cursor: pointer; border-top: 1px solid #15181d; }
.slash-menu .sm-i.on, .slash-menu .sm-i:hover { background: var(--panel2); }
.slash-menu .sm-n { font: 15px ui-monospace, "SF Mono", Menlo, monospace; color: var(--text); white-space: nowrap; }
.slash-menu .sm-n b { color: var(--accent); font-weight: 600; }
.slash-menu .sm-d { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.slash-menu .sm-tag { margin-left: auto; font-size: 10px; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; flex-shrink: 0; }
.notice { color: var(--accent); font-size: 13px; margin: 8px 0; }
.hint { color: var(--muted); font-size: 13px; margin-top: -6px; }

/* rich markdown: code blocks, file chips, tap-to-copy */
.bubble .cblock { background: #121418; border: 1px solid var(--border); border-radius: 12px; margin: .7em 0; overflow: hidden; }
.cblock .cb-head { display: flex; align-items: center; gap: 2px; padding: 3px 6px 3px 12px; border-bottom: 1px solid var(--border); min-height: 36px; }
.cblock .cb-lang { flex: 1; font: 12px ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted); }
.cblock .cb-btn { background: none; border: none; color: var(--muted); padding: 7px 9px; border-radius: 8px; display: inline-grid; place-items: center; }
.cblock .cb-btn:active, .cblock .cb-btn:hover { background: var(--panel2); color: var(--text); }
.cblock .cb-btn.ok { color: var(--accent); }
.bubble .cblock pre { background: none; border: none; border-radius: 0; margin: 0; padding: 12px 14px; font-size: 13.5px; line-height: 1.55;
  overflow-x: auto; white-space: pre; -webkit-overflow-scrolling: touch; }
.bubble .cblock.wrap pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble :not(pre) > code.copyable { cursor: pointer; transition: background .15s, color .15s; -webkit-user-select: text; user-select: text; }
.bubble :not(pre) > code.copyable:active { background: #2a313b; }
.bubble .inline-code { display: inline-flex; align-items: center; vertical-align: middle; max-width: 100%; min-width: 0;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.bubble .inline-code > code { background: none; padding: 3px 7px; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble .inline-code.command-code { display: flex; margin: .5em 0; }
.bubble .command-code > code { flex: 1; padding: 10px 12px; }
.ic-copy { display: inline-grid; place-items: center; flex: 0 0 44px; min-width: 44px; min-height: 44px; align-self: stretch;
  border: 0; border-left: 1px solid var(--border); background: none; color: var(--muted); padding: 8px; cursor: pointer; }
.ic-copy:hover, .ic-copy:active { background: #2a313b; color: var(--text); }
.ic-copy.ok { color: var(--accent); }
.ic-copy:focus-visible, .cb-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
.fchip { display: inline-flex; align-items: baseline; gap: 5px; vertical-align: baseline; cursor: pointer; padding: 0 2px; border-radius: 5px;
  color: #5cc8e6; transition: background .15s; white-space: nowrap; max-width: 100%; }
.fchip .fi { font: 700 .72em ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: -.02em; }
.fchip .fn { overflow: hidden; text-overflow: ellipsis; }
.fchip:active, .fchip:hover { background: var(--panel2); }
.copyable.flash { background: rgba(77,217,166,.25) !important; color: var(--accent) !important; }
#toast { position: fixed; left: 50%; bottom: calc(110px + var(--safe-bot)); transform: translate(-50%, 10px); background: #1f242c; color: var(--text);
  border: 1px solid var(--border); padding: 8px 14px; border-radius: 20px; font-size: 13px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 100; max-width: 86vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.fab-new { width: 38px; height: 38px; border-radius: 50%; border: none; flex-shrink: 0; display: grid; place-items: center;
  background: var(--accent); color: #08110d; box-shadow: 0 2px 10px rgba(77,217,166,.35); transition: transform .12s, opacity .2s; }
.fab-new:active { transform: scale(.9); }
.fab-new.busy { opacity: .55; pointer-events: none; }
.fab-new.busy svg { animation: spin 1s linear infinite; }

/* ---------- chat list, T3 style ---------- */
.chat-list { padding: 0 6px 12px; }
.chat-item { align-items: flex-start; gap: 12px; padding: 12px 10px; border-radius: 10px; border-bottom: 1px solid #191c21; }
.chat-item.active { background: #1e232b; border-color: transparent; }
.chat-item .ci { color: var(--muted); flex-shrink: 0; margin-top: 2px; display: grid; }
.chat-item .tw { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.chat-item .tw .t { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: normal; overflow: hidden;
  font-size: 15.5px; line-height: 1.3; color: var(--text); }
.chat-item.is-working .tw .t { color: #aab2bd; }
.chat-item .sub2 { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); }
.chat-item .sub2 svg { flex-shrink: 0; }
.chat-item .sub2 span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .rc { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; padding-top: 1px; }
.chat-item .rc2 { display: flex; align-items: center; gap: 4px; min-height: 18px; }
.chat-item .ago { font-size: 13px; color: var(--muted); white-space: nowrap; }
.chat-item .badge { font-size: 12px; }
.chat-item .badge.working { color: #5fb8ff; background: none; padding: 0; }
.chat-item .badge.working::before { width: 11px; height: 11px; background: none; border: 1.6px dashed #5fb8ff; animation: spin 2.4s linear infinite; box-sizing: border-box; }
.chat-item .badge.complete { background: none; padding: 0; }
.chat-item .badge.error, .chat-item .badge.stopped { background: none; padding: 0; }
.chat-item .del { padding: 0 4px; font-size: 13px; }
.sec-head { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: none; color: var(--muted);
  font-size: 14px; padding: 18px 10px 8px; text-align: left; }
.sec-head i { flex: 1; height: 1px; background: var(--border); }
.sec-head svg { transition: transform .2s; }
.sec-head.closed svg { transform: rotate(180deg); }

/* ---------- attachments ---------- */
.attach { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  flex-shrink: 0; display: grid; place-items: center; }
.attach:active { transform: scale(.92); }
.mic { height: 42px; min-width: 42px; border-radius: 21px; border: none; background: transparent; color: var(--text); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; gap: 4px; padding: 0 8px; font: inherit; font-size: 14px; font-variant-numeric: tabular-nums; }
.mic:active { transform: scale(.92); }
.mic[data-state="rec"] { background: var(--danger); color: #1a0606; }
.mic[data-state="rec"] .mic-ic { animation: pulse 1s infinite; }
.mic[data-state="busy"] { color: var(--accent); }
.mic[data-state="busy"] .mic-ic { animation: pulse .7s infinite; }
.mic[data-state="retry"] { color: var(--danger); }
.mic-cancel { width: 34px; height: 42px; border: none; background: transparent; color: var(--muted); font-size: 16px; flex-shrink: 0; }
.voice-key { display: flex; align-items: stretch; gap: 8px; margin-top: 8px; }
.voice-key input { flex: 1 1 0; width: 0; min-width: 0; min-height: 40px; background: var(--panel2); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; font: inherit; font-size: 16px; }
.voice-key .fd-btn, .sheet .voice-key .fd-btn { flex: 0 0 auto; width: auto; margin: 0; padding: 8px 14px; min-height: 40px; white-space: nowrap; }
.attach-bar { display: flex; gap: 8px; overflow-x: auto; padding: 8px max(10px, calc((100% - 820px)/2)) 0; -webkit-overflow-scrolling: touch; }
.att { position: relative; display: flex; align-items: center; gap: 8px; background: var(--panel2); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px 30px 6px 6px; max-width: 220px; flex-shrink: 0; overflow: hidden; }
.att img { width: 40px; height: 40px; object-fit: cover; border-radius: 8px; }
.att .att-ic { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 8px; background: #0f1215;
  font: 700 12px ui-monospace, "SF Mono", Menlo, monospace; }
.att .att-t { display: flex; flex-direction: column; min-width: 0; }
.att .att-n { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att .att-s { font-size: 11px; color: var(--muted); }
.att.err { border-color: var(--danger); }
.att.err .att-s { color: var(--danger); }
.att .att-x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: none;
  background: #0f1215; color: var(--muted); font-size: 11px; display: grid; place-items: center; }
.att .att-bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); transition: width .2s; }
.msg.user { flex-direction: column; align-items: flex-end; gap: 6px; }
.u-imgs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 85%; }
.u-img { max-width: 180px; max-height: 180px; border-radius: 12px; border: 1px solid var(--border); cursor: pointer; object-fit: cover; }
.u-files { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-top: 6px; white-space: normal; }
.u-files .fchip { background: rgba(0,0,0,.25); padding: 3px 8px; }

/* ---------- file sheet ---------- */
.fchip { text-decoration: underline; text-decoration-color: rgba(92,200,230,.35); text-underline-offset: 3px; }
.file-dlg, .sheet { margin: auto auto 0; width: min(560px, 100vw); max-width: 100vw; border-radius: 18px 18px 0 0; border-bottom: none;
  padding: 16px 16px calc(16px + var(--safe-bot)); }
.file-dlg[open], .sheet[open] { animation: sheetUp .22s ease-out; }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } }
.fd-preview { margin: -4px -4px 12px; border-radius: 12px; overflow: hidden; background: #0a0c0f; display: grid; place-items: center; max-height: 46vh; }
.fd-preview img { max-width: 100%; max-height: 46vh; object-fit: contain; }
.fd-head { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.fd-icon { width: 46px; height: 46px; border-radius: 12px; background: var(--panel2); display: grid; place-items: center; flex-shrink: 0;
  font: 700 14px ui-monospace, "SF Mono", Menlo, monospace; }
.fd-meta { min-width: 0; }
.fd-name { font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
.fd-info { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; margin-top: 2px; }
.fd-actions { display: flex; flex-direction: column; gap: 8px; }
.fd-btn { display: block; text-align: center; padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel2);
  color: var(--text); text-decoration: none; font-size: 15px; }
.fd-btn.primary { background: var(--accent); color: #08110d; border-color: var(--accent); font-weight: 600; }
.fd-btn.ghost { background: none; color: var(--muted); }
.fd-btn.disabled { opacity: .4; pointer-events: none; }

/* ---------- message queue ---------- */
.queue-pill { align-self: center; display: inline-flex; align-items: center; gap: 7px; margin: 6px auto 0; padding: 7px 14px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--panel2); color: var(--text); font-size: 13.5px; }
.queue-pill svg { color: var(--muted); }
.queue-pill:active { transform: scale(.96); }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: #3a404a; margin: -6px auto 12px; }
.sheet h3 { text-align: center; margin: 0 0 4px; }
.q-list { display: flex; flex-direction: column; margin-top: 8px; }
.q-item { display: flex; flex-direction: column; gap: 10px; padding: 12px 2px; border-bottom: 1px solid var(--border); }
.q-t { font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 7.5em; overflow: hidden; }
.q-f { margin-left: 8px; color: var(--muted); font-size: 12px; }
.q-actions { display: flex; gap: 8px; justify-content: flex-end; }
.q-actions .q-send { background: #3b6ef5; border: none; color: #fff; border-radius: 999px; padding: 8px 16px; font-weight: 600; }
.q-actions .q-del { background: none; border: 1px solid var(--border); color: var(--muted); border-radius: 999px; padding: 8px 12px; }

/* ---------- subscription limits ---------- */
.sp-limits { display: inline-flex; gap: 8px; align-items: center; background: var(--panel2); border: 1px solid var(--border); border-radius: 999px;
  padding: 2px 9px; color: var(--muted); font: inherit; cursor: pointer; }
.sp-limits .warn { color: #f5c451; } .sp-limits .crit { color: var(--danger); }
.u-list { display: flex; flex-direction: column; gap: 14px; margin: 10px 0 14px; }
.u-prov { display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.u-name { font-weight: 600; font-size: 14.5px; overflow-wrap: anywhere; }
.u-plan { font-weight: 500; font-size: 12px; color: var(--muted); background: var(--panel2); border-radius: 6px; padding: 1px 6px; margin-left: 4px; }
.u-row { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.u-bar { height: 8px; border-radius: 4px; background: var(--panel2); border: 1px solid var(--border); overflow: hidden; margin: 6px 0 4px; }
.u-bar i { display: block; height: 100%; background: var(--accent); }
.u-lim.warn .u-bar i { background: #f5c451; } .u-lim.crit .u-bar i { background: var(--danger); }
.u-lim.warn b { color: #f5c451; } .u-lim.crit b { color: var(--danger); }
.u-sub { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.u-err { color: var(--danger); font-size: 13px; }
.sec-head.pinned { cursor: default; } .sec-head.pinned svg { display: none; }

/* ---------- servers, settings, metrics ---------- */
.foot-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.icon-btn.gear { padding: 6px; display: grid; place-items: center; }
.metrics-btn { display: grid; place-items: center; padding: 6px 8px; }
.srv-chip { display: flex; align-items: center; gap: 8px; margin: 0 12px 4px; padding: 7px 10px; border-radius: 10px; border: 1px solid var(--border);
  background: transparent; color: var(--text); font-size: 13.5px; text-align: left; }
.srv-chip span { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.srv-chip svg { color: var(--muted); }
.srv-chip.hidden { display: none; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; vertical-align: middle; }
.dot.online, .srv-chip[data-state="online"] .dot { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.dot.offline, .srv-chip[data-state="offline"] .dot { background: var(--danger); }
.dot.auth { background: #f5c451; }
.dot.checking, .srv-chip[data-state="checking"] .dot { background: var(--muted); animation: pulse 1s infinite; }
.sheet.tall { max-height: 88vh; overflow-y: auto; }
.set-sec { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 2px 6px; }
.srv-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 12px; }
.srv-row { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel2); cursor: pointer; }
.srv-row.active { border-color: var(--accent-d); }
.srv-main { flex: 1; min-width: 0; }
.srv-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srv-tag { font-weight: 500; font-size: 11px; color: var(--accent); border: 1px solid var(--accent-d); border-radius: 6px; padding: 0 5px; margin-left: 4px; }
.srv-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.srv-url { font-size: 11.5px; color: #5d6470; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
dialog .srv-act { background: none; border: none; color: var(--muted); padding: 8px; border-radius: 8px; font-size: 18px; line-height: 1; display: grid; place-items: center; }
dialog .srv-act:active { background: var(--panel); color: var(--text); }
.srv-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.srv-form.hidden { display: none; }
.srv-form input { padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel2); color: var(--text); font-size: 16px; }
.srv-form-act { display: flex; gap: 8px; }
.srv-form-act .fd-btn { flex: 1; }
.fd-btn.danger { color: var(--danger); }
#srvAddBtn.hidden { display: none; }
.sheet .fd-btn { display: block; width: 100%; margin-top: 6px; }
.mx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.mx-card { padding: 10px 12px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--border); min-width: 0; }
.mx-h { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-size: 13px; color: var(--muted); }
.mx-h b { color: var(--text); font-size: 18px; white-space: nowrap; }
.mx-card.warn .mx-h b { color: #f5c451; } .mx-card.crit .mx-h b { color: var(--danger); }
.mx-card.warn .u-bar i { background: #f5c451; } .mx-card.crit .u-bar i { background: var(--danger); }
.spark { width: 100%; height: 28px; display: block; margin: 4px 0 2px; }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.spark .area { fill: rgba(77, 217, 166, .12); stroke: none; }
.mx-top { display: flex; flex-direction: column; font-size: 13px; }
.mx-p { display: grid; grid-template-columns: 1fr 56px 64px; gap: 8px; padding: 6px 2px; border-bottom: 1px solid var(--border); }
.mx-p span:not(.mx-pn) { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.mx-pn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#mxSub .dot { margin-right: 4px; }
@media (max-width: 360px) { .mx-grid { grid-template-columns: 1fr; } }

/* ---------- "to the end" button ---------- */
.jump-wrap { position: relative; height: 0; z-index: 5; }
.jump-btn { position: absolute; left: 50%; bottom: 10px; transform: translate(-50%, 12px) scale(.92); opacity: 0; pointer-events: none;
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: rgba(27, 31, 38, .94); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); color: var(--text); font-size: 13.5px;
  box-shadow: 0 6px 20px rgba(0,0,0,.45); transition: opacity .18s, transform .18s; white-space: nowrap; }
.jump-btn.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0) scale(1); }
.jump-btn:active { transform: translate(-50%, 0) scale(.95); }
.jump-btn svg { color: var(--accent); }
.jump-dot { display: none; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.jump-btn.new .jump-dot { display: inline-block; }

/* Projects: the sidebar choice affects new chats, the banner shows the actual current cwd. */
.project-chip { margin: -3px 12px 10px; padding: 8px 10px; min-height: 44px; display: flex; align-items: center; gap: 7px;
  text-align: left; border: 1px solid var(--border); border-radius: 10px; background: transparent; font-size: 12px; color: var(--muted); }
.project-chip b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); font-size: 13px; }
.project-chip.unavailable b { color: var(--danger); }
.chat-project { flex-shrink: 0; padding: 5px max(12px, calc((100% - 820px)/2)); border-bottom: 1px solid var(--border);
  color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.project-row { display: flex; align-items: center; gap: 2px; background: var(--panel2); border: 1px solid var(--border); border-radius: 12px; }
dialog .project-pick { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: 64px; text-align: left; border: 0; background: transparent; }
.project-pick > span:last-child { min-width: 0; }
.project-pick b, .project-pick small { display: block; overflow-wrap: anywhere; }
.project-pick small { color: var(--muted); font-size: 11.5px; line-height: 1.4; margin-top: 3px; }
.project-pick[aria-pressed="true"] { color: var(--accent); }
.project-tick { width: 16px; flex-shrink: 0; }
dialog .project-act { padding: 8px; min-width: 36px; min-height: 44px; border: 0; background: transparent; color: var(--muted); font-size: 18px; }
dialog .project-act.danger { color: var(--danger); }
#projectForm label { font-size: 12px; color: var(--muted); margin-top: 5px; }
#projectMsg:not(:empty) { padding: 8px; border: 1px solid var(--border); border-radius: 8px; overflow-wrap: anywhere; }
.project-safety { font-size: 11.5px; }
#projectsDlg button:disabled { opacity: .55; cursor: wait; }
.chat-views { display: flex; margin: 0 12px 8px; padding: 3px; gap: 3px; border: 1px solid var(--border); border-radius: 10px; }
.chat-views button { flex: 1; min-height: 34px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 12px; }
.chat-views button[aria-pressed="true"] { background: var(--panel2); color: var(--text); }
.project-group-head { display: flex; align-items: center; gap: 3px; margin-top: 8px; padding: 0 4px; }
.project-group-toggle { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; min-height: 40px; padding: 5px 2px; text-align: left; background: none; border: 0; font-size: 12px; color: var(--muted); }
.project-group-toggle b { color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-group-toggle small { margin-left: auto; flex-shrink: 0; font-size: 10px; }
.project-chevron { flex-shrink: 0; }
.project-group-add { flex-shrink: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--panel2); color: var(--accent); width: 36px; height: 36px; font-size: 20px; line-height: 1; }
.project-group-add:disabled { opacity: .4; }
.project-empty { padding: 2px 16px 10px; font-size: 11px; color: var(--muted); }

/* Folder selection: independent expansion and selection, not drill-down navigation. */
#folderDlg { width: min(680px, calc(100% - 24px)); height: min(760px, 92vh); height: min(760px, 92dvh); max-height: 92vh; max-height: 92dvh; box-sizing: border-box; margin: auto; border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
#folderDlg[open] { display: flex; flex-direction: column; }
#folderDlg > :not(.folder-tree) { flex-shrink: 0; }
#folderDlg .hint { margin: 6px 0; }
.folder-toolbar, .folder-go { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
#folderDlg .folder-toolbar .fd-btn, #folderDlg .folder-go .fd-btn { width: auto; margin: 0; flex-shrink: 0; }
.folder-toolbar label { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); margin-left: auto; }
.folder-go input { min-width: 0; width: 100%; box-sizing: border-box; border: 1px solid var(--border); border-radius: 10px; background: var(--panel2); color: var(--text); padding: 10px; font-size: 16px; }
.folder-tree { flex: 1 1 auto; min-height: 80px; overflow: auto; border: 1px solid var(--border); border-radius: 12px; padding: 6px; }
.folder-children { margin-left: 18px; padding-left: 6px; border-left: 1px solid var(--border); }
.folder-row { display: flex; align-items: center; gap: 4px; min-height: 44px; border-radius: 8px; }
.folder-node[aria-selected="true"] > .folder-row { background: var(--panel2); outline: 1px solid var(--accent-d); }
dialog .folder-toggle { flex: 0 0 36px; width: 36px; height: 36px; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--panel2); color: var(--accent); font-size: 22px; }
dialog .folder-toggle:disabled { border-color: transparent; background: none; color: var(--muted); }
dialog .folder-pick { flex: 1; min-width: 120px; padding: 10px 8px; text-align: left; white-space: nowrap; border: 0; background: transparent; color: var(--text); font-size: 15px; }
.folder-node[aria-selected="true"] > .folder-row .folder-pick { color: var(--accent); font-weight: 600; }
.folder-note { margin: 4px 8px 8px; }
.folder-selected { overflow-wrap: anywhere; margin: 4px 0 10px; padding: 10px; border: 1px solid var(--accent-d); border-radius: 8px; font-size: 13px; color: var(--accent); }
#folderDlg button:disabled { opacity: .5; }

/* push notifications (settings) */
.push-box { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: var(--panel2); }
.push-row { display: flex; align-items: center; gap: 10px; }
.push-state { flex: 1; font-size: 14px; }
.push-state.on { color: var(--accent); }
.push-state.bad { color: var(--danger); }
.push-btn { padding: 8px 14px; min-height: 40px; }
.push-box .hint { margin: 8px 0 0; }
.push-box #pushTest { margin-top: 6px; padding: 8px; }

/* Quick new chat sheet: default project button + recent project chips. */
.sheet .fd-btn.quick-go { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 56px; margin-top: 12px; }
.quick-go b { font-weight: 700; overflow-wrap: anywhere; }
.quick-go small { font-weight: 400; font-size: 12px; opacity: .75; overflow-wrap: anywhere; }
.quick-go:disabled { opacity: .5; }
.quick-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.quick-chip { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; max-width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--panel2); color: var(--text); text-align: left; font-size: 14px; }
.quick-chip b { font-weight: 600; overflow-wrap: anywhere; }
.quick-chip small { color: var(--muted); font-size: 11.5px; }
.quick-chip.none { border-style: dashed; }
.quick-chip:active { transform: scale(.96); }
/* finished but not looked at yet: bold title until the chat is opened */
.chat-item.unseen .tw .t { font-weight: 700; color: #fff; }

/* ---------- context handoff ---------- */
.handoff-btn { display: grid; place-items: center; padding: 6px 8px; }
.handoff-btn.busy { opacity: .5; pointer-events: none; }
.handoff-btn.busy svg { animation: spin 1s linear infinite; }
.msg.user.handoff-card { display: block; margin-left: auto; max-width: min(88%, 640px); background: var(--panel2); border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; }
.handoff-card summary { cursor: pointer; list-style: none; display: flex; flex-direction: column; gap: 3px; }
.handoff-card summary::-webkit-details-marker { display: none; }
.handoff-card small { color: var(--muted); font-size: 12px; }
.handoff-card pre { white-space: pre-wrap; word-break: break-word; max-height: 50vh; overflow: auto; font-size: 12px; margin: 10px 0 0; }
