:root {
  color-scheme: light;
  --ink: #1f1f1c;
  --muted: #6f6f69;
  --quiet: #989892;
  --line: #e3e3df;
  --line-strong: #d5d5d0;
  --canvas: #f7f7f5;
  --surface: #ffffff;
  --surface-soft: #f1f1ee;
  --surface-muted: #ecece8;
  --accent: #252522;
  --accent-hover: #10100f;
  --green: #198754;
  --green-soft: #e6f5eb;
  --blue: #276a8d;
  --blue-soft: #e8f3f8;
  --amber: #9a651d;
  --amber-soft: #fbf1dd;
  --red: #b44032;
  --red-soft: #fbe9e6;
  --radius: 8px;
  --safe-top: max(12px, env(safe-area-inset-top));
  --safe-bottom: max(14px, env(safe-area-inset-bottom));
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--canvas);
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgb(32 108 149 / 30%);
  outline-offset: 2px;
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  letter-spacing: 0;
}

.app-shell {
  min-height: 100dvh;
}

.auth-screen {
  display: flex;
  min-height: 100dvh;
  padding: var(--safe-top) 24px var(--safe-bottom);
  flex-direction: column;
  justify-content: center;
}

.auth-brand,
.auth-form {
  width: min(100%, 380px);
  margin-right: auto;
  margin-left: auto;
}

.auth-brand {
  margin-bottom: 28px;
}

.brand-mark {
  display: block;
  width: 48px;
  height: 48px;
}

.auth-brand .brand-mark {
  margin-bottom: 18px;
}

.auth-brand h1 {
  margin-bottom: 7px;
  font-size: 30px;
  line-height: 1.15;
  font-weight: 680;
}

.auth-brand p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.auth-form {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.auth-form label {
  display: block;
  margin-bottom: 8px;
  color: #44443f;
  font-size: 14px;
  font-weight: 600;
}

.password-field {
  display: flex;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
}

.password-field:focus-within {
  border-color: #8eb5ca;
  box-shadow: 0 0 0 3px rgb(32 108 149 / 11%);
}

.password-field input {
  width: 100%;
  min-width: 0;
  height: 46px;
  padding: 0 12px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.password-field input::placeholder,
.command-form textarea::placeholder {
  color: #9d9d97;
}

.field-toggle {
  min-width: 54px;
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  color: #4b4b46;
  font-size: 13px;
  font-weight: 600;
}

.primary-button,
.quiet-button,
.icon-button,
.send-button,
.task-main,
.task-cancel,
.danger-button {
  border: 0;
  border-radius: 6px;
  transition: background-color 150ms ease, color 150ms ease, opacity 150ms ease, transform 150ms ease;
}

.primary-button {
  display: inline-flex;
  width: 100%;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  margin-top: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 650;
}

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

.form-message {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.form-message.error {
  color: var(--red);
}

.workspace {
  width: min(100%, 880px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: var(--safe-top) 16px calc(230px + var(--safe-bottom));
}

.workspace-header,
.brand-lockup,
.workspace-actions,
.connection-strip,
.connection-copy,
.connection-metrics,
.conversation-heading,
.composer-footer,
.detail-header,
.output-heading,
.assistant-row,
.assistant-heading,
.message-meta,
.task-actions {
  display: flex;
  align-items: center;
}

.workspace-header {
  min-height: 40px;
  justify-content: space-between;
}

.brand-lockup {
  gap: 9px;
}

.brand-mark.compact {
  width: 30px;
  height: 30px;
}

.brand-lockup h1 {
  margin-bottom: 0;
  font-size: 16px;
  font-weight: 680;
  line-height: 1.2;
}

.workspace-actions {
  gap: 2px;
}

.icon-button {
  display: inline-grid;
  width: 36px;
  height: 36px;
  place-items: center;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 23px;
  line-height: 1;
}

.icon-button:hover:not(:disabled),
.quiet-button:hover:not(:disabled) {
  background: var(--surface-muted);
  color: var(--ink);
}

.quiet-button {
  min-height: 34px;
  padding: 0 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

#refresh-button span {
  display: block;
  line-height: 1;
}

#refresh-button.is-refreshing span {
  animation: spin 760ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.connection-strip {
  min-height: 50px;
  gap: 9px;
  margin-top: 13px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.connection-dot {
  flex: 0 0 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--quiet);
}

.connection-strip.online .connection-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgb(25 135 84 / 12%);
}

.connection-strip.offline .connection-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgb(180 64 50 / 10%);
}

.connection-copy {
  min-width: 0;
  flex: 1 1 auto;
  gap: 6px;
}

.connection-copy strong,
.connection-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection-copy strong {
  font-size: 13px;
  line-height: 1.3;
  font-weight: 650;
}

.connection-copy span {
  color: var(--muted);
  font-size: 12px;
}

.connection-metrics {
  flex: 0 0 auto;
  gap: 8px;
}

.connection-metric {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.connection-metric b {
  color: var(--ink);
  font-weight: 700;
}

.connection-status {
  display: inline-flex;
  min-height: 23px;
  align-items: center;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--surface-muted);
  color: #696964;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}

.connection-status.online {
  background: var(--green-soft);
  color: #227247;
}

.connection-status.offline {
  background: var(--red-soft);
  color: #a23e31;
}

.updated-time {
  flex: 0 0 auto;
  color: var(--quiet);
  font-size: 11px;
  white-space: nowrap;
}

.conversation-section {
  padding: 30px 0 6px;
}

.conversation-heading {
  justify-content: center;
  margin-bottom: 24px;
}

.conversation-heading h2 {
  margin-bottom: 0;
  color: var(--quiet);
  font-size: 12px;
  font-weight: 600;
}

.history-loading {
  padding: 52px 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.command-list {
  display: grid;
  gap: 28px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.conversation-turn {
  display: grid;
  gap: 15px;
}

.task-main {
  display: block;
  max-width: min(86%, 620px);
  padding: 11px 13px;
  background: var(--surface-muted);
  color: var(--ink);
  text-align: left;
}

.task-main:hover:not(:disabled) {
  background: #e3e3df;
}

.user-message {
  justify-self: end;
  border-radius: 8px;
}

.task-text {
  display: block;
  margin: 0;
  font-size: 15px;
  font-weight: 450;
  line-height: 1.52;
  overflow-wrap: anywhere;
}

.message-meta {
  justify-content: flex-end;
  gap: 6px;
  margin-top: 7px;
  color: #777772;
  font-size: 11px;
}

.assistant-row {
  align-items: flex-start;
  gap: 10px;
}

.assistant-avatar {
  display: inline-grid;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  place-items: center;
  margin-top: 1px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.assistant-content {
  min-width: 0;
  flex: 1 1 auto;
}

.assistant-heading {
  gap: 8px;
  min-height: 28px;
}

.assistant-name {
  font-size: 14px;
  font-weight: 680;
}

.assistant-message {
  width: 100%;
  margin-top: 6px;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.assistant-message:hover:not(:disabled) .assistant-answer {
  color: #090908;
}

.assistant-answer {
  display: block;
  color: #4a4a45;
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.assistant-answer.is-active {
  color: var(--muted);
}

.task-output {
  display: block;
  max-height: 178px;
  overflow: auto;
  margin-top: 9px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8f8f6;
  color: #42423e;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.58;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.task-output.error-output {
  border-color: #efcec8;
  background: #fff8f7;
  color: #8d372c;
}

.task-actions {
  gap: 8px;
  margin-top: 9px;
}

.task-time {
  color: var(--quiet);
  font-size: 11px;
}

.task-cancel {
  min-height: 28px;
  padding: 0 8px;
  background: var(--red-soft);
  color: #a13d30;
  font-size: 12px;
  font-weight: 600;
}

.task-cancel:hover:not(:disabled) {
  background: #f7dad5;
}

.status-badge {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
}

.status-badge.waiting,
.status-badge.neutral {
  background: var(--surface-muted);
  color: #696964;
}

.status-badge.running {
  background: var(--blue-soft);
  color: #216481;
}

.status-badge.success {
  background: var(--green-soft);
  color: #237247;
}

.status-badge.failed {
  background: var(--red-soft);
  color: #9f3b2f;
}

.status-badge.cancelled {
  background: var(--amber-soft);
  color: #825714;
}

.empty-state {
  padding: 94px 20px 58px;
  color: var(--muted);
  text-align: center;
}

.empty-state img {
  width: 38px;
  height: 38px;
  margin-bottom: 14px;
  opacity: 0.5;
}

.empty-state p {
  margin-bottom: 0;
  font-size: 15px;
  line-height: 1.5;
}

.command-form {
  position: fixed;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: var(--canvas);
}

.composer-shell {
  width: min(100%, 848px);
  margin: 14px auto 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgb(30 30 26 / 8%);
}

.composer-shell:focus-within {
  border-color: #9c9c96;
  box-shadow: 0 0 0 3px rgb(32 108 149 / 10%), 0 8px 24px rgb(30 30 26 / 8%);
}

.command-form textarea {
  display: block;
  width: 100%;
  min-height: 48px;
  max-height: 138px;
  resize: none;
  padding: 14px 14px 8px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
}

.composer-footer {
  min-height: 38px;
  justify-content: space-between;
  padding: 2px 7px 7px 13px;
}

.character-count {
  color: var(--quiet);
  font-size: 11px;
}

.send-button {
  display: inline-grid;
  width: 31px;
  height: 31px;
  place-items: center;
  padding: 0;
  background: var(--accent);
  color: #fff;
  font-size: 19px;
  font-weight: 650;
  line-height: 1;
}

.send-button:hover:not(:disabled) {
  background: var(--accent-hover);
}

.send-button.is-sending {
  background: #777771;
  font-size: 13px;
}

.composer-message {
  width: min(100%, 848px);
  min-height: 0;
  margin: 4px auto 0;
  padding-left: 4px;
}

.detail-overlay {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 0 0;
  background: rgb(29 29 26 / 36%);
  backdrop-filter: blur(3px);
}

.detail-sheet {
  width: min(100%, 720px);
  max-height: min(88dvh, 760px);
  overflow: auto;
  padding: 8px 16px calc(18px + var(--safe-bottom));
  border-radius: 10px 10px 0 0;
  background: var(--surface);
  box-shadow: 0 -14px 38px rgb(29 29 26 / 16%);
}

.sheet-handle {
  width: 34px;
  height: 4px;
  margin: 1px auto 13px;
  border-radius: 4px;
  background: #d2d2cd;
}

.detail-header {
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.detail-header h2 {
  margin: 8px 0 0;
  font-size: 20px;
  line-height: 1.3;
}

.detail-text {
  margin: 22px 0 18px;
  font-size: 16px;
  font-weight: 550;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.detail-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.detail-meta div {
  min-width: 0;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafaf8;
}

.detail-meta dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
}

.detail-meta dd {
  overflow: hidden;
  margin: 0;
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.output-section {
  margin-top: 18px;
}

.output-heading {
  justify-content: space-between;
  margin-bottom: 8px;
}

.output-heading h3 {
  margin-bottom: 0;
  font-size: 14px;
}

.output-heading span {
  color: var(--muted);
  font-size: 12px;
}

.detail-output {
  max-height: 285px;
  overflow: auto;
  margin: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f7f5;
  color: #3f3f3a;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.danger-button {
  width: 100%;
  min-height: 44px;
  margin-top: 18px;
  background: var(--red-soft);
  color: #a03d30;
  font-size: 14px;
  font-weight: 650;
}

.danger-button:hover:not(:disabled) {
  background: #f7d9d4;
}

.toast {
  position: fixed;
  z-index: 30;
  right: 16px;
  bottom: calc(114px + var(--safe-bottom));
  left: 16px;
  max-width: 480px;
  margin: auto;
  padding: 11px 13px;
  border-radius: 7px;
  background: #2a2a27;
  color: #fff;
  box-shadow: 0 10px 25px rgb(30 30 26 / 18%);
  font-size: 14px;
  line-height: 1.4;
}

.toast.error {
  background: #913a2f;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 520px) {
  .connection-metrics {
    display: none;
  }

  .connection-copy {
    gap: 4px;
  }

  .connection-copy span {
    max-width: 180px;
  }
}

@media (min-width: 640px) {
  .workspace {
    padding-right: 24px;
    padding-left: 24px;
  }

  .command-form {
    padding-right: 24px;
    padding-left: 24px;
  }

  .detail-overlay {
    align-items: center;
    padding: 24px;
  }

  .detail-sheet {
    border-radius: 8px;
  }

  .sheet-handle {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
