:root {
  --bg: #eef1f5;
  --surface: #fff;
  --ink: #1a1f2b;
  --muted: #667085;
  --line: #e4e7ec;
  --brand: #005a6e;
  --brand-2: #0a6f86;
  --gold: #c5a059;
  --chrome: #ffffff;
  --chrome-ink: #1a1f2b;
  --chrome-muted: #667085;
  --chrome-line: #e4e7ec;
  --nav-active: #e6f4f7;
  --accent: #2a8f6f;
  --ok: #0d7a4f;
  --ok-bg: #e8f7ef;
  --warn: #b54708;
  --warn-bg: #fef4e6;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --info: #175cd3;
  --info-bg: #e8f1fc;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --font: 13px/1.4 "Segoe UI", system-ui, sans-serif;
  --tap: 44px;
  --top: 52px;
  --bottom: 58px;
  --rail: 200px;
}
*, *::before, *::after { box-sizing: border-box; }
html {
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
}
html, body { margin: 0; min-height: 100%; }
body {
  font: var(--font);
  color: var(--ink);
  background: var(--bg);
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
}
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 16px; }
h2 { font-size: 14px; }
p { margin: 0 0 8px; }

.app {
  height: 100dvh;
  max-height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: var(--top) minmax(0, 1fr) auto;
  grid-template-areas:
    "top"
    "main"
    "bottom";
}
.rail { display: none; }
.topbar {
  grid-area: top;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--top);
  padding: 0 10px;
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  min-width: 0;
  overflow: hidden;
  background: var(--chrome);
  color: var(--chrome-ink);
  border-bottom: 1px solid var(--chrome-line);
}
.brand {
  display: flex;
  align-items: center;
  flex: 0 1 auto;
  min-width: 0;
  color: var(--chrome-ink);
}
.brand:hover { text-decoration: none; color: var(--chrome-ink); }
.brand img {
  display: block;
  height: 28px;
  width: auto;
  max-width: min(148px, 46vw);
  object-fit: contain;
  object-position: left center;
}
.page-title {
  display: none;
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 650;
  color: var(--chrome-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-end {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex: 0 1 auto;
  min-width: 0;
}
.topbar .who {
  font-size: 12px;
  color: var(--chrome-muted);
  white-space: nowrap;
  max-width: 110px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.05); text-decoration: none; color: #fff; }
.icon-btn {
  width: 36px;
  min-width: 36px;
  padding: 0;
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}
.icon-btn:hover { filter: none; background: #f4f6f8; color: var(--brand); text-decoration: none; }
.icon-btn svg { width: 18px; height: 18px; display: block; }
.btn-ghost { background: transparent; color: inherit; border-color: currentColor; }
.topbar .btn-ghost {
  color: var(--chrome-ink);
  border-color: var(--chrome-line);
  min-height: 32px;
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
  background: #fff;
  flex-shrink: 0;
}
.topbar .btn-ghost:hover { background: #f4f6f8; color: var(--chrome-ink); }
.btn-sm { min-height: 32px; padding: 0 8px; font-size: 12px; }
.btn-ok { background: var(--ok); }
.btn-warn { background: var(--warn); }
.btn-danger { background: var(--danger); }
.btn-line { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-line:hover { color: var(--ink); background: #f8fafc; }
.main {
  grid-area: main;
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  overflow-x: clip;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
  padding-bottom: 12px;
}
.bottom-nav {
  grid-area: bottom;
  z-index: 30;
  display: flex;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  scrollbar-width: none;
  background: #fff;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottom-nav::-webkit-scrollbar { display: none; width: 0; height: 0; }
.bottom-nav a, .rail a:not(.brand) {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--bottom);
  min-width: 0;
  max-width: 100%;
  padding: 0 1px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  overflow: hidden;
}
.bottom-nav a {
  flex: 1 1 0;
}
.bottom-nav a span, .rail a:not(.brand) span {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}
.bottom-nav a:hover, .rail a:hover { text-decoration: none; color: var(--brand); }
.bottom-nav a.active, .rail a.active { color: var(--brand); }
.bottom-nav svg, .rail svg { width: 18px; height: 18px; flex-shrink: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px;
  margin-bottom: 8px;
  max-width: 100%;
  min-width: 0;
  overflow-wrap: break-word;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  min-width: 0;
}
.card-head h1, .card-head h2 { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.card-head:last-child { margin-bottom: 0; }
.card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}
.filter-btn { position: relative; }
.filter-btn.on {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--nav-active);
}
.filter-count {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 99px;
  background: var(--brand);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
}

.modal {
  width: min(400px, calc(100% - 24px));
  max-width: 100%;
  max-height: min(86dvh, 640px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 16px 40px rgba(16, 24, 40, .18);
  overflow: auto;
}
.modal::backdrop { background: rgba(16, 24, 40, .45); }
.modal-form { display: grid; gap: 12px; padding: 14px; min-width: 0; }
.modal-head { display: flex; align-items: center; gap: 8px; }
.modal-head h2 { flex: 1; font-size: 15px; min-width: 0; }
.modal-head .icon-btn { width: 32px; min-width: 32px; min-height: 32px; font-size: 18px; line-height: 1; }
.modal .filters { margin: 0; grid-template-columns: minmax(0, 1fr); }
.modal-actions { display: flex; gap: 8px; }
.modal-actions .btn { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.tiny { font-size: 11px; }
.row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: stretch;
  max-width: 100%;
  min-width: 0;
}
.stack { display: grid; gap: 8px; min-width: 0; }
.grid-2 { display: grid; gap: 8px; min-width: 0; grid-template-columns: minmax(0, 1fr); }
.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 64px;
  color: inherit;
  text-decoration: none;
}
.stat:hover { text-decoration: none; border-color: var(--brand-2); }
.stat b { display: block; font-size: 20px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }

.filters {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  margin-bottom: 8px;
  min-width: 0;
}
.filters .grow { grid-column: 1 / -1; }
label.field { display: grid; gap: 3px; font-size: 11px; font-weight: 600; color: var(--muted); min-width: 0; max-width: 100%; }
.field input, .field select, .field textarea, input[type="text"], input[type="password"], input[type="email"], input[type="number"], input[type="datetime-local"], input[type="date"], select, textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
textarea { min-height: 72px; resize: vertical; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

.list { display: grid; gap: 6px; }
.item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 8px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  align-items: start;
  max-width: 100%;
  min-width: 0;
}
.item > div { min-width: 0; }
.item h3 { font-size: 13px; overflow-wrap: anywhere; }
.item .meta { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: #eef2f6;
  color: var(--muted);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }

.table-wrap { display: none; overflow-x: auto; max-width: 100%; }
table.data {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
}
table.data th, table.data td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
table.data th {
  position: sticky;
  top: 0;
  background: #f7f8fa;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
table.data tr:hover td { background: #fafbfc; }
table.data .col-actions {
  width: 220px;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}
.row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin: 0;
}
.row-actions form { margin: 0; }
.row-actions .btn {
  min-height: 28px;
  height: 28px;
  padding: 0 8px;
  font-size: 11px;
}
.item .row-actions { margin-top: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
}
.chip input { accent-color: var(--brand); }
.errors { background: var(--danger-bg); color: var(--danger); padding: 8px; border-radius: 8px; font-size: 12px; margin-bottom: 8px; }
.errors ul { margin: 0; padding-left: 16px; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; font-size: 13px; }
.toast {
  position: fixed;
  top: calc(var(--top) + 8px);
  left: 8px;
  right: 8px;
  z-index: 50;
  padding: 10px 12px;
  border-radius: 8px;
  background: #123;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.toast.ok { background: var(--ok); }
.toast.error, .toast.danger { background: var(--danger); }

.pager { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; margin-top: 8px; padding: 0; list-style: none; }
.pager a, .pager span {
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
}
.pager .active a, .pager li.active a { background: var(--brand); color: #fff; border-color: var(--brand); }

.login-body { display: grid; place-items: center; min-height: 100dvh; padding: 16px; background: var(--bg); width: 100%; max-width: 100%; overflow-x: hidden; }
.login-card { width: min(380px, 100%); padding: 0; overflow: hidden; }
.login-card h1 { margin-bottom: 4px; }
.login-brand { padding: 16px 16px 4px; display: flex; justify-content: center; background: transparent; }
.login-brand img { display: block; width: min(260px, 100%); height: auto; }
.login-form { padding: 14px 14px 16px; }

.exam-shell {
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}
.exam-bar {
  z-index: 10;
  flex-shrink: 0;
  display: flex; align-items: center; gap: 8px;
  min-height: 48px; padding: 6px 10px;
  background: var(--chrome);
  color: var(--chrome-ink);
  border-bottom: 1px solid var(--chrome-line);
  min-width: 0;
  overflow: hidden;
}
.exam-bar > div { min-width: 0; overflow: hidden; }
.exam-logo {
  display: block;
  height: 28px;
  width: auto;
  max-width: min(140px, 40vw);
  object-fit: contain;
  flex-shrink: 0;
}
.exam-logo-sm {
  height: 28px;
  width: 28px;
  max-width: 28px;
  object-fit: cover;
  object-position: left center;
  border-radius: 50%;
}
.exam-bar .timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  margin-left: auto;
  background: var(--nav-active);
  color: var(--brand);
  padding: 4px 8px;
  border-radius: 6px;
}
.exam-body {
  flex: 1;
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px;
}
.exam-qno {
  color: var(--brand);
  font-weight: 700;
  margin-right: 2px;
}
.option {
  display: flex; gap: 8px; align-items: flex-start;
  width: 100%; max-width: 100%; text-align: left;
  min-height: 44px; padding: 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fff; cursor: pointer;
}
.option span { min-width: 0; overflow-wrap: anywhere; }
.option.selected { border-color: var(--brand-2); background: #eef6fb; }
.option b { width: 22px; height: 22px; border-radius: 50%; background: #eef2f6; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; flex-shrink: 0; }
.option.selected b { background: var(--brand); color: #fff; }
.exam-foot {
  flex-shrink: 0;
  display: flex; gap: 6px; padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid var(--line);
  min-width: 0;
  max-width: 100%;
}
.exam-foot .btn, .exam-foot form { flex: 1 1 0; min-width: 0; }
.exam-foot .btn { min-height: var(--tap); }
.exam-progress {
  flex-shrink: 0;
  padding: 8px 10px 10px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.exam-progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.exam-progress-track {
  height: 8px;
  border-radius: 99px;
  background: #e8edf2;
  overflow: hidden;
}
.exam-progress-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--brand);
  transition: width .2s ease;
}

.exam-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.exam-status .timer { margin-left: 0; }
.exam-who { min-width: 0; }
.proc-dot { color: #3dd68c; font-size: 10px; }
.check-list { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.check-list li {
  padding: 8px 10px 8px 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  position: relative;
}
.check-list li::before { content: "…"; position: absolute; left: 10px; }
.check-list li.ok::before { content: "✓"; color: var(--ok); }
.check-list li.fail::before { content: "!"; color: var(--danger); }
.check-list li.wait::before { content: "…"; color: var(--muted); }
.cam-preview-wrap {
  width: min(280px, 100%);
  margin: 12px 0;
}
.cam-preview-wrap video,
.cam-pip video {
  display: block;
  width: 100%;
  border-radius: 8px;
  background: #111;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}
.cam-pip {
  flex: 0 0 88px !important;
  width: 88px;
  max-width: 88px;
}
.cam-pip video { aspect-ratio: 1; height: 66px; }
.fs-gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 32, .72);
  color: #fff;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
}
.fs-gate[hidden] { display: none; }
.exam-locked { pointer-events: none; opacity: .7; }
.check-actions { flex-wrap: wrap; }
.check-actions .btn { flex: 1 1 140px; }

.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.admin-tile {
  display: flex; flex-direction: column; gap: 4px;
  padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px; min-height: 72px;
  color: inherit;
}
.admin-tile:hover { text-decoration: none; border-color: var(--brand-2); }
.admin-tile b { font-size: 13px; }
.dl { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 4px 8px; font-size: 13px; min-width: 0; }
.dl dt { color: var(--muted); font-size: 11px; }
.dl dd { margin: 0; overflow-wrap: anywhere; word-break: break-word; }

@media (min-width: 768px) {
  .app {
    grid-template-columns: var(--rail) minmax(0, 1fr);
    grid-template-rows: var(--top) minmax(0, 1fr);
    grid-template-areas:
      "rail top"
      "rail main";
  }
  .row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
  }
  .row > .field { flex: 1 1 140px; min-width: 0; }
  .row > .btn, .row > button { flex: 0 0 auto; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modal .filters { grid-template-columns: minmax(0, 1fr); }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .rail {
    display: flex;
    flex-direction: column;
    grid-area: rail;
    background: var(--chrome);
    color: var(--chrome-ink);
    padding: 12px 8px;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    border-right: 1px solid var(--chrome-line);
  }
  .rail .brand {
    padding: 6px 8px;
    margin: 0 0 12px;
    min-height: 0;
    flex: 0 0 auto;
    text-transform: none;
    letter-spacing: 0;
    font-size: inherit;
    justify-content: center;
  }
  .rail .brand img {
    height: 36px;
    max-width: 176px;
    width: auto;
  }
  .rail a:not(.brand) {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    min-height: 40px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: 12px;
    text-transform: none;
    letter-spacing: 0;
    color: var(--chrome-muted);
  }
  .rail a.active { background: var(--nav-active); color: var(--brand); }
  .bottom-nav { display: none; }
  .topbar .brand { display: none; }
  .page-title { display: block; }
  .topbar .who { max-width: 180px; }
  .main { padding: 12px 16px; }
  .filters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .modal .filters { grid-template-columns: minmax(0, 1fr); }
  .cards-only { display: none; }
  .table-wrap { display: block; }
  .admin-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .toast { left: auto; right: 16px; width: min(360px, calc(100% - 32px)); }
}
@media (min-width: 1100px) {
  .main { max-width: 1100px; }
}
@media (max-width: 360px) {
  .topbar .who { display: none; }
  .brand img { max-width: min(132px, 52vw); }
}

#debug-icon,
#debug-bar {
  max-width: 100% !important;
  box-sizing: border-box;
}
#debug-bar {
  overflow: hidden !important;
  width: auto !important;
  left: 0 !important;
  right: 0 !important;
}
@media (max-width: 767px) {
  #debug-bar,
  #debug-icon {
    display: none !important;
  }
}
