:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --blue: #0068ff;
  --blue-dark: #004ecc;
  --green: #0b875b;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1380px;
  margin: 0 auto;
  padding: 12px 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-badge {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0068ff, #00c853);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.brand h1 { margin: 0; font-size: 17px; letter-spacing: 0.3px; }
.subtitle { font-size: 12.5px; color: var(--muted); }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.container { max-width: 1380px; margin: 18px auto 40px; padding: 0 18px; display: flex; flex-direction: column; gap: 18px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
@media (max-width: 960px) { .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .stats-grid { grid-template-columns: 1fr; } }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-label { font-size: 12.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.stat-value { font-size: 24px; font-weight: 800; margin: 6px 0 4px; }
.stat-value-sm { font-size: 16px; }
.stat-meta { font-size: 12.5px; color: var(--muted); }
.text-blue { color: var(--blue); }
.text-green { color: var(--green); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}
.card-title-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card-header h2 { margin: 0; font-size: 16px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.table-wrap { overflow-x: auto; }
.tx-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tx-table th, .tx-table td { padding: 10px 12px; border-bottom: 1px solid #f1f5f9; text-align: left; white-space: nowrap; }
.tx-table th { background: #f8fafc; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.tx-table tbody tr:hover { background: #f8fbff; }
.tx-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.tx-table .empty { text-align: center; padding: 36px 16px; color: var(--muted); white-space: normal; }
.tx-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; color: var(--blue-dark); cursor: pointer; }
.tx-id:hover { text-decoration: underline; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-fail { background: #fee2e2; color: #991b1b; }
.ctv-input { width: 110px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 12.5px; }

.pill { padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.pill-live { background: #dcfce7; color: #15803d; }
.pill-warn { background: #fef3c7; color: #b45309; }
.pill-muted { background: #e2e8f0; color: #475569; }
.chip { background: #f1f5f9; color: #475569; padding: 3px 10px; border-radius: 999px; font-size: 12px; }

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: opacity 0.15s, background 0.15s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { opacity: 0.92; }
.btn-danger { background: var(--red); color: #fff; }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: #f8fafc; }
.btn-ghost { background: transparent; color: var(--blue); }
.btn-ghost:hover { background: #eff6ff; }

.input {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
}
.input-sm { width: auto; min-width: 165px; padding: 6px 10px; font-size: 13px; }
.textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; resize: vertical; }

.zalo-guide { padding: 16px 18px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; font-size: 13.5px; }
@media (max-width: 820px) { .zalo-guide { grid-template-columns: 1fr; } }
.zalo-guide p { margin: 0 0 8px; }
.copy-box { display: flex; align-items: center; gap: 8px; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.copy-box code { flex: 1; font-size: 12px; overflow-x: auto; word-break: break-all; }
.copy-box-sm { margin-top: 6px; padding: 6px 8px; }
.linked-groups { margin-top: 8px; font-size: 13px; color: var(--muted); }

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.52);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.hidden { display: none !important; }
.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%; max-width: 540px;
  max-height: 90vh; overflow-y: auto;
  padding: 18px 20px 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-header h3 { margin: 0; font-size: 16.5px; }
.modal-close { border: none; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab {
  border: none; background: none; padding: 8px 14px; font-weight: 600; font-size: 13.5px;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent;
}
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 12px; }
.steps-list { margin: 0 0 12px; padding-left: 18px; font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.field-label { display: block; font-size: 12.5px; font-weight: 600; margin: 10px 0 4px; color: var(--muted); }
.modal-actions { margin-top: 14px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.row-inline { display: flex; gap: 8px; align-items: center; }
.unit-label { font-weight: 700; color: var(--muted); }
.date-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.qr-stage { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 14px; background: #f8fafc; border-radius: 10px; border: 1px dashed var(--border); }
.qr-box { min-height: 220px; min-width: 220px; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); font-size: 13px; padding: 10px; background: #fff; border-radius: 8px; }
.qr-status { font-size: 13px; font-weight: 600; color: var(--blue); text-align: center; }

.form-msg { margin-top: 10px; font-size: 13px; min-height: 18px; }
.form-msg.ok { color: var(--green); }
.form-msg.err { color: var(--red); }

.lookup-result { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.lookup-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: #f8fafc; font-size: 13px; }
.history-box { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.history-box h4 { margin: 0 0 8px; font-size: 13.5px; color: var(--muted); }
.history-box ul { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }

.toast {
  position: fixed; right: 18px; bottom: 18px;
  background: #0f172a; color: #fff; padding: 10px 16px;
  border-radius: 10px; font-size: 13.5px; z-index: 90;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
