:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  background: #0b1220;
  color: #e5edf8;

  --bg: #0b1220;
  --surface: rgba(15, 23, 42, .94);
  --surface-solid: #101a2e;
  --border: #29364d;
  --border-strong: #3b4b68;
  --text: #e5edf8;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-strong: #2563eb;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: .8rem;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at top, #14264d, var(--bg) 46%) fixed; }
h1, h2, p { margin-top: 0; }
button, input { font: inherit; }
button { cursor: pointer; }
.mono { font-family: "JetBrains Mono", Consolas, monospace; }
.muted { color: var(--muted); font-size: .8rem; }

/* ---------- 头部 ---------- */
.app-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: 1.1rem clamp(1rem, 4vw, 3rem); border-bottom: 1px solid var(--border); background: rgba(13, 20, 36, .92); backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: .9rem; }
.brand-mark { display: grid; place-items: center; width: 2.8rem; height: 2.8rem; border-radius: .8rem; background: linear-gradient(135deg, #2563eb, #0ea5e9); font-weight: 800; font-size: .95rem; color: white; letter-spacing: .02em; }
.eyebrow { margin-bottom: .2rem; color: #60a5fa; font-size: .74rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
h1 { margin-bottom: 0; font-size: 1.25rem; }
.header-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .6rem; }
#lastRefreshTime { min-width: 8.5rem; text-align: right; }

/* ---------- 开关 ---------- */
.switch { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track { position: relative; width: 2.1rem; height: 1.15rem; border-radius: 999px; background: var(--border-strong); transition: background .15s ease; flex: none; }
.switch-track::after { content: ""; position: absolute; top: .14rem; left: .16rem; width: .87rem; height: .87rem; border-radius: 50%; background: #cbd5e1; transition: transform .15s ease; }
.switch input:checked + .switch-track { background: var(--accent-strong); }
.switch input:checked + .switch-track::after { transform: translateX(.93rem); background: white; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-label { font-size: .85rem; color: #cbd5e1; }

/* ---------- 徽标与按钮 ---------- */
.status-badge { display: inline-flex; align-items: center; min-height: 2rem; padding: .3rem .75rem; border-radius: 999px; background: #78350f; color: #fde68a; font-size: .85rem; }
.status-badge.is-online { background: #064e3b; color: #a7f3d0; }
.version-badge { display: inline-flex; align-items: center; align-self: center; padding: .2rem .65rem; border-radius: 999px; border: 1px solid var(--border); background: rgba(30, 41, 59, .55); color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .72rem; letter-spacing: .04em; white-space: nowrap; }
.icon-button, .primary-button, .secondary-button, .danger-button, .danger-outline-button, .ghost-button { min-height: 2.4rem; padding: .5rem .85rem; border: 1px solid transparent; border-radius: .6rem; }
.icon-button { min-width: 2.4rem; padding: .5rem; border-color: var(--border-strong); background: var(--surface-solid); color: var(--text); font-size: 1.05rem; line-height: 1; }
.secondary-button, .danger-outline-button, .ghost-button { border-color: var(--border-strong); background: #1a2540; color: #dbe4f3; }
.ghost-button { border-style: dashed; }
.danger-outline-button { border-color: #7f1d1d; color: #fca5a5; }
.danger-outline-button:hover { background: #450a0a; }
.primary-button { background: var(--accent-strong); color: white; }
.danger-button { background: #991b1b; color: white; }
.primary-button:hover { background: #1d4ed8; }
.secondary-button:hover, .icon-button:hover { border-color: #64748b; }
button:disabled { cursor: not-allowed; opacity: .55; }
.button-small { min-height: 1.9rem; padding: .25rem .6rem; font-size: .8rem; border-radius: .5rem; border: 1px solid transparent; }
.button-small.secondary-button, .button-small.danger-button { min-height: 1.9rem; }

/* ---------- 布局与页签 ---------- */
main { width: min(1220px, calc(100% - 2rem)); margin: 1.5rem auto 3rem; }
.tabs { display: flex; gap: .4rem; margin-bottom: 1.1rem; padding: .35rem; border: 1px solid var(--border); border-radius: .9rem; background: var(--surface-solid); overflow-x: auto; }
.tab { flex: 1; min-width: 7.5rem; padding: .7rem 1rem; border: 0; border-radius: .6rem; background: transparent; color: var(--muted); font-weight: 600; }
.tab:hover { color: #cbd5e1; }
.tab.is-active { background: var(--accent-strong); color: white; }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* ---------- 指标卡 ---------- */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: .9rem; margin-bottom: 1rem; }
.metric-card, .content-section { padding: 1.05rem 1.15rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 12px 30px rgba(0, 0, 0, .22); }
.metric-card { display: grid; gap: .3rem; align-content: start; }
.metric-card--wide { grid-column: span 2; }
.metric-card span { color: var(--muted); font-size: .82rem; }
.metric-card strong { font-size: 1.55rem; line-height: 1.2; word-break: break-all; }
.metric-card small { color: #64748b; font-size: .75rem; }
.metric-ok { color: var(--ok); }
.metric-bad { color: var(--danger); }

.progress { height: .5rem; margin-top: .2rem; border-radius: 999px; background: #1e293b; overflow: hidden; }
.progress-bar { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #2563eb, #38bdf8); transition: width .3s ease; }
.progress-bar.is-warning { background: linear-gradient(90deg, #d97706, #fbbf24); }
.progress-bar.is-critical { background: linear-gradient(90deg, #b91c1c, #f87171); }

/* ---------- 内容区块 ---------- */
.content-section { margin-bottom: 1rem; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .9rem; }
.section-heading h2 { margin-bottom: .25rem; font-size: 1.05rem; }
.section-heading p { margin-bottom: 0; color: var(--muted); font-size: .85rem; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .68rem .75rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; vertical-align: middle; }
th { color: #93c5fd; font-size: .8rem; font-weight: 600; }
tbody tr:hover { background: rgba(59, 130, 246, .06); }
.empty-state { padding: 2rem; color: var(--muted); text-align: center; white-space: normal; }
.ipv6-cell { font-family: "JetBrains Mono", Consolas, monospace; font-size: .84rem; word-break: break-all; white-space: normal; }
.actions-cell { display: flex; gap: .35rem; flex-wrap: wrap; }
.standby-row { opacity: .72; }
.sort-button { padding: 0; border: 0; background: none; color: inherit; font-size: inherit; font-weight: inherit; }
.sort-button::after { content: "↕"; margin-left: .3rem; color: #475569; font-size: .75rem; }
.sort-button.is-sorted::after { color: #93c5fd; }
.sort-button[data-dir="asc"]::after { content: "↑"; }
.sort-button[data-dir="desc"]::after { content: "↓"; }
.table-footnote { margin: .6rem 0 0; color: var(--muted); font-size: .8rem; }

.pill { display: inline-block; padding: .18rem .6rem; border-radius: 999px; background: #27354f; color: #b6c4dc; font-size: .74rem; }
.pill--ok { background: #064e3b; color: #a7f3d0; }
.pill--warn { background: #78350f; color: #fde68a; }

/* ---------- 键值网格 ---------- */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: .55rem 1.4rem; margin: 0; }
.kv-item { display: flex; justify-content: space-between; gap: 1rem; padding: .45rem .2rem; border-bottom: 1px dashed var(--border); }
.kv-item dt { color: var(--muted); font-size: .84rem; flex: none; }
.kv-item dd { margin: 0; font-family: "JetBrains Mono", Consolas, monospace; font-size: .84rem; text-align: right; word-break: break-all; }

/* ---------- 连接信息与代码块 ---------- */
.connection-value { font-family: "JetBrains Mono", Consolas, monospace; color: #7dd3fc; word-break: break-all; white-space: normal; }
.connection-hint { color: var(--muted); white-space: normal; min-width: 14rem; font-size: .84rem; }
.code-block { margin: 0; padding: 1rem 1.1rem; border: 1px solid var(--border); border-radius: .7rem; background: #0a1120; color: #a5f3fc; font-family: "JetBrains Mono", Consolas, monospace; font-size: .8rem; line-height: 1.7; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }

/* ---------- 配置表单 ---------- */
.config-form { display: grid; gap: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; }
.field { display: grid; gap: .4rem; align-content: start; }
.field--full { grid-column: 1 / -1; }
.field input { width: 100%; padding: .65rem .8rem; border: 1px solid var(--border-strong); border-radius: .6rem; background: #0d1526; color: #f8fafc; }
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.field small, .check-field { color: var(--muted); font-size: .78rem; line-height: 1.5; }
.field.is-disabled { opacity: .5; }
.input-row { display: flex; gap: .5rem; align-items: stretch; }
.input-row input { flex: 1 1 auto; min-width: 0; }
.input-row .secondary-button { flex: 0 0 auto; white-space: nowrap; }
.check-field { display: flex; align-items: center; gap: .5rem; font-size: .88rem; color: #cbd5e1; }
.check-field input { width: 1rem; height: 1rem; accent-color: var(--accent-strong); }
.form-actions { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
#saveMessage { color: #93c5fd; font-size: .85rem; }
.dirty-badge { display: inline-block; padding: .25rem .7rem; border-radius: 999px; background: #78350f; color: #fde68a; font-size: .78rem; }
.restart-banner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .9rem 1.1rem; border: 1px solid #92400e; border-radius: var(--radius); background: #451a03; color: #fde68a; font-size: .88rem; flex-wrap: wrap; }
.restart-banner[hidden] { display: none; }
.restart-banner-text { display: grid; gap: .25rem; }
.restart-banner .primary-button { flex: 0 0 auto; }
.token-create { display: flex; gap: .5rem; align-items: end; }
.token-create .field { min-width: 14rem; }

.segmented-control { display: flex; flex-wrap: wrap; gap: .75rem; margin: 0 0 .9rem; padding: 0; border: 0; }
.segmented-control label { position: relative; }
.segmented-control input { position: absolute; opacity: 0; }
.segmented-control span { display: block; padding: .65rem 1.1rem; border: 1px solid var(--border-strong); border-radius: .65rem; color: #cbd5e1; }
.segmented-control input:checked + span { border-color: #60a5fa; background: var(--accent-strong); color: white; }
.segmented-control input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 模态框 ---------- */
.modal-root { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 1rem; }
.modal-root[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2, 6, 16, .7); backdrop-filter: blur(3px); }
.modal { position: relative; width: min(480px, 100%); max-height: calc(100vh - 4rem); display: grid; grid-template-rows: auto auto auto; gap: .4rem; padding: 1.1rem 1.25rem; border: 1px solid var(--border-strong); border-radius: 1rem; background: var(--surface-solid); box-shadow: 0 24px 60px rgba(0, 0, 0, .5); overflow-y: auto; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.modal-header h2 { margin: 0; font-size: 1.05rem; }
.modal-body { display: grid; gap: .8rem; padding: .4rem 0; }
.modal-body .field input { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: .55rem; flex-wrap: wrap; }
.modal-error { margin: 0; color: var(--danger); font-size: .84rem; }
.confirm-text { margin: 0; color: #cbd5e1; line-height: 1.6; white-space: normal; }

/* ---------- 登录页 ---------- */
body.is-logged-out > .app-header,
body.is-logged-out > main,
body.is-logged-out > .notification-region { display: none; }
.login-overlay { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 1rem; background: radial-gradient(circle at top, #14264d, var(--bg) 46%); }
.login-overlay[hidden] { display: none; }
.login-card { width: min(400px, 100%); display: grid; gap: 1rem; padding: 1.75rem 1.6rem; border: 1px solid var(--border-strong); border-radius: 1rem; background: var(--surface-solid); box-shadow: 0 24px 60px rgba(0, 0, 0, .5); }
.login-card .brand { margin-bottom: .25rem; }
.login-card h1 { font-size: 1.2rem; }
.login-card .primary-button { padding: .75rem; }
.login-hint { color: var(--muted); font-size: .78rem; text-align: center; }

/* ---------- 通知 ---------- */
.notification-region { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; width: min(360px, calc(100% - 2rem)); z-index: 50; }
.toast { padding: .75rem 1rem; border: 1px solid var(--border-strong); border-radius: .65rem; background: #12203c; color: #dbe4f3; font-size: .86rem; box-shadow: 0 10px 28px rgba(0, 0, 0, .35); word-break: break-all; }
.toast--success { border-color: #166534; }
.toast--error { border-color: #b91c1c; background: #3f0d0d; color: #fecaca; }

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

@media (max-width: 760px) {
  .app-header { align-items: stretch; flex-direction: column; }
  #lastRefreshTime { display: none; }
  .metric-card--wide { grid-column: span 1; }
  .section-heading { flex-direction: column; }
  .kv-item { flex-direction: column; gap: .15rem; }
  .kv-item dd { text-align: left; }
}
