:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --primary: #1f2328;
  --primary-text: #ffffff;
  --green: #15803d;
  --green-bg: #f0fdf4;
  --red: #b91c1c;
  --red-bg: #fef2f2;
  --amber: #b45309;
  --amber-bg: #fffbeb;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

.app { max-width: 1200px; margin: 0 auto; padding: 24px 20px; }

/* Header */
.hero {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
  margin-bottom: 20px; padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.hero h1 { margin: 0; font-size: 20px; font-weight: 600; }
.hero p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.hero p strong { color: var(--text); font-weight: 600; }

.brand { display: flex; gap: 12px; align-items: flex-start; }
.logo {
  flex: none; width: 40px; height: 40px; border-radius: 10px;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 20px;
}
.logo-img { flex: none; width: 40px; height: 40px; border-radius: 10px; object-fit: cover; display: block; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chip {
  font-size: 12px; color: var(--muted);
  background: #f3f4f6; border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 10px;
}
.chip::before { content: "✓"; color: var(--green); margin-right: 5px; font-weight: 700; }

.nav { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.nav a {
  font-weight: 500; font-size: 13px; color: var(--text);
  padding: 7px 12px; border-radius: var(--radius);
}
.nav a:hover { background: #eceef1; text-decoration: none; }
.btn-donate {
  border: 1px solid #fecaca; color: var(--red) !important; background: var(--red-bg);
}
.btn-donate:hover { background: #fee2e2 !important; }

.footer-note {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  margin-top: 20px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--muted); font-size: 13px;
}

.layout { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 20px; }

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.panel-content { padding: 20px; }
.panel h2 { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.panel p { margin: 0 0 16px; color: var(--muted); font-size: 13px; }

/* Form */
.field + .field { margin-top: 16px; }
.field label {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  margin-bottom: 6px; font-size: 13px; font-weight: 500; color: var(--text);
}
.hint { color: var(--muted); font-weight: 400; font-size: 12px; }

textarea, input[type="number"], input[type="text"], input[type="password"], select {
  width: 100%; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea:focus, input:focus, select:focus {
  border-color: #9ca3af; box-shadow: 0 0 0 3px rgba(31, 35, 40, 0.06);
}
textarea { min-height: 320px; resize: vertical; padding: 10px 12px; font-size: 13px; line-height: 1.6; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
input[type="number"], input[type="text"], input[type="password"] { height: 38px; padding: 0 12px; }
select { height: 38px; padding: 0 10px; }

.actions, .export-actions { display: flex; flex-wrap: wrap; gap: 8px; }

button {
  appearance: none; cursor: pointer; min-height: 38px; padding: 0 14px;
  border-radius: var(--radius); font: inherit; font-weight: 500; font-size: 13px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  transition: background .15s, border-color .15s, opacity .15s;
}
button:hover { background: #f3f4f6; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.primary:hover { background: #000; }
.secondary { background: var(--surface); }
.ghost { color: var(--red); border-color: var(--line-strong); }
.ghost:hover { background: var(--red-bg); }

/* Stats */
.status-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin: 0 0 16px; }
.stat { padding: 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.stat .label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.stat .value { display: block; font-size: 20px; font-weight: 600; }
.stat.live-stat .value { color: var(--green); }
.stat.die-stat .value { color: var(--red); }
.stat.unknown-stat .value { color: var(--amber); }

.progress-wrap { margin-bottom: 14px; }
.progress-track { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress-bar { width: 0%; height: 100%; background: var(--primary); transition: width .2s; }

.log {
  min-height: 20px; padding: 10px 12px; border-radius: var(--radius);
  background: #f3f4f6; border: 1px solid var(--line);
  color: var(--muted); font-size: 13px;
}

/* Table */
.table-wrap { max-height: 520px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
thead th {
  position: sticky; top: 0; z-index: 1; padding: 10px 12px; background: #f3f4f6;
  color: var(--muted); font-size: 12px; font-weight: 600; text-align: left;
  border-bottom: 1px solid var(--line);
}
tbody td { padding: 10px 12px; font-size: 13px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafafa; }

.badge {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 4px;
  font-size: 12px; font-weight: 600; border: 1px solid transparent;
}
.badge.waiting, .badge.running { color: var(--muted); background: #f3f4f6; }
.badge.live { color: var(--green); background: var(--green-bg); border-color: #bbf7d0; }
.badge.die, .badge.error { color: var(--red); background: var(--red-bg); border-color: #fecaca; }
.badge.lock, .badge.unknown { color: var(--amber); background: var(--amber-bg); border-color: #fde68a; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-word; font-size: 12px; }
.empty-state { padding: 20px; text-align: center; color: var(--muted); }
.row-refresh { min-height: 0; padding: 2px 8px; font-size: 12px; border-radius: 4px; }

/* Quảng cáo */
.ad-slot { display: none; margin: 14px 0; text-align: center; }
.ad-slot.filled { display: block; }
.ad-slot img { max-width: 100%; border-radius: var(--radius); }
.ad-top { margin: 0 0 16px; }

/* Trang nội dung */
.content { max-width: 800px; }
.content .panel-content h2 { margin-top: 22px; }
.content .panel-content h2:first-child { margin-top: 0; }
.content ul { line-height: 1.8; padding-left: 20px; }
.donate-btn { width: 100%; }

/* Logo Facebook nổi góc dưới phải */
.fb-float {
  position: fixed; right: 18px; bottom: 18px; z-index: 40;
  width: 52px; height: 52px; border-radius: 50%;
  background: #1877f2; color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  transition: transform .15s, background .15s, box-shadow .15s;
}
.fb-float:hover { background: #0f66da; transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3); text-decoration: none; }
.fb-float svg { width: 26px; height: 26px; fill: currentColor; }

@media (max-width: 560px) {
  .fb-float { right: 14px; bottom: 14px; width: 48px; height: 48px; }
  .fb-float svg { width: 24px; height: 24px; }
}

/* Popup ủng hộ */
.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); }
.modal-card {
  position: relative; z-index: 1; width: 100%; max-width: 340px; max-height: 90vh; overflow: auto;
  background: #fff; border-radius: var(--radius); padding: 22px; text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}
.modal-card h3 { margin: 0 0 12px; font-size: 16px; font-weight: 600; }
.modal-close {
  position: absolute; top: 8px; right: 8px; min-height: 0; width: 30px; height: 30px;
  padding: 0; border: 0; background: transparent; font-size: 22px; line-height: 1; color: var(--muted);
}
.modal-close:hover { background: #f3f4f6; }

/* Cổng điều khoản */
.gate .modal-backdrop { background: rgba(0, 0, 0, 0.6); }
.gate-card { max-width: 600px; text-align: left; }
.gate-card h3 { text-align: left; }
.terms-box {
  max-height: 44vh; overflow: auto; text-align: left;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin: 4px 0 8px; background: #fafafa;
  font-size: 13px; line-height: 1.65;
}
.terms-box h4 { margin: 14px 0 4px; font-size: 13px; font-weight: 600; }
.terms-box h4:first-child { margin-top: 0; }
.terms-box p { margin: 0; color: var(--text); }
.agree-row { display: flex; gap: 8px; align-items: flex-start; margin: 14px 0 12px; font-size: 13px; cursor: pointer; }
.agree-row input { margin-top: 3px; flex: none; }
#agreeBtn { width: 100%; }

.site-footer {
  margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px; text-align: center;
}
.site-footer a { color: var(--muted); }

.donate-qr { text-align: center; padding: 8px 0; }
.donate-qr img { width: 240px; max-width: 80%; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; background: #fff; }
.donate-qr p { margin: 10px 0 0; }
.donate-qr code { background: #f3f4f6; padding: 1px 5px; border-radius: 4px; }
.disclaimer { font-size: 13px; color: var(--muted); line-height: 1.7; }

/* ===== Tablet ===== */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

/* ===== Điện thoại ===== */
@media (max-width: 600px) {
  .app { padding: 14px 12px; }

  .hero { gap: 10px; }
  .hero h1 { font-size: 18px; }
  .hero p { font-size: 12.5px; }
  .brand { gap: 10px; }
  .logo, .logo-img { width: 36px; height: 36px; }

  .panel-content { padding: 16px 14px; }
  textarea { min-height: 200px; }

  /* Thống kê: 3 cột cho gọn */
  .status-bar { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat { padding: 10px 8px; }
  .stat .label { font-size: 11px; }
  .stat .value { font-size: 17px; }

  /* Nút điều khiển dàn đều, dễ bấm */
  .actions button, .export-actions button { flex: 1 1 auto; }

  /* Bảng vừa màn hình + chữ nhỏ lại */
  table { min-width: 0; }
  thead th, tbody td { padding: 8px; font-size: 12px; }
  .mono { font-size: 11px; }

  /* Bảng kết quả của tool: ẩn cột "Thời gian" cho đỡ chật */
  .result-table { width: 100%; }
  .result-table thead th:nth-child(4),
  .result-table tbody td:nth-child(4) { display: none; }

  /* Modal & cổng điều khoản fit màn nhỏ */
  .modal { padding: 12px; }
  .modal-card { padding: 18px; }
  .gate-card { max-width: 100%; }
  .terms-box { max-height: 52vh; }
  .donate-qr img { width: 200px; }

  /* Footer xuống dòng gọn */
  .site-footer { line-height: 2; }
}
