:root {
  --bg: #0f1620;
  --card: #18222e;
  --card2: #1f2c3a;
  --text: #e6edf3;
  --muted: #8aa0b3;
  --accent: #3da9fc;
  --green: #2ecc71;
  --amber: #f0a020;
  --red: #ff5a5a;
  --border: #2a3a4a;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Noto Sans TC", sans-serif;
  font-size: 16px;
}
.hidden { display: none !important; }

/* 登入 */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--card); padding: 28px; border-radius: 16px; width: 100%; max-width: 360px; text-align: center; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { color: var(--muted); margin: 0 0 16px; }
.login-card input { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); margin-bottom: 12px; }
.err { color: var(--red); margin-top: 10px; min-height: 20px; font-size: 14px; }

/* 版面 */
#app { display: flex; flex-direction: column; min-height: 100vh; padding-bottom: 64px; }
header { display: flex; align-items: center; gap: 8px; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); background: var(--card); position: sticky; top: 0; z-index: 5; border-bottom: 1px solid var(--border); }
header .spacer { flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--green); } .dot.bad { background: var(--red); }
#conn-text { font-size: 14px; color: var(--muted); }
main { flex: 1; padding: 14px; max-width: 720px; width: 100%; margin: 0 auto; }

/* 卡片與元件 */
.card { background: var(--card); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.meter-row { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.meter-row label { width: 64px; font-size: 14px; color: var(--muted); }
.meter { flex: 1; height: 14px; background: var(--bg); border-radius: 8px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--accent); transition: width .12s linear; }
.meter-fill.amber { background: var(--amber); } .meter-fill.green { background: var(--green); }
.val { width: 84px; text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; }
.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.kv:last-of-type { border-bottom: none; }

button { font: inherit; cursor: pointer; border: none; border-radius: 10px; padding: 11px 14px; color: var(--text); background: var(--card2); }
button.primary { background: var(--accent); color: #04121f; font-weight: 600; width: 100%; }
button.ghost { background: transparent; color: var(--muted); padding: 6px 10px; }
button.danger { background: transparent; color: var(--red); border: 1px solid var(--border); }
.badge { font-size: 12px; padding: 4px 8px; border-radius: 999px; }
.badge.rec { background: var(--red); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* 列表 */
.list { display: flex; flex-direction: column; gap: 10px; }
.listbar { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.item { background: var(--card); border-radius: 12px; padding: 12px 14px; }
.item .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.item .time { color: var(--muted); font-size: 13px; }
.item .msg { margin-top: 4px; font-size: 14px; color: var(--text); }
.tag { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--card2); }
.tag.sound { color: var(--accent); } .tag.brightness { color: var(--amber); }
.tag.motion { color: var(--green); } .tag.manual { color: var(--muted); }
audio { width: 100%; margin-top: 10px; }
.segs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.seg { font-size: 12px; padding: 4px 8px; border-radius: 8px; background: var(--card2); color: var(--accent); border: 1px solid var(--border); }
.rowbtns { display: flex; gap: 8px; margin-top: 10px; }

/* 情境表單 */
.field { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 7px 0; }
.field label { color: var(--muted); font-size: 14px; }
.field input[type=number], .field input[type=text], .field select { width: 110px; padding: 7px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.field input[type=checkbox] { width: 22px; height: 22px; }
.sub { font-size: 13px; color: var(--muted); margin: 12px 0 4px; text-transform: uppercase; letter-spacing: .04em; }
.windows { font-size: 13px; color: var(--muted); }

/* 底部導覽 */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabbar button { flex: 1; background: transparent; border-radius: 0; color: var(--muted); font-size: 13px; padding: 12px 0; }
.tabbar button.active { color: var(--accent); }
code { background: var(--bg); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
a { color: var(--accent); }
