:root {
  --bg: #0b0f14;
  --bg-2: #10161d;
  --card: #141b23;
  --card-2: #1a222c;
  --line: #243040;
  --text: #e6edf3;
  --muted: #8b98a8;
  --faint: #5d6b7c;
  --accent: #22c55e;
  --accent-ink: #052e16;
  --red: #f05252;
  --red-bg: rgba(240, 82, 82, .12);
  --amber: #f5b83d;
  --amber-bg: rgba(245, 184, 61, .12);
  --blue: #5aa9ff;
  --blue-bg: rgba(90, 169, 255, .12);
  --green-bg: rgba(34, 197, 94, .12);
  --radius: 12px;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.55 "IBM Plex Sans Thai", system-ui, sans-serif; min-height: 100vh; }
button, input { font: inherit; color: inherit; }
a { color: var(--blue); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.hidden { display: none !important; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- buttons, inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card-2); cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { border-color: #36475d; background: #202a36; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #2fd96a; }
.btn.danger { color: var(--red); }
.btn.danger:hover:not(:disabled) { border-color: var(--red); background: var(--red-bg); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { color: var(--text); background: var(--card-2); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--muted); }
.input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-2); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.input-prefix { display: flex; align-items: stretch; }
.input-prefix span {
  padding: 10px 10px 10px 12px; border: 1px solid var(--line); border-right: 0; border-radius: 10px 0 0 10px;
  background: var(--card-2); color: var(--muted); font-family: var(--mono); font-size: 14px; white-space: nowrap;
}
.input-prefix .input { border-radius: 0 10px 10px 0; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.error { color: var(--red); font-size: 14px; min-height: 20px; }

/* ---------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 32px 28px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center;
}
.brand-mark svg { width: 18px; height: 18px; }
.login h1 { font-size: 22px; margin: 22px 0 4px; }
.login p.lead { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.login .btn.primary { width: 100%; padding: 11px; margin-top: 6px; }

/* ---------- shell */
.top {
  position: sticky; top: 0; z-index: 10; background: rgba(11, 15, 20, .88); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.top-in { max-width: 1180px; margin: 0 auto; padding: 0 20px; height: 60px; display: flex; align-items: center; gap: 18px; }
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; font-size: 14px;
}
.nav a:hover { color: var(--text); background: var(--card-2); }
.nav a.active { color: var(--text); background: var(--card-2); }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 13px; }
.who .name { font-weight: 600; font-size: 14px; }
.who .meta { color: var(--muted); text-align: right; line-height: 1.3; }
.main { max-width: 1180px; margin: 0 auto; padding: 28px 20px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 22px; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.banner {
  padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; font-size: 14px;
  border: 1px solid; display: flex; gap: 10px; align-items: center;
}
.banner.red { background: var(--red-bg); border-color: rgba(240, 82, 82, .35); color: #ffb4b4; }
.banner.amber { background: var(--amber-bg); border-color: rgba(245, 184, 61, .35); color: #ffe1a3; }

/* ---------- cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.card-pad { padding: 20px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }

/* live session card */
.live { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 0; margin-bottom: 24px; }
.live > div { padding: 22px; }
.live > div + div { border-left: 1px solid var(--line); }
.pin-label { font-size: 12px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); }
.pin { font-family: var(--mono); font-size: 40px; font-weight: 700; letter-spacing: 6px; margin: 2px 0 14px; }
.link-row { display: flex; gap: 8px; }
.link-row .input { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.live .actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.countdown { margin-top: 16px; font-size: 14px; color: var(--muted); }
.countdown b { color: var(--text); font-family: var(--mono); font-weight: 700; }
.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.step { position: relative; padding-top: 14px; font-size: 13px; color: var(--faint); }
.step::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px; border-radius: 4px; background: var(--line); }
.step.done { color: var(--muted); }
.step.done::before { background: var(--accent); }
.step.now { color: var(--text); font-weight: 600; }
.step.now::before { background: linear-gradient(90deg, var(--accent), #86efac); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.status-big { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.progress { height: 8px; border-radius: 8px; background: var(--bg-2); overflow: hidden; margin: 12px 0 6px; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .4s; }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px; padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 16px; white-space: nowrap; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255, 255, 255, .015); }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 6px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap; border: 1px solid transparent;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.red { color: var(--red); background: var(--red-bg); }
.badge.amber { color: var(--amber); background: var(--amber-bg); }
.badge.green { color: var(--accent); background: var(--green-bg); }
.badge.blue { color: var(--blue); background: var(--blue-bg); }
.badge.gray { color: var(--muted); background: var(--card-2); }

/* ---------- report */
.report-head { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: center; margin-bottom: 20px; }
.verdict {
  width: 172px; padding: 20px 16px; border-radius: var(--radius); text-align: center; border: 1px solid;
}
.verdict .v-label { font-size: 12px; letter-spacing: 1px; text-transform: uppercase; opacity: .8; }
.verdict .v-text { font-size: 20px; font-weight: 700; margin-top: 4px; }
.verdict.red { color: var(--red); background: var(--red-bg); border-color: rgba(240, 82, 82, .4); }
.verdict.amber { color: var(--amber); background: var(--amber-bg); border-color: rgba(245, 184, 61, .4); }
.verdict.green { color: var(--accent); background: var(--green-bg); border-color: rgba(34, 197, 94, .4); }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px 24px; }
.facts div span { display: block; font-size: 12px; color: var(--muted); }
.facts div b { font-weight: 600; font-size: 14px; word-break: break-word; }
.tally { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 18px; }
.tally button {
  text-align: left; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  cursor: pointer;
}
.tally button.on { border-color: var(--text); }
.tally b { display: block; font-size: 22px; font-family: var(--mono); }
.tally span { font-size: 12.5px; color: var(--muted); }
.tally .red b { color: var(--red); } .tally .amber b { color: var(--amber); }
.tally .blue b { color: var(--blue); } .tally .gray b { color: var(--muted); }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; align-items: center; flex-wrap: wrap; }
.toolbar .input { max-width: 320px; }
.modules { display: grid; gap: 10px; }
.module { overflow: hidden; }
.module-head {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 14px 18px; background: none; border: 0;
  cursor: pointer; text-align: left;
}
.module-head .m-name { font-weight: 600; flex: 1; min-width: 0; }
.module-head .m-name small { display: block; font-weight: 400; color: var(--faint); font-family: var(--mono); font-size: 12px; }
.module-head .chev { color: var(--faint); transition: transform .15s; }
.module.open .chev { transform: rotate(90deg); }
.counts { display: flex; gap: 6px; }
.count { font-family: var(--mono); font-size: 12.5px; padding: 2px 8px; border-radius: 6px; }
.count.red { color: var(--red); background: var(--red-bg); }
.count.amber { color: var(--amber); background: var(--amber-bg); }
.count.blue { color: var(--blue); background: var(--blue-bg); }
.findings { border-top: 1px solid var(--line); }
.finding { display: grid; grid-template-columns: 86px 1fr auto; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--line); font-size: 14px; }
.finding:last-child { border-bottom: 0; }
.finding td, .finding { white-space: normal; }
.finding .f-title { font-weight: 500; word-break: break-word; }
.finding .f-detail { color: var(--muted); font-size: 13px; word-break: break-word; white-space: pre-wrap; margin-top: 2px; }
.finding .f-time { color: var(--faint); font-size: 12.5px; white-space: nowrap; font-family: var(--mono); }
.module-msg { padding: 10px 18px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }

/* ---------- grid for subusers / account */
.two { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.secret {
  margin-top: 14px; padding: 14px; border-radius: 10px; background: var(--green-bg); border: 1px solid rgba(34, 197, 94, .35);
  font-size: 14px;
}
.secret code { font-family: var(--mono); font-size: 15px; font-weight: 700; user-select: all; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 10px 16px; font-size: 14px; }
.kv span { color: var(--muted); }

/* ---------- modal, toast */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 22px; }
.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.modal .row { display: flex; justify-content: flex-end; gap: 8px; }
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #1f2937; border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  transition: all .2s; pointer-events: none; z-index: 60; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { border-color: rgba(240, 82, 82, .5); color: #ffb4b4; }

/* ---------- small screens */
@media (max-width: 860px) {
  .live, .two, .report-head { grid-template-columns: 1fr; }
  .live > div + div { border-left: 0; border-top: 1px solid var(--line); }
  .tally { grid-template-columns: repeat(3, 1fr); }
  .verdict { width: 100%; }
  .who .meta { display: none; }
}
@media (max-width: 640px) {
  .top-in { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .nav { order: 3; margin-left: 0; width: 100%; overflow-x: auto; }
  .main { padding: 20px 16px 48px; }
  .pin { font-size: 32px; letter-spacing: 4px; }
  .finding { grid-template-columns: 1fr; gap: 4px; }
  .hide-sm { display: none; }
  th, td { padding: 10px 12px; }
}
