:root {
  --bg-canvas: #09090b;
  --bg-card: #111113;
  --bg-elevated: #18181b;
  --bg-hover: #222226;
  --border: #27272a;
  --border-strong: #3f3f46;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --text-dim: #71717a;
  --emerald: #10b981;
  --emerald-dim: rgba(16, 185, 129, 0.14);
  --emerald-border: rgba(16, 185, 129, 0.35);
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.14);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.14);
  --radius: 10px;
  --font-sans: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.icon-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* 登录视图 */
.login-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 600;
}

.login-sub {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.login-form {
  display: grid;
  gap: 12px;
}

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

.login-form input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}

.login-form input:focus {
  outline: none;
  border-color: var(--emerald);
}

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

/* 主布局 */
.app-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 20px 40px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.topbar-left,
.topbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

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

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--emerald);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.55);
}

.brand-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.host-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.pill-tag {
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--emerald-dim);
  color: var(--emerald);
  font-size: 11px;
  font-weight: 600;
}

.sync-meta {
  font-size: 12px;
  color: var(--text-dim);
}

.feedback-bar {
  margin-bottom: 16px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 13px;
}

.feedback-bar[data-tone="error"] {
  border-color: rgba(239, 68, 68, 0.4);
  background: var(--red-dim);
}

.feedback-bar[data-tone="ok"] {
  border-color: var(--emerald-border);
  background: var(--emerald-dim);
}

/* 按钮与徽章 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

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

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

.btn-primary {
  background: var(--emerald);
  border-color: var(--emerald);
  color: #052e16;
  font-weight: 600;
}

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

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}

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

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

.btn-block {
  width: 100%;
  min-height: 44px;
}

.btn-icon {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}

.badge-neutral {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.badge-emerald {
  background: var(--emerald-dim);
  border: 1px solid var(--emerald-border);
  color: var(--emerald);
}

.badge-amber {
  background: var(--amber-dim);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: var(--amber);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--text-dim);
  flex-shrink: 0;
}

.status-dot[data-state="ok"] {
  background: var(--emerald);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.45);
}

.status-dot[data-state="warn"] {
  background: var(--amber);
}

.status-dot[data-state="error"] {
  background: var(--red);
}

/* 卡片与网格 */
.dashboard-main {
  display: grid;
  gap: 18px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.eyebrow {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

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

.telemetry-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 18px;
}

/* 流量配额卡 */
.quota-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quota-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 14px;
}

.quota-used {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.quota-unit,
.quota-sep {
  color: var(--text-muted);
  font-size: 14px;
}

.quota-total {
  color: var(--text-muted);
  font-size: 18px;
}

.progress-wrap {
  margin-bottom: 18px;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--emerald);
  transition: width 0.35s ease;
}

.progress-fill[data-level="warn"] {
  background: var(--amber);
}

.progress-fill[data-level="danger"] {
  background: var(--red);
}

.progress-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-dim);
}

.sub-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.sub-metric {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 4px;
}

.metric-label {
  font-size: 11px;
  color: var(--text-dim);
}

.metric-value {
  font-size: 17px;
  font-weight: 600;
}

.metric-note {
  font-size: 11px;
  color: var(--text-muted);
}

.quota-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.quota-footer strong {
  color: var(--text);
  font-weight: 500;
}

/* 节点健康卡 */
.endpoint-list {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.endpoint-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: grid;
  gap: 8px;
}

.endpoint-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.endpoint-name {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.proto-tag {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.endpoint-state {
  font-size: 12px;
  color: var(--emerald);
}

.endpoint-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
}

.sub-sync-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}

.sub-sync-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.sub-sync-note {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* 三端订阅区 */
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 4px 0 0;
  font-size: 18px;
  font-weight: 600;
}

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

.sub-rows {
  display: grid;
  gap: 10px;
}

.sub-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.sub-client {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.row-num {
  font-size: 12px;
  color: var(--text-dim);
}

.platform-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sub-client h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.sub-client p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.status-pill i {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--text-dim);
}

.status-pill[data-state="ready"] {
  border-color: var(--emerald-border);
  background: var(--emerald-dim);
  color: var(--emerald);
}

.status-pill[data-state="ready"] i {
  background: var(--emerald);
}

.status-pill[data-state="error"] {
  border-color: rgba(239, 68, 68, 0.35);
  background: var(--red-dim);
  color: var(--red);
}

.status-pill[data-state="error"] i {
  background: var(--red);
}

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

/* 可选本机 Clash 控制器 */
.clash-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.clash-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.clash-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.clash-sub {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

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

.secret-input,
.node-select {
  min-height: 38px;
  padding: 0 10px;
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
}

.clash-live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* 二维码弹窗 */
.qr-dialog {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 20px;
  max-width: min(360px, calc(100vw - 32px));
  width: 100%;
}

.qr-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

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

.dialog-head h3 {
  margin: 4px 0 0;
  font-size: 16px;
}

.qr-frame {
  display: grid;
  place-items: center;
  padding: 16px;
  background: #ffffff;
  border-radius: 8px;
  margin-bottom: 12px;
}

.qr-frame svg,
.qr-frame img {
  width: 220px;
  height: 220px;
  display: block;
}

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

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

  .sub-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .row-actions .btn {
    flex: 1 1 auto;
    min-height: 44px;
  }
}
