:root {
  --bg: #f3f5f9;
  --surface: #fff;
  --surface-muted: #f8f9fc;
  --border: #dfe5ef;
  --border-strong: #cbd5e3;
  --text: #1d2b42;
  --text-muted: #68768b;
  --primary: #315fc9;
  --primary-hover: #2a52ad;
  --ok: #196544;
  --ok-bg: #e0f2e9;
  --warn: #8a5512;
  --warn-bg: #fff0dc;
  --danger: #a42b32;
  --danger-bg: #fce6e5;
  --neutral: #55637a;
  --neutral-bg: #edf0f5;
  color: var(--text);
  background: var(--bg);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
h1, h2, h3, p, dl, dd { margin: 0; }
h1 { font-size: 20px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
a { color: inherit; text-decoration: none; }

/* 顶部导航 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  height: 52px; padding: 0 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-size: 15px; font-weight: 700; white-space: nowrap; }
.topnav { display: flex; align-self: stretch; gap: 4px; flex: 1; }
.topnav a {
  display: flex; align-items: center; padding: 0 12px;
  color: var(--text-muted); border-bottom: 2px solid transparent; border-top: 2px solid transparent;
  white-space: nowrap;
}
.topnav a:hover { color: var(--text); }
.topnav a[aria-current=page] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

main { max-width: 1320px; margin: 0 auto; padding: 20px 24px 40px; }
.panel { padding: 18px 20px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.page-head, .list-heading, .buttons, .control-head, .pager {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.page-head { margin-bottom: 16px; }
.buttons { justify-content: flex-start; flex-wrap: wrap; gap: 8px; }
.muted { color: var(--text-muted); font-size: 13px; }

/* 按钮与表单 */
button, input, select, textarea {
  padding: 7px 12px; color: inherit; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 6px; font: inherit; font-size: 13px;
}
button { cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { background: var(--surface-muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary, .download-button { color: var(--surface); background: var(--primary); border-color: var(--primary); }
button.primary:hover:not(:disabled), .download-button:hover { background: var(--primary-hover); }
button.danger { color: var(--danger); border-color: #dc9ca1; }
button.danger:hover:not(:disabled) { background: var(--danger-bg); }
button.danger-solid { color: #fff; background: var(--danger); border-color: var(--danger); }
button.danger-solid:hover:not(:disabled) { background: #8c2329; }
button.small { padding: 4px 10px; font-size: 12px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid #b3caff; outline-offset: 1px;
}
label { display: block; font-size: 13px; }
.field { margin-bottom: 14px; }
.field input, .field select, .field textarea { display: block; width: 100%; margin-top: 4px; }
.field small { display: block; margin-top: 4px; color: var(--text-muted); font-size: 12px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
details { margin-bottom: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
summary { margin-bottom: 10px; color: var(--text-muted); font-size: 13px; cursor: pointer; }
details:not([open]) summary { margin-bottom: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* 状态标签 */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 11px;
  color: var(--ok); background: var(--ok-bg); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.error { color: var(--danger); background: var(--danger-bg); }
.badge.neutral { color: var(--neutral); background: var(--neutral-bg); }

/* 采集控制 */
.status-line { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; min-width: 0; }
#action { color: var(--text-muted); font-size: 13px; }
.control #schedule { margin-top: 10px; }
#reason:not(:empty) {
  margin-top: 10px; padding: 8px 12px; color: var(--warn); background: var(--warn-bg);
  border-radius: 6px; font-size: 13px; overflow-wrap: anywhere;
}
#verification { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
#verification .buttons { margin-top: 6px; }
#verification input { width: 180px; }
#verification .muted { margin-top: 6px; }

/* 采集范围 */
.ranges { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-bottom: 16px; }
.range { padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; min-width: 0; }
.range-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.range h2 { font-size: 13px; font-weight: 600; }
.range strong { display: block; margin: 8px 0 0; font-size: 24px; font-weight: 650; line-height: 1.3; }
.range p { color: var(--text-muted); font-size: 12px; overflow-wrap: anywhere; }

/* 列表 */
.filters { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.search { width: 280px; }
.search input { width: 100%; }
.table-scroll { margin-top: 14px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: left; }
th {
  padding: 9px 10px; color: var(--text-muted); background: var(--surface-muted);
  border-bottom: 1px solid var(--border); font-size: 12px; font-weight: 500; white-space: nowrap;
}
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-muted); }
td small { display: block; color: var(--text-muted); font-size: 12px; }
td.empty { padding: 36px 16px; color: var(--text-muted); text-align: center; }
td.nowrap, #events td { white-space: nowrap; }
td.row-actions { width: 1%; white-space: nowrap; }
td.row-actions button + button { margin-left: 6px; }
.pager { justify-content: flex-end; margin-top: 14px; }
#page { color: var(--text-muted); font-size: 13px; }
.audit-detail { color: var(--text-muted); font-size: 12px; overflow-wrap: anywhere; }
#manageBody > .table-scroll:first-child { margin-top: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }

/* 提示 */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 20; transform: translateX(-50%);
  max-width: min(640px, calc(100vw - 32px)); padding: 9px 16px;
  color: #fff; background: #1d2b42; border-radius: 8px; box-shadow: 0 8px 24px #1d2b4240;
  font-size: 13px; overflow-wrap: anywhere;
}
.toast:empty { display: none; }
.toast[data-tone=error] { background: var(--danger); }
.alert:empty { display: none; }
.alert { margin-bottom: 12px; padding: 8px 12px; color: var(--danger); background: var(--danger-bg); border-radius: 6px; font-size: 13px; overflow-wrap: anywhere; }
.alert[data-tone=ok] { color: var(--ok); background: var(--ok-bg); }

/* 弹窗 */
dialog {
  width: min(520px, 94vw); max-height: 90vh; padding: 0; color: inherit;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: 0 16px 48px #1d2b4233;
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: #1d2b4266; }
dialog.wide { width: min(860px, 96vw); height: min(680px, 90vh); }
dialog > form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.dialog-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.dialog-head h2 { font-size: 16px; }
.dialog-head p { margin-top: 2px; color: var(--text-muted); font-size: 12px; }
.dialog-body { flex: 1; min-height: 0; padding: 16px 20px; overflow: auto; }
.dialog-body > .field:last-child, .dialog-body > .check:last-child, .dialog-body > details:last-child { margin-bottom: 0; }
.dialog-note { margin-bottom: 14px; color: var(--text-muted); font-size: 13px; white-space: pre-line; }
.dialog-foot {
  display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px;
  background: var(--surface-muted); border-top: 1px solid var(--border); border-radius: 0 0 10px 10px;
}
.tabs { display: flex; gap: 2px; padding: 0 20px; border-bottom: 1px solid var(--border); }
.tabs button {
  padding: 9px 12px; color: var(--text-muted); background: none;
  border: 0; border-bottom: 2px solid transparent; border-radius: 0;
}
.tabs button:hover:not(:disabled) { color: var(--text); background: none; }
.tabs button[aria-selected=true] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.kv { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 6px 12px; margin-bottom: 16px; font-size: 13px; }
.kv dt { color: var(--text-muted); }
.kv dd { overflow-wrap: anywhere; }
.action-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 0; border-top: 1px solid var(--border);
}
.permission-toggle { display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0; white-space: nowrap; }
.action-row p { color: var(--text-muted); font-size: 12px; }

/* 登录 */
.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px 16px; }
.login-card { width: min(380px, 100%); padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.login-card h1 { margin-top: 4px; margin-bottom: 20px; }
.login-card .brand { color: var(--text-muted); font-size: 13px; font-weight: 600; }
.login-card input { display: block; width: 100%; margin: 4px 0 14px; }
.login-card button { width: 100%; }
#loginError { min-height: 20px; margin-bottom: 8px; color: var(--danger); font-size: 13px; }

@media (max-width: 720px) {
  .topbar { gap: 8px; padding: 0 14px; }
  .topnav a { padding: 0 8px; }
  main { padding: 14px 14px 32px; }
  .panel { padding: 14px; }
  .control-head, .list-heading, .page-head { align-items: flex-start; flex-direction: column; }
  .filters, .search { width: 100%; }
}

/* 通知配置与窄屏导航 */
#telegramForm .buttons { margin: 12px 0; }
@media (max-width: 540px) {
  .topbar { height: auto; min-height: 52px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .topnav { order: 3; width: 100%; flex-basis: 100%; min-height: 36px; }
  .topbar > button { margin-left: auto; }
}

.release-notes { white-space: pre-wrap; overflow-wrap: anywhere; margin: 12px 0; }
.download-page { max-width: 680px; }
.download-button { display: inline-block; padding: 7px 12px; border-radius: 6px; }
.release-download-link { color: var(--primary); text-decoration: underline; }
.installer-drop {
  margin-top: 4px; padding: 12px; border: 1px dashed var(--border-strong);
  border-radius: 6px; background: var(--surface-muted);
}
.installer-drop.is-dragging { border-color: var(--primary); background: var(--surface); }
.installer-drop input { min-width: 0; padding: 0; border: 0; background: transparent; }
#manageDialog progress { width: 100%; accent-color: var(--primary); }
#manageDialog li { overflow-wrap: anywhere; }
#releases td:last-child { white-space: nowrap; }

.topnav { min-width: 0; overflow-x: auto; }
#orders td { min-width: 130px; overflow-wrap: anywhere; }

.orders-empty thead { display: none; }
.orders-empty, .orders-empty tbody, .orders-empty tr, .orders-empty td { display: block; width: 100%; }
@media (max-width: 540px) {
  .topnav { flex-wrap: wrap; }
}

dialog.remote-ledger { width: min(1200px, calc(100vw - 24px)); }
.remote-ledger .dialog-body, .remote-ledger .filters, .remote-ledger .field { min-width: 0; }
.remote-ledger .filters { flex-wrap: wrap; }
.remote-ledger select { max-width: 100%; }
.remote-ledger .table-scroll { max-width: 100%; }
.remote-ledger td { white-space: normal; overflow-wrap: anywhere; }
.remote-ledger td:nth-child(2) { min-width: 180px; }
.remote-ledger .dialog-head h2 { overflow-wrap: anywhere; }
.remote-ledger [hidden] { display: none; }

.permission-field { display: block; margin: 14px 0; }
.permission-field small { display: block; margin-top: 4px; color: var(--text-muted); }
