/* ══════════════════════════════════════════
   GYMTRACKER — Modern Clean Theme
   White · Mint Green · Rounded Cards
   ══════════════════════════════════════════ */

:root {
  /* ── Base colors ─────────────────────── */
  --bg:          #F4F6F8;
  --surface:     #FFFFFF;
  --surface-2:   #F0F2F5;
  --surface-3:   #E8EBF0;

  /* ── Green palette ───────────────────── */
  --green:       #22C55E;
  --green-dk:    #16A34A;
  --green-lt:    #DCFCE7;
  --green-mid:   #4ADE80;
  --green-muted: #86EFAC;
  --green-bg:    #F0FDF4;

  /* ── Borders & shadows ───────────────── */
  --border:      #E5E7EB;
  --border-soft: #F3F4F6;
  --shadow-xs:   0 1px 3px rgba(0,0,0,.06);
  --shadow:      0 2px 12px rgba(0,0,0,.07), 0 1px 3px rgba(0,0,0,.04);
  --shadow-md:   0 4px 24px rgba(0,0,0,.10), 0 2px 6px rgba(0,0,0,.05);
  --shadow-lg:   0 8px 40px rgba(0,0,0,.13);
  --shadow-green: 0 4px 20px rgba(34,197,94,.30);

  /* ── Text ────────────────────────────── */
  --text:        #111827;
  --text-2:      #6B7280;
  --text-3:      #9CA3AF;

  /* ── Other accents ───────────────────── */
  --danger:      #EF4444;
  --yellow:      #F59E0B;
  --amber:       #FBBF24;
  --purple:      #8B5CF6;
  --blue:        #3B82F6;

  /* ── Shapes ──────────────────────────── */
  --r:           18px;
  --r-sm:        12px;
  --r-xs:        8px;
  --r-pill:      999px;

  /* ── Gradient ────────────────────────── */
  --gradient:    linear-gradient(135deg, #16A34A 0%, #22C55E 60%, #4ADE80 100%);
  --gradient-soft: linear-gradient(135deg, #F0FDF4 0%, #DCFCE7 100%);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 15px;
  overflow-x: hidden; /* iOS Safari: body overflow alone doesn't block horizontal scroll */
  max-width: 100vw;
  overscroll-behavior-x: none; /* prevent horizontal rubber-band scroll on iOS */
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  max-width: 100vw;
  overscroll-behavior-x: none;
}

/* ══════════════════════════════════════════
   LAYOUT
══════════════════════════════════════════ */
.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: 64px 1fr;
  height: 100dvh;
}

/* ══════════════════════════════════════════
   HEADER
══════════════════════════════════════════ */
header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(0,0,0,.04);
  z-index: 20;
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -.4px;
  color: var(--text);
}

.logo svg { width: 32px; height: 18px; flex-shrink: 0; }

.logo-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1;
}

.logo-accent { color: var(--green-dk); }

.brand-tagline {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-3);
  letter-spacing: .3px;
}

/* ── Session pill ────────────────────────── */
.session-pill {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-pill);
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  transition: all .25s;
}

.session-pill.active {
  background: var(--green-bg);
  border-color: var(--green-muted);
  color: var(--green-dk);
  box-shadow: 0 2px 10px rgba(34,197,94,.18);
}

.pulse-ring {
  position: relative;
  width: 10px; height: 10px;
}
.pulse-ring::before,
.pulse-ring::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--border);
}
.session-pill.active .pulse-ring::before { background: var(--green); }
.session-pill.active .pulse-ring::after {
  background: transparent;
  border: 2px solid var(--green);
  animation: ring 1.8s ease-out infinite;
  opacity: 0;
}

@keyframes ring {
  0%   { transform: scale(1); opacity: .8; }
  100% { transform: scale(3); opacity: 0; }
}

.session-timer {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--green-dk);
  display: none;
}
.session-pill.active .session-timer { display: inline; }

/* ── Header gamify pill ───────────────────── */
.header-gamify {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 700;
  margin-left: 12px;
  flex-shrink: 0;
}
.hg-streak { color: #F97316; }
.hg-sep    { color: var(--text-3); font-weight: 400; }
.hg-level  { color: var(--green-dk); }

/* ══════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════ */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── Section labels ──────────────────────── */
.section-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
}
.sl-icon { font-size: 12px; }

/* ══════════════════════════════════════════
   AVATAR BAR — always visible in chat panel
══════════════════════════════════════════ */
.chat-avatar-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  transition: border-color .3s;
}

/* Ring wrap inside the bar */
.cab-ring-wrap {
  position: relative;
  width: 72px; height: 72px;
  flex-shrink: 0;
  animation: avatarBreath 4s ease-in-out infinite;
}

.cab-ring-svg {
  width: 72px; height: 72px;
  position: absolute; inset: 0;
}

/* Face inside the bar ring */
.chat-avatar-bar .avatar-face-wrap {
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  overflow: hidden;
}

.chat-avatar-bar .avatar-face-wrap svg { width: 100%; height: 100%; }
.chat-avatar-bar .avatar-face-img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
  transition: filter 0.8s ease;
}

/* Info column */
.cab-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.cab-status {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  transition: color .4s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cab-bar-track {
  height: 6px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}

.cab-bar-fill {
  height: 100%;
  background: var(--gradient);
  border-radius: 99px;
  transition: width 1.2s cubic-bezier(.4,0,.2,1), background .6s ease;
  min-width: 4px;
}

.cab-pct {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  transition: color .5s;
}

/* State classes on the bar */
.chat-avatar-bar.state-exhausted .cab-ring-wrap {
  animation: exhaustedShake 2.5s ease-in-out infinite;
}
.chat-avatar-bar.state-dead .cab-ring-wrap {
  animation: none;
}

/* Legacy - unused now but kept */
.avatar-ring-wrap {
  position: relative;
  width: 72px; height: 72px;
  flex-shrink: 0;
}
.avatar-ring-svg { width: 72px; height: 72px; position: absolute; inset: 0; }

/* Generic avatar-face-wrap (used inside cab-ring-wrap) */
.avatar-face-wrap {
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  overflow: hidden;
}

@keyframes avatarBreath {
  0%,100% { transform: scale(1); }
  50%      { transform: scale(1.04); }
}

/* Per-user avatar photo — CSS filter transitions based on energy */
.avatar-face-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
  transition: filter 0.8s ease;
}

.avatar-pct {
  position: absolute;
  bottom: -6px; left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-pill);
  padding: 3px 12px;
  font-size: 13px;
  font-weight: 800;
  color: var(--green-dk);
  white-space: nowrap;
  transition: color .5s;
  box-shadow: var(--shadow-xs);
}

.avatar-status {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-2);
  text-align: center;
  transition: all .4s;
  line-height: 1.3;
  margin-top: 4px;
}

/* sweat animation on tired face */
@keyframes sweatDrop {
  0%   { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(8px); opacity: 0; }
}

/* shake on exhausted */
@keyframes exhaustedShake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-2px); }
  40%     { transform: translateX(2px); }
  60%     { transform: translateX(-2px); }
  80%     { transform: translateX(2px); }
}

.avatar-card.state-exhausted .avatar-face-wrap {
  animation: exhaustedShake 2.5s ease-in-out infinite;
}
.avatar-card.state-dead .avatar-face-wrap {
  animation: none;
}

/* ══════════════════════════════════════════
   AVATAR CARD (sidebar)
══════════════════════════════════════════ */
.avatar-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  padding: 20px 14px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-xs);
  transition: border-color .3s;
  animation: avatarBreath 4s ease-in-out infinite;
}

/* Override ring size to 110px in the sidebar card */
.avatar-card .avatar-ring-wrap {
  width: 110px;
  height: 110px;
}

.avatar-card .avatar-ring-svg {
  width: 110px;
  height: 110px;
}

/* For 110px display of 110-viewBox SVG: inner edge ≈ 13px from border */
.avatar-card .avatar-face-wrap {
  inset: 13px;
}

/* ══════════════════════════════════════════
   STAT CARDS
══════════════════════════════════════════ */
.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  padding: 16px 14px;
  position: relative;
  overflow: hidden;
  transition: border-color .2s, box-shadow .2s, transform .15s;
  box-shadow: var(--shadow-xs);
}

.stat-card.has-data {
  border-color: var(--green-muted);
  background: var(--green-bg);
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.stat-icon { font-size: 20px; margin-bottom: 6px; }
.stat-value {
  font-size: 28px;
  font-weight: 900;
  color: var(--green-dk);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ══════════════════════════════════════════
   XP CARD
══════════════════════════════════════════ */
.xp-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  box-shadow: var(--shadow-xs);
}

.xp-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.xp-level-name { font-size: 14px; font-weight: 800; color: var(--text); }
.xp-pts        { font-size: 13px; font-weight: 700; color: var(--green-dk); }

.xp-bar-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 6px;
}
.xp-bar-fill {
  height: 100%;
  background: var(--gradient);
  border-radius: 99px;
  transition: width .6s cubic-bezier(.34,1.56,.64,1);
  min-width: 4px;
}

.xp-bottom { font-size: 11px; color: var(--text-3); font-weight: 500; }

/* ══════════════════════════════════════════
   EXERCISE LIST
══════════════════════════════════════════ */
.exercise-list { display: flex; flex-direction: column; gap: 8px; }

.exercise-item {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 11px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all .2s;
  box-shadow: var(--shadow-xs);
}

.exercise-item:hover {
  border-color: var(--green-muted);
  background: var(--green-bg);
  transform: translateX(3px);
}

.ex-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--green-lt);
  border: 1px solid var(--green-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}

.ex-info { flex: 1; min-width: 0; }
.ex-name {
  font-size: 13px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
.ex-detail { font-size: 11px; color: var(--text-3); margin-top: 2px; font-weight: 500; }

.ex-max {
  font-size: 15px;
  font-weight: 900;
  color: var(--green-dk);
  white-space: nowrap;
  letter-spacing: -.3px;
}

/* ══════════════════════════════════════════
   VOLUME CHART
══════════════════════════════════════════ */
.chart-wrap {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  padding: 14px;
  box-shadow: var(--shadow-xs);
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 72px;
}

.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }

.bar {
  width: 100%;
  background: var(--gradient);
  border-radius: 6px 6px 0 0;
  min-height: 4px;
  transition: height .6s cubic-bezier(.34,1.56,.64,1);
  position: relative;
  cursor: pointer;
  opacity: .75;
}

.bar:hover { opacity: 1; }

.bar::after {
  content: attr(data-vol);
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%; transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 3px 7px;
  border-radius: 6px;
  font-size: 9px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}
.bar:hover::after { opacity: 1; }
.bar-label { font-size: 9px; color: var(--text-3); text-align: center; font-weight: 600; }

/* ══════════════════════════════════════════
   WEEKLY CHALLENGE
══════════════════════════════════════════ */
.weekly-challenge {
  background: var(--green-bg);
  border: 1.5px solid var(--green-muted);
  border-radius: var(--r);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.wc-icon { font-size: 26px; flex-shrink: 0; }
.wc-text { font-size: 13px; font-weight: 600; color: var(--green-dk); line-height: 1.45; }

/* ══════════════════════════════════════════
   HISTORY
══════════════════════════════════════════ */
.history-list { display: flex; flex-direction: column; gap: 8px; }

.history-item {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 36px 12px 14px;
  cursor: pointer;
  transition: all .2s;
  position: relative;
  box-shadow: var(--shadow-xs);
}

.history-item:hover {
  border-color: var(--green-muted);
  background: var(--green-bg);
  transform: translateX(3px);
  box-shadow: var(--shadow);
}

.hi-header { display: flex; justify-content: space-between; align-items: center; }
.hi-date { font-size: 13px; font-weight: 800; color: var(--green-dk); }
.hi-vol  { font-size: 12px; font-weight: 700; color: var(--text-2); }
.hi-meta { font-size: 11px; color: var(--text-3); margin-top: 3px; font-weight: 500; }

.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.tag {
  background: var(--green-lt);
  border: 1px solid var(--green-muted);
  border-radius: var(--r-pill);
  padding: 2px 9px;
  font-size: 10px;
  color: var(--green-dk);
  font-weight: 700;
}

.hi-arrow {
  position: absolute; right: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--green); font-size: 18px; font-weight: 400;
  transition: transform .2s;
}
.history-item:hover .hi-arrow { transform: translateY(-50%) translateX(3px); }

/* ══════════════════════════════════════════
   BADGES
══════════════════════════════════════════ */
.badges-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.badge-item {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 8px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  transition: all .25s;
  box-shadow: var(--shadow-xs);
}

.badge-item.earned {
  border-color: var(--green-muted);
  background: var(--green-bg);
  box-shadow: 0 3px 14px rgba(34,197,94,.15);
}
.badge-item.earned:hover { transform: translateY(-3px); box-shadow: var(--shadow-green); }
.badge-item:not(.earned) { opacity: .32; filter: grayscale(1); }

.badge-emoji { font-size: 24px; line-height: 1; }
.badge-name {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-2);
  text-align: center;
  line-height: 1.2;
}
.badge-item.earned .badge-name { color: var(--green-dk); }

/* ══════════════════════════════════════════
   EMPTY STATE
══════════════════════════════════════════ */
.empty {
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; padding: 20px 12px;
  color: var(--text-3); font-size: 12px; text-align: center;
}
.empty .e-icon { font-size: 28px; opacity: .5; }

/* ══════════════════════════════════════════
   CHAT PANEL
══════════════════════════════════════════ */
.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

.chat-panel.hidden { display: none; }

/* ── Messages ────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── Welcome screen ──────────────────────── */
.welcome {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  flex: 1; gap: 14px; padding: 40px 20px; text-align: center;
}

.welcome-icon {
  width: 88px; height: 56px;
  border-radius: 20px;
  background: var(--green-lt);
  border: 2px solid var(--green-muted);
  display: flex; align-items: center; justify-content: center;
  animation: float 3s ease-in-out infinite;
  box-shadow: var(--shadow-green);
  padding: 12px;
}

@keyframes float {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}

.welcome h2 {
  font-size: 24px; font-weight: 900;
  color: var(--text);
  letter-spacing: -.5px;
}
.welcome p { font-size: 14px; color: var(--text-2); line-height: 1.6; max-width: 340px; }

/* ── Welcome tips card ───────────────────── */
.welcome-tips {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  box-shadow: var(--shadow-xs);
  text-align: left;
}

.tip-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.tip-icon {
  font-size: 20px;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
  margin-top: 1px;
}

.tip-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.tip-desc {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
  font-weight: 500;
  line-height: 1.4;
}

.quick-chips {
  display: flex; flex-direction: column; gap: 8px;
  width: 100%; max-width: 380px; margin-top: 4px;
}

.chip {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-pill);
  padding: 11px 18px;
  font-size: 13px; font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  transition: all .2s;
  display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-xs);
  text-align: left;
}
.chip:hover {
  border-color: var(--green);
  background: var(--green-bg);
  color: var(--green-dk);
  transform: translateX(4px);
  box-shadow: var(--shadow);
}
.chip-icon { font-size: 16px; flex-shrink: 0; }

/* ── Messages ─────────────────────────────── */
.msg {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  animation: msgIn .25s ease-out;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
}

.msg.bot .msg-avatar  { background: var(--green-lt); border-color: var(--green-muted); }
.msg.user .msg-avatar { background: var(--green-dk); }

.bubble-wrap { display: flex; flex-direction: column; gap: 4px; max-width: 75%; }
.msg.user .bubble-wrap { align-items: flex-end; }

.bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
}

.msg.bot  .bubble {
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-xs);
}

.msg.user .bubble {
  background: var(--gradient);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: var(--shadow-green);
}

.bubble-time {
  font-size: 10px;
  color: var(--text-3);
  padding: 0 4px;
}

/* ── Typing indicator ────────────────────── */
.typing-indicator { display: flex; align-items: center; gap: 5px; padding: 14px 16px; }
.typing-indicator span {
  width: 8px; height: 8px;
  background: var(--green);
  border-radius: 50%;
  animation: typeDot .9s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .15s; }
.typing-indicator span:nth-child(3) { animation-delay: .30s; }

@keyframes typeDot {
  0%,60%,100% { transform: translateY(0); opacity: .4; }
  30%          { transform: translateY(-8px); opacity: 1; }
}

/* ── Quick bar ────────────────────────────── */
.quick-bar {
  display: flex;
  gap: 8px;
  padding: 10px 20px;
  overflow-x: auto;
  scrollbar-width: none;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.quick-bar::-webkit-scrollbar { display: none; }

.qbtn {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-pill);
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  white-space: nowrap;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}
.qbtn:hover {
  background: var(--green-bg);
  border-color: var(--green);
  color: var(--green-dk);
}

/* ── Input area ───────────────────────────── */
.input-area {
  padding: 12px 20px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-pill);
  padding: 8px 8px 8px 12px;
  transition: border-color .2s, box-shadow .2s;
}
.input-row:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34,197,94,.12);
  background: var(--surface);
}

.input-box {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  resize: none;
  max-height: 120px;
  min-height: 24px;
  line-height: 1.5;
  padding: 4px 0;
}
.input-box::placeholder { color: var(--text-3); }

.btn-round {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all .2s;
  font-family: inherit;
}

.btn-mic {
  background: var(--surface-3);
  color: var(--text-3);
}
.btn-mic:hover { background: var(--surface-2); color: var(--text-2); }
.btn-mic.listening {
  background: rgba(239,68,68,.12);
  color: var(--danger);
  animation: micPulse 1.2s ease-in-out infinite;
}

@keyframes micPulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.3); }
  50%      { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

.btn-send {
  background: var(--gradient);
  color: white;
  box-shadow: var(--shadow-green);
}
.btn-send:hover:not(:disabled) { transform: scale(1.08); box-shadow: 0 6px 24px rgba(34,197,94,.4); }
.btn-send:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }

.input-hint {
  font-size: 10px;
  color: var(--text-3);
  text-align: center;
  margin-top: 8px;
}

/* ── Toast ────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: var(--text);
  color: white;
  padding: 10px 20px;
  border-radius: var(--r-pill);
  font-size: 13px; font-weight: 600;
  z-index: 900;
  transition: transform .35s cubic-bezier(.34,1.56,.64,1), opacity .35s;
  opacity: 0;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ══════════════════════════════════════════
   BOTTOM NAV (mobile)
══════════════════════════════════════════ */
.bottom-nav {
  display: none;
  grid-column: 1 / -1;
}

/* ══════════════════════════════════════════
   GAMIFICATION — XP Float, Level Up, Badge
══════════════════════════════════════════ */
.xp-float {
  position: fixed;
  font-size: 14px;
  font-weight: 900;
  color: var(--green-dk);
  background: var(--green-lt);
  border: 1.5px solid var(--green-muted);
  border-radius: var(--r-pill);
  padding: 4px 12px;
  z-index: 700;
  pointer-events: none;
  animation: xpFloat 2s ease-out forwards;
}

@keyframes xpFloat {
  0%   { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-60px); }
}

.badge-unlock-toast {
  position: fixed;
  top: 76px; right: 16px;
  background: var(--surface);
  border: 2px solid var(--green-muted);
  border-radius: var(--r);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow-md);
  z-index: 800;
  animation: slideInRight .4s cubic-bezier(.34,1.56,.64,1) forwards,
             fadeOut .5s ease-in 3.7s forwards;
  max-width: 280px;
}

@keyframes slideInRight {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
  to { opacity: 0; transform: translateX(120%); }
}

.bu-emoji { font-size: 28px; flex-shrink: 0; }
.bu-title { font-size: 10px; font-weight: 700; color: var(--green-dk); text-transform: uppercase; letter-spacing: .8px; }
.bu-name  { font-size: 14px; font-weight: 800; color: var(--text); margin-top: 2px; }
.bu-desc  { font-size: 11px; color: var(--text-2); margin-top: 2px; }

.level-up-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 850;
  animation: fadeInBg .3s ease-out;
}

@keyframes fadeInBg {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.level-up-card {
  background: var(--surface);
  border: 3px solid var(--green);
  border-radius: var(--r);
  padding: 36px 48px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: popIn .4s cubic-bezier(.34,1.56,.64,1);
}

@keyframes popIn {
  from { transform: scale(.6); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.lu-icon  { font-size: 48px; margin-bottom: 10px; }
.lu-title { font-size: 13px; font-weight: 700; color: var(--text-2); letter-spacing: 1px; text-transform: uppercase; }
.lu-name  { font-size: 24px; font-weight: 900; color: var(--green-dk); margin-top: 6px; }

/* ── Exercise feedback chips ─────────────── */
.ex-feedback {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.fb-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 700;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: default;
}
.fb-chip.pr  { border-color: rgba(245,158,11,.5); color: #D97706; background: rgba(245,158,11,.08); }
.fb-chip.orm { border-color: var(--green-muted);  color: var(--green-dk); background: var(--green-bg); }
.fb-chip.sug { border-color: rgba(139,92,246,.4); color: var(--purple); background: rgba(139,92,246,.06); }

/* ══════════════════════════════════════════
   REST TIMER WIDGET
══════════════════════════════════════════ */
.rest-timer-widget {
  position: fixed;
  bottom: 96px; right: 16px;
  background: var(--text);
  border-radius: var(--r);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 600;
  box-shadow: var(--shadow-lg);
  min-width: 100px;
  animation: slideUp .3s cubic-bezier(.34,1.56,.64,1);
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.rt-ring {
  position: relative;
  width: 70px; height: 70px;
}
.rt-ring svg { width: 70px; height: 70px; }
.rt-time {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 900;
  color: white;
  font-variant-numeric: tabular-nums;
}

.rt-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(255,255,255,.5);
}

.rt-skip {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--r-pill);
  color: rgba(255,255,255,.7);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 12px;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}
.rt-skip:hover { background: rgba(255,255,255,.2); color: white; }

/* ══════════════════════════════════════════
   HEART FLOAT & ENERGY FLASH
══════════════════════════════════════════ */
@keyframes heartFloat {
  0%   { transform: translateY(0) scale(1) rotate(0deg); opacity: 1; }
  60%  { opacity: 1; }
  100% { transform: translateY(-90px) scale(.4) rotate(20deg); opacity: 0; }
}

@keyframes energyFlash {
  0%   { opacity: 1; transform: scale(1); }
  40%  { opacity: .9; transform: scale(1.04); }
  100% { opacity: 0; transform: scale(1); }
}

/* ══════════════════════════════════════════
   CONFETTI
══════════════════════════════════════════ */
@keyframes confettiFall {
  0%   { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(var(--rot)); opacity: 0; }
}

/* ══════════════════════════════════════════
   MODAL
══════════════════════════════════════════ */
.session-modal {
  display: none;
  position: fixed; inset: 0;
  z-index: 1000;
}
.session-modal.open { display: block; }

.modal-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  width: min(520px, 92vw);
  max-height: 80vh;
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex; flex-direction: column;
  animation: popIn .3s cubic-bezier(.34,1.56,.64,1);
}

.modal-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 800; color: var(--text); }
.modal-meta  { font-size: 12px; color: var(--text-2); margin-top: 3px; }
.modal-close {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 13px; color: var(--text-2);
  transition: all .2s; flex-shrink: 0;
  font-family: inherit;
}
.modal-close:hover { background: var(--danger); color: white; border-color: var(--danger); }

.modal-body { overflow-y: auto; padding: 18px 20px; }

.modal-exo-item {
  background: var(--surface-2);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.modal-exo-name { font-size: 14px; font-weight: 800; color: var(--text); margin-bottom: 8px; }
.modal-set-row {
  display: flex; gap: 8px; flex-wrap: wrap; margin-top: 5px;
}
.modal-set-chip {
  background: var(--green-lt);
  border: 1px solid var(--green-muted);
  border-radius: var(--r-pill);
  padding: 3px 10px;
  font-size: 11px; font-weight: 700;
  color: var(--green-dk);
}

/* ══════════════════════════════════════════
   RIPPLE
══════════════════════════════════════════ */
.ripple-effect {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  transform: scale(0);
  animation: rippleAnim .5s linear;
  pointer-events: none;
}

@keyframes rippleAnim {
  to { transform: scale(4); opacity: 0; }
}

/* ══════════════════════════════════════════
   MOBILE — max-width 768px
══════════════════════════════════════════ */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 58px 1fr 58px;
  }

  header {
    padding: 0 14px;
  }

  .logo { font-size: 16px; }
  .logo svg { width: 28px; height: 16px; }

  .header-gamify {
    display: none; /* hidden on mobile, shown in sidebar */
  }

  /* Sidebar hidden by default on mobile */
  .sidebar {
    display: none;
    grid-column: 1;
    grid-row: 2;
    border-right: none;
    border-top: 1px solid var(--border);
    padding: 14px 12px 80px;
  }

  /* Show sidebar when stats tab is active */
  .sidebar.show {
    display: flex;
  }

  /* Chat panel hidden when stats tab active */
  .chat-panel {
    grid-column: 1;
    grid-row: 2;
  }

  /* Bottom nav shown on mobile */
  .bottom-nav {
    display: flex;
    grid-column: 1;
    grid-row: 3;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0;
    justify-content: stretch;
    box-shadow: 0 -2px 12px rgba(0,0,0,.06);
  }

  .bottom-nav button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    padding: 8px 4px;
    transition: color .2s;
    font-family: inherit;
  }

  .bottom-nav button svg {
    width: 22px; height: 22px;
    transition: fill .2s;
    fill: var(--text-3);
  }

  .bottom-nav button.active {
    color: var(--green-dk);
  }

  .bottom-nav button.active svg {
    fill: var(--green-dk);
  }

  /* Make chat messages area use more space */
  .messages {
    padding: 14px 12px 8px;
  }

  .quick-bar {
    padding: 8px 12px;
  }

  .input-area {
    padding: 8px 12px 12px;
  }

  /* Rest timer above nav bar on mobile */
  .rest-timer-widget {
    bottom: 72px;
    right: 10px;
  }

  /* Badge grid 2 columns on mobile */
  .badges-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Welcome screen adjustments */
  .welcome h2 { font-size: 20px; }
  .quick-chips { max-width: 100%; }

  /* Bubble max width */
  .bubble-wrap { max-width: 88%; }

  /* Toast above nav */
  .toast { bottom: 72px; }

  /* Badge toast top right */
  .badge-unlock-toast {
    top: 68px;
    right: 8px;
    max-width: calc(100vw - 16px);
  }

  /* ── Avatar bar compact on mobile ─── */
  .chat-avatar-bar {
    padding: 7px 14px;
    gap: 10px;
  }
  .cab-ring-wrap {
    width: 52px;
    height: 52px;
  }
  .cab-ring-svg {
    width: 52px;
    height: 52px;
  }
  .chat-avatar-bar .avatar-face-wrap {
    inset: 6px;
  }
  .cab-status { font-size: 13px; }
  .cab-mood   { font-size: 11px; }

  /* ── Quick bar touch targets ────── */
  .qbtn { padding: 9px 14px; font-size: 12px; min-height: 38px; }

  /* ── Input area touch targets ───── */
  .btn-round { width: 42px; height: 42px; }

  /* ── Welcome screen compact ─────── */
  .welcome { padding: 24px 16px; gap: 10px; }
  .welcome-icon { width: 72px; height: 46px; }

  /* ── Chips responsive ───────────── */
  .chip { padding: 10px 16px; font-size: 12px; }

  /* ── Fix grid item sizing (prevents page going wider on Stats tab) ── */
  /* Layer 1: constrain .app itself so it can never exceed 100vw         */
  .app         { overflow: hidden; width: 100%; max-width: 100vw; }

  /* Layer 2: all grid items must opt out of min-width:auto              */
  header       { min-width: 0; overflow: hidden; }
  .chat-panel  { min-height: 0; min-width: 0; overflow: hidden; }
  .sidebar     { min-height: 0; min-width: 0; overflow-x: hidden; }
  .bottom-nav  { min-width: 0; }
  .messages    { min-height: 0; min-width: 0; }

  /* Layer 3: sidebar direct children must not exceed sidebar width      */
  .sidebar > * { max-width: 100%; }

  /* Layer 4: chart must never overflow (flex bars can grow sideways)    */
  .chart-wrap  { overflow: hidden; }
  .chart-bars  { overflow: hidden; min-width: 0; }
  .bar-col     { min-width: 0; }

  /* Layer 5: header flex items must shrink on narrow screens            */
  .session-pill { flex-shrink: 1; min-width: 0; max-width: 140px; overflow: hidden; }
  #sessionText  { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .user-pill    { flex-shrink: 1; min-width: 0; overflow: hidden; }
  .user-pill-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; }

  /* Layer 6: exercise items inside sidebar                              */
  .exercise-item { min-width: 0; }
  .ex-max        { max-width: 72px; overflow: hidden; text-overflow: ellipsis; }
}

/* ══════════════════════════════════════════
   SMALL PHONE — max-width 480px
══════════════════════════════════════════ */
@media (max-width: 480px) {

  /* Avatar bar extra compact */
  .chat-avatar-bar { padding: 6px 12px; gap: 8px; }
  .cab-ring-wrap, .cab-ring-svg { width: 46px; height: 46px; }
  .chat-avatar-bar .avatar-face-wrap { inset: 5px; }
  .cab-status { font-size: 12px; }
  .cab-mood   { font-size: 10px; }
  .cab-info   { gap: 3px; }

  /* Messages tighter */
  .messages { padding: 10px 10px 6px; gap: 10px; }
  .quick-bar { padding: 6px 10px; gap: 6px; }
  .input-area { padding: 6px 10px 10px; }

  /* Bubbles wider */
  .bubble-wrap { max-width: 93%; }
  .bubble { font-size: 13px; padding: 10px 13px; }

  /* Welcome screen minimal */
  .welcome { padding: 16px 12px; }
  .welcome h2 { font-size: 17px; }
  .welcome p  { font-size: 12px; }
  .welcome-tips { padding: 10px 12px; gap: 8px; }
  .tip-title    { font-size: 12px; }
  .tip-desc     { font-size: 10px; }
  .chip         { padding: 9px 14px; font-size: 11px; }

  /* Input hint hidden to save space */
  .input-hint { display: none; }

  /* Auth modal slides up from bottom on tiny screens */
  .auth-overlay { align-items: flex-end; }
  .auth-modal {
    border-radius: 24px 24px 0 0;
    max-width: 100%;
    padding: 28px 20px 24px;
    gap: 14px;
  }

  /* Toast above nav bar */
  .toast { bottom: 70px; }
}

/* ══════════════════════════════════════════
   SCROLLBAR GLOBAL
══════════════════════════════════════════ */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ══════════════════════════════════════════
   AUTH OVERLAY & MODAL
══════════════════════════════════════════ */
.auth-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,.55); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .3s ease;
}
.auth-overlay.visible { opacity: 1; pointer-events: all; }

.auth-modal {
  background: var(--surface); border-radius: 20px;
  box-shadow: var(--shadow-lg); padding: 36px 32px 32px;
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 18px;
}

.auth-logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 1.3rem; font-weight: 800; color: var(--green);
  justify-content: center;
}

.auth-tabs {
  display: flex; gap: 4px; background: var(--surface-2);
  border-radius: 12px; padding: 4px;
}
.auth-tab {
  flex: 1; background: none; border: none; cursor: pointer;
  padding: 8px 0; border-radius: 9px; font-size: .85rem;
  font-weight: 600; color: var(--text-muted);
  transition: background .2s, color .2s;
}
.auth-tab.active {
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-xs);
}

.auth-panel { display: flex; flex-direction: column; gap: 14px; }
.auth-panel.hidden { display: none; }

.auth-intro { font-size: .85rem; color: var(--text-muted); line-height: 1.55; margin: 0; }

.auth-field { display: flex; flex-direction: column; gap: 5px; }
.auth-field label {
  font-size: .8rem; font-weight: 600; color: var(--text-muted);
  display: flex; align-items: center; justify-content: space-between;
}
.auth-link { font-size: .75rem; color: var(--green); text-decoration: none; font-weight: 600; }
.auth-field input[type="text"],
.auth-field input[type="password"] {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: 10px; font-size: .9rem; background: var(--surface-2);
  color: var(--text); transition: border-color .2s, background .2s;
  box-sizing: border-box;
}
.auth-field input:focus { outline: none; border-color: var(--green); background: var(--surface); }
.auth-hint { font-size: .73rem; color: var(--text-muted); }

.auth-gender-row { display: flex; gap: 14px; flex-wrap: wrap; }
.gender-opt {
  display: flex; align-items: center; gap: 5px;
  cursor: pointer; font-size: .88rem; font-weight: 500; color: var(--text);
}

.auth-btn {
  width: 100%; padding: 13px; background: var(--green);
  color: #fff; border: none; border-radius: 12px; cursor: pointer;
  font-size: .95rem; font-weight: 700; letter-spacing: .02em;
  transition: background .2s, transform .1s;
  box-shadow: var(--shadow-green);
}
.auth-btn:hover { background: var(--green-dk); }
.auth-btn:active { transform: scale(.98); }
.auth-btn:disabled { opacity: .6; cursor: not-allowed; }

.auth-error { font-size: .82rem; color: #EF4444; min-height: 18px; text-align: center; }

/* ── User pill in header ── */
.user-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--green-bg); border: 1.5px solid var(--green-muted);
  border-radius: 20px; padding: 4px 4px 4px 12px;
}
.user-pill-name { font-size: .8rem; font-weight: 700; color: var(--green-dk); white-space: nowrap; }
.user-pill-logout {
  background: none; border: none; cursor: pointer;
  font-size: 1rem; line-height: 1; padding: 4px 6px;
  border-radius: 12px; color: var(--text-muted); transition: background .2s;
}
.user-pill-logout:hover { background: var(--border); }

/* ── Token reveal modal ── */
.token-reveal-overlay {
  position: fixed; inset: 0; z-index: 2100;
  background: rgba(0,0,0,.65); backdrop-filter: blur(6px);
  display: none; align-items: center; justify-content: center;
}
.token-reveal-modal {
  background: var(--surface); border-radius: 20px;
  box-shadow: var(--shadow-lg); padding: 32px 28px 28px;
  width: 100%; max-width: 400px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center;
}
.tr-icon  { font-size: 2.5rem; }
.tr-title { font-size: 1.2rem; font-weight: 800; color: var(--text); }
.tr-warn  { font-size: .82rem; color: #F97316; font-weight: 600; }
.tr-token {
  background: var(--surface-2); border: 1.5px dashed var(--green);
  border-radius: 10px; padding: 14px 16px; font-family: monospace;
  font-size: .78rem; word-break: break-all; color: var(--text);
  width: 100%; box-sizing: border-box; user-select: all;
}
.tr-copy {
  background: var(--surface-2); border: 1.5px solid var(--border);
  border-radius: 10px; padding: 9px 20px; cursor: pointer;
  font-size: .85rem; font-weight: 600; color: var(--text);
  transition: background .2s;
}
.tr-copy:hover { background: var(--green-bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }
