:root {
  --navy: #1a365d;
  --navy-2: #234e7a;
  --red: #b42318;
  --gold: #c9a227;
  --paper: #f4efe6;
  --card: #fffdf8;
  --ink: #1c1917;
  --muted: #57534e;
  --line: #d6cfc3;
  --ok: #166534;
  --shadow: 0 10px 30px rgba(26, 54, 93, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "Noto Sans", BeVietnamPro, sans-serif;
  background:
    radial-gradient(1200px 400px at 50% -120px, #2a5298 0%, transparent 70%),
    var(--paper);
  color: var(--ink);
  min-height: 100vh;
}

.topbar {
  background: linear-gradient(135deg, var(--navy), var(--navy-2));
  color: #fff;
  padding: 18px 16px 22px;
  box-shadow: 0 8px 24px rgba(26, 54, 93, 0.25);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  gap: 14px;
  align-items: center;
}
.crest {
  width: 52px; height: 52px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: radial-gradient(circle at 30% 30%, #f4e4a6, var(--gold) 45%, #8a6a12);
  color: var(--navy);
  border: 2px solid #fff3;
}
.kicker { margin: 0; font-size: 12px; opacity: 0.85; text-transform: uppercase; letter-spacing: 0.08em; }
.topbar h1 { margin: 0; font-size: 18px; line-height: 1.3; }
.sub { margin: 0; font-size: 13px; opacity: 0.85; }

.page { max-width: 720px; margin: 0 auto; padding: 18px 14px 40px; }
.page.wide { max-width: 1200px; }

.notice, .card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.notice { padding: 12px 14px; margin-bottom: 14px; font-size: 14px; line-height: 1.5; }
.form-card, .success-card, .login-card { padding: 18px; }
.form-card h2, .success-card h2, .login-card h1 { margin: 0 0 14px; color: var(--navy); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { font-weight: 650; font-size: 14px; }
.field em { color: var(--red); font-style: normal; }
.field small { color: var(--muted); font-size: 12px; }
input[type="text"], input[type="password"], input:not([type]), input[type="search"], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 12px;
  font: inherit;
  background: #fff;
}
input:focus, select:focus { outline: 2px solid #93c5fd; border-color: #3b82f6; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: #fff;
  font-size: 13px;
}
.chip input:checked + span {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; border-radius: 12px; border: 1px solid transparent;
  padding: 12px 14px; font: inherit; font-weight: 650; cursor: pointer;
  text-decoration: none; color: inherit;
}
.btn.primary { background: var(--navy); color: #fff; }
.btn.ghost { background: #fff; border-color: var(--line); }
.btn.submit { width: 100%; margin-top: 8px; background: var(--red); color: #fff; font-size: 16px; }
.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-actions .btn { flex: 1; min-width: 140px; }

.photo-preview-wrap {
  margin-top: 10px;
  width: 180px;
  aspect-ratio: 3 / 4;
  border: 1px dashed var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #ffffff;
  display: grid;
  place-items: center;
}
.photo-preview-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.placeholder { color: var(--muted); font-size: 13px; }
.hint { min-height: 1.2em; font-size: 13px; color: var(--muted); }
.hint.ok { color: var(--ok); }
.hint.warn, .warn { color: var(--red); }

.camera-modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8, 12, 20, 0.92);
  display: grid; place-items: center;
  padding: 12px;
}
.camera-modal[hidden] { display: none !important; }
.camera-panel { width: min(420px, 100%); }
.camera-title { color: #fff; text-align: center; margin: 0 0 10px; }
.camera-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: 18px;
  background: #000;
}
#camera-video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.face-guide {
  position: absolute;
  left: 22%; right: 22%; top: 8%; bottom: 34%;
  border: 3px solid rgba(255,255,255,0.92);
  border-radius: 50% 50% 46% 46%;
  box-shadow: 0 0 0 999px rgba(0,0,0,0.35);
  pointer-events: none;
}
.camera-bar { display: flex; gap: 10px; margin-top: 12px; }
.camera-bar .btn { flex: 1; }
#btn-shutter { background: var(--gold); color: var(--navy); }

.success-card { text-align: center; }
.ok-badge {
  display: inline-block; background: #dcfce7; color: var(--ok);
  border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 700;
}
.id-photo {
  width: 180px; aspect-ratio: 3/4; object-fit: cover;
  border-radius: 10px; margin: 12px auto; display: block;
  border: 1px solid var(--line);
}
.facts { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; text-align: left; margin: 16px 0; }
.facts div { background: #f8f4ec; border-radius: 10px; padding: 8px; }
.facts dt { font-size: 11px; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 700; }
.muted { color: var(--muted); }
.site-footer { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 12px 28px; }
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(420px, 100%); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.stats article {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px; text-align: center; box-shadow: var(--shadow);
}
.stats strong { display: block; font-size: 26px; color: var(--navy); }
.stats span { color: var(--muted); font-size: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; margin-bottom: 12px; }
.filters input, .filters select { flex: 1; min-width: 160px; }
.table-wrap { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
  background: var(--navy); color: #fff; text-align: left; padding: 10px 8px;
  position: sticky; top: 0;
}
.data-table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tr:nth-child(even) td { background: #fbf8f1; }
.thumb { width: 42px; height: 56px; object-fit: cover; border-radius: 4px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-word; }
.row-actions { white-space: nowrap; }
.row-actions form { display: inline; }
.link-danger { background: none; border: 0; color: var(--red); cursor: pointer; font: inherit; }
.empty { text-align: center; color: var(--muted); padding: 24px !important; }
.footer-note { margin-top: 16px; }

@media (max-width: 800px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .topbar-inner { flex-wrap: wrap; }
  .facts { grid-template-columns: 1fr; }
}
