:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  --page: #f7f7f5;
  --surface: #ffffff;
  --surface-muted: #eeeeeb;
  --text: #202321;
  --muted: #6c716d;
  --border: #d9dcd8;
  --accent: #137761;
  --accent-strong: #0e5c4a;
  --accent-soft: #e2f1ec;
  --danger: #b33a32;
  --shadow: 0 12px 40px rgba(26, 31, 28, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--page);
  color: var(--text);
}

body {
  min-height: 100dvh;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

[hidden] {
  display: none !important;
}

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

.login-panel {
  width: min(100%, 360px);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  font-size: 20px;
  font-weight: 700;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.login-panel h1 {
  margin: 22px 0 28px;
  font-size: 24px;
  line-height: 1.25;
}

.login-panel label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.login-panel input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
}

.login-panel input:focus,
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(19, 119, 97, 0.13);
}

.form-error,
.composer-error {
  min-height: 20px;
  margin: 8px 0;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.5;
}

.primary-button,
.quiet-button,
.danger-button {
  min-height: 40px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 650;
}

.primary-button {
  width: 100%;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
}

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

.quiet-button {
  padding: 0 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.danger-button {
  padding: 0 14px;
  border: 1px solid #e8c5c1;
  background: #fff5f3;
  color: var(--danger);
}

.chat-view {
  display: grid;
  width: 100%;
  height: 100dvh;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  background: var(--surface);
}

.topbar {
  z-index: 2;
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(10px, env(safe-area-inset-top)) 18px 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
}

.brand-mark-small {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  font-size: 17px;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
}

.connection-row {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.connection-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a7aca8;
}

.connection-dot.online {
  background: #25a06f;
}

.messages {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px max(16px, calc((100% - 760px) / 2));
  scroll-behavior: smooth;
}

.empty-state {
  display: grid;
  min-height: 100%;
  place-content: center;
  justify-items: center;
  padding-bottom: 72px;
  text-align: center;
}

.empty-mark {
  width: 48px;
  height: 48px;
  margin-bottom: 18px;
}

.empty-state h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.35;
}

.message {
  display: flex;
  margin: 0 0 22px;
}

.message.user {
  justify-content: flex-end;
}

.message-body {
  max-width: min(88%, 680px);
}

.message.user .message-body {
  padding: 11px 14px;
  border: 1px solid #c9e4da;
  border-radius: 8px 8px 2px 8px;
  background: var(--accent-soft);
}

.message.assistant .message-body {
  width: 100%;
  padding: 2px 0;
}

.message-label {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.message-text {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.7;
}

.attachment {
  display: block;
  width: min(100%, 680px);
  margin-top: 12px;
  color: var(--text);
  text-decoration: none;
}

.attachment-image img,
.attachment-video video {
  display: block;
  width: 100%;
  max-height: 460px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
  object-fit: contain;
}

.attachment-audio audio {
  width: 100%;
}

.attachment-file {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.attachment-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  font-weight: 650;
}

.attachment-size {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.task-status {
  padding: 10px max(18px, calc((100% - 760px) / 2));
  border-top: 1px solid var(--border);
  background: #fbfbfa;
  color: var(--muted);
  font-size: 13px;
}

.task-status-line {
  display: flex;
  align-items: center;
  gap: 9px;
}

.execution-details {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.execution-details summary {
  width: fit-content;
  cursor: pointer;
  color: var(--muted);
  font-weight: 650;
}

.execution-list {
  margin-top: 8px;
  padding-left: 11px;
  border-left: 2px solid var(--border);
}

.execution-item {
  padding: 5px 0 8px;
}

.execution-item-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  font-weight: 600;
}

.execution-status {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.status-failed .execution-status {
  color: var(--danger);
}

.execution-text {
  margin-top: 3px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-family: Consolas, "SFMono-Regular", monospace;
  line-height: 1.5;
}

.message-execution {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.status-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #c9cdca;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.composer-band {
  padding: 12px max(12px, calc((100% - 780px) / 2)) max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--page);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.composer textarea {
  width: 100%;
  min-height: 40px;
  max-height: 152px;
  resize: none;
  overflow-y: auto;
  padding: 9px 4px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
}

.composer textarea::placeholder {
  color: #999e9a;
}

.upload-preview {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.pending-image {
  position: relative;
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
}

.pending-image img {
  display: block;
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  object-fit: cover;
}

.remove-image {
  position: absolute;
  top: 3px;
  right: 3px;
  display: grid;
  width: 24px;
  height: 24px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 24, 22, 0.82);
  color: #ffffff;
  font-size: 20px;
  line-height: 1;
}

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

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 25px;
  line-height: 1;
}

.icon-button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.send-button {
  width: auto;
  min-width: 64px;
  padding: 0 16px;
}

.composer-error {
  min-height: 0;
  margin: 6px 2px 0;
}

.composer-error.info {
  color: var(--muted);
}

.composer-meta {
  display: flex;
  min-height: 30px;
  align-items: center;
  margin: 4px 2px 0;
}

.model-settings-button {
  min-height: 30px;
  padding: 0 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.model-settings-button:hover:not(:disabled) {
  color: var(--accent);
}

.settings-dialog {
  width: min(calc(100% - 28px), 380px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.settings-dialog::backdrop {
  background: rgba(20, 24, 22, 0.38);
}

.settings-form {
  display: grid;
  gap: 9px;
  padding: 18px;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.settings-header h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.35;
}

.dialog-close {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.settings-form label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.settings-form select {
  width: 100%;
  height: 44px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.settings-form select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(19, 119, 97, 0.13);
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.settings-save {
  width: auto;
  padding: 0 18px;
}

@media (max-width: 560px) {
  .topbar {
    min-height: 62px;
    padding-right: 12px;
    padding-left: 12px;
  }

  .quiet-button {
    min-height: 36px;
    padding: 0 11px;
  }

  .messages {
    padding-top: 16px;
  }

  .message-body {
    max-width: 92%;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .composer-actions {
    justify-content: flex-end;
  }

  .send-button {
    min-width: 72px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .messages {
    scroll-behavior: auto;
  }

  .status-spinner {
    animation-duration: 1.6s;
  }
}
