/* DMA（DataManagerAi）全局样式 —— 专业金融终端风
   深藏青 + 低饱和金强调色，克制的中性灰层级。 */

:root {
    --navy: #10263f;
    --navy-dark: #0b1c30;
    --gold: #b8912f;
    --gold-bright: #d4ac3d;
    --bg: #f4f6f9;
    --card: #ffffff;
    --border: #dde3ea;
    --border-strong: #c8d2dc;
    --text: #24303c;
    --muted: #6b7885;
    --success: #2e7d4f;
    --danger: #b3362b;
    --warning: #b97d1e;
    --info: #2f6b9a;
    --purple: #6d4a8f;
    --diff-bg: #fdf0ef;
    --diff-border: #e5c4c1;
    --mono: 'Consolas', 'JetBrains Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.55;
}

a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 顶栏 ---------- */

.topbar {
    background: linear-gradient(90deg, var(--navy-dark), var(--navy) 40%, #16324f);
    border-bottom: 3px solid var(--gold);
    padding: 0 24px;
    display: flex;
    align-items: center;
    height: 52px;
}
.topbar .brand {
    color: #fff;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-right: 28px;
}
.topbar .brand:hover { text-decoration: none; }
.topbar .brand .accent { color: var(--gold-bright); }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
    color: #b9c6d4;
    padding: 15px 14px;
    font-size: 14px;
    border-bottom: 3px solid transparent;
    margin-bottom: -3px;
}
.topbar nav a:hover { color: #fff; text-decoration: none; }
.topbar nav a.active { color: #fff; border-bottom-color: var(--gold-bright); }
.topbar .topbar-search {
    margin-left: auto;
    position: relative;
}
.topbar .topbar-search input {
    width: 240px;
    height: 30px;
    padding: 0 10px;
    font-size: 13px;
    color: #e8eef5;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 3px;
    outline: none;
}
.topbar .topbar-search input::placeholder { color: #8fa2b5; }
.topbar .topbar-search input:focus { border-color: var(--gold-bright); }
.search-drop {
    position: absolute;
    top: 38px;
    right: 0;
    width: 380px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--card);
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    box-shadow: 0 6px 18px rgba(16, 38, 63, 0.25);
    z-index: 200;
}
.search-drop .search-item {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.search-drop .search-item:last-child { border-bottom: none; }
.search-drop .search-item:hover, .search-drop .search-item.active { background: #f0f5fa; }

.view-toggle {
    margin-left: auto;
    display: flex;
    border: 1px solid var(--border-strong);
    border-radius: 3px;
    overflow: hidden;
}
.view-toggle a {
    padding: 4px 14px;
    font-size: 12.5px;
    font-weight: 400;
    color: var(--text);
    background: var(--card);
}
.view-toggle a + a { border-left: 1px solid var(--border-strong); }
.view-toggle a.active { background: var(--navy); color: #fff; }
.view-toggle a:hover { text-decoration: none; }

/* ---------- 主区域 ---------- */

main { padding: 18px 24px 40px; max-width: 1440px; margin: 0 auto; }

.breadcrumb {
    font-size: 13px;
    color: var(--muted);
    margin: 0 0 12px;
}
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--info); }
.breadcrumb .sep { margin: 0 6px; color: var(--border-strong); }
.breadcrumb .current { color: var(--text); }

.page-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin: 0 0 16px;
    flex-wrap: wrap;
}
.page-header h2 { margin: 0; font-size: 20px; font-weight: 600; color: var(--navy); }
.page-header .subtitle { color: var(--muted); font-size: 13px; }

/* ---------- 面板 ---------- */

.panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 16px;
}
.panel-header {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--navy);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.panel-header .muted { font-weight: 400; }
.panel-body { padding: 14px 16px; }

/* ---------- 统计卡片 ---------- */

.stat-cards {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-top: 3px solid var(--border-strong);
    border-radius: 4px;
    padding: 12px 20px;
    min-width: 130px;
    color: var(--text);
    display: block;
}
.stat-card:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: 0 1px 4px rgba(16, 38, 63, 0.08); }
.stat-card .stat-num {
    display: block;
    font-size: 26px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}
.stat-card .stat-label { font-size: 13px; color: var(--muted); }
.stat-card.st-1 { border-top-color: var(--muted); }
.stat-card.st-2 { border-top-color: var(--warning); }
.stat-card.st-3 { border-top-color: var(--success); }
.stat-card.st-4 { border-top-color: #8795a3; }
.stat-card.active {
    background: var(--navy);
    border-color: var(--navy);
}
.stat-card.active .stat-num { color: #fff; }
.stat-card.active .stat-label { color: #b9c6d4; }
.stat-card.diff-good { border-top-color: var(--success); }
.stat-card.diff-good .stat-num { color: var(--success); }
.stat-card.diff-bad { border-top-color: var(--danger); }
.stat-card.diff-bad .stat-num { color: var(--danger); }
.stat-card.diff-mid { border-top-color: var(--warning); }
.stat-card.diff-mid .stat-num { color: var(--warning); }

/* ---------- 表格 ---------- */

table.data-table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    background: var(--card);
    font-size: 13px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
    border-radius: 4px;
    /* 圆角裁剪不能用 overflow:hidden——它会让 th 的 position:sticky 失效
       （sticky 被钳制在最近的滚动容器内）。clip-path 不创建滚动容器，
       是 sticky 表头的标准替代方案，全站表头冻结靠它生效。 */
    clip-path: inset(0 round 4px);
}
.data-table th, .data-table td {
    padding: 7px 10px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}
.data-table th {
    background: #eef1f5;
    color: var(--navy);
    font-weight: 600;
    white-space: nowrap;
    position: sticky;
    top: 0;
    /* 冻结时盖住下方滚过的行（含斑马纹/悬停底色）；覆盖层（弹窗 z≥90）不受影响 */
    z-index: 2;
}
.data-table tbody tr:hover { background: #f6f9fc; }
/* 斑马纹：奇数行浅底（与悬停色 #f6f9fc 错开保证可感知）；th 表头不受影响 */
.data-table tbody tr:nth-child(odd) { background: #f2f5f9; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* 分组竖线：同一表内两个统计口径区块的分隔（如 PDF 覆盖漏斗的文档口径 vs 份额类口径） */
.data-table td.sep, .data-table th.sep { border-left: 2px solid #ccd3dd; }
.data-table td.mono, .data-table th.mono { font-family: var(--mono); font-size: 12.5px; }
/* 分红结构化站点（pdf_dispatch L0 有意跳过）：整行斜纹背景标记 + 居中的
   占位说明单元格；覆盖在斑马纹之上，悬停仍保留一层底色保证可读 */
.data-table tbody tr.row-skipped td {
    background-color: rgba(120, 130, 145, .07);
    background-image: repeating-linear-gradient(45deg, rgba(120, 130, 145, .12) 0 6px, transparent 6px 12px);
}
.data-table tbody tr.row-skipped:hover td { background-color: #e8edf3; }
.data-table td.skipped-note { text-align: center; font-style: italic; color: var(--muted); }

tr.row-diff td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
tr.row-diff:hover td { background: var(--diff-bg); }

td.diff-cell {
    background: var(--diff-bg);
    color: var(--danger);
    font-weight: 600;
}

.empty-cell { color: var(--muted); }

/* ---------- 徽章 ---------- */

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 10px;
    color: #fff;
    font-size: 12px;
    white-space: nowrap;
    line-height: 1.5;
}
.st-gray { background: var(--muted); }
.st-orange { background: var(--warning); }
.st-green { background: var(--success); }
.st-dark { background: #555f6b; }
.st-blue { background: var(--info); }
.st-purple { background: var(--purple); }

/* ---------- 表单与按钮 ---------- */

.filters { padding: 12px 16px; }
.filters label { margin-right: 14px; display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
input[type=text], textarea, select {
    padding: 5px 8px;
    border: 1px solid var(--border-strong);
    border-radius: 3px;
    font-size: 13px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}
input[type=text]:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--info);
    box-shadow: 0 0 0 2px rgba(47, 107, 154, 0.15);
}

button, .btn {
    background: var(--navy);
    color: #fff;
    border: none;
    padding: 6px 16px;
    border-radius: 3px;
    cursor: pointer;
    text-decoration: none;
    font-size: 13px;
    display: inline-block;
    font-family: inherit;
}
button:hover, .btn:hover { background: #1b3f63; text-decoration: none; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #93291f; }
.btn-success { background: var(--success); }
.btn-success:hover { background: #256b42; }
.btn-secondary { background: #6b7885; }
.btn-secondary:hover { background: #55626f; }
.btn-gold { background: var(--gold); }
.btn-gold:hover { background: var(--gold-bright); }
.btn-blue { background: var(--info); }
.btn-blue:hover { background: #285b84; }
.btn-sm { padding: 3px 10px; font-size: 12px; }
form.inline { display: inline; }

textarea.full {
    width: 100%;
    box-sizing: border-box;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.5;
}

/* ---------- 消息条 ---------- */

.msg {
    background: #fcf6e5;
    border: 1px solid #eadfae;
    border-left: 4px solid var(--gold);
    padding: 9px 14px;
    margin-bottom: 14px;
    border-radius: 3px;
}
.msg-error { background: #fbf0ef; border-color: var(--diff-border); border-left-color: var(--danger); }
.msg-ok { background: #eef7f1; border-color: #cbe3d4; border-left-color: var(--success); }

/* ---------- 值对比卡 ---------- */

.compare { display: flex; gap: 0; align-items: stretch; margin-bottom: 4px; }
.compare-col { flex: 1; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.compare-head {
    background: #eef1f5;
    padding: 6px 14px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--navy);
    border-bottom: 1px solid var(--border);
}
.compare-head.qa { background: #f3f0e7; }
.compare-value {
    padding: 16px 14px;
    font-family: var(--mono);
    font-size: 16px;
    font-variant-numeric: tabular-nums;
    word-break: break-all;
}
.compare-value.diff { background: var(--diff-bg); color: var(--danger); font-weight: 700; }
.compare-vs {
    align-self: center;
    padding: 0 14px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

/* ---------- trial 阶段 stepper ---------- */

.stepper {
    list-style: none;
    padding: 0;
    margin: 0 0 14px;
    display: flex;
    gap: 0;
}
.stepper li {
    flex: 1;
    text-align: center;
    position: relative;
    padding-top: 26px;
    font-size: 12.5px;
    color: var(--muted);
}
.stepper li::before {
    content: '';
    position: absolute;
    top: 11px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--border-strong);
    z-index: 0;
}
.stepper li:first-child::before { left: 50%; }
.stepper li:last-child::before { right: 50%; }
.step-dot {
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 16px;
    line-height: 16px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--border-strong);
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 700;
    z-index: 1;
}
.stepper li.done { color: var(--success); }
.stepper li.done::before { background: var(--success); }
.stepper li.done .step-dot { border-color: var(--success); background: var(--success); color: #fff; }
.stepper li.active { color: var(--info); font-weight: 600; }
.stepper li.active .step-dot { border-color: var(--info); color: var(--info); box-shadow: 0 0 0 3px rgba(47, 107, 154, 0.2); }
.step-hint { display: block; font-size: 11.5px; color: var(--info); font-weight: 400; }

/* ---------- 日志 / 代码 ---------- */

.log-tail {
    background: var(--navy-dark);
    color: #a8c0d8;
    font-family: var(--mono);
    font-size: 12px;
    padding: 10px 12px;
    border-radius: 4px;
    max-height: 140px;
    overflow: auto;
    margin: 6px 0 0;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ---------- 抽屉 ---------- */

details.drawer summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--info);
    outline: none;
}
details.drawer[open] summary { margin-bottom: 8px; }

/* ---------- 分页 ---------- */

.pager { margin: 12px 0; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.pager a {
    padding: 4px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 3px;
    background: #fff;
    color: var(--text);
}
.pager a:hover { border-color: var(--info); color: var(--info); text-decoration: none; }
.pager .page-info { font-variant-numeric: tabular-nums; }

/* 分页局部刷新加载态（data-pager-region，见 base.html 拦截器） */
[data-pager-region].pager-loading { opacity: .45; pointer-events: none; }

/* ---------- 其他 ---------- */

.muted { color: var(--muted); font-size: 12px; }
h3 { color: var(--navy); font-size: 15.5px; margin: 18px 0 10px; }
h4 { color: var(--navy); font-size: 14px; margin: 14px 0 8px; }
h4.diff-good { color: var(--success); }
h4.diff-bad { color: var(--danger); }
h4.diff-mid { color: var(--warning); }
pre.rule-text { white-space: pre-wrap; margin: 0; font-family: inherit; }

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--navy);
    color: #fff;
    padding: 8px 20px;
    border-radius: 3px;
    font-size: 13px;
    opacity: 0;
    transition: opacity 0.25s;
    pointer-events: none;
    z-index: 99;
}
.toast.show { opacity: 0.95; }

/* ---------- 视图切换 tabs ---------- */

.page-header .tabs { margin-left: auto; display: flex; gap: 0; }
.page-header .tabs.tabs-left { margin-left: 0; }
.page-header .tabs a {
    padding: 5px 16px;
    border: 1px solid var(--border-strong);
    background: #fff;
    color: var(--muted);
    font-size: 13px;
}
.page-header .tabs a:first-child { border-radius: 3px 0 0 3px; }
.page-header .tabs a:last-child { border-radius: 0 3px 3px 0; }
.page-header .tabs a.active {
    background: var(--navy);
    border-color: var(--navy);
    color: #fff;
    font-weight: 600;
}
.page-header .tabs a:hover { text-decoration: none; }
.page-header .header-actions { margin-left: auto; }
.page-header .tabs + .header-actions { margin-left: 12px; }

/* ---------- 嵌套明细表 / 聚合行 ---------- */

.data-table.nested {
    margin: 8px 0 4px;
    font-size: 12.5px;
    background: #fafbfc;
}
tr.group-row > td { background: #fff; }

/* ---------- 代码块 / 解释文本 ---------- */

pre.code-block {
    background: #f7f8fa;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 10px 12px;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 420px;
    overflow: auto;
    margin: 8px 0;
}
pre.raw-excerpt { max-height: 520px; }
pre.explain-text {
    background: #f4f7f4;
    border: 1px solid #d5e2d8;
    border-left: 4px solid var(--success);
    border-radius: 4px;
    padding: 12px 14px;
    font-family: inherit;
    font-size: 13.5px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
}
.explain-form { margin-top: 10px; }
.explain-form .muted { margin-left: 10px; }

/* ---------- 解析逻辑面板：段落间距 + 字段高亮 ---------- */

.parse-body > * + * { margin-top: 14px; }
.parse-body .code-block { margin: 10px 0; }
.parse-body h4 { margin: 16px 0 8px; }
mark {
    background: #ffe9a8;
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
    font-weight: 600;
}

/* ---------- raw 摘录：结构化渲染（HTML 高亮 / JSON 树 / 渲染预览） ---------- */

.mini-tabs { margin: 6px 0; }
.mini-tabs button {
    background: #fff;
    color: var(--muted);
    border: 1px solid var(--border-strong);
    padding: 4px 14px;
    font-size: 12.5px;
}
.mini-tabs button:first-child { border-radius: 3px 0 0 3px; }
.mini-tabs button:last-child { border-radius: 0 3px 3px 0; }
.mini-tabs button.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.render-preview {
    width: 100%;
    min-height: 480px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fff;
}

/* HTML 源码高亮 */
.ht { color: #10263f; font-weight: 700; }
.ha { color: #0e7c86; }
.hv { color: #b35c1e; }
.hc { color: #8795a3; font-style: italic; }

/* JSON 源码高亮 */
.jk { color: #7a4ea3; }
.js { color: #2e7d4f; }
.jn { color: #2f6b9a; }
.jb { color: #b3362b; }

/* JSON 树 */
.json-tree { font-family: var(--mono); font-size: 12.5px; line-height: 1.7; }
.json-tree .jt-node { margin-left: 16px; }
.json-tree .jt-node > details > summary { cursor: pointer; outline: none; }
.json-tree .jt-key { color: #7a4ea3; }
.json-tree .jt-meta { color: #8795a3; font-size: 11.5px; }
.json-tree .jp-str { color: #2e7d4f; word-break: break-all; }
.json-tree .jp-num { color: #2f6b9a; }
.json-tree .jp-bool, .json-tree .jp-null { color: #b3362b; }

/* ---------- 顶栏用户区 ---------- */

.topbar .userbox {
    margin-left: 10px;
    color: #d7e1ea;
    font-size: 13px;
    white-space: nowrap;
}
.topbar .userbox a {
    margin-left: 10px;
    color: #8fa2b5;
    font-size: 12.5px;
}
.topbar .userbox a:hover { color: #fff; }

/* ---------- 登录页 ---------- */

.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--navy-dark), var(--navy) 55%, #16324f);
}
.login-card {
    background: var(--card);
    border-radius: 6px;
    border-top: 4px solid var(--gold);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    padding: 34px 38px 30px;
    width: 360px;
}
.login-card .login-brand {
    font-size: 22px;
    font-weight: 700;
    color: var(--navy);
    letter-spacing: 0.5px;
}
.login-card .login-brand .accent { color: var(--gold); }
.login-card .login-subtitle { color: var(--muted); font-size: 13px; margin: 6px 0 20px; }
.login-card label { font-size: 13px; color: var(--text); }
.login-card input[type=text], .login-card input[type=password] {
    width: 100%;
    margin-top: 4px;
    padding: 8px 10px;
    font-size: 14px;
}
.login-card p { margin: 0 0 14px; }
.login-card form > p:last-of-type { margin-bottom: 20px; }
.login-card .login-btn { width: 100%; padding: 9px 0; font-size: 15px; letter-spacing: 6px; }

input[readonly] { background: #f0f3f6; color: var(--muted); }

/* ---------- 详情页全高双栏 + AI 顾问聊天面板（VS Code 布局） ---------- */

/* 详情页：body 占满视口、禁止整页滚动，只有左右两栏内部滚动（列表页不受影响） */
body.detail-full { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
body.detail-full main {
    flex: 1; min-height: 0; width: 100%; max-width: none; margin: 0;
    padding: 10px 18px 14px; display: flex; flex-direction: column;
}
body.detail-full .breadcrumb { flex: 0 0 auto; margin-bottom: 8px; }

.detail-layout { flex: 1; min-height: 0; display: flex; align-items: stretch; }

.detail-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.detail-scroll { flex: 1; min-height: 0; overflow-y: auto; padding-right: 18px; }
.page-header .header-actions { display: inline-flex; gap: 8px; align-items: center; }

/* VS Code sash 风格分隔条 */
.splitter {
    flex: 0 0 5px; margin: 0 6px; cursor: col-resize; border-radius: 2px;
    background: var(--border); transition: background 0.15s;
}
.splitter:hover { background: var(--info); }

.chat-panel {
    width: 380px; flex-shrink: 0; min-height: 0;
    background: var(--card); border: 1px solid var(--border); border-radius: 4px;
    display: flex; flex-direction: column;
}
.chat-header {
    padding: 8px 12px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.chat-header .chat-title { font-weight: 600; color: var(--navy); font-size: 14px; margin-right: auto; }
/* 模型下拉：药丸风格与上下文仪表一致（间距由 header 的 gap 提供，
   title 的 margin-right:auto 负责把下拉之外的仪表/按钮组推到右侧） */
.chat-header .chat-model-select {
    font-size: 12px; color: var(--navy); cursor: pointer;
    background: #eef1f5; border: 1px solid var(--border); border-radius: 999px;
    padding: 2px 8px;
}

/* 上下文仪表（Kimi Code 插件同款）：% + ↑上行 + ↓下行，药丸徽标——
   浅灰底、无线框、大圆角；阈值变色（绿/黄/红）作用于文字与圆环弧长 */
.chat-ctx { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums;
    display: inline-flex; align-items: center; gap: 3px;
    background: #eef1f5; border-radius: 999px; padding: 2px 10px; margin-left: 10px; }
.chat-ctx .ctx-arrow { color: var(--muted); font-size: 11px; margin-left: 5px; }
/* 仪表盘圆环：灰色轨道 + currentColor 弧长随百分比填充（JS 改 stroke-dashoffset） */
.chat-ctx .ctx-ring { transform: rotate(-90deg); flex: none; }
.chat-ctx .ring-track { fill: none; stroke: var(--border); stroke-width: 3; }
.chat-ctx .ring-val { fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round;
    transition: stroke-dashoffset .4s ease; }
.chat-ctx.ctx-low { color: var(--success); }
.chat-ctx.ctx-mid { color: var(--warning); }
.chat-ctx.ctx-high { color: var(--danger); font-weight: 600; }

.chat-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.chat-messages {
    flex: 1; min-height: 0; overflow-y: auto;
    padding: 12px 14px; display: flex; flex-direction: column; gap: 10px;
}
.chat-msg {
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    max-width: 92%;
}
.chat-user {
    align-self: flex-end;
    background: var(--navy);
    color: #fff;
    border-bottom-right-radius: 2px;
}
.chat-assistant {
    align-self: flex-start;
    background: #eef1f5;
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 2px;
}
.chat-sys {
    align-self: stretch;
    max-width: none;
    background: #fcf6e5;
    border: 1px solid #eadfae;
    border-left: 4px solid var(--gold);
    font-size: 12.5px;
}
.chat-error { border-left-color: var(--danger); background: #fbf0ef; border-color: var(--diff-border); }

/* ---- AI 回复 markdown 渲染（markdown.js 输出，已转义，见 static/markdown.js） ---- */
.chat-assistant { white-space: normal; }
.chat-msg > :first-child { margin-top: 0; }
.chat-msg > :last-child { margin-bottom: 0; }
.chat-msg p { margin: 6px 0; }
.chat-msg h1, .chat-msg h2, .chat-msg h3, .chat-msg h4, .chat-msg h5, .chat-msg h6 {
    margin: 12px 0 6px; font-size: 13.5px;
}
.chat-msg table { border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 12.5px; background: #fff; }
.chat-msg th, .chat-msg td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; }
.chat-msg th { background: #e2e8f0; }
.chat-msg code { background: #e2e8f0; border-radius: 3px; padding: 1px 4px; font-family: Consolas, "Courier New", monospace; font-size: 12px; }
.chat-msg pre.code-block { background: #f6f8fa; border: 1px solid var(--border); border-radius: 6px;
    padding: 8px 10px; overflow-x: auto; margin: 8px 0; white-space: pre; }
.chat-msg pre.code-block code { background: none; padding: 0; }
.chat-msg ul, .chat-msg ol { margin: 6px 0; padding-left: 22px; }
.chat-msg li { margin: 2px 0; }
.chat-msg hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.chat-msg blockquote { margin: 8px 0; padding: 2px 10px; border-left: 3px solid var(--border); color: var(--muted); }
.chat-msg a { color: var(--info); }

.chat-hint { padding: 0 14px; margin: 4px 0; }

.chat-stages { display: flex; flex-direction: column; gap: 3px; margin: 6px 0; }
.chat-stage { font-size: 12px; color: var(--muted); }
.chat-stage.done { color: var(--success); }
.chat-stage.active { color: var(--info); font-weight: 600; }
.chat-status-line { font-size: 12.5px; margin-top: 4px; }
.chat-status-line b { color: var(--success); font-variant-numeric: tabular-nums; }
.chat-status-line b.chat-bad { color: var(--danger); }

.chat-input { border-top: 1px solid var(--border); padding: 10px 14px; }
.chat-input textarea {
    width: 100%;
    box-sizing: border-box;
    resize: vertical;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.5;
}
.chat-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.chat-actions .chat-actions-left { display: flex; align-items: center; gap: 10px; }
.chat-actions .chat-actions-right { display: flex; align-items: center; gap: 10px; }

.chat-verify-box {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(11, 28, 48, 0.45);
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-verify-inner {
    background: var(--card);
    border-radius: 6px;
    border-top: 4px solid var(--gold);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    padding: 20px 24px;
    width: 560px;
    max-width: 92vw;
}
.chat-verify-title { font-size: 16px; font-weight: 600; color: var(--navy); margin-bottom: 8px; }

/* 提示词弹窗（/prompts 展开全文用：遮罩 + 宽文本框，Esc/关闭/点遮罩退出） */
.prompt-modal-mask {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(11, 28, 48, 0.45);
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
}
.prompt-modal-box {
    background: var(--card);
    border-radius: 6px;
    border-top: 4px solid var(--gold);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    padding: 16px 20px 20px;
    width: min(960px, 94vw);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}
.prompt-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.prompt-modal-head .prompt-modal-title { font-size: 15px; font-weight: 600; color: var(--navy); }
.prompt-modal-box textarea {
    flex: 1;
    min-height: 50vh;
    font-family: Consolas, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.55;
    resize: vertical;
}
.prompt-modal-foot { margin-top: 10px; display: flex; gap: 10px; align-items: center; }

/* 字段级溯源（design-docs/03 §ds_field_provenance）：详情页字段旁 ⧉ 图标 + 页底溯源面板 */
.prov-icon {
    cursor: help;
    color: var(--blue, #1a73e8);
    margin-left: 5px;
    font-size: 13px;
    user-select: none;
}
.prov-ref { max-width: 420px; word-break: break-all; white-space: normal; }
.prov-val { max-width: 320px; word-break: break-all; white-space: normal; }
.panel-header .head-link { margin-left: auto; font-weight: normal; font-size: 13px; }
.panel-header .head-filter { margin-left: auto; font-weight: 400; font-size: 13px; }
.panel-header .head-filter select { font-size: 13px; padding: 2px 4px; }
/* 字段来源设置：批量保存的脏行高亮（有未保存修改的行） */
tr.fp-dirty td { background: #fff8e6; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 4px 6px; border: 1px solid var(--border); border-radius: 4px;
    background: #fff; cursor: pointer; color: var(--navy);
}
.icon-btn:hover { background: #f5f7fa; }
.icon-btn svg { width: 14px; height: 14px; }
.fp-actions { white-space: nowrap; }
textarea { font-family: inherit; font-size: 13px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 4px; resize: vertical; }

/* ---------- 通用弹窗（modal.js：字段来源策略等 iframe 浮层） ---------- */
.modal-mask {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 1000;
    display: flex; align-items: center; justify-content: center;
}
.modal-box {
    background: #fff; border-radius: 8px; width: min(1100px, 92vw);
    height: min(760px, 88vh); display: flex; flex-direction: column;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
.modal-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 12px; border-bottom: 1px solid var(--border);
}
.modal-title { font-weight: 600; color: var(--navy); font-size: 14px; }
.modal-close {
    border: none; background: none; font-size: 20px; line-height: 1;
    cursor: pointer; color: #666;
}
.modal-frame { flex: 1; border: none; width: 100%; }


/* ---------- 响应式：平板（≤900px）与手机（≤600px） ----------
   桌面端（>900px）不命中任何媒体查询，视觉零变化。 */

.nav-toggle {
    display: none;
    background: none;
    border: none;
    padding: 6px;
    margin-right: 6px;
    color: #b9c6d4;
    cursor: pointer;
    align-items: center;
}
.nav-toggle:hover { color: #fff; }

@media (max-width: 900px) {
    /* 顶栏压缩 */
    .topbar { padding: 0 12px; }
    .topbar .brand { margin-right: 12px; font-size: 15px; }
    .topbar nav a { padding: 15px 8px; font-size: 13px; white-space: nowrap; }
    .topbar .topbar-search input { width: 160px; }

    main { padding: 14px 12px 32px; }

    /* 宽表横向滚动兜底：列对齐保持，sticky 表头在块级滚动容器内仍生效。
       matrix 表（按 Provider 矩阵）排除：display:block 会把 thead/tbody 拆成
       两个独立匿名表格，表头表体列宽各自计算导致错位、单元格重叠，长字段
       名列还会吞掉下方整列数字；matrix 自带 .table-scroll 横滚 + sticky 首列，
       保持原生 table 布局即可（问题项列表 items.html） */
    table.data-table:not(.matrix-table) { display: block; overflow-x: auto; }

    /* 详情页单栏化：聊天面板全宽堆叠到内容下方，消息区内部滚动 */
    body.detail-full { height: auto; overflow: visible; }
    body.detail-full main { padding: 10px 12px 20px; }
    .detail-layout { flex-direction: column; }
    .detail-scroll { overflow: visible; padding-right: 0; }
    .splitter { display: none; }
    .chat-panel { width: 100%; height: 65vh; }
}

@media (max-width: 600px) {
    .topbar { position: relative; }
    .topbar .brand { font-size: 14px; margin-right: 8px; }
    .nav-toggle { display: inline-flex; }

    /* 汉堡下拉导航 */
    .topbar nav {
        display: none;
        position: absolute;
        top: 52px;
        left: 0;
        right: 0;
        flex-direction: column;
        background: var(--navy-dark);
        border-bottom: 3px solid var(--gold);
        box-shadow: 0 10px 20px rgba(11, 28, 48, 0.35);
        z-index: 300;
    }
    .topbar nav.open { display: flex; }
    .topbar nav a {
        padding: 12px 18px;
        font-size: 14px;
        border-bottom: 3px solid transparent;
        border-left: 3px solid transparent;
        margin-bottom: 0;
    }
    .topbar nav a + a { border-top: 1px solid rgba(255, 255, 255, 0.07); }
    .topbar nav a.active {
        border-bottom-color: transparent;
        border-left-color: var(--gold-bright);
        background: rgba(212, 172, 61, 0.10);
    }

    .topbar { padding: 0 8px; }
    .topbar .topbar-search input { width: 92px; }
    .search-drop { width: 300px; max-width: calc(100vw - 16px); }
    /* 退出链接必须可点：顶栏空间不足时压缩搜索框，用户区不收缩不裁剪 */
    .topbar .userbox { flex: none; margin-left: 8px; font-size: 12px; }

    /* 列表卡片化（items-table=问题项列表，batch-table=流水线批次；依赖模板 data-label；
       抽屉内嵌套明细表不挂这些 class，仍走横向滚动） */
    table.items-table, table.batch-table { border: none; background: transparent; overflow: visible; }
    table.items-table > thead, table.batch-table > thead { display: none; }
    table.items-table > tbody > tr, table.batch-table > tbody > tr {
        display: block;
        border: 1px solid var(--border);
        border-radius: 4px;
        margin-bottom: 10px;
        background: var(--card);
    }
    table.items-table > tbody > tr:nth-child(odd), table.batch-table > tbody > tr:nth-child(odd) { background: var(--card); }
    table.items-table > tbody > tr:hover > td, table.batch-table > tbody > tr:hover > td { background: transparent; }
    table.items-table > tbody > tr > td, table.batch-table > tbody > tr > td { display: block; border-bottom: none; padding: 4px 10px; }
    table.items-table > tbody > tr > td::before, table.batch-table > tbody > tr > td::before {
        content: attr(data-label);
        display: inline-block;
        width: 88px;
        color: var(--muted);
        font-size: 12px;
    }
    table.items-table > tbody > tr > td.drawer-cell::before { content: none; }
    /* 卡片内数字回到左对齐（td.num 的右对齐是表格列对齐语义，卡片里显得离散） */
    table.items-table > tbody > tr > td.num, table.batch-table > tbody > tr > td.num { text-align: left; }

    /* 双栏对比堆叠（值对照 / 覆盖对比卡共用 .compare） */
    .compare { flex-direction: column; gap: 0; }
    .compare-vs { align-self: center; padding: 2px 0; }

    /* 聊天操作区允许折行，按钮不被压成竖排文字 */
    .chat-actions { flex-wrap: wrap; row-gap: 6px; }

    /* 统计卡两列 */
    .stat-card { flex: 1 1 40%; min-width: 0; padding: 10px 14px; }
    .stat-card .stat-num { font-size: 22px; }

    /* 页头 tab 允许换行（dashboard 七个 tab） */
    .page-header .tabs { flex-wrap: wrap; }
    .page-header .tabs a { padding: 5px 10px; font-size: 12.5px; }

    /* 触控加大：翻页与主要 CTA */
    .pager a { padding: 8px 14px; }
    .btn-gold, .btn-blue { padding: 8px 18px; }

    /* 登录卡片收窄 */
    .login-card { width: auto; max-width: calc(100vw - 28px); padding: 26px 22px; }

    /* 字段来源设置「新增规则行」：5 列 grid 降为单列（内联样式需 !important 覆盖） */
    form[action="/field-policy/add"] { grid-template-columns: 1fr !important; }
    form[action="/field-policy/add"] > label,
    form[action="/field-policy/add"] > button { grid-column: 1 / -1 !important; grid-row: auto !important; width: 100% !important; }
    form[action="/field-policy/add"] > * { min-width: 0; }
    form[action="/field-policy/add"] select,
    form[action="/field-policy/add"] input[type="text"],
    form[action="/field-policy/add"] textarea { width: 100%; box-sizing: border-box; }

    /* raw 渲染预览高度收敛 */
    .render-preview { min-height: 320px; }
}
