/* ============================================
   侨e心管理后台 — 共享样式
   ============================================ */

/* ---- Design Tokens ---- */
:root {
  --color-primary: #773B4B;
  --color-primary-hover: #5E2E3A;
  --color-primary-soft: #F4EBED;
  --color-danger: #EF4444;
  --color-danger-hover: #DC2626;
  --color-warning: #D97706;
  --color-warning-soft: #FEF3C7;
  --color-success: #10B981;
  --color-success-soft: #D1FAE5;
  --color-bg: #F7F8FC;
  --color-surface: #FFFFFF;
  --color-border: #E6E9F0;
  --color-text: #1E293B;
  --color-text-muted: #64748B;
  --color-text-subtle: #94A3B8;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-card: 0 4px 20px rgba(119, 59, 75, 0.05), 0 1px 3px rgba(0,0,0,0.03);
  --shadow-modal: 0 20px 60px rgba(30, 41, 59, 0.18);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --header-h-compact: 56px; /* 客服面板 compact header 实际高度，layout 高度计算依赖此值 */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

/* ---- Reset ---- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ---- Base ---- */
body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
}

/* ---- Header ---- */
.header {
  background: linear-gradient(135deg, #773B4B 0%, #86515C 100%);
  color: white;
  padding: var(--space-4) var(--space-6);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  box-shadow: 0 4px 16px rgba(119, 59, 75, 0.2);
}
/* compact 模式：锁定高度，使客服面板 layout 的 calc(100vh - var(--header-h-compact)) 精确对齐，零溢出 */
.header.header-compact {
  height: var(--header-h-compact);
  padding: 10px 20px;
  flex-wrap: nowrap;
}
.header h1 { font-size: 20px; font-weight: 600; white-space: nowrap; }
.header-left { display: flex; align-items: center; gap: var(--space-3); }
.header-left .subtitle { font-size: 13px; opacity: 0.85; }

/* ---- Navigation ---- */
.nav { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.nav a, .nav button {
  color: white; text-decoration: none; padding: 6px 14px; border-radius: var(--radius-sm);
  font-size: 13px; border: none; cursor: pointer; background: rgba(255,255,255,0.15);
  transition: background 0.2s;
}
.nav a:hover, .nav button:hover { background: rgba(255,255,255,0.25); }
.nav a.active { background: rgba(255,255,255,0.35); font-weight: 600; }
.nav .nav-sep { width: 1px; height: 20px; background: rgba(255,255,255,0.2); margin: 0 var(--space-1); }
.nav .btn-logout { background: rgba(255,255,255,0.2); border: 1px solid rgba(255,255,255,0.3); }

/* 移动端导航折叠按钮（默认隐藏） */
.nav-toggle {
  display: none;
  background: none; border: none; color: white; font-size: 22px;
  cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm);
}

/* ---- Container ---- */
.container { max-width: 1400px; margin: var(--space-5) auto; padding: 0 20px; }

/* ---- Card ---- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--color-border);
  margin-bottom: 20px;
}
.card-header {
  padding: 18px var(--space-5);
  border-bottom: 1px solid var(--color-border);
  display: flex; justify-content: space-between; align-items: center;
}
.card-header h2 { font-size: 16px; font-weight: 600; }
.card-body { padding: var(--space-5); }

/* ---- Stats ---- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}
.stat-card {
  background: var(--color-surface);
  padding: 22px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--color-border);
}
.stat-card h3 { font-size: 13px; color: var(--color-text-muted); margin-bottom: var(--space-2); }
.stat-card .number { font-size: 30px; font-weight: 700; color: var(--color-primary); }

/* ---- Tabs ---- */
.tabs {
  display: flex; gap: var(--space-2); margin-bottom: 20px;
  background: var(--color-surface);
  padding: 6px;
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}
.tab-item {
  padding: 10px 22px; border-radius: var(--radius-md); cursor: pointer;
  font-size: 14px; font-weight: 500; transition: all 0.2s;
  border: none; background: transparent; color: #374151;
}
.tab-item:hover { background: #f3f4f6; }
.tab-item.active { background: var(--color-primary); color: white; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---- Table ---- */
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--color-bg);
  position: sticky; top: 0; z-index: 5;
}
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--color-border); }
th { font-weight: 600; font-size: 13px; color: var(--color-text-muted); }
td { font-size: 13px; }
tbody tr:hover { background: #f9fafb; }

/* 表格横向滚动包裹 */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---- Buttons ---- */
.btn {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  border: none; cursor: pointer; font-size: 13px; transition: all 0.2s;
  display: inline-flex; align-items: center; gap: 4px;
}
.btn-primary { background: var(--color-primary); color: white; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: #f3f4f6; color: #374151; border: 1px solid #dce0e8; }
.btn-secondary:hover { background: #e5e7eb; }
.btn-danger { background: var(--color-danger); color: white; }
.btn-danger:hover { background: var(--color-danger-hover); }
.btn-sm { padding: 5px 10px; font-size: 12px; margin: 0 3px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge-pending { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-reviewing { background: #dbeafe; color: #1e3a8a; }
.badge-approved, .badge-completed { background: #d1fae5; color: #065f46; }
.badge-rejected { background: #fee2e2; color: #991b1b; }
.badge-signed { background: var(--color-primary-soft); color: var(--color-primary); }
.badge-draft { background: #f3f4f6; color: #6b7280; }

/* 会话列表小型徽章 */
.badge-sm { padding: 1px 6px; border-radius: 999px; font-size: 10px; font-weight: 600; }
.badge-unread { background: var(--color-danger); color: #fff; }
.badge-ai { background: var(--color-primary-soft); color: var(--color-primary); }
.badge-human { background: var(--color-warning-soft); color: var(--color-warning); }

/* ---- Form ---- */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13px; color: #374151; }
.form-group input, .form-group textarea, .form-group select {
  width: 100%; padding: 9px var(--space-3); border: 1px solid #d1d5db; border-radius: var(--radius-sm);
  font-size: 14px; outline: none; transition: border-color 0.2s;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(20,125,127,0.1);
}
.form-group textarea { min-height: 100px; resize: vertical; }

/* ---- Filter Bar ---- */
.filter-bar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-bar select, .filter-bar input {
  padding: var(--space-2) var(--space-3); border: 1px solid #d1d5db;
  border-radius: var(--radius-sm); font-size: 13px; outline: none;
}
.filter-bar input:focus, .filter-bar select:focus { border-color: var(--color-primary); }

/* ---- Modal ---- */
.modal {
  display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45); z-index: 1000; align-items: center; justify-content: center;
}
.modal.active { display: flex; }
.modal-content {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  max-width: 600px; width: 92%; max-height: 85vh; overflow-y: auto;
  box-shadow: var(--shadow-modal);
}
.modal-header {
  padding: 20px var(--space-5);
  border-bottom: 1px solid var(--color-border);
  font-size: 16px; font-weight: 600;
}
.modal-body { padding: var(--space-5); }
.modal-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ---- Detail Grid ---- */
.detail-row {
  display: grid; grid-template-columns: 120px 1fr;
  padding: 11px 0; border-bottom: 1px solid #f3f4f6;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { font-weight: 500; color: var(--color-text-muted); font-size: 13px; }
.detail-value { color: var(--color-text); font-size: 13px; }

/* ---- Image Preview ---- */
.image-preview { max-width: 200px; max-height: 150px; margin-top: 10px; border-radius: var(--radius-md); border: 1px solid var(--color-border); }

/* ---- Utility ---- */
.empty { text-align: center; padding: 60px 20px; color: var(--color-text-subtle); font-size: 14px; }
.empty-icon { font-size: 40px; display: block; margin-bottom: var(--space-3); opacity: 0.5; }
.loading { text-align: center; padding: 40px; color: var(--color-text-muted); }

/* ---- Skeleton (骨架屏) ---- */
.skeleton { background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius-sm); }
.skeleton-row { height: 40px; margin-bottom: var(--space-2); }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---- Toast ---- */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: var(--space-2); }
.toast {
  padding: 12px 20px; border-radius: var(--radius-md); font-size: 14px;
  color: white; box-shadow: var(--shadow-modal);
  animation: toastIn 0.3s ease-out;
  max-width: 360px;
  display: flex; align-items: center; gap: var(--space-2);
}
.toast-success { background: #059669; }
.toast-error { background: var(--color-danger); }
.toast-info { background: var(--color-primary); }
.toast-removing { animation: toastOut 0.3s ease-in forwards; }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }

/* ---- Confirm Dialog ---- */
.confirm-overlay {
  display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45); z-index: 2000; align-items: center; justify-content: center;
}
.confirm-overlay.active { display: flex; }
.confirm-box {
  background: var(--color-surface); border-radius: var(--radius-lg); padding: var(--space-5);
  width: 380px; max-width: 90%; box-shadow: var(--shadow-modal);
}
.confirm-box h3 { font-size: 16px; font-weight: 600; margin-bottom: var(--space-3); }
.confirm-box p { font-size: 14px; color: var(--color-text-muted); margin-bottom: var(--space-5); }
.confirm-buttons { display: flex; justify-content: flex-end; gap: var(--space-2); }

/* ---- Login Overlay ---- */
.login-overlay {
  display: flex; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6); z-index: 9999; align-items: center; justify-content: center;
}
.login-overlay.hidden { display: none; }
.login-box {
  background: var(--color-surface); border-radius: var(--radius-xl); padding: 40px 36px;
  width: 380px; max-width: 90%; box-shadow: var(--shadow-modal);
  text-align: center;
}
.login-box h2 { color: var(--color-primary); font-size: 22px; margin-bottom: 6px; }
.login-box .subtitle { color: var(--color-text-subtle); font-size: 13px; margin-bottom: var(--space-5); }
.login-box .form-group { text-align: left; }
.login-error { color: var(--color-danger); font-size: 13px; margin-top: 10px; display: none; }
.login-error.show { display: block; }
.btn-login {
  width: 100%; padding: var(--space-3); background: var(--color-primary); color: white;
  border: none; border-radius: var(--radius-md); font-size: 16px; font-weight: 600; cursor: pointer;
  margin-top: 6px; transition: background 0.2s;
}
.btn-login:hover { background: var(--color-primary-hover); }
.btn-login:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---- Upload Status ---- */
.upload-status { font-size: 12px; color: var(--color-primary); margin-top: var(--space-1); display: none; }

/* ---- Chat Mode Tags ---- */
.mode-tag { padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.mode-ai { background: var(--color-primary-soft); color: var(--color-primary); }
.mode-human { background: var(--color-warning-soft); color: var(--color-warning); }

/* ---- AI Tag (message marker) ---- */
.tag-ai {
  background: rgba(20,125,127,0.15); color: var(--color-primary);
  padding: 1px 6px; border-radius: var(--radius-sm); font-size: 10px; font-weight: 600;
}

/* ============================================
   响应式
   ============================================ */
@media (max-width: 768px) {
  /* 导航：折叠菜单 */
  .nav-toggle { display: block; }
  .nav { display: none; flex-direction: column; width: 100%; gap: 4px; padding-top: var(--space-2); }
  .nav.open { display: flex; }
  .nav .nav-sep { display: none; }
  .nav a, .nav button { width: 100%; text-align: left; }
  .header { flex-direction: column; align-items: flex-start; }

  /* 统计单列 */
  .stats { grid-template-columns: 1fr; }

  /* 表格可横向滚动 */
  table { min-width: 600px; }
  .table-wrap { display: block; }

  /* Modal 全宽 */
  .modal-content { width: 96%; max-height: 90vh; border-radius: var(--radius-md); }

  /* 筛选栏纵向 */
  .filter-bar { flex-direction: column; }

  /* Login 框边距收紧 */
  .login-box { padding: 28px 20px; }

  /* Confirm 弹窗 */
  .confirm-box { width: 92%; }
}
