/* =====================================================
   PostureMonitor — style.css
   Premium dark-mode posture monitoring UI
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ─── CSS Variables ─── */
:root {
  --bg:          #080810;
  --bg-2:        #0e0e1a;
  --bg-3:        #141428;
  --panel:       rgba(255,255,255,0.04);
  --panel-b:     rgba(255,255,255,0.08);
  --border:      rgba(255,255,255,0.07);

  --primary:     #6366f1;
  --primary-glow:rgba(99,102,241,0.35);
  --primary-h:   #818cf8;

  --good:        #22c55e;
  --good-glow:   rgba(34,197,94,0.3);
  --fair:        #f59e0b;
  --fair-glow:   rgba(245,158,11,0.3);
  --poor:        #ef4444;
  --poor-glow:   rgba(239,68,68,0.35);

  --text:        #f1f5f9;
  --text-2:      #94a3b8;
  --text-3:      #64748b;

  --radius:      16px;
  --radius-sm:   10px;
  --transition:  0.25s cubic-bezier(0.4,0,0.2,1);
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; border: none; font-family: inherit; }
input[type=range] { cursor: pointer; }

/* ─── Screens ─── */
#app { width: 100vw; height: 100vh; position: relative; overflow: hidden; }
.screen {
  position: absolute; inset: 0;
  opacity: 0; pointer-events: none;
  transition: opacity 0.4s ease;
}
.screen.active { opacity: 1; pointer-events: all; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: inherit; font-weight: 600; border-radius: 50px;
  transition: var(--transition); border: none; cursor: pointer;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff;
  box-shadow: 0 0 30px var(--primary-glow);
}
.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 0 45px var(--primary-glow);
}
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-secondary {
  background: var(--panel-b); color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: rgba(255,255,255,0.12); }
.btn-xl { padding: 16px 36px; font-size: 17px; }
.btn-lg { padding: 14px 28px; font-size: 15px; }
.w-full { width: 100%; justify-content: center; }

.icon-btn {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 50%; width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2); transition: var(--transition);
}
.icon-btn:hover { background: var(--panel-b); color: var(--text); }

/* Special style for pause button to make it more visible */
#btn-pause {
  border-color: rgba(99, 102, 241, 0.5);
  color: var(--primary-h);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
}
#btn-pause:hover {
  border-color: rgba(99, 102, 241, 0.8);
  background: rgba(99, 102, 241, 0.15);
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

/* ─── Panels ─── */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  padding: 18px;
}
.panel-title {
  font-size: 12px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-3);
  margin-bottom: 14px; display: flex; justify-content: space-between;
}
.panel-sub { color: var(--text-3); font-weight: 400; }

/* ─── Camera wrap ─── */
.cam-wrap {
  position: relative; border-radius: 12px; overflow: hidden;
  background: #000; aspect-ratio: 4/3;
}
.cam-wrap video, .cam-wrap canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.cam-wrap canvas { z-index: 2; }

.live-badge {
  position: absolute; top: 10px; left: 10px; z-index: 5;
  display: flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,0.55); backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px; padding: 4px 10px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.08em; color: #fff;
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 8px var(--good);
  animation: pulse-dot 1.5s ease-in-out infinite;
}
@keyframes pulse-dot { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:0.6;transform:scale(0.8)} }

.pose-badge {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); z-index: 5;
  background: rgba(0,0,0,0.55); backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px; padding: 5px 14px;
  font-size: 12px; font-weight: 500; color: var(--text-2);
  white-space: nowrap;
}

/* Alert overlay */
.alert-overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  background: rgba(239,68,68,0.18);
  border: 2px solid var(--poor);
  border-radius: 12px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
.alert-overlay.show { opacity: 1; animation: alert-flash 0.8s ease-in-out infinite; }
@keyframes alert-flash { 0%,100%{background:rgba(239,68,68,0.18)} 50%{background:rgba(239,68,68,0.32)} }
.alert-icon { font-size: 40px; }
.alert-msg { font-size: 18px; font-weight: 700; color: #fff; }

/* Pause overlay */
.pause-overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  background: rgba(0,0,0,0.7);
  border-radius: 12px;
}
.pause-icon { font-size: 50px; }
.pause-msg { font-size: 18px; font-weight: 700; color: #fff; }

/* ========================================
   WELCOME SCREEN
   ======================================== */
#screen-welcome {
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.orb {
  position: absolute; border-radius: 50%;
  filter: blur(80px); opacity: 0.25; pointer-events: none;
}
.orb-1 { width: 500px; height: 500px; background: var(--primary); top: -150px; right: -100px; animation: orb-float 8s ease-in-out infinite; }
.orb-2 { width: 400px; height: 400px; background: #8b5cf6; bottom: -100px; left: -80px; animation: orb-float 10s ease-in-out infinite reverse; }
.orb-3 { width: 250px; height: 250px; background: #06b6d4; top: 40%; left: 30%; animation: orb-float 12s ease-in-out infinite 2s; }
@keyframes orb-float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-30px)} }

.welcome-content {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center;
  gap: 28px; max-width: 540px; text-align: center; padding: 32px;
}
.app-logo { display: flex; align-items: center; gap: 18px; }
.logo-icon { font-size: 56px; animation: logo-spin 20s linear infinite; }
@keyframes logo-spin { 0%{transform:rotate(0deg)} 100%{transform:rotate(360deg)} }
.app-logo h1 { font-size: 36px; font-weight: 800; background: linear-gradient(135deg, #fff 30%, #818cf8); -webkit-background-clip:text; -webkit-text-fill-color: transparent; }
.tagline { font-size: 14px; color: var(--text-2); font-weight: 500; }

.feature-chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  padding: 7px 16px; border-radius: 50px;
  background: rgba(99,102,241,0.12); border: 1px solid rgba(99,102,241,0.28);
  font-size: 13px; font-weight: 500; color: #a5b4fc;
}
.welcome-desc { font-size: 15px; line-height: 1.7; color: var(--text-2); }
.note { font-size: 12px; color: var(--text-3); }

/* ========================================
   CALIBRATION SCREEN
   ======================================== */
#screen-calibration {
  display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg);
}
.cal-layout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 32px;
  width: 100%; max-width: 1000px; align-items: center;
}
.step-badge {
  display: inline-block; padding: 5px 14px; border-radius: 50px;
  background: rgba(99,102,241,0.15); border: 1px solid rgba(99,102,241,0.3);
  font-size: 12px; font-weight: 600; color: var(--primary-h);
  margin-bottom: 16px;
}
.cal-left h2 { font-size: 28px; font-weight: 800; margin-bottom: 10px; }
.subtitle { font-size: 14px; color: var(--text-2); line-height: 1.65; margin-bottom: 24px; }

.instructions { display: flex; flex-direction: column; gap: 14px; margin-bottom: 28px; }
.instr-item {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 14px 16px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--border);
}
.instr-icon { font-size: 22px; flex-shrink: 0; }
.instr-item strong { font-size: 14px; font-weight: 600; }
.instr-item small { color: var(--text-2); font-size: 12px; }

.countdown-ring-wrap {
  position: relative; width: 90px; height: 90px; margin-bottom: 12px;
}
.countdown-ring { transform: rotate(-90deg); }
.cr-bg { fill: none; stroke: rgba(255,255,255,0.08); stroke-width: 8; }
.cr-fill {
  fill: none; stroke: var(--primary); stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 238.76;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear;
}
.countdown-num {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 800;
}
.count-label { font-size: 13px; color: var(--text-2); }

.cal-success {
  display: flex; align-items: center; gap: 14px;
  padding: 16px; border-radius: 12px;
  background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3);
}
.success-icon { font-size: 28px; }
.cal-success strong { font-size: 15px; font-weight: 600; color: var(--good); }
.cal-success p { font-size: 13px; color: var(--text-2); margin-top: 2px; }

.cal-right { display: flex; justify-content: center; }
#cal-cam-wrap { width: 100%; max-width: 420px; }

/* ========================================
   MONITORING SCREEN
   ======================================== */
#screen-monitoring {
  display: flex; flex-direction: column;
  background: var(--bg-2);
}

.mon-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px;
  background: rgba(8,8,16,0.8); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-l, .header-r { display: flex; align-items: center; gap: 14px; }
.logo-sm { font-size: 15px; font-weight: 700; }
.session-pill {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 12px; border-radius: 50px;
  background: var(--panel); border: 1px solid var(--border);
  font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.pulse-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--good); box-shadow: 0 0 6px var(--good);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 50px;
  border: 1px solid var(--border);
  font-size: 13px; font-weight: 600;
  background: var(--panel); transition: var(--transition);
}
.spill-dot { width: 8px; height: 8px; border-radius: 50%; transition: background 0.3s ease; }
.status-pill.good  { border-color: rgba(34,197,94,0.4);  background: rgba(34,197,94,0.08); }
.status-pill.fair  { border-color: rgba(245,158,11,0.4); background: rgba(245,158,11,0.08); }
.status-pill.poor  { border-color: rgba(239,68,68,0.4);  background: rgba(239,68,68,0.08); }
.status-pill.good  .spill-dot { background: var(--good); box-shadow: 0 0 6px var(--good); }
.status-pill.fair  .spill-dot { background: var(--fair); box-shadow: 0 0 6px var(--fair); }
.status-pill.poor  .spill-dot { background: var(--poor); box-shadow: 0 0 6px var(--poor); }

.mon-main {
  flex: 1; display: grid; grid-template-columns: 1fr 360px;
  gap: 16px; padding: 16px; overflow: hidden;
}

.mon-left { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.cam-panel { display: flex; flex-direction: column; gap: 12px; flex: 1; }
.cam-panel .cam-wrap { flex: 1; aspect-ratio: unset; min-height: 0; }

.metric-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.metric-chip {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 8px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--border);
  transition: border-color 0.3s, background 0.3s;
}
.metric-chip.good { border-color: rgba(34,197,94,0.35); background: rgba(34,197,94,0.07); }
.metric-chip.fair { border-color: rgba(245,158,11,0.35); background: rgba(245,158,11,0.07); }
.metric-chip.poor { border-color: rgba(239,68,68,0.35); background: rgba(239,68,68,0.07); }
.mc-label { font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.mc-val { font-size: 13px; font-weight: 700; }
.metric-chip.good .mc-val { color: var(--good); }
.metric-chip.fair .mc-val { color: var(--fair); }
.metric-chip.poor .mc-val { color: var(--poor); }

.mon-right { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }

/* Score gauge */
.score-panel { text-align: center; }
.gauge-wrap { position: relative; }
.gauge-svg { width: 100%; }
.gauge-bg-path { stroke: rgba(255,255,255,0.06); }
.gauge-fg-path {
  stroke: var(--good);
  stroke-dasharray: 251.33;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.6s ease, stroke 0.6s ease;
}
.gauge-center {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
}
.gauge-score { font-size: 42px; font-weight: 800; line-height: 1; }
.gauge-status { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); margin-top: 2px; }

#history-chart { width: 100%; border-radius: 8px; }
.history-panel .panel-title { margin-bottom: 10px; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  padding: 12px; border-radius: 10px;
  background: rgba(255,255,255,0.03); border: 1px solid var(--border);
  text-align: center;
}
.stat-val { font-size: 22px; font-weight: 800; color: var(--primary-h); }
.stat-lbl { font-size: 10px; font-weight: 500; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }

/* ========================================
   SETTINGS DRAWER
   ======================================== */
.settings-panel {
  position: fixed; inset: 0; z-index: 100;
  display: flex; justify-content: flex-end;
}
.settings-panel.hidden { pointer-events: none; }
.settings-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
  opacity: 0; transition: opacity 0.3s ease;
}
.settings-panel:not(.hidden) .settings-overlay { opacity: 1; }
.settings-drawer {
  position: relative; z-index: 1;
  width: 340px; height: 100%; overflow-y: auto;
  background: var(--bg-3); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform 0.35s cubic-bezier(0.4,0,0.2,1);
  display: flex; flex-direction: column;
}
.settings-panel:not(.hidden) .settings-drawer { transform: translateX(0); }
.settings-hdr {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 20px 16px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.settings-hdr h3 { font-size: 16px; font-weight: 700; }
.settings-body { flex: 1; padding: 16px 20px; display: flex; flex-direction: column; gap: 20px; }

.sg { display: flex; flex-direction: column; gap: 8px; }
.sg-label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 600; color: var(--text-2);
}
.sg-badge {
  font-size: 12px; font-weight: 500; color: var(--primary-h);
  background: rgba(99,102,241,0.12); border-radius: 20px; padding: 2px 8px;
}
.range-slider {
  -webkit-appearance: none; width: 100%; height: 5px;
  background: rgba(255,255,255,0.1); border-radius: 5px; outline: none;
}
.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--primary); cursor: pointer;
  box-shadow: 0 0 10px var(--primary-glow);
  transition: transform 0.15s;
}
.range-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.range-ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-3); }

.toggle-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--text-2); }
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.tog {
  position: absolute; inset: 0; cursor: pointer; border-radius: 24px;
  background: rgba(255,255,255,0.1); transition: 0.3s;
}
.tog::before {
  content: ''; position: absolute;
  width: 18px; height: 18px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: 0.3s;
}
.toggle input:checked + .tog { background: var(--primary); }
.toggle input:checked + .tog::before { transform: translateX(20px); }

.divider { border: none; border-top: 1px solid var(--border); margin: 0; }

.hidden { display: none !important; }
