:root {
    color-scheme: light;
    --bg: #f3f5f2;
    --surface: #ffffff;
    --surface-soft: #f8faf8;
    --ink: #17211d;
    --muted: #68756f;
    --line: #d5ddd8;
    --line-dark: #bdc9c2;
    --green: #147452;
    --green-dark: #0d5e42;
    --green-soft: #e9f5ef;
    --amber: #a66a12;
    --amber-soft: #fff3dc;
    --blue: #315b8b;
    --blue-soft: #eaf1f8;
    --violet: #76528c;
    --violet-soft: #f2ebf6;
    --red: #a23838;
    --red-soft: #faeceb;
    --shadow: 0 20px 45px rgba(25, 42, 34, 0.08);
    font-family: Inter, "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--bg); font-size: 15px; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
a { color: inherit; }

.auth-shell {
    width: min(1024px, calc(100% - 32px));
    min-height: 100vh;
    margin: 0 auto;
    display: grid;
    align-content: center;
    gap: 28px;
    padding: 48px 0;
}
.compact-auth { width: min(560px, calc(100% - 32px)); }
.brand-block { text-align: center; }
.eyebrow { display: block; color: var(--green); font-size: 12px; font-weight: 800; text-transform: uppercase; line-height: 1.4; }
.brand-block h1, .page-heading h1 { margin: 8px 0 0; font-size: 34px; line-height: 1.18; }
.auth-card { padding: 30px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.auth-card.login-only { display: grid; gap: 20px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 28px; border: 1px solid var(--line-dark); border-radius: 7px; background: var(--surface-soft); }
.segment { min-height: 52px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 700; }
.segment.active { background: var(--ink); color: #fff; }
.tab-panel { display: none; gap: 20px; }
.tab-panel.active { display: grid; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field { display: grid; gap: 7px; min-width: 0; }
.field > span { font-weight: 700; }
.field input, .field select, textarea {
    width: 100%;
    min-height: 48px;
    padding: 0 14px;
    border: 1px solid var(--line-dark);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    outline: none;
}
.field input:focus, .field select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(20, 116, 82, 0.12); }
.button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; padding: 0 18px; border: 1px solid transparent; border-radius: 6px; cursor: pointer; text-decoration: none; font-weight: 750; white-space: nowrap; }
.button-primary { background: var(--green); color: #fff; }
.button-primary:hover { background: var(--green-dark); }
.button-secondary { border-color: var(--line-dark); background: #fff; color: var(--ink); }
.button-danger { border-color: #e6b9b7; background: var(--red-soft); color: var(--red); }
.button-wide { width: 100%; margin-top: 10px; }
.button-small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.admin-entry { justify-self: center; color: var(--muted); font-weight: 650; text-decoration: none; }
.admin-entry:hover { color: var(--green); }

.toast { position: fixed; z-index: 50; top: 18px; left: 50%; width: min(520px, calc(100% - 32px)); transform: translateX(-50%); padding: 14px 18px; border: 1px solid; border-radius: 7px; box-shadow: var(--shadow); font-weight: 700; text-align: center; }
.toast-success { border-color: #b7ddc9; background: #eff9f4; color: var(--green-dark); }
.toast-error { border-color: #e5b6b3; background: var(--red-soft); color: var(--red); }

.topbar { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 12px max(24px, calc((100vw - 1500px) / 2)); border-bottom: 1px solid var(--line); background: rgba(255,255,255,0.95); }
.topbar-title { display: block; margin-top: 2px; font-size: 19px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-actions form { margin: 0; }
.topbar-role { color: var(--muted); font-weight: 700; }
.status-dot { width: 10px; height: 10px; flex: 0 0 10px; border-radius: 50%; background: #1e9a68; }
.status-dot.status-bad { background: #c44e49; }
.brand-link { text-decoration: none; }
.health-label { color: var(--muted); }

.page-shell { width: min(1500px, calc(100% - 48px)); margin: 0 auto; padding: 36px 0 56px; }
.page-heading { display: flex; min-height: 80px; align-items: flex-end; justify-content: space-between; gap: 24px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.page-heading h1 { font-size: 30px; }
.limit-meter, .health-box { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.limit-meter span { color: var(--muted); }
.limit-meter strong { font-size: 18px; }
.inline-alert { margin: 22px 0; padding: 14px 16px; border-radius: 6px; }
.inline-alert.error { border: 1px solid #e5b6b3; background: var(--red-soft); color: var(--red); }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; margin: 24px 0; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--line); }
.stat { min-height: 112px; display: grid; align-content: center; gap: 5px; padding: 18px 20px; background: var(--surface); }
.stat span, .stat small { color: var(--muted); }
.stat strong { overflow: hidden; font-size: 23px; text-overflow: ellipsis; white-space: nowrap; }
.tool-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; }
.tool-card { min-width: 0; display: grid; align-content: start; gap: 18px; padding: 22px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.tool-card > .button { justify-self: end; }
.tool-heading { display: flex; align-items: center; gap: 14px; }
.tool-heading h2 { margin: 0 0 3px; font-size: 19px; }
.tool-heading p { margin: 0; color: var(--muted); }
.tool-icon { width: 44px; height: 44px; display: grid; flex: 0 0 44px; place-items: center; border-radius: 7px; background: var(--green-soft); color: var(--green); font-size: 20px; font-weight: 850; }
.tool-icon.amber { background: var(--amber-soft); color: var(--amber); }
.tool-icon.blue { background: var(--blue-soft); color: var(--blue); }
.tool-icon.violet { background: var(--violet-soft); color: var(--violet); }
.tool-icon.neutral { background: #edf0ee; color: #4c5a54; }
.history-card { grid-row: span 2; }
.catalog-picker { display: grid; gap: 10px; min-width: 0; }
.catalog-meta { min-height: 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13px; }
.catalog-meta strong { max-width: 70%; overflow: hidden; color: var(--green-dark); text-overflow: ellipsis; white-space: nowrap; }
.catalog-list { height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); overscroll-behavior: contain; }
.catalog-option { width: 100%; min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 12px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.catalog-option:last-child { border-bottom: 0; }
.catalog-option:hover, .catalog-option.selected { background: var(--green-soft); }
.catalog-option.selected { box-shadow: inset 3px 0 0 var(--green); }
.catalog-option-main { min-width: 0; display: grid; gap: 3px; }
.catalog-option-main strong, .catalog-option-main small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catalog-option-main small { color: var(--muted); }
.catalog-option-meta { display: grid; flex: 0 0 auto; justify-items: end; gap: 3px; }
.catalog-option-meta code { color: var(--ink); font-family: Consolas, monospace; font-size: 13px; }
.catalog-option-meta small { color: var(--muted); }
.catalog-empty { height: 100%; display: grid; place-items: center; color: var(--muted); }
.history-list { display: grid; }
.history-row { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; border-top: 1px solid var(--line); }
.history-row strong, td strong { display: block; }
.history-row small, td small { display: block; margin-top: 3px; color: var(--muted); }
.empty { padding: 30px 12px !important; color: var(--muted); text-align: center; }
.badge { display: inline-flex; min-height: 26px; align-items: center; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge-success { background: var(--green-soft); color: var(--green-dark); }
.badge-pending { background: var(--amber-soft); color: var(--amber); }
.badge-failed { background: var(--red-soft); color: var(--red); }

.admin-nav { min-height: 50px; display: flex; align-items: stretch; gap: 4px; padding: 0 max(24px, calc((100vw - 1500px) / 2)); overflow-x: auto; border-bottom: 1px solid var(--line); background: #fff; }
.admin-nav a { min-width: max-content; display: flex; align-items: center; padding: 0 16px; border-bottom: 3px solid transparent; color: var(--muted); font-weight: 700; text-decoration: none; }
.admin-nav a.active { border-bottom-color: var(--green); color: var(--green-dark); }
.admin-shell { padding-top: 28px; }
.admin-stats { margin-top: 24px; }
.section-band { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line); }
.section-title { min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-title h2 { margin: 0; font-size: 19px; }
.section-title a { color: var(--green); font-weight: 700; }
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { padding: 13px 14px; background: var(--surface-soft); color: var(--muted); text-align: left; white-space: nowrap; }
td { min-width: 110px; padding: 14px; border-top: 1px solid var(--line); vertical-align: middle; }
.row-actions { display: flex; align-items: center; gap: 8px; }
.inline-reset { display: flex; gap: 6px; }
.inline-reset input { width: 120px; min-height: 36px; padding: 0 9px; border: 1px solid var(--line-dark); border-radius: 5px; }
.split-tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; margin-top: 24px; }
.policy-panel { min-width: 0; padding: 24px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.policy-panel h2 { margin: 7px 0 18px; }
.policy-panel dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0 0 20px; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.policy-panel dl div { padding: 15px; border-bottom: 1px solid var(--line); }
.policy-panel dl div:nth-child(odd) { border-right: 1px solid var(--line); }
.policy-panel dl div:nth-last-child(-n+2) { border-bottom: 0; }
.policy-panel dt { color: var(--muted); }
.policy-panel dd { margin: 5px 0 0; font-size: 20px; font-weight: 800; }
.generated-codes { margin-top: 22px; padding: 20px; border: 1px solid #ead7ac; border-radius: 8px; background: #fffbf1; }
.generated-codes textarea { min-height: 150px; margin-top: 10px; padding: 14px; resize: vertical; font-family: Consolas, monospace; line-height: 1.7; }
.check-row { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.check-row input { width: 18px; height: 18px; accent-color: var(--green); }

@media (max-width: 900px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tool-grid, .split-tools { grid-template-columns: 1fr; }
    .history-card { grid-row: auto; }
    .topbar { align-items: flex-start; }
    .health-label { display: none; }
}

@media (max-width: 620px) {
    .auth-shell { width: min(100% - 24px, 1024px); padding: 28px 0; gap: 20px; }
    .brand-block h1 { font-size: 28px; }
    .auth-card { padding: 18px; }
    .segmented { margin-bottom: 22px; }
    .segment { min-height: 46px; }
    .field-grid { grid-template-columns: 1fr; gap: 14px; }
    .topbar { min-height: 64px; padding: 10px 14px; gap: 12px; }
    .topbar .eyebrow, .topbar-role { display: none; }
    .topbar-title { font-size: 17px; }
    .topbar-actions { gap: 8px; }
    .page-shell { width: calc(100% - 24px); padding: 24px 0 40px; }
    .page-heading { align-items: flex-start; }
    .page-heading h1 { font-size: 26px; }
    .limit-meter { padding: 9px 11px; }
    .limit-meter span { display: none; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stat { min-height: 96px; padding: 14px; }
    .stat strong { font-size: 19px; }
    .tool-card, .policy-panel { padding: 18px; }
    .tool-card > .button { width: 100%; }
    .admin-nav { padding: 0 8px; }
    .admin-nav a { padding: 0 12px; }
    .row-actions { align-items: stretch; flex-direction: column; }
    .inline-reset input { width: 105px; }
    .policy-panel dl { grid-template-columns: 1fr; }
    .policy-panel dl div, .policy-panel dl div:nth-child(odd), .policy-panel dl div:nth-last-child(-n+2) { border-right: 0; border-bottom: 1px solid var(--line); }
    .policy-panel dl div:last-child { border-bottom: 0; }
}
