:root {
  --bg: #0f1115;
  --card: #171a21;
  --card-2: #1d2129;
  --line: #262b35;
  --text: #e8eaed;
  --muted: #98a0ad;
  --accent: #3b82f6;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app {
  min-height: 100vh;
  padding: max(12px, env(safe-area-inset-top)) 12px calc(24px + env(safe-area-inset-bottom));
  max-width: 900px;
  margin: 0 auto;
}

/* ---------- 顶部 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px 14px;
}
.brand { font-size: 17px; font-weight: 600; letter-spacing: .3px; }
.brand small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; margin-top: 2px; }
.topbar .who { color: var(--muted); font-size: 13px; }
.topbar .actions { display: flex; gap: 8px; }

/* ---------- 按钮 ---------- */
button {
  font: inherit;
  color: var(--text);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
}
button:active { transform: scale(.98); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- 卡片区 ---------- */
.section-title {
  margin: 14px 2px 10px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.door-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 620px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.tile {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 10;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .name {
  position: absolute; left: 8px; bottom: 8px;
  background: rgba(0,0,0,.55);
  padding: 3px 8px; border-radius: 8px;
  font-size: 12px; color: #fff;
}
.tile.empty {
  border-style: dashed;
  color: #5b6371;
  cursor: default;
}
.tile .live-dot {
  position: absolute; right: 8px; top: 8px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(34,197,94,.18);
}

.door-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.door-card .preview {
  aspect-ratio: 16 / 10;
  background: #12151b;
  display: flex; align-items: center; justify-content: center;
  color: #5b6371; font-size: 12px;
  cursor: pointer;
  position: relative;
}
.door-card .preview img { width: 100%; height: 100%; object-fit: cover; }
.door-card .meta { padding: 10px 12px 12px; }
.door-card .meta h3 { margin: 0 0 8px; font-size: 15px; font-weight: 600; }
.door-card .meta .loc { color: var(--muted); font-size: 12px; margin: -4px 0 8px; }

.open-btn {
  width: 100%;
  height: 56px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 12px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  position: relative;
  overflow: hidden;
}
.open-btn .fill {
  position: absolute; inset: 0; width: 0%;
  background: rgba(255,255,255,.25);
  transition: width .45s linear;
}
.open-btn span { position: relative; }

/* ---------- 登录 ---------- */
.auth-wrap {
  max-width: 380px;
  margin: 12vh auto 0;
  padding: 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.auth-wrap h1 { font-size: 20px; margin: 0 0 4px; }
.auth-wrap p.sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 12px 13px;
  font-size: 15px;
  color: var(--text);
  background: #10131a;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
.field input:focus { border-color: var(--accent); }
.auth-wrap button.primary { width: 100%; height: 46px; margin-top: 6px; }
.hint { margin-top: 12px; font-size: 12px; color: var(--muted); }
.hint a, .link { color: var(--accent); text-decoration: none; cursor: pointer; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---------- 管理 ---------- */
.tabs { display: flex; gap: 8px; margin: 8px 0 16px; flex-wrap: wrap; }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.panel h3 { margin: 0 0 12px; font-size: 15px; }

.row { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; border: 1px solid var(--line); color: var(--muted);
}
.badge.ok { color: var(--ok); border-color: rgba(34,197,94,.4); }
.badge.bad { color: var(--danger); border-color: rgba(239,68,68,.4); }

.toast {
  position: fixed;
  left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #23272f;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 50;
  max-width: 88vw;
  text-align: center;
}
.toast.ok { border-color: rgba(34,197,94,.5); }
.toast.bad { border-color: rgba(239,68,68,.5); }

/* ---------- 全屏查看 ---------- */
.viewer {
  position: fixed; inset: 0; background: #000; z-index: 40;
  display: flex; flex-direction: column;
}
.viewer .vhead {
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  display: flex; justify-content: space-between; align-items: center;
  color: var(--muted); font-size: 13px;
}
.viewer .vbody { flex: 1; display: flex; align-items: center; justify-content: center; }
.viewer .vbody video, .viewer .vbody .ph { width: 100%; height: 100%; object-fit: contain; }
.viewer .vbody .ph { display: flex; align-items: center; justify-content: center; color: #5b6371; }
.viewer .vfoot { padding: 12px 12px calc(16px + env(safe-area-inset-bottom)); }

.center-note { text-align: center; color: var(--muted); font-size: 13px; padding: 28px 8px; }

/* 实时画面的状态浮层 */
.vstatus {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,.6);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  max-width: 80%;
  text-align: center;
}
.vbody { position: relative; }

.live-badge {
  font-style: normal;
  font-size: 11px;
  color: #fff;
  background: var(--danger);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
  vertical-align: 1px;
}
