:root {
  --forest-950: #073c22;
  --forest-900: #0b4b2b;
  --forest-800: #0d6135;
  --forest-700: #118142;
  --forest-600: #15964c;
  --mint-100: #eaf7ef;
  --mint-50: #f4fbf6;
  --red-700: #c83e32;
  --red-100: #ffebe8;
  --amber-700: #a35c00;
  --amber-100: #fff3d7;
  --slate-950: #14221a;
  --slate-800: #26372d;
  --slate-600: #617168;
  --slate-500: #7d8a82;
  --slate-300: #cbd5ce;
  --slate-200: #dfe6e1;
  --slate-100: #edf2ee;
  --slate-50: #f7f9f7;
  --white: #fff;
  --shadow-sm: 0 1px 2px rgba(12, 54, 31, .04), 0 4px 14px rgba(12, 54, 31, .05);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  min-width: 320px;
  background: #f3f7f4;
  color: var(--slate-950);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(circle at 4% 0%, rgba(27, 151, 78, .08), transparent 25rem), #f4f7f5;
  color: var(--slate-950);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; opacity: .5; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(21, 150, 76, .24); outline-offset: 2px; }

.topbar {
  display: flex;
  min-height: 126px;
  align-items: center;
  justify-content: space-between;
  padding: 24px clamp(24px, 4vw, 64px);
  border-bottom: 1px solid rgba(13, 97, 53, .1);
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(18px);
}

.eyebrow { margin: 0 0 5px; color: var(--forest-700); font-size: 12px; font-weight: 750; letter-spacing: .08em; }
.topbar h1 { margin: 0; color: var(--forest-950); font-size: clamp(27px, 2.3vw, 36px); letter-spacing: -.035em; }
.subtitle { margin: 7px 0 0; color: var(--slate-600); font-size: 14px; }

.headerActions { display: flex; align-items: center; gap: 14px; }
.brokerState { display: flex; min-width: 176px; align-items: center; gap: 11px; padding-right: 20px; border-right: 1px solid var(--slate-200); }
.brokerState strong, .brokerState small { display: block; }
.brokerState strong { color: var(--forest-900); font-size: 14px; }
.brokerState small { margin-top: 3px; color: var(--slate-500); font-size: 11px; }
.brokerDot { width: 11px; height: 11px; flex: none; border-radius: 50%; background: var(--forest-600); box-shadow: 0 0 0 5px rgba(21, 150, 76, .1); }
.broker-connecting .brokerDot { background: #e29b19; box-shadow: 0 0 0 5px rgba(226, 155, 25, .12); animation: pulse 1.4s ease-in-out infinite; }
.broker-disconnected .brokerDot, .broker-error .brokerDot { background: #d95747; box-shadow: 0 0 0 5px rgba(217, 87, 71, .12); }

.primaryButton, .quickButton, .queryButton, .stopButton, .mobileQuickButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 11px;
  font-weight: 720;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

.primaryButton { min-height: 48px; padding: 0 21px; border: 0; background: linear-gradient(135deg, var(--forest-700), var(--forest-900)); color: var(--white); box-shadow: 0 8px 20px rgba(13, 97, 53, .2); }
.quickButton { min-height: 48px; padding: 0 18px; border: 1px solid var(--forest-700); background: var(--white); color: var(--forest-800); }
.primaryButton:not(:disabled):hover, .quickButton:not(:disabled):hover, .queryButton:not(:disabled):hover { transform: translateY(-1px); }

.content { width: min(1500px, calc(100% - 48px)); margin: 0 auto; padding: 28px 0 48px; }
.statsGrid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; }
.statCard { min-height: 100px; padding: 20px; border: 1px solid rgba(20, 34, 26, .08); border-radius: 16px; background: rgba(255, 255, 255, .92); box-shadow: var(--shadow-sm); }
.statCard p { margin: 0 0 5px; color: var(--slate-600); font-size: 13px; font-weight: 650; }
.statCard strong { color: var(--forest-950); font-size: 30px; font-variant-numeric: tabular-nums; line-height: 1; }
.statOnline { border-color: rgba(21, 150, 76, .18); }
.statOffline { border-color: rgba(200, 62, 50, .16); }
.statQuerying { border-color: rgba(163, 92, 0, .16); }

.progressPanel { display: grid; grid-template-columns: auto minmax(180px, 1fr) auto auto; align-items: center; gap: 20px; margin-top: 18px; padding: 17px 20px; border: 1px solid rgba(21, 150, 76, .22); border-radius: 14px; background: rgba(248, 253, 249, .96); }
.progressSummary { display: flex; align-items: baseline; gap: 12px; white-space: nowrap; }
.progressSummary strong { font-size: 14px; }
.progressSummary span, .progressPercent { color: var(--forest-700); font-weight: 760; font-variant-numeric: tabular-nums; }
.progressTrack { height: 10px; overflow: hidden; border-radius: 999px; background: #e6ece7; }
.progressTrack span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--forest-600), #43b96d); transition: width 200ms ease; }
.stopButton { min-height: 38px; padding: 0 14px; border: 1px solid rgba(13, 97, 53, .55); background: var(--white); color: var(--forest-800); }

.notice { margin-top: 16px; padding: 12px 14px; border: 1px solid #f0d392; border-radius: 11px; background: #fff9eb; color: #784a00; font-size: 13px; }
.notice.error { border-color: #efb0aa; background: #fff4f2; color: #8b2c24; }

.devicePanel { overflow: hidden; margin-top: 18px; border: 1px solid rgba(20, 34, 26, .09); border-radius: 17px; background: var(--white); box-shadow: var(--shadow-sm); }
.toolbar { display: grid; grid-template-columns: minmax(250px, 330px) minmax(520px, 1fr); align-items: center; gap: 14px; padding: 16px 18px; border-bottom: 1px solid var(--slate-100); }
.searchField { display: flex; min-height: 43px; align-items: center; gap: 9px; padding: 0 13px; border: 1px solid var(--slate-300); border-radius: 10px; color: var(--slate-500); background: var(--white); }
.searchField:focus-within { border-color: var(--forest-600); box-shadow: 0 0 0 3px rgba(21, 150, 76, .1); }
.searchField input { width: 100%; min-width: 0; border: 0; outline: 0; color: var(--slate-950); background: transparent; font-size: 13px; }
.filterScroller { display: flex; align-items: center; gap: 7px; overflow-x: auto; scrollbar-width: none; }
.filterScroller::-webkit-scrollbar { display: none; }
.filterScroller button { min-height: 40px; flex: none; padding: 0 13px; border: 1px solid var(--slate-200); border-radius: 9px; background: var(--white); color: var(--slate-600); cursor: pointer; font-size: 12px; font-weight: 650; }
.filterScroller button span { margin-left: 2px; color: var(--slate-500); font-variant-numeric: tabular-nums; }
.filterScroller button.active { border-color: var(--forest-700); background: var(--forest-700); color: var(--white); box-shadow: 0 6px 14px rgba(17, 129, 66, .16); }
.filterScroller button.active span { color: rgba(255, 255, 255, .8); }
.resultMeta { display: flex; justify-content: space-between; gap: 16px; padding: 10px 18px; color: var(--slate-500); background: var(--slate-50); font-size: 11px; }
.protocolHint { color: var(--forest-700); }

.desktopTableWrap { overflow-x: auto; }
.deviceTable { width: 100%; min-width: 1080px; border-collapse: collapse; }
.deviceTable th, .deviceTable td { padding: 12px; border-bottom: 1px solid var(--slate-100); text-align: left; vertical-align: middle; white-space: nowrap; }
.deviceTable th { color: var(--slate-600); background: #fbfcfb; font-size: 11px; letter-spacing: .02em; }
.deviceTable td { color: var(--slate-800); font-size: 12px; }
.deviceTable tbody tr:hover { background: #fbfefc; }
.ssid { color: var(--slate-950); font-size: 13px; }
.deviceId { color: var(--slate-600); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; }
.actionColumn, .deviceTable td:last-child { width: 96px; text-align: center; }

.statusBadge, .updateBadge { display: inline-flex; min-height: 28px; align-items: center; justify-content: center; gap: 6px; padding: 0 10px; border-radius: 999px; font-size: 11px; font-weight: 720; }
.statusDot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: currentColor; }
.statusBadge small { color: currentColor; font-size: 9px; opacity: .7; }
.status-online { background: var(--mint-100); color: var(--forest-700); }
.status-offline { background: var(--red-100); color: var(--red-700); }
.status-querying { background: var(--amber-100); color: var(--amber-700); }
.status-idle { background: var(--slate-100); color: var(--slate-600); }
.status-error { background: #fff0ea; color: #a94526; }
.updateBadge { border-radius: 7px; }
.updateBadge.updated { border: 1px solid #6ab984; background: #f7fcf8; color: var(--forest-700); }
.updateBadge.pending { background: var(--slate-100); color: var(--slate-600); }
.updateNote { display: block; max-width: 150px; overflow: hidden; margin-top: 3px; color: var(--slate-500); font-size: 9px; text-overflow: ellipsis; }
.queryButton { min-width: 78px; min-height: 36px; padding: 0 12px; border: 1px solid var(--forest-700); background: var(--white); color: var(--forest-800); font-size: 12px; }

.panelFooter { display: flex; min-height: 70px; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 18px; }
.infoNote { max-width: 670px; padding: 9px 12px; border-radius: 9px; background: var(--mint-50); color: var(--slate-600); font-size: 11px; }
.pagination { display: flex; align-items: center; gap: 8px; color: var(--slate-600); font-size: 11px; white-space: nowrap; }
.pagination button { display: grid; width: 34px; height: 34px; place-items: center; border: 1px solid var(--slate-200); border-radius: 8px; background: var(--white); color: var(--forest-800); cursor: pointer; font-size: 22px; }
.pagination > strong { display: grid; min-width: 34px; height: 34px; place-items: center; border-radius: 8px; background: var(--forest-700); color: var(--white); }
.emptyState { display: flex; min-height: 220px; align-items: center; justify-content: center; flex-direction: column; gap: 8px; color: var(--slate-500); }
.emptyState strong { color: var(--slate-800); }
.emptyState span { font-size: 12px; }

.mobileCards, .mobileActionBar { display: none; }

.quickOverlay { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(5, 29, 16, .54); backdrop-filter: blur(8px); }
.quickDialog { width: min(410px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 22px; border-radius: 22px; background: var(--white); box-shadow: 0 26px 80px rgba(3, 28, 15, .32); }
.quickDialogHeader { display: flex; align-items: center; justify-content: space-between; }
.quickDialogHeader p, .quickDialogHeader h2 { margin: 0; }
.quickDialogHeader p { color: var(--forest-700); font-size: 9px; font-weight: 800; letter-spacing: .14em; }
.quickDialogHeader h2 { margin-top: 3px; color: var(--forest-950); font-size: 22px; }
.quickClose { display: grid; width: 38px; height: 38px; padding: 0; place-items: center; border: 0; border-radius: 50%; background: var(--slate-100); color: var(--slate-600); cursor: pointer; font-size: 26px; }
.quickCode { display: grid; grid-template-columns: auto repeat(4, 1fr); align-items: center; gap: 8px; margin-top: 18px; }
.quickCode span { color: var(--forest-900); font-size: 25px; font-weight: 820; }
.quickCode strong { display: grid; height: 52px; place-items: center; border: 1px solid var(--slate-200); border-radius: 11px; background: var(--slate-50); color: var(--slate-300); font-size: 25px; font-variant-numeric: tabular-nums; }
.quickCode strong.filled { border-color: rgba(17, 129, 66, .35); background: var(--mint-50); color: var(--forest-900); }
.quickMessage, .quickResult { margin-top: 13px; border-radius: 12px; }
.quickMessage { padding: 11px 12px; background: var(--red-100); color: var(--red-700); font-size: 12px; }
.quickResult { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 7px 12px; padding: 12px; border: 1px solid var(--slate-200); background: var(--slate-50); }
.quickResult.online { border-color: rgba(21, 150, 76, .28); background: var(--mint-50); }
.quickResult.offline, .quickResult.error { border-color: rgba(200, 62, 50, .24); background: #fff9f8; }
.quickResultIdentity strong, .quickResultIdentity span { display: block; }
.quickResultIdentity strong { font-size: 17px; }
.quickResultIdentity span { margin-top: 2px; overflow: hidden; color: var(--slate-500); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; text-overflow: ellipsis; }
.quickResult p { grid-column: 1 / -1; margin: 0; color: var(--slate-600); font-size: 11px; }
.quickKeypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 16px; }
.quickKeypad button { display: flex; min-height: 55px; align-items: center; justify-content: center; gap: 5px; padding: 0; border: 1px solid var(--slate-200); border-radius: 12px; background: var(--white); color: var(--slate-950); font-size: 21px; font-weight: 720; cursor: pointer; }
.quickKeypad button:not(:disabled):hover { border-color: var(--forest-600); background: var(--mint-50); }
.quickKeypad button small { font-size: 10px; }
.quickKeypad .quickBackspace { color: var(--slate-600); }
.quickKeypad .quickConfirm { border-color: var(--forest-800); background: var(--forest-800); color: var(--white); }

.srOnly { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }
.spin { animation: spin 900ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .45; } }

@media (max-width: 1180px) {
  .statsGrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .toolbar { grid-template-columns: minmax(250px, .8fr) minmax(450px, 1.2fr); }
}

@media (max-width: 760px) {
  body { padding-bottom: 70px; }
  .topbar { min-height: auto; padding: 10px 12px; }
  .topbar h1 { font-size: 20px; }
  .subtitle, .eyebrow, .desktopAction, .brokerState small { display: none; }
  .headerActions { gap: 0; }
  .brokerState { width: auto; min-width: 0; padding: 0; border: 0; }
  .brokerState strong { font-size: 11px; }
  .content { width: calc(100% - 16px); padding: 8px 0 18px; }
  .statsGrid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
  .statCard { min-width: 0; min-height: 52px; padding: 6px 4px; border-radius: 9px; text-align: center; }
  .statCard p { overflow: hidden; margin-bottom: 2px; font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
  .statCard strong { font-size: 18px; }
  .progressPanel { grid-template-columns: 1fr auto; gap: 10px 12px; padding: 12px; }
  .progressTrack { grid-column: 1 / -1; grid-row: 2; }
  .progressPercent { grid-column: 2; grid-row: 1; }
  .stopButton { grid-column: 1 / -1; min-height: 38px; }
  .devicePanel { overflow: visible; margin-top: 8px; border: 0; background: transparent; box-shadow: none; }
  .toolbar { display: block; padding: 0; border: 0; }
  .searchField { min-height: 38px; border-radius: 9px; }
  .filterScroller { gap: 6px; margin: 7px -8px 0; padding: 0 8px 2px; }
  .filterScroller button { min-height: 32px; padding: 0 11px; border-radius: 8px; font-size: 10px; }
  .desktopTableWrap, .resultMeta { display: none; }
  .mobileCards { display: grid; gap: 5px; margin-top: 8px; }
  .deviceCard { display: grid; grid-template-columns: minmax(92px, 1fr) auto 61px; min-height: 60px; align-items: center; gap: 7px; padding: 6px 8px; border: 1px solid var(--slate-200); border-radius: 10px; background: var(--white); box-shadow: 0 1px 5px rgba(12, 54, 31, .04); }
  .deviceIdentity strong, .deviceIdentity span { display: block; }
  .deviceIdentity strong { font-size: 15px; letter-spacing: -.02em; }
  .deviceIdentity span { max-width: 120px; overflow: hidden; margin-top: 2px; color: var(--slate-500); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
  .mobileStatusPair { display: flex; align-items: stretch; flex-direction: column; gap: 3px; }
  .statusBadge, .updateBadge { min-height: 21px; padding: 0 7px; font-size: 9px; }
  .statusBadge small { display: none; }
  .mobileQueryButton { width: 61px; min-width: 61px; min-height: 42px; margin: 0; padding: 0 5px; border-radius: 9px; font-size: 10px; }
  .panelFooter { display: block; min-height: 0; margin-top: 9px; padding: 0; background: transparent; }
  .infoNote { display: none; }
  .pagination { justify-content: center; }
  .pagination > span:first-child { display: none; }
  .mobileActionBar { position: fixed; z-index: 30; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 8px; padding: 7px 10px calc(7px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(13, 97, 53, .12); background: rgba(255, 255, 255, .94); box-shadow: 0 -10px 30px rgba(11, 75, 43, .1); backdrop-filter: blur(18px); }
  .mobileActionBar .primaryButton, .mobileQuickButton { min-height: 44px; padding: 0 10px; font-size: 12px; }
  .mobileQuickButton { border: 1px solid var(--forest-700); background: var(--white); color: var(--forest-800); }
  .quickOverlay { align-items: end; padding: 0; }
  .quickDialog { width: 100%; max-height: calc(100dvh - 12px); padding: 16px 18px calc(18px + env(safe-area-inset-bottom)); border-radius: 22px 22px 0 0; }
  .quickDialogHeader h2 { font-size: 19px; }
  .quickCode { margin-top: 13px; }
  .quickCode strong { height: 45px; font-size: 22px; }
  .quickKeypad { gap: 7px; margin-top: 12px; }
  .quickKeypad button { min-height: 48px; border-radius: 10px; }
}

@media (max-width: 410px) {
  .content { width: calc(100% - 12px); }
  .deviceCard { grid-template-columns: minmax(84px, 1fr) auto 56px; gap: 5px; padding-inline: 7px; }
  .mobileQueryButton { width: 56px; min-width: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
