:root {
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color: #202124;
  background: #f7f7f8;
  font-size: 15px;
  letter-spacing: 0;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.shell {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(230px, 26vw) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  background: #ffffff;
}

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #dadce0;
  background: #f5f6f7;
  padding: 7px;
}

.window-row { height: 31px; display: flex; align-items: center; gap: 8px; padding: 0 4px 4px; }
.brand-mark, .empty-mark {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 2px solid #202124;
  border-radius: 7px;
  font-weight: 800;
}
.brand-name { font-size: 15px; font-weight: 650; }
.push { margin-left: auto; }

.icon-button {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 34px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  color: #41464c;
  background: transparent;
  font-size: 20px;
}
.icon-button:active, .icon-button:hover { background: #e5e7e9; }

.new-thread {
  height: 32px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border: 1px solid #cfd3d7;
  border-radius: 7px;
  background: #ffffff;
  color: #202124;
  font-weight: 600;
  text-align: left;
}
.new-thread:active { background: #eceff1; }

.search-box {
  height: 30px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border-radius: 7px;
  color: #697077;
  background: #e9ebed;
}
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: #202124; }
.search-box input::placeholder { color: #747b82; }

.sidebar-label { padding: 9px 7px 4px; color: #777e85; font-size: 11px; font-weight: 650; }
.thread-list {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}
.thread-list-content { --content-scale: 1; width: 100%; }
.thread-item {
  width: 100%;
  min-height: calc(33px * var(--content-scale));
  display: block;
  padding: calc(4px * var(--content-scale)) 7px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  touch-action: pan-x pan-y;
  scrollbar-width: none;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #25282c;
  text-align: left;
}
.thread-item::-webkit-scrollbar { display: none; }
.thread-scroll { width: max-content; min-width: 100%; display: flex; align-items: center; gap: calc(8px * var(--content-scale)); }
.thread-item.active { background: #dfe5e9; }
.thread-item:active { background: #d9dde1; }
.thread-name { display: block; flex: 0 0 auto; white-space: nowrap; font-size: calc(12px * var(--content-scale)); font-weight: 560; }
.thread-meta { display: flex; flex: 0 0 auto; margin-left: auto; color: #7b8289; font-size: calc(10px * var(--content-scale)); }
.thread-meta span:first-child { display: none; }
.thread-state { margin-right: calc(7px * var(--content-scale)); font-weight: 750; }
.thread-item.state-running .thread-state { color: #176b9b; }
.thread-item.state-completed .thread-state { color: #177245; }
.thread-item.state-interrupted .thread-state { color: #9a6416; }
.thread-item.state-failed .thread-state { color: #a23e3e; }

.account-row {
  min-height: 41px;
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 5px -2px -2px;
  padding: 5px 8px;
  border-top: 1px solid #dde0e3;
}
.account-row strong, .account-row small { display: block; }
.account-row strong { font-size: 12px; }
.account-row small { color: #747b82; font-size: 11px; margin-top: 2px; }
.connection-dot { width: 9px; height: 9px; border-radius: 50%; background: #aeb4ba; }
.connection-dot.online { background: #1f9d62; }
.connection-dot.offline { background: #cc4949; }
.update-button { width: 100%; min-height: 34px; margin-top: 7px; border: 1px solid #202124; border-radius: 7px; background: #202124; color: #fff; font-size: 12px; font-weight: 650; }
.update-button:disabled { border-color: #9ba1a7; background: #9ba1a7; }

.workspace { --composer-space: 128px; min-width: 0; min-height: 0; height: 100%; position: relative; display: flex; flex-direction: column; overflow: hidden; }
.topbar { min-width: 0; height: 54px; flex: 0 0 54px; display: flex; align-items: center; gap: 12px; padding: 0 15px 0 18px; border-bottom: 1px solid #e0e2e4; background: #fff; }
.title-wrap { min-width: 0; }
.title-wrap h1 { margin: 0; max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 650; }
.title-wrap span { display: block; max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #838990; font-size: 10px; margin-top: 2px; }
.top-actions { margin-left: auto; display: flex; }
.model-control { width: min(210px, 25vw); height: 34px; margin-right: 5px; }
.model-control select { width: 100%; height: 34px; padding: 0 26px 0 9px; border: 1px solid #d2d6da; border-radius: 7px; outline: 0; color: #30353a; background: #fff; font-size: 11px; }
.refresh-button { height: 34px; min-width: 66px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 0 10px; border: 1px solid #d2d6da; border-radius: 7px; background: #fff; color: #30353a; font-size: 11px; font-weight: 650; }
.refresh-button:active { background: #eceff1; }
.refresh-button:disabled { color: #858b91; background: #f3f4f5; }
.refresh-button.refreshing span:first-child { animation: refresh-spin .7s linear infinite; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }

.task-status-bar {
  min-height: 32px;
  flex: 0 0 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  border-bottom: 1px solid #dfe2e4;
  background: #f5f6f7;
  color: #5f666d;
  font-size: 12px;
  font-weight: 700;
}
.task-status-bar.running { border-color: #c9e1ef; background: #edf7fc; color: #176b9b; }
.task-status-bar.completed { border-color: #c8e5d5; background: #ebf7f0; color: #177245; }
.task-status-bar.interrupted { border-color: #ead7b8; background: #fff8e9; color: #8b5a13; }
.task-status-bar.failed { border-color: #efcaca; background: #fff1f1; color: #a23e3e; }
.task-status-symbol { width: 15px; flex: 0 0 15px; text-align: center; font-size: 15px; line-height: 1; }

.chat {
  height: 0;
  flex: 1 1 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  padding: 0;
  background: #fff;
}
.chat-content { --content-scale: 1; width: 100%; min-height: 100%; padding: calc(18px * var(--content-scale)) max(22px, 5vw) calc(24px * var(--content-scale)); }
.empty-state { height: 100%; display: grid; align-content: center; justify-items: center; color: #555c63; text-align: center; }
.empty-state h2 { margin: 15px 0 5px; color: #25282c; font-size: 20px; }
.empty-state p { margin: 0; font-size: 13px; }
.empty-mark { width: 38px; height: 38px; font-size: 18px; }

.message { width: min(760px, 92%); margin: 0 auto calc(17px * var(--content-scale)); font-size: calc(15px * var(--content-scale)); line-height: 1.55; word-break: break-word; }
.message.user { display: flex; justify-content: flex-end; }
.message.user .bubble { max-width: 82%; padding: calc(9px * var(--content-scale)) 12px; border-radius: 8px; background: #eceeef; color: #25282c; white-space: pre-wrap; }
.message.assistant .message-label { margin-bottom: calc(6px * var(--content-scale)); color: #777e85; font-size: calc(11px * var(--content-scale)); font-weight: 700; }
.message.assistant .bubble { color: #25282c; }
.image-message { display: flex; }
.image-message.assistant { justify-content: flex-start; }
.image-message.user { justify-content: flex-end; }
.image-frame { width: min(760px, 92%); min-height: 90px; display: grid; place-items: center; overflow: hidden; border: 1px solid #d8dcdf; border-radius: 7px; background: #f5f6f7; color: #747b82; font-size: calc(12px * var(--content-scale)); }
.image-frame.loading { background: #f5f6f7; }
.image-frame.error { padding: 14px; color: #a23e3e; }
.conversation-image { display: block; width: 100%; max-height: 58vh; object-fit: contain; background: #111; cursor: zoom-in; }
.image-lightbox { position: fixed; z-index: 80; inset: 0; display: grid; place-items: center; padding: 28px 150px 28px 28px; border: 0; background: rgba(0, 0, 0, .88); }
.image-lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.message.live .bubble::after { content: ""; display: inline-block; width: 6px; height: 15px; margin-left: 3px; vertical-align: -2px; background: #4f77a6; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.bubble p { margin: 0 0 9px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre { overflow: auto; margin: calc(8px * var(--content-scale)) 0; padding: calc(10px * var(--content-scale)); border: 1px solid #d9dde1; border-radius: 6px; background: #f4f5f6; font-family: Consolas, monospace; font-size: calc(12px * var(--content-scale)); line-height: 1.45; }
.bubble code { padding: 1px 4px; border-radius: 4px; background: #f0f1f2; font-family: Consolas, monospace; font-size: calc(12px * var(--content-scale)); }
.bubble pre code { padding: 0; background: transparent; }
.bubble strong { font-weight: 700; }

.activity-card { width: min(760px, 92%); margin: calc(-7px * var(--content-scale)) auto calc(15px * var(--content-scale)); border-left: 2px solid #b8bec4; padding: calc(5px * var(--content-scale)) 10px; color: #626a72; font-size: calc(12px * var(--content-scale)); }
.activity-card strong { display: block; margin-bottom: 3px; color: #3c4248; }
.activity-card pre { max-height: 150px; overflow: auto; margin: calc(5px * var(--content-scale)) 0 0; white-space: pre-wrap; font-family: Consolas, monospace; font-size: calc(11px * var(--content-scale)); line-height: 1.4; }

.composer-region { flex: 0 0 auto; position: relative; z-index: 10; padding: 10px 24px 12px; border-top: 1px solid #e0e2e4; background: #f7f8f9; }
.composer { position: relative; display: block; margin: 0; border: 1px solid #cfd3d7; border-radius: 8px; background: #fff; }
.composer:focus-within { border-color: #7b858e; }
.composer textarea { display: block; width: 100%; min-height: 52px; max-height: 130px; resize: none; padding: 11px 13px 5px; border: 0; outline: 0; color: #202124; background: transparent; line-height: 1.45; }
.composer-actions { height: 42px; display: flex; align-items: center; gap: 7px; padding: 3px 8px 6px; }
.composer-hint { color: #8a9096; font-size: 11px; }
.send-button, .stop-button { width: 34px; height: 34px; margin-left: auto; border: 0; border-radius: 7px; background: #202124; color: white; font-size: 21px; font-weight: 700; }
.stop-button { background: #b34444; font-size: 14px; }
.send-button:disabled { background: #aeb3b8; }
.attachment-bar { display: none; gap: 6px; overflow-x: auto; padding: 8px 10px 0; }
.attachment-bar.visible { display: flex; }
.attachment-chip { flex: 0 0 auto; max-width: 180px; display: flex; align-items: center; gap: 6px; padding: 5px 7px; border: 1px solid #d6dade; border-radius: 6px; background: #f6f7f8; font-size: 11px; }
.attachment-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip button { border: 0; background: transparent; color: #747b82; padding: 0; }

.scroll-latest {
  width: 34px;
  height: 34px;
  position: absolute;
  z-index: 11;
  right: 36px;
  bottom: calc(var(--composer-space) + 10px);
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #cfd3d7;
  border-radius: 50%;
  background: #fff;
  color: #34393e;
  box-shadow: 0 2px 8px rgba(32, 33, 36, .16);
  font-size: 20px;
  line-height: 1;
}
.scroll-latest:active { background: #eceff1; }

.activity-drawer { width: min(330px, 38vw); position: fixed; z-index: 20; top: 0; right: 0; bottom: 0; border-left: 1px solid #d8dbde; background: #f7f8f9; box-shadow: -5px 0 18px rgba(0,0,0,.08); }
.drawer-head { height: 54px; display: flex; align-items: center; padding: 0 10px 0 16px; border-bottom: 1px solid #dfe2e4; }
.drawer-head .icon-button { margin-left: auto; }
.activity-list { height: calc(100% - 54px); overflow: auto; padding: 10px; }
.drawer-event { margin-bottom: 8px; padding: 8px; border: 1px solid #dfe2e4; border-radius: 6px; background: white; font-size: 11px; color: #59616a; }
.drawer-event strong { display: block; color: #30353a; margin-bottom: 3px; }

.approval-panel { position: absolute; z-index: 12; right: 14px; bottom: 104px; width: min(460px, 70%); padding: 13px; border: 1px solid #d2b66f; border-radius: 8px; background: #fffaf0; box-shadow: 0 5px 18px rgba(0,0,0,.12); }
.approval-panel h3 { margin: 0 0 7px; font-size: 14px; }
.approval-panel p, .approval-panel pre { margin: 4px 0 9px; font-size: 12px; }
.approval-panel pre { max-height: 120px; overflow: auto; white-space: pre-wrap; }
.approval-actions { display: flex; justify-content: flex-end; gap: 7px; }
.approval-actions button { height: 32px; padding: 0 12px; border: 1px solid #c8ccd0; border-radius: 6px; background: white; }
.approval-actions button.primary { border-color: #202124; background: #202124; color: white; }

.toast { position: fixed; z-index: 50; left: 50%; bottom: 18px; transform: translateX(-50%); max-width: 72vw; padding: 9px 13px; border-radius: 6px; background: #292d31; color: white; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.hidden { display: none !important; }

@media (max-height: 600px) {
  .chat { padding-top: 12px; padding-bottom: 14px; }
  .message { margin-bottom: 12px; }
}
