:root {
    --red: #e60012;
    --red-dark: #b8000e;
    --red-soft: #fff1f1;
    --bg: #f6f6f8;
    --card: #fff;
    --text: #1f2329;
    --muted: #8a8f99;
    --line: #e8e9ec;
    --veto: #7a0010;
    --high: #e60012;
    --medium: #f59a00;
    --low: #2e9d5b;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .04);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
    color: var(--text);
    background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; font-size: 14px; line-height: 1.6; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.4em; margin: 8px 0 0; }
h1, h2, h3 { margin: 0; }

/* 按钮与表单 */
.btn {
    border: 1px solid var(--line); background: #fff; color: var(--text);
    padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
    transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: #cfd2d8; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; padding: 10px; }
.btn.ok { border-color: var(--low); color: var(--low); }
.btn.warn { border-color: var(--medium); color: #b56f00; }
.btn.bad { border-color: var(--high); color: var(--high); }
input, select, textarea {
    font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
    background: #fff; color: var(--text); outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(230, 0, 18, .08); }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; }

/* 登录 */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #e60012 0%, #ff5a5f 45%, #fff3f0 45.2%); }
.login-card { width: min(380px, 92vw); background: #fff; border-radius: 18px; padding: 32px 28px; box-shadow: 0 20px 60px rgba(150, 0, 10, .18); display: grid; gap: 14px; text-align: center; }
.login-card label { text-align: left; }
.brand-mark { width: 56px; height: 56px; margin: 0 auto; border-radius: 16px; background: var(--red); color: #fff; font-weight: 700; font-size: 26px; display: grid; place-items: center; }
.brand-mark.sm { width: 30px; height: 30px; font-size: 15px; border-radius: 8px; margin: 0; }

/* 布局 */
.layout { display: grid; grid-template-columns: 200px 1fr; grid-template-rows: 56px 1fr; height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.store-pick { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.store-pick select { margin: 0; min-width: 220px; }
.user-badge { padding: 4px 10px; border-radius: 999px; background: var(--red-soft); color: var(--red-dark); font-size: 13px; white-space: nowrap; }
.nav { background: #fff; border-right: 1px solid var(--line); padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav button { all: unset; cursor: pointer; padding: 9px 12px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; }
.nav button:hover { background: #f4f4f6; }
.nav button.active { background: var(--red-soft); color: var(--red-dark); font-weight: 600; }
.nav .dot { min-width: 18px; height: 18px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; display: grid; place-items: center; padding: 0 5px; }
.view { overflow-y: auto; padding: 20px 24px 40px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { font-size: 18px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar select { width: auto; }

.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 14px; }
.empty { text-align: center; color: var(--muted); padding: 48px 0; }

/* 对话 */
.chat { display: grid; grid-template-rows: auto 1fr auto; height: calc(100vh - 56px - 60px); background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.agent-tabs { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.agent-tab { all: unset; cursor: pointer; padding: 6px 14px; border-radius: 999px; background: #f4f4f6; white-space: nowrap; font-size: 13px; }
.agent-tab.active { background: var(--red); color: #fff; }
.agent-tab.off { opacity: .45; cursor: not-allowed; }
.msgs { overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 14px; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--red); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.agent { align-self: flex-start; background: #f5f6f8; border-bottom-left-radius: 4px; }
.msg .status { color: var(--muted); font-size: 12px; }
.msg.agent .md > :first-child { margin-top: 0; }
.msg.agent .md > :last-child { margin-bottom: 0; }
.intro { color: var(--muted); text-align: center; margin: auto; max-width: 460px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.chip { all: unset; cursor: pointer; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; color: var(--text); background: #fff; }
.chip:hover { border-color: var(--red); color: var(--red); }
.composer { display: flex; gap: 10px; padding: 12px; border-top: 1px solid var(--line); }
.composer textarea { resize: none; height: 44px; max-height: 160px; }

/* Markdown */
.md h1, .md h2, .md h3, .md h4 { margin: 12px 0 6px; font-size: 15px; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md code { background: rgba(0, 0, 0, .06); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.md pre { background: #23262d; color: #e8e8e8; padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 6px 0; padding: 4px 12px; border-left: 3px solid var(--medium); background: #fff9ec; color: #6b5200; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 13px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.md th { background: #fafafa; }

/* 建议卡片 */
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; border-left: 4px solid var(--low); display: flex; flex-direction: column; gap: 10px; }
.card.veto { border-left-color: var(--veto); }
.card.high { border-left-color: var(--high); }
.card.medium { border-left-color: var(--medium); }
.card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card-title { font-weight: 600; font-size: 15px; }
.card-meta { font-size: 12px; color: var(--muted); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap; background: #f0f1f3; color: #555; }
.tag.veto { background: var(--veto); color: #fff; }
.tag.high { background: var(--high); color: #fff; }
.tag.medium { background: #fff3dc; color: #a46400; }
.tag.low { background: #e6f6ec; color: #1f7a45; }
.tag.ok { background: #e6f6ec; color: #1f7a45; }
.tag.warn { background: #fff3dc; color: #a46400; }
.tag.bad { background: var(--red-soft); color: var(--red-dark); }
.sec-title { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.evidence { width: 100%; border-collapse: collapse; font-size: 12px; }
.evidence td, .evidence th { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; }
.evidence th { color: var(--muted); font-weight: 400; }
.card ol { margin: 0; padding-left: 20px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding-top: 4px; border-top: 1px dashed var(--line); }
.card-actions input { flex: 1; min-width: 140px; }
.edit-grid { display: grid; gap: 8px; }
.edit-grid textarea { min-height: 70px; }

/* 看板 */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 700; }
.kpi .k { color: var(--muted); font-size: 12px; }
.kpi .t { font-size: 12px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; }
.table th { color: var(--muted); font-weight: 400; }

/* 列表 */
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: none; }
.list-item.block { display: block; }
.mt { margin-top: 12px; }
.list-item.unread .li-title { font-weight: 600; }
.li-title { cursor: pointer; }
.steps { margin: 6px 0 0; padding-left: 18px; font-size: 12px; color: var(--muted); }
details summary { cursor: pointer; }
.report-body { margin-top: 10px; }

.toast { position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%); background: rgba(30, 30, 30, .92); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 99; max-width: 80vw; }

@media (max-width: 780px) {
    .layout { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; height: auto; min-height: 100vh; }
    .topbar { flex-wrap: wrap; height: auto; padding: 10px 12px; gap: 8px; }
    .top-actions { flex-wrap: wrap; width: 100%; }
    .store-pick select { min-width: 0; }
    .nav { flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); padding: 8px; }
    .nav button { white-space: nowrap; }
    .view { padding: 14px 12px 32px; }
    .chat { height: calc(100vh - 170px); }
    .cards { grid-template-columns: 1fr; }
    .msg { max-width: 92%; }
}
