﻿/* ===================================================================
   非接触式检测系统 — Android 12 Material You 风格
   =================================================================== */

:root {
  --bg: #0a0e17;
  --surface: #1a1f2e;
  --surface2: #222839;
  --outline: #2e3548;
  --primary: #7c9aff;
  --primary-dim: rgba(124,154,255,0.12);
  --on-bg: #f0f4ff;
  --on-surface: #e0e6f5;
  --on-surface-dim: #8b95b0;
  --green: #4ade80;
  --yellow: #facc15;
  --red: #f87171;
  --cyan: #22d3ee;
  --radius-card: 16px;
  --radius-btn: 12px;
  --elevation: 0 2px 8px rgba(0,0,0,0.4);
}

* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--on-bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Roboto, system-ui, sans-serif;
  font-size: 14px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* ===================================================================
   主布局 — 竖屏单列
   =================================================================== */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ===================================================================
   视频区域
   =================================================================== */
.video-section {
  flex-shrink: 0;
  padding: 8px 10px 6px;
}

.video-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  max-height: 42vh;
  background: #000;
  border-radius: var(--radius-card);
  overflow: hidden;
  border: 1px solid var(--outline);
  box-shadow: var(--elevation);
}

.video-wrapper video,
.video-wrapper canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: contain;
}

.video-wrapper canvas { z-index: 2; }

/* ===================================================================
   浮动底栏
   =================================================================== */
.overlay-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 3;
  display: flex;
  justify-content: space-around;
  background: linear-gradient(transparent, rgba(0,0,0,0.7) 20%, rgba(0,0,0,0.85) 100%);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 22px 4px 8px;
}

.ol-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.ol-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--on-surface-dim);
  margin-bottom: 1px;
}

.ol-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--on-bg);
  text-shadow: 0 0 12px rgba(124,154,255,0.25);
  transition: color 0.3s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  padding: 0 2px;
}

/* 压力颜色 */
#olStress.high { color: var(--red); }
#olStress.medium { color: var(--yellow); }
#olStress.low { color: var(--green); }
#olStress.collecting { color: var(--on-surface-dim); font-size: 13px; }

/* ===================================================================
   状态角标
   =================================================================== */
.status-chip {
  position: absolute;
  top: 8px; left: 8px;
  z-index: 4;
  font-size: 10px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: var(--on-surface-dim);
  border: 1px solid rgba(255,255,255,0.06);
  letter-spacing: 0.3px;
}
.status-chip.connected { color: var(--green); }
.status-chip.calibrating { color: var(--yellow); }
.status-chip.disconnected { color: var(--red); }

/* ===================================================================
   控制栏
   =================================================================== */
.controls {
  display: flex;
  gap: 6px;
  padding: 6px 0 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: 1;
  padding: 10px 0;
  border: none;
  border-radius: var(--radius-btn);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:disabled {
  background: var(--surface2);
  color: var(--on-surface-dim);
  opacity: 0.4;
}

.btn-danger {
  background: rgba(248,113,113,0.15);
  color: var(--red);
  border: 1px solid rgba(248,113,113,0.25);
}
.btn-danger:disabled {
  background: var(--surface2);
  color: var(--on-surface-dim);
  border-color: transparent;
  opacity: 0.4;
}

.btn-ghost {
  background: var(--surface);
  color: var(--on-surface-dim);
  border: 1px solid var(--outline);
  flex: 0 1 auto;
  padding: 10px 12px;
}

/* ===================================================================
   结果面板（可滚动卡片）
   =================================================================== */
.result-panel {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-content: start;
  -webkit-overflow-scrolling: touch;
}

/* 满行卡片 */
.card-full { grid-column: 1 / -1; }
/* 半行卡片 */
.card-half { grid-column: span 1; }

/* 2 列行 */
.row-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.m-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.result-panel::-webkit-scrollbar { width: 3px; }
.result-panel::-webkit-scrollbar-thumb { background: var(--outline); border-radius: 4px; }

/* ===================================================================
   卡片 — Material You 风格
   =================================================================== */
.m-card {
  background: var(--surface);
  border-radius: var(--radius-card);
  border: 1px solid var(--outline);
  padding: 12px 14px;
  box-shadow: var(--elevation);
}

.m-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--cyan);
}

.m-card-icon {
  display: inline-flex;
  align-items: center;
  opacity: 0.8;
}

.m-card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.m-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.m-label {
  font-size: 13px;
  color: var(--on-surface-dim);
}

.m-value {
  font-size: 17px;
  font-weight: 700;
  color: var(--on-surface);
}

.m-value-sm {
  font-size: 14px;
  font-weight: 500;
}

/* ===================================================================
   进度条
   =================================================================== */
.track-bar {
  height: 4px;
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}

.track-fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.calib-fill {
  background: linear-gradient(90deg, var(--yellow), var(--green));
}

#stressFill {
  background: linear-gradient(90deg, var(--primary), var(--cyan));
}

/* ===================================================================
   日志
   =================================================================== */
.log-card { flex-shrink: 0; }

.log-box {
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 11px;
  line-height: 1.7;
  color: var(--on-surface-dim);
  max-height: 100px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.log-box::-webkit-scrollbar { width: 3px; }
.log-box::-webkit-scrollbar-thumb { background: var(--outline); border-radius: 4px; }

.log-line { padding: 1px 0; }
.log-line.system { color: var(--cyan); }
.log-line.ok { color: var(--green); }
.log-line.error { color: var(--red); }

/* ===================================================================
   横屏适配
   =================================================================== */
@media (orientation: landscape) and (max-height: 500px) {
  .video-wrapper { max-height: 75vh; }
  .overlay-bar { padding-top: 14px; }
  .ol-value { font-size: 16px; }
}

/* ===================================================================
   大屏/平板
   =================================================================== */
@media (min-width: 768px) {
  .video-wrapper { max-height: 55vh; }

  .controls { max-width: 500px; margin: 0 auto; }

  .result-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .log-card { grid-column: 1 / -1; }
}

/* Camera preview is rendered by canvas so rotation and uploaded frames stay identical. */
.video-wrapper video {
  opacity: 0;
  pointer-events: none;
}
.video-wrapper canvas {
  z-index: 2;
  background: #000;
}
