/* ============================================================
   Cahot Hot · 品牌感深色主题 v2 (两栏布局)
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0b0e13;
  --bg-2: #161b22;
  --bg-3: #1f2630;
  --bg-4: #2a3340;
  --border: #2a3340;
  --text: #e6edf3;
  --text-2: #8b949e;
  --text-3: #6b7280;
  --accent: #ff5722;
  --accent-2: #ff7043;
  --accent-glow: rgba(255, 87, 34, 0.35);
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --blue: #58a6ff;
  --purple: #a371f7;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(ellipse at top, rgba(255, 87, 34, 0.08), transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(88, 166, 255, 0.05), transparent 50%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===================== 顶栏 ===================== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px); background: rgba(11, 14, 19, 0.7);
  position: sticky; top: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 24px; filter: drop-shadow(0 0 8px var(--accent-glow)); }
.title {
  font-size: 20px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.subtitle { color: var(--text-2); font-size: 12px; margin-left: 4px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.health-pill {
  padding: 4px 10px; border-radius: 999px; font-size: 11px;
  background: var(--bg-3); color: var(--text-2); border: 1px solid var(--border);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.health-pill.ok { color: var(--green); border-color: rgba(63, 185, 80, 0.3); }
.health-pill.warn { color: var(--yellow); border-color: rgba(210, 153, 34, 0.3); }
.health-pill.err { color: var(--red); border-color: rgba(248, 81, 73, 0.3); }

.admin-badge {
  padding: 3px 8px; border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 11px; font-weight: 600;
}
.btn-ghost {
  padding: 5px 12px; border-radius: 6px;
  border: 1px solid var(--border); color: var(--text-2);
  text-decoration: none; font-size: 12px; transition: all 0.2s;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ===================== 两栏主区 ===================== */
.two-col {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  max-width: 1600px; margin: 0 auto;
  padding: 20px 24px 60px;
  min-height: calc(100vh - 60px);
}

/* ===================== 左栏 ===================== */
.left-col {
  display: flex; flex-direction: column; gap: 16px;
  position: sticky; top: 76px; align-self: start;
  max-height: calc(100vh - 96px);
}

.add-panel {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.add-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.add-tab {
  flex: 1; padding: 6px; border-radius: 6px;
  background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text-2); cursor: pointer; font-size: 12px;
  transition: all 0.15s;
}
.add-tab:hover { color: var(--text); }
.add-tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent;
}

.add-form {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.add-form.active { display: grid; }
.add-form input:last-of-type { grid-column: 1 / -1; }
.add-form button { grid-column: 1 / -1; justify-self: end; min-width: 60px; }

.add-form input {
  padding: 8px 10px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text);
  font-size: 12px; font-family: inherit;
  min-width: 0;
}
.add-form input:focus { outline: none; border-color: var(--accent); }
.add-form input[name="ca"], .add-form input[name="x_url"] {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
}
.add-form input.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11px; }

.add-panel-title {
  font-size: 12px; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 10px;
}
.add-hint {
  margin-top: 8px;
  font-size: 10px;
  color: var(--text-3);
  text-align: center;
}

.btn-primary {
  padding: 8px 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none; border-radius: 6px;
  color: #fff; font-weight: 700; font-size: 16px;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--accent-glow);
}
.btn-primary:hover { box-shadow: 0 4px 14px var(--accent-glow); }

/* 左栏列表 */
.left-list-wrap {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius);
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
}
.left-list-header {
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.5px;
}
.left-list-count {
  background: var(--bg-3); padding: 2px 8px; border-radius: 10px;
  font-size: 11px; color: var(--text-2);
}

.left-list {
  overflow-y: auto;
  flex: 1;
}
.left-list-empty {
  padding: 40px 16px; text-align: center;
  color: var(--text-3); font-size: 12px;
}

.entry-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.entry-item:hover { background: var(--bg-3); }
.entry-item.active {
  background: linear-gradient(90deg, rgba(255, 87, 34, 0.12), transparent);
  border-left: 3px solid var(--accent);
  padding-left: 11px;
}
.entry-item.paused { opacity: 0.5; }

.entry-item-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
}
.entry-item-name {
  font-size: 14px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 180px;
}
.entry-item-badge {
  font-size: 9px; padding: 1px 6px; border-radius: 4px;
  font-family: ui-monospace, monospace; font-weight: 600;
  display: inline-flex; align-items: center; gap: 3px;
}
.entry-item-badge.combo { color: var(--accent); background: rgba(255, 87, 34, 0.12); border: 1px solid rgba(255, 87, 34, 0.3); }
.entry-item-badge.x-only { color: var(--blue); background: rgba(88, 166, 255, 0.12); border: 1px solid rgba(88, 166, 255, 0.3); }
.entry-item-badge.ca-only { color: var(--purple); background: rgba(163, 113, 247, 0.12); border: 1px solid rgba(163, 113, 247, 0.3); }

.entry-item-meta {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px; color: var(--text-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.entry-item-status {
  font-size: 9px; padding: 1px 6px; border-radius: 4px;
  font-family: ui-monospace, monospace; font-weight: 600;
  flex-shrink: 0;
}
.entry-item-status.running {
  background: rgba(63, 185, 80, 0.12); color: var(--green);
  border: 1px solid rgba(63, 185, 80, 0.3);
}
.entry-item-status.paused {
  background: rgba(139, 148, 158, 0.12); color: var(--text-3);
  border: 1px solid rgba(139, 148, 158, 0.3);
}

/* 左栏每条的小按钮 */
.entry-actions {
  display: flex; gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}
.entry-action-btn {
  width: 26px; height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s;
  padding: 0;
  line-height: 1;
}
.entry-action-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--bg-4);
}
.entry-action-btn.delete:hover {
  border-color: var(--red);
  color: var(--red);
  background: rgba(248, 81, 73, 0.1);
}
.entry-action-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===================== 右栏 ===================== */
.right-col {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 0;
  display: flex; flex-direction: column;
}

.right-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-3);
  gap: 16px; min-height: 400px;
}
.right-empty-icon { font-size: 48px; opacity: 0.6; }

.right-content {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0;
}

/* 详情头 */
.detail-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}
.detail-name {
  font-size: 20px; font-weight: 700; color: var(--text);
  margin-bottom: 4px;
}
.detail-meta {
  font-size: 12px; color: var(--text-2);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  word-break: break-all;
}
.detail-meta .meta-line {
  padding: 2px 0;
}
.detail-meta .meta-label {
  color: var(--text-3); margin-right: 4px;
  font-family: inherit;
}
.detail-meta .mono {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.detail-meta a {
  color: var(--blue); text-decoration: none;
}
.detail-meta a:hover { text-decoration: underline; }

.detail-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* sparkline 区 */
.detail-spark {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-3);
  position: relative;
}
.spark-svg { width: 100%; height: 90px; }
.spark-legend {
  display: flex; flex-wrap: wrap; gap: 16px;
  margin-top: 8px;
  font-size: 11px; color: var(--text-2);
}
.spark-legend-group {
  display: flex; align-items: center; gap: 8px;
  padding-right: 12px;
  border-right: 1px solid var(--border);
}
.spark-legend-group:last-child { border-right: none; }
.spark-legend-group-label {
  font-size: 10px; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-right: 2px;
}
.spark-legend-items { display: flex; gap: 10px; }
.spark-legend-item { display: flex; align-items: center; gap: 4px; }
.spark-legend-dot {
  width: 10px; height: 10px; border-radius: 2px;
}

/* 历史列表 */
.detail-history {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
}
.history-toolbar {
  padding: 10px 24px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-2);
}

.history-list {
  flex: 1; overflow-y: auto;
  padding: 12px 24px 24px;
}

.history-card {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 8px;
  position: relative;
  transition: border 0.15s;
}
.history-card:hover { border-color: var(--accent); }
.history-card.has-error { border-color: rgba(248, 81, 73, 0.4); }

.history-card-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
  font-size: 12px; color: var(--text-2);
}
.history-card-time {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 600; color: var(--text);
}
.history-card-ago {
  color: var(--text-3); margin-left: 8px;
  font-size: 11px;
}
.history-card-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
}
.history-card.has-error .history-card-dot { background: var(--red); }

/* 每行字段 - 一横排布局 */
.metric-group {
  margin-bottom: 8px;
}
.metric-group:last-child { margin-bottom: 0; }
.metric-group-head {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-2);
  margin-bottom: 4px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.metric-group-icon { font-size: 12px; }
.metric-group-x { color: var(--blue); }
.metric-group-ca { color: var(--purple); }
.metric-group-warn {
  margin-left: auto; font-size: 10px;
  color: var(--yellow);
}

/* 横排:X 5 字段 / CA 4 字段 */
.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  background: var(--bg-2);
  border-radius: 4px;
  padding: 6px 10px;
  flex-wrap: wrap;
}
.metric-cell {
  display: inline-flex; align-items: baseline; gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
}
.metric-cell-label {
  color: var(--text-3); font-size: 11px;
}
.metric-cell-value {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 600; color: var(--text);
}
.metric-cell-delta {
  font-size: 10px; font-weight: 600;
  padding: 1px 4px; border-radius: 3px;
}
.metric-cell-delta.up { color: var(--green); background: rgba(63, 185, 80, 0.12); }
.metric-cell-delta.down { color: var(--red); background: rgba(248, 81, 73, 0.12); }
.metric-cell-delta.same { color: var(--text-3); }

.history-error {
  color: var(--red); font-size: 12px;
  padding: 4px 0;
}

/* 按钮 */
.btn-sm {
  padding: 5px 12px; border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-3); color: var(--text-2);
  font-size: 12px; cursor: pointer; transition: all 0.15s;
  font-family: inherit;
}
.btn-sm:hover { color: var(--text); border-color: var(--accent); }
.btn-sm.danger:hover { border-color: var(--red); color: var(--red); }

/* ===================== Login page ===================== */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px; width: 100%; max-width: 360px;
  box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 24px; }
.brand-logo { font-size: 44px; filter: drop-shadow(0 0 12px var(--accent-glow)); margin-bottom: 6px; }
.brand-title {
  font-size: 26px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.brand-sub { color: var(--text-2); font-size: 12px; margin-top: 4px; }
.alert-error {
  background: rgba(248, 81, 73, 0.12); border: 1px solid rgba(248, 81, 73, 0.3);
  color: var(--red); padding: 9px 12px; border-radius: 6px;
  font-size: 12px; margin-bottom: 14px;
}
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form label { display: flex; flex-direction: column; gap: 4px; }
.login-form input {
  padding: 10px 12px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text);
  font-size: 13px; font-family: inherit;
}
.login-form input:focus { outline: none; border-color: var(--accent); }
.login-form button { margin-top: 6px; }

/* ===================== 响应式 ===================== */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; padding: 16px; }
  .left-col { position: static; max-height: none; }
  .left-list { max-height: 300px; }
  .detail-header { padding: 14px 16px; }
  .detail-spark, .history-toolbar, .history-list { padding-left: 16px; padding-right: 16px; }
}