:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --card: #fff;
  --text: #1a1d26;
  --muted: #5c6370;
  --border: #e2e4e9;
  --primary: #3b5bdb;
  --primary-hover: #2d4ac4;
  --danger: #c62828;
  --success: #2e7d32;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.login-body {
  min-height: 100vh;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  padding: 8px 12px;
}

button:hover:not(:disabled) {
  border-color: #c5cad3;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  padding: 8px 12px;
  text-decoration: none;
  font-size: 13px;
}

.button-link:hover {
  border-color: #c5cad3;
}

button.primary {
  width: 100%;
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 91, 219, 0.15);
}

textarea {
  min-height: 100px;
  resize: vertical;
}

label {
  display: grid;
  gap: 4px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

code {
  border-radius: 4px;
  background: #eef1f6;
  padding: 1px 5px;
  font-size: 0.92em;
}

/* —— 布局：首页 —— */
.page {
  width: min(1040px, calc(100% - 24px));
  margin: 0 auto;
  padding: 20px 0 40px;
}

.page-header {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.page-header-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.page-title {
  margin: 0 0 4px;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
  max-width: 42rem;
}

.page-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.status-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  font-size: 12px;
}

.chip span {
  color: var(--muted);
}

.chip strong {
  font-weight: 600;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.muted.sm {
  font-size: 12px;
}

.draft-hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 0 0 12px;
}

button.linkish {
  padding: 0;
  border: none;
  background: none;
  color: var(--accent, #0d6efd);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

button.linkish:hover {
  opacity: 0.85;
}

.create-page-head {
  margin-bottom: 12px;
}

.create-page-title {
  margin: 0 0 6px;
  font-size: 1.25rem;
}

.create-step-tabs {
  margin-bottom: 14px;
}

#tab-create .create-subpanel {
  margin-bottom: 0;
}

.create-form-stack {
  display: block;
}

.form-section-divider {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 10px;
}

.form-section-title {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.create-form-stack .batch-box,
.create-form-stack .probe-box {
  border: none;
  padding: 0;
  background: transparent;
}

/* —— 管理台壳 —— */
.app-shell {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  border-right: 1px solid var(--border);
  background: var(--card);
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.side-nav {
  display: grid;
  gap: 4px;
}

.side-nav a {
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  text-decoration: none;
  font-size: 13px;
}

.side-nav a:hover,
.side-nav a.active {
  background: #eef1f6;
  color: var(--primary);
}

.content {
  padding: 20px 20px 32px;
  max-width: 1100px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 1.25rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat-grid.compact {
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  margin-bottom: 0;
}

.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 10px 12px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.stat-card strong {
  display: block;
  margin-top: 2px;
  font-size: 1.1rem;
  font-weight: 700;
}

/* —— 卡片与表单 —— */
h1,
h2,
h3,
p {
  margin-top: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.05rem;
  font-weight: 700;
}

h3,
.block-title {
  margin: 0 0 6px;
  font-size: 0.95rem;
  font-weight: 700;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 16px;
  margin-bottom: 14px;
}

.form-card {
  display: grid;
  gap: 12px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.85fr);
  gap: 14px;
  align-items: start;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(0, 1.1fr);
  gap: 14px;
  align-items: start;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.inline-form input {
  min-width: 0;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.section-head h2 {
  margin-bottom: 0;
}

.toolbar {
  margin-bottom: 12px;
}

.message {
  min-height: 1.25em;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.message.error {
  color: var(--danger);
}

.message.success {
  color: var(--success);
}

.advanced {
  display: grid;
  gap: 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.advanced summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}

.advanced[open] summary {
  margin-bottom: 8px;
}

.probe-box,
.batch-box {
  display: grid;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: #fafbfc;
}

button.primary.ghost {
  width: auto;
  justify-self: start;
  background: var(--card);
  color: var(--primary);
  border-color: var(--primary);
}

button.primary.ghost:hover:not(:disabled) {
  background: #f0f3ff;
}

.toolbar-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.filter-label {
  display: flex;
  gap: 6px;
  align-items: center;
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.filter-label select {
  width: auto;
  min-width: 7rem;
}

.remote-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.95fr);
  gap: 14px;
  align-items: start;
}

.remote-detail {
  display: grid;
  gap: 10px;
}

.list {
  display: grid;
  gap: 8px;
}

.schedule-panel {
  margin: 12px 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8f9fb;
}

.schedule-option {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  margin: 10px 0 0;
  font-weight: 500;
  cursor: pointer;
}

.schedule-inline {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-weight: 400;
}

.schedule-inline input[type="number"] {
  width: 4.5rem;
}

.schedule-inline input[type="number"]#groupCheckInterval {
  width: 5.5rem;
}

.daily-times-box {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.daily-times-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.daily-time-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  font-size: 13px;
}

.daily-time-remove {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0 4px;
  line-height: 1;
  font-size: 16px;
}

.daily-time-remove:hover {
  color: var(--danger);
}

.schedule-preview {
  margin: 10px 0 0;
}

.selected-probe,
.probe-row,
.site-row,
.event-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 10px;
}

.probe-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  margin: 10px 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8f9fb;
}

.probe-toolbar.hidden {
  display: none;
}

.probe-toolbar-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

.probe-pick-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  min-width: 0;
}

.probe-pick-row input {
  margin-top: 3px;
  flex-shrink: 0;
}

.probe-pick-row span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.probe-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.probe-row-added {
  opacity: 0.72;
  background: #f5f7fa;
}

.selected-probe {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.site-row {
  display: grid;
  gap: 6px;
}

.row-title {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.row-title strong {
  word-break: break-word;
  font-size: 14px;
}

.event-row pre {
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
}

.remote-detail pre,
.health-card pre {
  max-height: 280px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
  color: var(--text);
  padding: 10px;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  background: #eef1f6;
  color: #3d4f6f;
}

.tag.warn {
  background: #fff8e6;
  color: #8a6d1b;
}

.tag.error {
  background: #fdecea;
  color: var(--danger);
}

.tag.accent {
  background: #e8f4fd;
  color: #1565c0;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.item-actions button {
  font-size: 12px;
  padding: 6px 10px;
}

.user-actions {
  align-items: stretch;
}

.empty {
  color: var(--muted);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

/* —— 标签页 —— */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  border-bottom: 1px solid var(--border);
}

.tabs a {
  display: inline-block;
  padding: 8px 14px;
  margin-bottom: -1px;
  border: 1px solid transparent;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.tabs a:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.03);
}

.tabs a.active {
  color: var(--primary);
  background: var(--card);
  border-color: var(--border);
  border-bottom-color: var(--card);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.tab-panel .card:last-child {
  margin-bottom: 0;
}

.tab-panel-narrow {
  max-width: 760px;
}

.tab-panel-probes {
  max-width: 1080px;
}

.probe-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

.probe-presets-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.probe-presets button.ghost {
  width: auto;
}

.check-log-card {
  margin-top: 0.75rem;
}

.check-log-pre {
  margin: 0;
  padding: 0.85rem 1rem;
  max-height: 22rem;
  overflow: auto;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.check-log-pre.empty {
  opacity: 0.65;
}

.speedtest-report {
  margin-top: 12px;
  border: 1px solid var(--border);
}

.speedtest-report-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.speedtest-site {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
  overflow: hidden;
}

.speedtest-site-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.speedtest-url {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  word-break: break-all;
  flex: 1 1 200px;
}

.speedtest-site-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.speedtest-site-badge.ok {
  color: var(--success);
  background: #e8f5e9;
}

.speedtest-site-badge.fail {
  color: var(--danger);
  background: #ffebee;
}

.speedtest-site-badge.pending {
  color: #6d4c00;
  background: #fff8e1;
}

.speedtest-metric {
  font-size: 12px;
  color: var(--muted);
}

.speedtest-note {
  margin: 0;
  padding: 8px 14px 0;
}

.speedtest-table-wrap {
  overflow-x: auto;
}

.speedtest-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--card);
}

.speedtest-table th,
.speedtest-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.speedtest-table th {
  background: #f0f2f5;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
}

.speedtest-table tbody tr:hover {
  background: #f8f9fb;
}

.speedtest-row-fail {
  background: #fff5f5;
}

.speedtest-rt {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.speedtest-badge {
  display: inline-block;
  min-width: 48px;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 12px;
  text-align: center;
  font-weight: 600;
}

.speedtest-badge.ok {
  color: #fff;
  background: #43a047;
}

.speedtest-badge.fail {
  color: #fff;
  background: #e53935;
}

.speedtest-badge.pending {
  color: #5c6370;
  background: #eceff1;
}

.speedtest-empty {
  text-align: center;
  color: var(--muted);
  padding: 20px !important;
}

.probe-quota-hint {
  margin: 0;
}

.probe-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.probe-section-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.probe-section-head .block-title {
  margin: 0;
}

.probe-isp-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 4px;
}

.probe-isp-filter {
  width: auto;
  padding: 5px 12px;
  font-size: 13px;
  border-radius: 999px;
}

.probe-isp-filter.active {
  border-color: var(--primary);
  background: #eef2ff;
  color: var(--primary);
  font-weight: 600;
}

.probe-tile-board {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 10px;
  min-height: 120px;
  max-height: min(42vh, 380px);
  overflow: auto;
}

#selectedProbes.probe-tile-board:not(.empty) {
  max-height: min(28vh, 220px);
}

.probe-tile-board.empty {
  padding: 14px 16px;
  color: var(--muted);
  background: #fafbfc;
  text-align: center;
}

.probe-tile-grid {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
}

@media (max-width: 900px) {
  .probe-tile-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .probe-tile-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* 覆盖全局 label { display: grid; width 继承 }，避免一排只显示一个 */
.probe-tile-grid > label.probe-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: auto;
  min-width: 0;
  max-width: none;
  margin: 0;
  min-height: 76px;
  padding: 8px 6px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
  cursor: pointer;
  user-select: none;
  text-align: center;
  font-weight: 500;
}

.probe-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 76px;
  padding: 8px 6px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
  cursor: pointer;
  user-select: none;
  text-align: center;
}

.probe-tile:hover {
  border-color: #c5d4f7;
  background: #f4f7ff;
}

.probe-tile.is-selected {
  border-color: #93b4f5;
  background: #eef3ff;
}

.probe-tile.is-added {
  opacity: 0.65;
  cursor: default;
}

.probe-tile input[type="checkbox"] {
  position: absolute;
  top: 6px;
  left: 6px;
  margin: 0;
}

.probe-tile-label {
  width: 100%;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  word-break: keep-all;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.probe-tile-grid > label.probe-tile input[type="checkbox"] {
  width: auto;
}

.probe-tile .probe-isp-badge {
  font-size: 10px;
  padding: 1px 6px;
}

.probe-tile-mark {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 10px;
  color: var(--muted);
}

.probe-tile-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.probe-tile-remove:hover {
  color: var(--danger);
}

.probe-pager {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.probe-pager.hidden {
  display: none;
}

.probe-pager-info {
  font-size: 12px;
  color: var(--muted);
}

.probe-pager button.ghost {
  width: auto;
}

.probe-isp-badge {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
}

.probe-isp-badge.isp-dx {
  background: #e8f4ff;
  color: #1565c0;
}

.probe-isp-badge.isp-lt {
  background: #fce8ec;
  color: #c62828;
}

.probe-isp-badge.isp-yd {
  background: #e8f5e9;
  color: #2e7d32;
}

.probe-isp-badge.isp-other {
  background: #f0f0f0;
  color: var(--muted);
}

/* —— 登录 —— */
.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: min(380px, 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 24px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.login-form {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .side-nav {
    display: flex;
    flex: 1;
    gap: 4px;
  }

  .grid,
  .remote-grid,
  .admin-grid,
  .stat-grid,
  .stat-grid.compact,
  .two-col {
    grid-template-columns: 1fr;
  }

  .page-header-top {
    flex-direction: column;
  }

  .inline-form {
    flex-direction: column;
    align-items: stretch;
  }
}
