:root {
  --bg: #0a0d12;
  --bg-2: #0f141b;
  --panel: #151b24;
  --panel-2: #1b222d;
  --panel-3: #212a36;
  --border: #283140;
  --border-strong: #3a4658;
  --text: #e8eef6;
  --muted: #8b97a8;
  --faint: #5c6675;
  --accent: #3b8eff;
  --accent-2: #1f6feb;
  --accent-glow: rgba(59, 142, 255, .35);
  --cyan: #56d4dd;
  --ok: #3fb950;
  --warn: #d6a017;
  --err: #f85149;
  --radius: 11px;
  --grad-accent: linear-gradient(135deg, #4b97ff 0%, #1f6feb 100%);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, .45);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, .6);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(1000px 500px at 85% -15%, rgba(31, 111, 235, .14), transparent 60%),
    radial-gradient(900px 500px at 0% 0%, rgba(86, 212, 221, .07), transparent 55%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  background-attachment: fixed;
  /* 整页占满视口、不滚动；宫格区域自适应填充 */
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
button, input, select { font-family: inherit; }

/* 自定义滚动条 */
* { scrollbar-width: thin; scrollbar-color: #38424f transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: #38424f; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #4a5666; background-clip: content-box; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: rgba(15, 20, 27, .72);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .03), 0 8px 24px -12px rgba(0, 0, 0, .6);
  flex: none;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: .3px;
}
.brand .logo {
  font-size: 17px;
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--grad-accent);
  border-radius: 10px;
  box-shadow: 0 4px 14px -2px var(--accent-glow);
}
.brand .count {
  font-size: 12px;
  font-weight: 600;
  color: #add0ff;
  background: rgba(59, 142, 255, .12);
  border: 1px solid rgba(59, 142, 255, .3);
  padding: 2px 10px;
  border-radius: 999px;
}
.toolbar { display: flex; align-items: center; gap: 11px; flex-wrap: wrap; }
.field { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }

/* 分段按钮 */
.seg {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .03);
}
.seg button {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 7px 13px;
  font-size: 13px;
  cursor: pointer;
  transition: .18s;
}
.seg button:hover { color: var(--text); background: var(--panel-2); }
.seg button.active {
  background: var(--grad-accent);
  color: #fff;
  box-shadow: 0 2px 10px -2px var(--accent-glow);
}

.pager { display: inline-flex; align-items: center; gap: 6px; }
.pager .btn { padding: 6px 11px; }
.pager #pageInfo { font-size: 13px; color: var(--muted); min-width: 36px; text-align: center; font-variant-numeric: tabular-nums; }

select, input {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
select:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 13px;
  font-size: 13px;
  cursor: pointer;
  transition: .16s ease;
}
.btn:hover { background: var(--panel-2); border-color: var(--border-strong); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary {
  background: var(--grad-accent);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 16px -4px var(--accent-glow);
}
.btn.primary:hover { filter: brightness(1.08); box-shadow: 0 6px 20px -4px var(--accent-glow); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); transform: none; }
.btn.danger { color: #ff8e88; border-color: rgba(248, 81, 73, .4); background: transparent; }
.btn.danger:hover { background: rgba(248, 81, 73, .14); border-color: rgba(248, 81, 73, .6); }
.btn.block { width: 100%; justify-content: center; padding: 11px; }

/* ---------- 宫格（占满视口，自适应不滚动） ---------- */
.grid { display: grid; gap: 0; padding: 0; flex: 1; min-height: 0; overflow: hidden; }
.grid-1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }                 /* 单画面：满宽满高 */
.grid-2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }            /* 双画面：左右各半 */
.grid-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }        /* 2×2 */
.grid-6 { grid-template-columns: repeat(3, 1fr); grid-template-rows: 1fr 1fr; } /* 3×2 */
/* 所有格子填满各自轨道 */
.grid .cell { aspect-ratio: auto; height: 100%; min-height: 0; border-radius: 0; }
@media (max-width: 760px) {
  body { overflow-x: hidden; }

  /* 顶栏：品牌一行，工具条换到第二行整行排布 */
  .topbar { padding: 9px 12px; gap: 9px; }
  .brand { font-size: 15px; gap: 8px; }
  .brand .logo { width: 30px; height: 30px; font-size: 15px; }
  .toolbar { width: 100%; gap: 8px; }
  .field span { display: none; }           /* 隐藏 "RTSP/RTMP" 文字省空间 */
  .seg button { padding: 8px 10px; }
  .btn { padding: 9px 12px; }              /* 更大的触摸目标 */

  /* 触屏没有 hover：每格控件常驻并加大 */
  .cell .ctrls { opacity: 1; gap: 8px; }
  .cbtn { width: 36px; height: 36px; font-size: 16px; }

  /* 抽屉满宽 */
  .drawer { width: 100%; }
  .aset-grid { grid-template-columns: 1fr; }

  /* 弹窗：底部抽屉式，满宽可滚动 */
  .modal-mask { padding: 0; align-items: flex-end; }
  .modal, .pb-modal { width: 100%; max-width: 100%; max-height: 90vh; border-radius: 16px 16px 0 0; }
  .form-grid { grid-template-columns: 1fr; }
  .pb-video { max-height: 42vh; }
  .pb-imgbar { flex-wrap: wrap; }
  .pb-imgbar .pb-range { flex-basis: 100%; order: 9; }
  .pb-seglist { max-height: 30vh; }

  /* iOS 输入聚焦不自动放大：字号需 ≥16px */
  input, select { font-size: 16px; }

  /* toast 横向自适应 */
  .toast { left: 12px; right: 12px; bottom: 16px; transform: translateY(20px); }
  .toast.show { transform: translateY(0); }
}

/* 超窄屏进一步收紧 */
@media (max-width: 380px) {
  .seg button { padding: 7px 8px; font-size: 12px; }
  .brand .count { display: none; }
}

.cell {
  position: relative;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  cursor: pointer;
  transition: border-color .2s, transform .2s, box-shadow .2s;
  animation: cellIn .35s cubic-bezier(.22, 1, .36, 1) both;
}
.cell:hover {
  border-color: rgba(59, 142, 255, .55);
  box-shadow: inset 0 0 0 1px rgba(59, 142, 255, .35);
}
@keyframes cellIn { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
.cell video, .cell img {
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}
.fit-cover .cell video, .fit-cover .cell img { object-fit: cover; }

.cell .overlay {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 16px 12px 9px;
  font-size: 12.5px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .78));
  pointer-events: none;
}
.cell .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--warn); color: var(--warn);
  box-shadow: 0 0 7px currentColor;
  flex: none;
}
.cell .dot.live { background: var(--ok); color: var(--ok); animation: pulse 1.8s ease-in-out infinite; }
.cell .dot.fail { background: var(--err); color: var(--err); animation: none; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(63, 185, 80, .5); }
  50% { box-shadow: 0 0 0 5px rgba(63, 185, 80, 0); }
}
.cell .name { font-weight: 600; text-shadow: 0 1px 3px rgba(0, 0, 0, .8); }
.cell .tag {
  position: absolute; left: 9px; top: 9px;
  font-size: 10px; padding: 3px 8px; border-radius: 7px;
  background: rgba(10, 14, 20, .6); color: #9fcaff;
  border: 1px solid rgba(121, 192, 255, .25);
  backdrop-filter: blur(4px);
  letter-spacing: .3px;
}
.cell .ctrls {
  position: absolute; right: 9px; top: 9px;
  display: flex; gap: 6px;
  opacity: 0; transform: translateY(-4px); transition: opacity .18s, transform .18s;
}
.cell:hover .ctrls { opacity: 1; transform: none; }
.cbtn {
  width: 31px; height: 31px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 14, 20, .6); color: #fff;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 8px; cursor: pointer; font-size: 15px; line-height: 1;
  backdrop-filter: blur(4px); transition: .15s;
}
.cbtn:hover { background: var(--accent-2); border-color: var(--accent); transform: translateY(-1px); }
.cell:fullscreen { border: none; border-radius: 0; }
.cell:fullscreen video, .cell:fullscreen img { object-fit: contain; }

.cell .state {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 10px;
  color: var(--muted); font-size: 13px; text-align: center; padding: 12px;
  background: radial-gradient(circle at center, rgba(21, 27, 36, .5), rgba(0, 0, 0, .25));
}
.cell .state.err { color: #ff9c96; }
.cell .state.err > div:first-child { font-size: 22px; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .12);
  border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  align-self: center;
  text-align: center;
  color: var(--muted);
  padding: 72px 20px;
  font-size: 14px;
  line-height: 2;
}

/* ---------- 抽屉 ---------- */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: .22s; z-index: 30;
}
.drawer-mask.show { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%;
  width: 384px; max-width: 90vw;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform .3s cubic-bezier(.22, 1, .36, 1);
  box-shadow: var(--shadow-lg);
  z-index: 31;
  display: flex; flex-direction: column;
}
.drawer.show { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 17px 20px; border-bottom: 1px solid var(--border);
}
.drawer-head h2 { margin: 0; font-size: 16px; font-weight: 650; }
.drawer-body { padding: 18px 20px; overflow-y: auto; }
.config-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.config-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
  transition: border-color .15s, transform .15s;
}
.config-item:hover { border-color: var(--border-strong); transform: translateX(-2px); }
.config-item .row1 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.config-item .nm { font-weight: 600; }
.config-item .id { font-size: 12px; color: var(--faint); margin-top: 2px; font-family: ui-monospace, monospace; }
.config-item .badge {
  font-size: 10px; padding: 3px 8px; border-radius: 7px;
  background: rgba(59, 142, 255, .12); color: #9fcaff;
  border: 1px solid rgba(121, 192, 255, .25); white-space: nowrap;
}
.config-item .acts { display: flex; gap: 6px; margin-top: 11px; }
.config-item .acts .btn { padding: 6px 12px; font-size: 12px; }

/* ---------- 弹窗表单 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; z-index: 40;
  padding: 20px;
}
.modal-mask.show { display: flex; animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 460px; max-width: 100%; max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn .25s cubic-bezier(.22, 1, .36, 1);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 17px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 650; }
.modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; }
.form-row { display: flex; flex-direction: column; gap: 7px; font-size: 13px; }
.form-row > span { color: var(--muted); display: flex; align-items: baseline; gap: 8px; }
.form-row > span i { font-style: normal; font-size: 11px; color: var(--faint); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint {
  font-size: 12px; color: var(--muted); line-height: 1.7;
  background: rgba(59, 142, 255, .07); border: 1px solid rgba(59, 142, 255, .22);
  border-radius: 9px; padding: 11px 13px; display: none;
}
.hint.show { display: block; }
.hint code {
  color: #9fcaff; background: rgba(0, 0, 0, .35);
  padding: 2px 6px; border-radius: 5px; word-break: break-all;
  font-family: ui-monospace, monospace;
}
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.drawer-sep { height: 1px; background: var(--border); margin: 18px 0; }

/* ---------- 登录 ---------- */
.login-mask {
  position: fixed; inset: 0; z-index: 60;
  display: none; align-items: center; justify-content: center;
  overflow: hidden;
  background:
    radial-gradient(800px 500px at 50% -5%, rgba(31, 111, 235, .25), transparent 60%),
    radial-gradient(600px 400px at 80% 100%, rgba(86, 212, 221, .12), transparent 60%),
    linear-gradient(180deg, #0f141b, #070a0e);
}
.login-mask.show { display: flex; }
.login-mask::before {
  content: ""; position: absolute; width: 480px; height: 480px;
  background: radial-gradient(circle, var(--accent-glow), transparent 70%);
  filter: blur(40px); opacity: .5;
  animation: floatGlow 8s ease-in-out infinite;
}
@keyframes floatGlow {
  0%, 100% { transform: translate(-120px, -90px); }
  50% { transform: translate(120px, 60px); }
}
.login-card {
  position: relative;
  width: 330px; max-width: 90vw;
  background: rgba(21, 27, 36, .85);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 20px; padding: 36px 30px;
  display: flex; flex-direction: column; gap: 13px;
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, .06);
  text-align: center;
  animation: modalIn .4s cubic-bezier(.22, 1, .36, 1);
}
.login-logo {
  font-size: 30px; width: 64px; height: 64px; margin: 0 auto 4px;
  display: flex; align-items: center; justify-content: center;
  background: var(--grad-accent); border-radius: 18px;
  box-shadow: 0 10px 30px -6px var(--accent-glow);
  animation: floatLogo 3.5s ease-in-out infinite;
}
@keyframes floatLogo { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.login-card h2 { margin: 4px 0 0; font-size: 20px; font-weight: 650; }
.login-sub { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.login-card input { width: 100%; padding: 12px 13px; text-align: left; }
.login-card .btn { margin-top: 6px; padding: 12px; font-size: 14px; }
.login-err { color: var(--err); font-size: 13px; min-height: 18px; }

/* ---------- 表单复选 ---------- */
.form-check {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; color: var(--text); cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 10px 12px;
}
.form-check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ---------- 抽屉里的子标题 / 告警面板 ---------- */
.drawer-sub { margin: 0 0 12px; font-size: 14px; font-weight: 650; color: var(--text); }
.aset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.ach-list { display: flex; flex-direction: column; gap: 8px; }
.ach-item { display: flex; align-items: center; gap: 8px; }
.ach-type { font-size: 11px; color: #9fcaff; white-space: nowrap; width: 62px; }
.ach-val { flex: 1; min-width: 0; }
.ach-item .ach-del { padding: 6px 9px; }
.ach-add { display: flex; gap: 8px; margin: 10px 0 0; }
.ach-add select { flex: 1; }
.hint2 { font-size: 12px; color: var(--faint); padding: 4px 0; }
.hint2 code { color: #9fcaff; background: rgba(0,0,0,.25); padding: 1px 4px; border-radius: 4px; }

/* 系统设置：隐藏数字输入框的上下微调箭头 */
#settingsDrawer input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
#settingsDrawer input[type="number"]::-webkit-outer-spin-button,
#settingsDrawer input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* 系统设置：分区卡片 */
.set-sec {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.set-h { margin: 0 0 12px; font-size: 13px; font-weight: 650; color: var(--text); }
.set-note { margin-top: 10px; font-size: 12px; color: var(--muted); line-height: 1.7; }
.set-note .rec-dir {
  color: #9fcaff; background: rgba(0,0,0,.3);
  padding: 2px 6px; border-radius: 5px; word-break: break-all;
  font-family: ui-monospace, monospace;
}

/* ---------- 回放弹窗 ---------- */
.pb-modal { width: 720px; }
.pb-video { width: 100%; max-height: 56vh; background: #000; border-radius: 10px; display: block; }
.pb-seglist { display: flex; flex-wrap: wrap; gap: 8px; max-height: 160px; overflow-y: auto; }
.pb-seg { font-size: 12px; padding: 6px 10px; }
.pb-seg.active { background: var(--grad-accent); border-color: transparent; color: #fff; }
.pb-imgwrap { background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 16/9; display: flex; align-items: center; justify-content: center; }
.pb-img { max-width: 100%; max-height: 100%; display: block; }
.pb-imgbar { display: flex; align-items: center; gap: 10px; }
.pb-imgbar .pb-date { min-width: 130px; }
.pb-imgbar .pb-range { flex: 1; accent-color: var(--accent); }
.pb-imgbar .pb-time { font-size: 12px; color: var(--muted); min-width: 70px; font-variant-numeric: tabular-nums; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(27, 34, 45, .95); border: 1px solid var(--border);
  backdrop-filter: blur(8px);
  color: var(--text); padding: 11px 20px; border-radius: 11px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .25s cubic-bezier(.22, 1, .36, 1); z-index: 50;
  box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: rgba(63, 185, 80, .5); box-shadow: var(--shadow-md), 0 0 0 1px rgba(63, 185, 80, .2); }
.toast.err { border-color: rgba(248, 81, 73, .5); box-shadow: var(--shadow-md), 0 0 0 1px rgba(248, 81, 73, .2); }
