:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
code { font-family: var(--mono); font-size: 12.5px; background: #eef2f7; padding: 1px 5px; border-radius: 4px; }

/* Login */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top right, #dbeafe, transparent 45%), var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 2px 0 0; }
.login-hint { margin-top: 20px; text-align: center; font-size: 12px; color: var(--muted); }

/* Brand */
.brand-row { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--muted); }

/* App Layout */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.sidebar-header .brand-row { margin-bottom: 24px; padding: 0 6px; }

.nav-list { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  border: none;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface-alt); color: var(--text); }
.nav-item.active { background: #eff6ff; color: var(--primary); font-weight: 600; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #334155;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-green { background: var(--success); box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.16); }

.user-row { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; }

.main-content {
  flex: 1;
  min-width: 0;
  padding: 24px 28px;
  max-width: 1440px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-header h2 { margin: 0 0 4px; font-size: 20px; }
.page-header p { margin: 0; font-size: 13px; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-header h3 { margin: 0; font-size: 15px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 12.5px; color: var(--muted); }
.kpi-value { font-size: 26px; font-weight: 700; margin: 6px 0 4px; letter-spacing: -0.5px; }
.kpi-sub { font-size: 12px; color: var(--muted); }

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

/* Status distribution */
.status-dist { display: flex; flex-direction: column; gap: 10px; }
.dist-row { display: grid; grid-template-columns: 44px 1fr 70px; align-items: center; gap: 10px; font-size: 13px; }
.dist-bar-track { height: 10px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.dist-bar-fill { height: 100%; border-radius: 999px; }
.fill-2xx { background: #16a34a; }
.fill-3xx { background: #0284c7; }
.fill-4xx { background: #d97706; }
.fill-5xx { background: #dc2626; }

.kv-list { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; margin: 0; font-size: 13px; }
.kv-list dt { color: var(--muted); }
.kv-list dd { margin: 0; word-break: break-all; }

/* Inputs & Buttons */
input[type="text"],
input[type="password"],
input[type="url"],
input[type="number"],
input[type="search"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: #fff; border-color: #cbd5e1; color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-alt); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-alt); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.file-btn { cursor: pointer; }

.input-group { display: flex; gap: 8px; }
.input-group input { flex: 1; }

.form-stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; font-weight: 500; color: #334155; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.field-wide { grid-column: span 1; }

.inline-check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.inline-check input { width: auto; }

.methods-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  font-size: 12.5px;
  cursor: pointer;
  background: var(--surface-alt);
}
.chip-check input { width: auto; margin: 0; }

.divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.section-label { font-size: 12.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; }

/* Toolbar & Filter */
.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar .input-grow { flex: 1; min-width: 220px; }
.toolbar select { width: auto; min-width: 140px; }

.filter-grid {
  display: grid;
  grid-template-columns: 2fr repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.filter-actions { display: flex; gap: 8px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface-alt);
}
.data-table td {
  padding: 11px 10px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
.data-table tbody tr:hover { background: #f8fafc; }
.clickable-row { cursor: pointer; }
.col-actions { width: 170px; text-align: right; }
.actions-cell { display: flex; justify-content: flex-end; gap: 6px; }
.empty-cell { text-align: center; padding: 32px !important; color: var(--muted); }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-neutral { background: #f1f5f9; color: #475569; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-red { background: #fee2e2; color: #b91c1c; }

/* Toggle Switch */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  transition: background 0.15s;
}
.slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(16px); }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.pagination-btns { display: flex; align-items: center; gap: 10px; }

/* Alerts & Probe */
.alert { padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }

.probe-result {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  margin-top: 6px;
}
.probe-ok { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.probe-fail { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-lg { max-width: 680px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.icon-btn {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.code-block {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12.5px;
  overflow-x: auto;
  margin: 0 0 12px;
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.2);
  max-width: 360px;
}
.toast-success { background: #15803d; }
.toast-error { background: #b91c1c; }

@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-two { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .nav-list { flex-direction: row; flex-wrap: wrap; }
  .field-row, .field-row-3 { grid-template-columns: 1fr; }
}
