:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --border: #e5e8f0;
  --text: #1a1f36;
  --muted: #6b7290;
  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --primary-soft: #eef0ff;
  --success: #10b981;
  --success-soft: #dcfce7;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --warning: #f59e0b;
  --gold: #f5b301;
  --silver: #a3acb9;
  --bronze: #d97a3a;
  --sidebar: #12122b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 20px 50px rgba(30, 27, 75, 0.18);
  --grad: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #db2777 100%);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
input, select, button, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- auth ---------- */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, #c7d2fe 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #fbcfe8 0%, transparent 55%), var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px 30px;
}
.brand-logo {
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--grad);
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 20px; letter-spacing: -0.5px;
  box-shadow: 0 10px 24px rgba(79, 70, 229, 0.35);
}
.auth-card .brand-logo { margin: 0 auto 16px; }
.auth-card h1 { text-align: center; font-size: 22px; }
.auth-card p.sub { text-align: center; color: var(--muted); margin: 6px 0 24px; }
.auth-foot { text-align: center; margin-top: 18px; font-size: 13px; }

/* ---------- form ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 13px; color: #3b4263; }
.input, select.input, textarea.input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12); }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; }
.hint { font-size: 12px; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1.5px solid transparent;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s, background 0.15s, box-shadow 0.15s, border-color 0.15s;
  white-space: nowrap;
  background: var(--surface);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(79, 70, 229, 0.25); }
.btn-primary:hover { background: #4338ca; }
.btn-grad { background: var(--grad); color: #fff; box-shadow: 0 8px 20px rgba(124, 58, 237, 0.3); }
.btn-grad:hover { filter: brightness(1.05); }
.btn-outline { border-color: var(--border); background: #fff; }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--primary-soft); color: var(--primary); }
.btn-danger { background: var(--danger-soft); color: #b91c1c; }
.btn-danger:hover { background: #fecaca; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-lg { padding: 13px 20px; font-size: 15.5px; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: #c9cbe6;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
  z-index: 40;
}
.sidebar .brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; }
.sidebar .brand-logo { width: 42px; height: 42px; font-size: 15px; border-radius: 12px; }
.sidebar .brand b { color: #fff; font-size: 16px; display: block; }
.sidebar .brand small { color: #8b8db3; font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: #6c6f99; padding: 14px 12px 6px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #c9cbe6;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav a .ico { width: 22px; text-align: center; font-size: 17px; }
.nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav a.active { background: var(--grad); color: #fff; box-shadow: 0 8px 20px rgba(124, 58, 237, 0.35); }
.side-user {
  margin-top: 12px;
  display: flex; align-items: center; gap: 10px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #818cf8, #c084fc);
  color: #fff; display: grid; place-items: center; font-weight: 700; flex-shrink: 0;
}
.side-user .meta { flex: 1; min-width: 0; }
.side-user b { color: #fff; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13.5px; }
.side-user small { color: #8b8db3; font-size: 12px; }
.side-user button { background: none; border: 0; color: #8b8db3; cursor: pointer; font-size: 18px; padding: 4px; }
.side-user button:hover { color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: none;
  align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.topbar .menu-btn { background: none; border: 0; font-size: 22px; cursor: pointer; padding: 4px 8px; }
.content { padding: 28px 32px 48px; max-width: 1400px; width: 100%; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.3px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- card ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h3 { font-size: 16px; font-weight: 700; }
.section { margin-bottom: 22px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat .value { font-size: 28px; font-weight: 800; margin-top: 6px; letter-spacing: -0.5px; }
.stat .emoji { position: absolute; right: 16px; top: 16px; font-size: 26px; opacity: 0.9; }
.stat.hero { background: var(--grad); color: #fff; border: 0; }
.stat.hero .label { color: rgba(255, 255, 255, 0.85); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbff; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .score { font-weight: 800; color: var(--primary); }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.empty .big { font-size: 36px; display: block; margin-bottom: 6px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-green { background: var(--success-soft); color: #047857; }
.badge-red { background: var(--danger-soft); color: #b91c1c; }
.badge-gray { background: #eef0f5; color: #555c7a; }
.badge-purple { background: var(--primary-soft); color: var(--primary); }
.badge-amber { background: #fef3c7; color: #b45309; }

.rank { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; font-weight: 800; font-size: 13px; background: #eef0f5; color: #555c7a; }
.rank.r1 { background: linear-gradient(135deg, #fde68a, #f59e0b); color: #78350f; }
.rank.r2 { background: linear-gradient(135deg, #e5e7eb, #9ca3af); color: #1f2937; }
.rank.r3 { background: linear-gradient(135deg, #fed7aa, #ea580c); color: #7c2d12; }

.who { display: flex; align-items: center; gap: 10px; }
.who .avatar { width: 32px; height: 32px; font-size: 13px; }
.who small { display: block; color: var(--muted); font-size: 12px; }

/* ---------- entry ---------- */
.date-nav { display: flex; align-items: center; gap: 8px; background: var(--surface); padding: 6px; border-radius: 12px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.date-nav .input { border: 0; padding: 6px 8px; width: auto; font-weight: 600; }
.date-nav .input:focus { box-shadow: none; }
.entry-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.entry-card { padding: 20px; display: flex; flex-direction: column; gap: 14px; transition: border-color 0.15s, box-shadow 0.15s; }
.entry-card.filled { border-color: #c7d2fe; box-shadow: 0 8px 24px rgba(79, 70, 229, 0.12); }
.entry-card .head { display: flex; align-items: center; gap: 12px; }
.entry-card .icon { width: 46px; height: 46px; border-radius: 12px; background: var(--primary-soft); display: grid; place-items: center; font-size: 24px; }
.entry-card .head b { font-size: 16px; display: block; }
.entry-card .head small { color: var(--muted); }
.stepper { display: flex; align-items: stretch; border: 1.5px solid var(--border); border-radius: 12px; overflow: hidden; }
.stepper button { width: 52px; border: 0; background: var(--surface-2); font-size: 22px; font-weight: 600; cursor: pointer; color: var(--primary); }
.stepper button:hover { background: var(--primary-soft); }
.stepper input { flex: 1; min-width: 0; border: 0; text-align: center; font-size: 26px; font-weight: 800; padding: 10px 0; outline: none; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.entry-card .sub-score { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.entry-card .sub-score b { color: var(--primary); }

.toggle { display: flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; padding: 14px; border-radius: 12px; border: 1.5px dashed var(--border); }
.toggle input { display: none; }
.toggle .sw { width: 52px; height: 30px; border-radius: 999px; background: #d4d8e4; position: relative; transition: background 0.2s; flex-shrink: 0; }
.toggle .sw::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); transition: transform 0.2s; }
.toggle input:checked + .sw { background: var(--success); }
.toggle input:checked + .sw::after { transform: translateX(22px); }
.toggle.on { border-color: var(--success); background: #f0fdf4; }

.save-bar {
  position: sticky; bottom: 16px; z-index: 10;
  margin-top: 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: #1e1b4b; color: #fff;
  padding: 14px 16px 14px 22px; border-radius: 16px;
  box-shadow: var(--shadow-lg);
}
.save-bar .total { font-size: 14px; color: #c7d2fe; }
.save-bar .total b { font-size: 26px; color: #fff; margin-left: 6px; }

/* ---------- config ---------- */
.config-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 18px; }
.cfg-card { padding: 0; }
.cfg-card .top { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.cfg-card .top .ico { font-size: 22px; }
.cfg-card .top b { flex: 1; font-size: 15px; }
.cfg-card .top .badge { cursor: pointer; }
.cfg-card .body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 12px; }
.cfg-value { background: linear-gradient(135deg, #eef2ff, #e0e7ff); border-radius: 12px; text-align: center; padding: 22px 10px; }
.cfg-value .v { font-size: 34px; font-weight: 800; color: #2547d0; letter-spacing: -0.5px; }
.cfg-value small { color: #4b5175; }
.cfg-card.off .cfg-value { background: #f1f2f6; }
.cfg-card.off .cfg-value .v { color: #9aa0b8; }
.cfg-scope { font-size: 12px; color: var(--muted); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- leaderboard (trong admin) ---------- */
.lb-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }
.lb-item { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.lb-item:last-child { border-bottom: 0; }
.lb-item .info { flex: 1; min-width: 0; }
.lb-item .info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-item .info small { color: var(--muted); font-size: 12px; }
.lb-item .pts { font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; }

.tabs { display: inline-flex; background: #e9ebf3; border-radius: 10px; padding: 4px; gap: 2px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; color: #555c7a; cursor: pointer; }
.tabs button.active { background: #fff; color: var(--primary); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08); }

.records { max-height: 360px; overflow-y: auto; }
.rec { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.rec:last-child { border-bottom: 0; }
.rec .qty { min-width: 46px; height: 32px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 800; }
.rec .info { flex: 1; min-width: 0; }
.rec .info small { display: block; color: var(--muted); font-size: 12px; }

.two-col { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }

/* ---------- modal & toast ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15, 16, 40, 0.5); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 16px; z-index: 100;
  animation: fade 0.15s ease;
}
.modal { width: 100%; max-width: 480px; background: #fff; border-radius: 18px; box-shadow: var(--shadow-lg); animation: pop 0.18s ease; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 17px; }
.modal-head button { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); }
.info-box { background: var(--primary-soft); border-radius: 12px; padding: 14px 16px; margin-bottom: 16px; display: flex; align-items: center; gap: 14px; }
.info-box .n { font-size: 30px; font-weight: 800; color: var(--primary); }
.cred { background: #0f172a; color: #e2e8f0; border-radius: 12px; padding: 14px 16px; font-family: ui-monospace, Consolas, monospace; font-size: 14px; line-height: 1.8; }
.cred b { color: #fbbf24; }

.toasts { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1e1b4b; color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow-lg); animation: slide 0.2s ease; max-width: 360px; font-weight: 500; }
.toast.error { background: #b91c1c; }
.toast.success { background: #047857; }

.loading { padding: 60px; text-align: center; color: var(--muted); }
.spinner { width: 32px; height: 32px; border: 3px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 12px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(0.96); opacity: 0; } }
@keyframes slide { from { transform: translateX(20px); opacity: 0; } }

/* ---------- responsive ---------- */
@media (max-width: 1200px) { .two-col { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); transition: transform 0.25s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .topbar { display: flex; }
  .content { padding: 20px 16px 40px; }
  .page-head h1 { font-size: 20px; }
  .grid-2 { grid-template-columns: 1fr; }
  .lb-grid { grid-template-columns: 1fr; }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 35; }
}
@media (max-width: 600px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 14px; }
  .stat .value { font-size: 22px; }
  .stat .emoji { font-size: 20px; right: 12px; top: 12px; }
  .stat.hero { grid-column: 1 / -1; }
  .save-bar { flex-wrap: nowrap; padding: 10px 10px 10px 16px; bottom: 10px; }
  .save-bar .total { font-size: 12.5px; }
  .save-bar .total b { display: block; font-size: 22px; margin-left: 0; }
  .save-bar .btn-lg { padding: 11px 14px; font-size: 14.5px; }
  .date-nav { width: 100%; justify-content: space-between; }
}

/* liên kết 1–3 */
.link-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); font-weight: 500; }
.seg { display: inline-flex; background: #eef0f6; border-radius: 10px; padding: 3px; gap: 2px; }
.seg input { display: none; }
.seg span { display: grid; place-items: center; width: 38px; height: 30px; border-radius: 8px; font-weight: 700; color: #555c7a; cursor: pointer; transition: background 0.15s, color 0.15s; }
.seg span:hover { color: var(--primary); }
.seg input:checked + span { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35); }
