:root {
  --bg-main: #0b0f17;
  --bg-elevated: rgba(22, 28, 41, 0.86);
  --bg-card: #151c28;
  --bg-user: #2563eb;
  --border-subtle: rgba(148, 163, 184, 0.16);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --accent-blue: #3b82f6;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-main);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  overscroll-behavior-y: none;
}

.hidden {
  display: none !important;
}

/* 采用 100dvh 让 iPhone Safari 软键盘弹起时自动收缩布局而不顶飞顶栏 */
.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
  background: var(--bg-main);
}

.topbar {
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: var(--bg-elevated);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 10;
}

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

.conn-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
  font-weight: 500;
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-amber);
}

.conn-dot.ok {
  background: var(--accent-green);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.65);
}

.conn-dot.warn {
  background: var(--accent-amber);
}

.conn-dot.offline {
  background: var(--accent-red);
}

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

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.workspace-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.instance-select {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
}

.model-pill {
  flex-shrink: 0;
  padding: 4px 9px;
  border-radius: 8px;
  background: rgba(59, 130, 246, 0.16);
  color: #93c5fd;
  font-size: 12px;
  font-weight: 500;
}

.pwa-tip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 14px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(59, 130, 246, 0.14);
  border: 1px solid rgba(59, 130, 246, 0.32);
  font-size: 12.5px;
  line-height: 1.45;
  color: #dbeafe;
}

.pwa-tip-close {
  border: none;
  background: transparent;
  color: #93c5fd;
  font-size: 15px;
  padding: 4px;
  cursor: pointer;
}

.chat-viewport {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
}

.empty-state {
  margin: 48px auto;
  max-width: 320px;
  text-align: center;
  color: var(--text-secondary);
}

.empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.empty-desc {
  font-size: 13.5px;
  line-height: 1.55;
  margin: 0;
}

.empty-desc code {
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 12px;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg-card {
  max-width: 90%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-card.user {
  align-self: flex-end;
  background: var(--bg-user);
  color: #ffffff;
  border-bottom-right-radius: 5px;
}

.msg-card.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-bottom-left-radius: 5px;
}

.msg-thought {
  font-size: 12px;
  color: var(--text-secondary);
  padding-bottom: 6px;
  margin-bottom: 6px;
  border-bottom: 1px dashed var(--border-subtle);
}

/* 审批高优横幅 */
.approval-banner {
  margin: 0 12px 8px;
  padding: 12px 14px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.2), rgba(21, 28, 40, 0.96));
  border: 1px solid rgba(245, 158, 11, 0.5);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.approval-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.approval-tag {
  font-size: 12.5px;
  font-weight: 600;
  color: #fcd34d;
}

.approval-count {
  font-size: 12px;
  color: var(--text-secondary);
}

.approval-context {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.32);
  padding: 8px 10px;
  border-radius: 9px;
  margin-bottom: 10px;
  max-height: 74px;
  overflow-y: auto;
}

.approval-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-approve,
.btn-reject {
  height: 40px;
  border-radius: 11px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-approve {
  background: var(--accent-green);
  color: #052e16;
}

.btn-reject {
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

/* 底部输入与快捷词 */
.composer-area {
  padding: 8px 12px calc(var(--safe-bottom) + 10px);
  background: var(--bg-elevated);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border-subtle);
}

.quick-bar {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}

.quick-bar::-webkit-scrollbar {
  display: none;
}

.chip,
.chip-stop {
  flex-shrink: 0;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  cursor: pointer;
}

.chip {
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-secondary);
}

.chip-stop {
  border: 1px solid rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
  font-weight: 600;
}

.composer-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

/* 字号固定 >= 16px，彻底阻止 iPhone Safari 点击输入框时自动放大页面 */
.prompt-input {
  flex: 1;
  min-height: 42px;
  max-height: 120px;
  padding: 10px 13px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.35;
  resize: none;
  outline: none;
}

.prompt-input:focus {
  border-color: var(--accent-blue);
}

.mic-btn {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 17px;
  cursor: pointer;
}

.mic-btn.recording {
  border-color: var(--accent-red);
  background: rgba(239, 68, 68, 0.22);
}

.send-btn {
  height: 42px;
  padding: 0 16px;
  border-radius: 13px;
  border: none;
  background: var(--accent-blue);
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.send-btn:disabled {
  opacity: 0.5;
}

/* iOS 底部抽屉与口令弹窗 */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.sheet-card {
  width: 100%;
  max-width: 680px;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 18px 18px calc(var(--safe-bottom) + 18px);
  border-radius: 22px 22px 0 0;
  background: #141b27;
  border-top: 1px solid var(--border-subtle);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.sheet-desc {
  margin: 8px 0 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.sheet-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.muted-note {
  font-weight: 400;
  color: var(--accent-green);
  margin-left: 6px;
}

.text-field {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border-radius: 11px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-main);
  color: var(--text-primary);
  font-size: 16px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}

.sheet-btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 6px;
}

.primary-btn,
.secondary-btn {
  height: 42px;
  border-radius: 12px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn {
  border: none;
  background: var(--accent-blue);
  color: #ffffff;
}

.secondary-btn {
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.toast {
  position: fixed;
  top: calc(var(--safe-top) + 60px);
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 13px;
  z-index: 80;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
