:root {
  --bg: #eef1ec;
  --paper: #f8faf6;
  --ink: #141914;
  --muted: #697168;
  --line: #cdd4ca;
  --accent: #ff5c35;
  --accent-dark: #c93818;
  --green: #18784a;
  --red: #b52c2c;
  --amber: #9b6513;
  --shadow: 0 18px 60px rgba(24, 34, 23, .09);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 4%, rgba(255, 92, 53, .10), transparent 25rem),
    linear-gradient(rgba(20, 25, 20, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 25, 20, .035) 1px, transparent 1px),
    var(--bg);
  background-size: auto, 32px 32px, 32px 32px, auto;
  min-height: 100vh;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .42; }

.page-shell { width: min(1500px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 70px; }
.hero { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.eyebrow { font: 700 11px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .28em; color: var(--accent-dark); }
h1 { margin: 6px 0 4px; font: 900 clamp(34px, 5vw, 68px)/.96 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: -.07em; }
.hero p { margin: 12px 0 0; color: var(--muted); }
.service-status { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.health { border: 1px solid var(--line); background: rgba(248,250,246,.75); padding: 10px 14px; border-radius: 999px; font-size: 13px; }
.health.ok { color: var(--green); border-color: rgba(24,120,74,.35); }
.health.bad { color: var(--red); border-color: rgba(181,44,44,.35); }
.queue-status { display: inline-grid; grid-template-columns: auto minmax(2ch, auto) auto; align-items: baseline; gap: 5px; min-width: 112px; min-height: 40px; padding: 9px 13px; border: 1px solid var(--line); border-radius: 999px; background: rgba(248,250,246,.75); font-size: 12px; white-space: nowrap; }
.queue-status strong { font: 800 17px/1 ui-monospace, SFMono-Regular, Consolas, monospace; text-align: right; }
.queue-status.idle { color: var(--green); border-color: rgba(24,120,74,.35); }
.queue-status.busy { color: var(--amber); border-color: rgba(155,101,19,.4); background: rgba(155,101,19,.07); }
.queue-status.bad { color: var(--red); border-color: rgba(181,44,44,.35); }

.panel { background: rgba(248, 250, 246, .94); border: 1px solid var(--line); box-shadow: var(--shadow); }
.input-panel { padding: 24px; }
.panel-title { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 16px; }
.panel-title > div:first-child { display: flex; align-items: center; gap: 12px; }
.panel-title h2 { margin: 0; font-size: 18px; }
.step { display: grid; place-items: center; width: 34px; height: 34px; color: white; background: var(--ink); font: 700 12px ui-monospace, monospace; }
.thread-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.thread-control input, .thread-control select { min-width: 86px; }

textarea {
  width: 100%; min-height: 190px; resize: vertical; border: 1px solid var(--line); outline: none;
  background: #111611; color: #d8f8d3; padding: 18px; font: 13px/1.75 ui-monospace, SFMono-Regular, Consolas, monospace;
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,92,53,.12); }
.input-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 14px; }
.input-footer p { color: var(--muted); margin: 0; font-size: 13px; }
button, select, input { min-height: 38px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); padding: 0 13px; }
button:hover:not(:disabled) { border-color: var(--ink); }
button.primary { color: white; border-color: var(--accent); background: var(--accent); font-weight: 750; padding-inline: 26px; }
button.primary:hover { background: var(--accent-dark); }

.stats { display: grid; grid-template-columns: repeat(7, 1fr); border: 1px solid var(--line); margin: 22px 0; background: var(--line); gap: 1px; }
.stats article { background: rgba(248,250,246,.94); padding: 18px 20px; }
.stats span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.stats strong { font: 850 28px ui-monospace, monospace; }
.stats .success strong { color: var(--green); }
.stats .danger strong { color: var(--red); }

.results-panel { padding: 20px; }
.result-head { flex-wrap: wrap; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.retry-note { margin: -4px 0 14px; color: var(--muted); font-size: 12px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); }
table { width: 100%; min-width: 1060px; border-collapse: collapse; background: var(--paper); }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 13px; }
th { position: sticky; top: 0; background: #e8ece5; color: var(--muted); font-size: 11px; letter-spacing: .05em; text-transform: uppercase; z-index: 1; }
tbody tr:hover { background: #f0f3ed; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.empty { text-align: center; color: var(--muted); padding: 42px; }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); font-size: 12px; white-space: nowrap; }
.badge.success { color: var(--green); border-color: rgba(24,120,74,.3); background: rgba(24,120,74,.07); }
.badge.failed, .badge.totp_error { color: var(--red); border-color: rgba(181,44,44,.3); background: rgba(181,44,44,.07); }
.badge.not_expired { color: var(--green); border-color: rgba(24,120,74,.3); background: rgba(24,120,74,.07); }
.badge.running { color: var(--amber); border-color: rgba(155,101,19,.3); background: rgba(155,101,19,.08); }
.badge.queued { color: #4d5967; }
.live-totp { display: inline-flex; align-items: center; gap: 7px; margin-left: 8px; padding: 4px 7px; border: 1px solid rgba(155,101,19,.32); background: rgba(155,101,19,.08); white-space: nowrap; }
.live-totp span { color: var(--amber); font-size: 10px; font-weight: 750; }
.live-totp code { color: var(--ink); font: 800 15px/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .08em; }
.live-totp small { min-width: 24px; color: var(--muted); font: 10px/1 ui-monospace, monospace; text-align: right; }
.error-cell { max-width: 360px; color: var(--red); }
.error-detail { color: var(--muted); font: 11px/1.45 ui-monospace, monospace; margin-top: 4px; word-break: break-word; }
.export-buttons { display: flex; flex-wrap: wrap; gap: 5px; }
.export-buttons a { color: var(--ink); text-decoration: none; border: 1px solid var(--line); padding: 5px 7px; font-size: 11px; }
.export-buttons a:hover { color: var(--accent-dark); border-color: var(--accent); }

.toast { position: fixed; right: 24px; bottom: 24px; max-width: min(440px, calc(100vw - 48px)); padding: 13px 17px; color: white; background: var(--ink); box-shadow: var(--shadow); transform: translateY(30px); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.bad { background: var(--red); }

@media (max-width: 980px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .hero { flex-direction: column; }
  .service-status { width: 100%; }
}
@media (max-width: 620px) {
  .page-shell { width: min(100% - 20px, 1500px); padding-top: 22px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .service-status { align-items: stretch; flex-direction: column; }
  .queue-status, .health { width: 100%; justify-content: center; text-align: center; }
  .input-footer { align-items: stretch; flex-direction: column; }
  .input-footer button { width: 100%; }
}
