:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --panel: #ffffff;
  --line: #deded8;
  --ink: #20211f;
  --muted: #6b6d67;
  --accent: #0f7b63;
  --accent-strong: #0a5f4c;
  --accent-soft: #dff2ec;
  --connected: #1f6fbe;
  --connected-soft: #eaf3ff;
  --user-bubble: #0f7b63;
  --user-bubble-strong: #0a5f4c;
  --warn: #9a4f12;
  --danger: #a93535;
  --surface: #fbfbf8;
  --soft-panel: #f4f4ef;
  --pill: #eef0eb;
  --tool-bg: #f0f0ec;
  --warning-bg: #fff7e8;
  --approval-bg: #fff9ef;
  --topbar-bg: rgba(247, 247, 244, 0.94);
  --composer-bg: rgba(247, 247, 244, 0.96);
  --visual-viewport-height: 100dvh;
  --visual-viewport-offset-top: 0px;
  --keyboard-inset: 0px;
  --fullscreen-status-inset: 0px;
  --fullscreen-navigation-inset: 0px;
  --focus-ring: rgba(15, 123, 99, 0.12);
  --shadow: 0 18px 45px rgba(30, 35, 32, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  font-size: 15px;
}

.desktop-bridge-offline .composer {
  opacity: 0.55;
  pointer-events: none;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151715;
  --panel: #1f221f;
  --line: #343832;
  --ink: #eceee9;
  --muted: #9da39a;
  --accent: #1f5f9f;
  --accent-strong: #6aa7e8;
  --accent-soft: #132c46;
  --connected: #27804f;
  --connected-soft: #173424;
  --user-bubble: #1f5f9f;
  --user-bubble-strong: #6aa7e8;
  --warn: #e2a35d;
  --danger: #e07777;
  --surface: #1a1d1a;
  --soft-panel: #232720;
  --pill: #292e28;
  --tool-bg: #242822;
  --warning-bg: #2e261a;
  --approval-bg: #2d2418;
  --topbar-bg: rgba(21, 23, 21, 0.94);
  --composer-bg: rgba(21, 23, 21, 0.96);
  --focus-ring: rgba(106, 167, 232, 0.18);
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #151715;
    --panel: #1f221f;
    --line: #343832;
    --ink: #eceee9;
    --muted: #9da39a;
    --accent: #1f5f9f;
    --accent-strong: #6aa7e8;
    --accent-soft: #132c46;
    --connected: #27804f;
    --connected-soft: #173424;
    --user-bubble: #1f5f9f;
    --user-bubble-strong: #6aa7e8;
    --warn: #e2a35d;
    --danger: #e07777;
    --surface: #1a1d1a;
    --soft-panel: #232720;
    --pill: #292e28;
    --tool-bg: #242822;
    --warning-bg: #2e261a;
    --approval-bg: #2d2418;
    --topbar-bg: rgba(21, 23, 21, 0.94);
    --composer-bg: rgba(21, 23, 21, 0.96);
    --focus-ring: rgba(106, 167, 232, 0.18);
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

.back-sentinel {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  border: 0;
  padding: 0;
  background: transparent;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  height: 100dvh;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 14px;
}

.brand-row,
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-row {
  justify-content: space-between;
}

.brand-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  flex: 0 0 auto;
}

.brand {
  font-size: 18px;
  font-weight: 750;
}

.connection,
.thread-meta {
  color: var(--muted);
  font-size: 12px;
}

.theme-select {
  width: 96px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  outline: none;
  cursor: pointer;
}

.theme-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.primary-action,
.secondary-action,
.ghost-action,
.send-button,
.approval-button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 700;
}

.primary-action,
.send-button,
.approval-button.accept {
  background: var(--accent);
  color: white;
}

.primary-action:active,
.send-button:active,
.approval-button.accept:active {
  background: var(--accent-strong);
}

.chat-pane.connected-thread .send-button {
  background: var(--connected);
  color: white;
}

.chat-pane.connected-thread .send-button:active {
  background: var(--connected);
}

.secondary-action {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.ghost-action {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 22px;
  line-height: 1;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.fullscreen-toggle {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  color: var(--muted);
}

.fullscreen-toggle.active {
  border-color: var(--accent);
  color: var(--accent);
}

.fullscreen-icon-exit,
.fullscreen-toggle.active .fullscreen-icon-enter {
  display: none;
}

.fullscreen-toggle.active .fullscreen-icon-exit {
  display: block;
}

.fullscreen-toggle:disabled {
  opacity: 0.45;
  cursor: default;
}

.field-label,
.setup-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
}

.field,
.thread-title,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  outline: none;
}

.field {
  min-height: 42px;
  padding: 0 12px;
}

.field[readonly] {
  background: var(--soft-panel);
  color: var(--muted);
  cursor: text;
}

.field:disabled {
  opacity: 0.72;
  cursor: default;
}

.field:focus,
.thread-title:focus,
.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.field[readonly]:focus {
  border-color: var(--line);
  box-shadow: none;
}

.thread-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.sidebar-section-title {
  color: var(--muted);
  font-size: 16px;
  font-weight: 800;
  padding: 10px 10px 4px;
}

.project-group {
  display: grid;
  gap: 2px;
  padding: 8px 0 14px;
  border-top: 1px solid var(--line);
}

.project-group:first-child {
  border-top: 0;
  padding-top: 0;
}

.project-heading {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.folder-icon {
  width: 21px;
  height: 21px;
  color: var(--muted);
}

.project-name,
.thread-name,
.thread-time {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-name {
  font-size: 15px;
  font-weight: 760;
}

.project-badge {
  min-width: 28px;
  border-radius: 999px;
  background: var(--pill);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 22px;
  text-align: center;
}

.thread-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 0 10px 0 44px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  text-align: left;
  text-decoration: none;
  touch-action: pan-y;
  -webkit-touch-callout: default;
}

.thread-item:hover,
.thread-item.active {
  background: var(--pill);
}

.thread-name {
  font-size: 14px;
  font-weight: 760;
}

.thread-time {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.expand-project {
  width: fit-content;
  min-height: 34px;
  margin-left: 44px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.direct-thread-group {
  display: grid;
  gap: 2px;
  padding-bottom: 12px;
}

.direct-thread-group .thread-item {
  padding-left: 10px;
}

.chat-pane {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto auto;
  min-width: 0;
  height: 100dvh;
  overflow: hidden;
}

.chat-pane::after {
  box-sizing: border-box;
  content: "";
  position: absolute;
  z-index: 15;
  inset: 0;
  border: 4px solid transparent;
  pointer-events: none;
  transition: border-color 160ms ease;
}

.chat-pane.connected-thread::after {
  border-color: var(--connected);
}

.chat-pane.resuming-thread::after {
  border-color: var(--connected);
  animation: connecting-border-pulse 0.9s ease-in-out infinite;
}

@keyframes connecting-border-pulse {
  0%,
  100% {
    opacity: 0.22;
  }

  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-pane.resuming-thread::after {
    animation: none;
    opacity: 1;
  }
}

.topbar {
  grid-row: 1;
}

.setup-band {
  grid-row: 7;
}

.auth-panel {
  grid-row: 4;
}

.approval-panel {
  grid-row: 5;
}

.messages {
  grid-row: 3;
}

.composer {
  grid-row: 6;
}

.connection-banner {
  grid-row: 2;
  display: flex;
  align-items: center;
  min-height: 34px;
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 32%, var(--line));
  background: var(--warning-bg);
  color: var(--warn);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 760;
}

.connection-banner.connecting::after {
  content: "";
  width: 1.2em;
  animation: reconnect-dots 1.1s steps(3, end) infinite;
}

.connection-banner.danger {
  border-bottom-color: color-mix(in srgb, var(--danger) 38%, var(--line));
  color: var(--danger);
}

@keyframes reconnect-dots {
  0% {
    content: "";
  }

  33% {
    content: ".";
  }

  66% {
    content: "..";
  }

  100% {
    content: "...";
  }
}

.topbar {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  padding: 10px 14px;
}

.thread-title-wrap {
  display: grid;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.thread-title-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 100%;
}

.thread-title {
  width: 100%;
  max-width: none;
  min-width: 0;
  min-height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 16px;
  font-weight: 760;
}

.thread-title:not(:disabled):hover {
  box-shadow: inset 0 -1px 0 var(--line);
}

.thread-title:focus {
  box-shadow: inset 0 -2px 0 var(--accent);
}

.thread-title:disabled {
  color: var(--muted);
  cursor: default;
}

.resume-status {
  display: grid;
  place-items: center;
  width: auto;
  min-width: 0;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

.resume-status.resumed {
  background: var(--connected-soft);
  color: var(--connected);
  border-color: var(--connected);
}

.resume-status.unresumed {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.resume-status:not(:disabled):hover {
  background: var(--pill);
  border-color: var(--muted);
  color: var(--ink);
}

.resume-status:disabled {
  cursor: default;
}

.traffic-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 240px;
  max-width: 460px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.traffic-summary strong,
.traffic-summary span {
  border-radius: 999px;
  background: var(--pill);
  padding: 4px 9px;
  white-space: nowrap;
}

.traffic-summary strong {
  color: var(--muted);
}

.setup-band,
.auth-panel,
.approval-panel {
  background: var(--surface);
  padding: 10px 14px;
}

.setup-band {
  border-top: 1px solid var(--line);
}

.auth-panel,
.approval-panel {
  border-bottom: 1px solid var(--line);
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
  align-items: end;
}

.field-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
}

.compact-action {
  min-height: 42px;
  padding-inline: 12px;
}

.cwd-setting {
  display: none;
}

.auth-panel,
.approval-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.auth-panel p,
.approval-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.approval-card {
  border-left: 4px solid var(--warn);
  background: var(--approval-bg);
  border-radius: 8px;
  padding: 12px;
}

.approval-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.question-request,
.question-form {
  display: grid;
  gap: 10px;
  width: 100%;
}

.question-field {
  display: grid;
  gap: 6px;
}

.question-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.approval-button.decline {
  background: var(--warning-bg);
  color: var(--danger);
}

.messages {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 18px 14px 22px;
  overscroll-behavior: contain;
}

.empty-state {
  display: grid;
  place-items: start;
  align-content: center;
  min-height: 100%;
  max-width: 620px;
  margin: 0 auto;
  color: var(--muted);
}

.empty-state h1 {
  color: var(--ink);
  font-size: 30px;
  margin: 0 0 8px;
}

.empty-state p {
  margin: 0;
  line-height: 1.6;
}

.loading-state {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  place-items: center start;
  align-content: center;
  gap: 14px;
  min-height: 100%;
  max-width: 620px;
  margin: 0 auto;
  color: var(--muted);
}

.loading-state h1 {
  color: var(--ink);
  font-size: 24px;
  margin: 0 0 6px;
}

.loading-state p {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.loading-traffic {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.loading-traffic span {
  border-radius: 999px;
  background: var(--pill);
  padding: 3px 8px;
}

.loading-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.load-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  max-width: 880px;
  margin: 0 auto 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.load-summary strong,
.load-summary span {
  border-radius: 999px;
  background: var(--pill);
  padding: 4px 9px;
}

.load-summary strong {
  color: var(--muted);
}

.history-loader {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  max-width: 880px;
  margin: 0 auto 12px;
  color: var(--muted);
  font-size: 12px;
}

.history-loader button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--pill);
  color: var(--muted);
  padding: 6px 12px;
  font-weight: 700;
}

.mini-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

.message-stream {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 880px;
  min-width: 0;
  margin: 0 auto;
}

.last-message-time {
  max-width: 880px;
  margin: 10px auto 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.message {
  display: grid;
  gap: 6px;
  min-width: 0;
  max-width: min(760px, 100%);
}

.message.user {
  align-self: flex-end;
}

.message.assistant,
.message.system,
.message.tool {
  align-self: flex-start;
}

.bubble {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.reply-dots::after {
  content: ".";
  color: var(--muted);
  font-weight: 760;
  animation: reply-dots-steps 1.2s steps(1, end) infinite;
}

@keyframes reply-dots-steps {
  0% {
    content: ".";
  }

  33% {
    content: "..";
  }

  66%,
  100% {
    content: "...";
  }
}

@media (prefers-reduced-motion: reduce) {
  .reply-dots::after {
    animation: none;
    content: "...";
  }
}

.bubble.plain {
  white-space: pre-wrap;
}

.bubble.markdown p,
.bubble.markdown ul,
.bubble.markdown ol,
.bubble.markdown blockquote,
.bubble.markdown pre {
  margin: 0 0 12px;
}

.bubble.markdown > :last-child {
  margin-bottom: 0;
}

.bubble.markdown h1,
.bubble.markdown h2,
.bubble.markdown h3,
.bubble.markdown h4,
.bubble.markdown h5,
.bubble.markdown h6 {
  margin: 0 0 10px;
  line-height: 1.25;
  font-size: 1.05em;
}

.bubble.markdown ul,
.bubble.markdown ol {
  padding-left: 22px;
}

.bubble.markdown li + li {
  margin-top: 4px;
}

.bubble.markdown a {
  color: var(--accent-strong);
  font-weight: 650;
}

.bubble.markdown code {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--pill);
  padding: 1px 5px;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.9em;
}

.bubble.markdown pre {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--pill);
  padding: 12px;
}

.bubble.markdown pre code {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
}

.bubble.markdown table {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

.bubble.markdown blockquote {
  border-left: 3px solid var(--line);
  padding-left: 12px;
  color: var(--muted);
}

.bubble.markdown img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 8px;
}

.message-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 8px;
}

.message.user .message-images {
  justify-content: flex-end;
}

.message-images img {
  width: min(180px, 100%);
  max-height: 160px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.loaded-message-image-button {
  position: relative;
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: white;
  cursor: zoom-in;
}

.loaded-message-image {
  cursor: zoom-in;
}

.image-placeholder {
  display: grid;
  place-items: center;
  gap: 3px;
  width: 112px;
  height: 78px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
}

.message.assistant .image-placeholder,
.message.system .image-placeholder,
.message.tool .image-placeholder {
  border-color: var(--line);
  background: transparent;
}

.image-placeholder span {
  font-weight: 760;
  font-size: 12px;
}

.image-placeholder small {
  color: currentColor;
  opacity: 0.72;
  font-size: 11px;
}

.image-placeholder.loading {
  cursor: progress;
}

.image-generation-status {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: min(260px, 100%);
  min-height: 78px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  color: var(--ink);
}

.image-generation-status strong,
.image-generation-status small {
  display: block;
}

.image-generation-status strong {
  font-size: 13px;
  font-weight: 780;
}

.image-generation-status small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.image-generation-status.failed {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
}

.image-generation-mark {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--danger);
  color: white;
  font-weight: 850;
  line-height: 1;
}

.image-load-error {
  display: grid;
  gap: 5px;
  max-width: min(420px, 100%);
  padding: 10px 12px;
  border: 1px dashed var(--danger);
  border-radius: 8px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
}

.image-load-error small {
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.image-viewer {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}

.workspace-picker {
  position: fixed;
  z-index: 110;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
}

.workspace-picker-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
}

.workspace-picker-panel {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto auto minmax(160px, 1fr) auto auto;
  gap: 12px;
  width: min(680px, 96vw);
  max-height: min(760px, 90dvh);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.workspace-picker-header,
.workspace-picker-actions,
.workspace-navigation-actions,
.workspace-create {
  display: flex;
  align-items: center;
  gap: 10px;
}

.workspace-picker-header {
  justify-content: space-between;
}

.workspace-current-path {
  max-width: min(540px, 72vw);
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-picker-actions {
  justify-content: space-between;
}

.workspace-directory-list {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 160px;
  padding: 6px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.workspace-directory {
  min-height: 42px;
  padding: 8px 11px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
}

.workspace-directory:active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.workspace-create .field {
  flex: 1;
}

.workspace-error {
  color: var(--danger);
  font-size: 13px;
}

.image-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
}

.image-viewer img {
  position: relative;
  z-index: 1;
  max-width: min(96vw, 1400px);
  max-height: 92vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.image-viewer-close {
  position: absolute;
  z-index: 2;
  top: 18px;
  right: 18px;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.48);
  color: white;
  font-size: 22px;
  line-height: 1;
}

.message.user .bubble {
  background: var(--user-bubble);
  color: white;
  border-color: var(--user-bubble);
}

.message.user .bubble.markdown a,
.message.user .bubble.markdown code {
  color: white;
}

.message.tool .bubble {
  background: var(--tool-bg);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

.automation-heartbeat-message {
  width: min(680px, 100%);
}

.automation-heartbeat-message details {
  width: 100%;
  min-width: 0;
}

.automation-heartbeat-message summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-panel);
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}

.automation-heartbeat-message summary::-webkit-details-marker {
  display: none;
}

.automation-heartbeat-pulse {
  width: 9px;
  height: 9px;
  border: 2px solid var(--accent);
  border-radius: 999px;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.automation-heartbeat-heading {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 7px;
}

.automation-heartbeat-heading strong {
  flex: 0 0 auto;
  color: var(--ink);
  font-size: 13px;
}

.automation-heartbeat-heading small {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.automation-heartbeat-message time {
  font-size: 11px;
  white-space: nowrap;
}

.automation-heartbeat-chevron {
  font-size: 18px;
  line-height: 1;
  transition: transform 160ms ease;
}

.automation-heartbeat-message details[open] .automation-heartbeat-chevron {
  transform: rotate(90deg);
}

.automation-heartbeat-body {
  margin-top: 7px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.automation-heartbeat-body p,
.automation-heartbeat-body pre {
  margin: 0;
}

.automation-heartbeat-body pre {
  max-height: min(42vh, 360px);
  overflow: auto;
  color: var(--muted);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.reasoning-message {
  width: min(680px, 100%);
}

.reasoning-message details {
  width: 100%;
  min-width: 0;
}

.reasoning-message summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--pill);
  color: var(--muted);
  padding: 8px 10px;
  cursor: pointer;
  list-style: none;
}

.reasoning-message summary::-webkit-details-marker {
  display: none;
}

.reasoning-chevron {
  font-size: 18px;
  line-height: 1;
  transition: transform 160ms ease;
}

.reasoning-message details[open] .reasoning-chevron {
  transform: rotate(90deg);
}

.reasoning-summary-title {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reasoning-summary-count {
  font-size: 12px;
  white-space: nowrap;
}

.reasoning-body {
  margin-top: 8px;
  border: 1px solid var(--line);
  background: var(--soft-panel) !important;
  color: var(--ink);
}

.reasoning-explainer {
  margin: 0 0 10px !important;
  color: var(--muted);
  font-size: 11px;
}

.reasoning-parts {
  display: grid;
  gap: 10px;
  margin: 0 !important;
  padding-left: 22px !important;
}

.reasoning-parts > li {
  padding-left: 3px;
}

.reasoning-parts > li::marker {
  color: var(--muted);
  font-size: 11px;
}

.compact-tool-group {
  max-width: min(760px, 100%);
}

.compact-tool-group details {
  min-width: 0;
  max-width: 100%;
  color: var(--muted);
  font-size: 12px;
}

.compact-tool-group summary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--pill);
  color: var(--muted);
  padding: 6px 10px;
  font-weight: 760;
  cursor: pointer;
  list-style: none;
}

.compact-tool-group summary::-webkit-details-marker {
  display: none;
}

.tool-summary-icon {
  display: grid;
  place-items: center;
  width: 15px;
  height: 15px;
  border: 1px solid currentColor;
  border-radius: 3px;
  font-size: 9px;
  line-height: 1;
}

.tool-group-details {
  display: grid;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  margin-top: 8px;
}

.tool-group-details pre {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tool-bg);
  color: var(--muted);
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

.message.system .bubble {
  background: var(--warning-bg);
  border-color: var(--line);
}

.message-label {
  display: none;
}

.composer {
  position: relative;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  gap: 8px;
  border-top: 1px solid var(--line);
  background: var(--composer-bg);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}

.composer.dragging {
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

.attach-button,
.settings-toggle {
  display: grid;
  place-items: center;
  align-self: end;
  grid-row: 1;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 26px;
  line-height: 1;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    transform 80ms ease;
}

.attach-button {
  cursor: pointer;
}

@media (hover: hover) {
  .attach-button:hover,
  .settings-toggle:hover {
    border-color: var(--muted);
    background: var(--pill);
    color: var(--ink);
  }
}

.attach-button:active,
.settings-toggle:active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  transform: translateY(1px);
}

.settings-toggle {
  font-size: 20px;
}

.settings-icon {
  display: block;
  width: 21px;
  height: 21px;
}

.settings-toggle.active {
  background: var(--pill);
  color: var(--ink);
}

.image-tray {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.image-chip {
  position: relative;
  display: grid;
  grid-template-columns: 56px minmax(0, 110px) auto;
  align-items: center;
  gap: 8px;
  max-width: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 6px;
}

.image-chip img {
  width: 56px;
  height: 42px;
  object-fit: cover;
  border-radius: 6px;
}

.image-chip span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-chip button {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--warning-bg);
  color: var(--danger);
}

.composer textarea {
  grid-column: 3;
  grid-row: 1;
  height: 40px;
  min-height: 40px;
  max-height: 160px;
  resize: none;
  overflow-y: hidden;
  padding: 8px 12px;
  line-height: 1.4;
}

.send-button {
  grid-column: 4;
  grid-row: 1;
  align-self: end;
  min-width: 70px;
  min-height: 40px;
}

.composer.has-image-tray .attach-button,
.composer.has-image-tray .settings-toggle,
.composer.has-image-tray textarea,
.composer.has-image-tray .send-button {
  grid-row: 2;
}

.hidden {
  display: none !important;
}

.mobile-only {
  display: none;
}

@media (max-width: 900px) {
  :root.fullscreen-active {
    --fullscreen-status-inset: max(env(safe-area-inset-top, 0px), 24px);
    --fullscreen-navigation-inset: max(env(safe-area-inset-bottom, 0px), 22px);
  }

  :root.fullscreen-active.keyboard-open {
    --fullscreen-navigation-inset: 0px;
  }

  :root.fullscreen-active .image-viewer {
    padding-top: var(--fullscreen-status-inset);
    padding-bottom: var(--fullscreen-navigation-inset);
  }

  :root.fullscreen-active .image-viewer-close {
    top: calc(18px + var(--fullscreen-status-inset));
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .chat-pane {
    --mobile-topbar-height: 62px;
    --mobile-composer-height: 56px;
    display: block;
    height: var(--visual-viewport-height);
    padding-top: var(--mobile-topbar-height);
    padding-bottom: var(--mobile-composer-height);
  }

  .topbar {
    position: fixed;
    z-index: 14;
    top: 0;
    left: 0;
    right: 0;
    transform: translateY(var(--visual-viewport-offset-top));
    padding-top: calc(10px + var(--fullscreen-status-inset));
  }

  .messages {
    height: calc(var(--visual-viewport-height) - var(--mobile-topbar-height) - var(--mobile-composer-height));
    padding-bottom: 22px;
  }

  .connection-banner:not(.hidden) ~ .messages {
    height: calc(var(--visual-viewport-height) - var(--mobile-topbar-height) - var(--mobile-composer-height) - 34px);
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: min(86vw, 360px);
    transform: translateX(-104%);
    transition: transform 160ms ease;
    box-shadow: var(--shadow);
    padding-top: calc(14px + var(--fullscreen-status-inset));
    padding-bottom: calc(14px + var(--fullscreen-navigation-inset));
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-only {
    display: grid;
  }

  .setup-grid {
    grid-template-columns: 1fr 1fr;
  }

  .traffic-summary {
    display: none !important;
  }

  .setup-band:not(.open) {
    display: none;
  }

  .setup-band {
    position: fixed;
    z-index: 13;
    left: 0;
    right: 0;
    bottom: calc(var(--mobile-composer-height) + var(--keyboard-inset));
    max-height: min(44svh, 360px);
    overflow: auto;
    padding-top: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    border-bottom: 1px solid var(--line);
  }

  .setup-grid {
    gap: 9px 10px;
  }

  .setup-grid span {
    margin-bottom: 4px;
    font-size: 11px;
  }

  .field {
    min-height: 42px;
    padding: 0 10px;
    font-size: 14px;
  }

  .composer {
    position: fixed;
    z-index: 14;
    left: 0;
    right: 0;
    bottom: var(--keyboard-inset);
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    gap: 6px;
    padding-top: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom) + var(--fullscreen-navigation-inset));
  }

  .keyboard-open .composer {
    padding-bottom: 6px;
  }

  .attach-button,
  .settings-toggle {
    width: 40px;
    height: 40px;
  }

  .composer textarea {
    grid-column: 3;
  }

  .send-button {
    grid-column: 4;
    min-width: 60px;
    min-height: 40px;
    width: auto;
    padding: 0 12px;
  }

  .ghost-action {
    display: none;
  }
}

@media (max-width: 620px) {
  .topbar,
  .setup-band,
  .auth-panel,
  .approval-panel,
  .connection-banner,
  .messages,
  .composer {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "menu title";
    align-items: center;
    gap: 10px;
    padding-top: 8px;
    padding-bottom: 6px;
  }

  .topbar .mobile-only {
    grid-area: menu;
  }

  .thread-title-wrap {
    grid-area: title;
  }

  .thread-title-line {
    display: grid;
  }

  .thread-title {
    width: 100%;
    max-width: none;
    min-height: 24px;
    font-size: 16px;
  }

  .thread-meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    line-height: 1.1;
  }

  .resume-status {
    min-width: 0;
    min-height: 28px;
    padding: 0 8px;
    font-size: 12px;
  }

  .fullscreen-toggle {
    width: 32px;
    height: 28px;
  }

  .setup-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .auth-panel,
  .approval-card {
    align-items: stretch;
    flex-direction: column;
  }

  .approval-actions {
    justify-content: stretch;
  }

  .approval-button,
  .secondary-action {
    width: 100%;
  }

  .field-action-row .secondary-action,
  .workspace-picker-actions .secondary-action,
  .workspace-create .secondary-action {
    width: auto;
  }

  .workspace-picker {
    padding: 10px;
  }

  .workspace-picker-panel {
    width: 100%;
    max-height: 92dvh;
    padding: 12px;
  }

  .workspace-create {
    align-items: stretch;
    flex-direction: column;
  }

  .workspace-create .secondary-action {
    width: 100%;
  }

  .empty-state h1 {
    font-size: 24px;
  }

}

.image-preview-placeholder {
  position: relative;
  display: block;
  width: min(240px, 58vw);
  height: 150px;
  overflow: hidden;
  padding: 0;
  border-style: solid;
  background: var(--soft-panel);
  cursor: zoom-in;
}

.message-image-preview {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 160ms ease;
}

.image-preview-placeholder.preview-ready .message-image-preview {
  opacity: 1;
}

.image-preview-placeholder.preview-failed .message-image-preview {
  display: none;
}

.image-preview-caption {
  position: absolute;
  inset: auto 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 22px 9px 8px;
  color: white;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.74));
  text-align: left;
}

.image-preview-caption strong,
.image-preview-caption small {
  overflow: hidden;
  color: inherit;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-preview-caption strong {
  font-weight: 680;
}

.setting-summary {
  display: grid;
  align-content: center;
  gap: 2px;
  min-height: 42px;
  min-width: 0;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.setting-summary strong,
.setting-summary small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.setting-summary strong {
  color: var(--ink);
  font-size: 13px;
  font-weight: 660;
}

.setting-summary small {
  color: var(--muted);
  font-size: 10px;
}

/* REQ-20260821-003 — DeepSeek Harness-inspired application shell. The
   transport and conversation components remain project-owned; these tokens
   intentionally translate the visual hierarchy rather than vendor another
   application's runtime. */
:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --surface: #f0f2f5;
  --soft-panel: #f4f5f7;
  --line: rgba(21, 23, 28, 0.1);
  --ink: #17191d;
  --muted: #737880;
  --accent: #4176e6;
  --accent-strong: #315fca;
  --accent-soft: #e4edff;
  --connected: #2ba76f;
  --connected-soft: #e4f7ee;
  --user-bubble: #e6edfb;
  --user-bubble-strong: #d8e4fb;
  --warn: #c67b18;
  --danger: #d64b4b;
  --pill: #e9ebef;
  --tool-bg: #f1f2f4;
  --warning-bg: #fff6e7;
  --approval-bg: #fff8eb;
  --topbar-bg: rgba(255, 255, 255, 0.88);
  --composer-bg: rgba(247, 248, 250, 0.92);
  --focus-ring: rgba(65, 118, 230, 0.18);
  --shadow: 0 18px 50px rgba(20, 24, 32, 0.16);
  --shadow-soft: 0 8px 24px rgba(20, 24, 32, 0.08);
  --sidebar-width: 300px;
}

:root[data-theme="dark"] {
  --bg: #151517;
  --panel: #1f2023;
  --surface: #111214;
  --soft-panel: #242529;
  --line: rgba(255, 255, 255, 0.09);
  --ink: #f0f1f3;
  --muted: #989ca4;
  --accent: #5686f5;
  --accent-strong: #86a7ff;
  --accent-soft: rgba(86, 134, 245, 0.16);
  --connected: #45be83;
  --connected-soft: rgba(69, 190, 131, 0.13);
  --user-bubble: #28334a;
  --user-bubble-strong: #303e59;
  --warn: #e6a44f;
  --danger: #ef6c6c;
  --pill: #292a2e;
  --tool-bg: #242529;
  --warning-bg: #302719;
  --approval-bg: #2d261b;
  --topbar-bg: rgba(21, 21, 23, 0.88);
  --composer-bg: rgba(21, 21, 23, 0.92);
  --focus-ring: rgba(86, 134, 245, 0.22);
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.42);
  --shadow-soft: 0 10px 26px rgba(0, 0, 0, 0.24);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151517;
    --panel: #1f2023;
    --surface: #111214;
    --soft-panel: #242529;
    --line: rgba(255, 255, 255, 0.09);
    --ink: #f0f1f3;
    --muted: #989ca4;
    --accent: #5686f5;
    --accent-strong: #86a7ff;
    --accent-soft: rgba(86, 134, 245, 0.16);
    --connected: #45be83;
    --connected-soft: rgba(69, 190, 131, 0.13);
    --user-bubble: #28334a;
    --user-bubble-strong: #303e59;
    --warn: #e6a44f;
    --danger: #ef6c6c;
    --pill: #292a2e;
    --tool-bg: #242529;
    --warning-bg: #302719;
    --approval-bg: #2d261b;
    --topbar-bg: rgba(21, 21, 23, 0.88);
    --composer-bg: rgba(21, 21, 23, 0.92);
    --focus-ring: rgba(86, 134, 245, 0.22);
    --shadow: 0 22px 60px rgba(0, 0, 0, 0.42);
    --shadow-soft: 0 10px 26px rgba(0, 0, 0, 0.24);
  }
}

body {
  letter-spacing: -0.008em;
}

.app-shell {
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
  gap: 12px;
  padding: 16px 14px 12px;
  border-right-color: var(--line);
}

.brand-lockup,
.connection-row {
  display: flex;
  align-items: center;
}

.brand-lockup {
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: var(--ink);
  color: var(--panel);
  font-size: 15px;
  font-weight: 850;
  box-shadow: var(--shadow-soft);
}

.brand {
  font-size: 16px;
  font-weight: 760;
  letter-spacing: -0.025em;
}

.connection-row {
  gap: 5px;
  margin-top: 2px;
}

.connection-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--connected);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--connected) 13%, transparent);
}

.connection {
  font-size: 11px;
}

.theme-select {
  width: 82px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: var(--pill);
  font-weight: 650;
}

.new-thread-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  border-radius: 11px;
  background: var(--ink);
  color: var(--panel);
  font-weight: 700;
}

.new-thread-action span:first-child {
  font-size: 19px;
  font-weight: 400;
  line-height: 1;
}

.sidebar-search {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--pill);
  color: var(--muted);
}

.sidebar-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.sidebar-search svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.sidebar-search input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
}

.thread-list {
  margin: 0 -4px;
  padding: 0 4px 8px;
}

.sidebar-section-title {
  padding: 10px 8px 5px;
  font-size: 11px;
  font-weight: 720;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.project-group {
  gap: 1px;
  padding: 2px 0 10px;
  border-top: 0;
}

.project-heading {
  grid-template-columns: 12px 18px minmax(0, 1fr) auto;
  gap: 6px;
  min-height: 34px;
  padding: 0 8px;
}

.project-chevron {
  display: block;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  transform: rotate(90deg);
  transition: transform 140ms ease;
}

.project-group.collapsed .project-chevron {
  transform: rotate(0deg);
}

.folder-icon {
  width: 16px;
  height: 16px;
}

.project-name {
  font-size: 12px;
  font-weight: 680;
}

.project-badge {
  min-width: 22px;
  line-height: 19px;
}

.active-thread-group,
.direct-thread-group {
  display: grid;
  gap: 2px;
  padding-bottom: 9px;
}

.thread-item,
.direct-thread-group .thread-item {
  grid-template-columns: 14px minmax(0, 1fr) auto;
  gap: 8px;
  min-height: 47px;
  padding: 6px 8px;
  border-radius: 10px;
}

.thread-item:hover {
  background: color-mix(in srgb, var(--pill) 72%, transparent);
}

.thread-item.active {
  background: var(--pill);
}

.thread-item.unread .thread-name {
  font-weight: 780;
}

.thread-copy {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.thread-name {
  display: block;
  font-size: 13px;
  font-weight: 620;
}

.thread-status {
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-time {
  align-self: start;
  padding-top: 2px;
  font-size: 10px;
  font-weight: 560;
}

.thread-activity-dot {
  position: relative;
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  color: transparent;
}

.thread-activity-dot::before,
.thread-activity-dot::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: currentColor;
}

.thread-activity-dot::before {
  inset: 0;
  opacity: 0.13;
}

.thread-activity-dot::after {
  inset: 2px;
}

.thread-activity-dot[data-state="idle"] {
  color: var(--muted);
  opacity: 0.32;
}

.thread-activity-dot[data-state="running"] {
  color: var(--accent);
  animation: activity-pulse 1.5s ease-in-out infinite;
}

.thread-activity-dot[data-state="waiting"] {
  color: var(--warn);
}

.thread-activity-dot[data-state="completed"] {
  color: var(--connected);
}

.thread-activity-dot[data-state="failed"] {
  color: var(--danger);
}

@keyframes activity-pulse {
  50% { transform: scale(1.18); filter: brightness(1.2); }
}

.usage-card {
  flex: 0 0 auto;
  display: grid;
  gap: 9px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 68%, transparent);
}

.usage-card-header,
.usage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.usage-card-header strong {
  font-size: 12px;
}

.usage-card-header span {
  margin-left: 6px;
  color: var(--muted);
  font-size: 9px;
}

.usage-refresh {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
}

.usage-card.loading .usage-refresh {
  animation: usage-spin 900ms linear infinite;
}

@keyframes usage-spin { to { transform: rotate(360deg); } }

.usage-windows {
  display: grid;
  gap: 9px;
}

.usage-window {
  display: grid;
  gap: 5px;
}

.usage-row {
  color: var(--muted);
  font-size: 10px;
}

.usage-row strong {
  color: var(--ink);
  font-size: 10px;
  font-weight: 650;
}

.usage-track {
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--pill);
}

.usage-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.usage-window.warning .usage-track span { background: var(--warn); }
.usage-window.critical .usage-track span { background: var(--danger); }

.usage-reset,
.usage-empty {
  color: var(--muted);
  font-size: 9px;
}

.chat-pane::after {
  display: none;
}

.topbar {
  min-height: 58px;
  padding: 9px 18px;
  backdrop-filter: blur(18px);
}

.thread-title {
  font-size: 15px;
  font-weight: 690;
}

.resume-status,
.icon-button,
.field,
.secondary-action,
.ghost-action,
.approval-button {
  border-radius: 10px;
}

.messages {
  padding: 24px max(18px, calc((100% - 900px) / 2)) 34px;
}

.message-stream {
  gap: 20px;
}

.message {
  max-width: 820px;
}

.message.user .bubble {
  border-color: transparent;
  background: var(--user-bubble);
  color: var(--ink);
  border-radius: 16px 16px 4px 16px;
}

.message.user .bubble.markdown a,
.message.user .bubble.markdown code {
  color: var(--accent-strong);
}

.bubble {
  line-height: 1.68;
}

.bubble.markdown pre,
.tool-group-details pre,
.reasoning-message summary,
.automation-heartbeat-message summary {
  border-radius: 12px;
}

.approval-panel {
  padding: 10px max(18px, calc((100% - 900px) / 2));
}

.approval-card {
  border: 1px solid color-mix(in srgb, var(--warn) 24%, var(--line));
  border-left: 3px solid var(--warn);
  border-radius: 12px;
}

.composer {
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  gap: 9px;
  border-top: 0;
  background: var(--composer-bg);
  padding: 12px max(18px, calc((100% - 920px) / 2)) calc(14px + env(safe-area-inset-bottom));
  backdrop-filter: blur(18px);
}

.composer textarea {
  grid-column: 3;
  min-width: 0;
  min-height: 46px;
  height: 46px;
  padding: 11px 14px;
  border-radius: 15px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.attach-button,
.settings-toggle,
.send-button {
  width: 46px;
  height: 46px;
  min-height: 46px;
  border-radius: 14px;
}

.settings-toggle { grid-column: 1; }
.attach-button { grid-column: 2; }
.send-button { grid-column: 4; }

.setup-band:not(.open) {
  display: none;
}

.empty-state {
  width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
}

.send-button {
  min-width: 70px;
  background: var(--ink);
  color: var(--panel);
}

.follow-up-menu {
  position: absolute;
  z-index: 30;
  right: max(10px, calc((100% - 920px) / 2));
  bottom: calc(100% - 3px);
  display: grid;
  width: min(330px, calc(100vw - 20px));
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.follow-up-option {
  display: grid;
  width: 100%;
  min-height: 56px;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.follow-up-option:active,
.follow-up-option:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: 0;
}

.follow-up-option.danger {
  border-top-color: var(--line);
  color: var(--danger);
}

.follow-up-option.danger:active,
.follow-up-option.danger:focus-visible {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

.follow-up-option:disabled {
  cursor: default;
  opacity: 0.42;
}

.follow-up-option strong { font-size: 14px; }
.follow-up-option span { color: var(--muted); font-size: 12px; }

.chat-pane.connected-thread .send-button,
.chat-pane.connected-thread .send-button:active {
  background: var(--ink);
  color: var(--panel);
}

.setup-band {
  padding: 12px max(18px, calc((100% - 920px) / 2));
  background: var(--bg);
}

.toast-region {
  position: fixed;
  z-index: 1200;
  top: 18px;
  left: 50%;
  width: min(460px, calc(100vw - 28px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast-card {
  pointer-events: auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  color: var(--ink);
  box-shadow: var(--shadow);
  text-align: left;
  backdrop-filter: blur(18px);
  animation: toast-enter 180ms ease-out;
}

.toast-card.leaving {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--connected-soft);
  color: var(--connected);
  font-weight: 800;
}

.toast-card.failed .toast-icon {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
}

.toast-copy {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.toast-copy strong { font-size: 12px; }
.toast-copy span { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.toast-action { color: var(--accent-strong); font-size: 11px; font-weight: 700; }

@keyframes toast-enter {
  from { opacity: 0; transform: translateY(-8px); }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    width: min(88vw, 340px);
    padding: calc(14px + var(--fullscreen-status-inset)) 13px calc(12px + var(--fullscreen-navigation-inset));
  }

  .chat-pane { --mobile-topbar-height: 60px; --mobile-composer-height: 66px; }

  .topbar {
    min-height: var(--mobile-topbar-height);
    border-bottom-color: var(--line);
  }

  .messages {
    padding: 18px 14px 28px;
  }

  .composer {
    grid-template-columns: 40px 40px minmax(0, 1fr) 58px;
    gap: 7px;
    padding: 9px 10px calc(9px + env(safe-area-inset-bottom) + var(--fullscreen-navigation-inset));
  }

  .composer textarea,
  .attach-button,
  .settings-toggle,
  .send-button {
    height: 44px;
    min-height: 44px;
  }

  .composer textarea { grid-column: 3; min-width: 0; }
  .send-button { grid-column: 4; min-width: 58px; padding-inline: 8px; }

  .follow-up-menu {
    right: 10px;
    bottom: calc(100% + 6px);
  }

  .setup-band {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    background: var(--panel);
    box-shadow: 0 -18px 50px rgba(0, 0, 0, 0.2);
  }

  .toast-region {
    top: calc(10px + env(safe-area-inset-top));
  }

}

@media (max-width: 620px) {
  .topbar {
    padding: 8px 10px 6px;
  }

  .thread-title-line {
    grid-template-columns: minmax(0, 1fr) minmax(54px, auto);
  }

  .fullscreen-toggle {
    display: none;
  }

  .resume-status {
    max-width: 92px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .thread-title { font-size: 15px; }
  .thread-meta { font-size: 10px; }
  .resume-status { font-size: 10px; }

  .message-stream { gap: 16px; }
  .bubble { font-size: 14px; }
  .usage-card { padding: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .thread-activity-dot[data-state="running"],
  .usage-card.loading .usage-refresh,
  .toast-card {
    animation: none;
  }
}
