:root {
  --bg: #080b11;
  --bg-soft: #0d121b;
  --panel: #111826;
  --panel-2: #161f30;
  --line: #22304a;
  --line-soft: #1b2437;
  --text: #e6edf7;
  --muted: #8ea0bb;
  --accent: #3aa9ff;
  --accent-2: #17c9a3;
  --warn: #f0b429;
  --danger: #ff5d6c;
  --ok: #3ddc84;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(1200px 600px at 15% -10%, #16223a 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Source Han Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
small { font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }

/* ---------- 登录 ---------- */
.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, rgba(23, 33, 52, .96), rgba(15, 21, 33, .96));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 26px 26px;
  box-shadow: var(--shadow);
}

.auth-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #06121f;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  margin-bottom: 14px;
}

.auth-title { font-size: 20px; letter-spacing: .5px; }
.auth-card > p.muted { margin: 6px 0 18px; }

/* ---------- 顶栏 ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: rgba(10, 14, 22, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #06121f;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; letter-spacing: .4px; }
.brand-text small { font-size: 11px; }

.tabs { display: flex; gap: 4px; background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: 999px; padding: 4px; }
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: linear-gradient(135deg, rgba(58, 169, 255, .22), rgba(23, 201, 163, .18)); color: #fff; box-shadow: inset 0 0 0 1px rgba(58, 169, 255, .4); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  white-space: nowrap;
}
.badge.live { color: var(--ok); border-color: rgba(61, 220, 132, .4); background: rgba(61, 220, 132, .1); }
.badge.warn { color: var(--warn); border-color: rgba(240, 180, 41, .4); background: rgba(240, 180, 41, .1); }
.badge.busy { color: var(--accent); border-color: rgba(58, 169, 255, .45); background: rgba(58, 169, 255, .12); }

/* ---------- 资源占用 ---------- */
.resources {
  padding: 9px 18px 11px;
  background: linear-gradient(180deg, rgba(14, 20, 31, .92), rgba(10, 14, 22, .92));
  border-bottom: 1px solid var(--line);
}
.res-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.res-heading { font-size: 13px; letter-spacing: .6px; }
.res-status { font-size: 11px; color: var(--muted); margin-left: auto; text-align: right; overflow-wrap: anywhere; }
.res-status.warn { color: var(--warn); }

.res-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; }
.res-group {
  min-width: 0;
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 8px 10px 9px;
}
.res-group-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.res-group-head h3 { font-size: 12px; letter-spacing: .5px; }
.res-tag {
  font-size: 10px;
  line-height: 16px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 7px;
}
.res-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px 12px; }
.res-item { min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; gap: 1px; }
.res-label { font-size: 11px; line-height: 1.3; color: var(--muted); overflow-wrap: anywhere; }
.res-value { font-family: var(--mono); font-size: 12.5px; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.res-value.na { color: var(--muted); font-weight: 400; }
.res-meta { font-size: 10px; color: var(--muted); overflow-wrap: anywhere; }

/* ---------- 主体 ---------- */
.main { flex: 1 1 auto; padding: 18px; }

.panel { display: block; }
.panel[hidden] { display: none !important; }

.wb-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.card {
  background: linear-gradient(180deg, rgba(20, 28, 44, .92), rgba(14, 20, 31, .92));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .28);
}
.card.narrow { max-width: 720px; margin-bottom: 16px; }

.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 14px; letter-spacing: .6px; }
.card-head > .muted, .card-head > .state-label { margin-left: auto; }

.state-label { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: var(--bg-soft); white-space: nowrap; }
.state-label.live { color: var(--ok); border-color: rgba(61, 220, 132, .4); background: rgba(61, 220, 132, .1); }
.state-label.busy { color: var(--accent); border-color: rgba(58, 169, 255, .45); background: rgba(58, 169, 255, .12); }
.state-label.warn { color: var(--warn); border-color: rgba(240, 180, 41, .4); background: rgba(240, 180, 41, .1); }
.state-label.error { color: var(--danger); border-color: rgba(255, 93, 108, .45); background: rgba(255, 93, 108, .12); }

/* ---------- 表单 ---------- */
.row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.row.wrap { flex-wrap: wrap; }
.row:last-child { margin-bottom: 0; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label, .label { font-size: 12px; color: var(--muted); }

input[type="text"], input[type="password"], input[type="search"], input[type="url"], select, textarea {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(58, 169, 255, .15); }
select { width: auto; min-width: 200px; }
input::placeholder, textarea::placeholder { color: #55637d; }

.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.error-text { font-size: 12px; color: var(--danger); margin-top: 8px; word-break: break-all; }

.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  white-space: nowrap;
  transition: .15s;
}
.btn:hover:not(:disabled) { border-color: #38507a; background: #1b2740; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #2b7fd6); border-color: transparent; color: #04121f; font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: linear-gradient(135deg, var(--accent), #2b7fd6); }
.btn.accent { background: linear-gradient(135deg, var(--accent-2), #14a084); border-color: transparent; color: #032018; font-weight: 600; }
.btn.accent:hover:not(:disabled) { filter: brightness(1.08); background: linear-gradient(135deg, var(--accent-2), #14a084); }
.btn.danger { color: var(--danger); border-color: rgba(255, 93, 108, .4); }
.btn.danger.ghost:hover:not(:disabled) { background: rgba(255, 93, 108, .12); border-color: rgba(255, 93, 108, .6); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; }
.icon-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.icon-btn:hover { color: var(--text); border-color: #38507a; }

/* ---------- 画面 ---------- */
.viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #05080d;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  outline: none;
  cursor: crosshair;
  touch-action: none;
}
#browser-stage { min-width: 0; max-width: 100%; }
.stage-bar { display: none; }
body.stage-open { overflow: hidden; }
#browser-stage.stage-fallback {
  position: fixed;
  inset: 0;
  z-index: 80;
  box-sizing: border-box;
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #080b11;
  padding:
    calc(8px + env(safe-area-inset-top))
    calc(8px + env(safe-area-inset-right))
    calc(8px + env(safe-area-inset-bottom))
    calc(8px + env(safe-area-inset-left));
}
#browser-stage.stage-fallback .stage-bar {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  align-items: center;
}
#browser-stage.stage-fallback .fs-hide { display: none !important; }
#browser-stage.stage-fallback .stage-view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0;
}
#browser-stage.stage-fallback .stage-view .row { flex: 0 0 auto; margin-bottom: 8px; }
#browser-stage.stage-fallback .viewport {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: auto;
  aspect-ratio: auto !important;
}
.btn.warn-btn { color: #04121f; background: var(--warn); border-color: transparent; font-weight: 600; }
.viewport:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(58, 169, 255, .18); }
.viewport.busy { cursor: progress; opacity: .8; }
.frame-img { width: 100%; height: 100%; object-fit: contain; display: none; user-select: none; }
.frame-img[src] { display: block; }
.viewport-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 20px;
  pointer-events: none;
}
.field-overlay { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.remote-field {
  position: absolute;
  box-sizing: border-box;
  margin: 0;
  padding: 0 2px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: transparent;
  caret-color: #e6edf7;
  font: 16px/1.2 sans-serif;
  resize: none;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-user-select: text;
  user-select: text;
}
.remote-field:focus { outline: 1px solid rgba(58, 169, 255, .85); }
.pick-flag {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(240, 180, 41, .16);
  border: 1px solid rgba(240, 180, 41, .5);
  color: var(--warn);
  pointer-events: none;
}
.pick-row { margin-top: 10px; }

/* ---------- 列表 / 日志 ---------- */
.list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow: auto; }
.list.compact { max-height: 200px; }
.list li {
  border: 1px solid var(--line-soft);
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.list li .grow { overflow-wrap: anywhere; }
.list li .mono { font-family: var(--mono); font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.empty-line { color: var(--muted); font-size: 12px; justify-content: center; padding: 10px; }

.log {
  max-height: 300px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  background: #06090f;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}
.log-line { display: flex; gap: 8px; }
.log-time { color: #55637d; flex: 0 0 auto; }
.log-msg { color: #c9d6e8; overflow-wrap: anywhere; }
.log-line.err .log-msg { color: var(--danger); }
.log-line.ok .log-msg { color: var(--ok); }
.log-line.warn .log-msg { color: var(--warn); }

.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); max-width: 100%; }
.check input { width: 16px; height: 16px; margin: 0; flex: 0 0 auto; }
.wizard { display: flex; flex-direction: column; gap: 12px; margin: 0; padding-left: 18px; }
.wizard li { min-width: 0; }
.wizard strong { font-size: 13px; }
.kind-tag { display: inline-block; margin-right: 6px; font-size: 11px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.kind-tag.split { color: var(--warn); border-color: rgba(240, 180, 41, .5); background: rgba(240, 180, 41, .1); }
.candidate-check { width: 16px; height: 16px; margin: 0; flex: 0 0 auto; }
.validation { margin: 0 0 10px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); }
.validation.ok { border-color: rgba(61, 220, 132, .45); background: rgba(61, 220, 132, .08); }
.validation.warn { border-color: rgba(240, 180, 41, .5); background: rgba(240, 180, 41, .08); }
.validation.failed { border-color: rgba(255, 93, 108, .5); background: rgba(255, 93, 108, .08); }
.validation p { margin-top: 4px; }
.detail-content { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.detail-content details { border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 6px 8px; background: var(--bg-soft); }
.detail-content a { color: var(--accent); overflow-wrap: anywhere; }
.app, .main, .card, .row, .list, .wb-grid, .col { min-width: 0; max-width: 100%; }
.list li { flex-wrap: wrap; }

.stat-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.stat {
  flex: 1 1 70px;
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  text-align: center;
}
.stat b { display: block; font-size: 17px; color: var(--accent); font-family: var(--mono); }
.stat i { font-style: normal; font-size: 11px; color: var(--muted); }

.code-editor {
  min-height: 300px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
}

.kv { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.kv div { display: flex; gap: 10px; }
.kv span:first-child { color: var(--muted); min-width: 96px; }

/* ---------- 媒体库 ---------- */
.media-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}
.media-card {
  background: linear-gradient(180deg, rgba(20, 28, 44, .92), rgba(14, 20, 31, .92));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.poster-wrap, .detail-poster {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #05080d;
  overflow: hidden;
}
.poster-wrap img, .detail-poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #55637d;
  font-size: 12px;
  background: repeating-linear-gradient(45deg, #0b111b, #0b111b 10px, #0e1521 10px, #0e1521 20px);
}
.media-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.media-title { font-size: 13px; line-height: 1.4; max-height: 3em; overflow: hidden; overflow-wrap: anywhere; }
.media-meta { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.media-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }

.empty-box {
  margin-top: 16px;
  padding: 26px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
}

/* ---------- 弹层 ---------- */
.modal-host { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(3, 6, 11, .78); backdrop-filter: blur(3px); }
.modal {
  position: relative;
  width: 100%;
  max-width: 880px;
  max-height: 88vh;
  overflow: auto;
  background: linear-gradient(180deg, rgba(20, 28, 44, .98), rgba(13, 19, 30, .98));
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line-soft); position: sticky; top: 0; background: rgba(16, 23, 36, .96); }
.modal-head h2 { font-size: 14px; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 16px 18px 20px; }
.detail-grid { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 18px; }
.detail-main { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.detail-main h3 { font-size: 15px; overflow-wrap: anywhere; }
.detail-video { width: 100%; max-height: 320px; background: #05080d; border-radius: var(--radius-sm); border: 1px solid var(--line-soft); }

/* ---------- 提示条 ---------- */
.toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 32px));
}
.toast {
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(18, 26, 40, .96);
  box-shadow: var(--shadow);
  font-size: 13px;
  overflow-wrap: anywhere;
  animation: toast-in .18s ease-out;
}
.toast.ok { border-color: rgba(61, 220, 132, .5); color: #bff5d4; }
.toast.warn { border-color: rgba(240, 180, 41, .5); color: #ffe2a3; }
.toast.error { border-color: rgba(255, 93, 108, .55); color: #ffc6cc; }
.toast.fade { opacity: 0; transition: opacity .35s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) {
  .wb-grid { grid-template-columns: minmax(0, 1fr); }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .detail-poster { max-width: 380px; }
}

@media (max-width: 680px) {
  .main { padding: 12px; }
  .topbar { padding: 8px 12px; gap: 10px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; justify-content: flex-start; }
  .tab { padding: 6px 12px; }
  .topbar-right { margin-left: auto; }
  .card { padding: 12px; }
  .code-editor { min-height: 220px; }
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .row { flex-wrap: wrap; }
  .btn { white-space: normal; }
  .row input.grow { flex-basis: 100%; }
  select { min-width: 0; width: 100%; }
  .resources { padding: 8px 12px 10px; }
  .res-groups { grid-template-columns: minmax(0, 1fr); }
  .res-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px 10px; }
}
