:root {
  --bg: #f4f5f7; --panel: #ffffff; --panel-2: #f8f9fb; --text: #18202d; --text-2: #4b5565; --muted: #8a93a3;
  --line: #e4e7ec; --line-2: #eef0f3; --accent: #3b5bdb; --accent-soft: #e8edfd;
  --hit: #1f8a4c; --hit-soft: #e3f4ea; --miss: #c92a2a; --miss-soft: #fbe7e7; --tie: #6b7280; --tie-soft: #eef0f3;
  --warn: #b25e09; --warn-soft: #fdf1e1; --banker: #d6336c; --player: #1c7ed6; --tiecol: #2f9e44;
  --sidebar: #141a24; --sidebar-text: #aab3c2; --sidebar-active: #ffffff;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131a; --panel: #171c25; --panel-2: #1c222d; --text: #e7ebf1; --text-2: #b4bccb; --muted: #7d8696;
    --line: #283040; --line-2: #222a36; --accent: #7c95f5; --accent-soft: #232c45;
    --hit: #4cc27a; --hit-soft: #173225; --miss: #f0716f; --miss-soft: #3a1c1d; --tie: #9aa3b2; --tie-soft: #262d38;
    --warn: #f0a547; --warn-soft: #3a2a14; --banker: #f06595; --player: #4dabf7; --tiecol: #51cf66;
    --sidebar: #0b0f15; --sidebar-text: #8d97a8;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--hit); } .neg { color: var(--miss); }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ shell */
.app { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { color: #fff; font-weight: 600; font-size: 16px; padding: 4px 10px 18px; display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, #4c6ef5, #d6336c); display: grid; place-items: center; font-size: 14px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--sidebar-text); font-size: 14px; }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: rgba(255, 255, 255, .1); color: var(--sidebar-active); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; background: var(--warn); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.sidebar-foot { margin-top: auto; padding: 10px; font-size: 12px; line-height: 1.7; }
.sidebar-foot .dot { margin-right: 6px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding: 12px 28px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.topbar .status { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 12px; color: var(--text-2); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.ok { background: var(--hit); } .dot.bad { background: var(--miss); } .dot.warn { background: var(--warn); }
.view { padding: 22px 28px 48px; display: flex; flex-direction: column; gap: 18px; max-width: 1480px; width: 100%; }

.alerts { display: flex; flex-direction: column; gap: 8px; }
.alerts:empty { display: none; }
.alert { display: flex; gap: 10px; align-items: flex-start; background: var(--warn-soft); color: var(--warn); border-radius: var(--radius); padding: 10px 14px; font-size: 13px; }
.alert.bad { background: var(--miss-soft); color: var(--miss); }
.alert b { font-weight: 600; }

/* ------------------------------------------------------------ building blocks */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.card-head h2 { font-size: 15px; margin: 0; font-weight: 600; }
.card-head .sub { color: var(--muted); font-size: 12px; }
.card-head .tools { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-body { padding: 16px 18px; }
.card-body.flush { padding: 0; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid.with-aside { grid-template-columns: 390px minmax(0, 1fr); align-items: start; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 24px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.hero { background: linear-gradient(135deg, var(--accent), #6d4bd8); color: #fff; border: 0; }
.kpi.hero .label, .kpi.hero .hint { color: rgba(255, 255, 255, .78); }
.kpi.hero .pos, .kpi.hero .neg { color: #fff; }

.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: none; padding: 4px 12px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-size: 13px; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); font-weight: 500; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 13px; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--miss); }
.btn:disabled { opacity: .5; cursor: default; }

.input, select.input, textarea.input { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 10px; font-size: 13px; min-width: 0; }
.input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
.field .input { width: 100%; font-size: 14px; color: var(--text); }
.field .help { color: var(--muted); font-size: 11px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px 14px; }
.fields .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--tie-soft); color: var(--tie); }
.badge.HIT { background: var(--hit-soft); color: var(--hit); }
.badge.MISS { background: var(--miss-soft); color: var(--miss); }
.badge.PENDING { background: var(--accent-soft); color: var(--accent); }
.badge.LATE, .badge.VOID { background: var(--tie-soft); color: var(--tie); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.side { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 600; }
.side.BANKER { background: var(--banker); } .side.PLAYER { background: var(--player); } .side.TIE { background: var(--tiecol); } .side.UNKNOWN { background: var(--muted); }

/* tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { position: sticky; top: 0; background: var(--panel-2); color: var(--muted); font-weight: 500; text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; font-size: 12px; }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); white-space: nowrap; vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--panel-2); }
table.data tr.clickable { cursor: pointer; }
table.data tr.expand td { background: var(--panel-2); white-space: normal; padding: 12px 16px; }
table.data .bar-cell { min-width: 140px; }
.empty { padding: 28px; text-align: center; color: var(--muted); font-size: 13px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--line-2); font-size: 12px; color: var(--muted); }

.meter { display: flex; align-items: center; gap: 8px; }
.meter .track { flex: 1; height: 6px; border-radius: 3px; background: var(--line-2); overflow: hidden; min-width: 60px; }
.meter .fill { height: 100%; background: var(--accent); border-radius: 3px; }
.meter .fill.good { background: var(--hit); } .meter .fill.bad { background: var(--miss); }
.meter span { min-width: 48px; text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }
.split { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--line-2); }
.split i { display: block; height: 100%; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px 18px; font-size: 13px; }
.detail-grid dt { color: var(--muted); font-size: 12px; }
.detail-grid dd { margin: 0; }
.raw { white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-top: 10px; color: var(--text-2); }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.feed li:last-child { border-bottom: 0; }
.feed .when { color: var(--muted); font-size: 12px; width: 64px; flex: none; font-variant-numeric: tabular-nums; }
.feed .what { flex: 1; min-width: 0; }

/* table cards (桌台采集) */
.tables { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.tcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.tcard:hover { border-color: var(--muted); }
.tcard.watch { border-color: var(--warn); box-shadow: 0 0 0 1px var(--warn) inset; }
.tcard.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.tcard .top { display: flex; align-items: baseline; gap: 8px; }
.tcard .code { font-weight: 600; font-size: 15px; }
.tcard .round { margin-left: auto; color: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.tcard .stats { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tcard .state { font-size: 12px; color: var(--muted); min-height: 18px; }

/* charts */
.chart svg { width: 100%; display: block; }
.chart .axis { stroke: var(--line); }
.chart .grid-line { stroke: var(--line-2); }
.chart .ref { stroke: var(--muted); stroke-dasharray: 4 4; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .area { fill: var(--accent); opacity: .08; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--accent); }
.chart .bar.good { fill: var(--hit); } .chart .bar.bad { fill: var(--miss); }

/* simulator */
.sim-config { position: sticky; top: 74px; max-height: calc(100vh - 92px); overflow: auto; }
details.group { border-bottom: 1px solid var(--line-2); }
details.group:last-of-type { border-bottom: 0; }
details.group > summary { list-style: none; cursor: pointer; padding: 12px 18px; font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 8px; }
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::before { content: '▸'; color: var(--muted); transition: transform .15s; }
details.group[open] > summary::before { transform: rotate(90deg); }
details.group > summary .sub { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: auto; }
details.group .fields { padding: 0 18px 16px; grid-template-columns: 1fr 1fr; }
.sim-actions { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; position: sticky; bottom: 0; background: var(--panel); }
.radio-row { display: flex; flex-direction: column; gap: 6px; }
.placeholder { display: grid; place-items: center; text-align: center; color: var(--muted); min-height: 320px; padding: 24px; }
.placeholder b { color: var(--text); display: block; font-size: 15px; margin-bottom: 6px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line-2); padding: 0 12px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 11px 12px; cursor: pointer; color: var(--muted); font-size: 13px; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }
.note { font-size: 12px; color: var(--muted); padding: 10px 18px; background: var(--panel-2); border-bottom: 1px solid var(--line-2); }

.toast { position: fixed; right: 24px; bottom: 24px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; z-index: 20; }
.toast.show { opacity: 1; transform: none; }

/* ------------------------------------------------------------ narrow screens */
@media (max-width: 1100px) {
  .grid.two, .grid.with-aside { grid-template-columns: minmax(0, 1fr); }
  .sim-config { position: static; max-height: none; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center; padding: 8px 12px; overflow-x: auto; }
  .brand { padding: 0 8px 0 0; font-size: 0; }
  .nav { display: flex; gap: 2px; }
  .nav a { padding: 7px 9px; font-size: 13px; white-space: nowrap; }
  .nav a svg { display: none; }
  .sidebar-foot { display: none; }
  .topbar { position: static; padding: 12px 16px; }
  .view { padding: 16px; }
  details.group .fields { grid-template-columns: 1fr; }
}
