:root {
  --bg: #f5f4ef;
  --ink: #20211f;
  --muted: #696b65;
  --line: #d8d2c3;
  --line-strong: #c5bea9;
  --panel: #fffefa;
  --panel-quiet: #faf8f0;
  --accent: #256f5a;
  --accent-ink: #ffffff;
  --accent-soft: #e4f1eb;
  --danger: #a33a2b;
  --danger-soft: #fae6e2;
  --warn: #986b21;
  --warn-soft: #fff3ce;
  --shadow: 0 18px 42px rgba(58, 52, 38, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 254, 250, 0.72), rgba(245, 244, 239, 0) 260px),
    var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

code,
.mono,
.number {
  font-family: "SFMono-Regular", "Cascadia Mono", "Consolas", monospace;
}

.topbar {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 254, 250, 0.92);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: min(1180px, calc(100% - 32px));
  min-height: 68px;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 34px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--ink);
  color: var(--panel);
  font-family: "SFMono-Regular", "Cascadia Mono", "Consolas", monospace;
  font-size: 13px;
  letter-spacing: 0;
}

.brand-text {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.brand-name {
  line-height: 1.2;
}

.brand-sub {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.admin-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.logout-form {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
}

.topbar-divider {
  width: 1px;
  height: 24px;
  background: var(--line);
}

.operator,
.muted,
.subtle {
  color: var(--muted);
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 64px;
}

.page-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.compact-heading {
  margin: 8px 0 18px;
}

.detail-heading {
  align-items: flex-start;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.16;
}

h2 {
  margin-bottom: 14px;
  font-size: 18px;
  line-height: 1.25;
}

.section-head h2 {
  margin-bottom: 0;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.12s ease;
}

.button:hover {
  border-color: var(--ink);
  background: var(--panel-quiet);
}

.button:active {
  transform: translateY(1px);
}

.button[disabled],
.button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
}

.button[disabled]:hover,
.button[aria-disabled="true"]:hover {
  border-color: var(--line-strong);
}

.button:focus-visible,
input:focus-visible,
.brand:focus-visible,
.back-link:focus-visible,
a:not(.button):focus-visible,
.flash:focus-visible {
  outline: 3px solid rgba(37, 111, 90, 0.2);
  outline-offset: 2px;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.button.primary:hover {
  background: #1d5f4c;
}

.button.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fffefa;
}

.button.danger:hover {
  background: #8d2f23;
}

.button.primary[disabled],
.button.primary[aria-disabled="true"],
.button.primary[disabled]:hover,
.button.primary[aria-disabled="true"]:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.button.danger[disabled],
.button.danger[aria-disabled="true"],
.button.danger[disabled]:hover,
.button.danger[aria-disabled="true"]:hover {
  border-color: var(--danger);
  background: var(--danger);
  color: #fffefa;
}

.button.ghost {
  background: transparent;
}

.button.compact {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 13px;
}

.button.full {
  width: 100%;
}

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  font-weight: 800;
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 10px;
}

input:focus {
  border-color: var(--accent);
  outline: none;
}

.inline-create {
  display: flex;
  align-items: end;
  gap: 10px;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.72);
}

.limit-field {
  width: 108px;
}

.login-shell {
  display: grid;
  min-height: calc(100dvh - 148px);
  place-items: center;
}

.login-panel,
.panel,
.table-shell,
.delivery-panel,
.usage-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-panel {
  width: min(430px, 100%);
  padding: 30px;
}

.login-head {
  margin-bottom: 22px;
}

.login-head .subtle {
  margin: 10px 0 0;
}

.form-stack {
  display: grid;
  gap: 15px;
}

.flash,
.notice {
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--warn-soft);
}

.flash.success {
  background: var(--accent-soft);
  border-color: #bad9cc;
}

.flash.error {
  background: var(--danger-soft);
  border-color: #e4b6ac;
}

.flash.warn,
.notice {
  color: #5a3e0f;
}

.table-shell {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.employees-table {
  min-width: 800px;
  table-layout: fixed;
}

.employees-table th:nth-child(1) {
  width: 18%;
}

.employees-table th:nth-child(2) {
  width: 8%;
}

.employees-table th:nth-child(3) {
  width: 9%;
}

.employees-table th:nth-child(4) {
  width: 15%;
}

.employees-table th:nth-child(5) {
  width: 24%;
}

.employees-table th:nth-child(6) {
  width: 16%;
}

.employees-table th:nth-child(7) {
  width: 10%;
}

.nodes-table {
  min-width: 680px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

tbody tr {
  transition: background 0.16s ease;
}

tbody tr:hover {
  background: rgba(37, 111, 90, 0.035);
}

tbody tr:focus-within {
  background: rgba(37, 111, 90, 0.055);
}

tr:last-child td {
  border-bottom: 0;
}

.employee-cell strong,
.employee-cell .muted,
.usage-stack .muted,
.node-summary strong,
.node-summary .muted {
  display: block;
}

.empty {
  padding: 34px 16px;
  color: var(--muted);
  text-align: center;
}

.empty strong,
.empty .muted {
  display: block;
}

.empty strong {
  margin-bottom: 4px;
  color: var(--ink);
}

.pill,
.node-chip {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  max-width: 100%;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7f5ee;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
}

.pill.ok,
.node-chip.ok {
  border-color: #a9cdbd;
  background: var(--accent-soft);
  color: #165541;
}

.pill.muted-pill,
.node-chip.absent {
  color: var(--muted);
}

.pill.over,
.node-chip.failed {
  border-color: #dfb2a8;
  background: var(--danger-soft);
  color: #7d2d21;
}

.node-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.compact-node-list {
  margin-top: 8px;
}

.compact-node-list .node-chip {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-summary {
  display: grid;
  gap: 2px;
}

.usage-cell {
  white-space: nowrap;
}

.usage-stack {
  display: grid;
  gap: 6px;
  justify-items: start;
}

.usage-stack .muted {
  min-height: 20px;
}

.detail-page {
  display: grid;
  gap: 18px;
}

.back-link {
  width: fit-content;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}

.back-link:hover {
  color: var(--ink);
}

.delivery-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  overflow: hidden;
}

.delivery-main {
  min-width: 0;
  padding: 22px;
}

.copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
  margin-top: 16px;
}

.url-code {
  display: block;
  min-width: 0;
  min-height: 40px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  overflow-wrap: anywhere;
  color: #2f342f;
  font-size: 13px;
}

.copy-feedback {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.copy-feedback.success {
  color: var(--accent);
}

.copy-feedback.error {
  color: var(--danger);
}

.copy-button {
  min-width: 88px;
}

.copy-button.is-copied {
  border-color: var(--accent);
  background: #1d5f4c;
}

.copy-button.is-failed {
  border-color: var(--danger);
  background: var(--danger);
  color: #fffefa;
}

.delivery-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.delivery-meta > div {
  display: grid;
  gap: 7px;
  min-width: 0;
  padding: 13px 14px;
  background: var(--panel-quiet);
}

.delivery-meta > div + div {
  border-left: 1px solid var(--line);
}

.delivery-meta .muted {
  font-size: 12px;
  line-height: 1.45;
}

.label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.qr-card {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 22px;
  border-left: 1px solid var(--line);
  background: #fbfaf4;
}

.qr-card h2 {
  margin-bottom: 0;
}

.qr-card img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.qr-card .subtle {
  margin-bottom: 0;
  font-size: 13px;
}

.usage-panel {
  padding: 20px 22px 22px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.metric {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 14px;
  background: var(--panel-quiet);
}

.metric + .metric {
  border-left: 1px solid var(--line);
}

.metric strong {
  font-size: 16px;
}

.collecting-state {
  display: grid;
  gap: 5px;
  margin-top: 16px;
  padding: 16px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--panel-quiet);
}

.management-grid,
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.panel {
  padding: 20px;
}

.panel h2 {
  margin-bottom: 4px;
}

.form-note {
  margin: -4px 0 0;
  font-size: 13px;
  line-height: 1.45;
}

.danger-zone {
  border-color: #dfb2a8;
  background: #fffaf8;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.compact-table {
  margin-top: 0;
}

.table-hint {
  display: none;
  margin: -4px 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

@media (max-width: 900px) {
  .topbar-inner,
  .page-heading,
  .inline-create,
  .logout-form,
  .delivery-panel,
  .delivery-meta,
  .metrics-grid,
  .management-grid,
  .split {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .topbar-inner {
    padding: 14px 0;
  }

  .logout-form {
    justify-items: start;
  }

  .topbar-divider {
    display: none;
  }

  .inline-create {
    padding: 12px;
  }

  .limit-field {
    width: 100%;
  }

  .delivery-main,
  .qr-card,
  .usage-panel,
  .panel {
    padding: 18px;
  }

  .qr-card {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .delivery-meta > div + div,
  .metric + .metric {
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

@media (max-width: 520px) {
  .page,
  .topbar-inner {
    width: min(100% - 24px, 1180px);
  }

  .copy-row {
    grid-template-columns: 1fr;
  }

  .login-panel {
    padding: 24px 18px;
  }

  .table-hint {
    display: block;
  }
}

/* 提交遮罩：加员工 / 改设备上限 / 删员工都要同步下发 3 个节点（约 10 余秒），
   浏览器卡在 POST 上，用全屏遮罩给出即时反馈，跳转完成后自然消失。 */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(32, 33, 31, 0.34);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.24s ease, visibility 0.24s ease;
}

.overlay.is-active {
  opacity: 1;
  visibility: visible;
}

.overlay-card {
  min-width: 260px;
  max-width: 360px;
  padding: 30px 34px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(32, 33, 31, 0.24);
  transform: translateY(8px) scale(0.97);
  transition: transform 0.24s ease;
}

.overlay.is-active .overlay-card {
  transform: none;
}

.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 16px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: op-spin 0.8s linear infinite;
}

.overlay.danger .spinner {
  border-top-color: var(--danger);
}

.overlay-msg {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.overlay-sub {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
}

@keyframes op-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
    border-color: var(--line);
    border-top-color: var(--accent);
  }
  .overlay.danger .spinner {
    border-top-color: var(--danger);
  }
  .overlay,
  .overlay-card {
    transition-duration: 0.01ms;
  }
}
