:root {
  --ink: #0b1220;
  --paper: #f4f6fb;
  --card: #ffffff;
  --line: #e4e9f2;
  --line-soft: #eef2f8;
  --text: #0f172a;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --blue: #2563eb;
  --blue-soft: #e8f0ff;
  --red: #dc2626;
  --red-soft: #fdecec;
  --amber: #d97706;
  --amber-soft: #fef3e2;
  --green: #059669;
  --green-soft: #e6f6ef;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px -16px rgba(15, 23, 42, 0.18);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background:
    radial-gradient(1200px 400px at 100% -10%, rgba(37, 99, 235, 0.06), transparent 60%),
    var(--paper);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
b, strong { font-weight: 650; }
.num, .mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  color: #fff;
  background: linear-gradient(115deg, #0a1120 0%, #12233d 48%, #1b3557 100%);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 10px 30px -20px rgba(2, 6, 23, 0.9);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: #dbeafe;
  background: linear-gradient(150deg, rgba(96, 165, 250, 0.28), rgba(37, 99, 235, 0.14));
  border: 1px solid rgba(147, 197, 253, 0.32);
}

.brand-text h1 { font-size: 16px; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: #9db0cc; }
.brand-text span { color: #cbd8ea; font-variant-numeric: tabular-nums; }

.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: #c7d5e8;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tag b { color: #e8effa; font-weight: 600; }
.tag-sim { color: #fde68a; border-color: rgba(253, 230, 138, 0.28); background: rgba(253, 230, 138, 0.1); }

/* ---------- 布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 396px;
  gap: 18px;
  align-items: start;
  max-width: 1780px;
  margin: 0 auto;
  padding: 18px 24px 48px;
}

.main-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px 18px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-head h3 { font-size: 14px; color: #0f172a; }
.card-head h3::before {
  content: "";
  display: inline-block;
  width: 3px;
  height: 13px;
  margin-right: 8px;
  vertical-align: -2px;
  border-radius: 2px;
  background: linear-gradient(180deg, #60a5fa, #2563eb);
}
.hint { font-size: 12px; color: var(--muted-2); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-top: 2px; }
.section-head h2 { font-size: 15px; }
.skeleton-block { color: var(--muted-2); font-size: 13px; padding: 12px 0; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }

.kpi {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 14px 18px;
  overflow: hidden;
}
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--blue); opacity: 0.85; }
.kpi.red::before { background: var(--red); }
.kpi.amber::before { background: var(--amber); }
.kpi.green::before { background: var(--green); }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { margin-top: 4px; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.kpi .sub { margin-top: 4px; font-size: 12px; color: var(--muted-2); }
.kpi .sub b { color: var(--red); }
.kpi.green .sub b { color: var(--green); }

/* ---------- 三周 ---------- */
.weeks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }

.week {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.week .wk-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.week .wk-name { font-weight: 650; font-size: 13px; }
.week .wk-date { font-size: 12px; color: var(--muted-2); font-variant-numeric: tabular-nums; }
.week .wk-main { display: flex; align-items: baseline; gap: 6px; margin: 8px 0 2px; }
.week .wk-gap { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.week .wk-gap.bad { color: var(--red); }
.week .wk-gap.ok { color: var(--green); }
.week .wk-unit { font-size: 12px; color: var(--muted); }
.week .wk-sub { font-size: 12px; color: var(--muted); }
.week .bar { margin-top: 10px; }

.bar { height: 7px; border-radius: 99px; background: var(--line-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #60a5fa, #2563eb); }
.bar.warn > i { background: linear-gradient(90deg, #fbbf24, #d97706); }
.bar.bad > i { background: linear-gradient(90deg, #f87171, #dc2626); }
.bar.ok > i { background: linear-gradient(90deg, #34d399, #059669); }

/* ---------- 双栏 ---------- */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr); gap: 16px; }
@media (max-width: 1280px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

/* ---------- 重点单 ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--blue);
  background: var(--blue-soft);
  border: 1px solid rgba(37, 99, 235, 0.16);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pill-red { color: var(--red); background: var(--red-soft); border-color: rgba(220, 38, 38, 0.16); }
.pill-amber { color: var(--amber); background: var(--amber-soft); border-color: rgba(217, 119, 6, 0.18); }
.pill-green { color: var(--green); background: var(--green-soft); border-color: rgba(5, 150, 105, 0.16); }
.pill-gray { color: var(--muted); background: #f1f5f9; border-color: var(--line); }

.focus-id { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.focus-id .oid { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.focus-meta { margin-top: 6px; font-size: 12px; color: var(--muted); }

.focus-big { display: flex; align-items: baseline; gap: 8px; margin-top: 14px; }
.focus-big .big { font-size: 30px; font-weight: 750; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.focus-big .of { font-size: 13px; color: var(--muted); }

.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.fact { background: #fafbfe; border: 1px solid var(--line-soft); border-radius: 10px; padding: 9px 11px; }
.fact .k { font-size: 11px; color: var(--muted-2); }
.fact .v { font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; }
.fact .v.bad { color: var(--red); }
.fact .v.ok { color: var(--green); }

.timeline { margin-top: 14px; }
.timeline .tl-title { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.tl-row { display: grid; grid-template-columns: 54px 1fr 74px; gap: 10px; align-items: center; font-size: 12px; padding: 3px 0; }
.tl-row .d { color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-row .n { text-align: right; font-variant-numeric: tabular-nums; color: #334155; }

.donor { margin-top: 12px; font-size: 12px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 10px; }
.donor b { color: #334155; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
.table-wrap.table-tall { max-height: 330px; overflow-y: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted-2);
  background: #fbfcfe;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tbody tr:hover { background: #f9fbff; }
.table .empty { color: var(--muted-2); text-align: center; padding: 22px; }
.table .oid { font-variant-numeric: tabular-nums; font-weight: 600; }
.table .muted { color: var(--muted-2); font-size: 12px; }
.table tr.best { background: linear-gradient(90deg, rgba(37, 99, 235, 0.07), transparent 70%); }
.table tr.best td:first-child { box-shadow: inset 3px 0 0 var(--blue); }
.table tr.clickable { cursor: pointer; }

.mode-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.mode-name .badge {
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  background: var(--blue);
  border-radius: 4px;
  padding: 1px 5px;
  letter-spacing: 0.02em;
}
.mode-reason { font-size: 11px; color: var(--muted-2); font-weight: 400; margin-top: 2px; }

.footnote { margin: 10px 2px 0; font-size: 12px; color: var(--muted-2); }
.footnote b { color: var(--muted); }

/* ---------- 情景表单 ---------- */
.scenario { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.field > span { display: flex; justify-content: space-between; gap: 8px; }
.field > span b { color: var(--text); font-variant-numeric: tabular-nums; }
.field input[type="date"] {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: #fff;
}
.field input[type="date"]:focus { outline: 2px solid rgba(37, 99, 235, 0.25); border-color: var(--blue); }
.field input[type="range"] { width: 100%; accent-color: var(--blue); height: 20px; }
.field-check { flex-direction: row; align-items: center; gap: 8px; grid-column: span 3; }
.field-check input { accent-color: var(--blue); width: 15px; height: 15px; }
.scenario-actions { grid-column: span 3; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 2px; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 9px;
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(180deg, #3b82f6, #2563eb); border-color: #1d4ed8; color: #fff; box-shadow: 0 6px 14px -8px rgba(37, 99, 235, 0.8); }
.btn-primary:hover { background: linear-gradient(180deg, #4f8ef7, #2f6fed); }
.btn-ghost { background: rgba(255, 255, 255, 0.06); color: inherit; border-color: rgba(255, 255, 255, 0.18); }
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }
.main-col .btn-ghost { background: #fff; border-color: var(--line); color: var(--text); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- 逐日推演 ---------- */
.trace { display: flex; flex-direction: column; gap: 2px; max-height: 330px; overflow-y: auto; }
.trace-row { display: grid; grid-template-columns: 52px 1fr 62px 62px; gap: 8px; align-items: center; font-size: 12px; padding: 3px 2px; border-radius: 6px; }
.trace-row.head { color: var(--muted-2); font-size: 11px; position: sticky; top: 0; background: #fff; }
.trace-row .d { color: var(--muted); font-variant-numeric: tabular-nums; }
.trace-row .b { height: 8px; border-radius: 99px; background: var(--line-soft); overflow: hidden; }
.trace-row .b > i { display: block; height: 100%; background: linear-gradient(90deg, #93c5fd, #2563eb); border-radius: 99px; }
.trace-row .v { text-align: right; font-variant-numeric: tabular-nums; }
.trace-row .v.stock { color: var(--muted); }
.trace-row.zero .b > i { background: #e2e8f0; }
.trace-row.zero .v { color: var(--red); }

/* ---------- 风险表 ---------- */
.filters { display: flex; gap: 6px; }
.filters button {
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  cursor: pointer;
}
.filters button b { font-variant-numeric: tabular-nums; }
.filters button.on { color: var(--blue); border-color: rgba(37, 99, 235, 0.3); background: var(--blue-soft); }
.cause { display: inline-block; font-size: 11px; color: var(--red); background: var(--red-soft); border-radius: 5px; padding: 1px 6px; margin-right: 4px; }
.cause.ok { color: var(--green); background: var(--green-soft); }

/* ---------- 聊天 ---------- */
.chat {
  position: sticky;
  top: 78px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 100px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.chat-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.chat-head h3 { font-size: 14px; }
.chat-head p { margin: 2px 0 0; font-size: 11px; color: var(--muted-2); }
.dot { font-size: 11px; color: var(--muted-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.dot.llm { color: var(--green); border-color: rgba(5, 150, 105, 0.3); background: var(--green-soft); }
.dot.rules { color: var(--amber); border-color: rgba(217, 119, 6, 0.3); background: var(--amber-soft); }

.chat-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: #fbfcfe; }
.msg { max-width: 92%; border-radius: 12px; padding: 10px 12px; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-top-left-radius: 4px; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03); }
.msg.user { align-self: flex-end; background: linear-gradient(180deg, #3b82f6, #2563eb); color: #fff; border-top-right-radius: 4px; }
.msg.sys { align-self: center; background: #eef2f8; color: var(--muted); font-size: 12px; }
.msg .meta { display: block; margin-top: 6px; font-size: 10px; color: var(--muted-2); }
.msg .meta b { color: var(--blue); font-weight: 600; }

.chips { display: flex; gap: 6px; padding: 8px 12px 0; flex-wrap: wrap; background: #fff; border-top: 1px solid var(--line-soft); }
.chip {
  font: inherit;
  font-size: 11.5px;
  color: #334155;
  background: #f6f8fc;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { border-color: rgba(37, 99, 235, 0.35); color: var(--blue); background: var(--blue-soft); }

.chat-input { display: flex; gap: 8px; padding: 10px 12px 12px; background: #fff; }
.chat-input textarea {
  flex: 1;
  resize: none;
  font: inherit;
  font-size: 13px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  min-height: 40px;
}
.chat-input textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }

/* ---------- 底部说明 ---------- */
.foot { font-size: 11.5px; color: var(--muted-2); line-height: 1.7; border-top: 1px solid var(--line); padding-top: 12px; }
.foot b { color: var(--muted); }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(15, 23, 42, 0.42); display: grid; place-items: center; padding: 24px; }
.modal-card { position: relative; width: min(760px, 100%); max-height: 84vh; overflow-y: auto; background: #fff; border-radius: 16px; box-shadow: 0 24px 60px -20px rgba(2, 6, 23, 0.5); padding: 22px 24px; }
.modal-close { position: absolute; top: 12px; right: 14px; border: 0; background: transparent; font-size: 22px; line-height: 1; color: var(--muted-2); cursor: pointer; }
.modal-close:hover { color: var(--text); }
.modal h3 { font-size: 17px; margin-bottom: 4px; }
.modal .sub { font-size: 12px; color: var(--muted); margin-bottom: 16px; }
.modal h4 { font-size: 13px; margin: 18px 0 8px; color: #334155; }
.modal .kv { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.modal .kv > div { background: #fafbfe; border: 1px solid var(--line-soft); border-radius: 10px; padding: 8px 10px; }
.modal .kv .k { font-size: 11px; color: var(--muted-2); }
.modal .kv .v { font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .chat { position: static; height: 560px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .weeks { grid-template-columns: minmax(0, 1fr); }
  .scenario { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-check, .scenario-actions { grid-column: span 2; }
}
@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .layout { padding: 14px; }
  .facts, .kpis { grid-template-columns: minmax(0, 1fr); }
  .scenario { grid-template-columns: minmax(0, 1fr); }
  .field-check, .scenario-actions { grid-column: span 1; }
}

/* ---------- 库存构成 ---------- */
.stack { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: var(--line-soft); margin-top: 10px; }
.stack > span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin: 8px 0 12px; font-size: 11.5px; color: var(--muted); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }
.bad-text { color: var(--red); font-weight: 600; }

.modal[hidden] { display: none; }

.msg a { color: var(--blue); text-decoration: underline; word-break: break-all; }
.msg.bot a { color: var(--blue); }
