/* ===================== 设计变量 ===================== */
:root {
  --bg:          #f3f5f9;
  --panel:       #ffffff;
  --panel-soft:  #f8fafc;
  --line:        #e4e8ef;
  --line-soft:   #eef1f6;
  --text:        #1b2430;
  --text-2:      #475468;
  --muted:       #7c8798;
  --brand:       #2563eb;
  --brand-soft:  #eef3ff;
  --brand-deep:  #1d4ed8;
  --teal:        #0d9488;
  --amber:       #d97706;
  --red:         #d92b2b;   /* 上涨 / 增加 */
  --green:       #15803d;   /* 下跌 / 减少 */
  --shadow-sm:   0 1px 2px rgba(20, 30, 50, .06);
  --shadow:      0 4px 16px rgba(20, 30, 50, .08);
  --shadow-lg:   0 18px 48px rgba(20, 30, 50, .16);
  --r:           10px;
  --r-sm:        7px;
  --sidebar-w:   232px;
  /* 前端版本哨兵：JS 启动时读取它来判断浏览器是否缓存了旧样式。
   * 每次发布改动样式/结构后必须 +1。 */
  --app-css-ver: 13;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
[hidden] { display: none !important; }

/* ===================== 通用控件 ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: #fff; color: var(--text-2);
  cursor: pointer; white-space: nowrap;
  transition: .15s ease;
  user-select: none;
}
.btn:hover { border-color: #cdd5e2; background: var(--panel-soft); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-deep); border-color: var(--brand-deep); color: #fff; }
.btn-danger { background: #fff; border-color: #f0c4c4; color: var(--red); }
.btn-danger:hover { background: #fdf2f2; border-color: #e3a3a3; color: var(--red); }
.btn-ghost { background: transparent; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-xs { height: 24px; padding: 0 8px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }
.btn-link { border: 0; background: none; color: var(--brand); padding: 0 4px; cursor: pointer; }
.btn-link:hover { text-decoration: underline; background: none; }

.link { border: 0; background: none; color: var(--brand); cursor: pointer; padding: 0; }
.link:hover { text-decoration: underline; }

.field { display: block; margin-bottom: 12px; font-size: 13px; color: var(--text-2); }
.field > span.label, .field.label { display: block; }
.field input, .field select, .field textarea {
  display: block; width: 100%; margin-top: 5px;
  height: 36px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: #fff; color: var(--text);
  transition: .15s;
}
.field textarea { height: auto; min-height: 88px; padding: 9px 11px; resize: vertical; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.field .hint { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar .spacer { flex: 1; }
.input-inline {
  height: 34px; padding: 0 11px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: #fff; min-width: 140px;
}
.input-inline:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }

/* ===================== 登录页 ===================== */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 32px 16px;
  background:
    radial-gradient(1100px 520px at 12% -10%, #dfe8ff 0%, rgba(223,232,255,0) 60%),
    radial-gradient(900px 480px at 92% 6%, #d9f2ee 0%, rgba(217,242,238,0) 58%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg);
  padding: 26px 26px 20px;
}
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; }
.brand-mark {
  flex: none; width: 46px; height: 46px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--brand) 0%, #4f7ff5 55%, var(--teal) 130%);
  color: #fff; font-weight: 800; letter-spacing: .5px; font-size: 15px;
  box-shadow: 0 6px 16px rgba(37, 99, 235, .3);
}
.brand-mark.sm { width: 34px; height: 34px; border-radius: 9px; font-size: 12px; box-shadow: none; }
.brand-text h1 { font-size: 17px; letter-spacing: .2px; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.tabs { display: flex; gap: 4px; padding: 3px; background: var(--panel-soft); border: 1px solid var(--line-soft); border-radius: 9px; margin-bottom: 16px; }
.tab { flex: 1; height: 32px; border: 0; background: transparent; border-radius: 7px; color: var(--muted); cursor: pointer; font-weight: 500; }
.tab.is-active { background: #fff; color: var(--text); box-shadow: var(--shadow-sm); font-weight: 600; }

.seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--panel-soft); border-radius: 8px; margin-bottom: 16px; width: 100%; }
.seg-btn { flex: 1; height: 30px; border: 0; background: transparent; border-radius: 6px; color: var(--muted); cursor: pointer; font-size: 13px; }
.seg-btn.is-active { background: #fff; color: var(--brand); font-weight: 600; box-shadow: var(--shadow-sm); }

.auth-form .btn-block { margin-top: 6px; }
.auth-links { margin-top: 12px; text-align: center; font-size: 13px; }
.code-row { display: flex; gap: 8px; margin-top: 5px; }
.code-row input { margin-top: 0; flex: 1; min-width: 0; }
.code-row .btn { height: 36px; flex: none; width: 112px; padding: 0 8px; }
.auth-form [data-mail-status] { margin-bottom: 14px; }
.auth-migration-title { font-size: 17px; margin: 0 0 18px; }
.migration-counts { margin: 14px 0; font-size: 13px; }
.migration-counts > div { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--line-soft); }
.migration-counts dd { margin: 0; font-variant-numeric: tabular-nums; }
.migration-confirm { display: flex; align-items: flex-start; gap: 8px; margin: 14px 0; font-size: 13px; }
.migration-confirm input { flex: none; width: 16px; height: 16px; margin-top: 2px; }
.auth-msg { min-height: 20px; margin: 14px 0 0; font-size: 13px; color: var(--red); }
.auth-msg.ok { color: var(--green); }

/* ===================== 应用骨架 ===================== */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px 16px; border-bottom: 1px solid var(--line-soft); }
.side-brand-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.side-brand-text strong { font-size: 14px; }
.side-brand-text span { font-size: 11px; color: var(--muted); }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 3px; flex: 1; overflow: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  height: 38px; padding: 0 11px; border-radius: 8px;
  color: var(--text-2); font-size: 13.5px; font-weight: 500;
  transition: .13s;
}
.nav-item svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-item:hover { background: var(--panel-soft); color: var(--text); }
.nav-item.is-active { background: var(--brand-soft); color: var(--brand-deep); font-weight: 600; }

.side-foot { padding: 12px; border-top: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: 8px; }
.period-chip {
  font-size: 12px; color: var(--muted); background: var(--panel-soft);
  border: 1px solid var(--line-soft); border-radius: 7px; padding: 6px 10px; text-align: center;
}
.period-chip b { color: var(--brand-deep); }
.side-user { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); padding: 0 2px; flex-wrap: wrap; }
.side-user .dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; flex: none; }
.side-user #side-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1 1 auto; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  padding: 18px 26px 14px; background: rgba(243,245,249,.86); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar-title h2 { font-size: 19px; }
.topbar-title p { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.view { padding: 20px 26px 40px; }

/* ===================== 卡片 / 栅格 ===================== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 15px 16px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.kpi::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--brand); opacity: .85; }
.kpi.k-teal::after { background: var(--teal); }
.kpi.k-amber::after { background: var(--amber); }
.kpi.k-slate::after { background: #94a3b8; }
.kpi-label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 25px; font-weight: 700; letter-spacing: -.4px; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-value .unit { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.kpi-foot { font-size: 12px; color: var(--muted); }
.kpi-foot .up { color: var(--red); font-weight: 600; }
.kpi-foot .down { color: var(--green); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 14px; }
.grid-2.even { grid-template-columns: 1fr 1fr; }
@media (max-width: 1080px) { .grid-2, .grid-2.even { grid-template-columns: 1fr; } }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); margin-bottom: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }
/* 手机端可折叠工具区：桌面端不产生盒子（子元素直接参与 card-head 的 flex 布局） */
.cab-tools { display: contents; }
.card-head h3 { font-size: 14.5px; }
.card-head .sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 8px; }
.card-head .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

/* ===================== 时间回溯 ===================== */
.hist-bar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 9px 16px; border-bottom: 1px solid var(--line-soft);
  background: var(--panel-soft); font-size: 12.5px; color: var(--text-2);
}
.hist-bar.is-on { background: #fff8ec; border-bottom-color: #f3ddb0; }
.hist-bar .hist-bar-label { font-weight: 600; color: var(--text-2); }
.hist-bar .inline-field { display: inline-flex; align-items: center; gap: 6px; }
.hist-bar .input-inline { height: 28px; }
.hist-bar .sep { color: #cbd5e1; }
.hist-strip {
  display: flex; flex-wrap: wrap; gap: 7px; align-items: center;
  margin: 12px 16px 0; padding: 10px 12px; border-radius: var(--r-sm);
  background: #fff8ec; border: 1px solid #f3ddb0; font-size: 12.8px; color: var(--text-2);
}
.hist-strip .spacer { flex: 1; }
.hist-strip .sep { color: #e0c79a; }
.hist-badge {
  display: inline-flex; align-items: center; height: 20px; padding: 0 8px;
  border-radius: 999px; background: var(--amber); color: #fff;
  font-size: 11.5px; font-weight: 600; letter-spacing: .4px;
}
.hist-note { margin: 7px 16px 10px; font-size: 12px; color: var(--muted); line-height: 1.65; }
table.grid tr.is-hist td { background: #fffdf9; }
.card-body { padding: 16px; }
.card-body.tight { padding: 10px 16px 14px; }
.chart-box { position: relative; height: 260px; }
.chart-box.sm { height: 210px; }

/* ===================== 表格 ===================== */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 12px;
  padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
  background: var(--panel-soft); position: sticky; top: 0;
}
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
/* 行高统一：单元格不再逐字换行（窄屏 / 被挤压时逐字竖排会把行撑得高低不一），
   长内容交给 .table-wrap 横向滚动 */
table.grid td { white-space: nowrap; word-break: keep-all; }
table.grid tbody tr:hover { background: #fafbfe; }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 12.5px; }
table.grid .row-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
table.grid tr.is-total td { background: var(--brand-soft); font-weight: 700; border-top: 1px solid #d5e0fb; }
table.grid tr.is-clickable { cursor: pointer; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); font-size: 13px; }
.empty b { display: block; color: var(--text-2); font-size: 14px; margin-bottom: 4px; }

/* ===================== 标签 / 徽章 ===================== */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--panel-soft); color: var(--text-2); border: 1px solid var(--line);
}
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.tag.on   { background: #e9f9ef; color: var(--green); border-color: #bfe9cd; }
.tag.off  { background: #f4f6f9; color: #64748b; border-color: #e2e7ee; }
.tag.brand{ background: var(--brand-soft); color: var(--brand-deep); border-color: #cddcfd; }
.tag.amber{ background: #fdf5e7; color: var(--amber); border-color: #f3ddb0; }
.tag.plain::before { display: none; }

/* ===================== 模态框 ===================== */
.modal-mask {
  position: fixed; inset: 0; background: rgba(18, 26, 40, .45);
  display: grid; place-items: center; padding: 24px 16px; z-index: 200;
  animation: fade .14s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal {
  width: 100%; max-width: 560px; background: var(--panel); border-radius: 14px;
  box-shadow: var(--shadow-lg); max-height: 88vh; display: flex; flex-direction: column;
  animation: pop .16s ease;
}
@keyframes pop { from { transform: translateY(8px) scale(.985); opacity: .5 } to { transform: none; opacity: 1 } }
.modal.wide { max-width: 760px; }
.workbook-import-modal { grid-template-columns: minmax(0, 1fr); }
.workbook-import-modal .modal { min-width: 0; justify-self: center; }
.workbook-import-modal .modal-body { min-width: 0; overflow-wrap: anywhere; flex: 1; }
.workbook-import-modal .modal-body table.grid { min-width: 0; }
.workbook-import-modal select { min-width: 0; max-width: 100%; }
@media (max-width: 620px) {
  .workbook-import-modal .modal { max-width: 100%; }
}
.modal.narrow { max-width: 420px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 18px; border-bottom: 1px solid var(--line-soft); }
.modal-head h3 { font-size: 15px; }
.modal-head .x { border: 0; background: none; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.modal-head .x:hover { background: var(--panel-soft); color: var(--text); }
.modal-body { padding: 18px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 9px; padding: 13px 18px; border-top: 1px solid var(--line-soft); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.power-fields { border: 0; border-bottom: 1px solid var(--line-soft); padding: 0 0 4px; margin: 0 0 16px; min-width: 0; }
.power-fields legend { font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.power-state { display: flex; gap: 24px; margin-bottom: 12px; }
.power-state label { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.power-state input { accent-color: var(--brand); }
.power-fields input[type="datetime-local"] { min-width: 0; max-width: 100%; }
.cab-power-save { min-width: 132px; }
.power-repair-panel { border-left: 3px solid var(--amber); padding: 10px 12px; margin-bottom: 16px; background: #fff8ed; font-size: 13px; overflow-wrap: anywhere; }
.power-repair-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.power-repair-summary { margin: 9px 0; color: var(--text-2); line-height: 1.6; }
.power-repair-row { display: grid; gap: 5px; padding: 10px 0; border-top: 1px solid var(--line); }
.power-repair-row > div { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 6px; }
.power-repair-row time { font-variant-numeric: tabular-nums; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 620px) { .form-row, .form-row-3 { grid-template-columns: 1fr; } }
.note {
  font-size: 12.5px; color: var(--text-2); background: var(--panel-soft);
  border: 1px solid var(--line-soft); border-left: 3px solid var(--brand);
  border-radius: var(--r-sm); padding: 9px 12px; margin-bottom: 14px;
}
.note.warn { border-left-color: var(--amber); }
.note.danger { border-left-color: var(--red); background: #fdf5f5; border-color: #f2d4d4; }

/* ===================== Toast ===================== */
.toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 400; display: flex; flex-direction: column; gap: 9px; align-items: flex-end; }
.toast {
  background: #fff; border: 1px solid var(--line); border-left: 3px solid var(--brand);
  border-radius: var(--r-sm); box-shadow: var(--shadow); padding: 10px 14px;
  font-size: 13px; max-width: 380px; animation: slideIn .18s ease;
}
@keyframes slideIn { from { transform: translateX(16px); opacity: 0 } to { transform: none; opacity: 1 } }
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }

/* ===================== 其他小组件 ===================== */
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }

.bar-list { display: flex; flex-direction: column; gap: 11px; }
.bar-item .bar-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.bar-item .bar-top b { font-variant-numeric: tabular-nums; }
.bar-track { height: 7px; background: var(--line-soft); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--brand) 0%, #5b8def 100%); }
.bar-fill.teal { background: linear-gradient(90deg, var(--teal) 0%, #2dd4bf 100%); }

.detail-head { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; justify-content: space-between; margin-bottom: 15px; }
.detail-head .lead { display: flex; align-items: baseline; gap: 10px; }
.detail-head .lead .big { font-size: 26px; font-weight: 700; color: var(--brand-deep); font-variant-numeric: tabular-nums; }
.detail-head .lead .cap { font-size: 12.5px; color: var(--muted); }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 11px 16px; border-top: 1px solid var(--line-soft); font-size: 13px; color: var(--muted); }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); margin: 4px 0 10px; }
.checkbox-row input { width: 15px; height: 15px; accent-color: var(--brand); }

/* 批量编辑：勾选框 + 字段输入 */
.edit-field { display: grid; grid-template-columns: 132px 1fr; align-items: center; gap: 10px; margin-bottom: 10px; }
.edit-field > label.chk { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.edit-field > label.chk input { width: 15px; height: 15px; accent-color: var(--brand); }
.edit-field input, .edit-field select {
  width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--line);
  border-radius: 7px; background: #fff; color: var(--text); font-size: 13.5px; font-family: inherit;
}
.edit-field input:focus, .edit-field select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
.edit-field input:disabled, .edit-field select:disabled { background: var(--panel-soft); color: var(--muted); cursor: not-allowed; }

.loading { padding: 46px; text-align: center; color: var(--muted); font-size: 13px; }
.spinner {
  width: 22px; height: 22px; margin: 0 auto 10px;
  border: 2.5px solid var(--line); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.text-red { color: var(--red); }
.text-green { color: var(--green); }
.text-amber { color: var(--amber); }

/* 角色 / 状态小胶囊（与 .tag 区分：无圆点、更紧凑） */
.chip {
  display: inline-flex; align-items: center; height: 20px; padding: 0 9px;
  border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--panel-soft); color: var(--text-2); border: 1px solid var(--line);
}
.chip.ok   { background: #eef3ff; color: var(--brand-deep); border-color: #cddcfd; }
.chip.warn { background: #fdf5e7; color: var(--amber); border-color: #f3ddb0; }
.chip.dark { background: #eef1f6; color: #475468; border-color: #dfe4ec; }

/* 业务划分标签 */
.biz-tag {
  display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  padding: 1px 8px; border-radius: 6px; font-size: 12px; line-height: 18px;
  background: #f3efff; color: #6d3fd1; border: 1px solid #e0d5fb; white-space: nowrap;
}

/* 表格里的「操作」单元格（有一列写按钮时避免塌陷） */
.row-act { text-align: right; white-space: nowrap; }
.row-act .btn + .btn { margin-left: 6px; }
table.grid th.col-ops, table.grid td.col-ops { width: 1%; white-space: nowrap; text-align: right; }
table.grid th.col-check, table.grid td.col-check { width: 30px; text-align: center; }
table.grid td.col-check input { width: 16px; height: 16px; accent-color: var(--brand); }

/* 只读游客账号的提示条 */
.viewer-bar {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  padding: 9px 26px; font-size: 12.5px; color: #8a5a00;
  background: #fff8ec; border-bottom: 1px solid #f3ddb0;
}
.viewer-bar .chip { flex: none; }

/* 设置页「手机访问」：二维码 + 局域网地址 */
.mobile-access { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; margin-top: 14px; }
.qr-box {
  flex: none; width: 168px; height: 168px; padding: 7px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
}
.qr-box svg { display: block; width: 100%; height: 100%; }
.qr-info { flex: 1 1 260px; min-width: 0; }
.addr-row {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  padding: 8px 10px; margin-bottom: 6px;
  background: var(--panel-soft); border: 1px solid var(--line-soft); border-radius: var(--r-sm);
}
.addr-host {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px;
  color: var(--text); overflow-wrap: anywhere;
}

/* 环境自检告警条：浏览器缓存了旧样式 / 手机开了电脑版模式 */
.env-banner {
  position: fixed; left: 0; right: 0; top: 0; z-index: 200;
  background: #7f1d1d; color: #fff;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 8px;
  font-size: 13px; line-height: 1.5;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
.env-banner .env-row {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  max-width: 860px; margin: 0 auto;
}
.env-banner button {
  flex: none; height: 30px; padding: 0 14px; border: 0; border-radius: 6px;
  background: #fff; color: #7f1d1d; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.env-banner .env-close {
  position: absolute; right: 6px; top: calc(4px + env(safe-area-inset-top, 0px));
  width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .18); color: #fff;
  font-size: 17px; line-height: 1; font-weight: 400; cursor: pointer;
}

/* 只在手机上显示的入口（桌面端已有侧边栏对应入口，避免重复） */
.only-mobile { display: none !important; }
@media (max-width: 820px) { .only-mobile { display: inline-flex !important; } }

/* ===================== 移动端适配（手机 / 纯血鸿蒙 HarmonyOS）=====================
 * 目标设备：手机（360–430px 逻辑宽度），覆盖鸿蒙 ArkWeb、iOS WKWebView、Android Chrome。
 * 策略：
 *   1. 侧边栏 → 固定「底部标签栏」，拇指可达，符合鸿蒙原生交互习惯；
 *   2. 顶栏吸附顶部，并为刘海 / 状态栏 / 手势条让出安全区（env(safe-area-inset-*)）；
 *   3. 数据表格自动「卡片化」（依据单元格上的 data-label，无需改结构）；
 *   4. 触控目标 ≥ 44px，去掉只靠 hover 才出现的操作；
 *   5. 输入框字号 ≥ 16px，避免移动端聚焦时整页被自动放大。
 * =========================================================================== */
.table-wrap { -webkit-overflow-scrolling: touch; }

:root {
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
  --tabbar-h:    0px;   /* 桌面端无底部标签栏，由媒体查询覆盖 */
}

@media (max-width: 820px) {
  :root { --tabbar-h: 54px; }

  html, body { overscroll-behavior-x: none; }
  /* 任何元素都不得把页面撑宽：撑宽会触发手机浏览器「自动缩小以适应」，
   * 整页看起来就像缩水的电脑版。clip 不产生滚动容器，不影响 sticky 定位。 */
  html, body { max-width: 100%; overflow-x: clip; }
  body { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
  .app-shell { flex-direction: column; min-height: 100vh; min-height: 100dvh; }

  /* ---------- 底部标签栏 ---------- */
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; height: auto; flex-direction: row; align-items: stretch; gap: 0;
    padding: 5px calc(5px + var(--safe-left)) calc(5px + var(--safe-bottom)) calc(5px + var(--safe-right));
    border-right: 0; border-top: 1px solid var(--line);
    box-shadow: 0 -2px 14px rgba(20, 30, 50, .07);
    z-index: 120;
  }
  .side-brand, .side-foot { display: none !important; }

  .nav { flex: 1; flex-direction: row; flex-wrap: nowrap; gap: 2px; padding: 0; overflow: visible; }
  .nav-item {
    flex: 1 1 0; min-width: 0; height: auto; min-height: 44px;
    flex-direction: column; justify-content: center; gap: 3px;
    padding: 3px 2px; border-radius: 10px;
    font-size: 10.5px; font-weight: 500; line-height: 1.15;
  }
  .nav-item svg { width: 21px; height: 21px; stroke-width: 1.6; }
  .nav-item > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-item:hover { background: transparent; }
  .nav-item.is-active { background: var(--brand-soft); }
  .nav-item:active { background: var(--panel-soft); }

  /* ---------- 顶栏 ---------- */
  .topbar {
    position: sticky; top: 0; z-index: 90;
    padding: calc(7px + var(--safe-top)) calc(12px + var(--safe-right)) 7px calc(12px + var(--safe-left));
    align-items: center; flex-wrap: wrap; gap: 6px;
    background: rgba(255, 255, 255, .92);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  }
  .topbar-title { flex: 1 1 auto; min-width: 0; }
  .topbar-title h2 { font-size: 16px; }
  .topbar-title p { font-size: 11.5px; }
  .topbar-actions { flex: 0 0 auto; justify-content: flex-end; }

  .viewer-bar { padding: 7px calc(12px + var(--safe-right)) 7px calc(12px + var(--safe-left)); }

  /* 给底部标签栏 + 手势条留出高度，避免内容被永久遮挡 */
  .main { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom)); }
  .view { padding: 10px calc(10px + var(--safe-right)) 18px calc(10px + var(--safe-left)); }

  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi-value { font-size: 20px; }
  .card-head { padding: 9px 12px; }
  .card-body { padding: 11px; }
  .chart-box { height: 190px; }

  /* 触控目标放大：手机上按钮不再有小号 */
  .btn { min-height: 38px; }
  .btn-xs { min-height: 32px; padding: 0 12px; font-size: 12.5px; }
  .card-head .actions .btn, .toolbar .btn { min-height: 36px; }

  /* ---------- 表格卡片化 ----------
   * 手机上一行字段铺一整行太占屏幕（一个机柜卡片曾高达 500px），
   * 改为「自适应多列字段网格」：标签在上、值在下，390px 屏通常 3 列、大屏 4 列、超窄屏 2 列。
   * 多列排布腾出的空间用来把字号放大（值 15px / 标签 12.5px），比单纯缩字更易读。
   * 标题 / 勾选 / 操作列通过 c-lead / c-full / col-ops 占满整行；
   * 勾选框叠加到卡片右上角，不再独占一行；
   * 空值占位（"-" / "—"）单元格由 U.markEmptyCells 打 c-empty 后直接隐藏。 */
  table.grid.cards { border-collapse: separate; border-spacing: 0; font-size: 15px; }
  table.grid.cards > thead { display: none; }
  table.grid.cards > tbody { display: block; }
  table.grid.cards > tbody > tr {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
    gap: 9px 10px; align-items: start;
    position: relative;
    margin-bottom: 8px; padding: 11px 12px;
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--r); box-shadow: var(--shadow-sm);
  }
  table.grid.cards > tbody > tr:last-child { margin-bottom: 0; }
  table.grid.cards > tbody > tr > td {
    display: block; width: auto; min-width: 0; padding: 0; text-align: left;
    border-bottom: 0; min-height: 0; line-height: 1.35;
    white-space: normal; word-break: normal; overflow-wrap: anywhere;
  }
  table.grid.cards > tbody > tr > td::before {
    content: attr(data-label);
    display: block; max-width: none; margin-bottom: 1px; text-align: left;
    color: var(--muted); font-size: 12.5px; line-height: 1.3; font-weight: 500;
  }
  table.grid.cards > tbody > tr > td:not([data-label])::before { display: none; }
  /* 空值占位：整个字段不显示，省出留白 */
  table.grid.cards > tbody > tr > td.c-empty { display: none; }
  /* 占满整行的单元格：记录标题 / 操作行 / 明确标记 c-full */
  table.grid.cards > tbody > tr > td.c-lead,
  table.grid.cards > tbody > tr > td.c-full,
  table.grid.cards > tbody > tr > td.col-ops,
  table.grid.cards > tbody > tr > td.row-act { grid-column: 1 / -1; }
  /* 标题行右侧留出勾选框的位置 */
  table.grid.cards > tbody > tr > td.c-lead { padding-right: 30px; font-size: 16px; }
  /* 勾选框叠加到卡片右上角（原来独占一行，太浪费版幅） */
  table.grid.cards > tbody > tr > td.col-check {
    position: absolute; top: 10px; right: 11px; z-index: 1;
    grid-column: auto; padding: 2px;
  }
  table.grid.cards > tbody > tr > td.col-check input[type="checkbox"] { width: 18px; height: 18px; }
  table.grid.cards > tbody > tr > td.col-check::before { display: none; }
  table.grid.cards > tbody > tr > td.col-ops::before,
  table.grid.cards > tbody > tr > td.row-act::before { display: none; }
  table.grid.cards .row-actions { justify-content: flex-start; flex-wrap: wrap; gap: 6px; }
  table.grid.cards .row-actions .btn { min-height: 34px; }
  table.grid.cards > tbody > tr > td.row-act:empty { display: none; }

  /* 展开的明细行 / 合计行不算卡片，保持整行 */
  table.grid.cards > tbody > tr.no-card,
  table.grid.cards > tbody > tr.is-total { display: block; }
  table.grid.cards > tbody > tr.no-card {
    margin: -6px 0 10px; padding: 0; border: 0; box-shadow: none;
  }
  table.grid.cards > tbody > tr.no-card > td { display: block; padding: 0; text-align: left; border-bottom: 0; white-space: normal; word-break: normal; }
  table.grid.cards > tbody > tr.no-card > td::before { display: none; }
  table.grid.cards > tbody > tr.is-total {
    padding: 8px 12px; background: var(--brand-soft); border-color: #d5e0fb;
  }
  table.grid.cards > tbody > tr.is-total > td { padding: 5px 0; border-bottom: 0; font-weight: 700; }
  table.grid.cards > tbody > tr.is-total > td:empty { display: none; }

  /* 未卡片化的普通表格：允许横向滑动，滚动提示更明显 */
  .table-wrap { overflow-x: auto; }
  table.grid:not(.cards) { min-width: 560px; }
}

@media (max-width: 620px) {
  body { font-size: 14.5px; }

  /* iOS / 鸿蒙上输入框字号小于 16px 会被自动放大，这里统一提升 */
  .field input, .field select, .field textarea,
  .input-inline, .edit-field input, .edit-field select, .code-row input { font-size: 16px; }
  .field input, .field select { height: 44px; }
  .field textarea { min-height: 96px; }
  .input-inline { height: 40px; min-width: 0; width: 100%; }

  .btn { height: auto; min-height: 42px; padding: 0 16px; }
  .btn-sm { min-height: 40px; }
  .btn-xs { min-height: 36px; }

  .topbar { align-items: flex-start; padding-top: calc(10px + var(--safe-top)); }
  .topbar-actions { width: 100%; justify-content: flex-start; }
  .topbar-actions .btn { flex: 1 1 auto; }
  .view { padding-bottom: 18px; }

  /* 弹窗在手机上占满整屏，标题与操作区固定可见 */
  .modal-mask { padding: 0; place-items: stretch; }
  .modal { max-width: none; height: 100%; max-height: 100vh; max-height: 100dvh; border-radius: 0; }
  .modal-head {
    position: sticky; top: 0; z-index: 2; background: var(--panel);
    padding: calc(11px + var(--safe-top)) calc(14px + var(--safe-right)) 11px calc(14px + var(--safe-left));
  }
  .modal-body { padding: 13px; }
  .modal-foot {
    position: sticky; bottom: 0; background: var(--panel);
    padding: 10px calc(14px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(14px + var(--safe-left));
  }
  .modal-foot .btn { flex: 1; }

  .edit-field { grid-template-columns: 1fr; gap: 6px; margin-bottom: 14px; }
  .edit-field > label.chk { margin-bottom: 2px; }
  .form-row, .form-row-3 { gap: 0; }

  table.grid .row-actions { gap: 6px; }

  /* ---------- 手机端工具栏折叠（机柜管理的筛选 / 批量按钮区） ---------- */
  .cab-tools { display: none; }
  .is-tools-open .cab-tools { display: block; }
  .hist-bar { display: none; }
  .is-tools-open .hist-bar { display: flex; }
  .hist-bar.is-on { display: flex; }   /* 回溯激活时始终可见 */

  /* 弹窗表单更紧凑：字段间距 / 输入框高度略降（字号仍 ≥16px 防自动放大） */
  .field { margin-bottom: 9px; }
  .field input, .field select { height: 42px; }
  .field textarea { min-height: 76px; }
  .modal-body { padding: 11px 12px; }

  /* 工具栏按钮铺满整行，拇指好按（不再右对齐错落） */
  .toolbar { gap: 8px; }
  .toolbar .spacer { display: none; }
  .toolbar > .btn { flex: 1 1 auto; }
  .toolbar .input-inline { flex: 1 1 100%; min-width: 0; }
  /* 紧凑版工具栏（操作日志页）：筛选控件两两并排，省一半高度 */
  .toolbar.compact .input-inline { flex: 1 1 calc(50% - 4px); }
  .toolbar.compact > .btn { flex: 0 0 auto; }
  .toolbar.compact .input-inline:first-child { flex: 1 1 100%; }

  .toast-root {
    left: calc(12px + var(--safe-left)); right: calc(12px + var(--safe-right));
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); align-items: stretch;
  }
  .toast { max-width: none; }

  .auth-wrap {
    padding: calc(20px + var(--safe-top)) calc(12px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(12px + var(--safe-left));
  }
  .auth-card { padding: 20px 18px 16px; border-radius: 14px; }
  .detail-head { gap: 10px; }
  .detail-head .lead .big { font-size: 22px; }
  .pager { justify-content: center; }
}

/* 超窄屏（约 320–359px）：栏目自动落回 2 列（auto-fit），这里只压缩标签栏 */
@media (max-width: 360px) {
  .nav-item { font-size: 9.5px; }
  .nav-item svg { width: 19px; height: 19px; }
  table.grid.cards { font-size: 14px; }
  table.grid.cards > tbody > tr > td::before { font-size: 11.5px; }
}

/* 横屏手机：底部标签栏在横屏下会很占地方，改为更矮的一行 */
@media (max-width: 820px) and (orientation: landscape) and (max-height: 520px) {
  :root { --tabbar-h: 42px; }
  .nav-item { min-height: 34px; }
  .nav-item svg { width: 17px; height: 17px; }
}

/* 触屏设备：hover 不生效，改为按下反馈，避免操作「点不出来」 */
@media (hover: none) {
  table.grid tbody tr:hover { background: transparent; }
  .nav-item:active { background: var(--panel-soft); }
  .btn:active { transform: translateY(1px); }
}
