:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #f0f2f5;
  --border: #dcdfe6;
  --text: #16181d;
  --muted: #5d6472;
  --primary: #1f5eff;
  --primary-hover: #154bd6;
  --danger: #d93838;
  --success: #1b8a4b;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #111318;
  --surface: #191c23;
  --surface-alt: #21252f;
  --border: #2e3442;
  --text: #eef0f4;
  --muted: #9aa3b2;
  --primary: #4c82ff;
  --primary-hover: #366df0;
  --danger: #ef5b5b;
  --success: #34c77b;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
}

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

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.user-badge {
  font-size: 13px;
  color: var(--muted);
  background: var(--surface-alt);
  padding: 6px 10px;
  border-radius: 8px;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-shell {
  min-height: calc(100vh - 70px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
}

.auth-title {
  margin: 0 0 6px;
  font-size: 22px;
}

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

.card h2, .card h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.card-head h3 {
  margin: 0;
}

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

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.row-gap {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: stretch;
}

.flex-1 {
  flex: 1 1 180px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.span-2 {
  grid-column: span 2;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

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

.field input, .field select, .field textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.field textarea {
  min-height: 68px;
  resize: vertical;
}

.align-end {
  align-self: flex-end;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: var(--surface-alt);
  border-color: var(--border);
  color: var(--text);
}

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

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

.btn-sm {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 4px;
}

.stat-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th, .table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-ok {
  background: rgba(27, 138, 75, 0.14);
  color: var(--success);
}

.badge-off {
  background: rgba(217, 56, 56, 0.14);
  color: var(--danger);
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.notice {
  background: rgba(31, 94, 255, 0.1);
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  margin: 14px 0;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  max-width: min(420px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  width: 100%;
  max-width: 500px;
}

.secret-box {
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  word-break: break-all;
  user-select: all;
  margin-bottom: 14px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.auth-footer {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.auth-footer a,
.doc-footer a,
.doc-footer button.doc-back-link,
.doc-section a {
  color: var(--primary);
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

.auth-footer a:hover,
.doc-footer a:hover,
.doc-footer button.doc-back-link:hover,
.doc-section a:hover {
  text-decoration: underline;
}

.doc-shell {
  max-width: 780px;
}

.doc-card {
  padding: 24px;
}

.doc-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.doc-section {
  margin-top: 20px;
}

.doc-section h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.doc-section p {
  margin: 0;
  color: var(--text);
}

.doc-section ul {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.doc-section code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.doc-footer {
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

@media (max-width: 640px) {
  .topbar {
    padding: 10px 12px;
  }
  .doc-card {
    padding: 18px 16px;
  }
  .span-2 {
    grid-column: span 1;
  }
  .align-end {
    align-self: stretch;
  }
}
