:root {
  --bg-dark: #0f172a;
  --panel-bg: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --green: #16a34a;
  --green-hover: #15803d;
  --red: #dc2626;
  --amber: #f59e0b;
  --blue: #2563eb;
}

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

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom, 12px);
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: rgba(30, 41, 59, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.device-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot.online { background: #22c55e; box-shadow: 0 0 8px #22c55e; }
.dot.calling { background: #ef4444; animation: pulse 1s infinite; }
.dot.offline { background: #64748b; }

.viewer-badge {
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  padding: 4px 10px;
  border-radius: 999px;
}

.metrics-strip {
  font-size: 11px;
  color: #93c5fd;
  background: rgba(15, 23, 42, 0.92);
  border-bottom: 1px solid rgba(56, 189, 248, 0.16);
  padding: 5px 12px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  font-size: 14px;
}
.banner-icon { font-size: 24px; }
.banner-body strong { display: block; font-size: 15px; }
.banner-body p { font-size: 12px; opacity: 0.9; margin-top: 2px; }

.alarm-banner {
  background: linear-gradient(90deg, #991b1b, #dc2626);
  animation: flashBg 1.2s infinite alternate;
}

.busy-banner {
  background: linear-gradient(90deg, #065f46, #059669);
}

.stage {
  position: relative;
  flex: 1;
  background: #020617;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#remoteVideo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.placeholder-layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #020617;
  padding: 20px;
  text-align: center;
}

.snapshot-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.72;
}

.empty-hint {
  position: relative;
  z-index: 2;
  background: rgba(15, 23, 42, 0.78);
  padding: 20px 24px;
  border-radius: 16px;
  backdrop-filter: blur(6px);
}
.camera-icon { font-size: 42px; margin-bottom: 8px; }
.empty-hint p { font-size: 17px; font-weight: 600; }
.sub-hint { display: block; margin-top: 6px; font-size: 13px; color: var(--text-muted); }

.call-hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 5;
}
.hud-tag, .hud-timer {
  background: rgba(0, 0, 0, 0.6);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.hud-tag { color: #4ade80; }

.https-warn {
  background: rgba(245, 158, 11, 0.18);
  color: #fcd34d;
  font-size: 12px;
  padding: 8px 14px;
  line-height: 1.4;
}

.control-dock {
  background: var(--panel-bg);
  padding: 14px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 16px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-answer {
  background: var(--green);
  box-shadow: 0 4px 16px rgba(22, 163, 74, 0.4);
}
.btn-answer.ringing {
  animation: pulseBtn 1s infinite;
}

.btn-monitor {
  background: #334155;
  font-size: 15px;
  padding: 13px;
  font-weight: 600;
}

.in-call-bar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 6px 0 10px;
}

.circle-btn {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: none;
  background: #334155;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 24px;
  cursor: pointer;
}
.circle-btn small { font-size: 11px; color: #e2e8f0; }
.circle-btn.active { background: var(--blue); }
.circle-btn.hangup { background: var(--red); width: 84px; height: 84px; }

.identity-bar {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.identity-bar input {
  flex: 1;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 7px 10px;
  color: #fff;
  font-size: 14px;
}
.ota-mini-btn {
  background: rgba(51, 65, 85, 0.9);
  color: #cbd5e1;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
}
.ota-progress-wrap {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #0f172a;
  overflow: hidden;
}
.ota-progress-fill {
  height: 100%;
  width: 0%;
  background: #22c55e;
  transition: width 0.25s;
}
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-card {
  width: 100%;
  max-width: 340px;
  background: var(--panel-bg);
  padding: 22px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-card p { font-size: 13px; color: var(--text-muted); }
.modal-card input {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: #0f172a;
  color: #fff;
  font-size: 16px;
}

.log-modal-card {
  max-width: 600px;
  max-height: 82dvh;
}
.device-log-box {
  background: #020617;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 10px;
  padding: 10px 12px;
  height: 52dvh;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #cbd5e1;
  white-space: pre-wrap;
  word-break: break-all;
}
.log-err { color: #f87171; font-weight: 600; }
.log-warn { color: #fbbf24; }
.log-info { color: #4ade80; }

.hidden { display: none !important; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.25); }
}
@keyframes flashBg {
  from { filter: brightness(0.95); }
  to { filter: brightness(1.18); }
}
@keyframes pulseBtn {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.65); }
  50% { box-shadow: 0 0 0 12px rgba(34, 197, 94, 0); }
}
