/* 分布式网络诊断平台 - 自定义样式 */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  line-height: 1.6;
}

/* 顶部导航 */
.navbar {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #fff;
  padding: 14px 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
}
.navbar .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.navbar-brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
}
.navbar-brand:hover { color: #bfdbfe; }
.navbar-nav a {
  color: #dbeafe;
  text-decoration: none;
  margin-left: 20px;
  font-size: .9rem;
}
.navbar-nav a:hover { color: #fff; }

/* 主容器 */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
}

/* 首页 Hero */
.hero {
  text-align: center;
  padding: 60px 20px 40px;
}
.hero h1 {
  font-size: 2rem;
  margin-bottom: 8px;
  color: #0f172a;
}
.hero p {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 32px;
}

/* 检测表单卡片 */
.detect-card {
  background: var(--card);
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 4px 20px rgba(0,0,0,.06);
  max-width: 600px;
  margin: 0 auto;
}
.detect-card label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: #334155;
}
.detect-card input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color .2s;
}
.detect-card input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
}
.detect-card .btn-detect {
  width: 100%;
  margin-top: 16px;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.detect-card .btn-detect:hover { background: var(--primary-dark); }
.detect-card .btn-detect:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

/* 节点信息 */
.node-info {
  margin-top: 16px;
  font-size: .85rem;
  color: var(--text-muted);
  text-align: center;
}

/* 错误提示 */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: .9rem;
}
.alert-danger {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}
.alert-warning {
  background: #fffbeb;
  color: var(--warning);
  border: 1px solid #fde68a;
}
.alert-success {
  background: #f0fdf4;
  color: var(--success);
  border: 1px solid #bbf7d0;
}

/* 加载动画 */
.loading {
  text-align: center;
  padding: 40px 20px;
}
.loading .spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading p { color: var(--text-muted); }

/* 报告页 */
.report-header {
  padding: 24px 0 16px;
}
.report-header h2 {
  font-size: 1.4rem;
  margin: 0 0 4px;
}
.report-meta {
  color: var(--text-muted);
  font-size: .85rem;
}

/* 综合结论卡片 */
.summary-card {
  background: var(--card);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 20px 24px;
  margin-bottom: 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.summary-card h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  color: var(--primary-dark);
}
.summary-card p {
  margin: 0;
  font-size: .95rem;
  line-height: 1.7;
}

/* 节点结果卡片 */
.node-result {
  background: var(--card);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
  border: 1px solid var(--border);
}
.node-result.reachable { border-left: 4px solid var(--success); }
.node-result.unreachable { border-left: 4px solid var(--danger); }

.node-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.node-name {
  font-weight: 700;
  font-size: 1rem;
}
.node-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: .75rem;
  font-weight: 600;
}
.tag-success { background: #dcfce7; color: var(--success); }
.tag-danger  { background: #fee2e2; color: var(--danger); }
.tag-warning { background: #fef3c7; color: var(--warning); }

/* 指标网格 */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.metric {
  text-align: center;
  padding: 10px;
  background: var(--bg);
  border-radius: 8px;
}
.metric .value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}
.metric .label {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.metric.warn .value { color: var(--warning); }
.metric.danger .value { color: var(--danger); }

/* 诊断文字 */
.node-diagnosis {
  font-size: .9rem;
  color: #475569;
  padding: 10px 14px;
  background: #f8fafc;
  border-radius: 6px;
  margin-top: 8px;
}

/* 折叠面板 */
details.raw-data {
  margin-top: 10px;
}
details.raw-data summary {
  cursor: pointer;
  font-size: .8rem;
  color: var(--text-muted);
  user-select: none;
}
details.raw-data pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  border-radius: 6px;
  font-size: .75rem;
  overflow-x: auto;
  margin-top: 8px;
  max-height: 300px;
  overflow-y: auto;
}

/* 分享链接 */
.share-box {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.share-box input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .85rem;
  background: var(--bg);
}
.share-box button {
  padding: 8px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: .85rem;
}

/* 延迟柱状图 */
.chart-container {
  background: var(--card);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.chart-bar-wrap {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 160px;
  padding: 10px 0;
}
.chart-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}
.chart-bar .bar {
  width: 100%;
  max-width: 48px;
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  position: relative;
  transition: height .5s ease;
}
.chart-bar .bar.warn { background: linear-gradient(180deg, #f59e0b, #d97706); }
.chart-bar .bar.danger { background: linear-gradient(180deg, #ef4444, #dc2626); }
.chart-bar .bar-val {
  font-size: .7rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.chart-bar .bar-label {
  font-size: .7rem;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: center;
  word-break: break-all;
}

/* 后台样式 */
.admin-layout {
  display: flex;
  min-height: 100vh;
}
.admin-sidebar {
  width: 200px;
  background: #1e293b;
  color: #cbd5e1;
  padding: 20px 0;
  flex-shrink: 0;
}
.admin-sidebar .brand {
  padding: 0 20px 20px;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  border-bottom: 1px solid #334155;
  margin-bottom: 12px;
}
.admin-sidebar a {
  display: block;
  padding: 10px 20px;
  color: #cbd5e1;
  text-decoration: none;
  font-size: .9rem;
}
.admin-sidebar a:hover, .admin-sidebar a.active {
  background: #334155;
  color: #fff;
}
.admin-content {
  flex: 1;
  padding: 24px;
  overflow-x: auto;
}
.admin-content h2 {
  margin-top: 0;
  font-size: 1.3rem;
}

/* 表格 */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.table th, .table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: .88rem;
}
.table th {
  background: #f1f5f9;
  font-weight: 600;
  color: #475569;
}
.table tr:last-child td { border-bottom: none; }
.table .actions a {
  margin-right: 8px;
  text-decoration: none;
  font-size: .82rem;
}

/* 按钮 */
.btn {
  display: inline-block;
  padding: 8px 18px;
  border-radius: 6px;
  font-size: .88rem;
  text-decoration: none;
  cursor: pointer;
  border: none;
  font-weight: 500;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: .8rem; }

/* 表单 */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: .88rem;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
}
.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--primary);
}

/* 分页 */
.pagination {
  margin-top: 16px;
  display: flex;
  gap: 6px;
}
.pagination a, .pagination span {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
  font-size: .85rem;
  color: var(--text);
}
.pagination .current {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* 登录页 */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
}
.login-card {
  background: #fff;
  padding: 36px;
  border-radius: 12px;
  width: 360px;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.login-card h2 {
  text-align: center;
  margin: 0 0 24px;
  color: #0f172a;
}

/* 页脚 */
.footer {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: .8rem;
}

/* 附加检测项（DNS/HTTP/TCP） */
.extra-detect {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
  padding: 10px 14px;
  background: #f8fafc;
  border-radius: 6px;
}
.extra-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
}
.extra-label {
  color: var(--text-muted);
  font-weight: 600;
}
.extra-val.ok { color: var(--success); font-weight: 600; }
.extra-val.fail { color: var(--danger); font-weight: 600; }

/* TCP 端口标签 */
.tcp-ports {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.tcp-port {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: .72rem;
  font-weight: 600;
}
.tcp-port.open { background: #dcfce7; color: var(--success); }
.tcp-port.closed { background: #f1f5f9; color: var(--text-muted); }

/* 路由路径可视化 */
.route-path {
  margin-top: 12px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 6px;
}
.route-title {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.route-hops {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.route-hop {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 8px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--border);
  min-width: 70px;
  text-align: center;
}
.route-hop.normal { border-left: 3px solid var(--success); }
.route-hop.slow { border-left: 3px solid var(--warning); }
.route-hop.loss { border-left: 3px solid var(--danger); }
.hop-num {
  font-size: .65rem;
  color: var(--text-muted);
  font-weight: 700;
}
.hop-host {
  font-size: .7rem;
  color: var(--text);
  word-break: break-all;
  max-width: 80px;
  font-family: monospace;
}
.hop-meta {
  font-size: .62rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.hop-arrow {
  color: var(--text-muted);
  font-size: .75rem;
}

/* 验证码 */
.captcha-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}
.captcha-row input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}
.captcha-img {
  height: 42px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--border);
}
.captcha-refresh {
  font-size: .8rem;
  color: var(--primary);
  cursor: pointer;
  white-space: nowrap;
}

/* 节点选择 */
.node-select {
  margin-top: 14px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.node-select-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: .85rem;
  font-weight: 600;
  color: #475569;
}
.select-all-label {
  font-weight: 400;
  font-size: .82rem;
  cursor: pointer;
  color: var(--text-muted);
}
.node-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.node-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: .82rem;
  transition: border-color .2s;
}
.node-checkbox:hover { border-color: var(--primary); }
.node-checkbox input { cursor: pointer; }
.node-cb-name { font-weight: 500; }
.node-cb-isp {
  font-size: .72rem;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 1px 5px;
  border-radius: 3px;
}

/* 最近检测目标 */
.recent-targets {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.recent-label {
  font-size: .8rem;
  color: var(--text-muted);
}
.recent-tag {
  display: inline-block;
  padding: 3px 10px;
  background: #eff6ff;
  color: var(--primary);
  border-radius: 12px;
  font-size: .78rem;
  cursor: pointer;
  transition: background .2s;
}
.recent-tag:hover { background: #dbeafe; }

/* 报告导出按钮 */
.export-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
}
.export-bar button {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: .85rem;
  cursor: pointer;
  border: none;
  font-weight: 500;
}
.btn-export-img {
  background: #16a34a;
  color: #fff;
}
.btn-export-img:hover { background: #15803d; }
.btn-print {
  background: #f1f5f9;
  color: #475569;
}
.btn-print:hover { background: #e2e8f0; }

/* 打印样式 */
@media print {
  .navbar, .footer, .export-bar, .share-box, details.raw-data, .btn { display: none !important; }
  .node-result { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; }
  body { background: #fff; }
  .container { max-width: 100%; }
}

/* 检测进行中面板 */
.processing-panel {
  text-align: center;
  padding: 48px 20px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.06);
  margin: 24px 0;
}
.processing-panel .spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 20px;
}
.processing-panel h3 {
  font-size: 1.2rem;
  color: var(--text);
  margin: 0 0 8px;
}
.processing-desc {
  color: var(--text-muted);
  font-size: .95rem;
  margin-bottom: 16px;
}
.processing-desc span {
  font-weight: 700;
  color: var(--primary);
  font-size: 1.1rem;
}
.progress-bar {
  width: 100%;
  max-width: 400px;
  height: 10px;
  background: #e2e8f0;
  border-radius: 5px;
  margin: 0 auto 12px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #2563eb);
  border-radius: 5px;
  transition: width .3s ease;
}
.processing-tip {
  font-size: .82rem;
  color: var(--text-muted);
}

/* 历史检测记录 */
.history-section {
  background: var(--card);
  border-radius: 10px;
  padding: 20px;
  margin: 24px 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  font-size: .85rem;
  transition: background .2s;
}
.history-item:hover { background: #eef2ff; }
.history-time {
  color: var(--text-muted);
  font-size: .8rem;
  white-space: nowrap;
}
.history-nodes {
  background: #dbeafe;
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}
.history-summary {
  color: var(--text-muted);
  font-size: .8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

/* 响应式 */
@media (max-width: 640px) {
  .hero h1 { font-size: 1.5rem; }
  .detect-card { padding: 20px; }
  .admin-layout { flex-direction: column; }
  .admin-sidebar { width: 100%; padding: 10px 0; }
  .admin-sidebar a { display: inline-block; padding: 8px 14px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
}
