:root {
  --ink:        #1b1f24;
  --ink-2:      #4a525c;
  --muted:      #6c757d;
  --line:       #dfe3e8;
  --surface:    #ffffff;
  --bg:         #f4f6f8;
  --accent:     #8d1b2d;
  --accent-ink: #ffffff;
  --ok-bg:      #e6f4ea;
  --ok-ink:     #17502b;
  --err-bg:     #fdeaec;
  --err-ink:    #8d1b2d;
  --radius:     10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Sarabun", "Noto Sans Thai", "Cordia New", "Leelawadee UI",
               system-ui, -apple-system, sans-serif;
  font-size: 17px;
  line-height: 1.65;
}

.wrap { max-width: 900px; margin: 0 auto; padding: 0 16px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding-top: 14px; padding-bottom: 14px; flex-wrap: wrap;
}
.brand strong { display: block; font-size: 1.05rem; }
.brand-sub { color: var(--muted); font-size: 0.85rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin: 20px 0;
}
.card-narrow { max-width: 460px; margin-left: auto; margin-right: auto; }

h1 { font-size: 1.4rem; margin: 0 0 6px; }
h2 { font-size: 1.15rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.fineprint { color: var(--muted); font-size: 0.85rem; }

label { display: block; margin: 14px 0 4px; font-weight: 500; }
input, textarea, select {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
textarea { resize: vertical; }

.btn {
  display: inline-block; padding: 10px 16px; margin-top: 14px; margin-right: 8px;
  font: inherit; font-weight: 500; border: 1px solid transparent; border-radius: 8px;
  cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg); }
.btn-small { padding: 5px 10px; font-size: 0.85rem; margin-top: 0; }

/* Standing guidance, distinct from a transient alert: the e-mail to use is the
   single commonest reason a student cannot log in. */
.notice {
  padding: 11px 13px; margin: 14px 0; border-radius: 8px;
  background: #fff8e6; border: 1px solid #f0d78c; color: #5c4408;
  font-size: 0.92rem; line-height: 1.55;
}
.nowrap { white-space: nowrap; }

.alert { padding: 12px 14px; border-radius: 8px; margin: 14px 0; }
.alert-error { background: var(--err-bg); color: var(--err-ink); }
.alert-ok { background: var(--ok-bg); color: var(--ok-ink); }

.who { display: grid; grid-template-columns: max-content 1fr; gap: 2px 16px; margin: 10px 0 0; }
.who dt { color: var(--muted); }
.who dd { margin: 0; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 700; color: var(--ink-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.scores .total td { font-weight: 700; border-top: 2px solid var(--ink); }

.pdf-frame { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--bg); }
.pdf-frame iframe { display: block; width: 100%; height: 78vh; border: 0; }

.stats { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; }
.stat {
  flex: 1 1 130px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px 14px;
}
.stat-n { display: block; font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-l { display: block; color: var(--muted); font-size: 0.85rem; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters label { margin: 0 0 2px; font-size: 0.85rem; }
.filters select, .filters input { width: auto; min-width: 190px; }

.log { font-size: 0.88rem; }
.log .ts, .log .ua { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.log .ua { white-space: normal; word-break: break-all; }
.log .body { white-space: pre-wrap; }
.log tr.handled { opacity: 0.5; }

/* Roster: the un-collected rows are the ones worth spotting, so they are the ones
   that carry colour. Every state also has a glyph, never colour alone. */
.roster tr.never { background: #fff8e6; }
.roster .tick  { color: #17502b; font-weight: 700; }
.roster .cross { color: #9aa1a9; }
.roster td, .roster th { padding: 6px 8px; }
.sorts { margin: 4px 0 12px; }
.sorts .btn { margin-top: 0; }

.badge {
  display: inline-block; margin-left: 8px; padding: 2px 9px; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 0.78rem; font-weight: 500;
  vertical-align: middle;
}
.msgs .body { min-width: 260px; font-size: 0.95rem; }

.kind { font-size: 0.8rem; padding: 2px 7px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.kind-login_fail, .kind-login_blocked, .kind-admin_login_fail { background: var(--err-bg); color: var(--err-ink); border-color: transparent; }
.kind-login_ok, .kind-admin_login_ok { background: var(--ok-bg); color: var(--ok-ink); border-color: transparent; }

.footer { color: var(--muted); font-size: 0.85rem; padding-top: 6px; padding-bottom: 30px; }

@media (max-width: 560px) {
  body { font-size: 16px; }
  .card { padding: 16px; }
  .pdf-frame iframe { height: 60vh; }
  table, thead, tbody, tr, th, td { display: block; }
  .log thead { display: none; }
  .log tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  .log td { border: 0; padding: 2px 0; }
  .scores { display: table; }
  .scores thead { display: table-header-group; }
  .scores tbody { display: table-row-group; }
  .scores tr { display: table-row; }
  .scores th, .scores td { display: table-cell; }
}
