:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --primary: #3b82f6;
  --primary-2: #2563eb;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea {
  font-family: inherit; font-size: 15px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; width: 100%; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }

/* 登录 */
.screen { max-width: 520px; margin: 0 auto; min-height: 100vh; }
#login { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { background: var(--card); border-radius: 20px; padding: 32px 24px; width: 100%;
  box-shadow: 0 10px 30px rgba(0,0,0,.08); text-align: center; }
.logo { font-size: 26px; font-weight: 800; }
.sub { color: var(--muted); margin: 6px 0 20px; }
.field { text-align: left; }
.divider { margin: 20px 0; color: var(--muted); font-size: 12px; position: relative; }
.divider span { background: #fff; padding: 0 12px; position: relative; z-index: 1; }
.divider::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--line); }
.hint { color: var(--muted); font-size: 12px; margin-top: 16px; }

/* 顶栏 */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 8px;
  position: sticky; top: 0; background: var(--bg); z-index: 10; }
.topbar .title { font-size: 20px; font-weight: 800; }
.family { color: var(--muted); font-size: 13px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.badge { background: #dcfce7; color: #166534; font-size: 12px; padding: 3px 8px; border-radius: 999px; }
.icon-btn { border: none; background: var(--card); border-radius: 10px; font-size: 18px; padding: 8px 12px; }

main { padding: 8px 16px 90px; }
.sec-title { font-size: 16px; font-weight: 700; margin: 18px 0 10px; }
.card { background: var(--card); border-radius: 16px; padding: 16px; margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.04); }

/* 摘要 */
.summary { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.sum-item { background: var(--card); border-radius: 14px; padding: 14px; text-align: center; }
.sum-item .v { font-size: 24px; font-weight: 800; }
.sum-item .k { font-size: 12px; color: var(--muted); }

/* 设备 */
.devices { display: flex; flex-direction: column; gap: 12px; }
.device { background: var(--card); border-radius: 16px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.device .row1 { display: flex; justify-content: space-between; align-items: center; }
.device .name { font-weight: 700; font-size: 16px; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.pill.on { background: #dcfce7; color: #166534; }
.pill.off { background: #f3f4f6; color: #6b7280; }
.pill.block { background: #fee2e2; color: #991b1b; }
.time-row { display: flex; justify-content: space-between; margin: 10px 0 4px; font-size: 13px; color: var(--muted); }
.bar { height: 8px; background: #eef0f4; border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 999px; transition: width .4s; }
.bar > i.warn { background: var(--warn); }
.bar > i.over { background: var(--danger); }
.device .actions { display: flex; gap: 8px; margin-top: 12px; }
.device .actions button { flex: 1; }

.btn { border: none; border-radius: 12px; padding: 12px 16px; font-size: 15px; font-weight: 600; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.ghost { background: #eef2ff; color: var(--primary); }
.btn.block { width: 100%; margin-top: 10px; }
.btn.small { padding: 8px 12px; font-size: 13px; }

/* 事件 */
.events { display: flex; flex-direction: column; gap: 8px; }
.event { background: var(--card); border-radius: 12px; padding: 12px 14px; font-size: 14px;
  display: flex; gap: 10px; align-items: flex-start; box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.event .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex-shrink: 0; }
.event.warn .dot { background: var(--warn); }
.event.danger .dot { background: var(--danger); }
.event.ok .dot { background: var(--ok); }
.event .t { color: var(--muted); font-size: 11px; margin-left: auto; white-space: nowrap; }

/* 题库 */
.ai-box { background: linear-gradient(135deg, #eff6ff, #eef2ff); border-radius: 16px; padding: 16px;
  margin-bottom: 14px; border: 1px solid #dbeafe; }
.ai-box .ttl { font-weight: 700; }
.ai-box .desc { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.ai-box .row { display: flex; gap: 8px; align-items: center; }
.ai-box .row input { flex: 1; }
.ai-box .row select { width: auto; }
.filters { display: flex; gap: 10px; margin-bottom: 12px; }
.questions { display: flex; flex-direction: column; gap: 10px; }
.q { background: var(--card); border-radius: 12px; padding: 12px 14px; box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.q .tag { font-size: 11px; color: var(--primary); background: #eff6ff; padding: 2px 8px; border-radius: 6px; margin-right: 6px; }
.q .text { font-weight: 600; margin: 6px 0; }
.q .ans { color: var(--ok); font-size: 13px; }
.q .del { float: right; border: none; background: transparent; color: var(--muted); font-size: 16px; }
.form .row2 { display: flex; gap: 10px; }
.form .row2 > * { flex: 1; }
textarea { min-height: 70px; resize: vertical; }
.switch { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; }
.switch input { width: auto; }

/* 底部导航 */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; background: var(--card);
  border-top: 1px solid var(--line); display: flex; max-width: 520px; margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom); }
.tab-btn { flex: 1; border: none; background: transparent; padding: 12px; font-size: 14px; color: var(--muted); }
.tab-btn.active { color: var(--primary); font-weight: 700; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: rgba(17,24,39,.92); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; z-index: 100; max-width: 90%; }
