/* ═══════════════════════════════════════════════════
   CI/CD 运营平台 v3 — 暗色主题 (GitHub 风格)
   ═══════════════════════════════════════════════════ */

/* ── Reset & Base ── */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0d1117;
  color: #c9d1d9;
  min-height: 100vh;
}
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Header ── */
.header {
  background: #161b22;
  border-bottom: 1px solid #30363d;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.header h1 { font-size: 18px; color: #58a6ff; }
.header .user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: #8b949e;
}
.header .user-info .role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}
.role-badge-admin { background: #1b3a2a; color: #3fb950; }
.role-badge-viewer { background: #1b2e3a; color: #58a6ff; }
.header .logout {
  color: #8b949e;
  text-decoration: none;
  font-size: 13px;
}
.header .logout:hover { color: #f85149; }

/* ── Tabs ── */
.tabs {
  display: flex;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  padding: 0 24px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  color: #8b949e;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  user-select: none;
  outline: none;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: #c9d1d9; }
.tab:focus-visible {
  outline: 2px solid #58a6ff;
  outline-offset: -2px;
  border-radius: 2px;
}
.tab.active {
  color: #58a6ff;
  border-bottom-color: #58a6ff;
}

/* ── Content ── */
.content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}
.content h2 {
  font-size: 18px;
  margin-bottom: 16px;
  color: #e6edf3;
}
.content h3 {
  font-size: 15px;
  margin-bottom: 10px;
  color: #c9d1d9;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Loading ── */
.loading {
  color: #8b949e;
  font-size: 13px;
  padding: 20px 0;
  text-align: center;
}
.loading::before {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #30363d;
  border-top-color: #58a6ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ── */
.empty-state {
  color: #8b949e;
  font-size: 13px;
  padding: 40px 0;
  text-align: center;
}
.empty-row {
  color: #8b949e;
  font-size: 13px;
  padding: 32px 0;
  text-align: center;
  border-top: 1px solid #21262d;
}

/* ── Forms ── */
.form-group { margin-bottom: 12px; }
.form-group label {
  display: block;
  font-size: 12px;
  color: #8b949e;
  margin-bottom: 4px;
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  max-width: 500px;
  padding: 8px 10px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #c9d1d9;
  font-size: 13px;
  outline: none;
  font-family: monospace;
}
.form-group textarea {
  min-height: 60px;
  resize: vertical;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: #58a6ff;
}
.form-group select {
  font-family: inherit;
  cursor: pointer;
}

/* ── Buttons ── */
.btn {
  padding: 8px 20px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  outline: none;
  transition: background 0.15s, opacity 0.15s;
}
.btn:focus-visible {
  outline: 2px solid #58a6ff;
  outline-offset: 2px;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-save { background: #238636; color: #fff; }
.btn-save:hover:not(:disabled) { background: #2ea043; }
.btn-danger { background: #da3633; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #f85149; }
.btn-add { background: #1f6feb; color: #fff; }
.btn-add:hover:not(:disabled) { background: #388bfd; }
.btn-sm {
  padding: 4px 12px;
  font-size: 12px;
}

/* ── Messages ── */
.msg { font-size: 13px; margin-top: 8px; padding: 8px 12px; border-radius: 6px; }
.msg-ok { color: #3fb950; background: #1b3a2a; }
.msg-err { color: #f85149; background: #3a1b1b; }
.msg-info { color: #58a6ff; background: #1b2e3a; }

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  margin-bottom: 16px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 600px;
}
th {
  text-align: left;
  padding: 8px 12px;
  background: #161b22;
  color: #8b949e;
  font-weight: 500;
  border-bottom: 1px solid #30363d;
  white-space: nowrap;
}
td {
  padding: 8px 12px;
  border-bottom: 1px solid #21262d;
}
tr:nth-child(even) td { background: #0d1117; }
tr:hover td { background: #161b22; }
/* 斑马纹：偶数行微深背景 */
tr:nth-child(even) td { background: #0d1117; }
tr:nth-child(even):hover td { background: #161b22; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}
.badge-ok { background: #1b3a2a; color: #3fb950; }
.badge-err { background: #3a1b1b; color: #f85149; }
.badge-run { background: #1b2e3a; color: #58a6ff; }
.badge-pending { background: #1b2e3a; color: #d29922; }

/* ── Filters ── */
.filters {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.filters select,
.filters input {
  padding: 6px 10px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #c9d1d9;
  font-size: 13px;
  font-family: inherit;
}
.filters select:focus,
.filters input:focus {
  border-color: #58a6ff;
  outline: none;
}
.filters label {
  font-size: 13px;
  color: #8b949e;
}

/* ── Stats Grid & Cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 20px 16px 14px;
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}
.stat-card .num {
  font-size: 40px;
  font-weight: 800;
  line-height: 1.1;
}
.stat-card .label {
  font-size: 13px;
  color: #8b949e;
  margin-top: 6px;
}
.stat-card .rate { font-size: 14px; margin-top: 6px; font-weight: 600; }
.rate-ok { color: #3fb950; }
.rate-warn { color: #d29922; }
.rate-err { color: #f85149; }

/* 统计卡片顶部色条 */
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.stat-card-total .num { color: #58a6ff; }
.stat-card-total::before { background: #58a6ff; }
.stat-card-success .num { color: #3fb950; }
.stat-card-success::before { background: #3fb950; }
.stat-card-failed .num { color: #f85149; }
.stat-card-failed::before { background: #f85149; }
.stat-card-rate .num { color: #d2a8ff; }
.stat-card-rate::before { background: #d2a8ff; }

/* 统计卡片底部进度条 */
.stat-card .rate-bar {
  margin-top: 10px;
  height: 6px;
  background: #21262d;
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.stat-card .rate-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  min-width: 0;
}
.stat-card .rate-bar-fill .bar-label {
  font-size: 10px;
  color: rgba(255,255,255,0.8);
  white-space: nowrap;
}

/* ── Charts ── */
.chart-wrap {
  margin-top: 24px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.chart-wrap h3 {
  margin: 0 0 12px;
  font-size: 15px;
  color: #c9d1d9;
}
.chart-wrap canvas { max-height: 380px; }

/* ── Stats 3-column layout ── */
.stats-columns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-top: 24px;
}
.stats-columns > div {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.stats-columns > div h3 {
  margin: 0 0 12px;
  font-size: 15px;
  color: #c9d1d9;
}

/* 横向条形图行 */
.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
}
.bar-row .bar-rank {
  width: 22px;
  text-align: center;
  color: #8b949e;
  font-weight: 600;
  font-size: 12px;
}
.bar-row .bar-rank.top3 { color: #d2a8ff; }
.bar-row .bar-name {
  width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #c9d1d9;
}
.bar-row .bar-track {
  flex: 1;
  height: 20px;
  background: #21262d;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.bar-row .bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease;
  min-width: 2px;
  display: flex;
  align-items: center;
  padding-left: 8px;
}
.bar-row .bar-fill .bar-label {
  font-size: 11px;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
}
.bar-row .bar-val {
  width: 48px;
  text-align: right;
  color: #8b949e;
  font-size: 12px;
}
.bar-row .bar-val-warn {
  color: #f85149;
  font-weight: 600;
}

/* 空状态友好提示 */
.empty-hint {
  color: #8b949e;
  font-size: 13px;
  padding: 20px 0;
  text-align: center;
  line-height: 1.6;
}
.empty-hint small {
  color: #484f58;
  font-size: 11px;
}

/* 快捷按钮高亮 */
.btn-sm.btn-active {
  background: #58a6ff;
  color: #0d1117;
  border-color: #58a6ff;
}

/* 重置按钮 */
.btn-reset {
  background: transparent;
  color: #8b949e;
  border: 1px solid #30363d;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.btn-reset:hover {
  background: #21262d;
  color: #c9d1d9;
}

/* 环境成功率进度行 */
.env-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
}
.env-row .env-name {
  width: 50px;
  color: #c9d1d9;
  font-weight: 500;
}
.env-row .env-track {
  flex: 1;
  height: 20px;
  background: #21262d;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.env-row .env-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease;
  min-width: 2px;
  display: flex;
  align-items: center;
  padding-left: 8px;
}
.env-row .env-fill-label {
  font-size: 11px;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
}
.env-row .env-rate {
  width: 50px;
  text-align: right;
  font-weight: 600;
}

/* 响应式 */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-columns { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr; }
}
/* ── Pagination ── */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
  padding: 8px 0;
}
.pagination button {
  padding: 4px 10px;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 4px;
  color: #c9d1d9;
  font-size: 12px;
  cursor: pointer;
}
.pagination button:hover:not(:disabled) { background: #30363d; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination button.active {
  background: #1f6feb;
  border-color: #1f6feb;
  color: #fff;
}
.pagination .page-info {
  font-size: 12px;
  color: #8b949e;
  margin: 0 8px;
}

/* ── Modal / Dialog ── */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 32px;
  max-width: 480px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal h2 { margin-bottom: 20px; }
.modal .form-group { margin-bottom: 16px; }
.modal .form-group input,
.modal .form-group select {
  max-width: 100%;
}
.modal .modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ── User management ── */
.user-row { display: flex; align-items: center; gap: 12px; }
.user-row .user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: #21262d;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #8b949e;
}
.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* ── Pagination ── */
.pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  align-items: center;
  margin-top: 16px;
  font-size: 13px;
}
.pagination button {
  padding: 4px 10px;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 4px;
  color: #c9d1d9;
  cursor: pointer;
  font-size: 12px;
}
.pagination button:hover:not(:disabled) { background: #30363d; border-color: #58a6ff; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination button.active { background: #1f6feb; border-color: #1f6feb; color: #fff; }
.pagination .page-info { color: #8b949e; margin: 0 8px; font-size: 12px; }

/* ── Approval Page (from views.py unified) ── */
.approval-page {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  text-align: center;
  padding: 50px;
  background: #0d1117;
  color: #c9d1d9;
}
.approval-page .card {
  background: #161b22;
  border-radius: 12px;
  padding: 40px;
  max-width: 500px;
  margin: 0 auto;
  border: 1px solid #30363d;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.approval-page h1 { color: #e94560; margin-bottom: 20px; font-size: 24px; }
.approval-page .info {
  text-align: left;
  background: #0d1117;
  padding: 20px;
  border-radius: 8px;
  margin: 20px 0;
  border: 1px solid #30363d;
}
.approval-page .info p { margin: 8px 0; color: #8b949e; font-size: 14px; }
.approval-page .info strong { color: #c9d1d9; }
.approval-page .buttons { margin-top: 30px; display: flex; gap: 20px; justify-content: center; }
.approval-page .btn {
  padding: 15px 40px; border-radius: 8px; font-size: 16px; font-weight: 600;
  cursor: pointer; transition: all .2s; display: inline-block; border: none; font-family: inherit;
}
.approval-page .btn-approve { background: #238636; color: #fff; }
.approval-page .btn-approve:hover { background: #2ea043; }
.approval-page .btn-reject { background: #da3633; color: #fff; }
.approval-page .btn-reject:hover { background: #f85149; }
.approval-page .btn:disabled { cursor: not-allowed; opacity: 0.5; }
.approval-page .result-title { font-size: 28px; }
.approval-page .result-msg { color: #8b949e; font-size: 16px; }
.approval-page a { color: #58a6ff; }

/* ── Login animation ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.login-box { animation: fadeInUp 0.4s ease; }

/* ═══════════════════════════════════════════════════
   Login Page
   ═══════════════════════════════════════════════════ */
.login-box {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 40px;
  width: 380px;
  max-width: 90%;
  animation: fadeInUp 0.4s ease;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.login-box h1 {
  font-size: 20px;
  margin-bottom: 8px;
  color: #58a6ff;
}
.login-box .subtitle {
  font-size: 13px;
  color: #8b949e;
  margin-bottom: 24px;
}
.login-box input {
  width: 100%;
  padding: 10px 12px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #c9d1d9;
  font-size: 14px;
  outline: none;
}
.login-box input:focus { border-color: #58a6ff; }
.login-box button {
  width: 100%;
  padding: 10px;
  background: #238636;
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  margin-top: 16px;
}
.login-box button:hover { background: #2ea043; }
.login-box .error {
  color: #f85149;
  font-size: 13px;
  margin-top: 12px;
}

/* ═══════════════════════════════════════════════════
   Approval Page (独立审批页面，由钉钉链接跳转)
   ═══════════════════════════════════════════════════ */
.approval-page {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  text-align: center;
  padding: 50px;
  background: #0d1117;
  color: #c9d1d9;
}
.approval-page .card {
  background: #161b22;
  border-radius: 12px;
  padding: 40px;
  max-width: 500px;
  margin: 0 auto;
  border: 1px solid #30363d;
}
.approval-page h1 {
  color: #e94560;
  margin-bottom: 20px;
  font-size: 24px;
}
.approval-page .info {
  text-align: left;
  background: #0d1117;
  padding: 20px;
  border-radius: 8px;
  margin: 20px 0;
  border: 1px solid #30363d;
}
.approval-page .info p {
  margin: 8px 0;
  color: #8b949e;
  font-size: 14px;
}
.approval-page .info strong { color: #c9d1d9; }
.approval-page .buttons {
  margin-top: 30px;
  display: flex;
  gap: 20px;
  justify-content: center;
}
.approval-page .btn {
  padding: 15px 40px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all .2s;
  display: inline-block;
  border: none;
  font-family: inherit;
}
.approval-page .btn-approve { background: #238636; color: #fff; }
.approval-page .btn-approve:hover { background: #2ea043; }
.approval-page .btn-reject { background: #da3633; color: #fff; }
.approval-page .btn-reject:hover { background: #f85149; }
.approval-page .btn:disabled { cursor: not-allowed; opacity: 0.5; }

/* 审批结果页面（简化） */
.approval-result-page {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  text-align: center;
  padding: 50px;
  background: #0d1117;
  color: #c9d1d9;
}
.approval-result-page h1 { font-size: 28px; }
.approval-result-page p { color: #8b949e; font-size: 16px; }
.approval-result-page a { color: #58a6ff; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .content { padding: 16px; }
  .header { padding: 10px 16px; }
  .tabs { padding: 0 16px; }
  .tabs .tab { padding: 8px 12px; font-size: 12px; }
  .modal { padding: 24px; }
}

/* ── Print ── */
@media print {
  .header, .tabs, .filters, .btn { display: none; }
  body { background: #fff; color: #000; }
  .content { max-width: 100%; }
  table { min-width: auto; }
}

/* ── 对接配置表格 ── */
.cfg-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.cfg-table th { background: #161b22; color: #8b949e; font-size: 12px; padding: 6px 8px; text-align: left; }
.cfg-table td { padding: 8px; border-bottom: 1px solid #21262d; vertical-align: middle; }
.cfg-table tr:hover td { background: #161b22; }
