:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-alt: #eef1f4;
  --ink: #17212b;
  --muted: #65717d;
  --line: #dce1e6;
  --brand: #176b5b;
  --brand-dark: #0f4f43;
  --accent: #d99a2b;
  --danger: #b63c3c;
  --warning: #9a681b;
  --success: #187550;
  --sidebar: #182329;
  --sidebar-muted: #9fb0b8;
  --radius: 6px;
  font-family:
    Inter, "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(23, 107, 91, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(23, 107, 91, 0.08) 1px, transparent 1px),
    #edf1f0;
  background-size: 32px 32px;
}

.login-panel {
  width: min(100%, 390px);
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 22px 14px;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--brand);
  box-shadow: 0 16px 45px rgba(23, 33, 43, 0.12);
}

.login-panel h1 {
  margin-top: 2px;
  font-size: 24px;
}

.login-panel p {
  margin-top: 5px;
  color: var(--muted);
}

.login-panel label,
.login-panel .button,
.login-panel .form-error,
.login-panel .portal-link {
  grid-column: 1 / -1;
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: white;
  font-weight: 800;
  font-size: 18px;
  border-radius: 4px;
}

.brand-mark.small {
  width: 38px;
  height: 38px;
  font-size: 13px;
}

label {
  display: grid;
  gap: 7px;
  color: #35424e;
  font-size: 13px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd2d8;
  border-radius: 4px;
  padding: 10px 11px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(23, 107, 91, 0.12);
}

textarea {
  min-height: 104px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 7px 13px;
  background: var(--surface-alt);
  color: var(--ink);
  font-weight: 650;
}

.button:hover {
  filter: brightness(0.97);
}

.button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: white;
}

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

.button.quiet {
  border-color: var(--line);
  background: var(--surface);
}

.button.small {
  min-height: 30px;
  padding: 4px 9px;
  font-size: 12px;
}

.button.full {
  width: 100%;
}

.portal-link {
  text-align: center;
  color: var(--brand);
  text-decoration: none;
}

.form-error {
  min-height: 18px;
  color: var(--danger) !important;
  font-size: 13px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  color: white;
  border-right: 1px solid #0d171c;
}

.brand {
  height: 76px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 18px;
  border-bottom: 1px solid #304047;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 14px;
}

.brand small {
  margin-top: 3px;
  color: var(--sidebar-muted);
  font-size: 11px;
}

nav {
  display: grid;
  gap: 3px;
  padding: 16px 10px;
}

.nav-item {
  min-height: 42px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 3px;
  padding: 0 14px;
  background: transparent;
  color: var(--sidebar-muted);
  text-align: left;
  font-weight: 650;
}

.nav-item:hover {
  background: #233239;
  color: white;
}

.nav-item.active {
  border-left-color: #3eb79d;
  background: #293b42;
  color: white;
}

.sidebar-note {
  margin-top: auto;
  padding: 18px;
  border-top: 1px solid #304047;
  color: var(--sidebar-muted);
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  display: inline-block;
  margin-right: 7px;
  border-radius: 50%;
  background: #49c294;
}

.main {
  min-width: 0;
}

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar h2 {
  margin-top: 3px;
  font-size: 19px;
}

.eyebrow {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 13px;
}

.admin-name {
  color: var(--muted);
  font-size: 12px;
}

.menu-button {
  display: none;
}

.icon-button {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
}

.menu-button span {
  width: 16px;
  height: 2px;
  display: block;
  margin: 3px auto;
  background: currentColor;
}

.content {
  padding: 24px 28px 48px;
}

.page-toolbar {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 17px;
}

.page-toolbar .helper {
  color: var(--muted);
}

.page-toolbar .button:first-of-type {
  margin-left: auto;
}

.search-input {
  width: min(330px, 100%);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  background: var(--surface);
}

.metric {
  min-width: 0;
  padding: 20px;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

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

.metric-value {
  margin-top: 8px;
  font-size: 27px;
  font-weight: 750;
}

.metric-detail {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

.section {
  margin-top: 24px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-heading h3 {
  font-size: 14px;
}

.section-heading p {
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

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

th {
  background: #f7f8f9;
  color: #56626e;
  font-size: 11px;
  font-weight: 750;
}

td {
  font-size: 13px;
}

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

tbody tr:hover {
  background: #fafcfc;
}

.cell-title {
  font-weight: 700;
}

.cell-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  border: 1px solid #ccd6d1;
  border-radius: 999px;
  padding: 2px 8px;
  background: #f4faf7;
  color: var(--success);
  font-size: 11px;
  font-weight: 700;
}

.badge.warning {
  border-color: #ead5aa;
  background: #fff9eb;
  color: var(--warning);
}

.badge.danger {
  border-color: #e8c0c0;
  background: #fff5f5;
  color: var(--danger);
}

.badge.neutral {
  border-color: var(--line);
  background: var(--surface-alt);
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 6px;
}

.empty {
  padding: 44px 20px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}

.loading {
  min-height: 240px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

dialog {
  width: min(680px, calc(100vw - 30px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  box-shadow: 0 24px 70px rgba(12, 22, 27, 0.28);
}

dialog::backdrop {
  background: rgba(15, 27, 32, 0.55);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
}

.dialog-header h3 {
  margin-top: 4px;
  font-size: 18px;
}

.close-button {
  border: 0;
  font-size: 24px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 20px 22px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 22px 20px;
  border-top: 1px solid var(--line);
}

#dialog-error {
  padding: 0 22px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10;
  max-width: min(380px, calc(100vw - 48px));
  display: none;
  padding: 12px 15px;
  border: 1px solid #a9d1c3;
  border-radius: 4px;
  background: #edfaf5;
  color: var(--brand-dark);
  box-shadow: 0 12px 30px rgba(23, 33, 43, 0.15);
  font-weight: 650;
}

.toast.show {
  display: block;
}

.toast.error {
  border-color: #e4b5b5;
  background: #fff3f3;
  color: var(--danger);
}

.risk-bar {
  width: 72px;
  height: 5px;
  margin-top: 5px;
  overflow: hidden;
  border-radius: 3px;
  background: #e6e9ec;
}

.risk-bar span {
  height: 100%;
  display: block;
  background: var(--success);
}

.risk-bar span.medium {
  background: var(--accent);
}

.risk-bar span.high {
  background: var(--danger);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

@media (max-width: 900px) {
  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric:nth-child(2) {
    border-right: 0;
  }

  .metric:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 700px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    width: 224px;
    transform: translateX(-100%);
    transition: transform 160ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .menu-button {
    display: block;
  }

  .topbar {
    height: 68px;
    padding: 0 16px;
  }

  .content {
    padding: 18px 16px 36px;
  }

  .admin-name {
    display: none;
  }

  .page-toolbar {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .page-toolbar .button:first-of-type {
    margin-left: 0;
  }

  .search-input {
    flex: 1 1 100%;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .wide {
    grid-column: auto;
  }
}

@media (max-width: 470px) {
  .metrics {
    grid-template-columns: 1fr;
  }

  .metric {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .metric:last-child {
    border-bottom: 0;
  }

  .login-panel {
    padding: 25px 20px;
  }
}

/* ── 用户详情页 ── */

.detail-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
  align-items: start;
}

.detail-grid .card.wide {
  grid-column: 1 / -1;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card h3 {
  margin: 0;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card .table-wrap {
  margin: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--muted);
  flex: 1 1 160px;
}

.stack input,
.stack textarea,
.stack select {
  font: inherit;
  color: var(--ink);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  width: 100%;
}

.stack textarea {
  resize: vertical;
}

.field-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.field-row > input,
.field-row > select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  flex: 1 1 140px;
  min-width: 0;
}

.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  padding: 5px 0;
  border-bottom: 1px dashed var(--line);
}

.kv:last-of-type {
  border-bottom: 0;
}

.kv > span {
  color: var(--muted);
}

.kv-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  padding: 6px 0;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 26px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-alt);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 6px 3px 11px;
  font-size: 12px;
}

.chip-x {
  border: 0;
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  padding: 0 3px;
  border-radius: 999px;
}

.chip-x:hover {
  color: var(--danger);
  background: var(--surface);
}

.button.tiny {
  padding: 3px 8px;
  font-size: 12px;
}

.plain-list,
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.timeline li {
  padding-left: 11px;
  border-left: 2px solid var(--line);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

p.muted.small {
  margin: 0;
  line-height: 1.55;
}

tr.dim td {
  opacity: 0.5;
}

@media (max-width: 640px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

.qrcode-inline {
  text-align: center;
  padding: 16px;
}

.qrcode-inline img {
  max-width: 260px;
  border-radius: 8px;
  border: 1px solid var(--line);
  margin-bottom: 12px;
}
