:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #232738;
  --border: #2d3148;
  --accent: #4f8ef7;
  --accent-dim: #2d5abf;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --text: #e2e8f0;
  --text-dim: #8892a4;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

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

/* ── 顶栏 ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.topbar .logo { font-weight: 700; font-size: 16px; color: var(--accent); }
.topbar .spacer { flex: 1; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.badge.on  { background: #14532d; color: var(--green); }
.badge.off { background: #450a0a; color: var(--red); }
.badge.warn{ background: #451a03; color: var(--yellow); }

/* ── 布局 ── */
.layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
  padding: 16px 20px;
  max-width: 1400px;
  margin: 0 auto;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

/* ── 卡片 ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 13px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .05em;
}
.card-body { padding: 16px; }

/* ── 视频 ── */
#video-wrap {
  position: relative;
  background: #000;
  border-radius: 0;
  min-height: 240px;
  display: flex; align-items: center; justify-content: center;
}
#video-wrap img, #video-wrap video {
  width: 100%; height: auto; display: block;
  max-height: 520px; object-fit: contain;
}
.stream-overlay {
  position: absolute; bottom: 10px; right: 12px;
  display: flex; gap: 6px;
}
.stream-overlay button {
  background: rgba(0,0,0,.6); border: 1px solid rgba(255,255,255,.2);
  color: #fff; padding: 4px 10px; border-radius: 6px;
  cursor: pointer; font-size: 12px;
}
.stream-overlay button:hover { background: rgba(79,142,247,.4); }
#stream-status {
  position: absolute; top: 10px; left: 12px;
  font-size: 12px; padding: 2px 8px;
  border-radius: 4px; font-weight: 600;
}
.stream-status-live { background: rgba(34,197,94,.2); color: var(--green); }
.stream-status-off  { background: rgba(239,68,68,.2); color: var(--red); }
.stream-status-reconnecting { background: rgba(245,158,11,.2); color: var(--yellow); }

/* ── 环境卡片 ── */
.env-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.env-item { text-align: center; }
.env-val { font-size: 28px; font-weight: 700; line-height: 1.1; }
.env-label { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.env-co2 { color: #fb923c; }
.env-temp { color: #60a5fa; }
.env-humi { color: #34d399; }
.env-rssi { color: #a78bfa; }
.env-offline { color: var(--red); font-size: 12px; text-align: center; padding: 12px; }

#env-chart-wrap {
  margin-top: 12px;
  height: 120px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

/* ── 表单控件 ── */
.form-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px;
}
.form-row label { color: var(--text-dim); min-width: 110px; font-size: 13px; }
.form-row select, .form-row input[type=text],
.form-row input[type=number], .form-row input[type=time] {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
}
.form-row select:focus, .form-row input:focus { outline: none; border-color: var(--accent); }

/* ── 按钮 ── */
.btn {
  padding: 7px 16px; border-radius: 7px; border: none;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger  { background: var(--red); color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-muted   { background: var(--surface2); color: var(--text-dim); border: 1px solid var(--border); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Token 表格 ── */
.token-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.token-table th { text-align: left; padding: 6px 8px; color: var(--text-dim); border-bottom: 1px solid var(--border); }
.token-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); }
.token-table tr:last-child td { border-bottom: none; }
.token-url {
  font-family: monospace; font-size: 11px;
  background: var(--surface2); padding: 2px 6px; border-radius: 4px;
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: inline-block; vertical-align: middle;
}
.expired-tag { color: var(--red); font-size: 11px; }

/* ── 画廊 ── */
.gallery-days { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.day-btn {
  padding: 5px 12px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); cursor: pointer; font-size: 12px;
}
.day-btn.active { border-color: var(--accent); color: var(--accent); }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}
.thumb-wrap {
  aspect-ratio: 4/3;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
  position: relative;
}
.thumb-wrap img { width: 100%; height: 100%; object-fit: cover; }
.thumb-info {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.65); padding: 2px 5px;
  font-size: 10px; color: #ccc;
}
.thumb-del {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,.65); border: 1px solid rgba(255,255,255,.2);
  color: #fff; font-size: 16px; line-height: 18px; cursor: pointer;
  opacity: 0; transition: opacity .15s, background .15s;
}
.thumb-wrap:hover .thumb-del { opacity: 1; }
.thumb-del:hover { background: var(--red); }

/* ── 大图模态 ── */
#lightbox {
  display: none;
  position: fixed; inset: 0; z-index: 999;
  background: rgba(0,0,0,.9);
  align-items: center; justify-content: center;
}
#lightbox.open { display: flex; }
#lightbox img { max-width: 95vw; max-height: 88vh; border-radius: 8px; }
#lightbox-close {
  position: absolute; top: 16px; right: 20px;
  color: #fff; font-size: 28px; cursor: pointer; font-weight: 300;
}
#lightbox-del {
  position: absolute; top: 16px; left: 20px;
}

/* ── 侧栏 tabs ── */
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab-btn {
  padding: 8px 16px; background: none; border: none;
  color: var(--text-dim); cursor: pointer; font-size: 13px; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── 分隔线 ── */
.sep { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* ── 音频 ── */
audio { width: 100%; margin-top: 8px; filter: invert(.9) hue-rotate(180deg); }

/* ── 吐司提示 ── */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--surface2); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow);
  opacity: 0; transition: opacity .25s;
  pointer-events: none; z-index: 9999;
}
#toast.show { opacity: 1; }

/* ── online / offline dot ── */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.on  { background: var(--green); }
.dot.off { background: var(--red); }

/* ── 留言板 ── */
.comments-list {
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  padding-right: 2px;
}
.comments-list:empty::after {
  content: "还没有留言，来说第一句话吧 ~";
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 20px 0;
  display: block;
}
.comment-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.comment-item.mine {
  border-color: var(--accent-dim);
}
.comment-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-dim);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.comment-avatar.admin-av { background: #5b21b6; }
.comment-body { flex: 1; min-width: 0; }
.comment-meta {
  display: flex; align-items: baseline; gap: 6px; margin-bottom: 3px;
}
.comment-author { font-size: 12px; font-weight: 600; color: var(--text); }
.comment-role-tag {
  font-size: 10px; padding: 1px 5px; border-radius: 4px;
  background: #5b21b6; color: #e9d5ff;
}
.comment-time { font-size: 11px; color: var(--text-dim); margin-left: auto; }
.comment-text { font-size: 13px; color: var(--text); word-break: break-word; line-height: 1.5; }
.comment-del {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 14px; padding: 2px 4px; border-radius: 4px;
  opacity: 0; transition: opacity .15s;
  flex-shrink: 0; line-height: 1;
}
.comment-item:hover .comment-del { opacity: 1; }
.comment-del:hover { color: var(--red); background: rgba(239,68,68,.1); }
.comment-input-row {
  display: flex; gap: 8px; align-items: flex-end;
}
.comment-input-row textarea {
  flex: 1;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; resize: none;
  min-height: 60px; font-family: inherit; line-height: 1.4;
  transition: border-color .15s;
}
.comment-input-row textarea:focus { outline: none; border-color: var(--accent); }
.comment-input-row textarea::placeholder { color: var(--text-dim); }
.comment-char { font-size: 11px; color: var(--text-dim); text-align: right; margin-top: 3px; }

/* token 状态 */
.active-tag  { color: var(--green); font-size: 11px; }
.expired-tag { color: var(--red);   font-size: 11px; }
