/* ============================================================
   MG200 串口上位机 —— 界面样式
   左侧导航 + 顶部连接条 + 卡片式内容区
   ============================================================ */

:root {
  --paper: #f4f1e9;
  --paper-deep: #ebe5d8;
  --card: #fffdf8;
  --card-soft: #faf7ef;
  --ink: #18231f;
  --muted: #6d7a71;
  --line: #e2dbcb;
  --line-strong: #d3c9b5;
  --accent: #0f7a5a;
  --accent-deep: #0a5540;
  --accent-soft: rgba(15, 122, 90, 0.09);
  --amber: #b4650a;
  --amber-soft: rgba(180, 101, 10, 0.1);
  --red: #b42318;
  --red-soft: rgba(180, 35, 24, 0.09);
  --blue: #1f6fa8;
  --sidebar: #0f2a23;
  --sidebar-soft: #14362c;
  --sidebar-line: rgba(255, 255, 255, 0.08);
  --shadow-sm: 0 1px 2px rgba(35, 30, 18, 0.05), 0 6px 18px rgba(35, 30, 18, 0.04);
  --shadow-md: 0 18px 50px rgba(40, 33, 20, 0.1);
  --radius: 16px;
  --radius-sm: 11px;
  --mono: "Cascadia Code", "Consolas", "JetBrains Mono", "Microsoft YaHei UI", monospace;
  --sans: "Bahnschrift", "Segoe UI Variable Text", "Microsoft YaHei UI", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

/* 组件自带的 display 会覆盖 hidden 属性，这里统一兜底 */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 85% -10%, rgba(15, 122, 90, 0.1), transparent 62%),
    radial-gradient(900px 480px at -10% 0%, rgba(180, 101, 10, 0.07), transparent 55%),
    var(--paper);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

code,
pre,
input[type="text"],
input[type="number"],
input[type="search"],
textarea {
  font-family: var(--mono);
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

button {
  font-family: inherit;
}

/* ---------------- 整体布局 ---------------- */

.app {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: 100vh;
  padding: 22px 16px 18px;
  color: #e8f1ec;
  background:
    radial-gradient(420px 260px at 20% 0%, rgba(24, 138, 101, 0.28), transparent 70%),
    linear-gradient(180deg, var(--sidebar-soft), var(--sidebar) 55%);
  border-right: 1px solid rgba(0, 0, 0, 0.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 2px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.04em;
  color: #06231b;
  background: linear-gradient(150deg, #a8f0cd, #4fd1a1 55%, #23a87c);
  box-shadow: 0 10px 22px rgba(35, 168, 124, 0.3);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  white-space: nowrap;
}

.brand-text strong {
  font-size: 17px;
  letter-spacing: 0.02em;
}

.brand-text small {
  color: rgba(232, 241, 236, 0.62);
  font-size: 12px;
  letter-spacing: 0.12em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: rgba(232, 241, 236, 0.72);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
}

.nav-item:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
}

.nav-item.is-active {
  color: #ffffff;
  background: rgba(79, 209, 161, 0.16);
  border-color: rgba(79, 209, 161, 0.32);
}

.nav-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(232, 241, 236, 0.3);
  transition: background 160ms ease, box-shadow 160ms ease;
}

.nav-item.is-active .nav-dot {
  background: #4fd1a1;
  box-shadow: 0 0 0 4px rgba(79, 209, 161, 0.18);
}

.sidebar-foot {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 14px 10px 4px;
  border-top: 1px solid var(--sidebar-line);
  font-size: 11.5px;
  color: rgba(232, 241, 236, 0.6);
}

.sidebar-foot p {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(232, 241, 236, 0.85);
  font-size: 11px;
  letter-spacing: 0.02em;
}

.muted {
  color: inherit;
  opacity: 0.8;
}

.main {
  min-width: 0;
  padding: 22px 26px 44px;
}

/* ---------------- 顶部 ---------------- */

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.title-block h1 {
  font-size: 24px;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.title-block p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12.5px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 4px;
}

.seg {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
}

.seg button {
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.seg button.is-active {
  background: var(--card);
  color: var(--accent-deep);
  box-shadow: 0 1px 3px rgba(40, 33, 20, 0.12);
  font-weight: 700;
}

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
}

.conn-pill i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b8b1a0;
}

.conn-pill.is-live {
  border-color: rgba(15, 122, 90, 0.35);
  background: rgba(15, 122, 90, 0.08);
  color: var(--accent-deep);
}

.conn-pill.is-live i {
  background: #17a97b;
  box-shadow: 0 0 0 4px rgba(23, 169, 123, 0.18);
  animation: pulse 2s ease-in-out infinite;
}

.conn-pill.is-mock {
  border-color: rgba(180, 101, 10, 0.35);
  background: var(--amber-soft);
  color: #8a4c05;
}

.conn-pill.is-mock i {
  background: #d08a2c;
}

.conn-pill.is-error {
  border-color: rgba(180, 35, 24, 0.3);
  background: var(--red-soft);
  color: var(--red);
}

.conn-pill.is-error i {
  background: var(--red);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* ---------------- 连接条 ---------------- */

.connect-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

.connect-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.port-label {
  font-size: 11.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.port-select {
  min-width: 230px;
  max-width: 340px;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--card-soft);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12.5px;
}

.port-select:focus {
  outline: none;
  border-color: rgba(15, 122, 90, 0.5);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.connect-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 12.5px;
  color: var(--muted);
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: relative;
  width: 34px;
  height: 19px;
  border-radius: 999px;
  background: #d8d1c1;
  transition: background 160ms ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 160ms ease;
}

.switch input:checked + .switch-track {
  background: var(--amber);
}

.switch input:checked + .switch-track::after {
  transform: translateX(15px);
}

.switch input:disabled + .switch-track {
  opacity: 0.5;
}

/* ---------------- 按钮 ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: linear-gradient(140deg, #12886a, var(--accent-deep));
  color: #f4fffb;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, opacity 140ms ease, background 140ms ease;
  box-shadow: 0 6px 16px rgba(10, 85, 64, 0.22);
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(10, 85, 64, 0.26);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  box-shadow: none;
}

.btn.small {
  padding: 7px 13px;
  font-size: 12.5px;
}

.btn.ghost {
  background: var(--card);
  border-color: var(--line-strong);
  color: var(--accent-deep);
  box-shadow: none;
}

.btn.ghost:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: rgba(15, 122, 90, 0.4);
}

.btn.danger {
  background: linear-gradient(140deg, #c8402f, #97241a);
  box-shadow: 0 6px 16px rgba(151, 36, 26, 0.22);
}

.btn.ghost.danger {
  background: var(--card);
  border-color: rgba(180, 35, 24, 0.3);
  color: var(--red);
  box-shadow: none;
}

.btn.ghost.danger:hover:not(:disabled) {
  background: var(--red-soft);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---------------- 视图与卡片 ---------------- */

.views {
  min-width: 0;
}

.view {
  display: none;
  gap: 18px;
}

.view.is-active {
  display: grid;
}

.grid {
  display: grid;
  gap: 18px;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.card {
  min-width: 0;
  padding: 18px 20px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.card > header > h2,
.card-head h2 {
  font-size: 15.5px;
  letter-spacing: 0.01em;
}

.card > header > p,
.card-head p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12.5px;
}

.card > header {
  margin-bottom: 14px;
}

.card code {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(15, 122, 90, 0.08);
  color: var(--accent-deep);
  font-size: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card-soft);
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
}

.chip.ok {
  border-color: rgba(15, 122, 90, 0.3);
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.chip.warn {
  border-color: rgba(180, 101, 10, 0.3);
  background: var(--amber-soft);
  color: #8a4c05;
}

.chip.bad {
  border-color: rgba(180, 35, 24, 0.3);
  background: var(--red-soft);
  color: var(--red);
}

.hint {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--card-soft);
  border: 1px dashed var(--line-strong);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.hint code {
  background: rgba(15, 122, 90, 0.08);
}

/* ---------------- USB 识别 ---------------- */

.identify-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.25fr);
  gap: 16px;
  align-items: end;
  margin-bottom: 14px;
}

.vid-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.vid-row input {
  width: 96px;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--card-soft);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.vid-row input:focus {
  outline: none;
  border-color: rgba(15, 122, 90, 0.5);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.vid-sep {
  color: var(--muted);
  font-family: var(--mono);
}

.identify-auto {
  margin-top: 12px;
}

#identify-ports td .btn {
  padding: 4px 11px;
  font-size: 11.5px;
}

#identify-ports tbody tr:last-child td {
  border-bottom: 0;
}

.warn-text {
  color: #8a4c05;
  border-color: rgba(180, 101, 10, 0.3);
  background: var(--amber-soft);
}

/* ---------------- 键值列表 ---------------- */

.kv {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 18px;
  margin: 0;
}

.kv.kv-wide {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.kv > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--line);
}

.kv dt {
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.02em;
}

.kv dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  word-break: break-all;
}

/* ---------------- 统计卡片 ---------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: linear-gradient(170deg, var(--card), var(--card-soft));
  min-width: 0;
}

.stat-label {
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.02em;
}

.stat-value {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  word-break: break-all;
  line-height: 1.3;
}

.stat-value.accent {
  color: var(--accent-deep);
}

.stat-value.is-time {
  font-size: 12.5px;
  letter-spacing: -0.01em;
  word-break: normal;
  overflow-wrap: break-word;
}

.stat-value.bad {
  color: var(--red);
}

.stat-note {
  color: var(--muted);
  font-size: 11px;
}

.stat.is-empty .stat-value {
  color: #b9b1a0;
  font-size: 15px;
  font-weight: 400;
}

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

.table-wrap {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 12px;
  background: #f3eee2;
  border-bottom: 1px solid var(--line-strong);
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  text-align: left;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.table td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(226, 219, 203, 0.6);
  vertical-align: top;
  font-family: var(--mono);
}

.table tbody tr:nth-child(even) {
  background: rgba(243, 238, 226, 0.35);
}

.table tbody tr:hover {
  background: var(--accent-soft);
}

.table .num {
  text-align: right;
  white-space: nowrap;
}

.table.compact td,
.table.compact th {
  padding: 7px 10px;
}

.table.compact td:nth-child(2) {
  width: 60px;
  text-align: center;
}

/* ---------------- 表单 ---------------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > span {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
}

.field > span em {
  color: var(--muted);
  font-style: normal;
  font-weight: 400;
  font-size: 11px;
  white-space: nowrap;
}

.field input[type="number"],
.field input[type="text"],
.field select,
.inline-form input,
.manual-send input,
.table-toolbar input[type="search"] {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--card-soft);
  color: var(--ink);
  font-size: 13px;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.field input:focus,
.field select:focus,
.inline-form input:focus,
.manual-send input:focus,
.table-toolbar input:focus {
  outline: none;
  border-color: rgba(15, 122, 90, 0.5);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field input:disabled {
  opacity: 0.5;
}

.threshold-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.threshold-row input {
  flex: 1;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.check input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.inline-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.inline-form input {
  width: auto;
  flex: 1 1 220px;
  max-width: 320px;
  letter-spacing: 0.08em;
}

.sn-standalone-link {
  text-decoration: none;
  white-space: nowrap;
}

.field-inline-label {
  color: var(--muted);
  font-size: 12px;
}

.hint-inline {
  color: var(--muted);
  font-size: 11.5px;
}

/* ---------------- details / 原始数据 ---------------- */

.raw-details {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card-soft);
  overflow: hidden;
}

.raw-details > summary {
  padding: 9px 13px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.raw-details[open] > summary {
  border-bottom: 1px solid var(--line);
}

.raw-details pre {
  margin: 0;
  padding: 12px 13px;
  max-height: 240px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  color: var(--accent-deep);
  word-break: break-all;
  white-space: pre-wrap;
}

.section-title {
  margin: 18px 0 9px;
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.section-title:first-of-type {
  margin-top: 4px;
}

/* ---------------- 报警卡片 ---------------- */

.alarm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px;
}

.alarm-card {
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: linear-gradient(170deg, var(--card), var(--card-soft));
}

.alarm-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.alarm-card h3 {
  font-size: 13.5px;
}

.alarm-card .kv {
  grid-template-columns: 1fr;
  gap: 8px;
}

.alarm-card .kv > div {
  flex-direction: row;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: none;
  padding-bottom: 0;
}

.alarm-card .kv dt {
  font-size: 11.5px;
}

.alarm-card .kv dd {
  font-size: 12.5px;
  text-align: right;
}

/* ---------------- 记录页 ---------------- */

.progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.progress {
  position: relative;
  flex: 1;
  height: 7px;
  border-radius: 999px;
  background: var(--paper-deep);
  overflow: hidden;
}

.progress-bar {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #17a97b, #0a5540);
  transition: width 120ms linear;
}

.progress-text {
  min-width: 96px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  text-align: right;
}

.chart-wrap {
  position: relative;
  margin: 16px 0 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, #fffdf8, #f7f3e9);
}

#records-chart {
  display: block;
  width: 100%;
  height: 280px;
}

.empty-overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  color: var(--muted);
  font-size: 12.5px;
  background: rgba(250, 247, 239, 0.7);
  border-radius: var(--radius-sm);
}

.empty-overlay.is-visible {
  display: grid;
}

.chart-tip {
  position: absolute;
  top: 10px;
  display: none;
  min-width: 132px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 253, 248, 0.97);
  box-shadow: 0 8px 22px rgba(40, 33, 20, 0.14);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.55;
  pointer-events: none;
  z-index: 2;
}

.chart-tip strong {
  display: block;
  margin-bottom: 2px;
  font-family: var(--sans);
  font-size: 11.5px;
  color: var(--ink);
}

.chart-tip span {
  display: block;
  color: var(--muted);
}

.empty-cell {
  padding: 26px 12px !important;
  text-align: center;
  color: var(--muted);
  font-family: var(--sans) !important;
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 14px 0 10px;
}

.table-toolbar input[type="search"] {
  flex: 1 1 220px;
  max-width: 320px;
  padding: 7px 10px;
}

.pager {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.pager button {
  padding: 5px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font-size: 12px;
  cursor: pointer;
}

.pager button:hover:not(:disabled) {
  border-color: rgba(15, 122, 90, 0.4);
  color: var(--accent-deep);
}

.pager button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.status-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-family: var(--sans);
  white-space: nowrap;
}

.status-badge.ok {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.status-badge.bad {
  background: var(--red-soft);
  color: var(--red);
}

.status-badge.na {
  background: rgba(109, 122, 113, 0.12);
  color: var(--muted);
}

/* ---------------- 出厂测试 ---------------- */

.flow {
  display: grid;
  grid-template-columns: minmax(0, 320px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.flow-steps {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: flow;
}

.flow-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card-soft);
  transition: border-color 160ms ease, background 160ms ease;
}

.step-index {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--paper-deep);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.step-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.step-body strong {
  font-size: 12.5px;
  font-weight: 600;
}

.step-body small {
  color: var(--muted);
  font-size: 11px;
}

.step-state {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.flow-step[data-state="running"] {
  border-color: rgba(15, 122, 90, 0.4);
  background: var(--accent-soft);
}

.flow-step[data-state="running"] .step-index {
  background: var(--accent);
  color: #fff;
}

.flow-step[data-state="done"] .step-index {
  background: var(--accent);
  color: #fff;
}

.flow-step[data-state="done"] .step-state {
  color: var(--accent-deep);
}

.flow-step[data-state="error"] {
  border-color: rgba(180, 35, 24, 0.35);
  background: var(--red-soft);
}

.flow-step[data-state="error"] .step-index {
  background: var(--red);
  color: #fff;
}

.flow-step[data-state="error"] .step-state {
  color: var(--red);
}

.flow-log {
  min-height: 292px;
  max-height: 292px;
  overflow: auto;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #12241e;
  color: #d7e8df;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.75;
}

.flow-log .empty {
  color: rgba(215, 232, 223, 0.5);
  border: 0;
  padding: 0;
  background: none;
}

.flow-line {
  display: flex;
  gap: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

.flow-line .time {
  color: rgba(215, 232, 223, 0.45);
  flex: 0 0 auto;
}

.flow-line[data-level="ok"] .text {
  color: #7ee2b8;
}

.flow-line[data-level="error"] .text {
  color: #ff9b8f;
}

.flow-line[data-level="warn"] .text {
  color: #f3c37a;
}

.cmd-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
}

.cmd-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card-soft);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.cmd-btn:hover:not(:disabled) {
  border-color: rgba(15, 122, 90, 0.4);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.cmd-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.cmd-btn strong {
  font-size: 12.5px;
  font-weight: 600;
}

.cmd-btn small {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10.5px;
}

.cmd-btn.danger {
  border-color: rgba(180, 35, 24, 0.28);
}

.cmd-btn.danger:hover:not(:disabled) {
  border-color: rgba(180, 35, 24, 0.5);
  background: var(--red-soft);
}

/* ---------------- 日志 ---------------- */

.manual-send {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.manual-send input {
  flex: 1 1 320px;
  padding: 9px 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.log-list {
  max-height: 520px;
  overflow: auto;
  padding: 6px 0;
  border: 1px solid #0c1b16;
  border-radius: var(--radius-sm);
  background: #10201a;
  color: #d7e8df;
  font-family: var(--mono);
  font-size: 11.5px;
}

.log-list .empty {
  margin: 0;
  padding: 14px;
  color: rgba(215, 232, 223, 0.45);
}

.log-entry {
  padding: 6px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.log-entry:last-child {
  border-bottom: 0;
}

.log-entry:hover {
  background: rgba(255, 255, 255, 0.035);
}

.log-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.log-time {
  color: rgba(215, 232, 223, 0.42);
  flex: 0 0 auto;
}

.log-dir {
  display: inline-block;
  min-width: 34px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  text-align: center;
  letter-spacing: 0.06em;
}

.log-entry[data-dir="TX"] .log-dir {
  background: rgba(79, 168, 255, 0.18);
  color: #8fcdff;
}

.log-entry[data-dir="RX"] .log-dir {
  background: rgba(79, 209, 161, 0.18);
  color: #7ee2b8;
}

.log-entry[data-dir="SYS"] .log-dir {
  background: rgba(255, 255, 255, 0.09);
  color: rgba(215, 232, 223, 0.7);
}

.log-entry[data-level="warn"] .log-dir {
  background: rgba(243, 195, 122, 0.18);
  color: #f3c37a;
}

.log-entry[data-level="error"] .log-dir {
  background: rgba(255, 155, 143, 0.18);
  color: #ff9b8f;
}

.log-label {
  color: rgba(215, 232, 223, 0.9);
}

.log-summary {
  color: rgba(215, 232, 223, 0.55);
}

.log-size {
  margin-left: auto;
  color: rgba(215, 232, 223, 0.35);
  font-size: 10.5px;
}

.log-hex {
  margin: 3px 0 0;
  color: #9fd8c2;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 11px;
  line-height: 1.6;
}

.log-entry[data-level="error"] .log-hex {
  color: #ff9b8f;
}

/* ---------------- 提示与弹窗 ---------------- */

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, 90vw);
}

.toast {
  padding: 11px 15px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--card);
  box-shadow: var(--shadow-md);
  color: var(--ink);
  font-size: 12.5px;
  animation: toast-in 180ms ease;
}

.toast[data-level="error"] {
  border-left-color: var(--red);
}

.toast[data-level="warn"] {
  border-left-color: var(--amber);
}

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

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(18, 32, 26, 0.45);
  backdrop-filter: blur(2px);
}

.modal[hidden] {
  display: none;
}

.modal-panel {
  width: min(430px, 100%);
  padding: 22px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 30px 70px rgba(15, 32, 26, 0.35);
}

.modal-panel h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

.modal-panel p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.empty {
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: var(--card-soft);
  font-size: 12.5px;
}

/* ---------------- 响应式 ---------------- */

@media (max-width: 1180px) {
  .app {
    grid-template-columns: 212px minmax(0, 1fr);
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .identify-form {
    grid-template-columns: minmax(0, 1fr);
  }

  .kv.kv-wide {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    overflow-x: auto;
  }

  .brand {
    padding: 0;
  }

  .nav {
    flex-direction: row;
    gap: 4px;
  }

  .nav-item {
    white-space: nowrap;
    padding: 8px 11px;
  }

  .nav-dot,
  .sidebar-foot {
    display: none;
  }

  .main {
    padding: 16px 14px 32px;
  }

  .grid-2,
  .flow {
    grid-template-columns: 1fr;
  }

  .flow-log {
    max-height: 220px;
  }

  .topbar {
    flex-direction: column;
    gap: 10px;
  }

  .topbar-right {
    width: 100%;
    justify-content: space-between;
    padding-top: 0;
  }
}

@media (max-width: 680px) {
  .form-grid,
  .kv,
  .kv.kv-wide {
    grid-template-columns: 1fr;
  }

  .port-select {
    min-width: 0;
    width: 100%;
  }

  .connect-left,
  .connect-right {
    width: 100%;
  }

  .connect-right {
    justify-content: flex-end;
  }

  .card-head {
    flex-direction: column;
  }
}
