/* ============================ Theme tokens ============================ */
:root {
  --radius: 14px;
  --radius-sm: 10px;
  --gap: 18px;
  --font: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --accent: #6d5efc;
  --accent-2: #22d3ee;
  --accent-grad: linear-gradient(135deg, #6d5efc 0%, #22d3ee 100%);
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #34d399;
  --transition: 180ms cubic-bezier(.4,0,.2,1);
}

:root[data-theme="dark"] {
  --bg: #0b0d12;
  --bg-2: #11141b;
  --surface: #161a23;
  --surface-2: #1d2230;
  --border: #262c3a;
  --text: #eef1f7;
  --text-dim: #9aa3b5;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
}

:root[data-theme="light"] {
  --bg: #f5f6fa;
  --bg-2: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --border: #e2e6ef;
  --text: #161a23;
  --text-dim: #5c6678;
  --shadow: 0 10px 30px rgba(20,30,60,.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

/* ============================ Welcome Screen ============================ */
.welcome-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  animation: welcomeFadeIn .6s ease;
  overflow-y: auto;
}
.welcome-overlay.leaving {
  animation: welcomeFadeOut .45s ease forwards;
}
@keyframes welcomeFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes welcomeFadeOut { from { opacity: 1; } to { opacity: 0; } }

.welcome-content {
  text-align: center;
  max-width: 860px;
  padding: 48px 36px;
  position: relative;
}
.welcome-glow {
  position: absolute;
  top: -120px; left: 50%; transform: translateX(-50%);
  width: 550px; height: 550px;
  background: radial-gradient(circle, rgba(109,94,252,.3) 0%, rgba(34,211,238,.1) 45%, transparent 70%);
  border-radius: 50%;
  filter: blur(70px);
  pointer-events: none;
  z-index: -1;
}
.welcome-logo {
  width: 160px; height: 160px;
  border-radius: 0;
  box-shadow: none;
  object-fit: contain;
  margin-bottom: 24px;
  animation: floatLogo 3s ease-in-out infinite;
  filter: drop-shadow(0 12px 30px rgba(109,94,252,.35));
}
@keyframes floatLogo {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.welcome-title {
  font-size: 48px; font-weight: 800; letter-spacing: -1px;
  margin: 0 0 12px;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.welcome-sub {
  font-size: 18px; color: var(--text-dim); margin: 0 0 42px; line-height: 1.6;
  max-width: 520px; margin-left: auto; margin-right: auto;
}

.feature-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 40px;
}
.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  transition: var(--transition);
  box-shadow: var(--shadow);
}
.feature-card:hover {
  transform: translateY(-5px);
  border-color: var(--accent);
  box-shadow: 0 16px 48px rgba(109,94,252,.22);
}
.feature-icon { font-size: 40px; margin-bottom: 16px; }
.feature-card h3 {
  font-size: 17px; font-weight: 700; margin: 0 0 10px;
}
.feature-card p {
  font-size: 14px; color: var(--text-dim); margin: 0; line-height: 1.55;
}

.welcome-cta {
  padding: 16px 52px;
  font-size: 17px;
  border-radius: 999px;
  box-shadow: 0 8px 28px rgba(109,94,252,.4);
}
.welcome-cta:hover {
  box-shadow: 0 14px 36px rgba(109,94,252,.5);
}

.welcome-controls {
  display: flex; gap: 28px; justify-content: center; align-items: center;
  margin-top: 28px;
}

.welcome-badges {
  display: flex; gap: 12px; justify-content: center; margin-top: 20px; flex-wrap: wrap;
}
.welcome-badge {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 7px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--text-dim);
}

/* ============================ Layout ============================ */
.app-shell { display: grid; grid-template-columns: 264px 1fr; height: 100vh; }

.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.brand { display: flex; }
.brand-logo {
  width: 100%; height: auto; display: block;
  border-radius: 12px; box-shadow: var(--shadow);
}
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: -.2px; }
.brand-sub { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .8px; }

.nav { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  background: transparent; border: none; color: var(--text-dim);
  padding: 11px 12px; border-radius: var(--radius-sm); cursor: pointer;
  font: inherit; font-weight: 600; font-size: 14px; text-align: left;
  transition: var(--transition);
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.nav-ico { font-size: 16px; }

.sidebar-section { display: flex; flex-direction: column; gap: 8px; }
.section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-dim); }
.model-select {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.model-hint { font-size: 12px; color: var(--text-dim); margin: 0; line-height: 1.4; }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 14px; }
.footer-link { color: var(--text-dim); font-size: 12px; text-decoration: none; text-align: center; }
.footer-link:hover { color: var(--accent-2); }

/* ============================ Toggle Switches ============================ */
.toggle-row {
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.toggle-label {
  font-size: 13px; font-weight: 600; color: var(--text-dim);
  user-select: none; min-width: 20px; text-align: center;
}
.switch {
  position: relative;
  display: inline-block;
  width: 44px; height: 24px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: var(--transition);
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  left: 2px; bottom: 2px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: var(--transition);
}
.switch input:checked + .switch-slider {
  background: var(--accent);
  border-color: var(--accent);
}
.switch input:checked + .switch-slider::before {
  transform: translateX(20px);
  background: #fff;
}

/* ============================ Main ============================ */
.main { overflow-y: auto; padding: 30px 36px 50px; position: relative; display: flex; flex-direction: column; }

/* ============================ Top Bar ============================ */
.top-bar { display: flex; justify-content: flex-end; margin-bottom: 8px; min-height: 44px; }
.top-bar-user { display: flex; align-items: center; gap: 12px; }
.user-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(109,94,252,.3);
}
.user-info { display: flex; flex-direction: column; text-align: right; }
.user-name { font-weight: 600; font-size: 14px; }
.logout-btn {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 12px; cursor: pointer; padding: 0; text-align: right;
  text-decoration: none;
}
.logout-btn:hover { color: var(--danger); text-decoration: underline; }
.login-btn {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 9px 20px;
  font-weight: 600; font-size: 13px; cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  box-shadow: var(--shadow);
}
.login-btn:hover {
  border-color: var(--accent);
  color: var(--accent-2);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(109,94,252,.2);
}
.login-btn .hf-emoji { font-size: 18px; line-height: 1; }

/* ============================ Views ============================ */
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 24px; gap: 16px; }
.view-head h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -.4px; }
.muted { color: var(--text-dim); margin: 4px 0 0; }
.muted.small { font-size: 12px; }

/* ============================ Buttons ============================ */
.btn { border: none; border-radius: var(--radius-sm); padding: 10px 18px; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; transition: var(--transition); }
.btn.primary { background: var(--accent-grad); color: #fff; box-shadow: 0 6px 18px rgba(109,94,252,.35); }
.btn.primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.pill { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim); padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; }

/* ============================ Cards ============================ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: var(--gap);
  box-shadow: var(--shadow);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 16px; }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }

/* ============================ Empty state ============================ */
.empty-state, .chat-intro { text-align: center; padding: 60px 20px; }
.empty-emoji { font-size: 46px; margin-bottom: 12px; }
.intro-logo { width: 84px; height: 84px; border-radius: 20px; box-shadow: var(--shadow); object-fit: cover; margin-bottom: 16px; }
.empty-state h2, .chat-intro h2 { margin: 0 0 6px; font-size: 20px; }
.empty-actions { display: flex; gap: 12px; justify-content: center; margin-top: 18px; }
.hidden { display: none !important; }

/* ============================ Stats ============================ */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); margin-bottom: var(--gap); }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow);
  transition: var(--transition);
  position: relative; overflow: hidden;
}
.stat::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent-grad); opacity: 0;
  transition: opacity var(--transition);
}
.stat:hover::before { opacity: 1; }
.stat:hover { transform: translateY(-2px); }
.stat-val { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.stat-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .6px; margin-top: 4px; }
.stat-ico { font-size: 20px; position: absolute; top: 14px; right: 14px; opacity: .5; }

/* Frequency Row */
.freq-row {
  display: flex; gap: 14px; margin-bottom: var(--gap); flex-wrap: wrap;
}
.freq-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 16px;
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow);
}
.freq-chip .freq-ico { font-size: 16px; }
.freq-chip .freq-val { color: var(--accent-2); }

/* ============================ Chart Controls ============================ */
.chart-controls { display: flex; gap: 4px; }
.chart-tab {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  padding: 5px 12px; border-radius: 999px; font: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: var(--transition);
}
.chart-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chart-tab:hover:not(.active) { border-color: var(--accent); color: var(--text); }

/* ============================ Charts ============================ */
.chart { width: 100%; height: 240px; position: relative; cursor: crosshair; }
.chart svg { width: 100%; height: 100%; overflow: visible; }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .area { fill: url(#grad); opacity: .18; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart .dot { fill: var(--accent-2); transition: r .15s ease; pointer-events: all; }
.chart .dot:hover { r: 6; }
.chart .lbl { fill: var(--text-dim); font-size: 10px; }
.chart .grid-line { stroke: var(--border); stroke-width: 0.5; stroke-dasharray: 4 4; }
.chart .x-label { fill: var(--text-dim); font-size: 9px; text-anchor: middle; }

/* Chart tooltip */
.chart-tooltip {
  position: absolute; top: 0; left: 0;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px;
  font-size: 12px; font-weight: 600;
  pointer-events: none; z-index: 10;
  box-shadow: var(--shadow);
  white-space: nowrap;
  transition: opacity .15s ease;
}
.chart-tooltip.hidden { opacity: 0; pointer-events: none; }
.chart-tooltip .tt-date { color: var(--text-dim); font-weight: 400; font-size: 11px; display: block; margin-bottom: 2px; }
.chart-tooltip .tt-val { color: var(--accent-2); font-weight: 700; }

/* Crosshair */
.chart .crosshair { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; transition: opacity .15s ease; }
.chart:hover .crosshair { opacity: .5; }

/* ============================ Muscle Balance (Donut) ============================ */
.muscle-viz { display: flex; gap: 24px; align-items: center; justify-content: center; }
.donut-wrap { flex-shrink: 0; width: 220px; height: 220px; }
.donut-wrap svg { width: 100%; height: 100%; }
.donut-wrap .donut-segment { transition: opacity .15s ease; cursor: pointer; }
.donut-wrap .donut-segment:hover { opacity: .8; filter: brightness(1.15); }
.donut-center { font-size: 20px; font-weight: 800; fill: var(--text); text-anchor: middle; }
.donut-center-sub { font-size: 13px; fill: var(--text-dim); text-anchor: middle; }
.muscle-legend { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 150px; }
.legend-item {
  display: flex; align-items: center; gap: 8px; font-size: 13px;
  padding: 4px 8px; border-radius: 6px; transition: background var(--transition);
  cursor: default;
}
.legend-item:hover { background: var(--surface-2); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend-name { flex: 1; text-transform: capitalize; font-weight: 600; }
.legend-pct { color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ============================ Exercise Cards ============================ */
.exercise-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px;
}
.exercise-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 16px;
  transition: var(--transition);
}
.exercise-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.ex-name { font-weight: 700; font-size: 14px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-group { font-size: 11px; color: var(--text-dim); text-transform: capitalize; margin-bottom: 10px; }
.ex-sparkline { width: 100%; height: 36px; margin-bottom: 8px; }
.ex-sparkline svg { width: 100%; height: 100%; }
.ex-sparkline .spark-line { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; }
.ex-sparkline .spark-area { fill: url(#spark-grad); opacity: .15; }
.ex-stats { display: flex; justify-content: space-between; align-items: baseline; }
.ex-1rm { font-size: 18px; font-weight: 800; }
.ex-change { font-size: 13px; font-weight: 700; }
.ex-change.pos { color: var(--ok); }
.ex-change.neg { color: var(--danger); }
.ex-change.flat { color: var(--text-dim); }

/* ============================ Flags ============================ */
.flags { display: flex; flex-direction: column; gap: 10px; }
.flag { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); }
.flag .dot-ico { font-size: 14px; margin-top: 1px; }
.flag.plateau { border-left: 3px solid var(--warn); }
.flag.regression { border-left: 3px solid var(--danger); }
.flag-title { font-weight: 600; font-size: 13px; text-transform: capitalize; }
.flag-note { font-size: 12px; color: var(--text-dim); }
.flags-ok { color: var(--ok); font-size: 13px; }

/* ============================ Table ============================ */
.table-card { cursor: default; }
.table-card > summary { cursor: pointer; list-style: none; user-select: none; }
.table-card > summary::-webkit-details-marker { display: none; }
.clickable .expand-ico { transition: transform var(--transition); display: inline-block; }
.table-card[open] .expand-ico { transform: rotate(90deg); }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; color: var(--text-dim); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table td.pos { color: var(--ok); font-weight: 600; }
.data-table td.neg { color: var(--danger); font-weight: 600; }
.group-tag { text-transform: capitalize; font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }

/* ============================ Chat ============================ */
#view-chat.active { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-window { flex: 1; overflow-y: auto; padding: 8px 2px 16px; display: flex; flex-direction: column; gap: 16px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.chip { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 8px 14px; border-radius: 999px; font: inherit; font-size: 13px; cursor: pointer; transition: var(--transition); }
.chip:hover { border-color: var(--accent); color: var(--accent-2); transform: translateY(-1px); }

.msg { display: flex; gap: 12px; max-width: 760px; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg .avatar { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 16px; flex-shrink: 0; overflow: hidden; }
.msg.user .avatar { background: var(--surface-2); border: 1px solid var(--border); }
.msg.bot .avatar { background: var(--accent-grad); }
.avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bubble { background: var(--surface); border: 1px solid var(--border); padding: 13px 16px; border-radius: 14px; line-height: 1.55; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user .bubble { background: var(--accent-grad); color: #fff; border: none; }
.bubble.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent-2); }
@keyframes blink { 50% { opacity: 0; } }

/* ---- Reasoning / thinking block ---- */
.reasoning { margin-bottom: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); overflow: hidden; }
.reasoning .reasoning-body { padding: 10px 12px; font-size: 13px; color: var(--text-dim); border-top: 1px solid var(--border); max-height: 320px; overflow-y: auto; }
.reasoning .reasoning-body > :first-child { margin-top: 0; }
.reasoning .reasoning-body > :last-child { margin-bottom: 0; }

/* live (streaming) state */
.reasoning.live { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.reasoning-head { display: flex; align-items: center; gap: 4px; padding: 8px 12px; font-size: 12px; font-weight: 600; color: var(--accent-2); text-transform: uppercase; letter-spacing: .6px; }
.reasoning-dots::after { content: ""; animation: think-dots 1.4s steps(4, end) infinite; }
@keyframes think-dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* finished (collapsible) state */
details.reasoning > summary { cursor: pointer; list-style: none; padding: 8px 12px; font-size: 12px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: .6px; user-select: none; transition: color var(--transition); }
details.reasoning > summary::-webkit-details-marker { display: none; }
details.reasoning > summary::before { content: "▸"; display: inline-block; margin-right: 8px; transition: transform var(--transition); }
details.reasoning[open] > summary::before { transform: rotate(90deg); }
details.reasoning > summary:hover { color: var(--accent-2); }

/* ---- Rendered markdown inside bot bubbles ---- */
.bubble.markdown { white-space: normal; }
.bubble.markdown > :first-child { margin-top: 0; }
.bubble.markdown > :last-child { margin-bottom: 0; }
.bubble.markdown p { margin: 0 0 10px; }
.bubble.markdown h1, .bubble.markdown h2, .bubble.markdown h3, .bubble.markdown h4 { margin: 14px 0 8px; line-height: 1.3; font-weight: 700; }
.bubble.markdown h1 { font-size: 19px; }
.bubble.markdown h2 { font-size: 17px; }
.bubble.markdown h3 { font-size: 15px; }
.bubble.markdown h4 { font-size: 14px; }
.bubble.markdown ul, .bubble.markdown ol { margin: 0 0 10px; padding-left: 22px; }
.bubble.markdown li { margin: 3px 0; }
.bubble.markdown li > p { margin: 0; }
.bubble.markdown a { color: var(--accent-2); text-decoration: underline; }
.bubble.markdown strong { font-weight: 700; }
.bubble.markdown code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 5px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
.bubble.markdown pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; overflow-x: auto; margin: 0 0 10px; }
.bubble.markdown pre code { background: none; border: none; padding: 0; font-size: 12.5px; }
.bubble.markdown blockquote { margin: 0 0 10px; padding: 4px 0 4px 14px; border-left: 3px solid var(--accent); color: var(--text-dim); }
.bubble.markdown table { border-collapse: collapse; width: 100%; margin: 0 0 10px; font-size: 13px; }
.bubble.markdown th, .bubble.markdown td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.bubble.markdown th { background: var(--surface-2); }
.bubble.markdown hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

.composer { display: flex; gap: 10px; align-items: flex-end; padding-top: 14px; border-top: 1px solid var(--border); }
.chat-input { flex: 1; resize: none; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: var(--radius-sm); padding: 12px 14px; font: inherit; font-size: 14px; max-height: 160px; line-height: 1.4; }
.chat-input:focus { outline: none; border-color: var(--accent); }
.icon-btn { width: 44px; height: 44px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); cursor: pointer; font-size: 18px; transition: var(--transition); flex-shrink: 0; }
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.recording { background: var(--danger); border-color: var(--danger); animation: pulse 1.1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(248,113,113,.5); } 50% { box-shadow: 0 0 0 8px rgba(248,113,113,0); } }
.send { flex-shrink: 0; }
.mic-status { text-align: center; font-size: 12px; color: var(--text-dim); padding-top: 8px; }

/* ============================ Dropzone ============================ */
.dropzone { border: 2px dashed var(--border); background: var(--surface); cursor: pointer; transition: var(--transition); }
.dropzone.drag { border-color: var(--accent); background: var(--surface-2); }
.dz-inner { text-align: center; padding: 40px 20px; }
.import-status { margin-top: 16px; }
.status-card { padding: 16px 18px; border-radius: var(--radius-sm); font-size: 14px; }
.status-card.ok { background: rgba(52,211,153,.12); border: 1px solid var(--ok); color: var(--text); }
.status-card.err { background: rgba(248,113,113,.12); border: 1px solid var(--danger); color: var(--text); }

/* ============================ Toast ============================ */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--surface-2); border: 1px solid var(--border); color: var(--text); padding: 12px 20px; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: 14px; opacity: 0; transition: var(--transition); z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================ Responsive ============================ */

/* ---- Tablet (≤900px) ---- */
@media (max-width: 900px) {
  /* Welcome screen: scroll from top so logo is always visible */
  .welcome-overlay {
    align-items: flex-start;
    -webkit-overflow-scrolling: touch;
  }
  .welcome-content { padding: 40px 20px 60px; }
  .welcome-logo { width: 120px; height: 120px; }
  .welcome-title { font-size: 32px; }
  .welcome-sub { font-size: 16px; margin-bottom: 28px; }
  .welcome-glow { width: 340px; height: 340px; top: -60px; }
  .feature-cards { grid-template-columns: 1fr; gap: 14px; }
  .feature-card { padding: 22px 18px; }

  /* App shell: sidebar becomes compact top nav */
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: 100vh;
    height: 100dvh; /* dynamic viewport for mobile browsers */
  }
  .sidebar {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Hide the big brand logo on mobile — too large */
  .brand { display: none; }

  /* Compact nav row */
  .nav {
    flex-direction: row;
    gap: 4px;
    flex-shrink: 0;
  }
  .nav-item {
    padding: 8px 12px;
    font-size: 13px;
    gap: 6px;
    white-space: nowrap;
  }
  .nav-item.active { box-shadow: inset 0 -2px 0 var(--accent); }

  /* Hide model selector & footer in the top bar to save space */
  .sidebar-section { display: none; }
  .sidebar-footer { display: none; }

  /* Main area */
  .main { padding: 20px 16px 30px; overflow-y: auto; }

  /* Dashboard header: stack title + button vertically */
  .view-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .view-head .btn { align-self: flex-start; }

  /* Stat grid: 2 columns */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .stat-val { font-size: 22px; }

  /* Two-column layout → single column */
  .two-col { grid-template-columns: 1fr; }

  /* Charts */
  .chart { height: 200px; }
  .card { padding: 16px; }
  .card-head { flex-direction: column; align-items: flex-start; gap: 8px; }

  /* Muscle donut: stack vertically */
  .muscle-viz { flex-direction: column; }
  .donut-wrap { width: 180px; height: 180px; }

  /* Exercise grid */
  .exercise-grid { grid-template-columns: 1fr; }

  /* Chat composer */
  .composer { gap: 8px; }
  .chat-input { font-size: 16px; /* prevents iOS zoom on focus */ }

  /* Table */
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 8px; }
}

/* ---- Small phone (≤480px) ---- */
@media (max-width: 480px) {
  .welcome-content { padding: 24px 14px 48px; }
  .welcome-logo { width: 96px; height: 96px; }
  .welcome-title { font-size: 26px; }
  .welcome-sub { font-size: 14px; }
  .welcome-cta { padding: 14px 36px; font-size: 15px; }
  .welcome-controls { gap: 16px; }
  .welcome-badges { gap: 8px; }
  .welcome-badge { font-size: 11px; padding: 5px 12px; }

  .nav-item { padding: 7px 10px; font-size: 12px; }
  .nav-ico { font-size: 14px; }

  .main { padding: 14px 12px 24px; }

  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 14px; }
  .stat-val { font-size: 20px; }
  .stat-label { font-size: 11px; }

  .freq-row { gap: 8px; }
  .freq-chip { padding: 6px 12px; font-size: 12px; }

  .view-head h1 { font-size: 22px; }

  .empty-state, .chat-intro { padding: 40px 14px; }
  .empty-actions { flex-direction: column; align-items: center; }

  .suggestions { gap: 6px; }
  .chip { font-size: 12px; padding: 7px 12px; }

  .msg { gap: 8px; max-width: 100%; }
  .msg .avatar { width: 28px; height: 28px; font-size: 14px; }
  .bubble { padding: 10px 12px; font-size: 13px; }
}
