/* Motion Sense Lab — tema scuro, mobile-first, tecnico ma leggibile. */

:root {
  --bg: #0b0f17;
  --bg-elev: #131a26;
  --bg-elev2: #1c2433;
  --line: #243049;
  --text: #e8edf5;
  --text-dim: #9aa6bd;
  --accent: #5ad1ff;
  --accent-2: #8af0c8;
  --warn: #ffb547;
  --bad: #ff5b6e;
  --ok: #6ee895;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --tab-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
  min-height: 100%;
}

body {
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 8px);
  padding-top: var(--safe-top);
}

a { color: var(--accent); text-decoration: none; }
a:active { opacity: 0.7; }

h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.2; }
p { margin: 0 0 8px; color: var(--text-dim); line-height: 1.45; }
small { color: var(--text-dim); }

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
  gap: 12px;
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, rgba(11,15,23,0.95), rgba(11,15,23,0.6) 80%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 18px; font-weight: 700; letter-spacing: 0.2px; }
.brand .subtitle { font-size: 12px; color: var(--text-dim); margin: 2px 0 0; }
.logo {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 30%, var(--accent), #1a4d7a);
  color: #001827;
  border-radius: 50%;
  font-size: 18px; font-weight: 900;
  box-shadow: 0 0 16px rgba(90, 209, 255, 0.4);
}

/* ===== View ===== */
.view {
  padding: 8px 16px 24px;
  max-width: 720px;
  margin: 0 auto;
}

.section { margin-bottom: 18px; }

.muted { color: var(--text-dim); }

/* ===== Card ===== */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card h2 { font-size: 17px; }
.card h3 { font-size: 15px; color: var(--text); }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.grid .card { margin: 0; }
.grid .card .ico {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 18px;
  color: var(--accent);
}
.grid .card h3 { margin: 4px 0 4px; }
.grid .card p { font-size: 12.5px; margin: 0; }

/* ===== Buttons ===== */
.btn {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: #001321;
  font-weight: 700;
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 15px;
  width: 100%;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.06s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.985); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn.secondary { background: var(--bg-elev2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--bad); color: #200; }
.btn.warn { background: var(--warn); color: #201400; }
.btn.ok { background: var(--ok); color: #022; }
.btn.ghost {
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--line); padding: 8px 12px; width: auto; font-size: 13px;
}
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ===== Tabs ===== */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(11, 15, 23, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 100;
  padding-bottom: var(--safe-bottom);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  min-width: 64px;
  height: var(--tab-h);
  padding: 6px 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-dim);
  font-size: 11px;
  gap: 2px;
}
.tab.active { color: var(--accent); }
.tab-ico { font-size: 20px; line-height: 1; }

/* ===== Metric & Badge ===== */
.metric {
  display: flex; align-items: baseline; gap: 8px;
  font-family: var(--mono);
  font-size: 38px;
  font-weight: 700;
  color: var(--text);
}
.metric .unit { font-size: 14px; color: var(--text-dim); font-weight: 500; }
.metric-row { display: flex; gap: 14px; flex-wrap: wrap; }
.metric-row .metric { font-size: 22px; }

.badge {
  display: inline-block; padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 12px;
}
.badge.ok { background: rgba(110, 232, 149, 0.12); color: var(--ok); border-color: rgba(110,232,149,0.3); }
.badge.bad { background: rgba(255, 91, 110, 0.12); color: var(--bad); border-color: rgba(255,91,110,0.3); }
.badge.warn { background: rgba(255, 181, 71, 0.12); color: var(--warn); border-color: rgba(255,181,71,0.3); }
.badge.info { background: rgba(90, 209, 255, 0.12); color: var(--accent); border-color: rgba(90,209,255,0.3); }

.warning {
  background: rgba(255, 181, 71, 0.1);
  border: 1px solid rgba(255, 181, 71, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--warn);
  font-size: 13px;
  margin: 10px 0;
}
.warning strong { color: #fff; }

.kv {
  display: grid; grid-template-columns: 80px 1fr;
  gap: 4px 12px;
  font-family: var(--mono);
  font-size: 13px;
}
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; color: var(--text); }

canvas {
  display: block;
  width: 100%;
  background: #07090f;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

/* 3D box per visualizzazione orientamento */
.scene { perspective: 600px; height: 200px; display: flex; align-items: center; justify-content: center; }
.cube {
  width: 110px; height: 110px;
  transform-style: preserve-3d;
  transition: transform 0.05s linear;
  position: relative;
}
.cube .face {
  position: absolute; width: 110px; height: 110px;
  background: linear-gradient(135deg, rgba(90, 209, 255, 0.45), rgba(138, 240, 200, 0.15));
  border: 1px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  color: #001321; font-weight: 700; font-size: 14px;
}
.cube .f-front  { transform: translateZ(55px); }
.cube .f-back   { transform: rotateY(180deg) translateZ(55px); }
.cube .f-right  { transform: rotateY(90deg) translateZ(55px); }
.cube .f-left   { transform: rotateY(-90deg) translateZ(55px); }
.cube .f-top    { transform: rotateX(90deg) translateZ(55px); }
.cube .f-bottom { transform: rotateX(-90deg) translateZ(55px); }

/* Status dots */
.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  margin-right: 6px;
}
.status-dot.ok  { background: var(--ok);  box-shadow: 0 0 6px var(--ok); }
.status-dot.bad { background: var(--bad); box-shadow: 0 0 6px var(--bad); }
.status-dot.warn{ background: var(--warn);box-shadow: 0 0 6px var(--warn);}
.status-dot.unk { background: var(--text-dim); }

.hidden { display: none !important; }

/* Lista eventi (es. cadute) */
.events { list-style: none; padding: 0; margin: 8px 0 0; }
.events li {
  font-family: var(--mono);
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
  color: var(--text);
}
.events li:last-child { border-bottom: 0; }

/* Pulse animation on heart */
@keyframes pulse {
  0%   { transform: scale(1);   opacity: 1; }
  50%  { transform: scale(1.15);opacity: 0.85; }
  100% { transform: scale(1);   opacity: 1; }
}
.pulse { animation: pulse 0.6s ease-in-out 1; }

/* Toast */
.toast {
  position: fixed; left: 50%;
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 14px);
  transform: translateX(-50%);
  background: rgba(255, 91, 110, 0.95);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 700;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.toast.show { opacity: 1; }

/* ===== Gauge circolare (stile smartwatch) ===== */
.gauge-wrap { display: flex; justify-content: center; }
canvas.gauge {
  width: 100%;
  max-width: 280px;
  aspect-ratio: 1 / 1;
  height: auto;
  background: transparent;     /* override sfondo/bordi del canvas generico */
  border: 0;
  border-radius: 0;
}

/* Animazione decorativa "Scanning…": anello che pulsa durante la cattura.
   È solo un effetto visivo, non una scansione diagnostica. */
.scanning { position: relative; }
.scanning::after {
  content: "";
  position: absolute; inset: 6%;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: scanPulse 1.8s ease-out infinite;
  pointer-events: none;
}
@keyframes scanPulse {
  0%   { transform: scale(0.82); opacity: 0.5; }
  70%  { opacity: 0; }
  100% { transform: scale(1.02); opacity: 0; }
}

/* ===== Anelli salute (vista aggregata watch-style) ===== */
.rings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.ring {
  margin: 0;
  text-align: center;
  display: flex; flex-direction: column; align-items: center;
}
.ring canvas.gauge { max-width: 150px; }
.ring .ring-lbl { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.ring .ring-age { font-size: 11px; color: var(--text-dim); font-family: var(--mono); }

@media (prefers-reduced-motion: reduce) {
  .scanning::after { animation: none; display: none; }
  .pulse { animation: none; }
}
