:root {
  --orange: #ff7a1a;
  --orange-dark: #e8630a;
  --orange-light: #fff3e8;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #7b8494;
  --border: #e8ebf0;
  --green: #18b66a;
  --red: #ef4444;
  --shadow: 0 4px 20px rgba(20, 30, 60, 0.06);
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font-family: inherit; font-size: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }

/* ---------- 通用 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 10px; font-weight: 600; font-size: 14px;
  transition: .18s; white-space: nowrap;
}
.btn-primary { background: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-dark); }
.btn-ghost { background: var(--orange-light); color: var(--orange-dark); }
.btn-ghost:hover { background: #ffe4cc; }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--orange); color: var(--orange); }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; outline: none; transition: .18s; color: var(--text);
}
.input:focus { border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-light); }
textarea.input { resize: vertical; min-height: 90px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-on { background: #e6f9f0; color: var(--green); }
.badge-off { background: #f1f2f4; color: var(--muted); }
.badge-wait { background: #fff3e8; color: var(--orange-dark); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- 登录页 ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #fff7ef 0%, #f4f6f9 55%); padding: 20px;
}
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 20px; box-shadow: 0 20px 60px rgba(20,30,60,.1); padding: 38px 34px; }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-logo .mark {
  width: 46px; height: 46px; border-radius: 13px; background: linear-gradient(135deg,#ff9a3c,#ff6a00);
  display: flex; align-items: center; justify-content: center; font-size: 24px; color: #fff; box-shadow: 0 6px 16px rgba(255,122,26,.35);
}
.auth-logo h1 { font-size: 21px; letter-spacing: -.5px; }
.auth-logo p { font-size: 12px; color: var(--muted); margin-top: 2px; }
.auth-tabs { display: flex; background: #f2f4f7; border-radius: 10px; padding: 4px; margin-bottom: 22px; }
.auth-tabs button { flex: 1; padding: 9px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.auth-tabs button.active { background: #fff; color: var(--orange-dark); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.auth-field { margin-bottom: 15px; }
.auth-field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 7px; color: #4b5563; }
.auth-submit { width: 100%; margin-top: 8px; padding: 13px; font-size: 15px; }
.auth-error { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }
.auth-foot { text-align: center; font-size: 12px; color: var(--muted); margin-top: 20px; line-height: 1.7; }

/* ---------- 后台布局 ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 22px 20px; border-bottom: 1px solid var(--border); }
.sidebar .brand .mark {
  width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg,#ff9a3c,#ff6a00);
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 19px;
}
.sidebar .brand b { font-size: 17px; }
.sidebar nav { padding: 14px 12px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px; border-radius: 10px;
  color: #5b6472; font-size: 14px; font-weight: 500; margin-bottom: 4px; width: 100%; text-align: left;
}
.nav-item:hover { background: #f7f8fa; }
.nav-item.active { background: var(--orange-light); color: var(--orange-dark); font-weight: 700; }
.nav-item .icon { width: 20px; text-align: center; font-size: 16px; }
.sidebar .user-box { padding: 14px 16px; border-top: 1px solid var(--border); }
.sidebar .user-box .name { font-size: 13px; font-weight: 600; }
.sidebar .user-box .role { font-size: 11px; color: var(--muted); margin-top: 2px; }

.main { flex: 1; min-width: 0; padding: 28px 32px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.page-head h2 { font-size: 22px; letter-spacing: -.4px; }
.page-head p { font-size: 13px; color: var(--muted); margin-top: 4px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(170px,1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; display: flex; align-items: center; gap: 14px; }
.stat .ico { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 21px; }
.stat .ico.o { background: var(--orange-light); }
.stat .ico.g { background: #e6f9f0; }
.stat .ico.b { background: #e8f0ff; }
.stat .num { font-size: 26px; font-weight: 800; line-height: 1; }
.stat .label { font-size: 12px; color: var(--muted); margin-top: 5px; }

.panel { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 22px; }
.panel-head { padding: 17px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.panel-head h3 { font-size: 15px; }
.panel-body { padding: 20px; }

.device-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(280px,1fr)); gap: 16px; }
.device-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; border: 1px solid transparent; transition: .18s; }
.device-card:hover { border-color: var(--orange); transform: translateY(-2px); }
.device-card .top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 14px; }
.device-card .dname { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.device-card .dmeta { font-size: 11px; color: var(--muted); margin-top: 5px; }
.device-card .code { background: var(--orange-light); color: var(--orange-dark); font-size: 20px; font-weight: 800; letter-spacing: 3px; text-align: center; padding: 10px; border-radius: 10px; margin: 12px 0; }
.device-card .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; background: #fafbfc; }
tr:last-child td { border-bottom: none; }

/* ---------- 弹窗 ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100; }
.modal { background: #fff; border-radius: 18px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: 0 24px 80px rgba(0,0,0,.2); }
.modal.wide { max-width: 760px; }
.modal-head { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 17px; }
.modal-close { font-size: 22px; color: var(--muted); line-height: 1; }
.modal-body { padding: 22px 24px; }
.modal-foot { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; }
.form-hint { font-size: 11px; color: var(--muted); margin-top: 5px; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button { padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border); background: #fff; font-size: 13px; }
.seg button.active { border-color: var(--orange); background: var(--orange-light); color: var(--orange-dark); font-weight: 600; }

/* 画面查看 */
.screen-wrap { background: #0d1117; border-radius: 12px; overflow: hidden; display: flex; align-items: center; justify-content: center; min-height: 320px; }
.screen-wrap img { max-width: 100%; max-height: 62vh; width: auto; height: auto; display: block; margin: 0 auto; object-fit: contain; }
.screen-placeholder { color: #64748b; font-size: 14px; text-align: center; padding: 40px; }

/* Toast */
#toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1f2430; color: #fff; padding: 11px 20px; border-radius: 10px; font-size: 13px; box-shadow: 0 8px 30px rgba(0,0,0,.2); animation: fadein .2s; }
.toast.err { background: #b91c1c; }
@keyframes fadein { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- 手机网页 ---------- */
.mobile-app { max-width: 480px; margin: 0 auto; min-height: 100vh; background: var(--bg); position: relative; padding-bottom: 76px; }
.m-head { background: linear-gradient(135deg,#ff9a3c,#ff6a00); color: #fff; padding: 20px 18px 26px; border-radius: 0 0 22px 22px; }
.m-head .row { display: flex; align-items: center; justify-content: space-between; }
.m-head .brand { display: flex; align-items: center; gap: 9px; font-size: 18px; font-weight: 800; }
.m-head .brand .mark { width: 32px; height: 32px; border-radius: 9px; background: rgba(255,255,255,.22); display: flex; align-items: center; justify-content: center; font-size: 17px; }
.m-head .sub { font-size: 12px; opacity: .9; margin-top: 6px; }
.m-body { padding: 16px; }
.m-card { background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 16px; margin-bottom: 13px; }
.m-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px;
  background: #fff; border-top: 1px solid var(--border); display: flex; padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); z-index: 50;
}
.m-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); }
.m-nav button.active { color: var(--orange-dark); font-weight: 700; }
.m-nav .icon { font-size: 20px; line-height: 1; }

.m-dev { display: flex; align-items: center; gap: 13px; }
.m-dev .thumb { width: 78px; height: 58px; border-radius: 10px; background: #eef1f5; object-fit: cover; flex-shrink: 0; display:flex; align-items:center; justify-content:center; color:#9aa3b2; font-size:11px; }
.m-dev .info { flex: 1; min-width: 0; }
.m-dev .info .name { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-dev .info .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }

.m-screen { max-width: 100%; max-height: 58vh; width: auto; height: auto; border-radius: 12px; background: #0d1117; display: block; margin: 0 auto; object-fit: contain; }
.big-actions { display: grid; grid-template-columns: repeat(2,1fr); gap: 12px; }
.big-btn { background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 18px 10px; text-align: center; }
.big-btn .ic { font-size: 28px; }
.big-btn .t { font-size: 13px; font-weight: 700; margin-top: 8px; }
.big-btn.primary { background: linear-gradient(135deg,#ff9a3c,#ff6a00); color: #fff; }
.big-btn.talking { background: #ffe0e0; color: #b91c1c; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(.97); } }

.m-field { margin-bottom: 14px; }
.m-field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; color: #4b5563; }
.log-item { padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.log-item:last-child { border: none; }
.log-item .time { font-size: 11px; color: var(--muted); margin-top: 3px; }
.empty { text-align: center; color: var(--muted); padding: 50px 20px; font-size: 13px; }
.empty .em { font-size: 40px; display: block; margin-bottom: 10px; }
