/* ===== VARIABLES ===== */
:root {
  --primary: #667eea;
  --primary-dark: #5a6fd6;
  --primary-light: #eef0fd;
  --secondary: #764ba2;
  --success: #48bb78;
  --warning: #ed8936;
  --danger: #f56565;
  --info: #4299e1;
  --sidebar-w: 220px;
  --sidebar-bg: #1e2139;
  --sidebar-hover: #2d3561;
  --sidebar-active: #667eea;
  --bg: #f0f2f8;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #2d3748;
  --text-muted: #718096;
  --shadow: 0 2px 8px rgba(0,0,0,0.07);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius: 8px;
  --radius-sm: 5px;
  --t: 0.18s ease;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; font-family: inherit; font-size: 14px; border: none; outline: none; }
input, select, textarea { font-family: inherit; font-size: 14px; }
table { border-collapse: collapse; width: 100%; }

/* ===== LOGIN ===== */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}
.login-card {
  background: white;
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { font-size: 22px; color: var(--primary); font-weight: 700; margin-top: 8px; }
.login-logo p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.login-logo .logo-icon { font-size: 40px; }
.login-card .form-group { margin-bottom: 16px; }
.login-card label { display: block; font-weight: 500; margin-bottom: 6px; color: var(--text); }
.login-card input { width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); transition: border-color var(--t); }
.login-card input:focus { border-color: var(--primary); outline: none; }
.login-hint { background: #f8f9ff; border-radius: 6px; padding: 12px; margin-top: 16px; font-size: 12px; color: var(--text-muted); line-height: 1.8; }
.login-hint strong { display: block; margin-bottom: 4px; color: var(--text); }
.login-error { color: var(--danger); font-size: 13px; margin-bottom: 12px; text-align: center; min-height: 18px; }

/* ===== APP LAYOUT ===== */
.app-layout { display: flex; height: 100vh; overflow: hidden; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar-brand {
  padding: 20px 16px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.sidebar-brand .brand-icon { font-size: 22px; }
.sidebar-brand .brand-name { font-size: 15px; font-weight: 700; color: #fff; letter-spacing: 0.3px; }
.sidebar-user {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: white; font-weight: 600;
  flex-shrink: 0;
}
.user-info { overflow: hidden; }
.user-name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role-badge { font-size: 11px; color: rgba(255,255,255,0.55); margin-top: 1px; }
.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-section { padding: 12px 16px 4px; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: rgba(255,255,255,0.3); font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  transition: all var(--t);
  border-left: 3px solid transparent;
  font-size: 13.5px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: rgba(102,126,234,0.15); color: var(--primary); border-left-color: var(--primary); }
.nav-item .nav-icon { font-size: 16px; flex-shrink: 0; }
.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,255,255,0.07); }
.btn-logout {
  width: 100%; padding: 8px; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.07); color: rgba(255,255,255,0.6);
  font-size: 13px; transition: all var(--t);
}
.btn-logout:hover { background: rgba(245,101,101,0.2); color: #fc8181; }

/* ===== MAIN CONTENT ===== */
.main-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.page-header {
  padding: 20px 24px 0;
  display: flex; align-items: center; justify-content: space-between;
}
.page-header h2 { font-size: 20px; font-weight: 700; color: var(--text); }
.page-body { padding: 16px 24px 24px; flex: 1; }
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.breadcrumb a { color: var(--primary); cursor: pointer; }
.breadcrumb-sep { color: var(--border); }

/* ===== STATS CARDS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--card); border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 14px;
}
.stat-icon { font-size: 28px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text); line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat-card.primary .stat-value { color: var(--primary); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.info .stat-value { color: var(--info); }

/* ===== CARDS ===== */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 16px 20px; }
.card-body.no-pad { padding: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ===== TABLE ===== */
.table-wrapper { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  background: #f8f9fc; padding: 10px 14px;
  text-align: left; font-size: 12px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.5px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td { padding: 11px 14px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafbff; }
.table-actions { display: flex; gap: 6px; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500;
  transition: all var(--t); cursor: pointer;
  border: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #38a169; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #e53e3e; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #dd6b20; }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--text-muted); padding: 6px 10px; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; font-size: 15px; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-weight: 500; font-size: 13px; margin-bottom: 5px; color: var(--text); }
.form-group label .required { color: var(--danger); margin-left: 2px; }
.form-control {
  width: 100%; padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--t);
  background: #fff;
  color: var(--text);
}
.form-control:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(102,126,234,0.12); }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 100px;
  font-size: 11px; font-weight: 600;
  white-space: nowrap;
}
.badge-primary { background: #eef0fd; color: var(--primary); }
.badge-success { background: #f0fff4; color: #276749; }
.badge-warning { background: #fffaf0; color: #c05621; }
.badge-danger { background: #fff5f5; color: #c53030; }
.badge-info { background: #ebf8ff; color: #2b6cb0; }
.badge-gray { background: #edf2f7; color: var(--text-muted); }
.badge-s { background: #ebf8ff; color: #2b6cb0; }
.badge-p { background: #fffaf0; color: #c05621; }
.badge-i { background: #fff5f5; color: #c53030; }
.badge-n { background: #f0fff4; color: #276749; }
.spin-dist { display: flex; gap: 6px; flex-wrap: wrap; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  width: 100%; max-width: 520px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.18s ease;
}
.modal-box.modal-lg { max-width: 720px; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(-8px); } to { opacity: 1; transform: none; } }
.modal-header { padding: 18px 20px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--text-muted); cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  padding: 12px 18px; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; color: #fff;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  transform: translateY(80px); opacity: 0;
  transition: all 0.25s ease;
  max-width: 320px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: #276749; }
.toast.error { background: #c53030; }
.toast.info { background: #2b6cb0; }

/* ===== LOADING ===== */
.spinner { display: inline-block; width: 18px; height: 18px; border: 2.5px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.7s linear infinite; }
.spinner-lg { width: 36px; height: 36px; border-width: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px; color: var(--text-muted); gap: 14px; }

/* ===== FILTERS / SEARCH BAR ===== */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search-input { padding: 7px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); min-width: 200px; }
.search-input:focus { border-color: var(--primary); outline: none; }
.filter-group { display: flex; gap: 4px; }
.filter-btn { padding: 6px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: #fff; color: var(--text-muted); font-size: 12px; cursor: pointer; transition: all var(--t); }
.filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ===== CHAT / AI COACH ===== */
.chat-layout { display: grid; grid-template-columns: 1fr; height: calc(100vh - 140px); min-height: 500px; }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  background: #f8f9fc;
  border-radius: var(--radius) var(--radius) 0 0;
  min-height: 300px; max-height: 500px;
  border: 1px solid var(--border);
}
.chat-msg { max-width: 80%; word-wrap: break-word; }
.chat-msg.user { align-self: flex-end; }
.chat-msg.assistant { align-self: flex-start; }
.chat-bubble {
  padding: 10px 14px; border-radius: 12px;
  line-height: 1.6; font-size: 13.5px;
}
.chat-msg.user .chat-bubble { background: var(--primary); color: #fff; border-radius: 12px 12px 2px 12px; }
.chat-msg.assistant .chat-bubble { background: #fff; border: 1px solid var(--border); border-radius: 12px 12px 12px 2px; color: var(--text); }
.chat-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.chat-msg.user .chat-label { text-align: right; }
.chat-input-area { display: flex; gap: 8px; padding: 12px 0 0; }
.chat-input-area textarea { flex: 1; resize: none; border: 1.5px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13.5px; }
.chat-input-area textarea:focus { border-color: var(--primary); outline: none; }
.typing-indicator { display: flex; gap: 4px; align-items: center; padding: 8px 0; }
.typing-dot { width: 7px; height: 7px; background: var(--text-muted); border-radius: 50%; animation: typing 1.2s ease infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%,60%,100%{transform:translateY(0);opacity:.4} 30%{transform:translateY(-5px);opacity:1} }

/* ===== VISIT DETAIL ===== */
.visit-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.info-item label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; display: block; margin-bottom: 3px; }
.info-item p { font-size: 14px; color: var(--text); }
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 16px; gap: 0; }
.tab { padding: 10px 20px; font-size: 14px; font-weight: 500; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all var(--t); }
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }
.spin-record-item {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; margin-bottom: 10px; background: #fafbff;
}
.spin-record-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.spin-record-q { font-size: 13.5px; color: var(--text); margin-bottom: 4px; }
.spin-record-r { font-size: 13px; color: var(--text-muted); font-style: italic; }
.spin-record-feedback { margin-top: 8px; padding: 8px 10px; background: #fffbf0; border-left: 3px solid var(--warning); border-radius: 4px; font-size: 12px; color: var(--text); }
.score-bar-wrap { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.score-bar { flex: 1; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.score-bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--success)); border-radius: 3px; transition: width 0.4s ease; }
.score-text { font-size: 12px; font-weight: 600; color: var(--text-muted); min-width: 30px; }

/* ===== MEMBER CARD ===== */
.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.member-card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.member-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.member-avatar { width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--secondary)); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 16px; }
.member-name { font-size: 15px; font-weight: 600; }
.member-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; text-align: center; }
.member-stat-value { font-size: 18px; font-weight: 700; color: var(--primary); }
.member-stat-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ===== SCENARIO CONFIG ===== */
.scenario-form { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; border: 1px solid var(--border); }

/* ===== QUESTION LIBRARY ITEM ===== */
.question-item { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.question-item:last-child { border-bottom: none; }
.question-item:hover { background: #fafbff; }
.question-text { font-size: 13.5px; color: var(--text); margin: 4px 0; }
.question-meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 14px; margin-top: 4px; }

/* ===== USER/TEAM TABLE ROLE BADGE ===== */
.role-admin { background: #fef3c7; color: #92400e; }
.role-manager { background: #e0e7ff; color: #3730a3; }
.role-sales { background: #d1fae5; color: #065f46; }

/* ===== MARKDOWN IN CHAT BUBBLE ===== */
.md-content p { margin: 0 0 8px; }
.md-content p:last-child { margin-bottom: 0; }
.md-content h1,.md-content h2,.md-content h3 { font-size: 14px; font-weight: 700; margin: 10px 0 4px; }
.md-content ul,.md-content ol { padding-left: 18px; margin: 4px 0 8px; }
.md-content li { margin-bottom: 3px; line-height: 1.6; }
.md-content strong { font-weight: 700; }
.md-content em { font-style: italic; }
.md-content code { background: rgba(0,0,0,0.07); padding: 1px 5px; border-radius: 3px; font-size: 12px; font-family: 'SFMono-Regular', Consolas, monospace; }
.md-content pre { background: rgba(0,0,0,0.06); padding: 10px 12px; border-radius: 5px; overflow-x: auto; margin: 8px 0; }
.md-content pre code { background: none; padding: 0; font-size: 12px; }
.md-content blockquote { border-left: 3px solid rgba(0,0,0,0.15); padding-left: 10px; margin: 6px 0; color: inherit; opacity: 0.8; }
.md-content hr { border: none; border-top: 1px solid rgba(0,0,0,0.1); margin: 8px 0; }
/* 打字光标动画 */
.stream-cursor { display: inline-block; animation: blink 0.8s step-end infinite; color: var(--primary); margin-left: 1px; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-14 { margin-top: 14px; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
