:root {
  /* Bảng màu nền sáng khúc xạ ánh sáng cho Apple Light Liquid Glass */
  --bg-canvas: #eef3fa;
  --apple-blue: #007aff;
  --apple-blue-deep: #0062cc;
  --apple-indigo: #5856d6;
  --apple-mint: #30b0c7;

  /* Regular Liquid Glass — dùng cho các thẻ chính (Card, Topbar, Modal) */
  --glass-regular: linear-gradient(
    155deg,
    rgba(255, 255, 255, 0.80) 0%,
    rgba(255, 255, 255, 0.48) 52%,
    rgba(255, 255, 255, 0.64) 100%
  );
  --glass-regular-hover: linear-gradient(
    155deg,
    rgba(255, 255, 255, 0.88) 0%,
    rgba(255, 255, 255, 0.56) 52%,
    rgba(255, 255, 255, 0.72) 100%
  );

  /* Thin Liquid Glass — dùng cho nút phụ, ô nhập liệu, pill, chip */
  --glass-thin: linear-gradient(
    160deg,
    rgba(255, 255, 255, 0.72) 0%,
    rgba(255, 255, 255, 0.40) 100%
  );

  --glass-border: rgba(255, 255, 255, 0.72);
  --glass-border-subtle: rgba(15, 23, 42, 0.08);
  --glass-rim: rgba(255, 255, 255, 0.98);

  --glass-specular:
    inset 0 1.5px 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 -1px 1px 0 rgba(15, 23, 42, 0.04),
    inset 1px 0 0 0 rgba(255, 255, 255, 0.55);

  --glass-shadow:
    0 20px 44px -16px rgba(15, 23, 42, 0.11),
    0 4px 14px -3px rgba(15, 23, 42, 0.05),
    0 0 0 1px rgba(15, 23, 42, 0.04);

  --glass-shadow-hover:
    0 26px 52px -16px rgba(15, 23, 42, 0.15),
    0 8px 20px -4px rgba(0, 122, 255, 0.08),
    0 0 0 1px rgba(15, 23, 42, 0.05);

  --blur-regular: 28px;
  --blur-thin: 16px;
  --sat-glass: 195%;

  /* Hệ thống chữ & màu trạng thái Apple */
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-tertiary: #64748b;

  --safe-green: #248a3d;
  --safe-bright: #34c759;
  --safe-glass: rgba(52, 199, 89, 0.14);
  --safe-border: rgba(52, 199, 89, 0.35);

  --warn-amber: #ff9f0a;
  --danger-red: #ff3b30;
  --danger-deep: #d70015;
  --danger-glass: rgba(255, 59, 48, 0.12);
  --danger-border: rgba(255, 59, 48, 0.34);

  /* Spring Physics Timings */
  --ease-liquid: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Plus Jakarta Sans", sans-serif;
  background-color: var(--bg-canvas);
  background-image:
    radial-gradient(at 8% 6%, rgba(0, 122, 255, 0.18) 0px, transparent 48%),
    radial-gradient(at 92% 10%, rgba(88, 86, 214, 0.15) 0px, transparent 46%),
    radial-gradient(at 84% 90%, rgba(48, 176, 199, 0.16) 0px, transparent 50%),
    radial-gradient(at 14% 88%, rgba(52, 199, 89, 0.11) 0px, transparent 45%);
  background-attachment: fixed;
  overflow-x: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Các khối ánh sáng khúc xạ trôi nhẹ phía sau lớp kính */
body::before,
body::after {
  content: "";
  position: fixed;
  border-radius: 50%;
  filter: blur(85px);
  pointer-events: none;
  z-index: 0;
  will-change: transform;
  animation: liquidDrift 20s var(--ease-liquid) infinite alternate;
}

body::before {
  width: 480px;
  height: 480px;
  top: -80px;
  left: 12%;
  background: radial-gradient(circle, rgba(0, 122, 255, 0.22) 0%, rgba(0, 122, 255, 0) 70%);
}

body::after {
  width: 520px;
  height: 520px;
  bottom: -100px;
  right: 8%;
  background: radial-gradient(circle, rgba(88, 86, 214, 0.18) 0%, rgba(88, 86, 214, 0) 70%);
  animation-delay: -9s;
}

@keyframes liquidDrift {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(36px, 28px, 0) scale(1.06); }
  100% { transform: translate3d(-24px, -20px, 0) scale(0.95); }
}

.app-shell {
  width: min(1440px, 94vw);
  margin: 0 auto;
  padding: 20px 0 28px;
  position: relative;
  z-index: 1;
}

a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2.5px solid var(--apple-blue);
  outline-offset: 2px;
}

/* ==========================================================================
   Vật liệu Apple Light Liquid Glass (.surface-card)
   ========================================================================== */
.surface-card {
  position: relative;
  background: var(--glass-regular);
  backdrop-filter: blur(var(--blur-regular)) saturate(var(--sat-glass));
  -webkit-backdrop-filter: blur(var(--blur-regular)) saturate(var(--sat-glass));
  border: 1px solid var(--glass-border);
  border-radius: 26px;
  box-shadow: var(--glass-specular), var(--glass-shadow);
  isolation: isolate;
  transition:
    transform 0.4s var(--ease-liquid),
    background 0.35s var(--ease-liquid),
    box-shadow 0.4s var(--ease-liquid);
}

/* Viền sáng khúc xạ dọc mép trên-trái (Rim Light) */
.surface-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(
    135deg,
    var(--glass-rim) 0%,
    rgba(255, 255, 255, 0.5) 28%,
    rgba(255, 255, 255, 0.1) 55%,
    rgba(255, 255, 255, 0.65) 100%
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* ==========================================================================
   Header / Topbar
   ========================================================================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  padding: 12px 20px;
  border-radius: 22px;
}

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

.brand-logo {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border-radius: 13px;
  background: linear-gradient(155deg, #2997ff 0%, #007aff 100%);
  color: #ffffff;
  box-shadow:
    0 6px 16px -3px rgba(0, 122, 255, 0.42),
    inset 0 1.5px 1px rgba(255, 255, 255, 0.65);
}

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

.brand h1 {
  font-size: 18.5px;
  font-weight: 700;
  letter-spacing: -0.35px;
  color: var(--text-primary);
}

.version-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2.5px 9px;
  border-radius: 999px;
  background: rgba(52, 199, 89, 0.15);
  color: var(--safe-green);
  border: 1px solid rgba(52, 199, 89, 0.32);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 1px;
  font-weight: 500;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.server-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 15px;
  border-radius: 999px;
  background: var(--glass-thin);
  backdrop-filter: blur(var(--blur-thin)) saturate(var(--sat-glass));
  -webkit-backdrop-filter: blur(var(--blur-thin)) saturate(var(--sat-glass));
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 4px 12px rgba(15, 23, 42, 0.05);
  color: var(--text-secondary);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn-amber);
  box-shadow: 0 0 8px rgba(255, 159, 10, 0.6);
  animation: pulseDot 2s infinite ease-in-out;
}

.server-chip.ready {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.82), rgba(52, 199, 89, 0.14));
  border-color: rgba(52, 199, 89, 0.35);
  color: var(--safe-green);
}
.server-chip.ready .pulse-dot {
  background: var(--safe-bright);
  box-shadow: 0 0 9px rgba(52, 199, 89, 0.65);
}

.server-chip.error {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.82), rgba(255, 59, 48, 0.14));
  border-color: var(--danger-border);
  color: var(--danger-deep);
}
.server-chip.error .pulse-dot {
  background: var(--danger-red);
  box-shadow: 0 0 9px rgba(255, 59, 48, 0.65);
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.28); opacity: 0.65; }
}

/* ==========================================================================
   Bố cục Dashboard 2 cột
   ========================================================================== */
.dashboard {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(355px, 0.95fr);
  gap: 18px;
  align-items: start;
}

.camera-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.card-head h2 {
  font-size: 17.5px;
  font-weight: 700;
  letter-spacing: -0.25px;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.camera-tools {
  display: flex;
  gap: 8px;
}

.camera-tools[hidden] {
  display: none;
}

/* Dropdown kính mỏng */
.custom-select-wrap select {
  appearance: none;
  -webkit-appearance: none;
  background-color: rgba(255, 255, 255, 0.62);
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.35)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23334155' stroke-width='2.3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat, no-repeat;
  background-position: 0 0, right 10px center;
  backdrop-filter: blur(var(--blur-thin)) saturate(var(--sat-glass));
  -webkit-backdrop-filter: blur(var(--blur-thin)) saturate(var(--sat-glass));
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.95), 0 2px 8px rgba(15, 23, 42, 0.05);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 7.5px 30px 7.5px 13px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.25s var(--ease-liquid);
}

.custom-select-wrap select:hover {
  background-color: rgba(255, 255, 255, 0.85);
  transform: translateY(-1px);
  box-shadow: inset 0 1px 0 #ffffff, 0 6px 14px rgba(15, 23, 42, 0.08);
}

/* ==========================================================================
   Thanh chuyển đổi 3 chế độ & Cấu hình luồng từ xa (Liquid Segmented Control)
   ========================================================================== */
.mode-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 5px;
  border-radius: 15px;
  background: rgba(15, 23, 42, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.78);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05);
}

.mode-tab {
  flex: 1 1 0;
  min-width: 135px;
  padding: 7.5px 12px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition:
    background 0.25s var(--ease-liquid),
    color 0.25s var(--ease-liquid),
    box-shadow 0.25s var(--ease-liquid),
    transform 0.2s var(--ease-bounce);
}

.mode-tab:hover:not(.active) {
  background: rgba(255, 255, 255, 0.45);
  color: var(--text-primary);
}

.mode-tab.active {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(255, 255, 255, 0.84) 100%);
  color: var(--apple-blue-deep);
  border-color: rgba(255, 255, 255, 0.98);
  box-shadow:
    inset 0 1px 0 #ffffff,
    0 3px 10px -2px rgba(15, 23, 42, 0.10);
}

.remote-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  background: var(--glass-thin);
  backdrop-filter: blur(var(--blur-thin)) saturate(var(--sat-glass));
  -webkit-backdrop-filter: blur(var(--blur-thin)) saturate(var(--sat-glass));
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  animation: fadeSlideIn 0.25s var(--ease-liquid);
}

.remote-bar[hidden],
.remote-select-wrap[hidden],
.clean-input[hidden] {
  display: none;
}

.remote-select-wrap {
  flex: 1;
  min-width: 180px;
}

.remote-select-wrap select {
  width: 100%;
}

/* ==========================================================================
   Khung hình Video / Camera Stage (Bo góc đồng tâm 18px)
   ========================================================================== */
.video-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 18px;
  overflow: hidden;
  background: #0b1120;
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow:
    inset 0 2px 10px rgba(15, 23, 42, 0.12),
    0 4px 16px -4px rgba(15, 23, 42, 0.08);
  transition: border-color 0.35s var(--ease-liquid), box-shadow 0.35s var(--ease-liquid);
}

video, #remoteStreamImg, #poseCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

video[hidden], #remoteStreamImg[hidden] {
  display: none;
}

#poseCanvas {
  pointer-events: none;
}

/* Màn hình chờ kính mờ sáng sang trọng */
.camera-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 25% 25%, rgba(0, 122, 255, 0.14), transparent 55%),
    radial-gradient(circle at 78% 75%, rgba(88, 86, 214, 0.12), transparent 55%),
    linear-gradient(180deg, rgba(244, 248, 255, 0.96) 0%, rgba(235, 242, 252, 0.96) 100%);
}

.camera-placeholder.hidden {
  display: none;
}

.placeholder-box {
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0.55));
  backdrop-filter: blur(22px) saturate(190%);
  -webkit-backdrop-filter: blur(22px) saturate(190%);
  padding: 28px 34px;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.95);
  box-shadow:
    inset 0 1.5px 1px #ffffff,
    0 16px 36px -12px rgba(15, 23, 42, 0.12);
  text-align: center;
  max-width: 390px;
}

.camera-icon {
  color: var(--apple-blue);
  margin-bottom: 12px;
  display: inline-flex;
  padding: 13px;
  border-radius: 16px;
  background: linear-gradient(155deg, rgba(0, 122, 255, 0.16), rgba(0, 122, 255, 0.06));
  border: 1px solid rgba(0, 122, 255, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.placeholder-box h3 {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.placeholder-box p {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.placeholder-box b {
  color: var(--apple-blue);
  font-weight: 600;
}

/* Dải cảnh báo kính đỏ khi phát hiện té ngã */
.fall-flash {
  display: none;
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translate3d(-50%, 0, 0);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #ffffff;
  background: linear-gradient(160deg, rgba(255, 59, 48, 0.88), rgba(215, 0, 21, 0.82));
  backdrop-filter: blur(20px) saturate(200%);
  -webkit-backdrop-filter: blur(20px) saturate(200%);
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow:
    0 10px 28px rgba(255, 59, 48, 0.42),
    inset 0 1.5px 1px rgba(255, 255, 255, 0.6);
  z-index: 10;
  align-items: center;
  gap: 8px;
}

.fall-flash.visible {
  display: inline-flex;
  animation: liquidAlertPulse 0.85s var(--ease-liquid) infinite alternate;
}

.video-stage.fall {
  border-color: rgba(255, 59, 48, 0.85);
  box-shadow: 0 0 0 4px rgba(255, 59, 48, 0.22), 0 12px 32px rgba(255, 59, 48, 0.2);
}

@keyframes liquidAlertPulse {
  0% { transform: translate3d(-50%, 0, 0) scale(0.97); }
  100% { transform: translate3d(-50%, 0, 0) scale(1.03); }
}

/* ==========================================================================
   Thanh điều khiển & Nút bấm Liquid Glass
   ========================================================================== */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 2px;
}

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

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8.5px 16px;
  border-radius: 13px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition:
    transform 0.28s var(--ease-bounce),
    box-shadow 0.28s var(--ease-liquid),
    background 0.25s var(--ease-liquid);
}

.btn[hidden] {
  display: none;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1.5px);
}

.btn:active:not(:disabled) {
  transform: scale(0.95);
  transition-duration: 0.1s;
}

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

.btn-primary {
  background: linear-gradient(180deg, #2997ff 0%, #0071e3 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow:
    0 6px 18px -3px rgba(0, 113, 227, 0.45),
    inset 0 1.5px 1px rgba(255, 255, 255, 0.55);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #3ea3ff 0%, #007aff 100%);
  box-shadow:
    0 10px 24px -3px rgba(0, 122, 255, 0.52),
    inset 0 1.5px 1px rgba(255, 255, 255, 0.7);
}

.btn-secondary {
  background: linear-gradient(160deg, rgba(0, 122, 255, 0.14), rgba(0, 122, 255, 0.06));
  backdrop-filter: blur(var(--blur-thin)) saturate(var(--sat-glass));
  -webkit-backdrop-filter: blur(var(--blur-thin)) saturate(var(--sat-glass));
  color: var(--apple-blue-deep);
  border: 1px solid rgba(0, 122, 255, 0.28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85), 0 3px 10px rgba(0, 122, 255, 0.08);
}

.btn-secondary:hover:not(:disabled) {
  background: linear-gradient(160deg, rgba(0, 122, 255, 0.22), rgba(0, 122, 255, 0.10));
  border-color: rgba(0, 122, 255, 0.42);
}

.btn-ghost {
  background: var(--glass-thin);
  backdrop-filter: blur(var(--blur-thin)) saturate(var(--sat-glass));
  -webkit-backdrop-filter: blur(var(--blur-thin)) saturate(var(--sat-glass));
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 2px 8px rgba(15, 23, 42, 0.04);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.85);
  color: var(--text-primary);
}

.btn-sm {
  padding: 7.5px 13px;
  font-size: 12px;
  border-radius: 11px;
  white-space: nowrap;
}

/* Spinner Loading */
.btn-spinner { display: none; }
.btn.is-loading { cursor: wait; pointer-events: none; }
.btn.is-loading .btn-label { visibility: hidden; }
.btn.is-loading .btn-spinner {
  display: block;
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* Công tắc kiểu iOS Liquid Switch */
.toggles-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.switch-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 13px;
  border-radius: 999px;
  background: var(--glass-thin);
  backdrop-filter: blur(var(--blur-thin)) saturate(var(--sat-glass));
  -webkit-backdrop-filter: blur(var(--blur-thin)) saturate(var(--sat-glass));
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 2px 8px rgba(15, 23, 42, 0.04);
  cursor: pointer;
  user-select: none;
  transition: all 0.25s var(--ease-liquid);
}

.switch-pill:hover {
  background: rgba(255, 255, 255, 0.82);
  transform: translateY(-1px);
}

.switch-pill input { display: none; }

.toggle-slider {
  width: 34px;
  height: 20px;
  background: rgba(15, 23, 42, 0.14);
  border-radius: 999px;
  position: relative;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.12);
  transition: background 0.3s var(--ease-liquid);
}

.toggle-slider::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.22);
  transition: transform 0.32s var(--ease-bounce), width 0.2s ease;
}

.switch-pill input:checked + .toggle-slider {
  background: var(--safe-bright);
}

.email-pill input:checked + .toggle-slider {
  background: var(--apple-blue);
}

.switch-pill input:checked + .toggle-slider::before {
  transform: translate3d(14px, 0, 0);
}

.toggle-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ==========================================================================
   Cột phải (Side Panel)
   ========================================================================== */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-tertiary);
}

/* Thẻ 1: Trạng thái & Chỉ số hợp nhất */
.status-card {
  padding: 20px;
}

.status-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.status-pill-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.9);
  padding: 2.5px 9px;
  border-radius: 8px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.status-orb {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.95);
  box-shadow: inset 0 1px 0 #ffffff, 0 4px 12px rgba(15, 23, 42, 0.06);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: all 0.35s var(--ease-liquid);
}

.orb-core {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #94a3b8;
  transition: all 0.35s var(--ease-liquid);
}

.orb-ring {
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  border: 1.5px solid rgba(148, 163, 184, 0.35);
}

.status-row h2 {
  font-size: 17.5px;
  font-weight: 800;
  letter-spacing: -0.25px;
  color: var(--text-primary);
}

.status-row p {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Trạng thái Bình thường */
.status-normal .status-orb {
  background: linear-gradient(155deg, rgba(52, 199, 89, 0.2), rgba(255, 255, 255, 0.8));
}
.status-normal .orb-core {
  background: var(--safe-bright);
  box-shadow: 0 0 14px rgba(52, 199, 89, 0.55);
}
.status-normal .status-row h2 { color: var(--safe-green); }

/* Trạng thái Té ngã */
.status-fall {
  background: linear-gradient(
    155deg,
    rgba(255, 235, 235, 0.88) 0%,
    rgba(255, 255, 255, 0.65) 100%
  );
  border-color: rgba(255, 59, 48, 0.42);
}
.status-fall .status-orb {
  background: linear-gradient(155deg, rgba(255, 59, 48, 0.22), rgba(255, 255, 255, 0.85));
}
.status-fall .orb-core {
  background: var(--danger-red);
  box-shadow: 0 0 16px rgba(255, 59, 48, 0.65);
}
.status-fall .status-row h2 { color: var(--danger-deep); }

/* Thanh đo mức độ rủi ro */
.probability-block {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(15, 23, 42, 0.07);
}

.metric-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.metric-label b {
  color: var(--text-primary);
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

.probability-track {
  position: relative;
  height: 9px;
  margin-top: 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.08);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.1);
  overflow: visible;
}

#probabilityFill {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: var(--safe-bright);
  transition: width 0.28s var(--ease-liquid), background 0.3s ease;
}

#thresholdMark {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2.5px;
  background: var(--text-primary);
  border-radius: 2px;
}

.threshold-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

/* Hàng chỉ số kính mỏng bên trong Status Card */
.inline-metrics {
  display: flex;
  align-items: center;
  margin-top: 14px;
  padding: 11px 15px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.inline-metric-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.inline-metric-title {
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 500;
}

.inline-metric-item strong {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.inline-metric-item strong em {
  font-size: 11.5px;
  font-weight: 600;
  font-style: normal;
  color: var(--text-tertiary);
}

.inline-metric-divider {
  width: 1px;
  height: 28px;
  background: rgba(15, 23, 42, 0.08);
  margin: 0 14px;
}

/* ==========================================================================
   Thẻ 2: Cấu hình Email
   ========================================================================== */
.email-config-card {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.email-config-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.email-config-head h3 {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.email-status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2.5px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.06);
  color: var(--text-tertiary);
  border: 1px solid rgba(255, 255, 255, 0.8);
  transition: all 0.25s var(--ease-liquid);
}

.email-status-badge.active {
  background: rgba(0, 122, 255, 0.14);
  color: var(--apple-blue-deep);
  border-color: rgba(0, 122, 255, 0.3);
}

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

.clean-input {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 0 rgba(255, 255, 255, 0.8);
  border-radius: 11px;
  padding: 8px 12px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  transition: all 0.25s var(--ease-liquid);
}

.clean-input::placeholder {
  color: #94a3b8;
}

.clean-input:focus {
  background: rgba(255, 255, 255, 0.92);
  border-color: var(--apple-blue);
  box-shadow: 0 0 0 3.5px rgba(0, 122, 255, 0.16);
}

.email-hint {
  font-size: 11.5px;
  color: var(--text-tertiary);
  line-height: 1.45;
}

.email-hint b {
  color: var(--text-secondary);
}

/* ==========================================================================
   Thẻ 3: Lịch sử sự cố & Nhật ký
   ========================================================================== */
.events-card {
  padding: 18px 20px;
}

.events-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.events-head h3 {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.text-action-btn {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.8);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
  transition: all 0.2s var(--ease-liquid);
}

.text-action-btn:hover {
  background: rgba(255, 255, 255, 0.9);
  color: var(--text-primary);
}

.event-list {
  max-height: 270px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(15, 23, 42, 0.16) transparent;
}

.event-list::-webkit-scrollbar { width: 5px; }
.event-list::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.16);
  border-radius: 999px;
}

.empty-log {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #94a3b8;
  font-size: 12px;
  padding: 26px 0;
  text-align: center;
}

.event-item {
  display: grid;
  grid-template-columns: 7px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8.5px 11px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.85);
  font-size: 11.5px;
  color: var(--text-secondary);
  animation: fadeSlideIn 0.3s var(--ease-liquid);
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-5px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.event-item i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--apple-blue);
}

.event-item.fall i {
  background: var(--danger-red);
}

.event-item span {
  color: var(--text-tertiary);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* Thẻ sự cố té ngã có ảnh chụp khoảnh khắc */
.fall-history-card {
  display: flex;
  gap: 10px;
  padding: 10px;
  border-radius: 15px;
  background: linear-gradient(155deg, rgba(255, 235, 235, 0.78), rgba(255, 255, 255, 0.65));
  border: 1px solid rgba(255, 59, 48, 0.3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 4px 12px rgba(255, 59, 48, 0.08);
  animation: fadeSlideIn 0.35s var(--ease-liquid);
  transition: transform 0.25s var(--ease-bounce), box-shadow 0.25s var(--ease-liquid);
}

.fall-history-card:hover {
  transform: translateY(-1.5px);
  box-shadow: inset 0 1px 0 #ffffff, 0 8px 18px rgba(255, 59, 48, 0.14);
}

.fall-thumb-wrap {
  position: relative;
  width: 96px;
  height: 62px;
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.85);
  background: #0f172a;
  cursor: pointer;
}

.fall-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s var(--ease-liquid);
}

.fall-thumb-wrap:hover img {
  transform: scale(1.06);
}

.fall-thumb-zoom {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #ffffff;
  font-size: 9.5px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.fall-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 5px;
}

.fall-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.fall-card-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--danger-deep);
}

.fall-card-clock {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.fall-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.9);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-chip.video-chip {
  background: rgba(0, 122, 255, 0.12);
  color: var(--apple-blue-deep);
  border-color: rgba(0, 122, 255, 0.24);
}

.meta-chip.mail-sent-chip {
  background: rgba(52, 199, 89, 0.14);
  color: var(--safe-green);
  border-color: rgba(52, 199, 89, 0.28);
}

/* ==========================================================================
   Modal Lightbox xem ảnh chi tiết (Liquid Glass Sheet)
   ========================================================================== */
.snapshot-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
}

.snapshot-modal[hidden] {
  display: none;
}

.snapshot-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(12px) saturate(150%);
  -webkit-backdrop-filter: blur(12px) saturate(150%);
}

.snapshot-modal-dialog {
  position: relative;
  z-index: 1;
  width: min(680px, 94vw);
  padding: 22px;
  background: linear-gradient(
    155deg,
    rgba(255, 255, 255, 0.88) 0%,
    rgba(255, 255, 255, 0.70) 100%
  );
  box-shadow:
    inset 0 1.5px 1px #ffffff,
    0 28px 60px -12px rgba(15, 23, 42, 0.25);
}

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

.snapshot-modal-head h3 {
  font-size: 16.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text-secondary);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
  transition: all 0.2s var(--ease-bounce);
}

.modal-close-btn:hover {
  background: rgba(255, 59, 48, 0.14);
  color: var(--danger-deep);
  transform: scale(1.06);
}

.snapshot-modal-body img {
  width: 100%;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  display: block;
  margin-bottom: 14px;
}

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

.snapshot-meta-box {
  padding: 10px 13px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.9);
}

.snapshot-meta-box small {
  display: block;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: 2px;
}

.snapshot-meta-box strong {
  font-size: 12.5px;
  color: var(--text-primary);
  word-break: break-all;
}

/* ==========================================================================
   Footer & Responsive
   ========================================================================== */
.clean-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  padding: 12px 20px;
  border-radius: 18px;
  background: var(--glass-thin);
  backdrop-filter: blur(var(--blur-thin)) saturate(var(--sat-glass));
  -webkit-backdrop-filter: blur(var(--blur-thin)) saturate(var(--sat-glass));
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  color: var(--text-tertiary);
  font-size: 11.5px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1060px) {
  .dashboard { grid-template-columns: 1fr; }
  .side-panel { display: grid; grid-template-columns: 1fr 1fr; }
  .events-card { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  .app-shell { width: 94vw; padding-top: 12px; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
  .card-head { flex-direction: column; align-items: flex-start; }
  .camera-tools { width: 100%; }
  .custom-select-wrap { flex: 1; }
  .custom-select-wrap select { width: 100%; }
  .mode-tab { min-width: 105px; font-size: 11.5px; padding: 7px 8px; }
  .remote-bar { flex-direction: column; align-items: stretch; }
  .video-stage { aspect-ratio: 4 / 3; }
  .side-panel { display: flex; flex-direction: column; }
  .clean-footer { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  body::before, body::after, .fall-flash, .pulse-dot, .event-item, .fall-history-card, .remote-bar { animation: none !important; }
  .btn, #probabilityFill, .surface-card, .toggle-slider, .toggle-slider::before, .fall-thumb-wrap img, .mode-tab { transition: none !important; }
}