:root {
  --blue: #004280;
  --blue-hover: #0a5398;
  --blue-tint: #e8f0f8;
  --ink: #17232f;
  --muted: #5a6a7a;
  --line: #d8e0e8;
  --paper: #f3f5f8;
  --white: #fff;
  --danger: #b3261e;
  --danger-tint: #fbeceb;
  --ok: #1c6f46;
  --ok-tint: #e6f4ec;
  --warn: #7a4f00;
  --warn-tint: #fdf1d6;
  --font: "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.6 var(--font);
  color: var(--ink);
  background: var(--paper);
}
a { color: var(--blue); text-underline-offset: 2px; }
a:hover { color: var(--blue-hover); }
:focus-visible { outline: 3px solid #6fa8e0; outline-offset: 2px; }
code, .mono, pre { font-family: var(--mono); }
code { font-size: .9em; background: var(--blue-tint); padding: 1px 5px; border-radius: 3px; }
small { display: block; color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.block { display: block; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 40px; padding: 0 18px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  border: 1px solid transparent; border-radius: 4px;
}
.btn.block { display: flex; width: 100%; }
.btn.primary { background: var(--blue); color: var(--white); }
.btn.primary:hover { background: var(--blue-hover); color: var(--white); }
.btn.secondary { background: var(--white); color: var(--blue); border-color: var(--blue); }
.btn.secondary:hover { background: var(--blue-tint); }
.btn.danger { background: var(--danger); color: var(--white); }
.btn.danger:hover { background: #8f1d17; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--blue); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.danger-text { color: var(--danger); }

.form { display: grid; gap: 16px; }
.form.wide { max-width: 640px; margin-top: 20px; }
.form label { display: grid; gap: 6px; font-weight: 600; }
.form label small { font-weight: 400; }
.form label.check { display: flex; align-items: center; gap: 10px; font-weight: 400; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink);
  padding: 9px 12px; background: var(--white);
  border: 1px solid #aebbc8; border-radius: 4px;
}
textarea { resize: vertical; font-family: var(--mono); font-size: 13.5px; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--blue); }
form.inline { display: inline; }
.form .btn { justify-self: start; }
.form .btn.block { justify-self: stretch; }

/* ---------- messages ---------- */
.flash, .notice {
  margin: 0 0 20px; padding: 12px 16px; border-radius: 4px; border-left: 4px solid;
}
.flash.ok { background: var(--ok-tint); border-color: var(--ok); color: #104a2e; }
.flash.error { background: var(--danger-tint); border-color: var(--danger); color: #7d1913; }
.notice { background: var(--warn-tint); border-color: #d99a00; color: var(--warn); }
.notice a { color: inherit; font-weight: 600; margin-left: 6px; }
.hint { color: var(--muted); font-size: 13.5px; max-width: 640px; }
.empty { color: var(--muted); margin: 0; padding: 20px 0; }

/* ---------- plain pages (login, errors) ---------- */
.plain-body { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.door { width: 100%; max-width: 440px; background: var(--white); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.door-logo { display: block; width: 100%; height: auto; }
.door-body { padding: 28px 32px 32px; display: grid; gap: 18px; }
.door-title { margin: 0; font-size: 22px; line-height: 1.3; }
.lead { margin: 0; font-size: 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 0; }
.or { display: flex; align-items: center; gap: 12px; margin: 4px 0; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.foot { margin: 18px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- admin shell ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side {
  background: var(--blue); color: var(--white);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: block; }
.brand img { display: block; width: 100%; height: auto; }
.nav { display: flex; flex-direction: column; padding: 14px 0; flex: 1; }
.nav a {
  color: #d5e3f2; text-decoration: none; padding: 10px 24px;
  border-left: 4px solid transparent;
}
.nav a:hover { background: rgba(255,255,255,.08); color: var(--white); }
.nav a[aria-current="page"] { color: var(--white); font-weight: 600; background: rgba(255,255,255,.12); border-left-color: var(--white); }
.side :focus-visible { outline-color: #bcd8f5; }
.who { padding: 16px 24px 20px; border-top: 1px solid rgba(255,255,255,.18); display: grid; gap: 4px; font-size: 14px; }
.who-name { overflow-wrap: anywhere; }
.who .linkbtn { color: #d5e3f2; justify-self: start; }
.who .linkbtn:hover { color: var(--white); }

.main { padding: 32px 40px 64px; min-width: 0; max-width: 1180px; }
.page-head { margin-bottom: 24px; }
.page-head h1 { margin: 0; font-size: 26px; line-height: 1.25; }

.panel { background: var(--white); border: 1px solid var(--line); border-radius: 6px; padding: 22px 24px; margin-bottom: 24px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 17px; }
.panel.secret { border-color: #d99a00; background: #fffaf0; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--white); border: 1px solid var(--line); border-radius: 6px; margin-bottom: 24px; }
.stats div { padding: 20px 24px; border-left: 1px solid var(--line); }
.stats div:first-child { border-left: 0; }
.stats b { display: block; font-size: 34px; line-height: 1.1; font-weight: 600; color: var(--blue); font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); font-size: 14px; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); padding: 8px 12px; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
td small.mono { font-size: 12px; }

.tag { display: inline-block; padding: 1px 9px; border-radius: 10px; font-size: 12.5px; font-weight: 600; background: var(--blue-tint); color: var(--blue); }
.tag.ok, .tag.ev-login { background: var(--ok-tint); color: var(--ok); }
.tag.off { background: #e9edf1; color: var(--muted); }
.tag.warn { background: var(--warn-tint); color: var(--warn); }
.tag.ev-denied { background: var(--danger-tint); color: var(--danger); }

.filters, .search { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 14px; }
.filters label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; min-width: 200px; }
.search input { min-width: 240px; }
.pager { display: flex; justify-content: space-between; align-items: center; padding-top: 14px; color: var(--muted); }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 10px 24px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

pre.code { background: #0f2236; color: #e6eef7; padding: 16px 18px; border-radius: 4px; overflow-x: auto; font-size: 13px; line-height: 1.55; margin: 10px 0 0; }
.secret pre.code { font-size: 15px; user-select: all; }
.prose p, .prose li { max-width: 72ch; }
.prose ol, .prose ul { padding-left: 22px; }

details.danger { border-top: 1px solid var(--line); padding: 14px 0; }
details.danger:first-of-type { border-top: 0; padding-top: 0; }
details.danger summary { cursor: pointer; font-weight: 600; }
details.danger p { color: var(--muted); max-width: 640px; }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .brand img { max-width: 320px; }
  .nav { flex-direction: row; overflow-x: auto; padding: 0; }
  .nav a { white-space: nowrap; padding: 12px 16px; border-left: 0; border-bottom: 4px solid transparent; }
  .nav a[aria-current="page"] { border-left: 0; border-bottom-color: var(--white); }
  .who { grid-template-columns: 1fr auto; align-items: center; padding: 10px 16px; }
  .main { padding: 20px 16px 48px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats div:nth-child(3) { border-left: 0; }
  .stats div:nth-child(n+3) { border-top: 1px solid var(--line); }
  dl.kv { grid-template-columns: 1fr; gap: 2px; }
  dl.kv dd { margin-bottom: 10px; }
  .door-body { padding: 24px 20px 28px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
