/* 分组框布局 · 深夜蓝底 + 琥珀电光
   骨架：可分组的盒子并列铺开，首屏就能看到全部主要读数；
   保留衬线数字、刻度和仪表般的克制配色。 */

@font-face {
  font-family: "IBM Plex Sans";
  src: url("/fonts/IBMPlexSans-latin.woff2") format("woff2");
  /* 可变字体，一个文件覆盖 400–600 */
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
                 U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
                 U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #0d1526;
  --box: #111b2e;
  --box-head: #142034;
  --line: #1f2b45;
  --line-soft: #1a2540;
  --ink: #eef3fb;
  --ink-mid: #b9c5da;
  --ink-dim: #8b9ab5;
  --amber: #ffb020;
  --amber-soft: #ffc75a;
  --alert: #ff6b6b;
  --ok: #3ddc97;
  --r: 10px;
  --dur: .2s;
  --ease: cubic-bezier(.22, .61, .36, 1);
  --tap: cubic-bezier(.34, 1.56, .64, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  /* 数字与拉丁走 IBM Plex Sans，中文回落到系统黑体 */
  font: 15px/1.5 "IBM Plex Sans", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

h1, h2, p, dl, dt, dd { margin: 0; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

/* ---------- 顶栏 ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px clamp(16px, 3.4vw, 30px);
  background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
}

.room b { display: block; font-size: 15px; font-weight: 500; letter-spacing: .01em; }
.room span { display: block; margin-top: 3px; font-size: 12px; color: var(--ink-dim); }
.acts { display: flex; gap: 8px; flex: 0 0 auto; }

.act {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  font-size: 13px;
  color: var(--ink-mid);
  border: 1px solid var(--line);
  border-radius: 8px;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
              background var(--dur) var(--ease), transform .12s var(--tap);
}

.act svg {
  width: 14px; height: 14px;
  fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
}

.act:hover { color: var(--ink); border-color: #2d3c5e; background: #16203480; }
.act:active { transform: translateY(1px) scale(.98); }
.act:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.act[disabled] { opacity: .55; cursor: default; }
.act.is-busy svg { animation: spin .8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 状态条 ---------- */

.status {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px clamp(16px, 3.4vw, 30px);
  font-size: 13px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--box-head);
}

.status.is-on { display: flex; }
.status[data-kind="info"] { color: var(--ink-mid); }
.status[data-kind="ok"] { color: var(--ok); }
.status[data-kind="warn"] { color: var(--amber); }
.status[data-kind="error"] { color: #ff9a9a; }

.status-action {
  margin-left: auto;
  font-size: 12px;
  color: inherit;
  border-bottom: 1px solid currentColor;
  padding-bottom: 1px;
}

/* ---------- 分组框棋盘 ---------- */

.board {
  max-width: 1280px;
  margin: 0 auto;
  padding: clamp(14px, 2.4vw, 22px) clamp(14px, 3.4vw, 30px) 46px;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: clamp(12px, 1.6vw, 18px);
  align-content: start;
}

.box {
  grid-column: span 12;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--box);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  animation: rise .42s var(--ease) both;
}

/* 宽屏：主读数占大头，概览在右侧；曲线全宽；记录与会话并排 */
@media (min-width: 960px) {
  .box-balance { grid-column: span 7; }
  .box-overview { grid-column: span 5; }
  .box-chart { grid-column: span 12; }
  /* 记录表与会话都走通栏：并排时两框高度对不齐，会拉出一片空白 */
  .box-days { grid-column: span 12; }
  .box-session { grid-column: span 12; }
  .box-logs { grid-column: span 12; }
}

.box-balance { animation-delay: .02s; }
.box-overview { animation-delay: .06s; }
.box-chart { animation-delay: .1s; }
.box-days { animation-delay: .14s; }
.box-session { animation-delay: .18s; }
.box-logs { animation-delay: .22s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 11px 16px;
  background: var(--box-head);
  border-bottom: 1px solid var(--line);
}

.box-head h2 { font-size: 13px; font-weight: 600; letter-spacing: .02em; }
.box-meta { font-size: 12px; color: var(--ink-dim); }

.box-body { padding: 16px; flex: 1; min-height: 0; }

/* ---------- 剩余电量（主读数） ---------- */

.box-balance { border-color: #2a3752; }

.box-balance .big {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.box-balance .big span {
  font-family: "IBM Plex Sans", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: clamp(52px, 7.4vw, 76px);
  line-height: 1;
  font-weight: 500;
  letter-spacing: -.02em;
}

.box-balance .big small { font-size: 15px; color: var(--ink-dim); }

.big-note { margin-top: 8px; font-size: 13px; color: var(--ink-mid); }

body[data-status="warn"] .box-balance .big span { color: var(--amber-soft); }
body[data-status="error"] .box-balance .big span { color: #ff9a9a; }

.facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 20px;
  border-top: 1px solid var(--line-soft);
}

.facts > div {
  padding: 13px 12px 3px 0;
  border-right: 1px solid var(--line-soft);
  min-width: 0;
}

.facts > div:last-child { border-right: none; padding-right: 0; }
.facts > div:not(:first-child) { padding-left: 14px; }

.facts dt { font-size: 12px; color: var(--ink-dim); }

.facts dd {
  margin-top: 5px;
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.facts b { font-size: 19px; font-weight: 500; letter-spacing: -.01em; }
.facts i { font-style: normal; font-size: 12px; color: var(--ink-dim); }

.facts-wide { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 0; border-top: none; }
.facts-wide > div { padding: 4px 0 12px; border-right: none; }
.facts-wide > div:not(:first-child) { padding-left: 0; }

/* 会话四项横排，通栏时不至于只有左上角一小撮 */
@media (min-width: 760px) {
  .facts-wide { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 20px; }
}

/* ---------- 概览三格 ---------- */

.stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 16px;
}

.stats > div {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 4px 12px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line-soft);
}

.stats > div:last-child { border-bottom: none; padding-bottom: 0; }
.stats dt { font-size: 12px; color: var(--ink-dim); }

.stats dd {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 3px;
}

.stats b { font-size: 24px; font-weight: 500; letter-spacing: -.01em; }
.stats i { font-style: normal; font-size: 12px; color: var(--ink-dim); }
.stats small { grid-column: 1 / -1; font-size: 12px; color: var(--ink-dim); }

/* ---------- 曲线 ---------- */

.ranges { display: flex; gap: 6px; }

.range {
  font-size: 12px;
  padding: 4px 11px;
  color: var(--ink-dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
              background var(--dur) var(--ease);
}

.range:hover { color: var(--ink-mid); border-color: #2d3c5e; }
.range.is-on { color: var(--amber); border-color: #5a4419; background: #2a2213; }

.chart-wrap { position: relative; overflow-x: auto; }
.chart-wrap canvas { display: block; width: 100%; }

.empty {
  padding: 46px 12px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-dim);
}

.chart-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--ink-dim);
}

/* ---------- 表格 ---------- */

/* 表头 34.5 + 行高 36.5 × 10 ≈ 400：滚动区正好停在整行边界，不出现半行 */
.table-wrap { max-height: 400px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  color: var(--ink-dim);
  background: var(--box);
  border-bottom: 1px solid var(--line);
}

tbody td {
  padding: 8px 10px;
  color: var(--ink-mid);
  border-bottom: 1px solid var(--line-soft);
}

tbody tr:last-child td { border-bottom: none; }
tbody td:first-child { color: var(--ink); }
th.num, td.num { text-align: right; }
td.up { color: #ff9a9a; }
td.down { color: var(--ok); }

/* ---------- 会话 / 日志 ---------- */

.hint { margin-top: 12px; font-size: 13px; line-height: 1.6; color: var(--ink-dim); }

.log-list { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow: auto; }

/* 宽屏时日志分两栏，避免整行只占左侧留出大片空白 */
@media (min-width: 900px) {
  .log-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 26px;
  }
}

.log-list li {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  font-size: 12.5px;
  color: var(--ink-mid);
  border-bottom: 1px solid var(--line-soft);
}

.log-list li:last-child { border-bottom: none; }
.log-list li.error { color: #ff9a9a; }
.log-time { flex: 0 0 132px; color: var(--ink-dim); }

/* ---------- 设置 ---------- */

.dialog {
  width: min(560px, calc(100vw - 28px));
  max-height: min(88vh, 780px);
  padding: 0;
  color: var(--ink);
  background: var(--box);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 30px 70px -28px #000;
  overflow: hidden;
}

.dialog::backdrop { background: #05090fcc; }

.dialog form { display: flex; flex-direction: column; max-height: inherit; }

.dialog-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 18px 20px 4px; }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 0;
}

.dialog-head h2 { font-size: 16px; font-weight: 600; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  color: var(--ink-dim);
  border-radius: 7px;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}

.icon-btn:hover { color: var(--ink); background: var(--box-head); }
.icon-btn svg {
  width: 14px; height: 14px;
  fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round;
}

fieldset {
  margin: 0 0 14px;
  padding: 12px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

legend { padding: 0 6px; font-size: 12px; color: var(--ink-dim); }

label { display: block; margin-bottom: 10px; font-size: 13px; }
label > span { display: block; margin-bottom: 5px; color: var(--ink-mid); }

input[type="text"], input[type="number"], input:not([type]), input[type="file"], select {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

input::placeholder { color: #61708e; }

input:focus, select:focus {
  outline: none;
  border-color: #8a6a1e;
  box-shadow: 0 0 0 3px #ffb02026;
}

input[type="file"] { padding: 7px 10px; color: var(--ink-mid); }

.row-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-actions .hint { margin: 0; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  flex: 0 0 auto;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
  background: var(--box);
}

.btn {
  padding: 9px 16px;
  font-size: 13px;
  border: 1px solid transparent;
  border-radius: 8px;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              transform .12s var(--tap);
}

.btn:active { transform: scale(.98); }

.btn-quiet { color: var(--ink-mid); border-color: var(--line); }
.btn-quiet:hover { color: var(--ink); background: var(--box-head); }

.btn-primary { color: #1a1206; background: var(--amber); font-weight: 600; }
.btn-primary:hover { background: var(--amber-soft); }

/* ---------- 窄屏 ---------- */

@media (max-width: 700px) {
  .bar { padding: 13px 16px; }
  .act span { display: none; }
  .act { padding: 9px; }
  .act svg { width: 16px; height: 16px; }

  .board { padding: 14px 14px 34px; gap: 13px; }
  .box-head { padding: 11px 14px; }
  .box-body { padding: 14px; }

  .box-balance .big span { font-size: clamp(48px, 15vw, 66px); }

  .facts { grid-template-columns: 1fr; margin-top: 16px; border-top: none; }
  .facts > div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 10px 0;
    border-right: none;
    border-bottom: 1px solid var(--line-soft);
  }
  .facts > div:not(:first-child) { padding-left: 0; }
  .facts > div:last-child { border-bottom: none; }
  .facts dd { margin-top: 0; }

  .facts-wide { grid-template-columns: 1fr; }
  .facts-wide > div { padding: 9px 0; }

  .stats { padding: 14px; }
  .stats b { font-size: 21px; }

  .chart-foot { flex-direction: column; gap: 3px; }
  .log-list li { flex-direction: column; gap: 2px; }
  .log-time { flex-basis: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-delay: 0ms !important;
    transition-duration: .001ms !important;
  }
}
