/* ── TensionIQ Web App Styles ── */

:root {
  --bg: #0A0A0F;
  --surface: #12121A;
  --card: #1A1A24;
  --card-hi: #222230;
  --teal: #00E5CC;
  --teal-glow: rgba(0,229,204,0.13);
  --magenta: #FF2D7B;
  --text: #E8E8F0;
  --muted: #7A7A8E;
  --dim: #1E1E2A;
  --dim2: #2A2A38;
  --border: rgba(0,229,204,0.16);
  --border-hi: rgba(0,229,204,0.36);
  --red: #EF4444;
  --green: #4ADE80;
  --yellow: #FACC15;
  --orange: #F97316;
  --radius: 10px;
  --nav-height: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--teal); text-decoration: none; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 18px; border: none; border-radius: 8px;
  font-size: 14px; cursor: pointer; font-weight: 600;
  transition: opacity .15s; font-family: inherit;
}
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { background: var(--teal); color: var(--bg); }
.btn-danger { background: var(--red); color: #fff; }
.btn-warn { background: var(--yellow); color: var(--bg); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 14px 24px; font-size: 16px; }
.btn-block { width: 100%; justify-content: center; }

/* ── App Header ── */
#appHeader {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
#appHeader img { height: 70px; width: auto; }
#appHeader h1 { font-size: 17px; color: var(--teal); font-weight: 700; }
#appHeader .header-right { margin-left: auto; }
#appHeader .header-right button {
  background: none; border: none; color: var(--muted);
  font-size: 20px; cursor: pointer; padding: 4px 8px;
}

/* ── Bottom Nav ── */
#bottomNav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  cursor: pointer; color: var(--muted);
  font-size: 10px; font-weight: 500;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-item .nav-icon { font-size: 20px; line-height: 1; }
.nav-item.active { color: var(--teal); }
.nav-item:hover { color: var(--text); }

/* ── Main Container ── */
#pageContainer {
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + 12px)!important;
  max-width: 480px;
  margin: 0 auto;
  min-height: calc(100vh - 52px - var(--nav-height));
}

.page-loading {
  text-align: center; padding: 48px 16px;
  color: var(--muted); font-size: 14px;
}

/* ── Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.card-label {
  font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px;
  font-weight: 600; margin-bottom: 8px;
}

/* ── Forms ── */
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.form-group label {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px;
}
.form-group input, .form-group select, .form-group textarea {
  padding: 10px 12px; background: var(--dim);
  border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 14px; outline: none;
  font-family: inherit;
}
.form-group input:focus, .form-group select:focus { border-color: var(--teal); }

/* ── Toast ── */
.toast {
  position: fixed; bottom: calc(var(--nav-height) + 16px); left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px; border-radius: 8px;
  font-size: 14px; font-weight: 500; z-index: 999;
  animation: slideUp .25s ease;
  white-space: nowrap;
}
.toast-success { background: var(--green); color: var(--bg); }
.toast-error { background: var(--red); color: #fff; }
@keyframes slideUp {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ── Badges ── */
.badge {
  display: inline-block; padding: 2px 8px;
  border-radius: 10px; font-size: 11px; font-weight: 600;
}
.badge-primary { background: var(--teal-glow); color: var(--teal); }
.badge-muted { background: var(--dim2); color: var(--muted); }

/* ── Empty State ── */
.empty { text-align: center; padding: 32px; color: var(--muted); }
.empty-sm { text-align: center; padding: 16px; color: var(--muted); font-size: 13px; }

/* ── Alert ── */
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; margin-bottom: 12px;
  cursor: pointer;
}
.alert-warn {
  background: rgba(250,204,21,0.12); color: var(--yellow);
  border: 1px solid rgba(250,204,21,0.25);
}

/* ══════════════════════════════════════════
   AUTH PAGE
   ══════════════════════════════════════════ */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
  position: fixed; inset: 0;
  background: var(--bg);
}
.auth-card {
  width: 100%; max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
}
.auth-logo {
  text-align: center; margin-bottom: 24px;
}
.auth-logo img { height: 48px; margin-bottom: 8px; }
.auth-logo h1 { font-size: 22px; color: var(--teal); }
.auth-toggle {
  display: flex; margin-bottom: 20px;
  border-radius: 6px; overflow: hidden;
  border: 1px solid var(--border);
}
.auth-toggle-btn {
  flex: 1; padding: 8px; text-align: center;
  font-size: 13px; font-weight: 600;
  cursor: pointer; background: var(--dim);
  color: var(--muted); border: none;
  transition: all .15s; font-family: inherit;
}
.auth-toggle-btn.active {
  background: var(--teal); color: var(--bg);
}
.auth-form .form-group { margin-bottom: 14px; }
.auth-form .btn { margin-top: 8px; }
.auth-error {
  color: var(--red); font-size: 13px;
  padding: 8px 12px; background: rgba(239,68,68,0.1);
  border-radius: 6px; margin-bottom: 8px;
}
.auth-forgot {
  text-align: center; margin-top: 16px;
}
.auth-forgot a {
  color: var(--muted); font-size: 13px;
  text-decoration: none; transition: color .15s;
}
.auth-forgot a:hover { color: var(--teal); }

/* ══════════════════════════════════════════
   DASHBOARD
   ══════════════════════════════════════════ */
.greeting {
  font-size: 22px; margin-bottom: 16px; font-weight: 700;
}
.tension-card { text-align: center; }
.tension-score-row {
  display: flex; align-items: center; justify-content: center; gap: 12px;
}
.tension-sub { color: var(--muted); font-size: 13px; }

.stats-row {
  display: flex; gap: 8px; margin-bottom: 12px;
}
.stats-row.compact { gap: 6px; margin-bottom: 0; }
.stat-card {
  flex: 1; text-align: center;
  background: var(--dim); border-radius: 8px; padding: 12px 8px;
}
.stat-value { font-size: 20px; font-weight: 700; }
.stat-label { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── Charts ── */
.chart-legend {
  display: flex; justify-content: center; gap: 16px;
  margin-top: 8px;
}
.chart-legend-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted);
}
.chart-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
}

/* ── Tension Areas ── */
.tension-area-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.tension-area-row:last-child { border-bottom: none; }
.tension-area-left {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; min-width: 0;
}
.tension-area-thumb {
  width: 32px; height: 32px; border-radius: 6px;
  object-fit: cover; background: var(--dim); flex-shrink: 0;
}
.tension-thumb-vp {
  position: relative; overflow: hidden;
  border-radius: 6px; background: #080810; flex-shrink: 0;
}
.tension-thumb-vp img {
  position: absolute; display: block;
}
.tension-area-right {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.tension-bar-track {
  width: 60px; height: 6px; border-radius: 3px;
  background: var(--dim2);
}
.tension-bar-fill {
  height: 100%; border-radius: 3px;
  transition: width .3s ease;
}

.dash-exercises-toggle {
  text-align: center; font-size: 13px; color: var(--muted);
  cursor: pointer; padding: 8px 0 4px;
  transition: color .15s;
}
.dash-exercises-toggle:hover { color: var(--teal); }

.exercise-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.exercise-row:last-child { border-bottom: none; }
.exercise-info { display: flex; flex-direction: column; gap: 2px; }
.exercise-name { font-size: 14px; font-weight: 500; }
.exercise-detail { font-size: 12px; color: var(--muted); }
.exercise-video-icon { color: var(--teal); font-size: 16px; }

/* ── Milestone Badges ── */
.milestone-row {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 12px;
}
.milestone-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 12px; border-radius: 16px;
  font-size: 12px; font-weight: 600;
  background: linear-gradient(135deg, rgba(0,229,204,0.15), rgba(250,204,21,0.15));
  color: var(--teal);
  border: 1px solid rgba(0,229,204,0.2);
}

/* ── Welcome Card (First-Run) ── */
.welcome-card {
  padding: 24px 20px;
}
.welcome-steps {
  display: flex; flex-direction: column; gap: 16px;
}
.welcome-step {
  display: flex; align-items: flex-start; gap: 12px;
}
.welcome-step-num {
  flex-shrink: 0; width: 28px; height: 28px;
  border-radius: 50%; background: var(--teal);
  color: var(--bg); font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}

/* ── Recent Sessions ── */
.recent-session-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  font-size: 13px; gap: 8px;
}
.recent-session-row:last-child { border-bottom: none; }
.recent-session-date { color: var(--muted); min-width: 60px; }
.recent-session-pain { white-space: nowrap; }
.recent-session-pct { font-weight: 600; min-width: 40px; text-align: right; }
.recent-session-pct.improved { color: var(--green); }
.recent-session-dur { color: var(--muted); min-width: 30px; text-align: right; }

/* ══════════════════════════════════════════
   ASSESSMENT
   ══════════════════════════════════════════ */
.progress-bar-container {
  height: 4px; background: var(--dim);
  border-radius: 2px; margin-bottom: 16px; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; background: var(--teal);
  border-radius: 2px; transition: width .3s ease;
}
.assess-step-info {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.assess-step-count { font-size: 13px; color: var(--muted); }
.zone-viewport {
  position: relative; overflow: hidden;
  border-radius: 14px; background: #080810;
  margin-bottom: 12px;
}
.zone-viewport-img {
  position: absolute; display: block;
  transition: left 0.5s cubic-bezier(0.4, 0, 0.2, 1),
              top 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.assess-card { text-align: center; padding: 24px 16px; }
.assess-bp-name { font-size: 20px; color: var(--teal); margin-bottom: 20px; }
.assess-nav {
  display: flex; gap: 12px; margin-top: 16px;
}
.assess-nav .btn { flex: 1; justify-content: center; }

.review-list { margin-bottom: 12px; }
.review-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 6px;
  font-size: 14px;
}
.review-row-left {
  display: flex; align-items: center; gap: 10px;
}
.review-zone-thumb {
  width: 36px; height: 36px;
  border-radius: 6px; object-fit: cover;
  background: var(--dim);
}

/* ── Slider ── */
.slider-group { padding: 4px 0; }
.slider-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.slider-label { font-size: 13px; color: var(--muted); }
.slider-value { font-size: 24px; font-weight: 700; }

.tiq-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px;
  border-radius: 3px; outline: none;
  background: linear-gradient(to right, var(--slider-color) 0%, var(--slider-color) var(--slider-pct), var(--dim2) var(--slider-pct), var(--dim2) 100%);
}
.tiq-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--slider-color);
  cursor: pointer; border: 3px solid var(--bg);
  box-shadow: 0 0 8px rgba(0,0,0,0.4);
}
.tiq-slider::-moz-range-thumb {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--slider-color);
  cursor: pointer; border: 3px solid var(--bg);
  box-shadow: 0 0 8px rgba(0,0,0,0.4);
}

/* ══════════════════════════════════════════
   ROUTINES
   ══════════════════════════════════════════ */
.page-title-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.page-title-row h2 { font-size: 20px; }

.day-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}
.day-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; cursor: pointer;
  transition: background .15s;
}
.day-card-header:hover { background: var(--card-hi); }
.day-card-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.day-card-count { font-size: 12px; color: var(--muted); }
.day-card-body {
  max-height: 0; overflow: hidden;
  transition: max-height .3s ease;
  padding: 0 16px;
}
.day-card.expanded .day-card-body {
  max-height: 600px;
  padding: 0 16px 12px;
}

/* ── Routine Edit/Delete Actions ── */
.exercise-actions {
  display: flex; align-items: center; gap: 4px; flex-shrink: 0;
}
.exercise-actions .btn-sm {
  padding: 4px 8px; font-size: 14px; min-width: 28px;
  justify-content: center;
}

/* ── Edit Modal Overlay ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-card {
  width: 100%; max-width: 360px;
}

/* ══════════════════════════════════════════
   SESSION
   ══════════════════════════════════════════ */
.duration-btns {
  display: flex; gap: 8px;
}
.duration-btns .btn { flex: 1; justify-content: center; }

.exercise-check {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  cursor: pointer; font-size: 14px;
}
.exercise-check:last-child { border-bottom: none; }
.exercise-check input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--teal);
}

/* Active session */
.session-active { text-align: center; }
.session-progress-info {
  font-size: 14px; color: var(--muted); margin-bottom: 16px;
}

.timer-container {
  position: relative; width: 180px; height: 180px;
  margin: 0 auto 20px;
}
.timer-svg { width: 100%; height: 100%; }
.timer-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; font-weight: 700; color: var(--text);
}

.session-exercise-card { text-align: center; }
.session-exercise-card .exercise-name { font-size: 18px; font-weight: 600; }
.session-exercise-card .exercise-detail { font-size: 14px; color: var(--muted); margin-top: 4px; }
.session-video { margin-top: 12px; border-radius: 10px; overflow: hidden; }
.session-video-player {
  width: 100%; display: block;
  border-radius: 10px; max-height: 220px;
  object-fit: contain; background: #000;
}

.session-controls {
  display: flex; gap: 8px; margin-top: 16px; justify-content: center;
}

/* Summary */
.summary-row {
  display: flex; align-items: center; justify-content: center;
  gap: 16px; margin-bottom: 20px;
}
.summary-item { text-align: center; }
.summary-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.summary-arrow { font-size: 24px; color: var(--muted); }
.summary-stats { display: flex; gap: 8px; }

/* ══════════════════════════════════════════
   PROGRESS
   ══════════════════════════════════════════ */
.sub-tabs {
  display: flex; gap: 0; margin-bottom: 16px;
  border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border);
}
.sub-tab {
  flex: 1; padding: 8px 12px; text-align: center;
  font-size: 13px; font-weight: 600; cursor: pointer;
  background: var(--dim); color: var(--muted);
  border: none; transition: all .15s; font-family: inherit;
}
.sub-tab.active { background: var(--teal); color: var(--bg); }

.report-card .card-header { margin-bottom: 8px; }

/* ── Heat Map ── */
.heatmap-container {
  margin-bottom: 12px;
}
.heatmap-body {
  position: relative; border-radius: var(--radius);
  overflow: hidden; background: #080810;
}
.heatmap-img {
  width: 100%; display: block; opacity: 0.7;
}
.heatmap-dot {
  position: absolute; border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(0,0,0,0.4);
  cursor: pointer; z-index: 2;
  transition: transform .15s;
}
.heatmap-dot:hover { transform: translate(-50%, -50%) scale(1.3); }
.heatmap-dot.pulse { animation: dotPulse 2s ease-in-out infinite; }
@keyframes dotPulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  50% { transform: translate(-50%, -50%) scale(1.25); opacity: 0.8; }
}
.heatmap-legend {
  display: flex; justify-content: center; gap: 16px;
  padding: 8px 0 4px; font-size: 12px;
}
.heatmap-detail { margin-bottom: 8px; }

/* ── Sparklines ── */
.sparkline-wrap {
  height: 30px; margin-top: 8px;
}
.sparkline { display: block; }

.trend-card { margin-bottom: 6px; padding: 12px 16px; }
.trend-row {
  display: flex; align-items: center; justify-content: space-between;
}
.trend-name { font-size: 14px; }
.trend-score { display: flex; align-items: center; gap: 8px; }
.trend-change { font-size: 12px; font-weight: 600; }
.trend-change.improved { color: var(--green); }
.trend-change.worsened { color: var(--red); }

.history-card { margin-bottom: 6px; padding: 12px 16px; }
.history-row {
  display: flex; align-items: center; justify-content: space-between;
}
.history-date { font-size: 13px; color: var(--muted); margin-left: 8px; }

/* ── Comparison Panel (Progress History) ── */
.compare-content {
  padding: 12px 0 4px;
}
.compare-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0 12px; font-size: 14px; font-weight: 600;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.compare-arrow {
  color: var(--muted); font-size: 14px;
}
.compare-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.compare-row:last-child { border-bottom: none; }
.compare-bp-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compare-scores {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
}

/* ══════════════════════════════════════════
   SETTINGS
   ══════════════════════════════════════════ */
.settings-field {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.settings-field:last-child { border-bottom: none; }
.settings-label { font-size: 13px; color: var(--muted); }
.settings-value { font-size: 14px; }

/* ══════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════ */
@media (min-width: 600px) {
  #pageContainer { padding: 24px; }
  .auth-page { padding: 40px; }
}
