/*
 * 远程协作 · 中转管理 — admin page styles.
 * System fonts only, no images or other external resources (CSP default-src 'self').
 * Light/dark colours follow the operating system via prefers-color-scheme.
 */

:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef1f5;
  --border: #dfe3ea;
  --border-strong: #c5ccd8;
  --text: #1b2230;
  --muted: #5b6474;
  --primary: #2155d1;
  --primary-hover: #1a46b0;
  --primary-text: #ffffff;
  --primary-soft: #e9effc;
  --danger: #c0302a;
  --danger-hover: #a12520;
  --danger-text: #ffffff;
  --danger-soft: #fdeceb;
  --ok: #146c36;
  --ok-soft: #e5f4ea;
  --warn: #8f5400;
  --warn-soft: #fff3df;
  --info: #35537f;
  --info-soft: #edf2f9;
  --dot-online: #1fa356;
  --dot-online-ring: rgba(31, 163, 86, 0.2);
  --dot-warn: #e8a200;
  --dot-offline: #d9372c;
  --dot-offline-ring: rgba(217, 55, 44, 0.18);
  --dot-idle: #a2aab7;
  --dot-enrolled: #3a73df;
  --os-windows: #0b5cb8;
  --os-macos: #4a5361;
  --os-linux: #845400;
  --focus: #2155d1;
  --input-bg: #ffffff;
  --readonly-bg: #f6f7f9;
  --row-hover: #f8fafd;
  --backdrop: rgba(9, 12, 18, 0.55);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 20px 48px rgba(16, 24, 40, 0.22);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1217;
    --surface: #171b22;
    --surface-2: #1c212a;
    --surface-3: #252b36;
    --border: #2b323e;
    --border-strong: #3d4655;
    --text: #e7eaf0;
    --muted: #9ba4b4;
    --primary: #79a2ff;
    --primary-hover: #97b7ff;
    --primary-text: #0b1322;
    --primary-soft: #1c2944;
    --danger: #ff8078;
    --danger-hover: #ff9c95;
    --danger-text: #1d0b0a;
    --danger-soft: #3a1c1b;
    --ok: #5fd08a;
    --ok-soft: #15301f;
    --warn: #f2b552;
    --warn-soft: #3a2b11;
    --info: #a7bde0;
    --info-soft: #1d2635;
    --dot-online: #3ccf75;
    --dot-online-ring: rgba(60, 207, 117, 0.22);
    --dot-warn: #f1b33a;
    --dot-offline: #ff5f55;
    --dot-offline-ring: rgba(255, 95, 85, 0.2);
    --dot-idle: #6b7484;
    --dot-enrolled: #6f9bff;
    --os-windows: #7ab8ff;
    --os-macos: #c7cdd6;
    --os-linux: #f0c060;
    --focus: #8fb3ff;
    --input-bg: #11151b;
    --readonly-bg: #141820;
    --row-hover: #1b2029;
    --backdrop: rgba(0, 0, 0, 0.62);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.6);
  }
}

/* ---------------------------------------------------------------- base --- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
}

h1,
h2,
h3 {
  margin: 0 0 8px;
  line-height: 1.3;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 17px;
}

h3 {
  font-size: 15px;
}

p {
  margin: 0 0 8px;
}

code,
.mono {
  font-family: var(--mono);
}

code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-3);
  font-size: 0.92em;
}

a {
  color: var(--primary);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Headings and <main> only receive focus programmatically (tabindex=-1). */
h1:focus,
main:focus {
  outline: none;
}

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

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -60px;
  left: 12px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-text);
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

/* -------------------------------------------------------------- topbar --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 10px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
}

.brand-mark {
  display: inline-block;
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--primary), var(--dot-online));
}

.brand-mark-large {
  width: 44px;
  height: 44px;
  margin-bottom: 14px;
  border-radius: 12px;
}

.brand-sub {
  color: var(--muted);
  font-weight: 400;
}

.nav {
  display: flex;
  gap: 4px;
}

.nav-link {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 550;
  text-decoration: none;
}

.nav-link:hover {
  background: var(--surface-3);
  color: var(--text);
}

.nav-link[aria-current="page"] {
  background: var(--primary-soft);
  color: var(--primary);
}

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

.hub-info {
  color: var(--muted);
  font-size: 13px;
}

/* --------------------------------------------------------------- views --- */

.main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.view-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}

.card {
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card {
  width: min(400px, 100%);
}

.login-card h1 {
  font-size: 20px;
}

.login-card .hint {
  margin: 14px 0 0;
}

.noscript {
  max-width: 420px;
  margin: 40px auto;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-title h1 {
  margin-bottom: 4px;
}

.page-title p {
  margin: 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.search {
  flex: 1 1 280px;
  max-width: 480px;
}

.toolbar-end {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.refresh-info {
  color: var(--muted);
  font-size: 12.5px;
}

.refresh-info.is-error {
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--warn-soft);
  color: var(--warn);
}

/* --------------------------------------------------------------- forms --- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0 16px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  line-height: 1.4;
}

textarea {
  resize: vertical;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--focus);
  outline: 3px solid var(--focus);
  outline-offset: 0;
}

input[readonly],
textarea[readonly] {
  background: var(--readonly-bg);
}

input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.6;
}

.hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12.5px;
}

.field .hint {
  margin: 0;
}

.form-error,
.form-notice {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 8px;
  overflow-wrap: anywhere;
}

.form-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.form-notice {
  background: var(--info-soft);
  color: var(--info);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.plain-fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.plain-fieldset h2:not(:first-child) {
  margin-top: 20px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  align-items: start;
  gap: 20px;
}

.settings-side {
  display: grid;
  align-content: start;
  gap: 20px;
  min-width: 0;
}

/* ------------------------------------------------------------- buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  background: var(--surface-3);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

[aria-busy="true"] .btn:disabled {
  cursor: progress;
}

.btn-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-text);
}

.btn-primary:hover:not(:disabled) {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
}

.btn-danger {
  border-color: var(--danger);
  background: var(--danger);
  color: var(--danger-text);
}

.btn-danger:hover:not(:disabled) {
  border-color: var(--danger-hover);
  background: var(--danger-hover);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
}

.btn-danger-ghost {
  color: var(--danger);
}

.btn-danger-ghost:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-primary-ghost {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-primary-ghost:hover:not(:disabled) {
  background: var(--primary-soft);
}

.btn-small {
  padding: 5px 10px;
  font-size: 13px;
}

.btn-block {
  width: 100%;
  padding: 10px 14px;
}

.btn.is-done {
  border-color: var(--ok);
  background: var(--ok-soft);
  color: var(--ok);
}

/* ----------------------------------------------------------- pair list --- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.pairs-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

.pairs-table th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.pairs-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

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

.pairs-table tbody tr:hover {
  background: var(--row-hover);
}

.pairs-table tr.is-disabled td:not(.col-actions) {
  color: var(--muted);
}

.col-no {
  width: 132px;
}

.accounts {
  white-space: nowrap;
}

.col-label {
  min-width: 160px;
  max-width: 260px;
}

.col-endpoint {
  min-width: 220px;
}

.col-status {
  width: 72px;
}

.col-actions {
  width: 236px;
}

.pair-no {
  margin-right: 6px;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.pair-label {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.pair-note {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

.meta {
  color: var(--muted);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

.meta.pending {
  color: var(--info);
}

.status-line {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
}

.host-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  margin-top: 2px;
}

.hostname {
  font-weight: 550;
  overflow-wrap: anywhere;
}

.tone-online {
  color: var(--ok);
}

/* Certificate far from expiry: nothing to point out. */
.meta.tone-ok {
  color: var(--muted);
}

.tone-warn,
.meta.tone-warn {
  color: var(--warn);
}

.tone-offline,
.tone-bad,
.meta.tone-bad {
  color: var(--danger);
}

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

.dot {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dot-idle);
}

.dot-online {
  background: var(--dot-online);
  box-shadow: 0 0 0 3px var(--dot-online-ring);
}

.dot-warn {
  background: var(--dot-warn);
}

.dot-offline {
  background: var(--dot-offline);
  box-shadow: 0 0 0 3px var(--dot-offline-ring);
}

.dot-enrolled {
  background: var(--dot-enrolled);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.6;
  vertical-align: middle;
  white-space: nowrap;
}

.badge-ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge-off {
  border-color: var(--border-strong);
}

.badge-legacy,
.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-admin,
.badge-info {
  background: var(--info-soft);
  color: var(--info);
}

.badge-bad {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-os {
  border-color: currentColor;
  background: transparent;
  color: var(--muted);
}

.badge-os.os-windows {
  color: var(--os-windows);
}

.badge-os.os-macos {
  color: var(--os-macos);
}

.badge-os.os-linux {
  color: var(--os-linux);
}

.action-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.action-group + .action-group {
  margin-top: 8px;
}

.action-caption {
  margin-right: 2px;
  color: var(--muted);
  font-size: 12px;
}

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

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 12.5px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ------------------------------------------------------------- dialogs --- */

.dialog {
  width: min(560px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

/* Older browsers do not inherit custom properties into ::backdrop: keep a fallback. */
.dialog::backdrop {
  background: rgba(9, 12, 18, 0.55);
  background: var(--backdrop, rgba(9, 12, 18, 0.55));
}

.dialog-wide {
  width: min(1120px, calc(100vw - 32px));
}

/* Titles and subtitles may contain long, unbroken labels. */
.dialog h2,
.dialog-head p {
  overflow-wrap: anywhere;
}

.dialog-inner {
  padding: 20px 24px 22px;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.dialog-head h2 {
  margin-bottom: 2px;
}

.dialog-head p {
  margin: 0;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.confirm-body p {
  margin-bottom: 10px;
  overflow-wrap: anywhere;
}

.notice {
  margin-bottom: 16px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--info-soft);
  font-size: 13px;
}

.notice p {
  margin: 0;
}

.notice p + p {
  margin-top: 4px;
}

/* Events drawer: a modal dialog docked to the right edge. */
.drawer {
  width: min(520px, 100vw);
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0 0 0 auto;
  border-width: 0 0 0 1px;
  border-radius: 0;
}

.drawer-inner {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.drawer-foot {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.events-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.event {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

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

.event-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.event-time {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.event-detail {
  margin: 0;
  overflow-wrap: anywhere;
}

.events-empty {
  padding: 12px 0;
  color: var(--muted);
}

/* ------------------------------------------------------------- invites --- */

.invite-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.invite-cards.single {
  grid-template-columns: minmax(0, 1fr);
}

.invite-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-top-width: 4px;
  border-radius: 12px;
  background: var(--surface-2);
}

.invite-card-cn {
  border-top-color: var(--dot-online);
}

.invite-card-my {
  border-top-color: var(--dot-enrolled);
}

.invite-head h3 {
  margin-bottom: 0;
}

.invite-head p {
  font-size: 12.5px;
}

.copy-field {
  margin-bottom: 12px;
}

.copy-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.code-box {
  font-size: 12px;
  line-height: 1.45;
  word-break: break-all;
}

.message-box {
  min-height: 220px;
  font-size: 13px;
  line-height: 1.55;
}

.invite-expiry {
  margin-bottom: 12px;
  color: var(--warn);
  font-size: 13px;
  font-weight: 550;
}

.copy-status {
  min-height: 1.4em;
  margin: 0;
  color: var(--ok);
  font-size: 12.5px;
}

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

/* Off-screen textarea used by the execCommand('copy') fallback. */
.clipboard-helper {
  position: fixed;
  top: 0;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* -------------------------------------------------------------- toasts --- */

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 40px));
  pointer-events: none;
}

.toast {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--info);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  overflow-wrap: anywhere;
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}

.toast-success {
  border-left-color: var(--ok);
}

.toast-error {
  border-left-color: var(--danger);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------------------------------------------------------- responsive --- */

@media (max-width: 1000px) {
  /* The pair table turns into one card per pair; data-label names each cell. */
  .pairs-table {
    min-width: 0;
  }

  .pairs-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
  }

  .pairs-table,
  .pairs-table tbody,
  .pairs-table tr,
  .pairs-table td {
    display: block;
    width: 100%;
    max-width: none;
  }

  .pairs-table tr {
    padding: 8px 4px;
    border-bottom: 1px solid var(--border);
  }

  .pairs-table tbody tr:last-child {
    border-bottom: 0;
  }

  .pairs-table td {
    padding: 6px 12px;
    border-bottom: 0;
  }

  .pairs-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    color: var(--muted);
    font-size: 11.5px;
    font-weight: 600;
  }

  .settings-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 860px) {
  .invite-cards {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .main {
    padding: 16px 12px 40px;
  }

  .topbar-inner {
    padding: 8px 12px;
  }

  .hub-info {
    display: none;
  }

  .dialog-inner {
    padding: 16px;
  }

  .card {
    padding: 16px;
  }

  .toolbar-end {
    margin-left: 0;
  }

  .toasts {
    right: 12px;
    bottom: 12px;
    left: 12px;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    animation: none;
  }
}

/* Windows high-contrast mode drops background colours; keep the dots visible. */
@media (forced-colors: active) {
  .dot {
    border: 1px solid CanvasText;
    forced-color-adjust: none;
  }
}
