/* 云变频主题（手机优先，桌面宽屏自适应）— 客户端 dashboard 与登录页使用 */

:root {
  --primary: #1677ff;
  --primary-dark: #0958d9;
  --primary-light: #e6f4ff;
  --red: #f2564d;
  --bg: #efefef;
  --card: #ffffff;
  --text: #333333;
  --text-sub: #999999;
  --line: #e5e5e5;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- 顶部导航 ---------- */
.nav {
  position: sticky; top: 0; z-index: 100;
  height: 46px;
  background: var(--card);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 600;
  border-bottom: 1px solid var(--line);
}

/* ---------- 主体容器：手机全宽，桌面居中窄幅 ---------- */
.wrap {
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 12px 32px;
}

/* ---------- 工具行 ---------- */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 2px 12px;
}
.toolbar-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 16px; font-weight: 700;
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toolbar-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid #dcdcdc;
  background: var(--card);
  color: #555;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 17px;
}
.icon-btn:active { background: #f4f4f4; }

/* ---------- 语言切换（中文 / English） ---------- */
.lang-toggle {
  min-width: 36px; height: 36px; padding: 0 8px;
  border-radius: 18px;
  border: 1px solid #dcdcdc;
  background: var(--card);
  color: #555;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.lang-toggle:active { background: #f4f4f4; }

/* ---------- 语言选择页 ---------- */
.lang-page {
  max-width: 460px;
  margin: 0 auto;
  padding: 20px 16px;
}
.lang-title {
  font-size: 16px; color: var(--text);
  text-align: center; margin-bottom: 14px;
}
.lang-row {
  width: 100%; height: 48px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; margin-bottom: 8px;
  border: 1px solid #dcdcdc; border-radius: 10px;
  background: var(--card);
  font-size: 15px; color: var(--text);
  cursor: pointer;
}
.lang-row:active { background: #f4f4f4; }
.lang-row.active { border-color: var(--primary); color: var(--primary-dark); }
.lang-check { color: var(--primary); font-weight: 700; }

.searchbar { padding-bottom: 12px; }
.searchbar input {
  width: 100%; height: 40px;
  border: 1px solid #dcdcdc; border-radius: 20px;
  background: var(--card);
  padding: 0 16px; font-size: 14px;
  outline: none;
}
.searchbar input:focus { border-color: var(--primary); }

/* ---------- 空状态 ---------- */
.empty {
  text-align: center;
  padding: 46px 0 30px;
}
.empty p { color: var(--text-sub); font-size: 15px; margin-top: 14px; }

.add-btn {
  margin-top: 34px;
  width: 86%; height: 48px;
  border: 1px solid #d6d6d6; border-radius: 24px;
  background: var(--card);
  color: var(--text); font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer;
}
.add-btn:active { background: #f4f4f4; }

/* ---------- 设备卡片 ---------- */
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 14px 14px 12px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}

.card-head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px;
}
.dev-logo {
  width: 42px; height: 42px; flex: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #4096ff, #0958d9);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.dev-info { flex: 1; min-width: 0; }
.dev-name {
  font-size: 15px; font-weight: 700; color: var(--primary-dark);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dev-sub {
  display: flex; align-items: center; gap: 6px; row-gap: 3px;
  flex-wrap: wrap;
  margin-top: 2px; min-width: 0;
}
.dev-imei { font-size: 12px; color: var(--text-sub); font-family: Consolas, monospace; white-space: nowrap; }

.badge {
  flex: none;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
}
.badge-online  { color: var(--primary-dark); background: var(--primary-light); }
.badge-offline { color: #999; background: #f0f0f0; }
.badge-unknown { color: #b8860b; background: #faf0d7; }

/* 连接控件（卡片头部右侧） */
.link-slot {
  flex: none; min-width: 58px;
  display: flex; justify-content: flex-end; align-items: center;
}
.link-btn {
  border: 1px solid var(--primary);
  background: var(--card);
  color: var(--primary-dark);
  font-size: 13px;
  padding: 4px 13px;
  border-radius: 15px;
  cursor: pointer;
  white-space: nowrap;
}
.link-btn:active { background: var(--primary-light); }
.link-btn.off {
  border-color: var(--red); color: var(--red);
}
.link-btn.off:active { background: #fdeceb; }
.link-btn.busy {
  border-color: #dcdcdc; color: #999; cursor: default;
}

/* 蓝色状态条 */
.statbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: linear-gradient(135deg, #4096ff, #1668dc);
  border-radius: 10px;
  padding: 10px 0;
  text-align: center;
  color: #fff;
}
.stat-val { font-size: 16px; font-weight: 700; line-height: 1.3; }
.stat-val .unit { font-size: 11px; font-weight: 400; opacity: .9; margin-left: 1px; }
.stat-label { font-size: 11px; opacity: .85; margin-top: 2px; white-space: nowrap; }
.stat-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #fff; margin-right: 4px; vertical-align: 1px;
}
.stat-dot.off { background: rgba(255,255,255,.45); }

/* 底部操作行 */
.actions {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  margin-top: 12px;
  text-align: center;
}
.act {
  border: none; background: none;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  cursor: pointer;
  font-size: 12px; color: #666;
  padding: 2px 0;
  min-width: 0;
  white-space: normal; overflow-wrap: break-word; text-align: center;
}
.act-circle {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid #dcdcdc;
  background: var(--card);
  color: #666;
  display: flex; align-items: center; justify-content: center;
}
.act:active .act-circle { transform: scale(.94); }
.act-circle.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.act-circle.red   { background: var(--red); border-color: var(--red); color: #fff; }

/* 监控展开区 */
.monitor {
  margin-top: 12px;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}
.mon-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin-bottom: 10px;
}
.mon-item {
  background: #f7f7f7; border-radius: 8px;
  padding: 8px 6px; text-align: center;
}
.mon-item .k { font-size: 11px; color: var(--text-sub); }
.mon-item .v { font-size: 14px; font-weight: 600; margin-top: 2px; }
.log {
  background: #1e1e1e; color: #d4d4d4;
  border-radius: 8px;
  font-family: Consolas, monospace; font-size: 11px;
  height: 110px; overflow-y: auto;
  padding: 8px 10px;
  white-space: pre-wrap; word-break: break-all;
}

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal-mask[hidden] { display: none; }
.modal {
  width: 100%; max-width: 340px;
  background: var(--card);
  border-radius: 14px;
  padding: 20px 18px 16px;
}
.modal h3 { font-size: 17px; text-align: center; }
.modal-tip { font-size: 12px; color: var(--text-sub); text-align: center; margin: 8px 0 14px; }
.modal input {
  width: 100%; height: 44px;
  border: 1px solid #dcdcdc; border-radius: 8px;
  padding: 0 12px; font-size: 16px;
  outline: none;
}
.modal input:focus { border-color: var(--primary); }
.modal input.mono { font-family: Consolas, monospace; letter-spacing: 1px; }
.modal-msg { font-size: 12px; min-height: 18px; margin-top: 8px; text-align: center; }
.modal-msg.ok { color: var(--primary); }
.modal-msg.error { color: var(--red); }

/* 绑定弹窗：ID 输入 + 扫码按钮 */
.bind-row { display: flex; gap: 8px; }
.bind-row input { flex: 1; width: auto; min-width: 0; }
.scan-btn {
  flex: none; width: 44px; height: 44px;
  border: 1px solid #dcdcdc; border-radius: 8px;
  background: var(--card); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.scan-btn:active { background: var(--primary-light); }
.modal-btns {
  display: flex; gap: 10px; margin-top: 14px;
}
.modal-btns button {
  flex: 1; height: 42px;
  border-radius: 21px;
  font-size: 15px;
  cursor: pointer;
}
.btn-plain { border: 1px solid #d6d6d6; background: var(--card); color: #666; }
.btn-primary { border: none; background: var(--primary); color: #fff; }
.btn-primary:disabled { opacity: .55; }
.btn-danger-plain { border: 1px solid var(--red); background: var(--card); color: var(--red); }

/* 底部动作面板（更多操作） */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
  background: #f6f6f6;
  border-radius: 14px 14px 0 0;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  max-width: 520px; margin: 0 auto;
}
.sheet-mask { position: fixed; inset: 0; z-index: 190; background: rgba(0,0,0,.4); }
.sheet[hidden], .sheet-mask[hidden] { display: none; }
.sheet-item {
  display: block; width: 100%;
  height: 48px; margin-top: 8px;
  border: none; border-radius: 10px;
  background: var(--card); font-size: 15px; color: var(--text);
  cursor: pointer;
}
.sheet-item.danger { color: var(--red); }
.sheet-item:active { background: #ededed; }

/* 个人面板 */
.me-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px;
}
.me-row label { font-size: 14px; flex: none; }
.me-row input[type="tel"] {
  flex: 1; height: 40px;
  border: 1px solid #dcdcdc; border-radius: 8px;
  padding: 0 10px; font-size: 15px; outline: none;
}
.me-device {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 2px;
  border-top: 1px solid #f2f2f2;
  font-size: 13px;
}
.me-device .mono { font-family: Consolas, monospace; color: #666; }
.me-switches { display: flex; gap: 14px; }
.me-switches label { display: flex; align-items: center; gap: 4px; font-size: 12px; color: #666; white-space: nowrap; }
.me-section-title { font-size: 13px; color: var(--text-sub); margin: 12px 0 6px; }

/* ---------- 绑定审核（设备管理员/协管员） ---------- */
.req-card { padding: 14px 16px 6px; margin-bottom: 12px; }
.req-head { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.req-count {
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--red); color: #fff;
  font-size: 12px; line-height: 20px; text-align: center; font-weight: 600;
}
.req-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid #f2f2f2;
}
.req-row:last-child { border-bottom: none; }
.req-user { font-size: 14px; font-weight: 600; }
.req-dev { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.req-btns { display: flex; gap: 8px; flex: none; }
.req-btn { width: 62px; height: 32px; border-radius: 16px; font-size: 13px; cursor: pointer; }
.req-btn.ok { border: none; background: var(--primary); color: #fff; }
.req-btn.ok:active { opacity: .85; }
.req-btn.no { border: 1px solid #d6d6d6; background: var(--card); color: #666; }
.req-btn.no:active { background: #ededed; }

/* ---------- 设备成员管理 ---------- */
.member-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 0; border-bottom: 1px solid #f2f2f2; font-size: 14px;
}
.member-row:last-child { border-bottom: none; }
.m-name { font-weight: 600; margin-right: 8px; }
.m-badge {
  display: inline-block; font-size: 11px; padding: 1px 7px;
  border-radius: 9px; margin-right: 4px; vertical-align: 1px;
}
.m-badge.owner   { color: var(--primary-dark); background: var(--primary-light); }
.m-badge.coadmin { color: #b8860b; background: #faf0d7; }
.m-badge.member  { color: #666; background: #f0f0f0; }
.m-badge.wait    { color: var(--red); background: #fdeceb; }
.m-btn {
  border: 1px solid var(--primary); color: var(--primary-dark); background: var(--card);
  font-size: 12px; padding: 5px 10px; border-radius: 14px; cursor: pointer;
  flex: none;
}
.m-btn.off { border-color: #d6d6d6; color: #666; }
.members-empty { font-size: 12px; color: #999; text-align: center; padding: 10px 0; }

/* 设备卡片上的角色标签 */
.role-tag {
  font-size: 11px; padding: 1px 7px; border-radius: 9px;
  color: var(--primary-dark); background: var(--primary-light);
}
.role-tag.coadmin { color: #b8860b; background: #faf0d7; }

/* ---------- 扫码浮层（QrScan） ---------- */
.qs-mask {
  position: fixed; inset: 0; z-index: 400;
  background: #111;
  display: flex; flex-direction: column;
}
.qs-mask[hidden] { display: none; }
.qs-head {
  height: 48px; flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 0 16px;
  color: #fff; font-size: 16px;
}
.qs-close {
  border: none; background: none; color: #fff;
  font-size: 18px; padding: 10px 14px; cursor: pointer;
}
.qs-stage {
  position: relative; flex: 1;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.qs-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.qs-mask.no-live .qs-video { display: none; }
.qs-frame { position: relative; width: min(72vw, 270px); aspect-ratio: 1; }
.qs-frame .c { position: absolute; width: 26px; height: 26px; border: 3px solid var(--primary); }
.qs-frame .tl { top: 0; left: 0; border-right: none; border-bottom: none; }
.qs-frame .tr { top: 0; right: 0; border-left: none; border-bottom: none; }
.qs-frame .bl { bottom: 0; left: 0; border-right: none; border-top: none; }
.qs-frame .br { bottom: 0; right: 0; border-left: none; border-top: none; }
.qs-tip {
  flex: none; min-height: 20px;
  color: #bbb; font-size: 13px; text-align: center;
  padding: 12px 20px 0;
}
.qs-actions { flex: none; padding: 14px 24px calc(20px + env(safe-area-inset-bottom)); }
.qs-btn {
  width: 100%; height: 44px;
  border: none; border-radius: 22px;
  background: var(--primary); color: #fff;
  font-size: 15px; cursor: pointer;
}
.qs-btn:disabled { opacity: .55; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  z-index: 300;
  background: rgba(0,0,0,.75); color: #fff;
  font-size: 13px;
  padding: 9px 18px; border-radius: 8px;
  max-width: 80%;
  text-align: center;
  transition: opacity .25s;
  pointer-events: none;
}
.toast[hidden] { display: none; }

/* ---------- 登录页 ---------- */
.auth-wrap {
  min-height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
}
.auth-card {
  position: relative;
  width: 100%; max-width: 360px;
  background: var(--card);
  border-radius: 14px;
  padding: 28px 22px;
  box-shadow: 0 2px 12px rgba(0,0,0,.06);
}
.auth-card .lang-toggle {
  position: absolute; top: 14px; right: 14px;
  min-width: 44px; height: 28px; padding: 0 8px;
  font-size: 12px;
}
.auth-card h1 {
  font-size: 22px; text-align: center; color: var(--primary-dark);
}
.auth-card .subtitle {
  font-size: 13px; color: var(--text-sub); text-align: center;
  margin: 8px 0 20px;
}
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: #666; margin-bottom: 6px; }
.field input, .field select {
  width: 100%; height: 44px;
  border: 1px solid #dcdcdc; border-radius: 8px;
  padding: 0 12px; font-size: 15px;
  outline: none; background: #fff;
}
.field input:focus, .field select:focus { border-color: var(--primary); }
.btn-block { width: 100%; height: 44px; border-radius: 22px; font-size: 16px; }
.msg { font-size: 13px; min-height: 18px; margin-top: 10px; text-align: center; }
.msg.ok { color: var(--primary); }
.msg.error { color: var(--red); }
.tabs {
  display: flex; margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.tabs button {
  flex: 1; height: 42px;
  border: none; background: none;
  font-size: 15px; color: #888;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.tabs button.active {
  color: var(--primary-dark); font-weight: 700;
  border-bottom-color: var(--primary);
}
.hidden { display: none; }

.forgot-tip {
  font-size: 12px; color: var(--text-sub);
  text-align: center; margin-top: 14px;
}

/* ---------- 小屏适配 ---------- */
@media (max-width: 360px) {
  .stat-val { font-size: 14px; }
  .act-circle { width: 40px; height: 40px; }
}

/* ---------- 桌面端适配（≥768px）：容器加宽，设备卡片网格化 ---------- */
@media (min-width: 768px) {
  .nav { height: 52px; font-size: 18px; }
  .wrap { max-width: 1024px; padding: 20px 20px 40px; }
  #device-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 14px;
  }
  #device-list .card { margin-bottom: 0; }
  .empty { padding: 70px 0 40px; }
}

@media (min-width: 1400px) {
  .wrap { max-width: 1360px; }
}

/* 悬停反馈（仅真实指针设备，避免触屏粘滞悬停） */
@media (hover: hover) {
  .icon-btn:hover { background: #f4f4f4; }
  .act:hover .act-circle { background: #f4f4f4; }
  .act-circle.primary:hover { background: var(--primary-dark); }
  .act-circle.red:hover { background: #e04339; }
  .link-btn:hover { background: var(--primary-light); }
  .link-btn.off:hover { background: #fdeceb; }
  .add-btn:hover { background: #f4f4f4; }
  .sheet-item:hover { background: #ededed; }
  .req-btn.ok:hover { opacity: .9; }
  .req-btn.no:hover { background: #ededed; }
  .m-btn:hover { background: var(--primary-light); }
  .m-btn.off:hover { background: #f0f0f0; }
}
