:root {
  --bg: #0f1115;
  --bg-soft: #161a21;
  --card: #1b202a;
  --line: #262d3a;
  --text: #e6e9ef;
  --muted: #8b94a6;
  --accent: #3b82f6;
  --accent-soft: #1e3a8a33;

  /* Dải màu chuỗi dữ liệu — đã chạy qua validator cho nền tối #1b202a */
  --series-1: #3987e5;  /* người mới  */
  --series-2: #d95926;  /* đổi quà    */
  --series-3: #199e70;  /* điểm danh  */

  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;

  --grid: #2c2c2a;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; letter-spacing: .2px; }
small, .muted { color: var(--muted); }
.muted { font-size: 13px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ───────────── layout ───────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 236px; flex: 0 0 236px;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
}

.brand { display: flex; gap: 11px; align-items: center; padding: 0 6px 18px; }
.brand-logo { font-size: 26px; }
.brand strong { display: block; font-size: 15px; }
.brand small { display: block; font-size: 12px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0; color: var(--muted);
  font: inherit; text-align: left; cursor: pointer;
  padding: 10px 12px; border-radius: 9px;
}
.nav-item span { font-size: 16px; width: 20px; }
.nav-item:hover { background: #ffffff0a; color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: #fff; }

.sidebar-foot {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  border-top: 1px solid var(--line); padding-top: 14px; font-size: 12px; color: var(--muted);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: 0 0 8px; }
.dot.on { background: var(--good); box-shadow: 0 0 8px var(--good); }
.dot.off { background: var(--critical); }
.sidebar-foot .btn { margin-left: auto; }

.main { flex: 1; padding: 26px 30px 60px; max-width: 1180px; }

.tab { display: none; }
.tab.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 20px; flex-wrap: wrap;
}
.section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); margin: 22px 0 10px;
}
.section-title:first-of-type { margin-top: 0; }

/* ───────────── cards ───────────── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.card-head h2 { margin: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.grid-2 > .card { margin-bottom: 18px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px; margin-bottom: 18px;
}
.stat {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.stat.accent { border-color: #3b82f655; background: linear-gradient(180deg, #3b82f610, var(--card)); }
.stat small { display: block; font-size: 12px; margin-bottom: 6px; }
.stat strong { display: block; font-size: 27px; font-weight: 650; letter-spacing: -.5px; }
.trend { font-size: 12px; color: var(--muted); }

/* ───────────── form ───────────── */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label.check {
  display: flex; align-items: center; gap: 9px;
  color: var(--text); font-size: 14px; cursor: pointer;
}
label.check input { width: 16px; height: 16px; accent-color: var(--accent); }

input, select, textarea {
  width: 100%; margin-top: 6px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 11px; font: inherit;
  resize: vertical;
}
textarea { font-family: Consolas, Menlo, monospace; font-size: 13.5px; line-height: 1.6; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.field-grid label { margin-bottom: 0; }

.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-top: 4px; }
.grow { flex: 1; min-width: 140px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select { margin-top: 0; }
.toolbar select { width: auto; }

/* ───────────── buttons ───────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 15px; font: inherit; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #3a4454; background: #ffffff0a; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 550; }
.btn.primary:hover { background: #2f6fd8; }
.btn.danger { color: #f87171; }
.btn.danger:hover { background: #ef444418; border-color: var(--critical); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; margin-top: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.pill {
  background: var(--accent-soft); color: #93b8ff;
  border-radius: 999px; padding: 5px 13px; font-size: 13px; font-weight: 550;
}

/* ───────────── table ───────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 12px; font-weight: 550;
  color: var(--muted); text-transform: uppercase; letter-spacing: .4px;
  padding: 0 12px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
th.num { text-align: right; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #ffffff05; }

.tag { font-size: 12px; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.tag.ok { background: #0ca30c1f; color: #4ade80; }
.tag.no { background: #8b94a61f; color: var(--muted); }
.tag.warn { background: #fab2191f; color: #fbbf24; }
.tag.bad { background: #d03b3b1f; color: #f87171; }

.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding-top: 14px; }

/* ───────────── list ───────────── */
.list { display: flex; flex-direction: column; gap: 7px; }
.list.scroll { max-height: 330px; overflow-y: auto; padding-right: 4px; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 12px; font-size: 13.5px;
}
.list-item code { background: none; padding: 0; font-size: 13.5px; color: #93b8ff; }
.list-item .x {
  background: none; border: 0; color: var(--muted);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 4px;
}
.list-item .x:hover { color: #f87171; }
.rank { color: var(--muted); font-variant-numeric: tabular-nums; width: 20px; }

/* ───────────── chart ───────────── */
.chart {
  position: relative;
  display: flex; align-items: flex-end; gap: 8px;
  height: 190px; padding-top: 8px;
  background:
    repeating-linear-gradient(to top, transparent 0, transparent 24.9%, var(--grid) 24.9%, var(--grid) calc(24.9% + 1px));
}
.chart-group { flex: 1; display: flex; align-items: flex-end; gap: 2px; height: 100%; }
.chart-group .bar {
  flex: 1; min-height: 2px; display: block;
  border-radius: 4px 4px 2px 2px;
  transition: opacity .15s ease;
}
.chart-group:hover .bar { opacity: .55; }
.chart-group:hover .bar.hot { opacity: 1; }
.chart-axis {
  display: flex; gap: 8px; margin-top: 7px;
  border-top: 1px solid var(--line); padding-top: 7px;
}
.chart-axis span {
  flex: 1; text-align: center; font-size: 10px;
  color: var(--muted); font-variant-numeric: tabular-nums;
}

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

.tooltip {
  position: fixed; z-index: 60; pointer-events: none;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 12px; font-size: 12.5px;
  box-shadow: 0 8px 24px #0009; white-space: nowrap;
}
.tooltip b { display: block; margin-bottom: 5px; color: #fff; font-size: 12px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 7px; }
.tooltip .tt-row i { width: 8px; height: 8px; border-radius: 2px; }
.tooltip .tt-row span { margin-left: auto; font-variant-numeric: tabular-nums; }

/* ───────────── reward cards ───────────── */
.reward {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px;
}
.reward.off { opacity: .6; }
.reward-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.reward-head h3 { margin: 0; font-size: 16px; }
.reward-head .cost {
  background: var(--accent-soft); color: #93b8ff;
  border-radius: 999px; padding: 3px 11px; font-size: 12.5px; font-weight: 550;
}
.reward-head .spacer { flex: 1; }
.reward-meta { display: flex; gap: 18px; margin: 10px 0 0; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.reward-meta b { color: var(--text); }
.reward-body { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }

/* ───────────── hỗ trợ / chat ───────────── */
.badge {
  background: var(--critical); color: #fff;
  border-radius: 999px; padding: 1px 7px;
  font-size: 11px; font-weight: 650; margin-left: auto;
}

.chat-layout { display: grid; grid-template-columns: 290px 1fr; gap: 18px; align-items: start; }
.chat-threads { margin-bottom: 0; }
.chat-pane { margin-bottom: 0; display: flex; flex-direction: column; min-height: 600px; padding: 0; }

.chat-head {
  padding: 15px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.chat-head strong { font-size: 15px; }
.chat-head .meta { font-size: 12px; color: var(--muted); }

.chat-body {
  flex: 1; overflow-y: auto; padding: 18px;
  display: flex; flex-direction: column; gap: 10px;
  max-height: 460px;
}
.bubble {
  max-width: 72%; padding: 9px 13px; border-radius: 12px;
  font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
}
.bubble.in { align-self: flex-start; background: var(--bg-soft); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: #2b5278; border-bottom-right-radius: 4px; }
.bubble .time { display: block; margin-top: 5px; font-size: 10.5px; opacity: .65; }

.chat-input {
  border-top: 1px solid var(--line); padding: 13px 18px;
  display: flex; gap: 10px; align-items: flex-end;
}
.chat-input textarea { margin-top: 0; }
.chat-input .btn { flex: 0 0 auto; }

.thread {
  display: block; width: 100%; text-align: left;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; cursor: pointer;
  color: var(--text); font: inherit;
}
.thread:hover { border-color: #3a4454; }
.thread.active { border-color: var(--accent); background: var(--accent-soft); }
.thread .top { display: flex; align-items: center; gap: 7px; }
.thread .top strong { font-size: 13.5px; flex: 1; }
.thread .top .badge { margin-left: 0; }
.thread .snippet {
  display: block; margin-top: 4px; font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ───────────── telegram preview ───────────── */
.tg-preview { background: #17212b; border-radius: var(--radius); padding: 16px; }
.tg-bubble {
  background: #182533; border: 1px solid #22303d;
  border-radius: 12px 12px 12px 4px; padding: 10px 12px; max-width: 320px;
}
.tg-bubble img { width: 100%; border-radius: 8px; margin-bottom: 8px; display: block; }
.tg-text { white-space: pre-wrap; word-break: break-word; font-size: 14px; color: #e6e9ef; }
.tg-text b { color: #fff; }
.tg-btn {
  margin-top: 9px; text-align: center; padding: 8px;
  background: #2b5278; border-radius: 8px; font-size: 13.5px; color: #cfe3ff;
}

/* ───────────── tải ảnh lên ───────────── */
.upload-box {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 18px; text-align: center; margin-bottom: 12px;
  transition: border-color .15s ease, background .15s ease;
}
.upload-box.drag { border-color: var(--accent); background: var(--accent-soft); }
.upload-box img { max-width: 100%; max-height: 180px; border-radius: 9px; display: block; margin: 0 auto 10px; }
.upload-meta { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; font-size: 13px; }

/* ───────────── progress ───────────── */
.progress { background: var(--bg); border-radius: 999px; height: 8px; overflow: hidden; margin-bottom: 8px; }
.progress-bar { height: 100%; width: 0; background: var(--good); transition: width .3s ease; }

/* ───────────── setup ───────────── */
.status-box {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--bg); border: 1px solid var(--line);
  border-left: 3px solid var(--muted);
  border-radius: 9px; padding: 13px 15px; font-size: 14px;
}
.status-box.ok { border-left-color: var(--good); }
.status-box.warn { border-left-color: var(--warning); }
.status-box.bad { border-left-color: var(--critical); }
.status-box b { color: #fff; }

.steps { margin: 0 0 16px; padding-left: 20px; color: var(--muted); font-size: 13.5px; line-height: 1.9; }
.steps b { color: var(--text); }

.banner {
  background: #fab21914; border: 1px solid #fab21955;
  border-radius: var(--radius); padding: 14px 17px; margin-bottom: 18px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 14px;
}
.banner .btn { margin-left: auto; }

/* ───────────── toast ───────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 50;
  background: var(--card); border: 1px solid var(--line);
  border-left: 3px solid var(--good);
  border-radius: 9px; padding: 12px 17px; font-size: 14px;
  box-shadow: 0 10px 30px #0008;
  animation: slide .2s ease;
}
.toast.err { border-left-color: var(--critical); }
@keyframes slide { from { opacity: 0; transform: translateX(16px); } }

/* ───────────── login ───────────── */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 32px; width: 100%; max-width: 370px;
  text-align: center;
}
.login-logo { font-size: 42px; }
.login-card h1 { font-size: 20px; margin: 10px 0 4px; }
.login-card p { margin: 0 0 22px; }
.login-card label { text-align: left; }
.error {
  background: #d03b3b18; color: #f87171; border-radius: 8px;
  padding: 9px 12px; font-size: 13.5px; margin-bottom: 10px;
}

/* ───────────── responsive ───────────── */
@media (max-width: 1000px) {
  .field-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav-item span { display: none; }
  .main { padding: 20px 16px 50px; }
  .grid-2 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .field-grid { grid-template-columns: 1fr; }
}
