:root {
  --bg: #0f1420;
  --bg-2: #161c2c;
  --panel: #1b2334;
  --panel-2: #212b3f;
  --border: #2a3550;
  --text: #e6ebf5;
  --text-2: #9aa7c2;
  --text-3: #6b779a;
  --primary: #4f7cff;
  --primary-soft: rgba(79, 124, 255, 0.15);
  --green: #22c58b;
  --green-soft: rgba(34, 197, 139, 0.14);
  --red: #ff5c72;
  --red-soft: rgba(255, 92, 114, 0.14);
  --orange: #ffab3d;
  --orange-soft: rgba(255, 171, 61, 0.14);
  --purple: #a56bff;
  --cyan: #34d3e0;
  --yellow: #f5c542;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 232px;
  background: linear-gradient(180deg, #141b2b, #10151f);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 20px 16px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px; color: #fff;
  box-shadow: 0 6px 18px rgba(79,124,255,.4);
}
.brand-title { font-weight: 700; font-size: 16px; letter-spacing: .3px; }
.brand-sub { font-size: 11px; color: var(--text-3); }

.menu { flex: 1; overflow-y: auto; padding: 8px 12px; }
.menu-group { font-size: 11px; color: var(--text-3); padding: 14px 12px 6px; letter-spacing: 1px; }
.menu-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  color: var(--text-2); font-weight: 500; user-select: none;
  transition: all .15s;
}
.menu-item:hover { background: var(--panel); color: var(--text); }
.menu-item.active { background: var(--primary-soft); color: #fff; }
.menu-item.active .mi-icon { transform: scale(1.1); }
.mi-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer { border-top: 1px solid var(--border); padding: 14px; }
.user-mini { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--green), var(--cyan));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #06231b;
}
.um-name { font-size: 13px; font-weight: 600; }
.um-role { font-size: 11px; color: var(--text-3); }

/* ---------- 主区 ---------- */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: 64px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 26px; border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.topbar-left { display: flex; align-items: baseline; gap: 12px; }
.topbar-left h1 { font-size: 19px; font-weight: 700; }
.crumb { font-size: 12px; color: var(--text-3); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.env-badge { font-size: 12px; background: var(--green-soft); color: var(--green); padding: 6px 12px; border-radius: 20px; font-weight: 600; }

/* 游戏切换器 */
.game-switcher { position: relative; }
.gs-current { display: flex; align-items: center; gap: 9px; background: var(--panel); border: 1px solid var(--border); padding: 6px 12px; border-radius: 10px; cursor: pointer; font-weight: 600; min-width: 168px; }
.gs-current:hover { border-color: var(--primary); }
.gs-ic { width: 24px; height: 24px; border-radius: 7px; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.gs-name { flex: 1; font-size: 13px; }
.gs-caret { color: var(--text-3); font-size: 10px; }
.gs-menu { position: absolute; top: calc(100% + 8px); right: 0; width: 260px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 30; display: none; }
.gs-menu.show { display: block; }
.gs-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; cursor: pointer; }
.gs-item:hover { background: var(--panel); }
.gs-item.active { background: var(--primary-soft); }
.gs-item .gs-ic { width: 30px; height: 30px; font-size: 16px; }
.gs-item .gi-sub { font-size: 11px; color: var(--text-3); }
.gs-item .gi-name { font-size: 13px; font-weight: 600; }
.game-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 9px; border-radius: 20px; font-weight: 600; }

/* 期间切换 tab */
.period-tab { transition: all .15s; }
.period-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* 奖品图片缩略图（点击可上传替换） */
.prize-thumb { position: relative; width: 56px; height: 56px; border-radius: 10px; overflow: hidden; cursor: pointer; border: 1px solid var(--border); background: var(--panel-2); }
.prize-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.prize-thumb-mask { position: absolute; inset: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; font-weight: 600; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .15s; }
.prize-thumb:hover .prize-thumb-mask { opacity: 1; }
.prize-thumb:hover { border-color: var(--primary); }
.date-pill { font-size: 12px; color: var(--text-2); background: var(--panel); padding: 6px 12px; border-radius: 20px; }
.bell { position: relative; cursor: pointer; font-size: 17px; }
.bell .dot { position: absolute; top: -2px; right: -2px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }

.content { flex: 1; overflow-y: auto; padding: 24px 26px 60px; }

/* ---------- 通用组件 ---------- */
.grid { display: grid; gap: 16px; }
.cols-5 { grid-template-columns: repeat(5, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1400px) { .cols-5 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 1200px) { .cols-5 { grid-template-columns: repeat(2, 1fr); } .cols-4 { grid-template-columns: repeat(2, 1fr); } }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 700; }
.card-sub { font-size: 12px; color: var(--text-3); }

/* KPI 卡片 */
.kpi { position: relative; overflow: hidden; }
.kpi-label { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 7px; }
.kpi-ic { width: 30px; height: 30px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 15px; }
.kpi-value { font-size: 28px; font-weight: 800; margin: 12px 0 6px; letter-spacing: .5px; }
.kpi-trend { font-size: 12px; font-weight: 600; }
.up { color: var(--green); }
.down { color: var(--red); }
.kpi-spark { position: absolute; right: 0; bottom: 0; width: 100px; height: 44px; opacity: .5; }

.tag { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.tag-green { background: var(--green-soft); color: var(--green); }
.tag-red { background: var(--red-soft); color: var(--red); }
.tag-orange { background: var(--orange-soft); color: var(--orange); }
.tag-blue { background: var(--primary-soft); color: var(--primary); }
.tag-gray { background: var(--panel-2); color: var(--text-2); }
.tag-purple { background: rgba(165,107,255,.15); color: var(--purple); }

/* 表格 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--text-3); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 13px 14px; border-bottom: 1px solid rgba(42,53,80,.5); font-size: 13px; white-space: nowrap; }
tbody tr:hover { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: none; }

.u-cell { display: flex; align-items: center; gap: 10px; }
.u-av { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; color: #fff; }

/* 按钮 */
.btn { border: 1px solid var(--border); background: var(--panel-2); color: var(--text); padding: 7px 14px; border-radius: 9px; font-size: 13px; cursor: pointer; font-weight: 600; transition: all .15s; }
.btn:hover { border-color: var(--primary); color: #fff; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #3f6cf0; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); color: var(--red); }

/* 工具条 */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.input, .select { background: var(--panel); border: 1px solid var(--border); color: var(--text); padding: 8px 12px; border-radius: 9px; font-size: 13px; outline: none; }
.input:focus, .select:focus { border-color: var(--primary); }
.input::placeholder { color: var(--text-3); }
.spacer { flex: 1; }

/* 进度条 */
.bar { height: 7px; background: var(--panel-2); border-radius: 20px; overflow: hidden; min-width: 90px; }
.bar-fill { height: 100%; border-radius: 20px; }

.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }

/* 表单（配置页） */
.form-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid rgba(42,53,80,.5); }
.form-row:last-child { border-bottom: none; }
.fr-label { font-weight: 600; }
.fr-desc { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.fr-control { display: flex; align-items: center; gap: 8px; }
.num-input { width: 90px; text-align: center; }
.unit { font-size: 12px; color: var(--text-3); }
.switch { width: 44px; height: 24px; background: var(--panel-2); border-radius: 20px; position: relative; cursor: pointer; transition: .2s; }
.switch.on { background: var(--green); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: .2s; }
.switch.on::after { left: 23px; }

/* 抽屉 */
.drawer-mask { position: fixed; inset: 0; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: .2s; z-index: 40; }
.drawer-mask.show { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: -520px; width: 520px; max-width: 92vw; height: 100vh; background: var(--bg-2); border-left: 1px solid var(--border); z-index: 50; transition: right .25s; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.drawer.show { right: 0; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { font-size: 16px; }
.drawer-close { cursor: pointer; color: var(--text-3); font-size: 16px; }
.drawer-close:hover { color: var(--text); }
.drawer-body { flex: 1; overflow-y: auto; padding: 22px; }

/* toast */
.toast { position: fixed; top: 24px; left: 50%; transform: translateX(-50%) translateY(-80px); background: var(--panel); border: 1px solid var(--border); color: var(--text); padding: 12px 22px; border-radius: 10px; box-shadow: var(--shadow); z-index: 99; opacity: 0; transition: .25s; font-weight: 600; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.ok { border-color: var(--green); }

/* 状态机步骤 */
.steps { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); }
.step .dot2 { width: 9px; height: 9px; border-radius: 50%; background: var(--border); }
.step.done .dot2 { background: var(--green); }
.step.done { color: var(--green); }
.step .arr { color: var(--text-3); }

.detail-row { display: flex; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid rgba(42,53,80,.5); font-size: 13px; }
.detail-row .k { color: var(--text-3); }
.detail-row .v { font-weight: 600; }
.section-title { font-size: 13px; color: var(--text-3); margin: 20px 0 8px; letter-spacing: .5px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; }
.legend span { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; }

/* 字段说明「!」图标 + tooltip（tooltip 由 JS 挂到 body 上，避免被容器裁剪） */
.help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 50%;
  border: 1px solid var(--text-3); color: var(--text-3);
  font-size: 10px; font-weight: 700; font-style: normal; line-height: 1;
  margin-left: 4px; cursor: help; vertical-align: middle; user-select: none;
  flex-shrink: 0;
}
.help:hover { border-color: var(--primary); color: var(--primary); }

/* 全局 tooltip（挂到 body） */
#tipEl {
  position: fixed; z-index: 9999; pointer-events: none;
  background: #0b0f18; color: var(--text); border: 1px solid var(--border);
  padding: 7px 10px; border-radius: 8px; font-size: 12px; font-weight: 500;
  line-height: 1.5; box-shadow: var(--shadow); max-width: 260px;
  opacity: 0; transform: translateY(4px); transition: opacity .12s, transform .12s;
  white-space: normal;
}
#tipEl.show { opacity: 1; transform: translateY(0); }
#tipEl::before {
  content: ""; position: absolute; left: 50%; transform: translateX(-50%);
  border: 5px solid transparent;
}
#tipEl.above::before { top: 100%; border-top-color: var(--border); }
#tipEl.below::before { bottom: 100%; border-bottom-color: var(--border); }
