:root {
  --bg: #e8eee8;
  --bg-soft: rgba(247, 249, 246, 0.9);
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: rgba(247, 250, 248, 0.96);
  --border: rgba(20, 40, 30, 0.11);
  --text: #112116;
  --muted: #607166;
  --accent: #155b3a;
  --accent-strong: #0e482d;
  --accent-soft: rgba(21, 91, 58, 0.1);
  --user: #dcefe2;
  --assistant: #eef3fb;
  --system: rgba(255, 255, 255, 0.78);
  --shadow: 0 20px 50px rgba(18, 36, 27, 0.08);
  --radius-lg: 24px;
  --radius-md: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

body {
  min-height: 100dvh;
  font-family: "IBM Plex Sans", "PingFang SC", "Noto Sans SC", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(140, 198, 162, 0.28), transparent 24%),
    radial-gradient(circle at top right, rgba(171, 195, 227, 0.16), transparent 20%),
    linear-gradient(180deg, #f4f7f3 0%, #e7ede6 100%);
}

body.sidebar-collapsed .app-layout {
  grid-template-columns: minmax(0, 1fr);
}

body.sidebar-collapsed .control-panel {
  display: none;
}

body.activity-collapsed .activity-panel {
  display: none;
}

body:not(.activity-collapsed):not(.compact-mode) .app-shell {
  width: min(1560px, calc(100% - 420px));
  margin-left: 14px;
  margin-right: 406px;
}

button,
textarea,
input {
  font: inherit;
}

button,
input,
textarea {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(1560px, calc(100% - 28px));
  height: 100dvh;
  margin: 0 auto;
  padding: 14px 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  transition: width 160ms ease, margin 160ms ease;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(480px, 100%);
  padding: 28px;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-soft);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.topbar,
.activity-panel,
.control-panel,
.chat-panel {
  overflow: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  min-height: 64px;
}

.topbar-brand {
  display: grid;
  gap: 2px;
}

.topbar-brand strong {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.topbar-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
}

.topbar-pills {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}

.topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: "IBM Plex Serif", "Noto Serif SC", serif;
}

h2 {
  font-size: 22px;
  line-height: 1.15;
}

.compact {
  font-size: 15px;
}

.overview-label,
.field-label,
.panel-note-title {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.panel-note p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.app-layout {
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  gap: 14px;
  margin-top: 12px;
  min-height: 0;
  overflow: hidden;
}

.control-panel,
.chat-panel,
.activity-panel {
  background: var(--panel);
}

.control-panel {
  padding: 16px;
  align-self: start;
  max-height: 100%;
  min-height: 0;
  overflow: auto;
}

.control-panel > .thread-group {
  margin-top: 0;
}

.panel-head,
.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.field-block {
  margin-top: 16px;
}

.control-group {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.62);
  padding: 12px;
}

.control-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
  color: var(--text);
  font-weight: 700;
}

.control-group summary::-webkit-details-marker {
  display: none;
}

.control-group summary::after {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(16, 34, 23, 0.06);
  color: var(--muted);
  font-size: 14px;
}

.control-group[open] summary::after {
  content: "-";
}

.control-group summary small {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.directory-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 8px;
  margin-top: 10px;
}

.reasoning-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.reasoning-switch button {
  border-radius: 14px;
  padding: 10px 8px;
  background: rgba(16, 34, 23, 0.05);
  font-size: 13px;
}

.reasoning-switch button.active {
  background: var(--accent);
  color: #fff;
}

.panel-note {
  margin-top: 18px;
  padding: 14px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(18, 107, 68, 0.1), rgba(125, 168, 255, 0.08));
}

.workspace-section {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.workspace-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.thread-toolbar,
.thread-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.thread-search {
  margin-top: 12px;
  min-height: 40px;
}

.thread-head {
  min-width: 0;
}

.workspace-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.workspace-empty {
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  position: relative;
}

.compact-strip {
  display: none;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  padding: 12px 16px 0;
}

.chat-head {
  padding: 18px 20px 0;
}

.chat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.mini-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(16, 34, 23, 0.05);
  color: var(--muted);
  font-size: 12px;
  max-width: 100%;
}

.mini-pill strong {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill-key {
  color: var(--muted);
}

.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 20px 20px;
}

.message {
  max-width: min(100%, 980px);
  padding: 16px 18px;
  border-radius: 22px;
  animation: rise 180ms ease-out;
}

.message.user {
  align-self: flex-end;
  background: var(--user);
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant);
}

.message.system {
  align-self: center;
  width: 100%;
  background: var(--system);
  border: 1px dashed var(--border);
}

.message-role {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.message-body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.75;
}

.composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  background: var(--panel-strong);
  padding: 16px 20px 20px;
}

.upload-panel {
  margin-top: 0;
}

.upload-dropzone {
  display: grid;
  gap: 6px;
  padding: 14px 15px;
  border: 1.5px dashed rgba(18, 107, 68, 0.3);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.76);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.upload-panel-inline {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.upload-dropzone-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 12px;
}

.upload-dropzone strong {
  font-size: 13px;
}

.upload-dropzone span,
.upload-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.upload-dropzone.dragover,
.upload-dropzone:focus {
  border-color: var(--accent);
  background: rgba(18, 107, 68, 0.08);
  outline: none;
}

.upload-dropzone.busy {
  opacity: 0.72;
  cursor: progress;
}

.upload-meta {
  margin-top: 0;
  min-width: 0;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}

.activity-panel {
  position: fixed;
  top: 92px;
  right: 14px;
  bottom: 18px;
  z-index: 20;
  width: 378px;
  padding: 16px 18px;
  overflow: auto;
}

.side-console {
  margin-top: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.side-console .control-group {
  margin-top: 12px;
}

.drawer-head {
  align-items: center;
}

.approvals-section {
  margin-top: 14px;
  padding-top: 14px;
}

.activity-log {
  display: grid;
  gap: 8px;
  min-height: 96px;
  max-height: none;
  overflow-y: auto;
  margin: 12px 0 0;
  padding: 0;
}

.activity-entry {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.74);
  overflow: hidden;
}

.activity-entry summary {
  padding: 9px 12px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.activity-entry pre {
  margin: 0;
  padding: 0 12px 12px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  font-size: 12px;
}

.activity-command summary {
  color: #4f5f6f;
}

.activity-approval summary {
  color: var(--accent);
}

.activity-file summary {
  color: #6d4d12;
}

.activity-stderr summary {
  color: #9f271d;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--text);
  padding: 7px 11px;
  font-size: 12px;
  cursor: pointer;
}

.chip.active {
  background: var(--accent-soft);
  border-color: rgba(18, 107, 68, 0.28);
}

.request-card,
.thread-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.84);
}

.thread-card.active {
  border-color: rgba(18, 107, 68, 0.28);
  background: rgba(229, 241, 233, 0.96);
}

.request-title,
.thread-head strong {
  display: block;
  font-size: 14px;
  line-height: 1.5;
}

.thread-head strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.request-meta,
.thread-meta,
.request-copy {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.request-copy.subtle {
  font-size: 12px;
}

.thread-actions {
  margin-top: 10px;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.request-block {
  margin: 10px 0 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(16, 34, 23, 0.04);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}

.request-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.request-textarea {
  min-height: 120px;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.error-text {
  color: #b42318;
  margin-bottom: 0;
}

.login-form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #7f8c9b;
  box-shadow: 0 0 0 6px rgba(127, 140, 155, 0.16);
}

.status-dot.busy {
  background: #c68410;
  box-shadow: 0 0 0 6px rgba(198, 132, 16, 0.16);
}

.status-dot.ok {
  background: #0f9f58;
  box-shadow: 0 0 0 6px rgba(15, 159, 88, 0.16);
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}

textarea {
  min-height: 120px;
  resize: none;
}

textarea:focus,
input:focus {
  border-color: rgba(18, 107, 68, 0.36);
  box-shadow: 0 0 0 4px rgba(18, 107, 68, 0.1);
}

button {
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  background: rgba(16, 34, 23, 0.08);
  color: var(--text);
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, color 140ms ease;
  font-size: 13px;
  font-weight: 600;
}

button:hover {
  transform: translateY(-1px);
  background: rgba(16, 34, 23, 0.12);
}

button.primary {
  background: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-strong);
}

button.danger {
  background: rgba(180, 35, 24, 0.1);
  color: #9f271d;
}

button.danger:hover {
  background: rgba(180, 35, 24, 0.16);
}

button.subtle {
  background: rgba(16, 34, 23, 0.04);
  color: var(--muted);
}

button.subtle:hover {
  background: rgba(16, 34, 23, 0.08);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

body.compact-mode .topbar,
body.compact-mode .control-panel,
body.compact-mode .activity-panel,
body.compact-mode .compact-strip,
body.compact-mode .chat-head {
  display: none;
}

body.compact-mode .app-shell {
  width: 100%;
  padding: 0;
  grid-template-rows: minmax(0, 1fr);
}

body.compact-mode .app-layout {
  grid-template-columns: minmax(0, 1fr);
  margin-top: 0;
  height: 100%;
}

body.compact-mode .chat-panel {
  min-height: 0;
  height: 100%;
  border: 0;
  border-radius: 0;
}

body.compact-mode .messages {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding: 12px 12px 14px;
}

body.compact-mode .composer {
  flex: 0 0 auto;
  padding: 12px;
}

body.compact-mode .composer-actions .hint,
body.compact-mode .upload-meta {
  display: none;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1040px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(160px, 32vh) minmax(0, 1fr);
  }

  .chat-panel {
    min-height: 0;
    height: 100%;
  }

  body.sidebar-collapsed .app-layout,
  body.compact-mode .app-layout {
    grid-template-rows: minmax(0, 1fr);
  }

  .messages {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
  }

  .composer {
    flex: 0 0 auto;
  }

  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .topbar-meta {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 18px, 1320px);
    padding-top: 12px;
  }

  .card {
    border-radius: 22px;
  }

  .topbar,
  .control-panel,
  .activity-panel {
    padding: 18px;
  }

  .topbar,
  .composer-footer,
  .panel-head,
  .chat-head,
  .workspace-section-head {
    flex-direction: column;
    align-items: stretch;
  }

  .directory-row {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .topbar-pills,
  .chat-meta,
  .thread-toolbar {
    width: 100%;
    justify-content: stretch;
  }

  .topbar-actions button,
  .directory-row button,
  .composer-footer button,
  .thread-actions button {
    width: 100%;
  }

  .upload-panel-inline {
    grid-template-columns: 1fr;
  }

  .composer-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .chat-head {
    padding: 18px 18px 0;
  }

  .messages {
    min-height: 0;
    max-height: none;
    padding: 18px;
  }

  .composer {
    padding: 16px 18px 18px;
  }

  .reasoning-switch {
    grid-template-columns: 1fr;
  }

  .thread-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .compact-strip {
    flex-wrap: wrap;
    padding: 10px 12px 0;
  }
}
