:root {
    --bg: #f4f6f9;
    --sidebar: #ffffff;
    --panel: #ffffff;
    --text: #20252d;
    --muted: #7a8492;
    --line: #e1e5ec;
    --primary: #ef233c;
    --primary-dark: #c9182f;
    --red-soft: #fff1f3;
    --green: #128a4f;
    --yellow: #a86600;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    letter-spacing: 0;
}

h1, h2, p {
    margin: 0;
}

h1 {
    font-size: 22px;
    line-height: 1.25;
}

h2 {
    font-size: 17px;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fff;
    color: var(--text);
    padding: 7px 12px;
    cursor: pointer;
}

button:hover {
    border-color: var(--primary);
    color: var(--primary);
}

button.primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

button.primary:hover {
    border-color: var(--primary-dark);
    background: var(--primary-dark);
    color: #fff;
}

button.danger {
    border-color: #ffc2ca;
    background: #fff7f8;
    color: var(--primary);
}

button.small {
    min-height: 30px;
    padding: 5px 9px;
    font-size: 13px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fff;
    padding: 9px 10px;
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(239, 35, 60, 0.1);
}

textarea {
    resize: vertical;
}

label {
    display: block;
    margin: 12px 0 6px;
    color: var(--muted);
    font-size: 13px;
}

.hidden {
    display: none !important;
}

.modal-mask {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(20, 26, 36, 0.42);
}

.modal {
    width: min(560px, 100%);
    max-height: calc(100vh - 48px);
    overflow: auto;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 24px 60px rgba(18, 24, 34, 0.22);
}

.wide-modal {
    width: min(1120px, 100%);
}

.modal-head,
.modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
}

.modal-actions {
    justify-content: flex-end;
    border-top: 1px solid var(--line);
    border-bottom: 0;
}

.modal-body {
    padding: 18px;
}

.icon-button {
    width: 34px;
    min-height: 34px;
    padding: 0;
    font-size: 24px;
    line-height: 1;
}

.switch {
    position: relative;
    display: inline-flex;
    width: 42px;
    height: 24px;
    align-items: center;
}

.switch input {
    width: 0;
    height: 0;
    opacity: 0;
}

.switch span {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: #c6cbd4;
    transition: background 0.18s ease;
}

.switch span::before {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    content: "";
    transition: transform 0.18s ease;
}

.switch input:checked + span {
    background: var(--primary);
}

.switch input:checked + span::before {
    transform: translateX(18px);
}

.login-view {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #fff 0%, #f5f6fa 50%, #fff0f2 100%);
}

.login-card {
    width: 380px;
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 18px 45px rgba(25, 32, 44, 0.12);
}

.login-brand,
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.login-brand {
    margin-bottom: 22px;
}

.brand-mark {
    display: flex;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
}

.login-brand p {
    margin-top: 5px;
    color: var(--muted);
    font-size: 13px;
}

.login-submit {
    width: 100%;
    height: 42px;
    margin-top: 18px;
}

.danger-flash {
    border-color: var(--primary) !important;
    background: #fff7f8 !important;
    color: var(--primary) !important;
}

.app-shell {
    display: grid;
    min-height: 100vh;
    grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: auto;
    border-right: 1px solid var(--line);
    background: var(--sidebar);
}

.sidebar-brand {
    height: 82px;
    padding: 0 22px;
    border-bottom: 1px solid var(--line);
}

.sidebar-brand strong {
    display: block;
    font-size: 19px;
}

.sidebar-brand span {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
}

.side-menu {
    padding: 20px 0 28px;
}

.menu-group {
    padding: 12px 28px 8px;
    color: #9aa2ad;
    font-size: 14px;
    font-weight: 700;
}

.menu-item {
    display: flex;
    width: 100%;
    height: 44px;
    align-items: center;
    border: 0;
    border-radius: 0;
    background: transparent;
    padding: 0 28px;
    color: var(--text);
    font-size: 15px;
    text-align: left;
}

.menu-item:hover,
.menu-item.active {
    background: var(--red-soft);
    color: var(--primary);
}

.menu-item.active {
    box-shadow: inset 4px 0 0 var(--primary);
    font-weight: 800;
}

.menu-divider {
    height: 1px;
    margin: 16px 28px;
    background: var(--line);
}

.workspace {
    min-width: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    height: 82px;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 0 24px;
    border-bottom: 1px solid var(--line);
    background: #fff;
}

.topbar p,
.muted {
    color: var(--muted);
    font-size: 13px;
    margin-top: 4px;
}

.top-actions,
.tools,
.actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.search-input {
    width: 220px;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.admin-name {
    color: var(--muted);
    font-size: 14px;
}

main {
    padding: 20px;
}

.view {
    width: 100%;
}

.admin-view {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.customer-layout {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.panel {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    padding: 16px;
}

.grow {
    flex: 1;
}

.form-panel,
aside.panel {
    width: 300px;
}

.content-grid {
    display: grid;
    gap: 16px;
}

.content-grid.two {
    grid-template-columns: minmax(280px, 0.8fr) minmax(480px, 1.2fr);
}

.form-grid {
    grid-template-columns: repeat(2, minmax(320px, 1fr));
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.stats div {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    padding: 14px;
}

.stats span {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.stats strong {
    display: block;
    margin-top: 6px;
    font-size: 24px;
    line-height: 1.15;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.list,
.balance-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.merchant-card,
.balance-row {
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fff;
    padding: 12px;
}

.merchant-card {
    cursor: pointer;
}

.merchant-card.active {
    border-color: var(--primary);
    box-shadow: inset 3px 0 0 var(--primary);
}

.merchant-card strong,
.project-card strong {
    display: block;
    margin-bottom: 6px;
    font-size: 16px;
}

.merchant-card span,
.project-card span {
    color: var(--muted);
    font-size: 13px;
}

.balance-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.balance-row strong {
    color: var(--primary);
}

.openid-cell {
    max-width: 220px;
    word-break: break-all;
    color: var(--text);
    font-family: "SF Mono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 12px;
    cursor: pointer;
}

.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 12px;
}

.project-card {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    padding: 14px;
}

.project-card .price {
    display: inline-block;
    margin: 8px 0;
    padding: 4px 8px;
    border-radius: 4px;
    background: var(--red-soft);
    color: var(--primary);
    font-weight: 700;
}

.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}

.table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.edit-table {
    min-width: 980px;
}

.edit-table input {
    min-width: 120px;
}

.merchant-table-wrap {
    max-width: 100%;
    overflow-x: auto;
}

.merchant-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    background: #fff;
}

.merchant-table th,
.merchant-table td {
    border-bottom: 1px solid var(--line);
    padding: 10px 8px;
    text-align: left;
    font-size: 13px;
    vertical-align: middle;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.merchant-table .col-id { width: 50px; }
.merchant-table .col-name { width: 200px; }
.merchant-table .col-loc { width: 140px; }
.merchant-table .col-account { width: 160px; }
.merchant-table .col-rate { width: 80px; }
.merchant-table .col-balance { width: 110px; }
.merchant-table .col-status { width: 70px; }
.merchant-table .col-recharge { width: 90px; }
.merchant-table .col-project { width: 90px; }
.merchant-table .col-actions { width: 110px; white-space: nowrap; }

.merchant-table .one-line {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

.table-wrap.compact {
    max-height: 420px;
}

table {
    width: 100%;
    min-width: 1080px;
    border-collapse: collapse;
    background: #fff;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 10px;
    text-align: left;
    font-size: 14px;
    vertical-align: top;
}

th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #fafbfe;
    color: var(--muted);
    font-weight: 700;
}

tr:last-child td {
    border-bottom: none;
}

.num {
    white-space: nowrap;
    text-align: right;
}

.one-line {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge {
    display: inline-flex;
    min-height: 24px;
    align-items: center;
    padding: 3px 8px;
    border-radius: 4px;
    background: #eef1f6;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.badge.ok,
.status-CONFIRMED,
.status-PAID {
    background: #edf9f2;
    color: var(--green);
}

.badge.off,
.status-REJECTED {
    background: #f2f3f5;
    color: var(--muted);
}

.status-PENDING,
.status-PAYING,
.status-OFFLINE_PAID {
    background: #fff5df;
    color: var(--yellow);
}

.inline-edit {
    display: grid;
    grid-template-columns: 92px auto;
    gap: 6px;
}

.inline-edit input {
    min-width: 0;
    padding: 7px 8px;
}

.recharge-edit {
    display: grid;
    min-width: 230px;
    grid-template-columns: 72px 72px auto;
    gap: 6px;
}

.recharge-edit input {
    min-width: 0;
    padding: 7px 8px;
}

.user-admin-form {
    display: grid;
    min-width: 430px;
    grid-template-columns: 180px 130px auto;
    gap: 8px;
}

.toast {
    position: fixed;
    top: 98px;
    left: calc(248px + 50%);
    z-index: 20;
    transform: translateX(-50%);
    min-width: 180px;
    max-width: calc(100vw - 320px);
    padding: 10px 16px;
    border-radius: 4px;
    background: #1c2430;
    color: #fff;
    text-align: center;
}

@media (max-width: 1100px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .side-menu {
        display: flex;
        overflow-x: auto;
        padding: 10px;
    }

    .menu-group,
    .menu-divider {
        display: none;
    }

    .menu-item {
        width: auto;
        min-width: 96px;
        justify-content: center;
        padding: 0 14px;
        border-radius: 4px;
    }

    .menu-item.active {
        box-shadow: none;
    }

    .stats,
    .content-grid.two,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .customer-layout {
        flex-direction: column;
    }

    aside.panel,
    .form-panel {
        width: 100%;
    }

    .toast {
        left: 50%;
        max-width: calc(100vw - 32px);
    }
}

/* 危险按钮（删除） */
button.danger {
    color: #dc2626;
    border-color: #fca5a5;
}
button.danger:hover {
    background: #fef2f2;
    border-color: #dc2626;
}

@media (max-width: 640px) {
    main {
        padding: 12px;
    }

    .topbar {
        height: auto;
        align-items: flex-start;
        flex-direction: column;
        padding: 14px;
    }

    .stats {
        grid-template-columns: 1fr 1fr;
    }

    .panel {
        padding: 12px;
    }

    .login-card {
        width: 100%;
    }
}
