:root {
  --bg: #080c18;
  --bg-soft: #0d1324;
  --panel: rgba(18, 26, 46, 0.86);
  --panel-solid: #121a2e;
  --border: #243052;
  --border-soft: rgba(88, 112, 168, 0.18);
  --text: #e9edf9;
  --muted: #8e9ab8;
  --muted-2: #64708f;
  --accent: #6a93ff;
  --accent-2: #8a6bff;
  --green: #35d6a7;
  --amber: #ffb454;
  --red: #ff6b7a;
  --violet: #b18cff;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
  --font: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC",
    "Hiragino Sans GB", sans-serif;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 600px at 85% -10%, rgba(106, 147, 255, 0.16), transparent 60%),
    radial-gradient(900px 500px at 0% 0%, rgba(138, 107, 255, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: #9db8ff;
}

code {
  font-family: var(--mono);
  font-size: 0.92em;
  color: #cfe0ff;
  background: rgba(106, 147, 255, 0.1);
  border: 1px solid rgba(106, 147, 255, 0.14);
  padding: 1px 6px;
  border-radius: 6px;
  word-break: break-all;
}

.muted {
  color: var(--muted);
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px clamp(18px, 4vw, 48px);
  background: rgba(8, 12, 24, 0.78);
  border-bottom: 1px solid var(--border-soft);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
}

.brand:hover {
  color: var(--text);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-text strong {
  font-size: 15px;
  letter-spacing: 0.01em;
}

.brand-text small {
  color: var(--muted);
  font-size: 11px;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  padding: 7px 13px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(106, 147, 255, 0.12);
  color: var(--text);
}

.inline-form {
  display: inline;
  margin: 0;
}

.whoami {
  padding: 0 8px;
  color: var(--muted-2);
  font-family: var(--mono);
  font-size: 11px;
}

/* ---------- layout ---------- */

.container {
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: 30px clamp(18px, 4vw, 48px) 64px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.page-head h1 {
  margin: 0 0 4px;
  font-size: clamp(23px, 3vw, 30px);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.page-head p {
  margin: 0;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 4px;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  background: rgba(18, 26, 46, 0.6);
}

.back-link {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
}

.back-link:hover {
  color: var(--accent);
}

.client-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.client-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  color: var(--muted);
  font-size: 12px;
}

.client-meta .sep {
  color: var(--muted-2);
}

.client-meta code {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.footer {
  padding: 22px clamp(18px, 4vw, 48px) 34px;
  color: var(--muted-2);
  font-size: 11px;
  text-align: center;
  border-top: 1px solid var(--border-soft);
}

/* ---------- flashes / alerts ---------- */

.flashes {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.flash,
.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: 13px;
}

.flash.error,
.alert.error {
  border-color: rgba(255, 107, 122, 0.36);
  background: rgba(255, 107, 122, 0.1);
  color: #ffc2c9;
}

.flash.ok {
  border-color: rgba(53, 214, 167, 0.3);
  background: rgba(53, 214, 167, 0.08);
  color: #a9f2dd;
}

.alert {
  margin-bottom: 18px;
}

/* ---------- stats ---------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat-card {
  position: relative;
  overflow: hidden;
  padding: 16px 18px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stat-card::after {
  content: "";
  position: absolute;
  inset: auto -30% -70% auto;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(106, 147, 255, 0.25), transparent 65%);
  pointer-events: none;
}

.stat-card.accent-green::after {
  background: radial-gradient(circle, rgba(53, 214, 167, 0.22), transparent 65%);
}

.stat-card.accent-blue::after {
  background: radial-gradient(circle, rgba(106, 147, 255, 0.26), transparent 65%);
}

.stat-card.accent-amber::after {
  background: radial-gradient(circle, rgba(255, 180, 84, 0.2), transparent 65%);
}

.stat-card.accent-violet::after {
  background: radial-gradient(circle, rgba(177, 140, 255, 0.22), transparent 65%);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat-value {
  display: block;
  margin: 7px 0 3px;
  font-size: 29px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.stat-sub {
  color: var(--muted-2);
  font-size: 11px;
}

/* ---------- panels ---------- */

.panel {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border-soft);
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.panel-meta {
  color: var(--muted-2);
  font-size: 11px;
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 420px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted-2);
  font-size: 16px;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(8, 12, 24, 0.5);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(106, 147, 255, 0.15);
}

.search-box input::placeholder {
  color: var(--muted-2);
}

/* ---------- table ---------- */

.table-wrap {
  overflow-x: auto;
}

.client-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

.client-table th {
  padding: 11px 16px;
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-align: left;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}

.client-table td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(88, 112, 168, 0.1);
  vertical-align: middle;
}

.client-table tbody tr {
  transition: background 0.15s ease;
}

.client-table tbody tr:hover {
  background: rgba(106, 147, 255, 0.045);
}

.client-table tbody tr:last-child td {
  border-bottom: 0;
}

.run-table {
  min-width: 760px;
}

.run-table td {
  padding: 11px 14px;
}

.client-name {
  font-weight: 600;
  color: #f2f5ff;
}

.client-sub {
  color: var(--muted-2);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-id {
  margin-top: 2px;
  color: var(--muted-2);
  font-family: var(--mono);
  font-size: 10px;
}

.clamp {
  max-width: 230px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  white-space: nowrap;
}

.status.online {
  color: var(--green);
}

.status.offline {
  color: var(--muted-2);
}

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.status.online .dot {
  color: var(--green);
  box-shadow: 0 0 0 3px rgba(53, 214, 167, 0.14);
}

.dot.pulse {
  color: var(--green);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(53, 214, 167, 0.3); }
  50% { opacity: 0.55; box-shadow: 0 0 0 4px rgba(53, 214, 167, 0.06); }
}

.state-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  white-space: nowrap;
  color: #cbd6f5;
  background: rgba(106, 147, 255, 0.1);
  border: 1px solid rgba(106, 147, 255, 0.16);
}

.state-waiting_wechat,
.state-waiting_image,
.state-scanning_image,
.state-waiting_login {
  color: #b9c8eb;
  background: rgba(106, 147, 255, 0.1);
  border-color: rgba(106, 147, 255, 0.16);
}

.state-hooking {
  color: #ffe0af;
  background: rgba(255, 180, 84, 0.1);
  border-color: rgba(255, 180, 84, 0.22);
}

.state-waiting_restart,
.state-error {
  color: #ffc2c9;
  background: rgba(255, 107, 122, 0.1);
  border-color: rgba(255, 107, 122, 0.22);
}

.state-done {
  color: #a9f2dd;
  background: rgba(53, 214, 167, 0.1);
  border-color: rgba(53, 214, 167, 0.24);
}

.wechat-on {
  color: var(--green);
  font-size: 12px;
}

.wechat-off {
  color: var(--muted-2);
  font-size: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  white-space: nowrap;
  border: 1px solid transparent;
}

.chip.ok {
  color: #a9f2dd;
  background: rgba(53, 214, 167, 0.1);
  border-color: rgba(53, 214, 167, 0.22);
}

.chip.missing {
  color: var(--muted-2);
  background: rgba(142, 154, 184, 0.06);
  border-color: rgba(142, 154, 184, 0.14);
}

.chip.done {
  color: #d9ccff;
  background: rgba(177, 140, 255, 0.12);
  border-color: rgba(177, 140, 255, 0.24);
}

.chip.warn {
  color: #ffe0af;
  background: rgba(255, 180, 84, 0.1);
  border-color: rgba(255, 180, 84, 0.22);
}

.run-count {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.row-action {
  text-align: right;
}

.empty-row:hover {
  background: transparent !important;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 46px 20px;
  color: var(--muted);
  text-align: center;
}

.empty strong {
  color: #cfd9f3;
  font-size: 14px;
}

.empty span {
  font-size: 12px;
}

.empty.small {
  padding: 26px 20px;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(20, 29, 51, 0.8);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.btn:hover {
  border-color: rgba(106, 147, 255, 0.55);
  background: rgba(106, 147, 255, 0.12);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 600;
  box-shadow: 0 10px 26px rgba(106, 147, 255, 0.28);
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.btn.ghost {
  background: transparent;
}

.btn.tiny {
  padding: 4px 9px;
  border-radius: 8px;
  font-size: 11px;
}

.btn.block {
  width: 100%;
}

.btn.danger {
  border-color: rgba(255, 107, 122, 0.35);
  background: rgba(255, 107, 122, 0.1);
  color: #ffc2c9;
}

.btn.danger:hover {
  border-color: rgba(255, 107, 122, 0.7);
  background: rgba(255, 107, 122, 0.18);
}

/* ---------- login ---------- */

.login-wrap {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 230px);
}

.login-card {
  width: min(390px, 100%);
  padding: 34px 30px 26px;
  border: 1px solid var(--border-soft);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(22, 31, 55, 0.94), rgba(14, 20, 38, 0.94));
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 5px;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.login-card > .muted {
  margin: 0 0 22px;
  font-size: 12px;
}

.login-form {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
}

.field input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(8, 12, 24, 0.55);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(106, 147, 255, 0.15);
}

/* ---------- client detail ---------- */

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.key-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
}

.key-card {
  padding: 20px;
  border-right: 1px solid var(--border-soft);
}

.key-card:last-child {
  border-right: 0;
}

.key-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.key-title {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.key-card .secret {
  display: block;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(8, 12, 24, 0.5);
  color: #d7e4ff;
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.key-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 8px;
}

.key-empty {
  padding: 24px 14px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--muted-2);
  font-size: 12px;
  text-align: center;
}

.key-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--muted);
}

.key-line > span {
  flex: 0 0 62px;
}

.key-line code {
  flex: 1;
  padding: 7px 10px;
  background: rgba(8, 12, 24, 0.45);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-wrap: anywhere;
}

.info-list,
.info-grid {
  margin: 0;
}

.info-list {
  display: grid;
  gap: 0;
  padding: 4px 18px 14px;
}

.info-list > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px dashed rgba(88, 112, 168, 0.13);
}

.info-list > div:last-child {
  border-bottom: 0;
}

.info-list dt {
  color: var(--muted-2);
  font-size: 11px;
  white-space: nowrap;
}

.info-list dd {
  margin: 0;
  font-size: 12px;
  text-align: right;
  overflow-wrap: anywhere;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--border-soft);
}

.info-grid > div {
  padding: 14px 18px;
  background: var(--panel-solid);
}

.info-grid dt {
  margin-bottom: 3px;
  color: var(--muted-2);
  font-size: 11px;
}

.info-grid dd {
  margin: 0;
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

/* ---------- timeline ---------- */

.timeline {
  list-style: none;
  margin: 0;
  padding: 8px 22px 18px;
}

.event {
  position: relative;
  display: flex;
  gap: 14px;
  padding: 13px 0 13px 4px;
}

.event::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 30px;
  bottom: -2px;
  width: 1px;
  background: var(--border-soft);
}

.event:last-child::before {
  display: none;
}

.event-dot {
  position: relative;
  z-index: 1;
  flex: 0 0 11px;
  width: 11px;
  height: 11px;
  margin-top: 4px;
  border-radius: 50%;
  background: #3b4a72;
  box-shadow: 0 0 0 4px rgba(59, 74, 114, 0.16);
}

.event-online .event-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(106, 147, 255, 0.14);
}

.event-db_key .event-dot,
.event-image_key .event-dot,
.event-final .event-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(53, 214, 167, 0.14);
}

.event-error .event-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(255, 107, 122, 0.14);
}

.event-status .event-dot {
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(255, 180, 84, 0.14);
}

.event-body {
  flex: 1;
  min-width: 0;
}

.event-msg {
  font-size: 12.5px;
  color: #dbe4fa;
}

/* ---------- danger zone / error page ---------- */

.danger-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 20px;
  border-color: rgba(255, 107, 122, 0.2);
}

.danger-panel h2 {
  margin: 0 0 4px;
  font-size: 14px;
}

.danger-panel p {
  margin: 0;
  font-size: 12px;
}

.danger-panel form {
  margin: 0;
}

.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 55vh;
  text-align: center;
}

.error-code {
  font-size: clamp(64px, 12vw, 120px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.06em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.error-page h1 {
  margin: 8px 0 0;
  font-size: 20px;
}

.error-page .btn {
  margin-top: 14px;
}

.copy-helper {
  position: fixed;
  top: 0;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* ---------- focus ---------- */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- responsive ---------- */

@media (max-width: 1180px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .info-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topnav {
    width: 100%;
    justify-content: space-between;
  }

  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .key-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .key-card {
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
  }

  .key-card:last-child {
    border-bottom: 0;
  }

  .info-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .danger-panel {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .container {
    padding-top: 20px;
  }

  .brand-text small {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- scrollbars ---------- */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: #263250;
  border-radius: 999px;
  border: 2px solid var(--bg);
}

::-webkit-scrollbar-track {
  background: transparent;
}
