:root {
  --sidebar: #111827;
  --sidebar-2: #1f2937;
  --text-on-dark: #e5e7eb;
  --muted-on-dark: #9ca3af;
  --bg: #f3f4f6;
  --card: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --danger: #b91c1c;
  --ok: #047857;
  --shadow: 0 8px 24px rgba(17, 24, 39, 0.06);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: ui-sans-serif, -apple-system, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: var(--sidebar);
  color: var(--text-on-dark);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 28px;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}
.brand strong, .brand small { display: block; }
.brand small { color: var(--muted-on-dark); font-size: 12px; margin-top: 2px; }
.sidebar nav { display: grid; gap: 6px; }
.nav-item {
  color: var(--text-on-dark);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 10px;
}
.nav-item:hover { background: var(--sidebar-2); }
.nav-item.active { background: var(--accent); color: #fff; }
.sidebar-foot { margin-top: auto; }

.main { flex: 1; min-width: 0; }
.topbar {
  padding: 22px 28px 8px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.topbar h1 { margin: 0; font-size: 26px; letter-spacing: -0.03em; }
.content { padding: 12px 28px 40px; display: grid; gap: 16px; }
.muted { color: var(--muted); margin: 6px 0 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: grid;
  gap: 14px;
}
.card-head, .row-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
h2 { margin: 0; font-size: 16px; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 28px; letter-spacing: -0.04em; }
.stat span { color: var(--muted); font-size: 13px; }

.split {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 16px;
}

label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
select,
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}
textarea { resize: vertical; }
.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.ghost { background: transparent; color: var(--text-on-dark); border-color: #374151; }
.btn.block { width: 100%; }
.btn.icon { display: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { color: var(--muted); font-weight: 600; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #f3f4f6;
}
.status.on { background: var(--accent-soft); color: var(--ok); }
.empty, .result-list { font-size: 14px; }
.result-list .ok { color: var(--ok); }
.result-list .bad { color: var(--danger); }

.field-label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.uploader {
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  min-height: 160px;
  padding: 16px;
  cursor: pointer;
  background: #f8fafc;
}
.uploader.drag { border-color: var(--accent); background: var(--accent-soft); }
.upload-empty {
  min-height: 128px;
  display: grid;
  place-items: center;
  color: var(--muted);
}
#imageReady { display: grid; gap: 12px; }
#imageReady[hidden] { display: none; }
.preview-img, #imageThumb {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
}
.preview-card {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  white-space: pre-wrap;
  line-height: 1.6;
  display: grid;
  gap: 12px;
}
.tg-buttons { display: grid; gap: 8px; }
.tg-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tg-row.one { grid-template-columns: 1fr; }
.tg-btn {
  border: 1px solid #cbd5e1;
  background: #f1f5f9;
  color: #334155;
  border-radius: 8px;
  padding: 8px;
  text-align: center;
  font-size: 13px;
}
.tg-btn.primary { border-color: #60a5fa; background: #2563eb; color: #fff; }
.tg-btn.success { border-color: #34d399; background: #059669; color: #fff; }
.tg-btn.danger { border-color: #f87171; background: #dc2626; color: #fff; }
.button-editor { display: grid; gap: 8px; }
.btn-row { display: grid; grid-template-columns: 1fr 1.4fr 88px auto auto auto; gap: 8px; }
.btn-style { width: 88px; padding: 8px; }

.kv-card { gap: 0; }
.kv {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #0f172a;
}
.login-card {
  width: min(400px, calc(100% - 32px));
  background: #fff;
  border-radius: 18px;
  padding: 28px;
  display: grid;
  gap: 14px;
}
.login-card h1 { margin: 0; }
.login-card .brand { margin-bottom: 4px; color: var(--ink); }
.login-card .brand small { color: var(--muted); }
.alert {
  margin: 0;
  padding: 10px 12px;
  background: #fef2f2;
  color: var(--danger);
  border-radius: 10px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.46);
}
.modal-panel {
  position: relative;
  width: min(680px, 100%);
  max-height: min(92vh, 900px);
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  padding: 22px;
  display: grid;
  gap: 14px;
  box-shadow: 0 24px 64px rgba(17, 24, 39, 0.22);
}
body.modal-open { overflow: hidden; }
.card-head.tight { margin-top: 4px; }
#tokenField[hidden] { display: none; }

#toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  max-width: min(360px, calc(100% - 32px));
  z-index: 20;
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .sidebar.open { transform: none; }
  .btn.icon { display: inline-block; }
  .stats, .split { grid-template-columns: 1fr; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
  .btn-row { grid-template-columns: 1fr; }
}
