/* 冷鏈監控 — 深藍色系。淺色 / 深色兩組 token，預設跟隨系統，可在設定頁切換 */
:root {
  --bg: #eef2f8; --surface: #ffffff; --surface-2: #e8edf5; --surface-3: #dde4ef;
  --text: #0c1a33; --muted: #5d6b85; --border: #d3dbe8;
  --brand: #0b2a5b; --accent: #1467d8; --accent-soft: #e1ecfc; --on-accent: #fff;
  --ok: #138a4b; --ok-bg: #e4f5ec; --warn: #b86a00; --warn-bg: #fff3dc; --alarm: #d0312d; --alarm-bg: #fdeaea;
  --off: #7a879e; --off-bg: #e9edf3; --defrost: #0a8aa8; --cool: #1467d8;
  --shadow: 0 1px 2px rgba(12, 26, 51, .06), 0 4px 16px rgba(12, 26, 51, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #081226; --surface: #0f1d38; --surface-2: #162748; --surface-3: #1d3158;
    --text: #e7eefb; --muted: #8fa1c2; --border: #22375f;
    --brand: #0b2a5b; --accent: #4ea3ff; --accent-soft: #15325f; --on-accent: #06142b;
    --ok: #3fd18a; --ok-bg: #0e2e25; --warn: #fbbf24; --warn-bg: #33270c; --alarm: #ff6b66; --alarm-bg: #3a1419;
    --off: #7c8cab; --off-bg: #141f36; --defrost: #3cd3f0; --cool: #4ea3ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #081226; --surface: #0f1d38; --surface-2: #162748; --surface-3: #1d3158;
  --text: #e7eefb; --muted: #8fa1c2; --border: #22375f;
  --brand: #0b2a5b; --accent: #4ea3ff; --accent-soft: #15325f; --on-accent: #06142b;
  --ok: #3fd18a; --ok-bg: #0e2e25; --warn: #fbbf24; --warn-bg: #33270c; --alarm: #ff6b66; --alarm-bg: #3a1419;
  --off: #7c8cab; --off-bg: #141f36; --defrost: #3cd3f0; --cool: #4ea3ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35); color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif; overflow-x: hidden; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }
.t-ok { color: var(--ok); } .t-warn { color: var(--warn); } .t-alarm { color: var(--alarm); } .t-off { color: var(--off); }
.error { color: var(--alarm); min-height: 1.4em; margin: 8px 0 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.empty { text-align: center; color: var(--muted); padding: 48px 0; }
.hint { text-align: center; color: var(--muted); font-size: 12px; margin: 16px 0 0; }

/* 按鈕 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  padding: 11px 16px; border-radius: 12px; font-weight: 600; min-height: 44px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.outline { background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--alarm); }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; background: none; border-radius: 10px; color: var(--text); position: relative; flex: none; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.tiny { width: 28px; height: 28px; vertical-align: middle; }
.icon-btn.tiny svg { width: 16px; height: 16px; }

/* 登入 */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow); text-align: center; }
.login-logo { width: 68px; height: 68px; border-radius: 18px; }
.login-card h1 { margin: 10px 0 2px; font-size: 22px; }
.login-card label { display: block; text-align: left; margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.login-card input { display: block; width: 100%; margin-top: 6px; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); }
.login-card .btn { margin-top: 20px; }

/* 上方標題列 */
.topbar { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 4px;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar h1 { margin: 0; font-size: 18px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; }
.bell em, .root-nav em { position: absolute; top: 3px; right: 2px; background: var(--alarm); color: #fff; font-style: normal; font-size: 10px; font-weight: 700;
  min-width: 17px; height: 17px; line-height: 17px; border-radius: 9px; padding: 0 4px; text-align: center; }
.conn { display: inline-grid; place-items: center; width: 18px; height: 40px; }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.conn.on i { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.conn.off i { background: var(--alarm); }

.page { padding: 16px 16px calc(104px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.hello { margin: 4px 0 12px; color: var(--muted); }

/* 狀態燈 */
.sdot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--ok); flex: none; }
.sdot.warn { background: var(--warn); }
.sdot.alarm { background: var(--alarm); animation: pulse 1.2s infinite; }
.sdot.offline { background: var(--off); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--alarm) 22%, transparent); } }
.bdot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--off); vertical-align: -2px; margin-right: 6px; }
.bdot.on, .bdot.fault { border: 0; }
.bdot.on { background: var(--ok); }
.bdot.fault { background: var(--alarm); }

/* 案場清單 */
.group-title { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.group-title svg { width: 18px; height: 18px; }
.site-list { display: grid; gap: 10px; }
.site-card { display: block; width: 100%; text-align: left; background: var(--surface); border: 1.5px solid transparent; border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.site-card.alarm { border-color: var(--alarm); }
.site-card.warn { border-color: color-mix(in srgb, var(--warn) 60%, transparent); }
.site-top { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.site-top b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--muted); display: inline-grid; }
.chev svg { width: 18px; height: 18px; }
.site-stats { display: flex; gap: 14px; flex-wrap: wrap; margin: 8px 0 0 22px; font-size: 13px; color: var(--muted); }
.site-stats b { font-size: 15px; font-variant-numeric: tabular-nums; }

/* 總覽 */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--surface); border-radius: 14px; padding: 12px 10px; box-shadow: var(--shadow); min-width: 0; text-align: center; }
.stat b { display: block; font-size: 28px; line-height: 1.15; margin: 2px 0; font-variant-numeric: tabular-nums; }
.stat span { display: block; font-size: 11px; color: var(--muted); }
.stat .stat-name { font-size: 13px; font-weight: 700; color: var(--text); }
.stat.zero b { color: var(--off) !important; opacity: .6; }
.stat.ok b { color: var(--ok); } .stat.warn b { color: var(--warn); } .stat.alarm b { color: var(--alarm); } .stat.off b { color: var(--off); }
.kw-line { margin: 10px 2px 0; font-size: 14px; color: var(--muted); }
.kw-line b { color: var(--text); font-size: 16px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 7px 14px; font-size: 13px; }
.chip.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.small-chips { padding-top: 6px; }
.small-chips .chip { padding: 5px 12px; font-size: 12px; }

/* 設備卡片 */
.dev-list { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .dev-list { grid-template-columns: 1fr 1fr; } }
.dev-card { display: block; width: 100%; text-align: left; background: var(--surface); border: 1.5px solid transparent; border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; transition: transform .12s; }
.dev-card:active, .dev-card.pressed { transform: scale(.985); }
.dev-card.alarm { border-color: var(--alarm); background: linear-gradient(var(--alarm-bg), var(--surface) 70%); }
.dev-card.warn { border-color: color-mix(in srgb, var(--warn) 70%, transparent); background: linear-gradient(var(--warn-bg), var(--surface) 70%); }
.dev-card.offline { background: var(--off-bg); }
.dev-top { display: flex; align-items: center; gap: 10px; }
.dev-name { font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tags { display: flex; gap: 4px; flex: none; }
.tag { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.tag.defrost { color: var(--defrost); } .tag.stop { color: var(--warn); }
.dev-sub { font-size: 12px; color: var(--muted); margin: 3px 0 0 22px; font-variant-numeric: tabular-nums; }
.hero-row { display: flex; align-items: baseline; gap: 12px; margin: 8px 0 2px 22px; }
.hero { font-size: 36px; font-weight: 700; letter-spacing: -.5px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.dev-card.alarm .hero { color: var(--alarm); }
.dev-card.warn .hero { color: var(--warn); }
.hero.nodata { color: var(--off); font-size: 24px; }
.hero-sub { color: var(--muted); font-size: 13px; }
.alarm-line { margin: 6px 0 0 22px; font-size: 13px; font-weight: 600; color: var(--alarm); }
.alarm-line.warn { color: var(--warn); }
.qrows { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 6px; }
.qrow { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: 14px; }
.qrow span { color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qrow b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.qrow b.nodata, .fval.nodata { color: var(--off); font-weight: 500; }
.qrow b.fault, .fval.fault { color: var(--alarm); }

/* 告警 / 日誌 */
.alarm-list { display: grid; gap: 10px; }
.alarm-card { display: grid; gap: 3px; width: 100%; text-align: left; background: var(--surface); border: 0; border-left: 4px solid var(--alarm);
  border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.alarm-card.warn { border-left-color: var(--warn); }
.alarm-card.cleared { border-left-color: var(--ok); }
.alarm-card b { font-size: 16px; }
.alarm-msg { font-weight: 700; }
.alarm-msg em { font-style: normal; color: var(--alarm); margin-left: 6px; }
.alarm-card.warn .alarm-msg em { color: var(--warn); }
.alarm-card.cleared .alarm-msg em { color: var(--ok); }
.alarm-detail { font-size: 13px; }
.log-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.log { display: grid; grid-template-columns: 28px 1fr; gap: 8px; background: var(--surface); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); }
.log-ico { font-size: 18px; line-height: 1.4; }
.log-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.log-cat { font-weight: 700; color: var(--accent); }
.log.alarm .log-cat { color: var(--alarm); } .log.prealarm .log-cat { color: var(--warn); } .log.system .log-cat { color: var(--ok); }
.log-title { font-weight: 600; margin-top: 2px; }
.log-detail { font-size: 14px; font-variant-numeric: tabular-nums; }
.chip.toggle.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.card-block { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card-block h3 { margin: 0 0 8px; font-size: 15px; }
.card-block p { margin: 0 0 10px; }

/* 分段按鈕 */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; border-radius: 9px; padding: 9px 8px; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

/* 底部導覽（根層） */
.root-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.root-nav button { position: relative; border: 0; background: none; padding: 8px 0 7px; font-size: 11px; color: var(--muted); display: grid; justify-items: center; gap: 2px; }
.root-nav button.active { color: var(--accent); font-weight: 700; }
.root-nav em { right: calc(50% - 22px); }
@media (min-width: 760px) { .root-nav { max-width: 760px; margin: 0 auto; border-radius: 16px 16px 0 0; border: 1px solid var(--border); } }

/* 設備頁 */
.seg-tabs { position: fixed; z-index: 6; left: 16px; right: 16px; bottom: calc(12px + env(safe-area-inset-bottom)); max-width: 520px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 5px; border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(12px); box-shadow: 0 6px 24px rgba(0, 0, 0, .25); border: 1px solid var(--border); }
.seg-tabs button { border: 0; background: none; border-radius: 13px; padding: 11px 0; font-weight: 700; font-size: 15px; color: var(--muted); }
.seg-tabs button.active { background: var(--accent); color: var(--on-accent); }
.dev-title { display: flex; align-items: center; gap: 10px; }
.dev-title .sdot { width: 16px; height: 16px; }
.dev-title h2 { margin: 0; font-size: 22px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-meta { font-size: 13px; color: var(--muted); display: grid; gap: 2px; margin: 6px 0 10px; }
.dev-meta b { color: var(--text); }
.alarm-box { border-radius: 10px; padding: 10px 12px; margin: 0 0 10px; font-weight: 600; font-size: 14px; background: var(--alarm-bg); color: var(--alarm); }
.alarm-box.warn { background: var(--warn-bg); color: var(--warn); }
.alarm-box.offline { background: var(--off-bg); color: var(--off); }
.alarm-box .small { font-weight: 500; }
.hero-card { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; background: var(--surface); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 12px; border: 1.5px solid transparent; }
.hero-card.alarm { border-color: var(--alarm); } .hero-card.alarm .hero { color: var(--alarm); }
.hero-card.warn { border-color: var(--warn); } .hero-card.warn .hero { color: var(--warn); }
.hero-card .hero { font-size: 40px; }
.hero-side { display: grid; gap: 2px; text-align: right; font-size: 13px; color: var(--muted); }
.hero-side b { color: var(--text); }
.side-switch { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.side-switch .seg { flex: 1; }
.lock-hint { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin: 4px 0 8px; }
.lock-hint svg { width: 16px; height: 16px; }
.fgroup { margin-bottom: 6px; }
.fgroup-head { display: flex; width: 100%; justify-content: space-between; align-items: center; border: 0; background: none; padding: 12px 2px 8px;
  font-size: 16px; font-weight: 700; color: var(--text); }
.fgroup-head svg { color: var(--accent); transition: transform .15s; transform: rotate(180deg); }
.fgroup.collapsed .fgroup-head svg { transform: none; }
.fgroup.collapsed .fgroup-body { display: none; }
.fgroup-body { display: grid; gap: 6px; }
.frow { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--surface); border: 0; border-radius: 10px; padding: 13px 14px; min-height: 48px; }
.frow.tap:active { background: var(--surface-2); }
.fname { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; }
.fval { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.frow .chev svg { width: 16px; height: 16px; }
.pend { color: var(--warn); font-size: 12px; margin-right: 8px; }

/* 區間 / 表格 / 圖表 */
.range { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: hidden; }
.range label { position: relative; display: grid; padding: 8px 12px; gap: 2px; min-width: 0; cursor: pointer; }
.range b { font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.range b.placeholder { color: var(--muted); font-weight: 500; }
.range label + label { border-left: 1px solid var(--border); }
.range span { font-size: 12px; color: var(--muted); }
.range input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.tool-row { display: flex; justify-content: space-between; align-items: center; margin: 4px 0; }
.table-wrap { overflow: auto; max-height: calc(100dvh - 330px); border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
table.data { border-collapse: separate; border-spacing: 0; font-size: 14px; font-variant-numeric: tabular-nums; min-width: 100%; }
table.data th, table.data td { padding: 10px 12px; white-space: nowrap; text-align: center; border-bottom: 1px solid var(--border); }
table.data th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; font-weight: 700; z-index: 1; }
table.data th:first-child, table.data td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 2; text-align: left; border-right: 1px solid var(--border); }
table.data th:first-child { background: var(--surface-2); z-index: 3; }
table.data td.nodata { color: var(--off); }
table.data td.fault { color: var(--alarm); }
.chart-card { position: relative; background: var(--surface); border-radius: var(--radius); padding: 10px 8px 12px; margin-top: 10px; box-shadow: var(--shadow); }
.chart-info { min-height: 76px; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; margin: 0 44px 8px 0; font-size: 13px; display: grid; align-content: center; }
.chart-info .muted { text-align: center; }
.info-grid { display: grid; grid-template-columns: 1fr auto; gap: 1px 12px; margin-top: 4px; }
.info-grid span { display: flex; align-items: center; gap: 6px; color: var(--muted); min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.info-grid i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.chart-pick { position: absolute; right: 6px; top: 10px; color: var(--accent); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); padding: 6px 6px 0; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 16px; height: 3px; border-radius: 2px; background: var(--c); }
.legend i.dash { background: repeating-linear-gradient(90deg, var(--c) 0 5px, transparent 5px 8px); }
.uplot .u-select { background: color-mix(in srgb, var(--accent) 18%, transparent); }

/* 底部面板 */
.backdrop { position: fixed; inset: 0; background: rgba(2, 8, 20, .5); z-index: 10; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-height: 86dvh; overflow-y: auto; background: var(--bg);
  border-radius: 22px 22px 0 0; padding: 6px 18px calc(18px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; animation: up .2s ease-out; }
.sheet.tall { min-height: 55dvh; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 6px auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 8px; }
.sheet-head h2 { margin: 0; font-size: 19px; flex: 1; }
.sheet-actions { position: sticky; bottom: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 14px; background: var(--bg); margin-top: 12px; }
.kv-list { display: grid; gap: 6px; margin: 14px 0 10px; }
.kv-list div { display: flex; gap: 16px; }
.kv-list dt { color: var(--muted); width: 88px; flex: none; }
.kv-list dd { margin: 0; }
.info-box, .warn-box { display: flex; gap: 8px; align-items: center; border-radius: 10px; padding: 10px 12px; font-weight: 600; font-size: 14px; margin: 8px 0; }
.info-box { background: var(--accent-soft); color: var(--accent); }
.info-box svg { width: 18px; height: 18px; flex: none; }
.warn-box { background: var(--warn-bg); color: var(--warn); }
.field-label { display: block; color: var(--muted); margin: 14px 0 6px; font-size: 14px; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-size: 22px; flex: none; }
.stepper input { flex: 1; min-width: 0; text-align: center; font-size: 22px; font-weight: 700; padding: 8px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); height: 48px; }
.stepper .unit { color: var(--muted); width: 28px; }
.hm-input { display: flex; align-items: center; gap: 8px; }
.hm-input input { width: 90px; text-align: center; font-size: 22px; font-weight: 700; padding: 8px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); height: 48px; }
.opt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opt { border: 1.5px solid var(--border); background: var(--surface); border-radius: 12px; padding: 12px; font-weight: 600; }
.opt.current { border-style: dashed; }
.opt.chosen { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.btn.outline b { color: var(--accent); }
.sheet .btn.block.outline { margin-top: 12px; }
.sync-list { margin-top: 8px; display: grid; gap: 4px; }
.chk { display: flex; align-items: center; gap: 10px; background: var(--surface); border-radius: 10px; padding: 11px 12px; }
.chk input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.chk span { flex: 1; }
.chk em { font-style: normal; font-size: 13px; }
.chk.all { font-weight: 700; }
.result-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.result-list li { display: flex; justify-content: space-between; gap: 10px; background: var(--surface); border-radius: 10px; padding: 10px 12px; border-left: 4px solid var(--warn); font-size: 14px; }
.result-list li.success { border-left-color: var(--ok); } .result-list li.success b { color: var(--ok); }
.result-list li.failed { border-left-color: var(--alarm); } .result-list li.failed b { color: var(--alarm); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--surface-3); border-radius: 15px; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(20px); }
.pick-list { display: grid; gap: 6px; margin-top: 10px; }
.pick { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; background: var(--surface); border: 1.5px solid transparent;
  border-radius: 12px; padding: 12px 14px; font-weight: 600; min-height: 50px; }
.pick b { width: 28px; height: 28px; border-radius: 7px; border: 1.5px solid var(--border); display: grid; place-items: center; font-size: 13px; }
.pick.on { border-color: var(--accent); }
.pick.on b { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pick-group { margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.sync-box { margin-top: 12px; background: var(--surface); border-radius: 12px; padding: 4px 8px; }
.sync-box summary { display: flex; align-items: center; gap: 8px; padding: 10px 4px; font-weight: 600; list-style: none; }
.sync-box summary svg { width: 18px; height: 18px; }
.sync-box .chk { background: var(--surface-2); margin-bottom: 4px; }
.folder-edit { background: var(--surface); border-radius: 12px; padding: 10px; margin-top: 10px; display: grid; gap: 4px; }
.folder-edit .chk { background: var(--surface-2); }
input.text { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); font-weight: 600; }
.menu { display: grid; gap: 6px; padding-bottom: 4px; }
.menu-item { border: 0; background: var(--surface); border-radius: 12px; padding: 15px; font-weight: 600; font-size: 16px; }
.menu-item.muted { background: none; }

dialog { border: 0; border-radius: 18px; padding: 20px; width: min(92vw, 380px); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
dialog::backdrop { background: rgba(2, 8, 20, .55); }
dialog h3 { margin: 0 0 8px; }
dialog p { white-space: pre-line; line-height: 1.6; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }

.toast { position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 20; background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100vw - 32px); box-shadow: var(--shadow); }

@media (max-width: 360px) { .summary { grid-template-columns: repeat(2, 1fr); } .hero { font-size: 30px; } }

/* 資料來源標籤 */
.src-tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--ok-bg); color: var(--ok); flex: none; justify-self: end; }
.src-tag.sim { background: var(--surface-2); color: var(--muted); }

/* ───────── 今日重點 / 白話說明 ───────── */
.headline { background: var(--surface); border-radius: 18px; padding: 14px 16px 16px; box-shadow: var(--shadow); margin-bottom: 12px; border-left: 5px solid var(--ok); }
.headline.warn { border-left-color: var(--warn); }
.headline.alarm { border-left-color: var(--alarm); }
.headline-top { display: flex; justify-content: space-between; align-items: center; margin: -6px -8px 0 0; }
.headline-text { display: flex; align-items: center; gap: 10px; margin: 2px 0 0; font-size: 20px; }
.headline.alarm .headline-text b { color: var(--alarm); }
.headline.warn .headline-text b { color: var(--warn); }
.headline-detail { margin: 6px 0 0 22px; font-weight: 600; }
.headline-extra { margin: 6px 0 0 22px; font-size: 13px; color: var(--muted); }
.site-line { margin: 8px 0 0 22px; font-size: 14px; font-weight: 600; color: var(--ok); }
.site-line.warn { color: var(--warn); } .site-line.alarm { color: var(--alarm); }
.help-btn { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--border); font-weight: 800; font-size: 14px; color: var(--muted); }
.term { text-decoration: underline dotted var(--muted); text-underline-offset: 4px; cursor: help; }
.term-value { font-size: 30px; font-weight: 700; margin: 14px 0 6px; font-variant-numeric: tabular-nums; }
.term-value.nodata { color: var(--off); font-size: 22px; }
.term-desc { background: var(--surface); border-radius: 12px; padding: 12px 14px; line-height: 1.7; margin: 8px 0; }
.help-body p { line-height: 1.7; }
.legend-list { list-style: none; padding: 0; margin: 4px 0 10px; display: grid; gap: 12px; }
.legend-list li { display: flex; gap: 12px; align-items: flex-start; }
.legend-list .sdot { margin-top: 5px; }
.legend-list b { display: block; }
.legend-list span { font-size: 14px; color: var(--muted); }
.chart-tools { position: absolute; right: 6px; top: 10px; display: grid; gap: 6px; justify-items: center; color: var(--accent); }
.chart-pick { display: none; }

/* 新手教學 */
.onb-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(2, 8, 20, .6); display: grid; place-items: center; padding: 20px; animation: fade .2s; }
.onb { position: relative; width: min(100%, 380px); background: var(--surface); border-radius: 24px; padding: 28px 22px 20px; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .4); }
.onb-close { position: absolute; right: 10px; top: 10px; }
.onb-icon { font-size: 44px; }
.onb h2 { margin: 8px 0 12px; font-size: 21px; }
.onb-body { text-align: left; line-height: 1.8; color: var(--text); min-height: 150px; }
.onb-body .sdot { vertical-align: -1px; }
.onb-dots { display: flex; justify-content: center; gap: 6px; margin: 18px 0 16px; }
.onb-dots i { width: 7px; height: 7px; border-radius: 4px; background: var(--border); transition: width .2s; }
.onb-dots i.on { width: 22px; background: var(--accent); }
.onb-actions { display: flex; gap: 10px; }
.onb-actions .btn { flex: 1; }

/* 安裝到主畫面 */
.install-banner { position: fixed; z-index: 7; left: 12px; right: 12px; bottom: calc(66px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 10px 8px 10px 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .28); animation: up .25s ease-out; }
.install-banner img { width: 38px; height: 38px; border-radius: 10px; }
.install-banner div { flex: 1; min-width: 0; display: grid; }
.install-banner b { font-size: 14px; }
.install-banner span { font-size: 12px; color: var(--muted); }
.install-banner .btn { min-height: 36px; padding: 6px 14px; }
.ios-steps { padding-left: 22px; line-height: 1.6; display: grid; gap: 12px; margin: 14px 0 18px; }
.ios-steps span { display: block; font-size: 13px; color: var(--muted); }

/* 設定頁清單 / 名詞小百科 */
.list-block { padding-bottom: 6px; }
.list-row { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: none; padding: 12px 2px; border-top: 1px solid var(--border); text-align: left; }
.list-row:first-of-type { border-top: 0; }
.list-row b { font-weight: 600; }
.list-row em { font-style: normal; font-size: 12px; flex: 1; text-align: right; }
.list-row .chev { margin-left: auto; }
.list-row em + .chev { margin-left: 0; }
.search { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); margin-bottom: 12px; font-size: 16px; }
.gloss h3 span { font-weight: 500; }
.gloss-row { padding: 10px 0; border-top: 1px solid var(--border); }
.gloss-row:first-of-type { border-top: 0; }
.gloss-row p { margin: 4px 0 0; font-size: 14px; color: var(--muted); line-height: 1.6; }

body.has-install .page { padding-bottom: calc(184px + env(safe-area-inset-bottom)); }

/* ═════════ IoT Toolkit 版面 ═════════ */
.topbar h1 { line-height: 1.2; }
.topbar h1 small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }
.page { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.list-page { padding-top: 10px; }

/* 底部 6 個功能圖示（所有頁面都在） */
.root-nav { grid-template-columns: repeat(6, 1fr); background: var(--brand); border-top: 0; }
.root-nav button { color: rgba(255, 255, 255, .6); padding: 9px 0 7px; }
.root-nav button svg { width: 22px; height: 22px; }
.root-nav button.active { color: #fff; }
.root-nav button.active::after { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }

/* 案場：資料夾切換列 */
.folder-bar { position: sticky; top: calc(53px + env(safe-area-inset-top)); z-index: 4; display: flex; align-items: center; gap: 2px; padding: 8px 10px; background: var(--bg); border-bottom: 1px solid var(--border); }
.folder-bar select, .area-bar select { flex: 1; min-width: 0; height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-weight: 700; font-size: 15px; }
.site-card { padding: 14px 16px; }
.site-top { font-size: 16px; }
.site-sub { margin: 6px 0 0 22px; font-size: 13px; color: var(--muted); }
.site-sub span { font-weight: 700; }

/* 設備清單 */
.area-bar { position: sticky; top: calc(53px + env(safe-area-inset-top)); z-index: 4; padding: 8px 16px; background: var(--bg); border-bottom: 1px solid var(--border); display: flex; }
.status-strip { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); padding: 2px 2px 12px; }
.status-strip b { font-size: 15px; font-variant-numeric: tabular-nums; }
.status-strip .help-btn { margin-left: auto; width: 26px; height: 26px; font-size: 12px; }
.dev-card { padding: 12px 12px 10px; }
.dev-card.alarm, .dev-card.warn { background: var(--surface); }
.dev-card.alarm { box-shadow: inset 4px 0 0 var(--alarm), var(--shadow); }
.dev-card.warn { box-shadow: inset 4px 0 0 var(--warn), var(--shadow); }
.dev-name { font-size: 16px; }
.dev-sub { margin-left: 22px; }
.alarm-line { margin: 6px 0 0 0; padding: 6px 10px; border-radius: 8px; background: var(--alarm-bg); font-size: 13px; }
.alarm-line.warn { background: var(--warn-bg); }
.qrows { border-top: 0; margin-top: 8px; padding-top: 0; display: grid; gap: 4px; }
.frow.q { min-height: 36px; padding: 7px 12px; border-radius: 8px; background: var(--surface-2); font-size: 14px; }
.frow.q .fname { font-weight: 600; color: var(--text); }
.frow.q.primary .fval { font-size: 17px; }
.dev-card.alarm .frow.q.primary .fval { color: var(--alarm); }
.dev-card.warn .frow.q.primary .fval { color: var(--warn); }
.fval .bdot { margin: 0 0 0 6px; }
.fval.nodata { color: var(--alarm); font-weight: 600; font-size: 13px; }
.dev-card.offline .fval.nodata { color: var(--off); }

/* 設備頁 */
.sticky-head { position: sticky; top: 0; z-index: 5; }
.sticky-head .topbar { position: static; border-bottom: 0; }
.dev-tabs { display: grid; grid-template-columns: repeat(4, 1fr); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.dev-tabs button { border: 0; background: none; padding: 11px 0 10px; font-size: 15px; font-weight: 700; color: var(--muted); position: relative; }
.dev-tabs button.active { color: var(--accent); }
.dev-tabs button.active::after { content: ""; position: absolute; left: 25%; right: 25%; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent); }
.dev-page { padding-top: 12px; }
.dev-meta-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.dev-meta-line .src-tag { margin-left: auto; }
.conn-chip { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--ok-bg); color: var(--ok); }
.conn-chip.off { background: var(--alarm-bg); color: var(--alarm); }
.update-line { text-align: center; font-size: 13px; color: var(--muted); margin: 8px 0 10px; }
.update-line b { color: var(--text); }
.side-seg { margin-bottom: 10px; }
.field-tools { display: flex; align-items: center; gap: 10px; font-size: 13px; margin-bottom: 4px; }
.field-tools .spacer { flex: 1; }
.t-accent { color: var(--accent); }
.switch.sm { width: 42px; height: 24px; }
.switch.sm span::before { width: 18px; height: 18px; }
.switch.sm input:checked + span::before { transform: translateX(18px); }
.fgroup-head { padding: 12px 2px 8px; font-size: 15px; }
.fgroup-head em { font-style: normal; font-weight: 500; font-size: 12px; color: var(--muted); margin-left: 10px; }
.fgroup-head .fold { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; color: var(--muted); }
.fgroup-head .fold svg { width: 18px; height: 18px; }
.fgroup-body.flat { margin-top: 8px; }
.frow { background: var(--surface-2); border-radius: 10px; min-height: 46px; padding: 11px 14px; }
.frow.lost .fname { color: var(--muted); }
.add-param { margin: 12px 0 8px; }
.add-param svg { width: 18px; height: 18px; }
.series-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.series-list li { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 10px; padding: 6px 6px 6px 14px; min-height: 44px; font-weight: 600; font-size: 14px; }
.series-list li i { width: 14px; height: 4px; border-radius: 2px; flex: none; }
.series-list li i.dash { background: repeating-linear-gradient(90deg, var(--c) 0 5px, transparent 5px 8px); }
.series-list li span { flex: 1; }
.series-list li.th { font-weight: 500; color: var(--muted); padding-right: 14px; }
.series-list .del { color: var(--alarm); }

/* 日誌：本地 / 遠端設定標籤 */
.log { display: block; padding: 11px 14px; }
.log-top { display: flex; align-items: center; gap: 8px; font-size: 14px; justify-content: flex-start; }
.ltag { flex: none; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; color: #fff; background: #64748b; }
.ltag.local { background: #7c3aed; }
.ltag.remote { background: #475569; }
.ltag.alarm { background: #dc2626; }
.ltag.prealarm { background: #b7791f; }
.ltag.system { background: #15803d; }
.log-title { font-weight: 600; }
.log-bottom { display: flex; justify-content: space-between; gap: 10px; margin-top: 4px; font-size: 13px; }

/* 我的告警 */
.alarm-card { gap: 2px; }
.alarm-card b { font-size: 15px; }
.alarm-row { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.alarm-row em { font-style: normal; font-weight: 700; white-space: nowrap; }
.alarm-row.muted { font-size: 12px; }

/* 設定頁（表單式） */
.form-block { display: grid; gap: 2px; }
.hello-line { margin: 0; color: var(--muted); }
.hello-name { margin: 2px 0 10px; font-size: 20px; font-weight: 700; text-align: center; }
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 50px; border-top: 1px solid var(--border); }
.form-row > span { color: var(--muted); flex: none; }
.form-row select { min-width: 0; max-width: 62%; height: 38px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); font-weight: 600; }
.form-hint { margin: 0 0 6px; text-align: right; }
.small-seg { width: 150px; }
.small-seg button { padding: 6px 8px; }
.small-seg button:disabled { cursor: default; }
.small-btn { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.footer-note { text-align: center; color: var(--muted); font-size: 12px; margin-top: 18px; line-height: 1.7; }

/* 派工（規劃中） */
.badge-soon { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--warn-bg); color: var(--warn); vertical-align: 2px; }
.plan-list { padding-left: 20px; line-height: 1.8; margin: 6px 0 0; }

/* ═════════ 鎖定畫面縮放（仿原生 APP） ═════════ */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { overscroll-behavior: none; overflow-x: clip; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.root-nav, .topbar, .dev-tabs, .folder-bar, .area-bar, .seg, .btn, button, .fgroup-head, .dev-card, .site-card { -webkit-user-select: none; user-select: none; }
.table-wrap, .table-scroll { overscroll-behavior-x: contain; touch-action: pan-x pan-y; }
input, select, textarea { font-size: max(16px, 1em); }   /* iOS 小於 16px 會自動放大 */
