:root {
  color-scheme: light;
  --bg: #eef3f6;
  --panel: #ffffff;
  --panel-strong: #f6f9fb;
  --line: #e1e9ee;
  --text: #16232d;
  --muted: #71808c;
  --green: #07c160;
  --green-soft: #e8f8ef;
  --blue: #2f80ed;
  --blue-soft: #eaf2ff;
  --orange: #d46b08;
  --orange-soft: #fff4df;
  --red: #fa5151;
  --red-soft: #fff2f2;
  --shadow: 0 8px 24px rgba(21, 42, 56, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

body {
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

img {
  display: block;
}

.app-shell {
  width: min(100%, 430px);
  min-height: 100svh;
  background: #f7fafc;
  box-shadow: 0 0 0 1px rgba(219, 228, 235, 0.8), 0 24px 60px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
}

.mobile-header {
  padding: 16px 14px 12px;
  background: linear-gradient(180deg, rgba(7, 193, 96, 0.085) 0%, rgba(7, 193, 96, 0) 100%);
}

.brand-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.brand-icon {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.8);
  padding: 5px;
  box-shadow: inset 0 0 0 1px rgba(219, 228, 235, 0.85);
}

.brand-copy,
.hero-copy,
.profile-copy {
  min-width: 0;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-copy h1,
.panel h3,
.panel h4 {
  margin: 0;
  letter-spacing: 0;
}

.brand-copy h1 {
  font-size: 18px;
  line-height: 1.18;
}

.brand-copy p,
.panel p {
  margin: 0;
}

.brand-copy p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.header-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.workspace {
  flex: 1;
  display: grid;
  gap: 12px;
  padding: 0 12px calc(88px + env(safe-area-inset-bottom));
  min-width: 0;
}

.page {
  display: none;
  gap: 12px;
}

.page.active {
  display: grid;
}

.panel {
  padding: 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.hero {
  padding: 15px 13px 12px;
  background: linear-gradient(135deg, #effcf5 0%, #ffffff 72%);
  border-color: #d7eee2;
}

.hero-main,
.panel-head,
.summary-strip,
.contact-panel,
.profile-hero,
.panel-head-left {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.hero-main,
.panel-head,
.summary-strip,
.contact-panel,
.profile-hero {
  flex-direction: column;
}

.hero-main {
  flex-direction: row;
  align-items: center;
}

.hero-icon-wrap,
.panel-icon-wrap,
.profile-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 16px;
}

.hero-icon-wrap {
  width: 54px;
  height: 54px;
  background: #f0fff8;
}

.panel-icon-wrap {
  width: 48px;
  height: 48px;
  background: #f2f6fb;
}

.panel-icon-wrap.green {
  background: #f0fff8;
}

.panel-icon-wrap.blue {
  background: #f3f7ff;
}

.panel-icon {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.hero-icon {
  width: 35px;
  height: 35px;
  object-fit: contain;
}

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

.hero h3,
.profile-hero h3 {
  font-size: 18px;
  line-height: 1.18;
}

.hero p,
.summary-strip p,
.panel-head p,
.contact-panel p,
.profile-hero p,
.notice-panel p,
.field span,
.metric-label,
.sidebar-note {
  color: var(--muted);
}

.hero p,
.summary-strip p,
.panel-head p,
.contact-panel p,
.profile-hero p,
.notice-panel p {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.55;
}

.summary-strip,
.contact-panel,
.profile-hero {
  align-items: flex-start;
}

.summary-strip,
.contact-panel {
  flex-direction: row;
  align-items: center;
}

.summary-strip > div,
.contact-panel .panel-head-left {
  min-width: 0;
}

.summary-strip strong,
.profile-copy h3,
.contact-panel h4,
.panel-head h4,
.notice-panel h4 {
  font-size: 16px;
}

.mini-badge,
.status-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}

.mini-badge.green,
.status-chip.ok {
  background: var(--green-soft);
  color: var(--green);
}

.mini-badge.blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.mini-badge.orange,
.mini-badge.warn,
.status-chip.warn {
  background: var(--orange-soft);
  color: var(--orange);
}

.status-chip {
  background: #eef2f6;
  color: #475467;
}

.flow-progress {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  margin-top: 14px;
  padding: 11px 3px 0;
  border-top: 1px solid rgba(7, 193, 96, 0.14);
}

.flow-step {
  display: grid;
  flex: 1 1 0;
  min-width: 0;
  justify-items: center;
  gap: 5px;
  color: #9aa7b0;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.flow-dot {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 1px solid #dbe5ea;
  border-radius: 50%;
  background: #f5f8fa;
  color: #9aa7b0;
  font-size: 10px;
  font-weight: 800;
}

.flow-line {
  flex: 0 0 14px;
  height: 1px;
  margin-top: 10px;
  background: #dce6eb;
}

.flow-step.done,
.flow-step.active {
  color: var(--green);
}

.flow-step.done .flow-dot {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.flow-step.active .flow-dot {
  border: 2px solid var(--green);
  background: #fff;
  color: var(--green);
  box-shadow: 0 0 0 4px rgba(7, 193, 96, 0.12);
}

.flow-step.done + .flow-line {
  background: rgba(7, 193, 96, 0.45);
}

.content-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.content-grid > .stats-panel {
  order: 1;
}

.content-grid > .live-panel {
  order: 2;
}

.content-grid > .warning-panel {
  order: 3;
}

.content-grid > .control-panel {
  order: 4;
}

.content-grid > .ble-panel {
  order: 5;
}

.content-grid > .contact-panel {
  order: 6;
}

.content-grid > .log-strip {
  order: 7;
}

.ble-panel,
.live-panel,
.stats-panel,
.control-panel,
.contact-panel,
.warning-panel,
.form-panel,
.notice-panel,
.log-strip {
  min-width: 0;
}

.ble-panel,
.live-panel,
.control-panel,
.contact-panel,
.form-panel,
.notice-panel,
.log-strip {
  display: grid;
  gap: 14px;
}

.panel-head-left {
  width: 100%;
}

.panel-head.simple {
  gap: 0;
}

.port-selector {
  display: grid;
  gap: 7px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdfc;
}

.port-selector span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.port-selector select {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.panel-head button,
.panel-head .primary-btn {
  width: 100%;
}

.log-strip .panel-head {
  flex-direction: row;
  align-items: center;
}

.log-strip .panel-head button {
  width: auto;
  min-height: 38px;
}

.control-panel .panel-head {
  flex-direction: row;
  align-items: flex-start;
}

.control-panel .panel-head-left {
  flex: 1;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.stat-card {
  min-height: 96px;
  padding: 11px 10px;
  border-radius: 14px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.stat-card.primary {
  background: #0a9d60;
  border-color: #0a9d60;
  color: #fff;
  box-shadow: 0 8px 18px rgba(7, 193, 96, 0.18);
}

.stat-card.primary .metric-label {
  color: rgba(255, 255, 255, 0.78);
}

.stat-card.primary .metric-value {
  color: #fff;
}

.metric-head {
  display: flex;
  align-items: center;
  gap: 5px;
}

.metric-label {
  min-width: 0;
  font-size: 10px;
  white-space: nowrap;
}

.metric-value {
  margin-top: 12px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.15;
  white-space: nowrap;
}

.ok-text {
  color: var(--green);
}

.danger-text {
  color: var(--red);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #b5c0cc;
  flex: 0 0 auto;
}

.dot.ok {
  background: var(--green);
}

.dot.danger {
  background: var(--red);
}

.device-list {
  display: grid;
  gap: 10px;
}

.device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 11px;
  border-radius: 14px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  color: var(--text);
  text-align: left;
}

.device-item.active {
  background: #effcf5;
  border-color: #b8edd2;
  box-shadow: inset 0 0 0 1px rgba(7, 193, 96, 0.09);
}

.device-main {
  min-width: 0;
}

.device-title {
  display: flex;
  align-items: center;
  gap: 7px;
}

.device-led {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #b7c4cc;
}

.device-item.active .device-led {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(7, 193, 96, 0.13);
}

.device-side {
  display: grid;
  flex: 0 0 auto;
  justify-items: end;
  gap: 5px;
}

.device-item strong,
.device-item p {
  margin: 0;
}

.device-item p {
  margin-top: 4px;
  font-size: 12px;
  word-break: break-all;
}

.device-rssi {
  flex: 0 0 auto;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
}

.device-action {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.device-item.active .device-action {
  color: var(--green);
}

.connected-box,
.empty-state,
.live-wrap,
.summary-strip,
.warning-panel {
  padding: 14px;
  border-radius: 16px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.connected-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.connected-box > div {
  min-width: 0;
}

.connected-box p {
  margin-top: 4px;
  font-size: 11px;
  word-break: break-all;
}

.hidden {
  display: none !important;
}

.empty-state {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  line-height: 1.5;
}

.live-wrap {
  min-height: 210px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #111827;
  padding: 0;
  border: 0;
}

.mock-live {
  padding: 0;
}

.mock-live-shell {
  position: relative;
  width: 100%;
  min-height: 210px;
  overflow: hidden;
  border-radius: 14px;
}

.mock-live-canvas {
  display: block;
  width: 100%;
  height: 210px;
}

.mock-live-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px;
  color: #fff;
  pointer-events: none;
}

.mock-live-top,
.mock-live-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mock-live-stage {
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 10px;
  font-weight: 800;
  backdrop-filter: blur(6px);
}

.mock-live-info {
  flex: 1;
  font-size: 12px;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.82);
}

.mock-live-weight {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(7, 193, 96, 0.9);
  font-size: 12px;
  font-weight: 800;
}

.live-wrap.placeholder {
  color: #fff;
}

.live-wrap video,
.live-wrap iframe {
  width: 100%;
  height: 100%;
  min-height: 210px;
  border: 0;
  object-fit: cover;
}

.placeholder-title,
.warning-title {
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  text-align: center;
}

.placeholder-text {
  max-width: 320px;
  margin-top: 10px;
  color: rgba(255, 255, 255, 0.72);
  text-align: center;
  line-height: 1.55;
  font-size: 12px;
}

.warning-panel {
  background: var(--red-soft);
  border-color: #ffd8d8;
}

.warning-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.warning-head img {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
}

.warning-title {
  color: var(--red);
}

.warning-text {
  margin-top: 8px;
  color: #b42318;
  font-size: 12px;
  line-height: 1.58;
}

.control-grid,
.hold-grid {
  display: grid;
  gap: 10px;
}

.control-grid {
  grid-template-columns: 1.15fr 1fr 1fr;
}

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

.control-btn,
.hold-btn,
.ghost-btn,
.primary-btn,
.outline-btn,
.danger-btn {
  min-height: 44px;
  border-radius: 14px;
  padding: 0 14px;
  font-weight: 800;
  letter-spacing: 0;
}

button:not(:disabled):active {
  transform: translateY(1px) scale(0.99);
}

.primary-btn {
  background: var(--green);
  color: #fff;
}

.primary-btn.small {
  min-height: 40px;
  padding: 0 12px;
  font-size: 13px;
}

.ghost-btn {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}

.compact {
  min-height: 40px;
}

.outline-btn {
  background: #fff;
  color: var(--red);
  border: 1px solid #f7b4b4;
}

.danger-btn {
  background: #fff;
  color: var(--red);
  border: 1px solid #f7b4b4;
}

.control-btn {
  color: #fff;
  display: grid;
  min-height: 76px;
  align-content: center;
  justify-items: center;
  gap: 3px;
  padding: 8px 6px;
  border-radius: 14px;
  box-shadow: 0 7px 14px rgba(15, 23, 42, 0.08);
}

.control-btn-icon {
  font-size: 18px;
  line-height: 1;
}

.control-btn-label {
  font-size: 14px;
  line-height: 1.1;
  white-space: nowrap;
}

.control-btn-meta {
  font-size: 10px;
  font-weight: 600;
  line-height: 1.1;
  opacity: 0.78;
  white-space: nowrap;
}

.control-btn.start {
  background: var(--green);
}

.control-btn.stop {
  background: #f59e0b;
}

.control-btn.estop {
  background: var(--red);
}

.hold-btn {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

button:disabled {
  cursor: not-allowed;
  background: #eef2f6 !important;
  color: #98a2b3 !important;
  border-color: #e4e7ec !important;
}

.block-btn {
  width: 100%;
}

.control-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  flex: 0 0 auto;
}

.control-tools .ghost-btn {
  width: auto;
  min-height: 36px;
  padding: 0 10px;
  font-size: 11px;
}

.advanced-control {
  border-top: 1px solid var(--line);
}

.advanced-control summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 12px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  list-style: none;
}

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

.advanced-summary-main {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.advanced-summary-icon {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 8px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 15px;
}

.advanced-summary-hint {
  margin-left: auto;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.advanced-control[open] .advanced-summary-icon {
  background: var(--green-soft);
  color: var(--green);
}

.advanced-control .hold-grid {
  margin-top: 10px;
}

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

.field:last-child {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 16px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.field span {
  font-size: 12px;
  font-weight: 700;
}

.field input {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
}

.profile-hero {
  flex-direction: row;
  align-items: center;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  background: #f0fff8;
}

.profile-avatar img {
  width: 50px;
  height: 50px;
  object-fit: contain;
}

.profile-copy {
  flex: 1;
}

.log-list {
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
}

.log-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.45;
}

.log-item span:last-child {
  color: var(--muted);
  white-space: nowrap;
}

.bottom-nav {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 7px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(248, 251, 253, 0.96);
  border-top: 1px solid rgba(219, 228, 235, 0.95);
  backdrop-filter: blur(12px);
}

.nav-item {
  display: grid;
  justify-items: center;
  gap: 4px;
  min-height: 54px;
  padding: 6px 0 5px;
  border-radius: 16px;
  color: var(--muted);
  background: transparent;
  text-align: center;
}

.nav-item img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.nav-item.active {
  background: var(--green-soft);
  color: var(--green);
  box-shadow: inset 0 0 0 1px rgba(7, 193, 96, 0.12);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  z-index: 30;
  transform: translateX(-50%) translateY(24px);
  min-width: 220px;
  max-width: calc(100vw - 24px);
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(17, 24, 39, 0.92);
  color: #fff;
  text-align: center;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 720px) {
  .app-shell {
    margin: 16px 0;
    min-height: calc(100svh - 32px);
    border-radius: 24px;
    overflow: hidden;
  }
}
