    :root {
      --bg: #f5f7f7;
      --card: #ffffff;
      --text: #172b31;
      --muted: #687a80;
      --line: #e5ebec;
      --accent: #087d85;
      --accent-soft: #e6f3f2;
      --warn: #9d6825;
      --danger: #b42318;
      --danger-soft: #fef2f2;
      --radius: 16px;
      --shadow: 0 6px 24px rgba(31, 58, 62, 0.045);
    }
    * { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
    [hidden] { display: none !important; }
    html {
      max-width: 100%;
      overflow-x: hidden;
    }
    body {
      font: 400 13px/1.5 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
      background: var(--bg);
      color: var(--text);
      width: 100%;
      max-width: 480px;
      margin: 0 auto;
      min-height: 100vh;
      overflow-x: hidden;
      padding: max(12px, env(safe-area-inset-top)) 16px calc(116px + env(safe-area-inset-bottom));
      -webkit-font-smoothing: antialiased;
    }
    button, input, select { font: inherit; color: inherit; }
    button { cursor: pointer; }
    a { color: inherit; text-decoration: none; }
    button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
      outline: 3px solid #89c9c8;
      outline-offset: 2px;
    }
    .icon {
      width: 20px;
      height: 20px;
      stroke: currentColor;
      fill: none;
      stroke-width: 1.8;
      stroke-linecap: round;
      stroke-linejoin: round;
      flex: none;
    }

    .header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 12px;
      margin-bottom: 16px;
    }
    h1 {
      font-size: 22px;
      line-height: 1.3;
      font-weight: 600;
      letter-spacing: -0.02em;
    }
    h2 {
      font-size: 16px;
      line-height: 1.4;
      font-weight: 500;
    }
    .status-dot {
      display: inline-flex;
      align-items: center;
      gap: 7px;
      font-size: 12px;
      color: var(--muted);
      white-space: nowrap;
    }
    .status-dot::before {
      content: "";
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: var(--accent);
    }
    .status-dot.offline::before {
      background: var(--warn);
    }

    .card {
      background: var(--card);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      padding: 16px;
      margin-bottom: 14px;
      box-shadow: var(--shadow);
    }
    .card-head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 8px;
      margin-bottom: 12px;
    }
    .muted {
      color: var(--muted);
      font-size: 12px;
    }
    .text-link {
      color: var(--accent);
      font-weight: 500;
      font-size: 13px;
      background: transparent;
      border: 0;
      padding: 4px 0;
    }

    .overview-box {
      height: 220px;
      border-radius: 12px;
      border: 1px dashed #bdd4d2;
      background: linear-gradient(145deg, #f3f8f7, #eaf2f1);
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      gap: 6px;
      text-align: center;
      color: var(--muted);
      margin-bottom: 12px;
    }
    .overview-box strong {
      font-size: 15px;
      font-weight: 500;
      color: var(--text);
    }

    .btn {
      width: 100%;
      min-height: 44px;
      border: 1px solid var(--line);
      background: var(--card);
      color: var(--text);
      border-radius: 10px;
      padding: 0 16px;
      font-weight: 500;
      font-size: 13px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
    }
    .btn.primary {
      background: var(--accent);
      border-color: var(--accent);
      color: #ffffff;
    }
    .btn.secondary {
      background: #ffffff;
    }
    .btn.danger {
      background: var(--danger-soft);
      border-color: #fecdca;
      color: var(--danger);
    }
    .btn-row {
      display: flex;
      gap: 8px;
      align-items: center;
    }

    /* DANH SÁCH THIẾT BỊ 1 CỘT */
    .dev-list {
      display: grid;
      grid-template-columns: 1fr;
      gap: 10px;
    }
    .dev-row {
      background: #ffffff;
      border: 1px solid var(--line);
      border-radius: 12px;
      padding: 12px;
      display: flex;
      align-items: center;
      gap: 12px;
      min-height: 58px;
      cursor: pointer;
    }
    .dev-icon {
      width: 36px;
      height: 36px;
      border-radius: 10px;
      background: var(--accent-soft);
      color: var(--accent);
      display: grid;
      place-items: center;
      flex: none;
    }
    .dev-row.off .dev-icon {
      background: #f1f3f3;
      color: #89979b;
    }
    .dev-copy {
      flex: 1;
      min-width: 0;
    }
    .dev-name {
      font-size: 13px;
      font-weight: 500;
      color: var(--text);
    }
    .dev-room {
      font-size: 11px;
      font-weight: 400;
      color: var(--muted);
    }
    .switch {
      width: 40px;
      height: 22px;
      border-radius: 999px;
      background: #becacc;
      border: 0;
      padding: 3px;
      position: relative;
      flex: none;
    }
    .switch::after {
      content: "";
      width: 16px;
      height: 16px;
      border-radius: 50%;
      background: #ffffff;
      display: block;
      transition: transform 0.18s ease;
    }
    .dev-row.on .switch {
      background: var(--accent);
    }
    .dev-row.on .switch::after {
      transform: translateX(18px);
    }

    .filter-pills {
      display: flex;
      gap: 6px;
      flex-wrap: wrap;
      margin-bottom: 12px;
    }
    .pill {
      min-height: 36px;
      padding: 0 12px;
      border-radius: 999px;
      font-size: 12px;
      font-weight: 500;
      border: 1px solid var(--line);
      background: var(--bg);
      color: var(--muted);
    }
    .pill.active {
      background: var(--accent-soft);
      color: var(--accent);
      border-color: #cce5e3;
    }

    .results-box {
      border-top: 1px solid var(--line);
      border-bottom: 1px solid var(--line);
      padding: 12px 0;
      margin: 12px 0;
      display: grid;
      gap: 10px;
    }
    .result-label {
      font-size: 11px;
      font-weight: 500;
      color: var(--muted);
      margin-bottom: 2px;
    }
    .voice-input-row {
      display: flex;
      gap: 8px;
      margin-top: 12px;
    }
    input[type="text"], input[type="email"], select {
      width: 100%;
      min-height: 44px;
      background: #ffffff;
      border: 1px solid var(--line);
      border-radius: 10px;
      padding: 0 12px;
      color: var(--text);
      font-size: 13px;
    }

    .account-item {
      border: 1px solid var(--line);
      border-radius: 12px;
      background: #ffffff;
      margin-bottom: 10px;
      overflow: hidden;
    }
    .account-item > summary {
      list-style: none;
      cursor: pointer;
      padding: 14px;
      font-weight: 500;
      font-size: 14px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      min-height: 48px;
    }
    .account-item > summary::-webkit-details-marker { display: none; }
    .account-body {
      padding: 14px;
      border-top: 1px solid var(--line);
      background: var(--bg);
      display: grid;
      gap: 10px;
    }

    .log-list {
      display: grid;
      gap: 6px;
    }
    .log-line {
      padding: 10px 12px;
      border-radius: 10px;
      border: 1px solid var(--line);
      background: #ffffff;
      font-size: 13px;
      display: flex;
      justify-content: space-between;
      gap: 8px;
    }

    /* BOTTOM NAV 4 ITEMS ONLY: NHÀ, THIẾT BỊ, GIỌNG NÓI, TÀI KHOẢN */
    .bottom-nav {
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
      background: var(--card);
      border-top: 1px solid var(--line);
      z-index: 40;
      padding-bottom: env(safe-area-inset-bottom);
    }
    .bottom-nav-inner {
      max-width: 480px;
      margin: 0 auto;
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      padding: 6px 8px;
      gap: 4px;
    }
    .nav-tab {
      border: 0;
      background: transparent;
      color: var(--muted);
      border-radius: 10px;
      min-height: 48px;
      padding: 6px 4px;
      font-size: 11px;
      font-weight: 500;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 3px;
    }
    .nav-tab.active {
      background: var(--accent-soft);
      color: var(--accent);
    }

    /* LOGIN GATE */
    .login-gate {
      position: fixed;
      inset: 0;
      background: var(--bg);
      z-index: 100;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 24px;
    }
    .login-gate[hidden] { display: none !important; }
    .login-card {
      width: 100%;
      max-width: 360px;
      background: var(--card);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      padding: 28px 20px;
      box-shadow: var(--shadow);
    }
    .login-header {
      text-align: center;
      margin-bottom: 20px;
    }
    .login-form {
      display: grid;
      gap: 12px;
    }
    .login-form input[type="password"] {
      width: 100%;
      min-height: 44px;
      background: #ffffff;
      border: 1px solid var(--line);
      border-radius: 10px;
      padding: 0 12px;
      color: var(--text);
      font-size: 13px;
    }

    /* VOICE METRICS */
    .voice-result-badge {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      padding: 4px 10px;
      border-radius: 8px;
      font-size: 12px;
      font-weight: 500;
    }
    .voice-result-badge.pass {
      background: var(--accent-soft);
      color: var(--accent);
    }
    .voice-result-badge.fail {
      background: var(--danger-soft);
      color: var(--danger);
    }
  


/* ═══════════════════════════════════════════════════════════════
   PART 2: M1 - M5 SCREEN STYLES (Codex Design System)
   ═══════════════════════════════════════════════════════════════ */

/* TAB VIEWS */
.tab-view {
  display: block;
  max-width: 100%;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
.tab-view[hidden] {
  display: none !important;
}
#tabViewHome {
  max-width: 100%;
}
#tabViewHome .header {
  margin-bottom: 14px;
}
#tabViewHome .card {
  padding: 14px 16px;
  margin-bottom: 12px;
}
#tabViewHome .card-head {
  margin-bottom: 10px;
}
#tabViewHome .divider {
  margin: 10px 0;
}
#tabViewHome .actions {
  margin-top: 14px !important;
  gap: 10px !important;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
#tabViewAccount {
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
#mobileBtnLogout {
  margin-bottom: calc(24px + env(safe-area-inset-bottom));
}

/* M1: TOÀN CẢNH 16:9 PREVIEW */
.overview-box.preview-16-9 {
  height: auto;
  aspect-ratio: 16 / 9;
  min-height: 118px;
  max-height: 136px;
  border-radius: 12px;
  border: 1px dashed #b9ccce;
  background: #f4f9f9;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin-bottom: 4px;
  position: relative;
  overflow: hidden;
}
.overview-box.preview-16-9 canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
  object-fit: cover;
  border-radius: 12px;
}

/* M1: CẢM BIẾN 2 Ô GRID */
.sensorgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.sensor {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  background: #ffffff;
}
.sensor strong {
  font-size: 20px;
  font-weight: 600;
  display: block;
  margin-top: 4px;
  color: var(--text);
}
.sensor small {
  display: block;
  margin-top: 2px;
}

/* DIVIDER & LINK ROW */
.divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 12px 0;
}
.linkrow {
  min-height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  padding: 4px 0;
}
.linkrow span:last-child {
  color: var(--muted);
  font-size: 16px;
}

/* M4: BOTTOM SHEET GIỌNG NÓI & SCRIM */
.scrim {
  position: fixed;
  inset: 0;
  background: #0f22267a;
  z-index: 150;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.scrim[hidden] {
  display: none !important;
}
.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  max-height: 75%;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  background: #ffffff;
  padding: 12px 20px max(20px, env(safe-area-inset-bottom));
  box-shadow: 0 -12px 36px #0f222624;
  z-index: 160;
  animation: slideUp 0.25s ease-out;
}
.sheet[hidden] {
  display: none !important;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.handle {
  width: 36px;
  height: 4px;
  border-radius: 5px;
  background: #c8d4d6;
  margin: 0 auto 16px;
}
.wavecircle {
  width: 68px;
  height: 68px;
  border: 2px solid #9ed4d6;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  margin: 16px auto 12px;
}
.bars {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-bottom: 8px;
}
.bars i {
  width: 5px;
  background: var(--accent);
  border-radius: 4px;
  display: block;
  min-height: 8px;
  transition: height 0.15s ease;
}
.timer {
  text-align: center;
  font-size: 22px;
  font-weight: 600;
  margin: 4px 0 12px;
  color: var(--text);
}
.timer span {
  color: var(--muted);
  font-size: 14px;
}
.phrase {
  background: var(--bg);
  border-radius: 10px;
  padding: 12px;
  margin-top: 6px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.result {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 14px;
  font-size: 13px;
  text-align: center;
  font-weight: 500;
  color: #15803d;
}
.result span {
  color: var(--danger);
}

/* M5: CAMERA QUÉT QR MODAL */
.scanner-modal {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.scanner-modal[hidden] {
  display: none !important;
}
.scanner {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.scanner .top {
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  padding: 18px 16px 14px;
}
.scanner-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
}
.camera {
  min-height: 270px;
  flex: 1;
  max-height: 480px;
  background: #22383d;
  border-radius: 16px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}
.scanframe {
  width: 215px;
  height: 215px;
  position: relative;
  display: grid;
  place-items: center;
  color: #c0d3d5;
  font-size: 12px;
}
.scanframe i {
  position: absolute;
  width: 38px;
  height: 38px;
  border: 3px solid #ffffff;
}
.scanframe .tl {
  top: 0;
  left: 0;
  border-right: 0 !important;
  border-bottom: 0 !important;
  border-radius: 8px 0 0 0;
}
.scanframe .tr {
  top: 0;
  right: 0;
  border-left: 0 !important;
  border-bottom: 0 !important;
  border-radius: 0 8px 0 0;
}
.scanframe .bl {
  bottom: 0;
  left: 0;
  border-right: 0 !important;
  border-top: 0 !important;
  border-radius: 0 0 0 8px;
}
.scanframe .br {
  bottom: 0;
  right: 0;
  border-left: 0 !important;
  border-top: 0 !important;
  border-radius: 0 0 8px 0;
}
.instruction {
  text-align: center;
  font-weight: 500;
  margin: 18px 0 4px;
  color: var(--text);
}

/* Instant UI Feedback: Button spinner and loading state */
.btn-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
  box-sizing: border-box;
}

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

.btn.loading {
  opacity: 0.85;
  pointer-events: none;
  cursor: not-allowed;
}
