:root {
  --bg: var(--tg-theme-bg-color, #f5f7fb);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #161a22);
  --muted: var(--tg-theme-hint-color, #768092);
  --accent: var(--tg-theme-button-color, #2878ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--muted) 18%, transparent);
  --green: #24a46d;
  --orange: #e58b21;
  --red: #df5353;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { overscroll-behavior: none; }
button, textarea, input { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }
#shell { min-height: 100vh; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; min-height: 74px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(18px); border-bottom: 1px solid var(--line); }
.brand-mark { width: 46px; height: 46px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 15px; background: linear-gradient(145deg, #07162f, #123a82); box-shadow: 0 7px 20px #2878ff38; overflow: hidden; }
.brand-mark img { width: 43px; height: 43px; object-fit: contain; transform: scale(1.08); }
.heading { flex: 1; min-width: 0; }
.eyebrow { color: var(--muted); font-size: 10px; line-height: 1.2; font-weight: 750; letter-spacing: .11em; }
h1, h2 { margin: 2px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
h1 { font-size: 21px; letter-spacing: -.025em; }
h2 { font-size: 22px; }
.icon-button { appearance: none; width: 38px; height: 38px; flex: 0 0 auto; border: 0; border-radius: 12px; background: var(--surface); color: var(--text); font-size: 21px; box-shadow: inset 0 0 0 1px var(--line); }
#content { padding: 16px; }
.center-state { min-height: 58vh; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--muted); text-align: center; }
.center-state p { max-width: 280px; margin: 0; line-height: 1.45; }
.loader { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .75s linear infinite; }
.reply-loader { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: var(--muted); font-size: 13px; }
.reply-loader .loader { width: 20px; height: 20px; border-width: 2px; }
.model-select { max-width: 100%; margin: 2px 0 8px; padding: 5px 9px; font: inherit; font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; }
@keyframes spin { to { transform: rotate(360deg); } }
.section-label { display: flex; align-items: center; justify-content: space-between; margin: 4px 4px 10px; color: var(--muted); font-size: 12px; font-weight: 650; }
.grid { display: grid; gap: 11px; }
.project-card, .thread-card { width: 100%; appearance: none; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 15px; box-shadow: 0 8px 28px color-mix(in srgb, #0a1933 7%, transparent); }
.project-card { display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 13px; }
.folder { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 15px; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); font-size: 21px; }
.card-title { font-weight: 720; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { margin-top: 4px; color: var(--muted); font-size: 12px; }
.chevron { color: var(--muted); font-size: 22px; }
.thread-card { display: block; padding: 16px; }
.thread-top { display: flex; align-items: flex-start; gap: 9px; }
.thread-top .card-title { flex: 1; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.status-dot { width: 8px; height: 8px; margin-top: 6px; flex: 0 0 auto; border-radius: 50%; background: var(--muted); }
.status-dot.active { background: var(--orange); box-shadow: 0 0 0 4px #e58b2120; }
.status-dot.completed, .status-dot.idle { background: var(--green); }
.preview { margin-top: 9px; color: var(--muted); font-size: 13px; line-height: 1.42; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.floating { position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 12; appearance: none; border: 0; border-radius: 16px; background: var(--accent); color: var(--accent-text); padding: 13px 17px; font-weight: 720; box-shadow: 0 12px 26px color-mix(in srgb, var(--accent) 38%, transparent); }
.floating span { font-size: 19px; vertical-align: -1px; }
.thread-summary { border: 1px solid var(--line); background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 7%, var(--surface)), var(--surface)); border-radius: var(--radius); padding: 15px; margin-bottom: 16px; }
.summary-row { display: flex; align-items: center; gap: 9px; }
.summary-status { font-weight: 700; }
.summary-note { margin-top: 8px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.timeline { display: grid; gap: 11px; }
.message { max-width: 93%; padding: 12px 14px; border-radius: 17px; background: var(--surface); border: 1px solid var(--line); overflow-wrap: anywhere; line-height: 1.48; font-size: 14px; }
.message.user { justify-self: end; color: var(--accent-text); background: var(--accent); border-color: transparent; border-bottom-right-radius: 6px; }
.message.assistant { justify-self: start; border-bottom-left-radius: 6px; }
.message .role { margin-bottom: 6px; opacity: .64; font-size: 10px; font-weight: 750; letter-spacing: .08em; }
.message p { margin: 0 0 9px; }
.message p:last-child { margin-bottom: 0; }
.message pre { max-width: 100%; overflow: auto; padding: 10px; border-radius: 10px; background: #0d1420; color: #dce7fa; font-size: 12px; }
.message a { color: inherit; font-weight: 680; text-decoration: underline; text-underline-offset: 2px; }
.asset-image { display: block; width: 100%; max-height: 380px; object-fit: contain; margin-top: 9px; border-radius: 12px; background: #00000010; }
.asset-image { cursor: zoom-in; }
.image-viewer { position: fixed; inset: 0; z-index: 45; background: #080b10; color: white; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.viewer-toolbar { display: flex; gap: 10px; padding: 12px; align-items: center; }
.viewer-toolbar .primary { width: auto; padding: 10px 13px; font-size: 13px; }
.viewer-canvas { flex: 1; min-height: 0; overflow: auto; display: grid; align-items: center; }
.viewer-canvas img { width: 100%; height: auto; max-height: 100%; object-fit: contain; }
.viewer-canvas.zoomed { display: block; }
.viewer-canvas.zoomed img { width: 200%; max-width: none; max-height: none; }
.composer { position: fixed; z-index: 15; left: 0; right: 0; bottom: 0; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(18px); border-top: 1px solid var(--line); }
.compose-row { display: flex; align-items: flex-end; gap: 8px; }
.compose-row textarea, .sheet textarea { resize: none; border: 1px solid var(--line); outline: none; color: var(--text); background: var(--surface); }
.compose-row textarea { flex: 1; min-height: 44px; max-height: 130px; border-radius: 16px; padding: 11px 13px; }
.compose-row textarea:focus, .sheet textarea:focus { border-color: color-mix(in srgb, var(--accent) 65%, var(--line)); }
.attach-button, .send-button { width: 44px; height: 44px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 15px; border: 0; font-size: 24px; }
.attach-button { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.attach-button input, .file-line input { display: none; }
.send-button { background: var(--accent); color: var(--accent-text); font-weight: 800; }
.attachments { display: flex; gap: 7px; overflow-x: auto; padding: 1px 1px 8px; }
.attachment { flex: 0 0 auto; max-width: 180px; padding: 7px 10px; border-radius: 11px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal { position: fixed; z-index: 30; inset: 0; display: flex; align-items: flex-end; }
.scrim { position: absolute; inset: 0; background: #06101e94; backdrop-filter: blur(3px); }
.sheet { position: relative; width: 100%; max-height: 88vh; overflow: auto; border-radius: 24px 24px 0 0; padding: 8px 18px calc(20px + env(safe-area-inset-bottom)); background: var(--bg); animation: rise .2s ease-out; }
@keyframes rise { from { transform: translateY(30px); opacity: .7; } }
.sheet-handle { width: 40px; height: 4px; margin: 0 auto 15px; border-radius: 9px; background: var(--line); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet textarea { width: 100%; border-radius: 16px; padding: 13px; min-height: 150px; }
.file-line { display: block; margin: 11px 0; padding: 12px; text-align: center; border: 1px dashed color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: 14px; color: var(--accent); font-weight: 680; }
.primary { width: 100%; appearance: none; border: 0; border-radius: 15px; background: var(--accent); color: var(--accent-text); padding: 14px; font-weight: 740; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100% - 36px); padding: 10px 14px; border-radius: 13px; color: white; background: #151b25e8; box-shadow: 0 10px 28px #0004; font-size: 13px; text-align: center; }
.error-title { color: var(--text); font-weight: 740; font-size: 18px; }
@media (min-width: 720px) {
  #shell { max-width: 760px; margin: 0 auto; border-inline: 1px solid var(--line); }
  .grid.projects { grid-template-columns: 1fr 1fr; }
  .composer { left: 50%; right: auto; width: 760px; transform: translateX(-50%); }
  .sheet { max-width: 620px; margin: 0 auto; border-radius: 24px 24px 0 0; }
}
