:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #eef3fb;
    --line: #dce4ef;
    --text: #172033;
    --muted: #718096;
    --primary: #4969a8;
    --primary-dark: #365487;
    --green: #15956b;
    --red: #c53b45;
    --orange: #c77a22;
    --shadow: 0 12px 32px rgba(41, 58, 92, .08);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }

.layout { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar {
    position: sticky; top: 0; align-self: start; height: 100vh; height: 100dvh;
    display: flex; flex-direction: column; min-height: 0; overflow: hidden;
    padding: 28px 20px;
    background: #18243a; color: #dce6f7;
}
.brand { display: flex; align-items: center; gap: 12px; margin: 0 8px 30px; }
.sidebar > .brand { flex: 0 0 auto; }
.brand-mark {
    width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px;
    color: white; font-weight: 800; letter-spacing: -1px;
    background: linear-gradient(145deg, #6d8bc4, #405f9b);
}
.brand strong { display: block; font-size: 18px; }
.brand span { color: #92a4c2; font-size: 12px; }
.nav {
    display: flex; flex-direction: column; gap: 7px;
    flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden;
    overscroll-behavior-y: contain; scrollbar-gutter: stable;
    scrollbar-width: thin; scrollbar-color: #596b87 transparent;
    padding: 2px 6px 2px 0;
}
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-thumb { background: #596b87; border-radius: 6px; }
.nav a { flex: 0 0 auto; padding: 11px 14px; border-radius: 10px; color: #aebcd3; transition: .16s ease; scroll-margin-block: 8px; }
.nav a:hover { background: rgba(255,255,255,.07); color: white; }
.nav a:focus-visible { outline: 2px solid #c1d2f1; outline-offset: -2px; color: white; }
.nav a.active { background: #4a68a3; color: white; box-shadow: 0 8px 20px rgba(24, 44, 84, .35); }
.sidebar-footer { flex: 0 0 auto; margin: 18px 8px 0; }
.sidebar-footer form { margin: 0; }
.logout { width: 100%; padding: 9px; color: #aebcd3; background: transparent; border: 1px solid #3d4b62; border-radius: 9px; cursor: pointer; }

.main { min-width: 0; padding: 30px 34px 50px; }
.topbar { display: flex; justify-content: space-between; align-items: end; margin-bottom: 24px; }
.topbar h1 { margin: 0 0 6px; font-size: 28px; letter-spacing: -.5px; }
.topbar p { margin: 0; color: var(--muted); }
.pill { padding: 8px 12px; color: var(--green); background: #e4f6ef; border-radius: 999px; font-size: 13px; font-weight: 650; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.metric, .panel { background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.metric { padding: 20px; border-radius: 15px; }
.metric .label { color: var(--muted); font-size: 13px; }
.metric .value { margin-top: 8px; font-size: 29px; font-weight: 750; }
.panel { border-radius: 16px; overflow: hidden; }
.panel-header { display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; font-size: 17px; }
.panel-body { padding: 20px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.field { display: grid; gap: 6px; }
.field label { color: var(--muted); font-size: 12px; font-weight: 650; }
input, select {
    min-height: 40px; padding: 8px 11px; color: var(--text); background: white;
    border: 1px solid #cfd9e8; border-radius: 9px; outline: none;
}
input:focus, select:focus { border-color: #7290c6; box-shadow: 0 0 0 3px rgba(73, 105, 168, .12); }
.btn { min-height: 40px; padding: 8px 14px; border: 0; border-radius: 9px; cursor: pointer; font-weight: 650; }
.btn-primary { color: white; background: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-muted { color: #4e607b; background: var(--surface-soft); }
.btn-danger { color: var(--red); background: #fae9eb; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form input { max-width: 150px; }
.btn-small { min-height: 34px; padding: 6px 10px; font-size: 12px; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th { padding: 12px 15px; color: var(--muted); background: #f7f9fc; font-size: 12px; text-align: left; }
td { padding: 14px 15px; border-top: 1px solid #e7ecf3; font-size: 14px; vertical-align: middle; }
tbody tr:hover { background: #fbfcfe; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; }
.status { display: inline-block; padding: 5px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.status-ok, .status-ACTIVE, .status-SUCCEEDED, .status-UNUSED { color: var(--green); background: #e4f6ef; }
.status-PROCESSING, .status-CREATED { color: var(--primary); background: #e8eef9; }
.status-FAILED, .status-SUSPENDED, .status-EXPIRED, .status-DISABLED { color: var(--red); background: #fae9eb; }
.status-REDEEMED, .status-CANCELLED { color: var(--orange); background: #fff1df; }
.empty { padding: 45px 20px; color: var(--muted); text-align: center; }
.notice { margin-bottom: 18px; padding: 14px 16px; border-radius: 11px; color: #2e527f; background: #e8f1fc; }
.client-policy-form { display: grid; gap: 16px; }
.client-policy-form textarea { width: 100%; resize: vertical; min-height: 100px; padding: 10px 12px; font: inherit; color: var(--text); border: 1px solid #cfd9e8; border-radius: 9px; }
.client-policy-form .field span { color: var(--muted); font-size: 12px; font-weight: 650; }
.client-policy-check { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.client-policy-check input { min-height: auto; width: 17px; height: 17px; }
.client-policy-help, .client-policy-warning { margin: 0; font-size: 13px; line-height: 1.6; }
.client-policy-warning { color: var(--red); padding: 10px 12px; background: #fff4f4; border-radius: 9px; }
.client-policy-notice { margin-top: 22px; }
@media (max-width: 1100px) { .client-policy-grid { grid-template-columns: minmax(0, 1fr); } }
.code-box { max-height: 270px; overflow: auto; padding: 14px; border: 1px dashed #a9b9d0; border-radius: 10px; background: #f6f8fc; }
.code-box code { display: block; margin: 4px 0; user-select: all; }

.accounts-table { min-width: 1160px; table-layout: fixed; }
.accounts-table th:nth-child(1) { width: 245px; }
.accounts-table th:nth-child(2) { width: 125px; }
.accounts-table th:nth-child(3) { width: 145px; }
.accounts-table th:nth-child(4) { width: 240px; }
.accounts-table th:nth-child(5) { width: 130px; }
.accounts-table th:nth-child(6) { width: 82px; }
.accounts-table th:nth-child(7) { width: 190px; }
.accounts-table td { padding-top: 11px; padding-bottom: 11px; overflow: hidden; text-overflow: ellipsis; }
.accounts-table td:first-child .mono { overflow: hidden; text-overflow: ellipsis; }
.expiry-form, .balance-form, .account-actions { display: flex; align-items: center; gap: 6px; }
.expiry-form input { width: 178px; min-height: 34px; padding: 5px 7px; font-size: 12px; }
.balance-form { flex-wrap: wrap; width: 142px; }
.balance-form input { width: 92px; min-height: 34px; padding: 5px 8px; }
.balance-form label { order: 1; display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.balance-form input[type="checkbox"] { width: 14px; height: 14px; min-height: 0; padding: 0; }
.account-actions { align-items: flex-start; flex-wrap: wrap; }
.account-actions form { margin: 0; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: radial-gradient(circle at top, #dce8fa, #f4f7fb 48%); }
.login-card { width: min(420px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 20px; background: white; box-shadow: 0 22px 70px rgba(44, 66, 105, .16); }
.login-card .brand { margin: 0 0 28px; color: var(--text); }
.login-card form { display: grid; gap: 15px; }
.login-card .btn { margin-top: 5px; }
.alert { padding: 11px 13px; border-radius: 9px; font-size: 13px; }
.alert-error { color: #9c2630; background: #fdebed; }
.alert-ok { color: #117a58; background: #e5f7ef; }
.admin-toast {
    position: fixed; z-index: 1000; top: 24px; right: 28px;
    display: flex; align-items: center; gap: 10px; min-width: 230px;
    padding: 13px 17px; color: #176b52; background: #f0f9eb;
    border: 1px solid #d7edca; border-radius: 9px;
    box-shadow: 0 10px 28px rgba(28, 55, 45, .16);
    font-size: 14px; font-weight: 600;
    animation: admin-toast-in .2s ease-out;
    transition: opacity .2s ease, transform .2s ease;
}
.admin-toast-icon {
    width: 19px; height: 19px; display: grid; place-items: center;
    color: white; background: #67c23a; border-radius: 50%; font-size: 12px;
}
.admin-toast-hide { opacity: 0; transform: translateY(-8px); pointer-events: none; }
@keyframes admin-toast-in {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1000px) {
    .layout { grid-template-columns: 190px minmax(0, 1fr); }
    .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .main { padding: 24px 20px 40px; }
}
