:root {
  --main-color: #007aff;
  --success-color: #34c759;
  --danger-color: #ff3b30;
  --warning-color: #ff9500;
  --bg-color: #f2f2f7;
}

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

body {
  background-color: var(--bg-color);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  margin: 0;
  display: flex;
  justify-content: center;
  height: 100vh;
  overflow: hidden;
}

.init-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s, visibility 0.5s;
}
.init-overlay.hidden { opacity: 0; visibility: hidden; }
.init-spinner {
  width: 50px; height: 50px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.init-text { color: #fff; font-size: 16px; margin-top: 20px; letter-spacing: 1px; }
.init-subtext { color: rgba(255,255,255,0.7); font-size: 12px; margin-top: 8px; }

.app-container {
  width: 100%; max-width: 500px;
  background: #fff;
  display: flex;
  flex-direction: column;
  height: 100%;
  box-shadow: 0 10px 50px rgba(0,0,0,0.1);
}

.top-bar {
  padding: 10px 16px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.top-bar-left { display: flex; align-items: center; gap: 8px; }
.top-logo { width: 24px; height: 24px; border-radius: 4px; }
.top-title { font-size: 14px; font-weight: 600; letter-spacing: 2px; }
.top-bar-right { display: flex; align-items: flex-end; }
.device-id { font-size: 10px; color: rgba(255,255,255,0.7); font-family: monospace; }

.chat-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f9f9fb;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 88%;
  animation: fadeIn 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg-left { align-self: flex-start; flex-direction: row; }
.msg-right { align-self: flex-end; flex-direction: row-reverse; }

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px; font-weight: 700;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.avatar-sys { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); font-size: 11px; }
.avatar-user { background: linear-gradient(135deg, #007aff 0%, #00c6ff 100%); font-size: 14px; }

.msg-content { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.msg-right .msg-content { align-items: flex-end; }

.bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}
.msg-left .bubble { background: #fff; color: #1c1c1e; border: 1px solid #efeff4; border-top-left-radius: 4px; }
.msg-right .bubble { background: var(--main-color); color: #fff; border-top-right-radius: 4px; }

.timestamp { font-size: 10px; color: #aeaeb2; margin-top: 4px; padding: 0 4px; }

.msg-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; justify-content: flex-end; }
.msg-tag {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(0,122,255,0.1); color: var(--main-color);
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 500;
}
.msg-tag::before { content: '🎁'; font-size: 10px; }

.msg-images { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.msg-image {
  max-width: 120px; max-height: 120px;
  border-radius: 8px; cursor: pointer;
  object-fit: cover;
}
.msg-file {
  display: inline-flex; align-items: center; gap: 4px;
  background: #f0f0f5; padding: 4px 8px; border-radius: 8px;
  font-size: 11px; color: #666; margin-top: 4px;
}
.msg-file::before { content: '📄'; }

.activity-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.activity-card {
  background: #fff;
  border: 1px solid #e5e5ea;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s;
}
.activity-card:hover { border-color: var(--main-color); background: #f0f7ff; }
.activity-card.selected { border-color: var(--main-color); background: #e8f4ff; }
.activity-card .card-title {
  color: var(--main-color);
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 6px;
}
.activity-card .card-info { display: flex; justify-content: space-between; align-items: center; }
.activity-card .stock-info { font-size: 10px; color: #666; }
.activity-card .stock-info .remain { color: var(--success-color); font-weight: 600; }
.activity-card .limit-tag {
  font-size: 9px; background: #fff3e0; color: var(--warning-color);
  padding: 2px 6px; border-radius: 8px; font-weight: 500;
}

.audit-report {
  background: #fff; border-radius: 12px;
  border: 1px solid #efeff4; overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,0,0,0.04);
}
.report-header {
  padding: 10px 12px;
  background: linear-gradient(135deg, #f8f9fa 0%, #fff 100%);
  border-bottom: 1px solid #f0f0f0;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.report-title {
  font-weight: 600; font-size: 13px; color: #1c1c1e;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 35%;
}
.stat-pill {
  display: inline-flex; align-items: center;
  padding: 3px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600;
}
.stat-pill.success { background: #e8f8ed; color: var(--success-color); }
.stat-pill.fail { background: #ffebeb; color: var(--danger-color); }
.detail-btn {
  font-size: 11px; color: var(--main-color);
  background: #e8f4ff; border: none;
  padding: 4px 10px; border-radius: 10px;
  cursor: pointer; font-weight: 500;
}
.report-body {
  padding: 10px 12px;
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 6px; min-height: 60px;
}
.report-body.few-items {
  display: flex; flex-wrap: wrap;
  justify-content: flex-start; align-items: center; gap: 8px;
}
.no-data { color: #999; font-size: 11px; grid-column: 1 / -1; text-align: center; padding: 10px 0; }
.id-pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 5px 8px; border-radius: 6px; font-size: 11px;
}
.id-pill .id-text { font-family: monospace; font-weight: 500; }
.id-pill .id-count { font-size: 9px; opacity: 0.7; padding-left: 3px; border-left: 1px solid rgba(0,0,0,0.1); margin-left: 2px; }
.id-pill.success { background: #e8f8ed; color: #1a7f37; }
.id-pill.fail { background: #ffebeb; color: #cf222e; }
.id-pill.more { background: #f5f5f5; color: #666; font-family: -apple-system, sans-serif; font-size: 10px; }
.report-footer {
  padding: 8px 12px; background: #fafafa;
  border-top: 1px solid #f0f0f0;
  display: flex; justify-content: space-between; align-items: center;
}
.footer-item { display: inline-flex; align-items: center; font-size: 10px; color: #666; }
.footer-label { color: #999; margin-right: 3px; }

.modal-overlay {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 10000;
  opacity: 0; visibility: hidden;
  transition: all 0.3s;
}
.modal-overlay.show { opacity: 1; visibility: visible; }
.modal-content {
  width: 90%; max-width: 400px; max-height: 80vh;
  background: #fff; border-radius: 16px; overflow: hidden;
  transform: scale(0.9); transition: transform 0.3s;
}
.modal-overlay.show .modal-content { transform: scale(1); }
.modal-header {
  padding: 14px 16px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  display: flex; justify-content: space-between; align-items: center;
}
.modal-title { font-weight: 600; font-size: 15px; }
.modal-close {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.2); border-radius: 50%;
  cursor: pointer; font-size: 18px;
}
.modal-body { padding: 16px; overflow-y: auto; max-height: calc(80vh - 54px); }

.image-preview {
  max-width: 90%; max-height: 90%;
  border-radius: 8px;
}

.detail-section { margin-bottom: 16px; }
.detail-section:last-child { margin-bottom: 0; }
.detail-section-title {
  font-size: 13px; font-weight: 600; color: #666;
  margin-bottom: 10px; display: flex; align-items: center; gap: 6px;
}
.detail-section-title.success { color: var(--success-color); }
.detail-section-title.fail { color: var(--danger-color); }
.detail-id-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.detail-id-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 8px;
  font-size: 12px; font-family: monospace;
}
.detail-id-pill .pill-count { font-size: 10px; opacity: 0.7; padding-left: 4px; border-left: 1px solid rgba(0,0,0,0.1); }
.detail-id-pill.success { background: #e8f8ed; color: #1a7f37; }
.detail-id-pill.fail { background: #ffebeb; color: #cf222e; }
.fail-group { background: #fff8f8; border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.fail-reason { font-size: 12px; color: var(--danger-color); font-weight: 600; margin-bottom: 8px; }
.detail-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.detail-info-item { background: #f8f9fa; padding: 10px 12px; border-radius: 10px; }
.detail-info-label { font-size: 10px; color: #999; margin-bottom: 4px; }
.detail-info-value { font-size: 12px; color: #333; font-weight: 500; word-break: break-all; }

.input-area { padding: 12px 16px 28px; background: #fff; border-top: 1px solid #efeff4; }

.attachment-tags {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 8px; min-height: 0;
}
.attachment-tags:empty { display: none; }
.attachment-tag {
  display: inline-flex; align-items: center; gap: 4px;
  background: #f0f0f5; color: #333;
  padding: 4px 8px; border-radius: 8px;
  font-size: 11px; max-width: 150px;
}
.attachment-tag img {
  width: 20px; height: 20px;
  border-radius: 4px; object-fit: cover;
}
.attachment-tag .att-name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 80px;
}
.attachment-tag .att-close {
  width: 14px; height: 14px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.1); border-radius: 50%;
  font-size: 10px; cursor: pointer;
}
.attachment-tag .att-close:hover { background: rgba(0,0,0,0.2); }

.selected-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; align-items: center; }

.model-select {
  padding: 4px 8px;
  border: 1px solid #e5e5ea;
  border-radius: 10px;
  font-size: 11px;
  background: #fff;
  color: #333;
  outline: none;
  cursor: pointer;
}
.model-select:focus { border-color: var(--main-color); }

.mode-btn {
  display: inline-flex; align-items: center; gap: 3px;
  background: #e8f4ff; color: var(--main-color);
  padding: 4px 10px; border-radius: 10px;
  font-size: 10px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--main-color);
}
.mode-btn.thinking {
  background: linear-gradient(135deg, #667eea20, #764ba220);
  color: #667eea; border-color: #667eea;
}

.feature-tag {
  display: inline-flex; align-items: center; gap: 3px;
  background: #f5f5f5; color: #666;
  padding: 4px 10px; border-radius: 10px;
  font-size: 11px; font-weight: 500;
  cursor: pointer; border: 1px solid #e0e0e0;
  transition: all 0.2s;
}
.feature-tag:hover { background: #eee; }
.feature-tag.active {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff; border-color: transparent;
}

.selected-tag {
  display: inline-flex; align-items: center; gap: 4px;
  background: linear-gradient(135deg, #007aff, #00c6ff);
  color: #fff; padding: 4px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 500;
  cursor: pointer; animation: tagPop 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes tagPop {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}
.selected-tag .tag-name { max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected-tag .tag-close {
  width: 14px; height: 14px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.3); border-radius: 50%; font-size: 10px;
}
.selected-tag.image-cached {
  background: linear-gradient(135deg, #ff9500, #ffcc00);
}

.input-panel {
  background: #f2f2f7; border-radius: 18px;
  padding: 8px 12px;
  display: flex; flex-direction: column;
  transition: background 0.2s;
}
.input-panel:focus-within { background: #e5e5ea; }
.input-panel.drag-over { background: #d0e8ff; border: 2px dashed var(--main-color); }

textarea {
  width: 100%; border: none; background: transparent;
  resize: none; height: 80px; outline: none;
  font-size: 15px; padding: 8px; color: #1c1c1e;
}
.action-bar { display: flex; justify-content: space-between; align-items: center; padding-top: 4px; }
.action-left { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: #f5f5f5; border: 1px solid #e5e5ea;
  border-radius: 8px; cursor: pointer;
  padding: 6px; transition: all 0.2s;
}
.icon-btn:hover { background: #e8f4ff; border-color: var(--main-color); }
.icon-btn:active { opacity: 0.7; }
.icon-btn img { width: 18px; height: 18px; opacity: 0.6; }
.icon-btn:hover img { opacity: 1; }

button {
  background: var(--main-color); color: #fff;
  border: none; padding: 8px 20px; border-radius: 18px;
  font-weight: 600; font-size: 14px;
  cursor: pointer; transition: opacity 0.2s;
}
button:active { opacity: 0.7; }
button:disabled { background: #c7c7cc; cursor: not-allowed; }
button.running { background: var(--danger-color); }

.toast {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: rgba(0,0,0,0.75); color: #fff;
  padding: 12px 24px; border-radius: 20px;
  font-size: 14px;
  opacity: 0; visibility: hidden;
  transition: all 0.3s; z-index: 10000;
}
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, -50%) scale(1); }

.thinking-bubble {
  background: linear-gradient(135deg, #f8f9ff 0%, #f0f4ff 100%);
  border: 1px solid #e0e7ff; border-radius: 12px;
  overflow: hidden; font-size: 13px;
}
.thinking-header {
  padding: 8px 12px;
  background: linear-gradient(135deg, #667eea15, #764ba215);
  display: flex; align-items: center; gap: 6px;
  cursor: pointer; user-select: none;
}
.thinking-title { font-weight: 600; color: #667eea; flex: 1; }
.thinking-toggle { color: #667eea; font-size: 10px; transition: transform 0.2s; }
.thinking-bubble.collapsed .thinking-toggle { transform: rotate(-90deg); }
.thinking-body {
  padding: 10px 12px; color: #555; line-height: 1.6;
  max-height: 200px; overflow-y: auto;
}
.thinking-bubble.collapsed .thinking-body { max-height: 0; padding: 0 12px; overflow: hidden; }

.typing-cursor { display: inline-block; color: var(--main-color); animation: blink 0.8s infinite; }
@keyframes blink { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; } }

.tool-status { display: inline-flex; align-items: center; gap: 6px; color: #667eea; font-size: 13px; }
.tool-status::after {
  content: ''; width: 12px; height: 12px;
  border: 2px solid #667eea; border-top-color: transparent;
  border-radius: 50%; animation: spin 0.8s linear infinite;
}

.gen-image {
  max-width: 100%; border-radius: 12px;
  margin-top: 8px; cursor: pointer;
}

/* 等待结果提示 */
.pending-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: linear-gradient(135deg, #f8f9ff 0%, #f0f4ff 100%);
  border-radius: 16px;
  border: 1px solid #e0e6ff;
}
.pending-spinner {
  width: 22px; height: 22px;
  border: 3px solid #e0e6ff;
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
.pending-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  color: #333;
}
.pending-hint {
  font-size: 12px;
  color: #888;
}
.pending-row .msg-content { flex: 1; }
.pending-container { margin: 0; }
