:root {
  color-scheme: dark;
  --bg: #0b1220;
  --panel: #121a2b;
  --panel-2: #182235;
  --border: #273247;
  --text: #e8eefc;
  --muted: #93a0b8;
  --accent: #4f8cff;
  --accent-2: #2f6fed;
  --ok: #3ecf8e;
  --warn: #f0b429;
  --err: #ff6b6b;
  --live: #35d0ba;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: rgba(11, 18, 32, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

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

.title {
  font-size: 16px;
  font-weight: 650;
  line-height: 1.2;
}

.subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.subtitle.connected {
  color: var(--ok);
}
.subtitle.reconnecting {
  color: var(--warn);
}
.subtitle.disconnected {
  color: var(--err);
}

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

.icon-btn,
.text-btn,
.primary-btn {
  min-height: 44px;
  min-width: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
  padding: 0 14px;
  touch-action: manipulation;
}

.icon-btn {
  width: 44px;
  padding: 0;
  font-size: 20px;
}

.primary-btn {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-color: transparent;
  font-weight: 600;
}

.primary-btn:disabled,
.text-btn:disabled {
  opacity: 0.45;
}

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.card {
  margin: 24px 16px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

.muted {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 14px 0;
  font-size: 13px;
  color: var(--muted);
}

.field input,
.composer-wrap textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px; /* iOS 避免自动缩放 */
}

.error {
  color: var(--err);
  min-height: 1.2em;
  font-size: 13px;
}

.hint {
  padding: 10px 16px;
  color: var(--muted);
  font-size: 13px;
}

.session-list {
  overflow-y: auto;
  padding: 0 12px 24px;
  -webkit-overflow-scrolling: touch;
}

.session-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  color: inherit;
  min-height: 72px;
}

.session-item.live {
  border-color: rgba(53, 208, 186, 0.55);
  box-shadow: inset 0 0 0 1px rgba(53, 208, 186, 0.15);
}

.session-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.session-title {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  flex: 0 0 auto;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(53, 208, 186, 0.15);
  color: var(--live);
  border: 1px solid rgba(53, 208, 186, 0.35);
}

.session-preview {
  color: var(--muted);
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.session-meta {
  color: var(--muted);
  font-size: 11px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
}

.thread-meta {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 12px 8px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  max-width: 100%;
}

.msg.user {
  background: #1a2740;
  border-color: #2c3f63;
}

.msg.agent {
  background: #121c2e;
}

.msg.system {
  background: transparent;
  border-style: dashed;
  color: var(--muted);
  font-size: 13px;
}

.msg-role {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.msg-body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
  font-size: 15px;
}

.msg-body pre,
.msg-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.msg-body pre {
  overflow-x: auto;
  background: #0a101b;
  border-radius: 8px;
  padding: 10px;
  margin: 8px 0 0;
}

.tool-chip {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #1c2436;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.composer-wrap {
  position: sticky;
  bottom: 0;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: rgba(11, 18, 32, 0.96);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.composer-wrap textarea {
  resize: none;
  min-height: 48px;
  max-height: 140px;
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.composer-actions .primary-btn,
.composer-actions .text-btn {
  min-width: 88px;
}
