/* style.css —— 视觉取材：设备自身的反射式段码屏 + 气象站"温湿记录仪"的记录纸与红蓝墨水 */
:root {
  --paper: #EDF1EC;        /* 记录纸底色 */
  --paper-2: #F5F8F4;      /* 曲线区纸面 */
  --grid: #C4D3CA;         /* 记录纸粗格 */
  --grid-minor: #DDE6E0;   /* 记录纸细格 */
  --glass: #C8CFBC;        /* 反射式 HTN 玻璃 */
  --glass-edge: #A7B09A;
  --segment: #1F2822;      /* 段码墨色 */
  --ink-t: #B3372C;        /* 温度笔：茜红 */
  --ink-h: #2E4B96;        /* 湿度笔：蓝紫墨水 */
  --text: #27312B;
  --muted: #5C6961;
  --line: #BFCBC3;
  --housing: #F8FAF7;      /* 表壳 */
  --font-ui: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei UI", "Microsoft YaHei",
             "Noto Sans CJK SC", "Source Han Sans SC", system-ui, sans-serif;
  --font-num: "Bahnschrift", "DIN Alternate", "DIN 2014", "Roboto Condensed", "Arial Narrow", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {                 /* 夜间：纸面变暗，段码玻璃保持实物般的浅色 */
    --paper: #161B18; --paper-2: #1B211E; --grid: #33403A; --grid-minor: #242D28;
    --text: #DCE4DE; --muted: #97A59D; --line: #33403A; --housing: #1F2622;
    --ink-t: #E26A5C; --ink-h: #86A0EA;
  }
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--text); font: 15px/1.6 var(--font-ui); -webkit-text-size-adjust: 100%; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px 56px; }
h1, h2, h3 { font-weight: 600; line-height: 1.3; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ink-h); outline-offset: 2px; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* ---------- 顶栏 ---------- */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; padding: 18px 0 14px; border-bottom: 1px solid var(--line); }
.top h1 { font-size: 1.25rem; margin: 0; }
#conn-state { color: var(--muted); font-size: .875rem; }
body.online #conn-state { color: var(--text); }
#batt-box { margin-left: auto; display: flex; align-items: center; gap: 10px; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
#batt { --soc: 0; position: relative; width: 30px; height: 14px; border: 1.5px solid currentColor; border-radius: 3px; }
#batt::before { content: ""; position: absolute; inset: 2px auto 2px 2px; width: calc((100% - 4px) * var(--soc) / 100); background: currentColor; border-radius: 1px; }
#batt::after { content: ""; position: absolute; right: -4px; top: 3px; width: 2.5px; height: 5px; background: currentColor; border-radius: 0 1px 1px 0; }
#batt-box.low { color: var(--ink-t); }
.btn { border: 1px solid var(--line); background: var(--housing); border-radius: 8px; padding: 6px 14px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--segment); border-color: var(--segment); color: #EEF2EC; padding: 8px 18px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.warn { color: var(--ink-t); }

#notice { margin: 14px 0 0; padding: 10px 14px; border-left: 3px solid var(--ink-h); background: var(--housing); }
#notice[data-kind="err"] { border-left-color: var(--ink-t); }

/* ---------- 两路探头：表壳 + 段码玻璃 ---------- */
.probes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin: 24px 0 0; }
.probe { background: var(--housing); border: 1px solid var(--line); border-radius: 16px; padding: 14px 18px 12px; }
.probe header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.probe h2 { font-size: 1rem; margin: 0; }
.pstate { color: var(--muted); font-size: .875rem; }
.glass { display: block; width: 100%; height: auto; margin: 12px 0 10px; background: var(--glass); border-radius: 6px;
         box-shadow: inset 0 1px 3px rgba(20, 30, 20, .35), inset 0 0 0 1px var(--glass-edge); }
.glass polygon, .glass circle { fill: var(--segment); opacity: .07; transition: opacity .12s linear; }  /* 未点亮段隐约可见，像真屏 */
.glass .on { opacity: .9; }
.glass .glab { font: 13px var(--font-ui); fill: var(--segment); opacity: .8; }
.glass .gunit { font: 600 19px var(--font-num); fill: var(--segment); }
.probe.dim .glass .on { opacity: .28; }
.probe footer { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; min-height: 30px; }
.probe .st { font-size: .8125rem; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { appearance: none; width: 34px; height: 20px; border-radius: 10px; background: var(--line); position: relative; margin: 0; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--segment); }
.switch input:checked::after { transform: translateX(14px); }
.switch input:disabled { opacity: .5; cursor: default; }

/* ---------- 曲线 ---------- */
.record { margin-top: 36px; }
.record h2 { font-size: 1.125rem; margin: 0 0 10px; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 10px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 5px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--segment); color: #EEF2EC; }
#legend { display: inline-flex; flex-wrap: wrap; gap: 4px 14px; margin-left: auto; }
#legend button { border: 0; background: none; padding: 2px 0; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: .875rem; }
#legend button::before { content: ""; width: 22px; border-top: 2px solid var(--c); }
#legend button.dash::before { border-top-style: dashed; }
#legend button[aria-pressed="false"] { opacity: .4; }
.t { --c: var(--ink-t); } .h { --c: var(--ink-h); }
.chart-box { position: relative; height: clamp(260px, 46vh, 460px); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--paper-2); }
#chart { display: block; touch-action: none; cursor: grab; }
#chart:active { cursor: grabbing; }
#chart-tip { position: absolute; pointer-events: none; background: var(--housing); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font-size: .8125rem; line-height: 1.5; white-space: nowrap; }
#chart-tip b { font-weight: 600; }
#chart-tip .k.t { color: var(--ink-t); } #chart-tip .k.h { color: var(--ink-h); }
#chart-empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; color: var(--muted); text-align: center; pointer-events: none; }
.sync { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 10px; font-size: .875rem; color: var(--muted); }
#sync-state.bad { color: var(--ink-t); }
#sync-bar { width: 160px; height: 6px; accent-color: var(--ink-h); }
#server-note { margin: 8px 0 0; font-size: .875rem; color: var(--ink-t); }
.help { color: var(--muted); font-size: .8125rem; margin: 6px 0 0; }

/* ---------- 设置 ---------- */
#settings { border: 0; padding: 0; margin: 36px 0 0; min-width: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 44px; }
#settings > legend { font-size: 1.125rem; font-weight: 600; padding: 0; margin-bottom: 4px; grid-column: 1 / -1; }
#settings:disabled .group { opacity: .55; }
.lock { grid-column: 1 / -1; color: var(--muted); font-size: .875rem; margin: 0; }
body.online .lock { display: none; }
.group h3 { font-size: .9375rem; margin: 22px 0 4px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.row { display: grid; grid-template-columns: 7.5em minmax(0, 1fr); align-items: center; gap: 2px 14px; padding: 8px 0; }
.row .lab { color: var(--muted); }
.row .st { grid-column: 2; font-size: .8125rem; color: var(--ink-h); min-height: 1.1em; }
.st.bad { color: var(--ink-t) !important; }
.opts { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; width: max-content; }
.opts label { position: relative; }
.opts input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.opts span { display: block; padding: 4px 12px; }
.opts label + label span { border-left: 1px solid var(--line); }
.opts input:checked + span { background: var(--segment); color: #EEF2EC; }
.opts input:focus-visible + span { outline: 2px solid var(--ink-h); outline-offset: -2px; }
.range { display: flex; align-items: center; gap: 10px; }
.range input { width: 160px; accent-color: var(--segment); }
select { border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; background: var(--housing); }
.ofs { display: grid; grid-template-columns: auto 6.5em 6.5em; gap: 8px 12px; align-items: center; }
.ofs .hd { font-size: .8125rem; color: var(--muted); }
.ofs input { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; background: var(--housing); font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.ofs .ti { color: var(--ink-t); } .ofs .hi { color: var(--ink-h); }
.info { display: grid; grid-template-columns: 7.5em minmax(0, 1fr); gap: 6px 14px; margin: 10px 0 0; }
.info dt { color: var(--muted); } .info dd { margin: 0; }
.foot { margin-top: 40px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: .8125rem; }

@media (max-width: 760px) {
  .probes, #settings { grid-template-columns: 1fr; }
  #batt-box { margin-left: 0; }
  #legend { margin-left: 0; }
  .row { grid-template-columns: 1fr; } .row .st { grid-column: 1; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
