/* 南非域外法查明系统 —— 前端样式（ChatGPT / Claude 风格，暖中性 + 法律靛蓝） */
:root {
  --bg: #ffffff;
  --bg-soft: #f7f6f3;
  --bg-sidebar: #f5f4f0;
  --bg-hover: #ecebe5;
  --border: #e6e3dc;
  --border-strong: #d6d2c8;
  --text: #2a2a28;
  --text-soft: #6b6862;
  --text-faint: #9a958c;
  --accent: #4338ca;
  --accent-hover: #3730a3;
  --accent-soft: #eef0ff;
  --accent-ink: #312e81;
  --gold: #b4791f;
  --danger: #c0392b;
  --ok: #15803d;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-soft);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
.boot { display:flex; height:100vh; align-items:center; justify-content:center; color: var(--text-faint); }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; }
a { color: var(--accent); text-decoration: none; }

/* ---------- 通用按钮 ---------- */
.btn {
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: all .15s ease;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-danger:hover { background: #fbeae8; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* ---------- 登录 / 注册 ---------- */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #eef0ff 0%, var(--bg-soft) 55%);
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
  padding: 38px 36px 30px;
}
.auth-brand { text-align: center; margin-bottom: 26px; }
.auth-emblem {
  width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 14px;
  background: linear-gradient(135deg, var(--accent) 0%, #6d28d9 100%);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 26px; box-shadow: 0 6px 18px rgba(67,56,202,.35);
}
.auth-title { font-size: 21px; font-weight: 700; margin: 0; letter-spacing: .5px; }
.auth-sub { color: var(--text-faint); font-size: 12.5px; margin-top: 6px; letter-spacing: .3px; }
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 13px; color: var(--text-soft); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--bg); transition: border .15s;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-submit { width: 100%; padding: 12px; margin-top: 6px; font-size: 15px; }
.auth-switch { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-soft); }
.auth-switch a { cursor: pointer; font-weight: 600; }
.auth-error {
  background: #fbeae8; color: var(--danger); border: 1px solid #f0c9c4;
  border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13px; margin-bottom: 14px;
}
.auth-note { font-size: 12px; color: var(--text-faint); text-align:center; margin-top: 22px; line-height:1.5;}

/* ---------- 主布局 ---------- */
.layout { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 268px; flex-shrink: 0; background: var(--bg-sidebar);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.sb-head { padding: 16px 16px 12px; }
.sb-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sb-emblem {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent) 0%, #6d28d9 100%);
  display:flex; align-items:center; justify-content:center; color:#fff; font-size:16px;
}
.sb-brand-name { font-size: 14.5px; font-weight: 700; line-height: 1.2; }
.sb-brand-sub { font-size: 10.5px; color: var(--text-faint); }
.new-chat-btn {
  width: 100%; display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 10px; font-weight: 600;
}
.sb-section-label { padding: 8px 18px 4px; font-size: 11px; color: var(--text-faint); letter-spacing: .5px; text-transform: uppercase; }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-soft); font-size: 13.5px; margin-bottom: 2px;
  white-space: nowrap; overflow: hidden;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.conv-item .conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.conv-item .conv-del { opacity: 0; font-size: 15px; color: var(--text-faint); padding: 0 2px; }
.conv-item:hover .conv-del { opacity: 1; }
.conv-empty { padding: 18px; font-size: 13px; color: var(--text-faint); text-align: center; }
.sb-foot { border-top: 1px solid var(--border); padding: 10px; }
.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer;
}
.user-chip:hover { background: var(--bg-hover); }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; flex-shrink: 0;
}
.user-meta { flex: 1; overflow: hidden; }
.user-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 11px; color: var(--text-faint); }
.role-tag { font-size: 10px; padding: 1px 7px; border-radius: 20px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 600;}
.admin-entry { width:100%; margin-top:6px; justify-content:flex-start; gap:8px; }

/* ---------- 主区 ---------- */
.main { flex: 1; display: flex; flex-direction: column; background: var(--bg); min-width: 0; }
.topbar {
  height: 56px; flex-shrink: 0; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 22px; gap: 12px;
}
.topbar-title { font-weight: 600; font-size: 15px; }
.topbar-sub { font-size: 12px; color: var(--text-faint); }
.topbar-spacer { flex: 1; }

/* 聊天流 */
.chat-stream { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.stream-inner { max-width: 820px; margin: 0 auto; padding: 28px 24px 40px; }
.welcome { text-align: center; padding: 60px 20px; color: var(--text-soft); }
.welcome-emblem {
  width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 20px;
  background: linear-gradient(135deg, var(--accent) 0%, #6d28d9 100%);
  display:flex; align-items:center; justify-content:center; color:#fff; font-size:32px;
  box-shadow: 0 8px 24px rgba(67,56,202,.3);
}
.welcome h2 { font-size: 22px; color: var(--text); margin: 0 0 8px; }
.welcome p { font-size: 14px; max-width: 460px; margin: 0 auto 26px; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 600px; margin: 0 auto; }
.suggestion {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  text-align: left; background: var(--bg); transition: all .15s; font-size: 13.5px; color: var(--text);
}
.suggestion:hover { border-color: var(--accent); background: var(--accent-soft); }
.suggestion b { display: block; margin-bottom: 3px; font-size: 14px; }
.suggestion span { color: var(--text-faint); font-size: 12.5px; }

.msg { display: flex; gap: 14px; margin-bottom: 26px; }
.msg-avatar {
  width: 30px; height: 30px; border-radius: 7px; flex-shrink: 0; display:flex;
  align-items:center; justify-content:center; font-size: 14px; font-weight: 600; margin-top:2px;
}
.msg.user .msg-avatar { background: #e6e3dc; color: var(--text-soft); }
.msg.assistant .msg-avatar { background: linear-gradient(135deg, var(--accent) 0%, #6d28d9 100%); color: #fff; }
.msg-body { flex: 1; min-width: 0; }
.msg-role { font-size: 12.5px; font-weight: 700; color: var(--text-soft); margin-bottom: 4px; }
.msg-content { font-size: 15px; }
.msg-content > *:first-child { margin-top: 0; }
.msg-content > *:last-child { margin-bottom: 0; }
.msg-content p { margin: 10px 0; }
.msg-content h1,.msg-content h2,.msg-content h3,.msg-content h4 { margin: 18px 0 10px; line-height: 1.35; }
.msg-content h3 { font-size: 17px; } .msg-content h4 { font-size: 15px; }
.msg-content ul, .msg-content ol { padding-left: 24px; margin: 10px 0; }
.msg-content li { margin: 4px 0; }
.msg-content code { background: var(--bg-soft); padding: 2px 6px; border-radius: 5px; font-size: 13px; }
.msg-content pre { background: #1f2430; color: #e6e6e6; padding: 14px; border-radius: var(--radius-sm); overflow-x: auto; }
.msg-content pre code { background: transparent; padding: 0; color: inherit; }
.msg-content table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 13.5px; }
.msg-content th, .msg-content td { border: 1px solid var(--border-strong); padding: 8px 10px; text-align: left; vertical-align: top; }
.msg-content th { background: var(--bg-soft); font-weight: 600; }
.msg-content blockquote { border-left: 3px solid var(--accent); margin: 10px 0; padding: 2px 14px; color: var(--text-soft); }
.cursor-blink::after { content: "▋"; color: var(--accent); animation: blink 1s steps(2) infinite; margin-left: 1px; }
@keyframes blink { 0%,50%{opacity:1} 50.01%,100%{opacity:0} }

/* 工具调用指示 */
.tool-chip {
  display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--accent-ink);
  background: var(--accent-soft); border: 1px solid #dfe2ff; border-radius: 20px;
  padding: 6px 14px; margin: 4px 0 12px;
}
.tool-chip .spinner {
  width: 12px; height: 12px; border: 2px solid #c7cbff; border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 引用来源 */
.citations { margin-top: 16px; border-top: 1px dashed var(--border-strong); padding-top: 14px; }
.citations-title { font-size: 12.5px; font-weight: 700; color: var(--text-soft); margin-bottom: 10px; display:flex; align-items:center; gap:6px;}
.citation-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.citation-card {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px;
  background: var(--bg-soft); cursor: pointer; transition: all .15s; font-size: 12.5px;
}
.citation-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.citation-name { font-weight: 600; color: var(--text); margin-bottom: 3px; line-height: 1.35; }
.citation-meta { color: var(--text-faint); font-size: 11.5px; }

/* 输入区 */
.composer-wrap { flex-shrink: 0; padding: 0 24px 22px; background: var(--bg); }
.composer {
  max-width: 820px; margin: 0 auto; border: 1px solid var(--border-strong);
  border-radius: 16px; padding: 10px 12px 10px 16px; display: flex; align-items: flex-end; gap: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,.04); transition: border .15s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea {
  flex: 1; border: none; resize: none; outline: none; background: transparent;
  font-size: 15px; line-height: 1.5; max-height: 200px; padding: 6px 0; color: var(--text);
}
.send-btn {
  width: 38px; height: 38px; border-radius: 10px; border: none; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 18px;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { background: var(--border-strong); cursor: not-allowed; }
.composer-hint { max-width: 820px; margin: 8px auto 0; text-align: center; font-size: 11.5px; color: var(--text-faint); }

/* ---------- 管理后台 ---------- */
.admin-page { flex: 1; overflow-y: auto; }
.admin-inner { max-width: 1080px; margin: 0 auto; padding: 26px 28px 50px; }
.admin-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.admin-tab {
  padding: 10px 16px; border: none; background: transparent; color: var(--text-soft);
  font-size: 14px; font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.admin-tab:hover { color: var(--text); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 28px; }
.stat-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.stat-num { font-size: 28px; font-weight: 700; color: var(--accent-ink); letter-spacing: .5px; }
.stat-label { font-size: 12.5px; color: var(--text-faint); margin-top: 4px; }
.dist-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.dist-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.dist-card h3 { margin: 0 0 14px; font-size: 14px; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; font-size: 12.5px; }
.bar-label { width: 150px; flex-shrink: 0; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 18px; background: var(--bg-soft); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #6d28d9); border-radius: 5px; }
.bar-val { width: 56px; text-align: right; color: var(--text-soft); flex-shrink: 0; font-variant-numeric: tabular-nums; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type=text], .toolbar select {
  padding: 8px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg);
}
.toolbar input[type=text] { min-width: 260px; }
.toolbar .grow { flex: 1; }

.data-table { width: 100%; border-collapse: collapse; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; font-size: 13px; }
.data-table th { background: var(--bg-soft); text-align: left; padding: 11px 14px; font-weight: 600; color: var(--text-soft); border-bottom: 1px solid var(--border); }
.data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background .12s; }
.data-table tbody tr:hover { background: var(--bg-soft); }
.row-link { cursor: pointer; }
.pill { display: inline-block; font-size: 11px; padding: 2px 9px; border-radius: 20px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.pill-gray { background: #eceae4; color: var(--text-soft); }
.pill-green { background: #dcfce7; color: var(--ok); }
.pill-red { background: #fbeae8; color: var(--danger); }
.pill-gold { background: #fbf0d9; color: var(--gold); }
.muted { color: var(--text-faint); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 18px; font-size: 13px; color: var(--text-soft); }

/* ---------- 弹窗 / 抽屉 ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(20,20,20,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: var(--bg); border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 460px; padding: 26px 28px; }
.modal h3 { margin: 0 0 18px; font-size: 18px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.drawer-mask { position: fixed; inset: 0; background: rgba(20,20,20,.4); z-index: 60; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 560px; max-width: 92vw; background: var(--bg); box-shadow: -8px 0 30px rgba(0,0,0,.15); z-index: 61; display: flex; flex-direction: column; }
.drawer-head { padding: 18px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; gap: 12px; }
.drawer-head h3 { margin: 0; font-size: 16px; line-height: 1.4; flex: 1; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px 24px 40px; }
.detail-section { margin-bottom: 18px; }
.detail-section h4 { font-size: 13px; color: var(--accent-ink); margin: 0 0 6px; text-transform: uppercase; letter-spacing: .4px; }
.detail-section .val { font-size: 13.5px; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; }
.kv .k { color: var(--text-faint); }
.close-x { font-size: 22px; color: var(--text-faint); background: none; border: none; line-height: 1; }

.flash { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1f2430; color: #fff; padding: 11px 20px; border-radius: 10px; font-size: 13.5px; z-index: 100; box-shadow: var(--shadow); }
.flash.err { background: var(--danger); }
.spin-inline { width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; display:inline-block; vertical-align: middle;}
.loading-center { display:flex; align-items:center; justify-content:center; gap:10px; padding: 40px; color: var(--text-faint); }

@media (max-width: 760px) {
  .sidebar { display: none; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .dist-grid, .citation-grid, .suggestions { grid-template-columns: 1fr; }
}
