* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* hidden 属性必须生效（否则 display:flex 等样式会覆盖它） */
[hidden] {
  display: none !important;
}

:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --primary: #4f6ef7;
  --primary-dark: #3b55d9;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e4e8f0;
  --ai-bubble: #eef2ff;
  --user-bubble: #4f6ef7;
  --error: #d64545;
  --ok: #2e9e6b;
  --warn: #d99a2b;
}

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.brand h1 {
  font-size: 22px;
  color: var(--primary);
}

.brand p {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 18px;
}

.theme-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.theme-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafbfe;
  cursor: pointer;
  transition: all 0.15s;
}

.theme-item:hover {
  border-color: var(--primary);
  background: #f4f7ff;
}

.theme-item.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.theme-item .emoji {
  font-size: 18px;
  margin-right: 6px;
}

.theme-error {
  color: var(--error);
  font-size: 13px;
  line-height: 1.6;
  padding: 8px;
}

.stats {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

.stats h3 {
  color: var(--text);
  font-size: 15px;
}

.chat-area {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
}

.chat-header {
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.chat-header h2 {
  font-size: 20px;
}

.chat-header p {
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}

.ghost-btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
}

.ghost-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
}

.msg.ai {
  align-self: flex-start;
  background: var(--ai-bubble);
  border-bottom-left-radius: 4px;
}

.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg .role-tag {
  display: block;
  font-size: 12px;
  margin-bottom: 4px;
  opacity: 0.7;
}

.speak-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  margin-top: 6px;
  opacity: 0.8;
}

.speak-btn:hover {
  opacity: 1;
}

.feedback-panel {
  background: var(--panel);
  border-top: 2px solid var(--border);
  max-height: 300px;
  display: flex;
  flex-direction: column;
}

.feedback-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 16px 0;
}

.tab {
  padding: 8px 14px;
  border: none;
  background: transparent;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
}

.tab.active {
  background: #f4f6fb;
  color: var(--primary);
  font-weight: 600;
}

.feedback-content {
  padding: 14px 20px 18px;
  overflow-y: auto;
  font-size: 14.5px;
  line-height: 1.7;
}

.feedback-content h4 {
  font-size: 14px;
  margin: 10px 0 4px;
  color: var(--text);
}

.feedback-content h4:first-child {
  margin-top: 0;
}

.error-item {
  background: #fff5f5;
  border-left: 3px solid var(--error);
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 8px;
}

.error-item .wrong {
  color: var(--error);
  text-decoration: line-through;
}

.error-item .right {
  color: var(--ok);
  font-weight: 600;
}

.alt-item {
  background: #f2fbf6;
  border-left: 3px solid var(--ok);
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 8px;
}

.alt-item .cn {
  color: var(--muted);
  font-size: 13px;
}

.good-msg {
  color: var(--ok);
  font-weight: 600;
}

.input-area {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 14px 28px 8px;
  background: var(--panel);
}

.mic-wrap {
  position: relative;
}

.mic-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: #fff;
  font-size: 19px;
  cursor: pointer;
  transition: all 0.15s;
}

.mic-btn:hover {
  border-color: var(--primary);
}

.mic-btn.recording {
  border-color: var(--error);
  background: #fff0f0;
  animation: pulse 1.2s infinite;
}

.mic-status {
  position: absolute;
  bottom: 54px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--error);
  color: #fff;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  white-space: nowrap;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(214, 69, 69, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(214, 69, 69, 0); }
}

#user-input {
  flex: 1;
  resize: none;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
}

#user-input:focus {
  border-color: var(--primary);
}

.send-btn {
  padding: 12px 22px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}

.send-btn:hover {
  background: var(--primary-dark);
}

.hint {
  padding: 0 28px 14px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12.5px;
}

.cost-line {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.04);
  border-radius: 6px;
  padding: 4px 8px;
  display: inline-block;
}

.cost-line .amount {
  color: var(--primary);
  font-weight: 600;
}

.typing {
  color: var(--muted);
  font-style: italic;
}

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 35, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal {
  background: #fff;
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

.modal h2 {
  margin-bottom: 14px;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  font-size: 14px;
  margin-bottom: 6px;
  font-weight: 600;
}

.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

.field small {
  display: block;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.5;
}

.price-note {
  background: #fff7e8;
  border-left: 3px solid var(--warn);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 14px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  background: rgba(20, 25, 40, 0.9);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}

@media (max-width: 760px) {
  body {
    height: 100dvh;
    overflow: hidden;
  }
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
  }
  .sidebar {
    position: relative;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 12px 6px;
    overflow: hidden;
    background: var(--panel);
  }
  .brand {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
  }
  .brand h1 {
    font-size: 17px;
    margin: 0;
  }
  .brand p {
    margin: 0;
    font-size: 11px;
    color: var(--muted);
  }
  .theme-list {
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    padding: 8px 0 6px;
  }
  .theme-list::-webkit-scrollbar {
    display: none;
  }
  .theme-item {
    white-space: nowrap;
    flex: 0 0 auto;
    padding: 8px 13px;
    font-size: 13px;
    border-radius: 18px;
  }
  .stats {
    display: none;
  }
  .chat-area {
    height: 100%;
    min-height: 0;
  }
  .msg {
    max-width: 92%;
    font-size: 14.5px;
  }
  .chat-header {
    padding: 10px 14px;
  }
  .chat-header h2 {
    font-size: 17px;
  }
  .chat-header p {
    font-size: 12px;
  }
  .chat-log {
    padding: 12px 14px;
    gap: 12px;
  }
  .input-area {
    padding: 8px 12px 6px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
  }
  .hint {
    padding: 0 12px calc(8px + env(safe-area-inset-bottom));
  }
  .feedback-panel {
    max-height: 40dvh;
  }
  .feedback-content {
    padding: 10px 12px 12px;
  }
  .mic-btn {
    width: 42px;
    height: 42px;
  }
  .send-btn {
    padding: 10px 18px;
  }
}
