:root {
  --ink: #172033;
  --ink-soft: #3d4a5c;
  --muted: #6b7789;
  --line: #d8dee8;
  --paper: #f3f5f8;
  --card: #ffffff;
  --accent: #0f6e56;
  --accent-soft: #e3f4ee;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --info: #185fa5;
  --info-soft: #e6f1fb;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(23, 32, 51, 0.08);
  --font: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  --nav-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
#app { min-height: 100dvh; }

.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px calc(24px + var(--safe-b));
  background:
    radial-gradient(1200px 400px at 10% -10%, #d7ece4 0%, transparent 55%),
    radial-gradient(800px 320px at 110% 10%, #d9e4f2 0%, transparent 50%),
    var(--paper);
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 24px 22px;
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  display: grid; place-items: center;
  margin-bottom: 16px;
}
.login-card h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: -0.02em; }
.login-card .sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.guide {
  background: var(--paper);
  border-radius: 10px;
  padding: 12px 14px 6px;
  margin-bottom: 16px;
}
.guide h3 { margin: 0 0 6px; }
.guide-list { margin: 0 0 10px; padding-left: 1.2em; color: var(--ink-soft); font-size: 13px; line-height: 1.65; }
.guide-list li { margin-bottom: 6px; }
.hint-box {
  margin-top: 16px;
  background: var(--paper);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--ink-soft);
  font-size: 13px;
}
.hint-box code { font-family: var(--mono); font-size: 12px; }

.shell { display: flex; min-height: 100dvh; }
.sider {
  width: 220px;
  background: var(--ink);
  color: #e8edf5;
  padding: 20px 12px;
  display: none;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100dvh;
}
.sider .logo {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 18px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.sider a {
  color: #c5cedb;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  display: flex; align-items: center; gap: 10px;
  min-height: 44px;
}
.sider a.active, .sider a:hover { background: rgba(255,255,255,.08); color: #fff; }
.main { flex: 1; min-width: 0; padding-bottom: calc(72px + var(--safe-b)); }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar h2 { margin: 0; font-size: 17px; font-weight: 650; }
.who { color: var(--muted); font-size: 13px; }
.content { padding: 16px; max-width: 1100px; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 8;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #fff;
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  max-width: 100%;
}
.bottom-nav a {
  min-height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none;
}
.bottom-nav a.active { color: var(--accent); font-weight: 650; }

.grid-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
}
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; }
.row {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.item .title { font-weight: 650; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.mono { font-family: var(--mono); font-size: 13px; }

label.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 14px; font-weight: 600; }
label.field span.help { font-weight: 400; color: var(--muted); font-size: 12px; }
input[type="text"], input[type="password"], input[type="tel"], input[type="number"],
input[type="datetime-local"], select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: #fff;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.btn {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  padding: 0 16px;
  background: var(--ink);
  color: #fff;
  font-weight: 650;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); }
.btn.warn { background: var(--warn); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 13px; }

.badge {
  display: inline-flex; align-items: center;
  height: 22px; padding: 0 8px;
  border-radius: 999px;
  font-size: 12px; font-weight: 650;
  background: var(--paper); color: var(--ink-soft);
  white-space: nowrap;
}
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.approved { background: var(--accent-soft); color: var(--accent); }
.badge.used { background: var(--info-soft); color: var(--info); }
.badge.expired, .badge.revoked, .badge.idle { background: var(--paper); color: var(--muted); }
.badge.issued { background: var(--accent-soft); color: var(--accent); }
.badge.fail { background: var(--danger-soft); color: var(--danger); }
.badge.ok { background: var(--accent-soft); color: var(--accent); }

.table-wrap { overflow: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
table.data th, table.data td {
  text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top;
}
table.data th { color: var(--muted); font-weight: 600; font-size: 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 10px 14px; border-radius: 10px;
  font-size: 14px; z-index: 20;
  max-width: calc(100% - 32px);
}
.err { color: var(--danger); font-size: 13px; margin: 8px 0; }
.empty { color: var(--muted); padding: 28px 8px; text-align: center; }
.checks { display: flex; flex-direction: column; gap: 8px; }
.checks label { display: flex; gap: 8px; align-items: center; font-weight: 500; min-height: 40px; }

.visitor {
  min-height: 100dvh;
  background: #121821;
  color: #eef2f6;
  display: flex; flex-direction: column;
  padding: 20px 16px calc(24px + var(--safe-b));
}
.visitor header { text-align: center; margin-bottom: 12px; }
.visitor header .kicker { color: #93a0b3; font-size: 12px; letter-spacing: .08em; }
.visitor h1 { margin: 4px 0 0; font-size: 22px; }
.visitor > p { text-align: center; color: #9aa0b4; }
.qr-card {
  background: #fff; color: var(--ink);
  border-radius: 18px;
  padding: 18px 16px 14px;
  margin: 8px 0 16px;
  display: flex; flex-direction: column; align-items: center;
}
.qr-card img, .qr-card svg { width: min(86vw, 360px); height: auto; }
.qr-card .scan-hint { margin-top: 10px; font-size: 15px; font-weight: 650; color: var(--ink); }
.qr-card .card-no { margin-top: 4px; font-size: 18px; letter-spacing: 0.08em; color: var(--ink); }
.countdown {
  font-variant-numeric: tabular-nums;
  font-size: 28px; font-weight: 700; letter-spacing: -0.03em;
  text-align: center; margin: 4px 0 12px;
}
.visitor .panel {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px;
  padding: 14px;
}
.visitor .panel p { margin: 6px 0; color: #d5dde8; font-size: 14px; }
.visitor.invalid { justify-content: center; text-align: center; }
.muted { color: var(--muted); }

.detail-grid {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px 12px;
  margin-top: 12px;
  font-size: 13px;
}
.detail-row { display: contents; }
.detail-row .k { color: var(--muted); }
.detail-row .v { word-break: break-all; }
.timeline-title { margin: 16px 0 8px; font-size: 13px; }
.timeline .ev { padding: 8px 0; border-top: 1px solid var(--line); }
.pre-raw {
  font-family: var(--mono);
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--paper);
  padding: 8px;
  border-radius: 8px;
  max-height: 140px;
  overflow: auto;
  margin: 6px 0 0;
}
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.form-actions .btn { flex: 1; }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.perm-box { margin: 4px 0 12px; }
.perm-building { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; background: #fff; }
.perm-head { margin-bottom: 8px; }
.perm-head label, .perm-floor { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.perm-floors { display: flex; flex-wrap: wrap; gap: 8px 12px; }
.perm-floor { min-height: 36px; padding: 0 4px; }
.room-hits { margin-top: 8px; }
.room-hit-list { display: grid; gap: 0; }

.xmt {
  background: #12141c;
  color: #f2efe6;
  border-radius: 16px;
  padding: 14px;
  margin: 0 0 14px;
  border: 1px solid #34384a;
}
.xmt h3 { margin: 0 0 6px; font-size: 18px; color: #f2efe6; letter-spacing: -0.02em; }
.xmt .sub { color: #9aa0b4; margin: 0 0 14px; font-size: 13px; font-weight: 400; }
.xmt .elev-grid { display: grid; gap: 10px; }
.xmt .elev {
  text-align: left;
  background: #222633;
  border: 1px solid #34384a;
  border-radius: 14px;
  padding: 16px;
  min-height: 72px;
  color: #f2efe6;
  width: 100%;
}
.xmt .elev b { display: block; font-size: 17px; }
.xmt .elev span { color: #9aa0b4; font-size: 12px; }
.xmt .elev:active, .xmt .room:active { transform: scale(0.99); }
.xmt .chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 12px;
  -webkit-overflow-scrolling: touch;
}
.xmt .chip {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid #34384a;
  background: #1a1d28;
  color: #f2efe6;
}
.xmt .chip.on {
  background: #e2b23a;
  color: #1a1406;
  border-color: transparent;
  font-weight: 700;
}
.xmt .rooms {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.xmt .room {
  min-height: 56px;
  border-radius: 12px;
  border: 1px solid #34384a;
  background: #1a1d28;
  color: #f2efe6;
  font-weight: 600;
}
.xmt .room.on {
  background: #e2b23a;
  color: #1a1406;
  border-color: transparent;
}
.xmt .back {
  border: 0;
  background: transparent;
  color: #e2b23a;
  padding: 0;
  min-height: 32px;
  margin-bottom: 8px;
}
.xmt .picked {
  background: #222633;
  border: 1px solid #34384a;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.xmt .picked b { display: block; }
.xmt .picked span { color: #9aa0b4; font-size: 12px; }
.xmt .err { color: #e05a4f; min-height: 18px; margin-top: 8px; }
.xmt label {
  display: block;
  font-size: 13px;
  color: #9aa0b4;
  margin: 10px 0 6px;
  font-weight: 400;
}
.xmt input {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid #34384a;
  background: #1a1d28;
  padding: 0 14px;
  color: #f2efe6;
}
.xmt .captcha-row {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 10px;
  align-items: end;
}
.xmt .captcha {
  height: 48px;
  border-radius: 12px;
  border: 1px solid #34384a;
  background: #fff;
  object-fit: contain;
  cursor: pointer;
}

.pass-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 4px auto 12px;
  max-width: 480px;
  width: 100%;
}
.pass-tabs button {
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid #34384a;
  background: #1a1d28;
  color: #f2efe6;
}
.pass-tabs button.on {
  background: #e2b23a;
  color: #1a1406;
  border-color: transparent;
  font-weight: 700;
}

.xmt-qr { max-width: 480px; margin: 0 auto; }
.xmt-qr h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -0.02em; }
.xmt-qr .sub { color: #9aa0b4; margin: 0 0 12px; font-size: 13px; }
.xmt-qr .qr-wrap {
  display: grid;
  place-items: center;
  width: fit-content;
  background: #fff;
  border-radius: 18px;
  padding: 20px;
  margin: 8px auto 16px;
}
.xmt-qr .qr-wrap canvas,
.xmt-qr .qr-wrap img {
  width: 150px;
  height: 150px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.xmt-qr .meta {
  display: grid;
  gap: 8px;
  font-size: 14px;
  color: #f2efe6;
}
.xmt-qr .meta div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #34384a;
  padding-bottom: 8px;
}
.xmt-qr .meta span { color: #9aa0b4; }
.xmt-qr .meta b { font-weight: 600; text-align: right; word-break: break-all; color: #f2efe6; }

@media (min-width: 720px) {
  .xmt .rooms { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 900px) {
  .sider { display: flex; }
  .bottom-nav { display: none; }
  .main { padding-bottom: 24px; }
  .grid-stats { grid-template-columns: repeat(5, 1fr); }
  .content { padding: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
