:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --border: #e4e7ee;
  --text: #1b1f2a;
  --muted: #6b7280;
  --primary: #4c6ef5;
  --primary-soft: #eef1fe;
  --ok: #12b886;
  --warn: #f59f00;
  --danger: #e03131;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 "PingFang SC", "Microsoft YaHei", -apple-system, "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); cursor: pointer;
  font-size: 13px; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: #f2f4f9; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #4263eb; }
.btn.ghost { background: transparent; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 7px; }
.btn.block { width: 100%; }
.btn.warn { background: #fff9db; border-color: #ffe066; color: #8a6100; }
.btn.danger { background: #fff5f5; border-color: #ffc9c9; color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  width: 100%; height: 34px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); font-size: 13px; outline: none;
  font-family: inherit;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(76, 110, 245, .12);
}
input[type=checkbox] { width: auto; height: auto; }

/* ---------- 登录 ---------- */
.login-wrap {
  height: 100%; display: grid; place-items: center;
  background: linear-gradient(160deg, #eef1fe 0%, #f6f7fb 45%, #eefaf6 100%);
}
.login-card {
  width: 340px; padding: 32px 28px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-logo { font-size: 40px; }
.login-card h1 { margin: 0; font-size: 22px; letter-spacing: .5px; }
.login-card .sub { margin: -6px 0 8px; color: var(--muted); font-size: 12px; }
.err { color: var(--danger); font-size: 12px; min-height: 16px; }

/* ---------- 布局 ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  height: 52px; flex: 0 0 52px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.brand .logo { font-size: 18px; }
.brand em { font-style: normal; font-size: 11px; color: var(--muted); font-weight: 400; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.chip {
  padding: 3px 10px; border-radius: 999px; background: var(--primary-soft);
  color: var(--primary); font-size: 12px;
}
.me { font-size: 12px; color: var(--muted); }

.body { flex: 1; display: grid; grid-template-columns: 240px 320px 1fr; min-height: 0; }

.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 12px; overflow: auto; }
.side-actions { display: grid; gap: 8px; margin-bottom: 12px; }
.search { margin-bottom: 10px; }
.tree-item {
  display: flex; align-items: center; gap: 6px; padding: 7px 8px; border-radius: 8px;
  cursor: pointer; font-size: 13px; user-select: none;
}
.tree-item:hover { background: #f4f6fb; }
.tree-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.tree-item .cnt { margin-left: auto; font-size: 11px; color: var(--muted); }
.tree-item .dot { width: 8px; height: 8px; border-radius: 99px; }
.tags-filter { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip {
  padding: 2px 9px; border-radius: 999px; background: #f1f3f9; border: 1px solid var(--border);
  font-size: 12px; cursor: pointer;
}
.tag-chip.on { background: var(--primary-soft); border-color: #c7d2fe; color: var(--primary); }
.switch-line { display: flex; align-items: center; gap: 6px; margin-top: 14px; font-size: 12px; color: var(--muted); }

.list { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.list-head {
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: baseline; justify-content: space-between; font-weight: 600;
}
.cards { flex: 1; overflow: auto; padding: 10px; display: grid; gap: 10px; align-content: start; }
.card {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px;
  background: #fff; cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.card:hover { border-color: #c7d2fe; box-shadow: var(--shadow); }
.card.active { border-color: var(--primary); background: #fbfcff; }
.card-top { display: flex; align-items: center; gap: 8px; }
.card-name { font-weight: 600; font-size: 13px; }
.card-meta { color: var(--muted); font-size: 11.5px; margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.card-tags { margin-top: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.tag-mini { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: #f1f3f9; color: #495057; }
.card-actions { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 6px; }
.badge.ok { background: #e6fcf5; color: #087f5b; }
.badge.failed { background: #fff5f5; color: var(--danger); }
.badge.manual { background: #fff9db; color: #8a6100; }
.badge.never { background: #f1f3f5; color: var(--muted); }
.badge.live { background: var(--primary-soft); color: var(--primary); }

.stage { display: flex; flex-direction: column; min-height: 0; background: #eef0f5; }
.stage-bar { display: flex; gap: 6px; padding: 10px 12px; align-items: center; background: var(--panel); border-bottom: 1px solid var(--border); }
.urlbar { flex: 1; min-width: 120px; }
.stage-status { display: flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 12px; background: #fff; border-bottom: 1px solid var(--border); }
.dot { width: 8px; height: 8px; border-radius: 99px; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.danger { background: var(--danger); }
.dot.live { background: var(--primary); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.viewport { flex: 1; overflow: hidden; display: grid; place-items: center; padding: 12px; position: relative; }
#screen {
  max-width: 100%; max-height: 100%; background: #fff; border-radius: 10px;
  box-shadow: var(--shadow); outline: none; cursor: crosshair; display: block;
}
.placeholder { position: absolute; inset: 12px; display: grid; place-items: center; pointer-events: none; }
.ph-inner { color: var(--muted); background: #fff; padding: 12px 18px; border-radius: 10px; border: 1px dashed var(--border); }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; background: rgba(16, 24, 40, .38); display: grid; place-items: center; z-index: 50; }
.modal-card {
  width: 420px; max-width: calc(100vw - 32px); max-height: calc(100vh - 60px);
  background: var(--panel); border-radius: 14px; box-shadow: 0 20px 60px rgba(16,24,40,.2);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-card.wide { width: 760px; }
.modal-card header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-card h3 { margin: 0; font-size: 15px; }
.x { border: 0; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-card footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.modal-body { padding: 16px 18px; overflow: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px 18px; overflow: auto; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.form-grid label.full { grid-column: 1 / -1; }
.inline { display: flex; gap: 6px; }
.inline input { flex: 1; }

.kv { display: grid; grid-template-columns: 92px 1fr; gap: 6px 10px; font-size: 13px; }
.kv b { font-weight: 500; color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; }
.reveal-box { background: #f8f9fb; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 90; }
.toast {
  min-width: 220px; max-width: 380px; padding: 10px 14px; border-radius: 10px;
  background: #fff; border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: 13px; border-left: 4px solid var(--primary);
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

@media (max-width: 1180px) {
  .body { grid-template-columns: 200px 280px 1fr; }
}
@media (max-width: 900px) {
  .body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar, .list { display: none; }
}
