:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --sidebar: #101828;
    --sidebar-soft: #1b2537;
    --text: #101828;
    --muted: #667085;
    --border: #e4e7ec;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff4ff;
    --green: #067647;
    --green-bg: #ecfdf3;
    --amber: #b54708;
    --amber-bg: #fffaeb;
    --red: #b42318;
    --red-bg: #fef3f2;
    --gray: #475467;
    --gray-bg: #f2f4f7;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .05);
    --radius: 14px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
code { font-family: "Cascadia Mono", Consolas, "Courier New", monospace; font-size: 12.5px; background: var(--gray-bg); border-radius: 5px; padding: 2px 6px; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.error-text { color: var(--red); font-size: 12px; margin-top: 8px; word-break: break-word; }

/* Login */
.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(900px 480px at 15% 0%, rgba(37, 99, 235, .18), transparent 60%),
        radial-gradient(700px 420px at 95% 100%, rgba(12, 74, 110, .16), transparent 55%),
        #eef2f9;
}
.login-panel {
    width: min(420px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(16, 24, 40, .14);
    padding: 40px 36px 32px;
}
.brand-mark {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: linear-gradient(135deg, #2563eb, #0e7490);
    color: #fff;
    font-weight: 700;
    letter-spacing: .04em;
    margin-bottom: 20px;
    box-shadow: 0 8px 18px rgba(37, 99, 235, .28);
}
.brand-mark.small-mark { width: 32px; height: 32px; margin: 0; border-radius: 9px; font-size: 11px; box-shadow: none; }
.login-panel h1 { font-size: 24px; letter-spacing: -.02em; }
.login-panel > .muted { margin: 6px 0 24px; }
.login-panel label { display: grid; gap: 7px; margin-bottom: 16px; font-size: 13px; font-weight: 600; color: #344054; }
.login-panel input {
    height: 44px;
    border: 1px solid #d0d5dd;
    border-radius: 9px;
    padding: 0 12px;
    font-weight: 400;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.login-panel input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.hint { color: var(--muted); font-size: 12px; margin-top: 18px; text-align: center; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    padding: 0 16px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fff;
    color: #344054;
    font-weight: 600;
    font-size: 13px;
    line-height: 1;
    white-space: nowrap;
    transition: background .15s, border-color .15s, transform .05s;
}
.button:hover { background: #f9fafb; border-color: #d0d5dd; text-decoration: none; }
.button:active { transform: translateY(1px); }
.button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.button.full { width: 100%; height: 44px; margin-top: 4px; }
.small-button { height: 32px; padding: 0 12px; font-size: 12px; }
.danger-link { background: none; border: 0; color: var(--red); font-size: 12px; padding: 4px 0; }
.danger-link:hover { text-decoration: underline; }
.text-link { font-size: 13px; font-weight: 600; white-space: nowrap; }

.notice {
    border-radius: 10px;
    padding: 11px 14px;
    margin-bottom: 18px;
    font-size: 13px;
    border: 1px solid transparent;
}
.notice.success { background: var(--green-bg); border-color: #abefc6; color: var(--green); }
.notice.error { background: var(--red-bg); border-color: #fecdca; color: var(--red); }
.notice.warning { background: var(--amber-bg); border-color: #fedf89; color: var(--amber); }

/* Shell */
.app-shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
    background: var(--sidebar);
    color: #cbd5e1;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: .01em;
    padding: 2px 8px 20px;
}
.brand:hover { text-decoration: none; }
.workspace-label {
    color: #667085;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    padding: 18px 10px 8px;
}
.sidebar nav { display: grid; gap: 2px; }
.sidebar nav a {
    color: #cbd5e1;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 500;
    border-left: 2px solid transparent;
}
.sidebar nav a:hover { background: var(--sidebar-soft); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--sidebar-soft); color: #fff; border-left-color: #60a5fa; }
.sidebar-bottom { margin-top: auto; display: grid; gap: 2px; }
.sidebar-bottom .logout-form { margin-top: 0; padding: 8px 0 0; border-top: 1px solid rgba(255, 255, 255, .07); }
.logout-form { margin-top: auto; padding: 12px 4px 0; border-top: 1px solid rgba(255, 255, 255, .07); }
.nav-link {
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    color: #98a2b3;
    padding: 8px;
    border-radius: 8px;
    font-size: 13px;
}
.nav-link:hover { color: #fff; background: var(--sidebar-soft); text-decoration: none; }
.nav-link { display: block; }

.admin-ui .sidebar { background: #191735; }
.admin-ui .sidebar nav a.active { border-left-color: #a78bfa; }
.admin-ui .brand-mark { background: linear-gradient(135deg, #4f46e5, #7c3aed); box-shadow: 0 8px 18px rgba(79, 70, 229, .28); }
.admin-ui .brand-mark.small-mark { box-shadow: none; }
.admin-ui .login-shell {
    background:
        radial-gradient(900px 480px at 12% 0%, rgba(79, 70, 229, .18), transparent 60%),
        radial-gradient(700px 420px at 95% 100%, rgba(124, 58, 237, .14), transparent 55%),
        #f1f0fa;
}
.inline-action { display: inline; }
.nav-badge {
    float: right;
    min-width: 18px;
    background: #ef4444;
    color: #fff;
    border-radius: 99px;
    padding: 0 6px;
    font-size: 10.5px;
    line-height: 18px;
    text-align: center;
}
.money-positive { color: var(--green); font-weight: 600; }
.stats-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.account-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; align-items: start; margin-bottom: 8px; }
.withdraw-process { display: flex; flex-direction: column; gap: 7px; min-width: 210px; }
.withdraw-process input {
    height: 32px;
    border: 1px solid #d0d5dd;
    border-radius: 7px;
    padding: 0 9px;
    font-size: 12px;
    min-width: 0;
}
.button.danger { color: var(--red); border-color: #fecdca; background: var(--red-bg); }
.button.danger:hover { background: #fee4e2; border-color: #fda29b; }
.button:disabled { opacity: .5; cursor: not-allowed; }

.main-area { min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: 68px;
    background: rgba(255, 255, 255, .88);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-title { display: flex; align-items: baseline; gap: 10px; }
.topbar-label { color: var(--muted); font-size: 12px; }
.topbar-title strong { font-size: 15px; }
.user-chip { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 600; }
.avatar {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
}
.role-tag {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    background: var(--gray-bg);
    border-radius: 99px;
    padding: 2px 8px;
}
.content { padding: 30px 32px 48px; max-width: 1320px; width: 100%; margin: 0 auto; }

.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-heading h1 { font-size: 25px; letter-spacing: -.025em; }
.page-heading p { color: var(--muted); margin-top: 4px; font-size: 13px; }
.count-label { color: var(--muted); font-size: 12.5px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 34px; }
.stat {
    position: relative;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 2px;
}
.stat::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #2563eb, #60a5fa);
    opacity: .9;
}
.stats-grid .stat:nth-child(2)::after { background: linear-gradient(90deg, #d97706, #fbbf24); }
.stats-grid .stat:nth-child(3)::after { background: linear-gradient(90deg, #059669, #34d399); }
.stats-grid .stat:nth-child(4)::after { background: linear-gradient(90deg, #e11d48, #fb7185); }
.stat span { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat strong { font-size: 30px; line-height: 1.2; letter-spacing: -.03em; }
.stat small { color: #98a2b3; font-size: 11.5px; }

.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 30px 0 12px; }
.section-head h2 { font-size: 16.5px; letter-spacing: -.01em; }
.section-head p { color: var(--muted); font-size: 12.5px; margin-top: 3px; }

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: auto;
}
table { width: 100%; border-collapse: collapse; min-width: 680px; }
thead th {
    text-align: left;
    background: #f9fafb;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    padding: 11px 16px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody td { padding: 13px 16px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfe; }
.empty { text-align: center; color: var(--muted); padding: 34px 16px !important; }

.status { display: inline-flex; align-items: center; border-radius: 99px; padding: 3px 9px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.status.green { color: var(--green); background: var(--green-bg); }
.status.amber { color: var(--amber); background: var(--amber-bg); }
.status.red { color: var(--red); background: var(--red-bg); }
.status.gray { color: var(--gray); background: var(--gray-bg); }

.switch { position: relative; display: inline-block; width: 42px; height: 24px; vertical-align: middle; }
.switch input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}
.switch span {
    position: absolute;
    inset: 0;
    background: #d0d5dd;
    border-radius: 99px;
    transition: background .18s;
    cursor: pointer;
}
.switch span::before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(16, 24, 40, .2);
    transition: transform .18s;
}
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch input:disabled + span { opacity: .45; cursor: not-allowed; }
.switch input:focus-visible + span { outline: 3px solid rgba(37, 99, 235, .25); }

.poll-message { min-height: 22px; margin-top: 10px; font-size: 12.5px; }
.poll-message.success { color: var(--green); }
.poll-message.error { color: var(--red); }

.new-orders {
    margin-top: 12px;
    background: var(--amber-bg);
    border: 1px solid #fedf89;
    border-radius: 12px;
    padding: 14px 16px;
    display: grid;
    gap: 9px;
}
.new-orders[hidden] { display: none; }
.new-orders-title { color: #93370d; font-weight: 700; font-size: 13px; }
.new-order-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    background: #fff;
    border: 1px solid #fef0c7;
    border-radius: 9px;
    padding: 9px 12px;
    font-size: 13px;
}
.order-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }

.inline-details summary {
    cursor: pointer;
    color: var(--primary);
    font-size: 11.5px;
    font-weight: 600;
    list-style: none;
    width: fit-content;
}
.inline-details summary::-webkit-details-marker { display: none; }
.inline-details summary::before { content: "＋ "; }
.inline-details[open] summary::before { content: "－ "; }

.admin-grid { display: grid; grid-template-columns: minmax(300px, 420px) minmax(0, 1fr); gap: 22px; align-items: start; }
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.panel h2, .device-list > h2 { font-size: 15px; margin-bottom: 14px; }
.form-grid { display: grid; gap: 13px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 600px) { .form-grid.two { grid-template-columns: 1fr; } .form-grid .full { grid-column: auto; } }
.form-grid label { display: grid; gap: 6px; font-size: 12.5px; font-weight: 600; color: #344054; }
.form-grid input, .form-grid select, .inline-edit input, .inline-edit select {
    height: 38px;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    padding: 0 10px;
    font-weight: 400;
    background: #fff;
    outline: none;
    min-width: 0;
}
.form-grid input:focus, .form-grid select:focus, .inline-edit input:focus, .inline-edit select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}
.check-line { display: flex !important; align-items: center; gap: 8px; font-weight: 500 !important; }
.check-line input { height: auto !important; width: 16px; height: 16px !important; }
.form-actions { display: flex; gap: 8px; margin-top: 4px; }

.device-list { display: grid; gap: 12px; }
.device-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 15px 17px;
}
.device-row-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.device-row-head .muted { margin-top: 3px; }
.row-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 12px; }
.assign-form { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.assign-options { display: flex; flex-wrap: wrap; gap: 10px 16px; font-size: 12.5px; color: #344054; }
.assign-options label { display: inline-flex; align-items: center; gap: 6px; }
.assign-options input { accent-color: var(--primary); }

.inline-details { position: relative; }
.inline-edit { display: grid; gap: 7px; margin-top: 8px; min-width: 190px; }
.inline-edit input, .inline-edit select { height: 32px; font-size: 12px; }


.response-link {
    display: inline-block;
    margin-top: 5px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--primary);
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
}
.response-link:hover { text-decoration: underline; }
.response-dialog {
    width: min(900px, 94vw);
    max-height: 86vh;
    padding: 0;
    border: 0;
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 30px 80px rgba(16, 24, 40, .32);
    overflow: hidden;
}
.response-dialog::backdrop { background: rgba(16, 24, 40, .55); backdrop-filter: blur(2px); }
.dialog-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 22px 16px;
    border-bottom: 1px solid var(--border);
}
.dialog-eyebrow {
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
}
.dialog-head h3 { margin: 4px 0 0; font-size: 18px; letter-spacing: -.02em; }
.response-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 7px 12px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.response-meta code { font-size: 11px; }
.dialog-close {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: #fff;
    color: var(--muted);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}
.dialog-close:hover { background: var(--gray-bg); color: var(--text); }
.response-sections {
    display: grid;
    gap: 13px;
    padding: 18px 22px;
    max-height: calc(86vh - 180px);
    overflow-y: auto;
}
.response-section { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.response-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 12px;
    background: #f9fafb;
    border-bottom: 1px solid var(--border);
    color: #344054;
    font-size: 12px;
    font-weight: 600;
}
.copy-button {
    padding: 3px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    color: var(--muted);
    font-size: 11px;
    cursor: pointer;
}
.copy-button:hover { color: var(--text); border-color: #d0d5dd; }
.code-block {
    margin: 0;
    padding: 14px;
    max-height: 250px;
    overflow: auto;
    background: #0f172a;
    color: #dbeafe;
    font-family: "Cascadia Mono", Consolas, "Courier New", monospace;
    font-size: 11.5px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
}
.response-error {
    padding: 12px 14px;
    border: 1px solid #fecdca;
    border-radius: 10px;
    background: var(--red-bg);
    color: var(--red);
    font-size: 12px;
}
.response-error strong { display: block; margin-bottom: 5px; }
.response-error p { margin: 0; word-break: break-word; }
.dialog-actions { padding: 12px 22px 18px; border-top: 1px solid var(--border); text-align: right; }
@media (max-width: 600px) {
    .response-dialog { width: 96vw; max-height: 92vh; }
    .dialog-head { padding: 16px; }
    .response-sections { padding: 12px; max-height: calc(92vh - 160px); }
    .code-block { max-height: 210px; }
}


.page-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.admin-dialog {
    width: min(540px, 94vw);
    max-height: 88vh;
    padding: 0;
    border: 0;
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 30px 80px rgba(16, 24, 40, .32);
    overflow: hidden;
}
.admin-dialog::backdrop { background: rgba(16, 24, 40, .55); backdrop-filter: blur(2px); }
.dialog-body {
    padding: 20px 22px;
    max-height: calc(88vh - 160px);
    overflow-y: auto;
}
.dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    background: #fcfcfd;
}
.filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 99px;
    background: #fff;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
}
.filter-chip:hover { border-color: #d0d5dd; color: var(--text); }
.filter-chip.active { background: var(--primary-soft); border-color: #b2ccff; color: var(--primary); }
.filter-count { min-width: 18px; padding: 0 5px; border-radius: 99px; background: var(--gray-bg); color: var(--muted); font-size: 10.5px; line-height: 17px; text-align: center; }
.filter-chip.active .filter-count { background: #dbe7ff; color: var(--primary); }
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 32px; height: 32px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 700; }
.user-name { font-weight: 600; color: var(--text); }
.user-meta { margin-top: 1px; color: var(--muted); font-size: 11.5px; }
.user-device-line { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.user-device-line code { font-size: 12px; }
.user-device-meta { margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.user-device-meta code { font-size: 10.5px; }
.product-name { display: block; font-weight: 700; }
.product-alias { display: block; margin-top: 1px; color: var(--muted); font-size: 11px; font-family: "Cascadia Mono", Consolas, monospace; }
.device-bind-section { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.device-bind-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.device-bind-head strong { display: block; font-size: 13px; }
.device-bind-head div span { display: block; margin-top: 2px; color: var(--muted); font-size: 11.5px; font-weight: 400; }
.device-bind-head > .status { flex: 0 0 auto; margin-top: 0; }
.form-hint { margin-top: 10px; line-height: 1.6; }
.device-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 14px; }
.device-list > h2 { grid-column: 1 / -1; }
@media (max-width: 1100px) { .device-list { grid-template-columns: 1fr; } }
@media (max-width: 600px) {
    .admin-dialog { width: 96vw; max-height: 92vh; }
    .dialog-body { max-height: calc(92vh - 150px); padding: 16px; }
    .dialog-footer { padding: 12px 16px; }
}

@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .admin-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; padding: 14px 16px; }
    .brand { padding-bottom: 10px; }
    .workspace-label { display: none; }
    .sidebar nav { display: flex; flex-wrap: wrap; gap: 4px; }
    .sidebar nav a { border-left: 0; padding: 7px 11px; }
    .logout-form { margin-top: 10px; border-top: 0; padding: 0; }
    .nav-link { width: auto; padding: 6px 10px; }
    .topbar { padding: 0 18px; height: 60px; }
    .content { padding: 22px 18px 40px; }
    .page-heading { align-items: flex-start; flex-direction: column; gap: 10px; }
    .section-head { align-items: flex-start; flex-direction: column; gap: 6px; }
    .account-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .stats-grid, .stats-grid.three { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat { padding: 14px; }
    .stat strong { font-size: 24px; }
    .login-panel { padding: 30px 22px 24px; }
    .user-chip > span:not(.avatar):not(.role-tag) { display: none; }
    .page-heading h1 { font-size: 22px; }
}

.button.confirm-action { background: var(--green); border-color: var(--green); color: #fff; }
.button.confirm-action:hover { background: #05603a; border-color: #05603a; }


/* Staff auto-listen panel */
.listen-page { width: 100%; max-width: 760px; margin: 0 auto; }
.listen-hero { text-align: center; padding: 10px 0 22px; }
.listen-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--green);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .14em;
    text-transform: uppercase;
    margin-bottom: 8px;
}
.listen-hero h1 { font-size: 29px; letter-spacing: -.035em; line-height: 1.2; }
.listen-hero p { color: var(--muted); font-size: 13px; margin-top: 7px; }
.listen-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 22px 24px;
    margin-bottom: 16px;
}
.listen-device-picker {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}
.listen-device-picker select { max-width: 62%; height: 36px; padding: 0 10px; border: 1px solid #d0d5dd; border-radius: 9px; background: #fff; font-weight: 600; }
.listen-info { border-top: 1px solid var(--border); }
.listen-info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 15px 0;
    border-bottom: 1px solid #f0f2f5;
}
.listen-info-row:last-child { border-bottom: 0; }
.listen-info-row > span { color: var(--muted); font-size: 13px; font-weight: 600; }
.listen-info-row > strong { font-size: 15px; font-weight: 700; text-align: right; word-break: break-all; }
.listen-info-row > strong code { font-size: 13px; padding: 3px 8px; }
.listen-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; }
.listen-btn {
    height: 52px;
    border-radius: 12px;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 800;
    transition: transform .15s, background .15s, box-shadow .15s, opacity .15s;
}
.listen-btn:active:not(:disabled) { transform: translateY(1px); }
.listen-btn:disabled { opacity: .42; cursor: not-allowed; box-shadow: none; }
.listen-btn-icon { font-size: 11px; line-height: 1; }
.listen-btn-start { background: linear-gradient(180deg, #22c55e, #16a34a); border-color: #15803d; color: #fff; box-shadow: 0 8px 18px rgba(22, 163, 74, .24); }
.listen-btn-start:hover:not(:disabled) { background: linear-gradient(180deg, #16a34a, #15803d); }
.listen-btn-stop { background: #f2f4f7; border-color: #d0d5dd; color: #344054; }
.listen-btn-stop:hover:not(:disabled) { background: #e4e7ec; }
.listen-status {
    margin-top: 14px;
    padding: 9px 12px;
    border-radius: 10px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    background: var(--gray-bg);
    color: var(--gray);
    transition: color .15s, background .15s;
}
.listen-status.is-polling { color: var(--green); background: var(--green-bg); }
.listen-status.is-paused { color: var(--amber); background: var(--amber-bg); }
.listen-status.is-error { color: var(--red); background: var(--red-bg); }
.listen-status.is-stopped { color: var(--gray); background: var(--gray-bg); }
.listen-hint { text-align: center; color: #98a2b3; font-size: 11.5px; margin-top: 10px; }
.listen-panel .notice { margin-top: 12px; margin-bottom: 0; }
.listen-no-device { text-align: center; padding-top: 32px; padding-bottom: 32px; }
.listen-no-device-mark {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    margin: 0 auto 12px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 24px;
    font-weight: 500;
}
.listen-no-device h2 { font-size: 17px; }
.listen-no-device p { color: var(--muted); font-size: 12.5px; margin-top: 6px; }

.active-order {
    position: relative;
    overflow: hidden;
    background: linear-gradient(180deg, #fff, #fffdf8);
    border: 1px solid #fedf89;
    border-radius: 20px;
    box-shadow: 0 16px 40px rgba(181, 71, 8, .10);
    padding: 22px 24px;
    margin-bottom: 16px;
}
.active-order::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 4px;
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
}
.active-order-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.active-order-kicker { color: var(--amber); font-size: 10.5px; font-weight: 800; letter-spacing: .12em; }
.active-order-head h2 { font-size: 20px; margin-top: 3px; letter-spacing: -.02em; }
.active-order-id { margin-top: 14px; color: var(--muted); font-size: 12px; }
.active-order-id strong { color: var(--text); font-size: 13px; font-family: "Cascadia Mono", Consolas, monospace; }
.active-order-amount { font-size: 36px; font-weight: 800; letter-spacing: -.045em; line-height: 1.1; margin-top: 10px; }
.active-order-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; color: var(--muted); font-size: 11.5px; }
.active-order-meta code { font-size: 11px; }
.active-order-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.active-order-actions.single-action { grid-template-columns: 1fr; }
.listen-form { margin: 0; }
.listen-action {
    width: 100%;
    height: 52px;
    border-radius: 12px;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 16px;
    font-weight: 800;
    text-decoration: none;
}
.listen-action:hover { text-decoration: none; }
.listen-action-pay { background: linear-gradient(180deg, #3b82f6, #2563eb); border-color: #1d4ed8; color: #fff; box-shadow: 0 8px 18px rgba(37, 99, 235, .22); }
.listen-action-pay:hover { background: linear-gradient(180deg, #2563eb, #1d4ed8); color: #fff; }
.listen-action-confirm { background: linear-gradient(180deg, #22c55e, #16a34a); border-color: #15803d; color: #fff; box-shadow: 0 8px 18px rgba(22, 163, 74, .22); }
.listen-action-confirm:hover { background: linear-gradient(180deg, #16a34a, #15803d); }
.listen-action-disabled { background: var(--gray-bg); color: var(--muted); cursor: not-allowed; }
.active-order-note { margin-top: 12px; color: var(--muted); font-size: 11.5px; line-height: 1.6; }

.listen-waiting {
    background: var(--surface);
    border: 1px dashed #d0d5dd;
    border-radius: 20px;
    padding: 26px 24px;
    text-align: center;
    margin-bottom: 16px;
}
.listen-waiting-pulse {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #60a5fa;
    box-shadow: 0 0 0 0 rgba(96, 165, 250, .5);
    animation: listen-pulse 1.8s infinite;
    margin-bottom: 10px;
}
@keyframes listen-pulse {
    0% { box-shadow: 0 0 0 0 rgba(96, 165, 250, .5); }
    70% { box-shadow: 0 0 0 10px rgba(96, 165, 250, 0); }
    100% { box-shadow: 0 0 0 0 rgba(96, 165, 250, 0); }
}
.listen-waiting h2 { font-size: 16.5px; }
.listen-waiting p { color: var(--muted); font-size: 12.5px; margin-top: 5px; }

.listen-log-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 16px;
}
.listen-log-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 22px 14px; }
.listen-log-head h2 { font-size: 16px; }
.listen-log-head p { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.listen-log-live { display: inline-flex; align-items: center; gap: 5px; color: var(--green); font-size: 11px; font-weight: 700; white-space: nowrap; }
.listen-log-live i { width: 6px; height: 6px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .14); }
.listen-log { max-height: 300px; overflow: auto; background: #fbfcfe; border-top: 1px solid var(--border); }
.listen-log-line { display: flex; align-items: flex-start; gap: 9px; padding: 10px 22px; border-bottom: 1px solid #f0f2f5; font-size: 12px; line-height: 1.55; }
.listen-log-line:last-child { border-bottom: 0; }
.listen-log-time { flex: 0 0 auto; color: #98a2b3; font-size: 10.5px; font-family: "Cascadia Mono", Consolas, monospace; padding-top: 1px; }
.listen-log-text { min-width: 0; color: #344054; word-break: break-word; }
.listen-log-empty { padding: 26px 20px; text-align: center; color: var(--muted); font-size: 12px; }
.listen-history-link { display: block; text-align: center; padding: 8px 12px 4px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.listen-history-link:hover { color: var(--primary); text-decoration: none; }
.order-history-count { color: var(--muted); font-size: 12.5px; margin: -10px 0 12px; }

/* Mobile staff experience */
@media (max-width: 720px) {
    html { -webkit-tap-highlight-color: transparent; }
    .staff-ui .main-area { padding-bottom: 82px; }
    .staff-ui .topbar { height: 56px; padding: 0 16px; }
    .staff-ui .content { padding: 18px 14px 30px; }
    .staff-ui .sidebar {
        position: fixed;
        inset: auto 0 0 0;
        width: auto;
        height: auto;
        min-height: 0;
        z-index: 60;
        flex-direction: row;
        align-items: center;
        gap: 5px;
        padding: 7px 9px calc(7px + env(safe-area-inset-bottom));
        box-shadow: 0 -10px 30px rgba(16, 24, 40, .22);
    }
    .staff-ui .sidebar .brand,
    .staff-ui .sidebar .workspace-label { display: none; }
    .staff-ui .sidebar nav { display: flex; flex: 1; min-width: 0; gap: 4px; }
    .staff-ui .sidebar nav a {
        flex: 1;
        text-align: center;
        padding: 10px 5px;
        border: 0;
        border-radius: 9px;
        font-size: 12.5px;
        font-weight: 600;
    }
    .staff-ui .sidebar nav a.active { border: 0; background: var(--sidebar-soft); }
    .staff-ui .sidebar .logout-form { flex: 0 0 auto; margin: 0; padding: 0; border: 0; }
    .staff-ui .sidebar .logout-form .nav-link { padding: 10px 7px; font-size: 11.5px; text-align: center; }

    .staff-ui .page-heading { margin-bottom: 16px; }
    .staff-ui .page-heading .page-actions { width: 100%; }
    .staff-ui .page-heading .page-actions .button { flex: 1; height: 44px; }
    .staff-ui .stats-grid { gap: 9px; margin-bottom: 22px; }
    .staff-ui .stat { padding: 13px 14px; }
    .staff-ui .stat strong { font-size: 25px; }
    .staff-ui .stat small { font-size: 10.5px; }
    .staff-ui .section-head { margin: 22px 0 10px; }

    .staff-ui .order-table-wrap,
    .staff-ui .device-table-wrap {
        background: transparent;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        overflow: visible;
    }
    .staff-ui .order-table,
    .staff-ui .device-table { display: block; min-width: 0; width: 100%; }
    .staff-ui .order-table thead,
    .staff-ui .device-table thead { display: none; }
    .staff-ui .order-table tbody,
    .staff-ui .device-table tbody { display: block; }

    .staff-ui .order-table tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 4px 12px;
        margin: 0 0 12px;
        padding: 15px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 14px;
        box-shadow: var(--shadow);
    }
    .staff-ui .order-table td { display: block; padding: 0 !important; border: 0; min-width: 0; }
    .staff-ui .order-table .order-id-cell { grid-column: 1; grid-row: 1; align-self: center; overflow: hidden; }
    .staff-ui .order-table .order-id-cell strong { display: block; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
    .staff-ui .order-table .order-id-cell .response-link { margin-top: 2px; }
    .staff-ui .order-table .alias-cell { grid-column: 1 / -1; grid-row: 2; margin-top: 7px; color: var(--text); font-size: 16px; font-weight: 700; }
    .staff-ui .order-table .alias-cell::before { content: ""; }
    .staff-ui .order-table .status-cell { grid-column: 2; grid-row: 1; align-self: center; text-align: right; }
    .staff-ui .order-table .device-cell { grid-column: 1; grid-row: 3; color: var(--muted); font-size: 11.5px; }
    .staff-ui .order-table .device-cell::before { content: "设备 "; color: #98a2b3; }
    .staff-ui .order-table .amount-cell { grid-column: 2; grid-row: 3; text-align: right; font-size: 15px; }
    .staff-ui .order-table .amount-cell::before { content: ""; }
    .staff-ui .order-table .time-cell { grid-column: 1 / -1; grid-row: 4; color: var(--muted); font-size: 11px; }
    .staff-ui .order-table .time-cell::before { content: "接单 "; color: #98a2b3; }
    .staff-ui .order-table .actions-cell { grid-column: 1 / -1; grid-row: 5; margin-top: 9px; padding-top: 12px !important; border-top: 1px solid var(--border) !important; }
    .staff-ui .order-table .order-actions { width: 100%; gap: 8px; }
    .staff-ui .order-table .order-actions > .button,
    .staff-ui .order-table .order-actions > form,
    .staff-ui .order-table .order-actions > form > .button { width: 100%; }
    .staff-ui .order-table .order-actions > .button,
    .staff-ui .order-table .order-actions > form > .button {
        height: 46px;
        border-radius: 10px;
        font-size: 14px;
        font-weight: 700;
    }
    .staff-ui .order-table .order-actions .small { width: 100%; text-align: center; }
    .staff-ui .order-table .empty-row { display: block; }
    .staff-ui .order-table .empty-row td { padding: 30px 16px !important; }

    .staff-ui .device-table tr {
        display: block;
        margin: 0 0 12px;
        padding: 14px 16px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 14px;
        box-shadow: var(--shadow);
    }
    .staff-ui .device-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 5px 0 !important;
        border: 0;
    }
    .staff-ui .device-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 11.5px;
        font-weight: 600;
    }
    .staff-ui .device-table td[data-label="商品别名"] { color: var(--text); font-size: 15px; font-weight: 700; }
    .staff-ui .device-table td[data-label="自动抢单"] {
        margin-top: 7px;
        padding-top: 12px !important;
        border-top: 1px solid var(--border) !important;
    }
    .staff-ui .device-table td[data-label="自动抢单"]::before { color: var(--text); font-size: 13px; }
    .staff-ui .device-table .switch { width: 48px; height: 28px; }
    .staff-ui .device-table .switch span::before { width: 22px; height: 22px; }
    .staff-ui .device-table .switch input:checked + span::before { transform: translateX(20px); }
    .staff-ui .device-table .empty-row td { display: block; text-align: center; padding: 30px 16px !important; }
    .staff-ui .device-table .empty-row td::before { display: none; }

    .staff-ui .new-orders { padding: 13px; margin-top: 0; margin-bottom: 12px; }
    .staff-ui .new-orders-title { font-size: 14px; }
    .staff-ui .new-order-row { flex-direction: column; align-items: stretch; gap: 9px; padding: 12px; }
    .staff-ui .new-order-row .button { width: 100%; height: 46px; border-radius: 10px; font-size: 14px; }
    .staff-ui .poll-message { margin: 2px 0 10px; }

    .staff-ui .listen-page { max-width: none; }
    .staff-ui .listen-page.has-active-order { display: flex; flex-direction: column; }
    .staff-ui .listen-page.has-active-order .listen-hero { order: 1; }
    .staff-ui .listen-page.has-active-order .active-order { order: 2; }
    .staff-ui .listen-page.has-active-order .listen-panel { order: 3; }
    .staff-ui .listen-page.has-active-order .listen-log-card { order: 4; }
    .staff-ui .listen-page.has-active-order .listen-history-link { order: 5; }
    .staff-ui .listen-hero { padding: 2px 0 18px; }
    .staff-ui .listen-eyebrow { font-size: 10px; margin-bottom: 6px; }
    .staff-ui .listen-hero h1 { font-size: 25px; }
    .staff-ui .listen-hero p { font-size: 12px; }
    .staff-ui .listen-panel { padding: 18px 16px; border-radius: 16px; margin-bottom: 12px; }
    .staff-ui .listen-info-row { padding: 13px 0; gap: 12px; }
    .staff-ui .listen-info-row > span { font-size: 12.5px; }
    .staff-ui .listen-info-row > strong { font-size: 14px; }
    .staff-ui .listen-info-row > strong code { font-size: 12px; padding: 2px 6px; }
    .staff-ui .listen-actions { gap: 8px; margin-top: 16px; }
    .staff-ui .listen-btn { height: 50px; border-radius: 11px; font-size: 15px; }
    .staff-ui .listen-status { margin-top: 12px; font-size: 12.5px; }
    .staff-ui .listen-hint { font-size: 10.5px; }
    .staff-ui .listen-device-picker { font-size: 11.5px; }
    .staff-ui .listen-device-picker select { height: 34px; }
    .staff-ui .active-order { padding: 18px 16px; border-radius: 16px; margin-bottom: 12px; }
    .staff-ui .active-order-head h2 { font-size: 18px; }
    .staff-ui .active-order-amount { font-size: 31px; }
    .staff-ui .active-order-actions { grid-template-columns: 1fr; gap: 8px; margin-top: 16px; }
    .staff-ui .listen-action { height: 52px; border-radius: 11px; font-size: 16px; }
    .staff-ui .active-order-note { font-size: 11px; }
    .staff-ui .listen-waiting { padding: 22px 16px; border-radius: 16px; margin-bottom: 12px; }
    .staff-ui .listen-waiting h2 { font-size: 16px; }
    .staff-ui .listen-log-card { border-radius: 16px; margin-bottom: 12px; }
    .staff-ui .listen-log-head { padding: 15px 16px 12px; }
    .staff-ui .listen-log-head h2 { font-size: 15px; }
    .staff-ui .listen-log-line { padding: 9px 15px; gap: 7px; font-size: 11.5px; }
    .staff-ui .listen-log-time { font-size: 10px; }
    .staff-ui .listen-log { max-height: 280px; }
    .staff-ui .listen-history-link { font-size: 12px; padding-bottom: 12px; }
    .staff-ui .order-history-count { margin: -4px 0 10px; }
}
