/* 业务端 — 对齐管理后台 WF 浅绿风格，自适应浅色/深色 */
:root {
  color-scheme: light dark;
  --bg: #f0f2f5;
  --bg2: #ffffff;
  --bg3: #f4f7f0;
  --line: #e2e8f0;
  --text: #1e2a3a;
  --muted: #64748b;
  --accent: #8bc34a;
  --accent-hover: #7cb342;
  --accent-soft: rgba(139, 195, 74, 0.15);
  --ok: #2e7d32;
  --danger: #e53935;
  --header: #8bc34a;
  --header-text: #ffffff;
  --player-bg: #0b1220;
  --radius: 12px;
  --topbar-h: 56px;
  --tabbar-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --bg2: #1a222c;
    --bg3: #243040;
    --line: #2e3a48;
    --text: #e8eef4;
    --muted: #94a3b8;
    --accent: #9ccc65;
    --accent-hover: #8bc34a;
    --accent-soft: rgba(156, 204, 101, 0.18);
    --ok: #81c784;
    --danger: #ef5350;
    --header: #2e7d32;
    --header-text: #f1f8e9;
    --player-bg: #000;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}
#app { height: 100%; overflow: hidden; }
.hidden { display: none !important; }
.view { height: 100%; min-height: 0; }
.muted { color: var(--muted); font-size: 12px; }

.btn {
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--header-text);
}
.btn.ghost:hover { background: rgba(255, 255, 255, 0.12); }
.err { color: var(--danger); min-height: 1.2em; }
.badge { font-size: 12px; color: var(--ok); margin-left: 8px; font-weight: 600; }
.mode-tag { margin-left: auto; color: var(--muted); font-size: 12px; }
.chk {
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ---- login ---- */
.login-view {
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
  background: linear-gradient(135deg, #e8f5e9 0%, #f0f2f5 55%, #fff 100%);
}
@media (prefers-color-scheme: dark) {
  .login-view {
    background: radial-gradient(900px 420px at 20% 0%, #1b3320, transparent), var(--bg);
  }
}
.login-card {
  width: min(400px, 100%);
  background: var(--bg2);
  border-radius: 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1);
  padding: 32px 28px 24px;
  border: 1px solid var(--line);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.brand-ico {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  border-radius: 16px;
  background: #f0f7e6;
  color: #8bc34a;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 700;
}
@media (prefers-color-scheme: dark) {
  .brand-ico { background: rgba(139, 195, 74, 0.15); color: var(--accent); }
}
.login-card h1 { margin: 0 0 6px; font-size: 22px; font-weight: 700; }
.login-card .sub { margin: 0; color: var(--muted); font-size: 13px; }
.login-card label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 8px;
}
.login-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  background: var(--bg2);
  color: var(--text);
  margin-bottom: 14px;
}
.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.login-card .btn { width: 100%; padding: 12px; margin-top: 0; }
#btn-wecom-login { margin-top: 8px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 14px; line-height: 1.5; text-align: center; }

/* ---- shell ---- */
.main-view {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
.topbar {
  height: var(--topbar-h);
  flex: 0 0 var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--header);
  color: var(--header-text);
  box-shadow: var(--shadow);
  gap: 12px;
  z-index: 30;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  display: grid;
  place-items: center;
  font-size: 14px;
}
.menu-chip {
  display: none;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: var(--header-text);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  cursor: pointer;
}
.top-actions { display: flex; gap: 8px; align-items: center; }

.layout {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* 左侧：搜索 + 区域/通道 */
.sidebar {
  width: 300px;
  flex: 0 0 300px;
  border-right: 1px solid var(--line);
  background: var(--bg2);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.side-search {
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--line);
}
.side-search input {
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg3);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.side-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.side-head {
  flex: 0 0 auto;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.tree-split {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}
.region-pane {
  flex: 0 0 42%;
  max-width: 46%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg3);
  border-right: 1px solid var(--line);
}
.ch-pane {
  flex: 1 1 58%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.tree {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 4px 6px 10px;
  -webkit-overflow-scrolling: touch;
}
.tree::-webkit-scrollbar { width: 6px; }
.tree::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 45%, transparent);
  border-radius: 4px;
}

.ch-item {
  padding: 10px 10px;
  cursor: pointer;
  font-size: 14px;
  border-radius: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 2px;
}
.ch-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  flex: none;
}
.ch-item .dot.on { background: var(--ok); }
.ch-item:hover,
.ch-item.active { background: var(--accent-soft); }

.region-item {
  border-radius: 8px;
  margin-bottom: 2px;
}
.region-h {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  cursor: pointer;
  font-size: 13px;
  border-radius: 8px;
}
.region-h:hover { background: color-mix(in srgb, var(--bg2) 70%, transparent); }
.region-h.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.region-h .twist {
  width: 16px;
  flex: none;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
  user-select: none;
}
.region-h .twist.empty { visibility: hidden; }
.region-h .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.region-h .cnt { color: var(--muted); font-size: 11px; flex: none; }
.region-children { display: none; padding-left: 10px; }
.region-item.open > .region-children { display: block; }
.tree .empty {
  color: var(--muted);
  font-size: 13px;
  padding: 12px 8px;
}

.content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px;
  overflow: hidden;
}

.player-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.player-meta {
  flex: 0 0 auto;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
}
.player-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg3);
  padding: 10px;
}
/* 视频画面保持 4:3 */
.player-box {
  width: min(100%, calc((100vh - 220px) * 4 / 3));
  max-width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--player-bg);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 8px;
}
.player-box > .player-inner {
  width: 100%;
  height: 100%;
  position: relative;
}
.player-box video {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.player-toolbar {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
  background: var(--bg2);
}
.live-meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-right: 4px;
}
.live-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.25;
}
.live-region {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.2;
  min-height: 1.2em;
}
.player-toolbar .badge {
  flex: 0 0 auto;
  margin-left: 0;
  margin-right: 4px;
  white-space: nowrap;
}

#page-record {
  min-height: 0;
}
.record-bar {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.record-bar input,
.record-bar #rec-date,
#rec-speed {
  width: auto;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg2);
  color: var(--text);
  font-size: 14px;
}
.rec-channel {
  flex: 1;
  min-width: 120px;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rec-tip {
  flex: 0 0 auto;
  margin: 0 0 8px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--muted);
  background: var(--bg2);
  border: 1px dashed var(--line);
  border-radius: 8px;
}
.record-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}
.rec-player-wrap {
  flex: 0 0 auto;
  order: -1;
}
.rec-video {
  width: 100%;
  max-width: 720px;
  max-height: 42vh;
  aspect-ratio: 4 / 3;
}
/* 录像：选通道态显示资源树；结果态占满内容区 */
.layout.rec-result .sidebar {
  display: none;
}
.layout.rec-result .content {
  flex: 1 1 auto;
}
.rec-progress {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.rec-progress input[type="range"] {
  flex: 1;
  margin: 0;
  min-width: 0;
  accent-color: var(--accent);
}
.rec-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
}
.rec-item {
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.rec-item:hover,
.rec-item.active { background: var(--bg3); border-color: var(--line); }
.rec-item .t { color: var(--muted); font-size: 12px; margin-top: 4px; }
.rec-item-body { flex: 1; min-width: 0; }
.rec-dl { flex: 0 0 auto; padding: 6px 10px; font-size: 12px; }
#rec-speed { width: 80px; }

.mine-block {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.mine-block h3 { margin: 0 0 10px; font-size: 15px; }
#page-mine { overflow-y: auto; }
.simple-list .item {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 14px;
}
.simple-list .item:last-child { border-bottom: 0; }
.simple-list .empty { color: var(--muted); font-size: 13px; }

.tabbar {
  flex: 0 0 auto;
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--bg2);
  padding-bottom: var(--safe-b);
  min-height: var(--tabbar-h);
}
.tabbar .tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 12px 0;
  font-size: 14px;
  cursor: pointer;
}
.tabbar .tab.active {
  color: var(--accent);
  font-weight: 700;
}

/* 手机：上视频(4:3) → 搜索 → 区域/通道 */
@media (max-width: 860px) {
  .topbar { display: none; }
  .menu-chip { display: none; }
  .layout {
    flex-direction: column;
  }
  .content {
    order: 1;
    flex: 0 0 auto;
    max-height: none;
  }
  .sidebar {
    order: 2;
    width: 100%;
    flex: 1 1 auto;
    border-right: 0;
    border-top: 1px solid var(--line);
    position: relative;
    transform: none;
    box-shadow: none;
  }
  .page { padding: 8px; }
  .player-panel { flex: none; }
  .player-stage { flex: none; padding: 8px; }
  .player-box {
    width: 100%;
    max-width: 100%;
    aspect-ratio: 4 / 3;
  }
  .rec-video { max-height: 36vh; }
  .top-actions .btn.ghost { color: var(--header-text); }

  /* 录像选通道：顶栏查询条 + 下方整块资源树 */
  .layout.rec-pick .content {
    order: 1;
    flex: 0 0 auto;
  }
  .layout.rec-pick .sidebar {
    order: 2;
    flex: 1 1 auto;
    border-top: 1px solid var(--line);
  }
  .layout.rec-pick #page-record {
    padding-bottom: 0;
  }
  .layout.rec-result .content {
    order: 1;
    flex: 1 1 auto;
    min-height: 0;
  }
  .layout.rec-result #page-record {
    min-height: 0;
  }
  .layout.rec-result .record-body {
    flex: 1;
  }
  .layout.rec-result .rec-list {
    flex: 1;
  }
}

a { color: var(--accent); text-decoration: none; }
