/* ============================================================
   VioraAI V3 Demo — 全局样式
   覆盖：主聊天界面 + 后台管理界面
   ============================================================ */

/* ---- 基础重置 ---- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  background: #f5f5f5;
  color: #333;
}

/* ============================================================
   风险等级颜色系统（全局使用）
   ============================================================ */
.risk-r0 { color: #28a745; }
.risk-r1 { color: #fd7e14; }
.risk-r2 { color: #dc3545; }
.risk-badge-r0 { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.risk-badge-r1 { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.risk-badge-r2 { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

/* 通用徽章 */
.badge-mode { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 500; }
.mode-normal  { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.mode-safety  { background: #fff8e1; color: #f57f17; border: 1px solid #ffe082; }
.mode-crisis  { background: #fce4ec; color: #ad1457; border: 1px solid #f48fb1; }

/* 模板风险标签色块（多模板标签匹配功能） */
.tag-chip {
  display: inline-block;
  background: #ede9fe;
  color: #5b21b6;
  border: 1px solid #c4b5fd;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  white-space: nowrap;
}

/* ============================================================
   主聊天界面布局
   ============================================================ */
#chat-app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* 左侧会话列表栏 */
#sidebar {
  width: 280px;
  min-width: 220px;
  background: #1a1a2e;
  color: #e0e0e0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #333;
  flex-shrink: 0;
}

#sidebar-header {
  padding: 16px;
  background: #16213e;
  border-bottom: 1px solid #333;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#sidebar-header .brand {
  font-size: 16px;
  font-weight: 700;
  color: #a78bfa;
  letter-spacing: 0.5px;
}

#btn-new-session {
  background: #7c3aed;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.2s;
}
#btn-new-session:hover { background: #6d28d9; }

#session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

#session-list::-webkit-scrollbar { width: 4px; }
#session-list::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }

.session-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #222;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 10px;
}
.session-item:hover { background: #16213e; }
.session-item.active { background: #16213e; border-left: 3px solid #7c3aed; }

.session-item .session-title {
  font-size: 13px;
  color: #ddd;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-item .session-meta {
  font-size: 10px;
  color: #888;
}

.session-risk-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.risk-dot-r0 { background: #28a745; }
.risk-dot-r1 { background: #fd7e14; }
.risk-dot-r2 { background: #dc3545; }

#sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid #333;
  font-size: 11px;
  color: #666;
  text-align: center;
}
#sidebar-footer a { color: #7c3aed; text-decoration: none; }

/* 主聊天区域 */
#chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

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

#chat-header .session-info h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #333;
}
#chat-header .session-info .meta {
  font-size: 11px;
  color: #888;
  margin-top: 2px;
}

#risk-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 消息列表区域 */
#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#messages-container::-webkit-scrollbar { width: 6px; }
#messages-container::-webkit-scrollbar-thumb { background: #ddd; border-radius: 3px; }

/* 欢迎空状态 */
#empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #aaa;
  text-align: center;
  padding: 40px;
}
#empty-state .icon { font-size: 48px; margin-bottom: 16px; }
#empty-state h3 { margin: 0 0 8px; color: #999; font-size: 18px; }
#empty-state p { margin: 0; font-size: 13px; line-height: 1.6; }

/* 消息气泡 */
.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.message-row.user-row { flex-direction: row-reverse; }

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.user-avatar { background: #7c3aed; color: white; }
.bot-avatar  { background: #e8f4fd; color: #1a73e8; }

.bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}
.user-bubble {
  background: #7c3aed;
  color: white;
  border-bottom-right-radius: 4px;
}
.bot-bubble {
  background: #f1f3f5;
  color: #333;
  border-bottom-left-radius: 4px;
}

.message-time {
  font-size: 10px;
  color: #aaa;
  margin-top: 4px;
  text-align: right;
}
.user-row .message-time { text-align: left; }

/* 输入区域 */
#chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid #e0e0e0;
  background: #fff;
  flex-shrink: 0;
}

#input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#message-input {
  flex: 1;
  resize: none;
  border: 1.5px solid #ddd;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  max-height: 140px;
  overflow-y: auto;
  transition: border-color 0.2s;
  line-height: 1.5;
}
#message-input:focus { border-color: #7c3aed; }
#message-input::placeholder { color: #bbb; }

#btn-send {
  background: #7c3aed;
  color: white;
  border: none;
  width: 42px; height: 42px;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  transition: background 0.2s, transform 0.1s;
  flex-shrink: 0;
}
#btn-send:hover { background: #6d28d9; }
#btn-send:active { transform: scale(0.94); }
#btn-send:disabled { background: #ccc; cursor: not-allowed; }

#input-hint {
  font-size: 11px;
  color: #bbb;
  margin-top: 6px;
  text-align: right;
}

/* 正在输入动画 */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: #f1f3f5;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}
.typing-dot {
  width: 7px; height: 7px;
  background: #aaa;
  border-radius: 50%;
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* ============================================================
   后台管理界面（admin.html）
   ============================================================ */
#admin-app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* 管理端左侧导航 */
#admin-nav {
  width: 220px;
  background: #1e293b;
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#admin-nav .nav-brand {
  padding: 20px 16px;
  font-size: 15px;
  font-weight: 700;
  color: #e2e8f0;
  border-bottom: 1px solid #334155;
  display: flex;
  align-items: center;
  gap: 8px;
}

#admin-nav .nav-item {
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  border-left: 3px solid transparent;
}
#admin-nav .nav-item:hover { background: #334155; color: #e2e8f0; }
#admin-nav .nav-item.active { background: #1e3a5f; color: #60a5fa; border-left-color: #3b82f6; }
#admin-nav .nav-item .nav-icon { font-size: 16px; }

#admin-nav .nav-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid #334155;
  font-size: 11px;
  color: #475569;
}
#admin-nav .nav-footer a { color: #60a5fa; text-decoration: none; }

/* 管理端主内容区 */
#admin-content {
  flex: 1;
  overflow-y: auto;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
}

#admin-topbar {
  padding: 14px 24px;
  background: white;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
#admin-topbar h1 { margin: 0; font-size: 18px; font-weight: 600; color: #1e293b; }

#admin-body { padding: 24px; flex: 1; }

/* 卡片 */
.card {
  background: white;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  padding: 20px;
  margin-bottom: 20px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f1f5f9;
}

/* 统计卡片 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: #1e293b; }
.stat-card .stat-label { font-size: 12px; color: #94a3b8; margin-top: 4px; }

/* 表单样式 */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: #475569; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-control {
  width: 100%;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.form-control:focus { border-color: #3b82f6; }
textarea.form-control { resize: vertical; min-height: 100px; }

/* 按钮 */
.btn { padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer; font-size: 13px; font-weight: 500; transition: all 0.2s; }
.btn-primary { background: #3b82f6; color: white; }
.btn-primary:hover { background: #2563eb; }
.btn-success { background: #22c55e; color: white; }
.btn-success:hover { background: #16a34a; }
.btn-danger  { background: #ef4444; color: white; }
.btn-danger:hover  { background: #dc2626; }
.btn-warning { background: #f59e0b; color: white; }
.btn-warning:hover { background: #d97706; }
.btn-secondary { background: #e2e8f0; color: #475569; }
.btn-secondary:hover { background: #cbd5e1; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-outline-primary { background: transparent; border: 1.5px solid #3b82f6; color: #3b82f6; }
.btn-outline-primary:hover { background: #3b82f6; color: white; }

/* 表格 */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { background: #f8fafc; padding: 10px 14px; font-weight: 600; color: #475569; border-bottom: 1.5px solid #e2e8f0; text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.table td { padding: 10px 14px; border-bottom: 1px solid #f1f5f9; color: #334155; vertical-align: middle; }
.table tr:hover td { background: #f8fafc; }

/* 标签页 */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 2px solid #e2e8f0; }
.tab-btn { padding: 8px 16px; background: transparent; border: none; cursor: pointer; font-size: 13px; color: #64748b; font-weight: 500; border-bottom: 3px solid transparent; margin-bottom: -2px; transition: all 0.2s; }
.tab-btn:hover { color: #3b82f6; }
.tab-btn.active { color: #3b82f6; border-bottom-color: #3b82f6; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* 审计JSON展示 */
.audit-section { margin-bottom: 12px; }
.audit-label { font-size: 11px; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.audit-json-block {
  background: #1e293b;
  color: #e2e8f0;
  padding: 12px;
  border-radius: 8px;
  font-family: "Fira Code", "Cascadia Code", monospace;
  font-size: 11px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
}
.audit-text-block {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  color: #334155;
}

/* JSON语法高亮（简单着色） */
.json-string { color: #86efac; }
.json-number { color: #93c5fd; }
.json-bool   { color: #f9a8d4; }
.json-null   { color: #94a3b8; }
.json-key    { color: #fbbf24; }

/* 标注面板 */
.annotation-item {
  padding: 10px 12px;
  border-radius: 8px;
  border-left: 3px solid;
  margin-bottom: 8px;
  background: #f8fafc;
}
.annotation-item.correct      { border-color: #22c55e; }
.annotation-item.incorrect    { border-color: #ef4444; }
.annotation-item.needs_review { border-color: #f59e0b; }
.annotation-item.good_example { border-color: #3b82f6; }
.annotation-item.bad_example  { border-color: #8b5cf6; }
.annotation-item.false_positive { border-color: #06b6d4; }
.annotation-item.false_negative { border-color: #f97316; }

.annotation-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.annotation-type-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; background: #e2e8f0; color: #475569; }
.annotation-field-path { font-size: 11px; color: #94a3b8; font-family: monospace; }
.annotation-annotator { font-size: 11px; color: #94a3b8; margin-left: auto; }
.annotation-comment { font-size: 13px; color: #334155; margin-top: 4px; }
.annotation-suggested { font-size: 11px; color: #f59e0b; margin-top: 4px; }

/* 会话列表（admin端） */
.session-card {
  padding: 14px 16px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  margin-bottom: 10px;
  background: white;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 12px;
}
.session-card:hover { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.session-card.selected { border-color: #3b82f6; background: #eff6ff; }

.session-card .risk-pill {
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

/* 消息审计列表 */
.audit-msg-item {
  padding: 12px 16px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  margin-bottom: 10px;
  background: white;
}
.audit-msg-item.has-risk-r1 { border-left: 3px solid #fd7e14; }
.audit-msg-item.has-risk-r2 { border-left: 3px solid #dc3545; }
.audit-msg-item-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

/* 加载状态 */
.loading-spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast通知 */
#toast-container {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 16px;
  border-radius: 8px;
  color: white;
  font-size: 13px;
  min-width: 240px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: toast-in 0.3s ease;
}
.toast-success { background: #22c55e; }
.toast-error   { background: #ef4444; }
.toast-info    { background: #3b82f6; }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

/* ---- Response Quality Card ---- */
.quality-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 12px;
}
.quality-card-title {
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 10px;
}
.quality-metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
}
.quality-metric {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.quality-metric-label {
  font-size: 11px;
  color: #64748b;
}
.quality-hint {
  font-size: 10px;
  color: #94a3b8;
  font-weight: 400;
}
.quality-metric-value {
  font-size: 15px;
  font-weight: 700;
  color: #1e293b;
}
.quality-bar-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.quality-bar-bg {
  flex: 1;
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
}
.quality-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.quality-metric-score {
  font-size: 11px;
  font-weight: 600;
  color: #475569;
  min-width: 32px;
  text-align: right;
}

/* ---- Visual JSON Field Display (vjson + vf) ---- */

/* Card wrapper for each JSON top-level section */
.vjson-card {
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
}
.vjson-card-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}

/* Section color themes */
.vjson-amber  { background: #fffbeb; border: 1px solid #fde68a; }
.vjson-amber  .vjson-card-title { color: #92400e; }
.vjson-blue   { background: #eff6ff; border: 1px solid #bfdbfe; }
.vjson-blue   .vjson-card-title { color: #1e40af; }
.vjson-orange { background: #fff7ed; border: 1px solid #fed7aa; }
.vjson-orange .vjson-card-title { color: #9a3412; }
.vjson-red    { background: #fef2f2; border: 1px solid #fecaca; }
.vjson-red    .vjson-card-title { color: #991b1b; }
.vjson-purple { background: #f5f3ff; border: 1px solid #ddd6fe; }
.vjson-purple .vjson-card-title { color: #5b21b6; }
.vjson-green  { background: #f0fdf4; border: 1px solid #bbf7d0; }
.vjson-green  .vjson-card-title { color: #14532d; }
.vjson-teal   { background: #f0fdfa; border: 1px solid #99f6e4; }
.vjson-teal   .vjson-card-title { color: #134e4a; }
.vjson-gray   { background: #f8fafc; border: 1px solid #e2e8f0; }
.vjson-gray   .vjson-card-title { color: #334155; }

/* Field layout */
.vf-object { display: flex; flex-direction: column; gap: 5px; }
.vf-nested { background: rgba(0,0,0,0.03); border-radius: 6px; padding: 8px 10px; margin-top: 2px; }
.vf-field  { display: flex; align-items: flex-start; gap: 10px; font-size: 12px; }
.vf-key {
  font-family: "Fira Code", "Cascadia Code", monospace;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  min-width: 90px;
  max-width: 160px;
  flex-shrink: 0;
  padding-top: 2px;
  word-break: break-all;
}
.vf-value { flex: 1; word-break: break-word; }

/* Scalar value badges */
.vf-badge { font-size: 11px; padding: 1px 7px; border-radius: 10px; font-weight: 600; display: inline-block; line-height: 1.6; }
.vf-badge-success { background: #d1fae5; color: #065f46; }
.vf-badge-danger  { background: #fee2e2; color: #991b1b; }
.vf-badge-warning { background: #fef3c7; color: #92400e; }
.vf-badge-info    { background: #dbeafe; color: #1e40af; }
.vf-badge-neutral { background: #f1f5f9; color: #475569; }

/* Inline string */
.vf-string { font-size: 12px; color: #047857; }
/* Null / empty */
.vf-null   { font-size: 12px; color: #94a3b8; font-style: italic; }
/* Long / multiline text block */
.vf-longtext {
  font-size: 12px;
  color: #334155;
  background: rgba(0,0,0,0.03);
  border-radius: 4px;
  padding: 6px 8px;
  margin-top: 2px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Array of strings → chip row */
.vf-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.vf-chip  { font-size: 11px; background: #ede9fe; color: #5b21b6; border-radius: 10px; padding: 1px 8px; font-weight: 500; }

/* Mixed array */
.vf-array { display: flex; flex-direction: column; gap: 4px; }
.vf-array-item { display: flex; align-items: flex-start; gap: 6px; padding: 2px 0; }
.vf-array-idx  { font-size: 10px; color: #94a3b8; font-family: monospace; min-width: 16px; padding-top: 3px; flex-shrink: 0; }

/* Export button */
.btn-export { background: #0f172a; color: #f8fafc; }
.btn-export:hover { background: #334155; }

/* 响应式 */
@media (max-width: 768px) {
  #sidebar { width: 60px; }
  #sidebar .session-title, #sidebar .session-meta { display: none; }
  .bubble { max-width: 90%; }
  #admin-nav { width: 56px; }
  #admin-nav .nav-item span { display: none; }
}
