:root {
    --bg: #f3f5f9;
    --panel: #ffffff;
    --line: #e3e8ef;
    --text: #111827;
    --muted: #6b7280;
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --brand-soft: #eff6ff;
    --green: #15803d;
    --green-bg: #dcfce7;
    --red: #b91c1c;
    --red-bg: #fee2e2;
    --amber: #b45309;
    --amber-bg: #fef3c7;
    --sidebar: #0f172a;
    --sidebar-2: #1e293b;
    --xbox: #107c10;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 10px 30px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    background: var(--bg); color: var(--text);
    font-family: "Segoe UI", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
    font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; }
.mono { font-family: Consolas, "Courier New", monospace; }
.mono.big { font-size: 18px; font-weight: 700; letter-spacing: .3px; }
.muted { color: var(--muted); }
.ok { color: var(--green); }
.bad { color: var(--red); }
.hint { color: var(--muted); font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 232px; flex-shrink: 0; background: var(--sidebar); color: #e2e8f0;
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 18px 16px; border-bottom: 1px solid #24324a; }
.brand .logo {
    width: 36px; height: 36px; border-radius: 9px; background: var(--xbox); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 19px;
    box-shadow: 0 0 0 3px rgba(16, 124, 16, .18);
}
.brand-text b { display: block; font-size: 13.5px; color: #fff; line-height: 1.3; }
.brand-text small { color: #93a3b8; font-size: 11px; }
.nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a {
    display: flex; align-items: center; gap: 10px; color: #cbd5e1; padding: 9px 12px;
    border-radius: 7px; font-size: 13px; text-decoration: none;
}
.nav a span { width: 16px; text-align: center; color: #64748b; font-size: 13px; }
.nav a:hover { background: var(--sidebar-2); color: #fff; }
.nav a.active { background: var(--brand); color: #fff; box-shadow: 0 4px 14px rgba(37, 99, 235, .35); }
.nav a.active span { color: #dbeafe; }
.sidebar-foot { padding: 12px 16px 16px; border-top: 1px solid #24324a; font-size: 12px; }
.engine-line { display: flex; align-items: center; gap: 7px; color: #cbd5e1; margin-bottom: 5px; }
.engine-line .worker-id { color: #64748b; font-size: 10.5px; margin-left: auto; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #64748b; display: inline-block; flex-shrink: 0; }
.dot.online, .dot.real { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .15); }
.dot.offline { background: #ef4444; }
.dot.mock { background: #f59e0b; }
.user-line { color: #f8fafc; margin: 10px 0 6px; font-weight: 600; }
.user-line small { color: #94a3b8; font-weight: 400; margin-left: 4px; }
.sidebar-links { display: flex; gap: 14px; align-items: center; }
.sidebar-links a { color: #93c5fd; }
.link-btn { background: none; border: none; color: #93c5fd; cursor: pointer; padding: 0; font: inherit; }
.link-btn:hover { text-decoration: underline; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 14px 28px; background: var(--panel); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; font-weight: 700; line-height: 1.3; }
.topbar-sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.topbar-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.content { padding: 22px 28px 56px; max-width: 1500px; }

/* ---------- Flash / Toast ---------- */
.flash-stack { padding: 12px 28px 0; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 10px; font-size: 13px;
         background: var(--brand-soft); border: 1px solid #bfdbfe; color: #1e40af; }
.flash.error { background: var(--red-bg); border-color: #fecaca; color: var(--red); }
.flash.success { background: var(--green-bg); border-color: #bbf7d0; color: var(--green); }
.toast {
    position: fixed; right: 22px; bottom: 22px; z-index: 100; max-width: 460px;
    background: #111827; color: #fff; padding: 11px 16px; border-radius: 8px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, .25); font-size: 13px;
    opacity: 0; transform: translateY(8px); transition: all .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #991b1b; }
.toast.success { background: #166534; }

/* ---------- 统计卡片 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(172px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
             padding: 16px 18px; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 14px; font-weight: 600; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 7px; }
.mini-stats { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.mini-stats b { color: var(--text); font-size: 15px; }

/* ---------- 快捷入口 ---------- */
.quick-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-bottom: 18px; }
.quick-card { display: flex; flex-direction: column; gap: 5px; background: var(--panel);
              border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px;
              box-shadow: var(--shadow); color: var(--text); text-decoration: none;
              transition: border-color .15s, transform .15s; }
.quick-card:hover { border-color: var(--brand); transform: translateY(-1px); text-decoration: none; }
.quick-card b { font-size: 14.5px; }
.quick-card small { color: var(--muted); font-size: 12px; line-height: 1.5; }
.quick-icon { width: 30px; height: 30px; border-radius: 8px; background: var(--brand-soft); color: var(--brand);
              display: flex; align-items: center; justify-content: center; font-size: 15px; margin-bottom: 3px; }

/* ---------- Panel / 表格 ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
         box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
              padding: 13px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h2 { font-size: 15px; font-weight: 700; }
.panel-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.panel.narrow { max-width: 620px; padding: 18px; }
.create-panel { padding: 0 18px 4px; }
.create-panel > summary {
    cursor: pointer; padding: 14px 0; font-weight: 600; color: var(--brand); list-style: none;
}
.create-panel > summary::-webkit-details-marker { display: none; }
.create-panel[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 720px; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { background: #f8fafc; color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: none; }
.table.compact { min-width: 0; }
.table.compact th, .table.compact td { padding: 8px 12px; }
.table .empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.actions { white-space: nowrap; }
.actions .btn, .actions .link { margin-right: 5px; }
.actions-col { text-align: right; }
td.actions { text-align: right; }

/* ---------- 徽章 ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px;
         font-weight: 600; background: #f1f5f9; color: #475569; white-space: nowrap; }
.badge.big { font-size: 13px; padding: 5px 14px; }
.badge.status-success, .badge.status-active, .badge.status-ok, .badge.status-used,
.badge.status-eligible, .badge.status-precheck_ok { background: var(--green-bg); color: var(--green); }
.badge.status-failed, .badge.status-risk, .badge.status-invalid,
.badge.status-ineligible, .badge.status-precheck_failed { background: var(--red-bg); color: var(--red); }
.badge.status-pending, .badge.status-queued, .badge.status-waiting_verification,
.badge.status-manual, .badge.status-allocated, .badge.status-unchecked,
.badge.status-recharging, .badge.status-unknown { background: var(--amber-bg); color: var(--amber); }
.badge.status-running, .badge.status-prechecked, .badge.status-in_stock { background: #dbeafe; color: #1d4ed8; }
.badge.status-cancelled, .badge.status-disabled, .badge.status-skipped { background: #f1f5f9; color: #475569; }

/* ---------- 表单 / 按钮 ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 20px; padding: 4px 0 16px; }
.form-grid.single { grid-template-columns: 1fr; }
.form-row { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.form-row.span-2 { grid-column: span 2; }
.form-row label { font-size: 12px; font-weight: 600; color: #374151; }
input[type="text"], input[type="password"], input[type="email"], input[type="number"],
select, textarea {
    width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 7px;
    background: #fff; color: var(--text); font: inherit; font-size: 13px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
textarea { resize: vertical; font-family: Consolas, "Courier New", monospace; font-size: 12.5px; }
.form-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.checkbox-inline { display: inline-flex; align-items: center; gap: 7px; font-size: 13px;
                   color: #374151; font-weight: 600; cursor: pointer; }
.checkbox-inline input { width: auto; }
.filter-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filter-form input[type="text"] { width: 230px; }
.filter-form select { width: auto; }
.report-filter { margin-bottom: 16px; }
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 5px;
    padding: 7px 14px; border: 1px solid #d1d5db; border-radius: 7px; background: #fff;
    color: #374151; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
    text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.danger { color: var(--red); border-color: #fca5a5; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.inline-form { display: flex; gap: 8px; align-items: center; max-width: 560px; }
.inline-form input { flex: 1; }
.notice { background: #fff; border: 1px dashed #cbd5e1; border-radius: var(--radius); padding: 13px 17px;
          color: var(--muted); font-size: 12.5px; line-height: 1.8; margin-bottom: 18px; }
.notice b { color: #374151; }
.result-box { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px;
              padding: 10px 14px; font-size: 12.5px; color: #374151; line-height: 1.8; }
.result-box.ok { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }
.result-box.warn { border-color: #fde68a; background: #fffbeb; color: var(--amber); }

/* ---------- 账号多选 ---------- */
.picker-tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
.picker-tools input[type="text"] { width: 260px; }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 6px 14px;
          max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px;
          padding: 10px 12px; background: #fbfdff; }
.picker-item { display: flex; align-items: flex-start; gap: 9px; padding: 6px 8px; border-radius: 7px;
               cursor: pointer; border: 1px solid transparent; }
.picker-item:hover { background: var(--brand-soft); border-color: #dbeafe; }
.picker-item input { width: auto; margin-top: 3px; }
.picker-main b { display: block; font-size: 13px; word-break: break-all; }
.picker-main small { display: block; color: var(--muted); font-size: 11.5px; }

/* ---------- 详情页 ---------- */
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 18px;
               background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
               padding: 16px 20px; margin-bottom: 16px; box-shadow: var(--shadow); flex-wrap: wrap; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px 26px; padding: 18px 20px; }
.info-grid.flat { background: transparent; border: none; box-shadow: none; margin: 0; }
.info-item > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 3px; }
.info-item > b { font-weight: 600; word-break: break-all; }
.verify-panel { border-color: #fcd34d; background: #fffbeb; padding: 16px 20px; }
.verify-panel h2 { font-size: 15px; margin-bottom: 8px; color: var(--amber); }
.verify-panel p { margin: 6px 0 10px; }
.verify-message { font-weight: 600; color: #92400e; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ---------- 事件日志 ---------- */
.log { max-height: 380px; overflow-y: auto; padding: 12px 16px; background: #0b1220; color: #cbd5e1;
       font-family: Consolas, "Courier New", monospace; font-size: 12.5px; }
.log-line { display: flex; gap: 12px; padding: 2px 0; }
.log-time { color: #64748b; flex-shrink: 0; }
.log-msg { white-space: pre-wrap; word-break: break-word; }
.log-line.error .log-msg { color: #fca5a5; }
.log-line.error .log-time { color: #f87171; }
.log-line.warning .log-msg { color: #fcd34d; }
.log-line.success .log-msg { color: #86efac; }
.log-line.verification .log-msg { color: #93c5fd; }
.log .empty { color: #64748b; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
         padding: 20px; }
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); }
.modal-card { position: relative; width: 460px; max-width: 100%; max-height: 90vh; overflow-y: auto;
              background: #fff; border-radius: 12px; box-shadow: 0 24px 60px rgba(15, 23, 42, .35); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px;
              border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 15px; }
.modal-body { padding: 16px 18px 4px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px;
              border-top: 1px solid var(--line); }

/* ---------- 登录页 ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh;
              background: radial-gradient(1200px 600px at 20% 0%, #dbeafe 0%, transparent 60%), #f3f5f9; }
.login-card { width: 390px; max-width: calc(100vw - 32px); background: #fff; border: 1px solid var(--line);
              border-radius: 14px; box-shadow: var(--shadow); padding: 28px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.login-brand .logo { width: 44px; height: 44px; border-radius: 11px; background: var(--xbox); color: #fff;
                     display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 22px; }
.login-brand b { display: block; font-size: 15.5px; }
.login-brand small { color: var(--muted); font-size: 12px; }
.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form label { font-size: 12px; font-weight: 600; color: #374151; margin-top: 6px; }
.login-form .btn { margin-top: 12px; padding: 9px 14px; }
.login-tip { color: var(--muted); font-size: 11.5px; line-height: 1.7; margin: 16px 0 0; }

/* ---------- 响应式 ---------- */
@media (max-width: 1000px) {
    .two-col { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .form-row.span-2 { grid-column: span 1; }
}
@media (max-width: 860px) {
    .layout { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; }
    .brand { padding: 14px 16px; }
    .nav { flex-direction: row; flex-wrap: wrap; padding: 8px; }
    .nav a { padding: 8px 10px; }
    .sidebar-foot { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; }
    .engine-line { margin: 0; }
    .user-line { margin: 0; }
    .topbar { position: static; flex-direction: column; align-items: flex-start;
              padding-left: 16px; padding-right: 16px; }
    .content { padding: 16px 16px 40px; }
    .flash-stack { padding: 10px 16px 0; }
    .topbar-right { width: 100%; }
    .filter-form input[type="text"], .picker-tools input[type="text"] { width: 100%; }
    .picker { grid-template-columns: 1fr; }
}

/* 密码显示/隐藏按钮 */
.password-field { display: flex; gap: 6px; align-items: center; flex: 1; min-width: 0; }
.password-field input { flex: 1; min-width: 0; }
.eye-toggle {
    border: 1px solid #d0d5dd;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    padding: 6px 8px;
    font-size: 14px;
    line-height: 1;
}
.eye-toggle:hover { background: #f2f4f7; }

/* 店主提交开通：单选组 */
.radio-group { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; padding-top: 4px; }
.radio-group label {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 13px; font-weight: 600; color: #374151; cursor: pointer;
}
.radio-group input { width: auto; }

/* 店主登录页：输入框与按钮间距、按钮居中 */
.login-card form .form-row { margin-bottom: 14px; }
.login-card form .btn.primary {
    display: block;
    width: 70%;
    margin: 22px auto 0;
    text-align: center;
}

/* 批量选择与操作 */
.check-col { width: 34px; text-align: center; }
.check-col input { width: auto; cursor: pointer; }
.bulk-actions {
    display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
    padding: 10px 18px; border-bottom: 1px solid var(--line); background: #f8fafc;
}
.bulk-actions .hint { margin-right: 4px; }
