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

:root {
  --primary: #07C160;
  --primary-dark: #06AD56;
  --danger: #FF4D4F;
  --warning: #FAAD14;
  --bg: #F5F5F5;
  --card-bg: #FFFFFF;
  --text: #333333;
  --text-light: #999999;
  --border: #E5E5E5;
  --user-msg: #95EC69;
  --ai-msg: #FFFFFF;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* =============== 登录/注册页面 =============== */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.auth-container {
  width: 100%;
  max-width: 360px;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 32px 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.auth-header {
  text-align: center;
  margin-bottom: 24px;
}

.auth-header h1 {
  font-size: 28px;
  color: var(--primary);
  margin-bottom: 8px;
}

.auth-header p {
  color: var(--text-light);
  font-size: 14px;
}

.auth-form h2 {
  font-size: 20px;
  margin-bottom: 20px;
  text-align: center;
}

.form-group {
  margin-bottom: 16px;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--primary);
}

.captcha-group {
  display: flex;
  gap: 12px;
  align-items: center;
}

.captcha-group input {
  flex: 1;
}

#captchaCanvas {
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid var(--border);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

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

.btn-primary:disabled {
  background: var(--text-light);
  cursor: not-allowed;
}

.auth-switch {
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-light);
}

.auth-switch a {
  color: var(--primary);
  text-decoration: none;
}

/* =============== 主应用页面 =============== */

.main-app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* 头部 */
.header {
  background: var(--card-bg);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 50px;
}

.header h1 {
  font-size: 18px;
  font-weight: 600;
}

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

.nav-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 6px;
  background: rgba(7, 193, 96, 0.1);
  transition: all 0.2s;
}

.nav-link:hover {
  background: rgba(7, 193, 96, 0.2);
}

.menu-btn {
  width: 36px;
  height: 36px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
}

.menu-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: all 0.3s;
}

/* 客户名称区域 */
.customer-section {
  background: var(--card-bg);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 50px;
  left: 0;
  right: 0;
  z-index: 99;
}

.customer-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.customer-input-wrapper label {
  font-size: 14px;
  color: var(--text-light);
  white-space: nowrap;
}

.customer-input-wrapper input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}

.customer-input-wrapper input:focus {
  border-color: var(--primary);
}

/* 对话区域 */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
  position: fixed;
  top: 95px;
  left: 0;
  right: 0;
  bottom: 70px;
}

/* 欢迎消息 */
.welcome-msg {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}

.welcome-msg p {
  font-size: 16px;
  margin-bottom: 8px;
}

.welcome-msg .example {
  font-size: 14px;
  color: #AAAAAA;
}

/* 消息气泡 */
.message {
  display: flex;
  margin-bottom: 16px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.message.ai {
  justify-content: flex-start;
}

.message-content {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
}

.message.user .message-content {
  background: var(--user-msg);
  color: var(--text);
  border-bottom-right-radius: 4px;
}

.message.ai .message-content {
  background: var(--ai-msg);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* 商品卡片网格 */
.items-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

@media (max-width: 400px) {
  .items-grid {
    grid-template-columns: 1fr;
  }
}

/* 紧凑商品卡片 */
.item-card {
  background: #F8F8F8;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  border-left: 3px solid #CCCCCC; /* 默认灰色 */
}

/* 匹配货品清单 - 绿色边框 */
.item-card.matched {
  border-left-color: var(--primary);
  background: #F0FFF4;
}

/* 未匹配货品清单 - 红色边框 */
.item-card.unmatched {
  border-left-color: var(--danger);
  background: #FFF2F0;
}

.item-main {
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

.item-main .name {
  color: var(--text);
}

.item-main .qty {
  color: var(--primary);
  font-weight: 600;
}

.item-main .unit {
  color: var(--text-light);
  font-size: 12px;
}

.item-note {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px dashed #E0E0E0;
}

/* 底部输入栏 */
.input-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 100;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 800px;
  margin: 0 auto;
}

.chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 15px;
  resize: none;
  max-height: 100px;
  outline: none;
  font-family: inherit;
}

.chat-input:focus {
  border-color: var(--primary);
}

.send-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

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

/* =============== 侧边抽屉菜单 =============== */

.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s;
}

.drawer-overlay.show {
  opacity: 1;
}

.side-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 280px;
  max-width: 80vw;
  background: var(--card-bg);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 16px rgba(0,0,0,0.1);
}

.side-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  padding: 20px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 48px;
  height: 48px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.user-details {
  display: flex;
  flex-direction: column;
}

.nickname {
  font-size: 16px;
  font-weight: 600;
}

.role {
  font-size: 12px;
  opacity: 0.8;
}

.close-btn {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.drawer-section h3 {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.new-form-btn {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.new-form-btn span {
  font-size: 18px;
}

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

.form-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

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

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

.form-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.form-item-title {
  font-weight: 500;
  font-size: 14px;
}

.form-item-count {
  font-size: 12px;
  color: var(--text-light);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 10px;
}

.form-item-meta {
  font-size: 12px;
  color: var(--text-light);
}

.form-item-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  background: var(--danger);
  color: white;
  border-radius: 50%;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}

.form-item:hover .form-item-delete {
  opacity: 1;
}

.drawer-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-link {
  padding: 12px;
  background: #F0F0F0;
  color: var(--text);
  text-decoration: none;
  border-radius: 8px;
  text-align: center;
  font-size: 14px;
}

.admin-link:hover {
  background: #E8E8E8;
}

.logout-btn {
  padding: 12px;
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

.logout-btn:hover {
  background: #FFF2F0;
}

/* =============== 通用组件 =============== */

.loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 300;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 400;
}

.hidden {
  display: none !important;
}

/* 已录入提示 */
.saved-hint {
  text-align: center;
  padding: 8px;
  margin-top: 8px;
  background: rgba(7, 193, 96, 0.1);
  border-radius: 6px;
  font-size: 12px;
  color: var(--primary);
}

/* 确认对话框 */
.confirm-dialog {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.confirm-dialog-content {
  background: white;
  padding: 24px;
  border-radius: 12px;
  width: 90%;
  max-width: 320px;
  text-align: center;
}

.confirm-dialog-content h3 {
  margin-bottom: 12px;
}

.confirm-dialog-content p {
  color: var(--text-light);
  margin-bottom: 20px;
}

.confirm-dialog-buttons {
  display: flex;
  gap: 12px;
}

.confirm-dialog-buttons button {
  flex: 1;
  padding: 10px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
}

.btn-cancel {
  background: var(--bg);
  color: var(--text);
}

.btn-confirm {
  background: var(--danger);
  color: white;
}
