:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #e6ebf2;
  --text: #0f172a;
  --muted: #64748b;
  --blue: #2563eb;
  --blue-soft: #eaf2ff;
  --green: #16a34a;
  --yellow: #d97706;
  --red: #dc2626;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  height: 36px;
  border: 1px solid #d7deea;
  border-radius: 6px;
  padding: 0 16px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

button.danger {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input,
select {
  height: 34px;
  border: 1px solid #d7deea;
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
}

.page-shell {
  width: min(1200px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 32px;
}

.hero,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 28px 30px;
  margin-bottom: 10px;
}

.hero h1,
.hero p,
.panel-title,
.block-head h3 {
  margin: 0;
}

.hero h1 {
  font-size: 22px;
  line-height: 1.35;
}

.hero p {
  margin-top: 8px;
  color: var(--muted);
}

.hero-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  min-width: 220px;
}

.status-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  color: var(--muted);
  white-space: nowrap;
}

.status-chip.ok {
  border-color: #bfe7cb;
  color: var(--green);
}

.status-chip.bad {
  border-color: #f7c0c0;
  color: var(--red);
}

.connection-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 7px 14px;
  background: #f8fafc;
  color: var(--muted);
}

.connection-state.is-connected {
  background: #ecfdf3;
  color: var(--green);
}

.connection-state.is-connecting {
  background: #fff8e6;
  color: var(--yellow);
}

.connection-state.is-idle {
  background: #f1f5f9;
  color: var(--muted);
}

.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.guide-card {
  padding: 0;
  margin-bottom: 10px;
}

.guide summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 62px;
  padding: 0 30px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.guide summary::-webkit-details-marker {
  display: none;
}

.guide summary::after {
  content: "收起";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  height: 30px;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

.guide[open] summary::after {
  content: "收起";
}

.guide:not([open]) summary::after {
  content: "展开";
}

.guide-body {
  display: grid;
  gap: 26px;
  padding: 10px 30px 30px;
  border-top: 1px solid var(--line);
}

.guide-step h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.guide-step p {
  margin: 0;
}

.guide-note {
  margin-top: 3px !important;
  color: #98a2b3;
  font-size: 13px;
}

.guide-note::before {
  content: "i";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  margin-right: 4px;
  border: 1px solid #a7b0bd;
  border-radius: 50%;
  color: #8d96a3;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.connect-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 30px;
  margin-bottom: 10px;
}

.connect-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 12px;
  color: var(--muted);
}

.device-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: #fff;
}

.field-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.hint-inline {
  color: var(--muted);
}

.connect-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.tabs {
  display: flex;
  gap: 24px;
  padding: 0 30px;
  border-bottom: 1px solid var(--line);
}

.tab {
  height: 52px;
  border: 0;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
}

.tab.active {
  color: var(--blue);
  border-bottom: 2px solid var(--blue);
}

.tab-page {
  display: none;
  padding: 18px 30px 30px;
}

.tab-page.active {
  display: block;
}

button[data-tab="log"],
#logTab {
  display: none !important;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

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

.summary-panel,
.sub-panel,
.card-block {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.summary-panel {
  padding: 18px 18px 14px;
}

.panel-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 14px;
}

.summary-list {
  display: grid;
  grid-template-columns: 136px minmax(0, 1fr);
  row-gap: 14px;
  column-gap: 16px;
  margin: 0;
}

.summary-list dt {
  color: var(--muted);
}

.summary-list dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.card-block {
  margin-top: 16px;
  padding: 18px;
}

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

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

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.9fr);
  gap: 16px;
}

.sub-panel {
  padding: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.form-row-tight {
  margin-top: 12px;
  margin-bottom: 0;
}

.battery-inputs {
  display: grid;
  gap: 10px;
}

.button-stack {
  display: grid;
  gap: 10px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.data-table th,
.data-table td {
  padding: 14px 18px;
  border-bottom: 1px solid #edf1f7;
  text-align: left;
}

.data-table th {
  font-weight: 700;
}

.empty-row {
  text-align: center !important;
  color: var(--muted);
  height: 160px;
}

.reading-mask {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(248, 250, 252, 0.86);
  backdrop-filter: blur(2px);
  cursor: wait;
}

.reading-mask[hidden] {
  display: none;
}

.reading-mask-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: min(320px, calc(100vw - 48px));
  padding: 28px 34px;
  border: 1px solid #dbe5f0;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 12px 36px rgba(15, 23, 42, 0.16);
  text-align: center;
}

.reading-mask-card > span:last-child {
  color: var(--muted);
  font-size: 13px;
}

.loading-spinner {
  width: 30px;
  height: 30px;
  border: 3px solid #dbeafe;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: reading-mask-spin 0.8s linear infinite;
}

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

.log-box {
  min-height: 320px;
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #0f172a;
  color: #dbeafe;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.6;
  white-space: pre-wrap;
}

.log-info { color: #cbd5e1; }
.log-ok { color: #86efac; }
.log-error { color: #fca5a5; }
.log-tx { color: #93c5fd; }
.log-rx { color: #fde68a; }

.toast-host {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1000;
  display: grid;
  gap: 10px;
  pointer-events: none;
}

.toast {
  min-width: 160px;
  max-width: min(320px, calc(100vw - 40px));
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.96);
  color: #fff;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
}

.toast-ok {
  background: rgba(22, 163, 74, 0.96);
}

.toast-info {
  background: rgba(37, 99, 235, 0.96);
}

.toast-error {
  background: rgba(220, 38, 38, 0.96);
}

@media (max-width: 900px) {
  .page-shell {
    width: calc(100vw - 16px);
    padding-top: 8px;
  }

  .hero,
  .connect-card {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-status {
    align-items: flex-start;
    min-width: 0;
  }

  .summary-grid,
  .detail-layout {
    grid-template-columns: 1fr;
  }
}
