/* ============================================================
   4Stones 管理后台 —— 设计系统 v2（浅色 + 紫，专业现代运营后台）
   字体：Roboto（正文/表格/按钮）+ Roboto Mono（数字/代号），self-host。
   中文自动回退系统 CJK 字体（Roboto 只含拉丁 + 数字）。
   ============================================================ */
@font-face {
  font-family: 'Roboto'; font-style: normal; font-weight: 300 800; font-display: swap;
  src: url('/static/fonts/roboto-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}
@font-face {
  font-family: 'Roboto Mono'; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url('/static/fonts/roboto-mono-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+2000-206F, U+2212;
}

:root {
  --bg: #f5f6fb; --panel: #fff; --ink: #1c2030; --muted: #6b7089; --faint: #9aa0b8;
  --line: #e9e8f2; --line-2: #f2f1f9; --line-3: #faf9fe;
  --purple: #6c4bd6; --purple-d: #5638bd; --purple-soft: #efecfb; --purple-ring: rgba(108,75,214,.16);
  --green: #12915a; --green-soft: #e6f5ee; --red: #d23f4a; --red-soft: #fdecec;
  --amber: #b26a00; --amber-soft: #fff3e0;
  --shadow-sm: 0 1px 2px rgba(28,32,60,.05);
  --shadow: 0 1px 2px rgba(30,25,70,.04), 0 6px 20px rgba(80,60,160,.06);
  --shadow-lg: 0 16px 48px rgba(40,30,90,.16);
  --mono: 'Roboto Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --sans: 'Roboto', system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', 'Hiragino Sans GB', sans-serif;
  --radius: 12px; --radius-sm: 9px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans); background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; letter-spacing: .1px;
}
h1, h2, h3 { letter-spacing: -.2px; }
/* 文字选中：用高对比蓝，别用接近主色紫的浅色，保证框选一眼可见、文字清晰可读 */
::selection { background: #aacdff; color: #06213f; }
::-moz-selection { background: #aacdff; color: #06213f; }

/* 按钮 */
button {
  font: inherit; font-weight: 500; cursor: pointer; border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 8px 15px; background: var(--purple); color: #fff; transition: background .15s, box-shadow .15s, border-color .15s, transform .05s;
  box-shadow: 0 1px 2px rgba(86,56,189,.18);
}
button:hover { background: var(--purple-d); }
button:active { transform: translateY(.5px); }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--purple-ring); }
button.ghost { background: #fff; color: var(--purple-d); border-color: var(--line); box-shadow: var(--shadow-sm); font-weight: 500; }
button.ghost:hover { background: var(--purple-soft); border-color: var(--purple-soft); }
button.sm { padding: 5px 11px; font-size: 12.5px; border-radius: 8px; }
button:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
button:disabled:hover { background: var(--purple); }
button.ghost:disabled:hover { background: #fff; }

.gname { cursor: pointer; color: var(--purple); font-weight: 600; }
.gname:hover { color: var(--purple-d); text-decoration: underline; }
tr.clickrow { cursor: pointer; }
tr.clickrow:hover td { background: var(--purple-soft); }

/* 表单控件 */
input, select {
  font: inherit; padding: 8px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink); outline: none; transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: var(--faint); }
input:hover, select:hover { border-color: #d7d5e8; }
input:focus, select:focus { border-color: var(--purple); box-shadow: 0 0 0 3px var(--purple-ring); }
input:disabled, select:disabled { background: var(--line-3); color: var(--muted); cursor: not-allowed; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--purple); cursor: pointer; }
input[type=file] { padding: 6px; font-size: 13px; }

a { color: var(--purple-d); cursor: pointer; text-decoration: none; }
a:hover { text-decoration: underline; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: 0; }
.pos { color: var(--green); } .neg { color: var(--red); }

/* 登录 */
/* 启动中性加载占位：默认显示；#login 默认隐藏，由 showLogin 置为 grid（避免已登录刷新闪登录页） */
#boot { min-height: 100vh; display: grid; place-items: center; background: var(--bg); }
#login { display: none; min-height: 100vh; place-items: center; background: radial-gradient(1100px 460px at 50% -12%, #ece6fd, var(--bg)); padding: 20px; }
.login-card { background: var(--panel); padding: 36px 34px; border-radius: 18px; box-shadow: var(--shadow-lg); width: 348px; border: 1px solid var(--line); }
.login-card .logo { width: 42px; height: 42px; border-radius: 11px; background: linear-gradient(135deg, var(--purple), #9b7bef); margin-bottom: 14px; display: grid; place-items: center; color: #fff; font-weight: 800; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; font-weight: 700; }
.login-card h1.brandtext { font-size: 25px; margin-bottom: 6px; }
.login-card p { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.login-card input { width: 100%; margin-bottom: 12px; padding: 10px 12px; }
.login-card button { width: 100%; padding: 11px; font-size: 15px; }
.login-card img { display: block; margin: 6px auto; }
.err { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* 布局 */
#app { display: none; min-height: 100vh; grid-template-columns: 232px 1fr; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; font-weight: 800; font-size: 17px; }
.sidebar .brand .logo { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--purple), #9b7bef); display: grid; place-items: center; color: #fff; font-size: 15px; }
.brandtext { color: var(--purple-d); font-weight: 800; letter-spacing: -.4px; }
.navitem { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--muted); cursor: pointer; font-weight: 500; margin-bottom: 2px; transition: background .12s, color .12s; }
.navitem:hover { background: var(--line-2); color: var(--ink); text-decoration: none; }
.navitem.active { background: var(--purple-soft); color: var(--purple-d); font-weight: 600; box-shadow: inset 3px 0 0 var(--purple) }
.navitem .ico { width: 18px; text-align: center; }
.navitem .badge { margin-left: auto; background: var(--red); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 600; }
/* 侧边栏分组小标题；测试专区(.test)上方加分隔线，与正式功能明显隔开 */
.navgroup { color: var(--faint); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 15px 12px 5px; }
.navgroup.test { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 13px; }
.sidebar .foot { margin-top: auto; color: var(--faint); font-size: 12px; padding: 10px; }

.content { display: flex; flex-direction: column; min-width: 0; }
.topbar { background: rgba(255,255,255,.85); backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--line); padding: 13px 24px; display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 16px; margin: 0; font-weight: 700; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; font-weight: 500; }
main { padding: 22px 24px 52px; }

/* 卡片 */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card h2 { font-size: 14px; margin: 0 0 14px; font-weight: 700; }
.card .sub { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }

/* 统计卡片 */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(184px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); transition: box-shadow .15s, transform .15s; }
.stat:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 500; margin-bottom: 8px; }
.stat .value { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 25px; font-weight: 600; letter-spacing: -.5px; }
.stat .unit { font-size: 14px; color: var(--faint); font-weight: 600; margin-right: 3px; }
.stat.alert { border-color: #f6c9c9; background: linear-gradient(0deg, var(--red-soft), #fff); }
.stat.alert .value { color: var(--red); }

/* 图表 */
.chart-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 16px; }
.chart-box { position: relative; height: 260px; }
@media (max-width: 1100px) { .chart-grid { grid-template-columns: 1fr; } }

/* 过滤条 / 分段 */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters label { font-size: 12px; color: var(--muted); font-weight: 500; display: flex; flex-direction: column; gap: 5px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--shadow-sm); }
.seg button { background: #fff; color: var(--muted); border-radius: 0; border: none; border-right: 1px solid var(--line); padding: 7px 14px; box-shadow: none; font-weight: 500; }
.seg button:last-child { border-right: none; }
.seg button:hover { background: var(--line-2); color: var(--ink); }
.seg button.active { background: var(--purple); color: #fff; }
.seg button.active:hover { background: var(--purple-d); }
/* 游戏页工具区·第一行：+新增游戏 / 归档 / （右侧）搜索框 —— 34px 等高一条线 */
.gmtoolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.gmtoolbar button, .gmtoolbar input { height: 34px; box-sizing: border-box; padding-top: 0; padding-bottom: 0; flex-shrink: 0; }
.gmtoolbar button { display: inline-flex; align-items: center; white-space: nowrap; }

/* 游戏页工具区·第二行：游戏商筛选（全部 + 品牌 chip，可折叠）。默认只显示一行，点「展开」铺开全部 */
.gmbrandbar { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 12px; }
.gmbrands { display: flex; flex-wrap: wrap; gap: 6px; overflow: hidden; max-height: 34px; flex: 1; min-width: 0; }
.gmbrands.expanded { max-height: none; overflow: visible; }         /* 展开：换行铺满显示全部品牌 */
.gmchip, .gmbrands button {
  height: 34px; box-sizing: border-box; white-space: nowrap; flex-shrink: 0;
  background: #fff; color: var(--muted); border: 1px solid var(--line); border-radius: 8px;
  padding: 0 12px; font-weight: 500; box-shadow: var(--shadow-sm); display: inline-flex; align-items: center;
}
.gmchip:hover, .gmbrands button:hover { background: var(--line-2); color: var(--ink); }
.gmchip.active, .gmbrands button.active { background: var(--purple); color: #fff; border-color: var(--purple); }
.gmexpand { flex-shrink: 0; height: 34px; box-sizing: border-box; padding-top: 0; padding-bottom: 0; display: inline-flex; align-items: center; white-space: nowrap; }

/* 表格 */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; background: var(--line-3); position: sticky; top: 0; z-index: 1; }
tbody tr { transition: background .1s; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--line-2); }
td.r, th.r { text-align: right; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.6; }
.tag.on, .tag.settled { background: var(--green-soft); color: var(--green); }
.tag.off { background: #eef0f4; color: var(--muted); }
.tag.open { background: var(--purple-soft); color: var(--purple-d); }
.tag.pending, .tag.pending_recon { background: var(--amber-soft); color: var(--amber); }
.tag.rolled_back, .tag.cancelled { background: #eef0f4; color: var(--muted); }
.tag.failed { background: var(--red-soft); color: var(--red); }

/* 游戏管理表格 */
.gametable table { font-size: 13.5px; }
.gametable th, .gametable td { padding: 12px 16px; vertical-align: middle; }
.gametable tbody td:first-child { font-weight: 600; }
/* 游戏列表固定列宽：切换「全部」/品牌 tab 时每列位置与宽度像素级一致（列宽由 colgroup 定） */
.gmfixed { table-layout: fixed; }
.gmfixed td .actions { flex-wrap: wrap; }
/* 游戏列表：所有格子强制单行，放不下省略号（悬浮 title 看全文）；操作按钮由行内 flex-wrap:nowrap 保持单行 */
.gmgames td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 游戏/游戏商/供应商三页（都在 #gmBody 里）：名字列不特殊加粗，与整表其它列一套字 */
#gmBody .gametable tbody td:first-child { font-weight: 400; }
.gcode { color: var(--muted); font-size: 12.5px; font-weight: 400; font-family: var(--mono); font-variant-numeric: tabular-nums; cursor: help; }
.actions { display: inline-flex; gap: 6px; flex-wrap: nowrap; align-items: center; }
.actions .sm { white-space: nowrap; }

/* 分页 */
.pager { display: flex; align-items: center; gap: 10px; margin-top: 14px; color: var(--muted); font-size: 13px; }
.pager .spacer { flex: 1; }

/* 空/加载 */
.empty { color: var(--muted); padding: 40px; text-align: center; font-size: 13.5px; }
.empty .big { font-size: 34px; margin-bottom: 8px; }
.empty.neg { color: var(--red); }
.loading { color: var(--muted); padding: 32px; text-align: center; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--purple-soft); border-top-color: var(--purple); border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translate(-50%, 12px); background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 11px; font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .22s, transform .22s; z-index: 50; box-shadow: var(--shadow-lg); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }

.hint { color: var(--muted); font-size: 12px; margin-top: 10px; line-height: 1.6; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; }
.checks label { display: flex; align-items: center; gap: 6px; color: var(--ink); font-size: 13px; flex-direction: row; }
code.j { font-family: var(--mono); font-size: 12px; color: var(--muted); max-width: 320px; display: inline-block; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }

/* 弹层 */
.modal-bg { position: fixed; inset: 0; background: rgba(28,32,60,.34); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 40; padding: 20px; animation: fadein .15s ease; }
.modal { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 24px; width: min(760px, 96vw); max-height: 88vh; overflow: auto; box-shadow: var(--shadow-lg); animation: pop .16s ease; }
.modal h3 { margin: 0 0 6px; font-size: 16px; font-weight: 700; }
.modal .close { float: right; }
@keyframes fadein { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* 右侧抽屉（编辑/新增表单） */
.drawer-bg { position: fixed; inset: 0; background: rgba(28,32,60,.34); backdrop-filter: blur(2px); z-index: 40; display: flex; justify-content: flex-end; animation: fadein .15s ease; }
.drawer { background: #fff; height: 100%; width: min(460px, 96vw); box-shadow: -16px 0 48px rgba(40,30,90,.16); border-left: 1px solid var(--line); padding: 24px; overflow: auto; animation: slidein .22s cubic-bezier(.2,.7,.2,1); }
.drawer h3 { margin: 0 0 10px; font-size: 16px; font-weight: 700; }
.drawer .close { float: right; }
@keyframes slidein { from { transform: translateX(46px); opacity: .4; } }
