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

/* SVG 圖示 */
.icon {
  width: 20px;
  height: 20px;
  vertical-align: middle;
  display: inline-block;
  flex-shrink: 0;
}

.icon-lg {
  width: 36px;
  height: 36px;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

.stat-icon {
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
  color: #667eea;
}


body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f7fa;
  color: #333;
}

.hidden { display: none !important; }

/* 登入畫面 */
.login-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
  background: white;
  padding: 40px;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  width: 360px;
}

.login-box h1 { font-size: 28px; margin-bottom: 8px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.login-box p { color: #666; margin-bottom: 24px; }

.login-box input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e1e5eb;
  border-radius: 8px;
  font-size: 16px;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.login-box input:focus { border-color: #667eea; }

.login-box button {
  width: 100%;
  padding: 12px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.login-box button:hover { background: #5a6fd6; }

/* 導航列 */
nav {
  background: white;
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 60px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand { font-size: 18px; font-weight: 700; margin-right: 40px; display: flex; align-items: center; gap: 8px; }

.nav-links { display: flex; gap: 4px; flex: 1; }

.nav-link {
  padding: 8px 16px;
  text-decoration: none;
  color: #666;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-link:hover { background: #f0f2f5; color: #333; }
.nav-link.active { background: #667eea; color: white; }

.btn-logout {
  padding: 8px 16px;
  background: none;
  border: 1px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  color: #666;
  font-size: 14px;
}

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

/* 頁籤內容 */
.tab-content { display: none; padding: 24px; max-width: 1200px; margin: 0 auto; }
.tab-content.active { display: block; }

/* 主容器用 flex 填滿視窗 */
#mainApp {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
#mainApp > nav { flex-shrink: 0; }
#mainApp > .merchant-bar { flex-shrink: 0; }

/* 非 logs 的 tab 正常捲動 */
.tab-content.active:not(#tab-logs) {
  flex: 1;
  overflow-y: auto;
  width: 100%;
  min-height: 0;
}

/* logs tab 全寬，用 flex 填滿剩餘空間 */
#tab-logs.active {
  max-width: none;
  margin: 0;
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  padding-bottom: 0;
}
#tab-logs h2 { flex-shrink: 0; margin-bottom: 12px; }

.tab-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }

h2 { font-size: 24px; margin-bottom: 20px; }

/* 商戶上下文列 */
.merchant-bar {
  background: #eef0ff;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 500;
  color: #667eea;
  border-bottom: 1px solid #dde0ff;
}

.btn-sm { padding: 5px 12px; font-size: 12px; }

.status-badge {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.status-active { background: #e8f5e9; color: #2e7d32; }
.status-inactive { background: #fce4ec; color: #c62828; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.form-panel h4 {
  margin: 20px 0 12px;
  padding-top: 16px;
  border-top: 1px solid #eee;
  font-size: 14px;
  color: #667eea;
}

code {
  background: #f0f2f5;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

/* 測試結果 */
.test-results {
  margin-top: 16px;
  border: 1px solid #e1e5eb;
  border-radius: 8px;
  overflow: hidden;
}

.test-item {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #f0f2f5;
  font-size: 14px;
}

.test-item:last-child { border-bottom: none; }

.test-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.test-ok { background: #e8f5e9; color: #2e7d32; }
.test-error { background: #ffebee; color: #c62828; }
.test-skip { background: #fff3e0; color: #e65100; }
.test-info { background: #e3f2fd; color: #1565c0; }

.test-name { font-weight: 600; min-width: 160px; }
.test-detail { color: #555; word-break: break-all; }

/* 統計卡片 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.stat-card {
  background: white;
  padding: 24px;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.stat-number { font-size: 36px; font-weight: 700; color: #667eea; }
.stat-label { color: #888; margin-top: 8px; font-size: 14px; }

/* 按鈕 */
.btn-primary {
  padding: 10px 20px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s;
}

.btn-primary:hover { background: #5a6fd6; }

.btn-secondary {
  padding: 10px 20px;
  background: white;
  color: #333;
  border: 1px solid #ddd;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.btn-secondary:hover { background: #f5f5f5; }

.btn-danger {
  padding: 6px 12px;
  background: #ff4757;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.btn-danger:hover { background: #e8384f; }

.btn-edit {
  padding: 6px 12px;
  background: #ffa502;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  margin-right: 4px;
}

.btn-edit:hover { background: #e69500; }

/* 表單 */
.form-panel {
  background: white;
  padding: 24px;
  border-radius: 12px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.form-panel h3 { margin-bottom: 16px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 14px; }

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #e1e5eb;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus { border-color: #667eea; }

.form-actions { display: flex; gap: 12px; }

/* 表格 */
.table-container {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

table { width: 100%; border-collapse: collapse; }

th {
  background: #f8f9fa;
  padding: 12px 16px;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: #666;
  border-bottom: 2px solid #e1e5eb;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid #f0f2f5;
  font-size: 14px;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

tr:hover { background: #fafbfc; }

/* 篩選列 */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.filter-bar select,
.filter-bar input {
  padding: 10px 14px;
  border: 2px solid #e1e5eb;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}

.filter-bar select { min-width: 140px; }
.filter-bar input { flex: 1; }

/* 分頁 */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 20px;
}

/* 管道標籤 */
.channel-badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.channel-facebook { background: #e3f2fd; color: #1877f2; }
.channel-line { background: #e8f5e9; color: #06c755; }

.category-badge {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  background: #f0f0f5;
  color: #555;
}

.source-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  margin-left: 4px;
  vertical-align: middle;
}

.source-gdrive {
  background: #e8f0fe;
  color: #1a73e8;
}

/* 按鈕群組 */
.tab-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tab-header-actions .btn-secondary,
.tab-header-actions a.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  font-size: 14px;
}

/* 匯入面板 */
.form-hint {
  color: #888;
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.5;
}

.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #e1e5eb;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
  background: white;
  transition: border-color 0.2s;
}

.form-group select:focus { border-color: #667eea; }

.import-result {
  margin-top: 16px;
  padding: 14px 18px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.6;
}

.import-result.success {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #c8e6c9;
}

.import-result.error {
  background: #ffebee;
  color: #c62828;
  border: 1px solid #ffcdd2;
}

/* 分類統計 */
.category-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.category-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: white;
  border-radius: 20px;
  font-size: 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
}

.category-tag:hover { border-color: #667eea; }

.category-tag .tag-count {
  background: #667eea;
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
}

.category-tag.uncategorized { color: #999; }

/* 批次操作列 */
.batch-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.batch-actions span {
  font-size: 14px;
  font-weight: 500;
  color: #667eea;
}

.batch-actions select {
  padding: 8px 12px;
  border: 2px solid #e1e5eb;
  border-radius: 8px;
  font-size: 13px;
  outline: none;
}

/* 載入動畫 */
.loading {
  text-align: center;
  padding: 40px;
  color: #888;
}

/* === 對話紀錄 - 聊天介面 === */
.chat-layout {
  display: flex;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-sidebar {
  width: 300px;
  min-width: 300px;
  border-right: 1px solid #e1e5eb;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 12px;
  border-bottom: 1px solid #e1e5eb;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-header select,
.sidebar-header input {
  padding: 8px 12px;
  border: 2px solid #e1e5eb;
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  width: 100%;
}

.sidebar-header select:focus,
.sidebar-header input:focus { border-color: #667eea; }

.user-list {
  flex: 1;
  overflow-y: auto;
}

.user-list-empty {
  text-align: center;
  color: #999;
  padding: 32px 16px;
  font-size: 14px;
}

.user-item {
  padding: 14px 16px;
  border-bottom: 1px solid #f0f2f5;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user-item:hover { background: #f8f9fa; }
.user-item.active { background: #eef0ff; border-left: 3px solid #667eea; }

.user-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.user-item-id {
  font-size: 13px;
  font-weight: 600;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

.user-item-time {
  font-size: 11px;
  color: #999;
  white-space: nowrap;
}

.user-item-subid {
  font-size: 11px;
  color: #aaa;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-off-badge {
  background: #e53935 !important;
  color: #fff !important;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  margin-right: 4px;
}

.user-item-phone {
  font-size: 11px;
  color: #4a9eff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-item-preview {
  font-size: 12px;
  color: #888;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-item-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  margin-right: 4px;
}

/* 右側聊天區 */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.chat-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #bbb;
  gap: 12px;
}

.chat-placeholder svg { width: 48px; height: 48px; }

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

.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid #e1e5eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-chat-back {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: #667eea;
}

.chat-msg-count {
  font-size: 13px;
  color: #999;
}

.chat-messages {
  flex: 1;
  overflow-y: scroll;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  -webkit-overflow-scrolling: touch;
}

/* 捲軸樣式 */
.chat-messages::-webkit-scrollbar,
.user-list::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-track,
.user-list::-webkit-scrollbar-track {
  background: #f0f2f5;
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb,
.user-list::-webkit-scrollbar-thumb {
  background: #b0b8c4;
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.user-list::-webkit-scrollbar-thumb:hover {
  background: #8a94a3;
}

.msg-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg-time {
  font-size: 11px;
  color: #999;
  text-align: center;
  margin: 8px 0;
}

.msg-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

/* Markdown 內容樣式 */
.msg-bubble ul {
  margin: 4px 0;
  padding-left: 20px;
  white-space: normal;
}

.msg-bubble li {
  margin-bottom: 2px;
}

.msg-bubble strong {
  font-weight: 700;
}

.msg-bubble code {
  background: rgba(0,0,0,0.1);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 13px;
}

.msg-user {
  align-self: flex-start;
  background: #f0f2f5;
  color: #333;
  border-bottom-left-radius: 4px;
}

.msg-bot {
  align-self: flex-end;
  background: #667eea;
  color: white;
  border-bottom-right-radius: 4px;
}

.msg-staff {
  align-self: flex-end;
  background: #06c755;
  color: white;
  border-bottom-right-radius: 4px;
}

.msg-label {
  font-size: 11px;
  color: #999;
  margin-bottom: 2px;
}

.msg-label-right {
  text-align: right;
}

/* 用戶個資面板 */
.chat-header-actions-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-ai-toggle {
  background: #e8f5e9;
  border: 1px solid #4caf50;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  color: #2e7d32;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-ai-toggle.ai-off {
  background: #fbe9e7;
  border-color: #e53935;
  color: #c62828;
}

.btn-ai-toggle:hover { opacity: 0.85; }

.ai-reply-warning {
  background: #fdecea;
  border: 1px solid #e53935;
  color: #c62828;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.5;
  flex-shrink: 0;
}

.btn-profile-toggle {
  background: none;
  border: 1px solid #e1e5eb;
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
  color: #666;
  display: flex;
  align-items: center;
  transition: all 0.2s;
}

.btn-profile-toggle:hover { background: #f0f2f5; color: #667eea; }

.profile-name-tag {
  font-size: 13px;
  color: #667eea;
  font-weight: 600;
  margin-left: 4px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-panel {
  padding: 12px 20px;
  background: #f8f9fb;
  border-bottom: 1px solid #e1e5eb;
  flex-shrink: 0;
}

.profile-grid {
  display: grid;
  grid-template-columns: 50px 1fr 50px 1fr;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.profile-grid label {
  font-weight: 600;
  color: #555;
  white-space: nowrap;
}

.profile-grid input {
  padding: 5px 10px;
  border: 1px solid #dde0e7;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.profile-grid input:focus, .profile-grid textarea:focus { border-color: #667eea; }

.profile-notes-row {
  margin-top: 8px;
}

.profile-notes-row label {
  font-weight: 600;
  color: #555;
  font-size: 13px;
  display: block;
  margin-bottom: 4px;
}

.profile-notes-row textarea {
  width: 100%;
  padding: 5px 10px;
  border: 1px solid #dde0e7;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  resize: vertical;
  min-height: 48px;
  box-sizing: border-box;
}

.profile-notes-row textarea:focus { border-color: #667eea; }

.profile-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.profile-save-status {
  font-size: 12px;
  color: #2e7d32;
}

/* 回覆輸入區 */
.chat-reply-bar {
  padding: 12px 20px;
  border-top: 1px solid #e1e5eb;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
}

.chat-reply-bar textarea {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid #e1e5eb;
  border-radius: 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: none;
  transition: border-color 0.2s;
}

.chat-reply-bar textarea:focus { border-color: #667eea; }

.btn-send {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  white-space: nowrap;
}

/* 客戶標籤 */
.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  background: #e8f0fe;
  color: #1a73e8;
  margin: 1px 2px;
  white-space: nowrap;
}

.tag-pill .tag-remove {
  cursor: pointer;
  font-size: 13px;
  color: #999;
  margin-left: 2px;
}
.tag-pill .tag-remove:hover { color: #e53935; }

.tag-pill.tag-ai { background: #f3e8fd; color: #7c3aed; }
.tag-pill.tag-manual { background: #e8f5e9; color: #2e7d32; }

.tag-add-btn {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 11px;
  background: #f0f2f5;
  color: #667eea;
  cursor: pointer;
  border: 1px dashed #ccc;
}
.tag-add-btn:hover { background: #e8eaff; }

/* 通知觸發設定 */
.trigger-settings {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.trigger-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.trigger-label { flex: 1; font-size: 14px; font-weight: 500; }
.trigger-desc { font-size: 12px; color: #888; margin-top: 2px; }

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #ccc;
  border-radius: 24px;
  transition: 0.3s;
}
.toggle-switch .slider:before {
  content: "";
  position: absolute;
  height: 18px; width: 18px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}
.toggle-switch input:checked + .slider { background: #667eea; }
.toggle-switch input:checked + .slider:before { transform: translateX(20px); }

.trigger-keywords {
  margin-top: 6px;
  display: flex;
  gap: 6px;
  align-items: center;
}
.trigger-keywords input {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid #dde0e7;
  border-radius: 6px;
  font-size: 12px;
  outline: none;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
}

.modal-box {
  background: white;
  border-radius: 12px;
  padding: 28px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-box h3 { margin-bottom: 16px; }

/* ===== 手機版優化 ===== */
@media (max-width: 768px) {
  /* 導航列 */
  nav { padding: 0 12px; height: 50px; }
  .nav-brand { font-size: 14px; margin-right: 12px; }
  .nav-brand span { display: none; }
  .nav-links { gap: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .nav-link { padding: 6px 10px; font-size: 12px; white-space: nowrap; }
  .nav-link .icon-sm { display: none; }
  .btn-logout { padding: 6px 10px; font-size: 12px; }

  /* 商戶列 */
  .merchant-bar { padding: 8px 12px; font-size: 12px; flex-wrap: wrap; gap: 6px; }

  /* 頁籤內容 */
  .tab-content { padding: 12px; }

  /* 標題列 */
  .tab-header { flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 12px; }
  .tab-header h2 { font-size: 20px; margin-bottom: 0; }
  .tab-header-actions { flex-wrap: wrap; gap: 6px; width: 100%; }
  .tab-header-actions .btn-secondary,
  .tab-header-actions .btn-primary { font-size: 12px; padding: 8px 12px; }

  /* 統計卡片 */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 16px; }
  .stat-number { font-size: 28px; }

  /* 表格 */
  .table-container { overflow-x: auto; }
  table { min-width: 500px; }
  th, td { padding: 8px 10px; font-size: 13px; }
  td { max-width: 150px; }

  /* 表單 */
  .form-panel { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .form-actions { flex-wrap: wrap; }

  /* 篩選列 */
  .filter-bar { flex-wrap: wrap; }
  .filter-bar select, .filter-bar input { font-size: 13px; }

  /* 知識庫分類標籤 */
  .category-stats { gap: 6px; }
  .category-tag { padding: 6px 12px; font-size: 12px; }

  /* 客戶資料表格 */
  .table-wrapper { overflow-x: auto; }

  /* ===== 對話紀錄 ===== */
  #tab-logs.active { padding: 0; }

  /* 對話紀錄標題列 */
  #tab-logs > div:first-child { padding: 12px; margin-bottom: 0 !important; }
  #tab-logs > div:first-child h2 { font-size: 18px; }

  /* 聊天佈局：手機用全屏切換 */
  .chat-layout { flex-direction: column; }
  .chat-sidebar {
    width: 100%;
    min-width: auto;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid #e1e5eb;
  }
  .chat-main { min-height: 0; }

  /* 手機版：選中用戶後隱藏側邊欄，顯示聊天 */
  .chat-layout.chat-active .chat-sidebar { display: none; }
  .chat-layout.chat-active .chat-main { flex: 1; }
  .chat-layout:not(.chat-active) .chat-main { display: none; }
  .chat-layout:not(.chat-active) .chat-sidebar { flex: 1; max-height: none; overflow: hidden; }
  .chat-layout:not(.chat-active) .chat-sidebar .user-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* 聊天頭部 */
  .chat-header { padding: 10px 12px; flex-wrap: wrap; gap: 6px; }
  .chat-header-info { font-size: 13px; }
  .chat-header-actions-area { gap: 6px; }
  .chat-msg-count { font-size: 11px; }

  /* 聊天訊息 */
  .chat-messages { padding: 12px; gap: 10px; }
  .msg-bubble { max-width: 88%; font-size: 14px; padding: 8px 12px; }

  /* 回覆列 */
  .chat-reply-bar { padding: 8px 12px; }
  .chat-reply-bar textarea { font-size: 14px; }
  .btn-send { padding: 8px 14px; font-size: 13px; }
  .btn-send .icon-sm { display: none; }

  /* AI 警告 */
  .ai-reply-warning { font-size: 12px; padding: 6px 10px; }

  /* 用戶個資面板 */
  .profile-panel { padding: 10px 12px; }
  .profile-grid { grid-template-columns: 40px 1fr; gap: 6px; }
  .profile-grid label { font-size: 12px; }
  .profile-grid input { font-size: 12px; padding: 4px 8px; }

  /* 返回按鈕 */
  .btn-chat-back { display: block; }

  /* 登入畫面 */
  .login-box { width: 90%; padding: 28px 24px; }
  .login-box h1 { font-size: 22px; }
}
