:root {
  color-scheme: light;
  --ink: #17201d;
  --muted: #65706c;
  --line: #d8dedb;
  --surface: #ffffff;
  --canvas: #f4f6f5;
  --green: #147d50;
  --green-dark: #0d5f3c;
  --green-soft: #dff3e8;
  --coral: #c7543b;
  --coral-soft: #fbe8e3;
  --amber: #9b6815;
  --amber-soft: #fff2d5;
  --shadow: 0 8px 24px rgba(19, 35, 28, 0.07);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font: 14px/1.5 "Segoe UI", "Microsoft YaHei", sans-serif; letter-spacing: 0; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
h1 { font-size: 18px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 700; }
.hidden { display: none !important; }
.subtle { color: var(--muted); font-size: 12px; }
.topbar { height: 64px; padding: 0 28px; display: flex; align-items: center; justify-content: space-between; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand-block, .header-actions { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; background: var(--green); color: white; border-radius: 6px; font-size: 12px; font-weight: 800; }
.admin-mark { background: var(--coral); }
.text-link { color: var(--green-dark); text-decoration: none; font-weight: 650; }
.text-link:hover { text-decoration: underline; }
.page-shell { width: min(1180px, calc(100% - 32px)); margin: 22px auto 56px; display: grid; gap: 18px; }
.heatmap-band, .workbench, .results-band, .management-band, .login-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); padding: 20px; }
.section-heading { min-height: 40px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.legend { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 11px; }
.legend i { width: 12px; height: 12px; background: #e4e8e6; border: 1px solid rgba(0,0,0,.03); border-radius: 2px; }
.legend .level-1, .heat-cell.level-1 { background: #9bd5b7; }
.legend .level-2, .heat-cell.level-2 { background: #47aa78; }
.legend .level-3, .heat-cell.level-3 { background: #147d50; }
/* 48 列 × 3 行 = 144 格（12h / 5min），列均分铺满容器；按行填充：先从左到右，再从上到下 */
.heatmap {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(48, minmax(0, 1fr));
  grid-template-rows: repeat(3, auto);
  grid-auto-flow: row;
  gap: 3px;
  padding: 2px 0 4px;
}
.heat-cell {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  min-width: 0;
  background: #e4e8e6;
  border: 1px solid rgba(0,0,0,.03);
  border-radius: 2px;
}
.form-stack { display: grid; gap: 10px; }
.field-label { color: #39433f; font-size: 12px; font-weight: 700; display: block; margin-bottom: 5px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-count { color: var(--muted); font-size: 12px; }
input, textarea { width: 100%; border: 1px solid #bcc7c2; border-radius: 5px; background: white; color: var(--ink); padding: 10px 11px; outline: none; }
textarea { resize: vertical; min-height: 80px; font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }
input:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(20, 125, 80, .12); }
.inline-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.button { min-height: 36px; border-radius: 5px; border: 1px solid transparent; padding: 7px 14px; font-weight: 700; white-space: nowrap; }
.button:disabled { cursor: default; opacity: .45; }
.button.primary { color: white; background: var(--green); border-color: var(--green); }
.button.primary:hover:not(:disabled) { background: var(--green-dark); }
.button.secondary { color: var(--ink); background: white; border-color: #b8c4be; }
.button.secondary:hover:not(:disabled) { background: #f0f4f2; }
.button.ghost { color: var(--muted); background: transparent; border-color: transparent; }
.form-actions { min-height: 42px; display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.form-message { color: var(--coral); font-size: 12px; overflow-wrap: anywhere; }
.token-preview { border: 1px solid var(--line); border-radius: 5px; max-height: 230px; overflow: auto; }
.token-preview.empty-state { padding: 22px; color: var(--muted); text-align: center; }
.token-item { display: grid; grid-template-columns: 42px minmax(0, 1fr) 100px; align-items: center; gap: 10px; padding: 9px 11px; border-bottom: 1px solid #edf0ee; }
.token-item:last-child { border-bottom: 0; }
.token-index { color: var(--muted); font-variant-numeric: tabular-nums; }
.token-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state-pill { display: inline-flex; align-items: center; justify-content: center; min-width: 72px; min-height: 24px; border-radius: 999px; padding: 2px 9px; font-size: 11px; font-weight: 700; background: #edf0ef; color: #4e5954; }
.state-pill.success { background: var(--green-soft); color: var(--green-dark); }
.state-pill.failed { background: var(--coral-soft); color: var(--coral); }
.state-pill.running { background: var(--amber-soft); color: var(--amber); }
.result-heading { align-items: center; }
.download-group { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.table-wrap { width: 100%; overflow: auto; border: 1px solid var(--line); border-radius: 5px; }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th, td { padding: 10px 11px; border-bottom: 1px solid #e8ecea; text-align: left; vertical-align: middle; }
th { background: #f6f8f7; color: #4d5853; font-size: 11px; text-transform: uppercase; font-weight: 750; }
.select-col { width: 42px; text-align: center; }
.select-all-label, .row-select-label { display: inline-flex; align-items: center; justify-content: center; margin: 0; cursor: pointer; }
.select-col input[type="checkbox"] { width: 15px; height: 15px; margin: 0; accent-color: var(--green); cursor: pointer; }
.select-col input[type="checkbox"]:disabled { cursor: default; opacity: .35; }
tbody tr:last-child td { border-bottom: 0; }
.status-stack { display: grid; gap: 3px; min-width: 170px; }
.refresh-token { display: flex; align-items: center; gap: 7px; max-width: 360px; }
.token-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: "Cascadia Mono", Consolas, monospace; font-size: 11px; }
.mini-button { border: 0; background: transparent; color: var(--green-dark); font-weight: 700; padding: 3px; }
.toast { position: fixed; right: 18px; bottom: 18px; max-width: min(380px, calc(100% - 36px)); background: #1f2b26; color: white; border-radius: 5px; padding: 10px 14px; box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); pointer-events: none; transition: .18s ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
.admin-shell { max-width: 1280px; }
.login-panel { width: min(420px, 100%); margin: 70px auto 0; }
.compact-form { gap: 8px; }
.admin-dashboard { display: grid; gap: 18px; }
.generator-grid { display: grid; grid-template-columns: 150px 150px minmax(220px, 1fr) auto; gap: 10px; align-items: end; }
.generator-grid label { min-width: 0; }
.settings-grid { display: grid; grid-template-columns: 180px 180px; gap: 12px 14px; align-items: start; }
.settings-grid .country-field { grid-column: 1 / -1; display: grid; gap: 8px; }
.settings-grid .settings-save { justify-self: start; }
.settings-grid .form-message { grid-column: 1 / -1; min-height: 18px; }
.country-toolbar { display: grid; grid-template-columns: minmax(180px, 1fr) auto auto; gap: 8px; align-items: center; }
.country-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  max-height: 280px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}
.country-option {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: white;
  cursor: pointer;
}
.country-option:hover { border-color: #c9d5cf; }
.country-option input { margin-top: 2px; }
.country-option .country-meta { display: grid; gap: 2px; min-width: 0; }
.country-option .country-title { font-size: 13px; font-weight: 700; color: #24312c; }
.country-option .country-sub { font-size: 11px; color: #66746e; word-break: break-word; }
.country-option.hidden { display: none; }
.generated-panel { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 15px; }
.generated-panel textarea { margin-top: 8px; }
.search-toolbar { display: grid; grid-template-columns: minmax(260px, 1fr) auto auto; align-items: end; gap: 8px; margin-bottom: 12px; }
.search-toolbar textarea { min-height: 62px; }
.pager { display: flex; justify-content: flex-end; align-items: center; gap: 7px; margin-top: 12px; min-height: 36px; }
.pager input { width: 64px; height: 34px; padding: 5px 8px; }
.pager .button { min-height: 34px; padding: 5px 10px; }
.code-cell { font-family: "Cascadia Mono", Consolas, monospace; font-size: 11px; white-space: nowrap; }

@media (max-width: 760px) {
  .topbar { height: auto; min-height: 60px; padding: 10px 16px; }
  .page-shell { width: min(100% - 20px, 1180px); margin-top: 10px; }
  .heatmap-band, .workbench, .results-band, .management-band, .login-panel { padding: 14px; }
  .section-heading, .result-heading { align-items: flex-start; flex-direction: column; }
  .legend { align-self: flex-end; }
  .generator-grid { grid-template-columns: 1fr 1fr; }
  .generator-grid .note-field { grid-column: 1 / -1; }
  .generator-grid > .button { grid-column: 1 / -1; }
  .settings-grid { grid-template-columns: 1fr 1fr; }
  .country-toolbar { grid-template-columns: 1fr 1fr; }
  .country-toolbar input { grid-column: 1 / -1; }
  .search-toolbar { grid-template-columns: 1fr 1fr; }
  .search-toolbar textarea { grid-column: 1 / -1; }
  .token-item { grid-template-columns: 32px minmax(0, 1fr); }
  .token-item .state-pill { grid-column: 2; justify-self: start; }
  .download-group { justify-content: flex-start; }
}
