/* Design tokens live in tokens.generated.css (built from design/tokens.ts). */

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

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(124, 92, 255, 0.06), transparent 60%),
    radial-gradient(900px 500px at -10% 20%, rgba(0, 210, 106, 0.05), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

::selection { background: var(--accent-soft); color: var(--ink); }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-hover); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: padding-box; border: 2px solid transparent; }

/* ── Top bar ────────────────────────────────────────────── */
#top-bar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--top-h);
  background: rgba(14, 16, 20, 0.72);
  backdrop-filter: saturate(140%) blur(16px);
  -webkit-backdrop-filter: saturate(140%) blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: 32px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 12px; color: #001b0e; letter-spacing: -0.02em;
  background: linear-gradient(135deg, #00e87a 0%, #00b85d 100%);
  box-shadow: 0 2px 10px rgba(0, 210, 106, 0.35);
}
.brand-name { font-weight: 700; font-size: 15px; color: var(--ink); letter-spacing: -0.01em; }

#nav { display: flex; gap: 2px; flex: 1; }
#nav a {
  padding: 8px 14px; border-radius: 8px;
  font-size: 13.5px; color: var(--muted); font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}
#nav a:hover { background: var(--surface); color: var(--ink-soft); }
#nav a.active { background: var(--surface-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--border-strong); }

/* ── Main view ──────────────────────────────────────────── */
#view {
  position: fixed;
  top: var(--top-h); left: 0;
  right: var(--chat-w);
  bottom: 0;
  overflow-y: auto;
  padding: 28px 32px 40px;
  transition: right 0.25s ease;
}
body.chat-collapsed #view { right: 0; }

.loading, .empty {
  color: var(--muted); font-style: italic;
  padding: 40px; text-align: center;
}
.error { color: var(--bad); padding: 20px; }

/* ── Card primitive ─────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin-bottom: 14px; font-weight: 600;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card h3 .row-actions { display: flex; gap: 8px; }

.back-link {
  color: var(--accent); cursor: pointer; font-size: 13px; font-weight: 500;
  display: inline-block; margin-bottom: 14px;
}
.back-link:hover { color: var(--accent-hover); }

/* ── Stat grid ──────────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 24px; font-weight: 600; color: var(--ink);
  letter-spacing: -0.02em;
}
.stat-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-top: 4px; font-weight: 600; }

/* ── Tables ─────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border);
  color: var(--muted); font-weight: 600; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
}
td { padding: 14px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--ink-soft); }
tr.clickable { cursor: pointer; transition: background 0.12s ease; }
tr.clickable:hover { background: var(--surface-2); }
tr:last-child td { border-bottom: none; }

.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 0 0; font-size: 12px; color: var(--muted);
}
.pagination button {
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--border);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 12.5px; font-weight: 500;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.pagination button:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--border-strong); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  background: var(--accent); color: #001b0e; border: none;
  padding: 8px 16px; border-radius: 8px; cursor: pointer;
  font-size: 13px; font-weight: 600;
  transition: background 0.15s ease, transform 0.05s ease;
  letter-spacing: -0.005em;
}
.btn:hover:not(:disabled) { background: var(--accent-hover); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { background: var(--surface-hover); color: var(--muted-2); cursor: not-allowed; }
.btn.ghost {
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--border);
}
.btn.ghost:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--border-strong); }
.btn.sm { padding: 5px 11px; font-size: 12px; border-radius: 6px; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.01em;
  border: 1px solid transparent;
}
.badge.good { background: rgba(0, 210, 106, 0.12); color: #4ae59c; border-color: rgba(0, 210, 106, 0.25); }
.badge.warn { background: rgba(247, 185, 85, 0.12); color: #f7b955; border-color: rgba(247, 185, 85, 0.25); }
.badge.bad  { background: rgba(255, 90, 106, 0.12); color: #ff8793; border-color: rgba(255, 90, 106, 0.28); }
.badge.info { background: rgba(93, 169, 255, 0.12); color: #8dc3ff; border-color: rgba(93, 169, 255, 0.25); }

/* ── Home ───────────────────────────────────────────────── */
.home-hero {
  position: relative; overflow: hidden;
  background:
    radial-gradient(600px 200px at 100% 0%, rgba(124, 92, 255, 0.25), transparent 60%),
    radial-gradient(500px 200px at 0% 100%, rgba(0, 210, 106, 0.18), transparent 60%),
    linear-gradient(135deg, #15181d 0%, #1c1f25 100%);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 26px;
  border-radius: var(--radius-lg);
  margin-bottom: 18px;
  display: flex; justify-content: space-between; align-items: center; gap: 24px;
  box-shadow: var(--shadow);
}
.home-hero h2 { font-size: 20px; margin-bottom: 6px; font-weight: 700; letter-spacing: -0.02em; }
.home-hero .goal { color: var(--muted); font-size: 13px; }
.home-hero .hero-stats { display: flex; gap: 36px; }
.home-hero .hero-stat-value {
  font-family: var(--font-mono);
  font-size: 30px; font-weight: 600; letter-spacing: -0.03em;
  background: linear-gradient(180deg, #ffffff 0%, #c2c7d0 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.home-hero .hero-stat-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; margin-top: 2px; }

.week-strip {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px;
}
.week-day {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 6px;
  text-align: center; min-height: 82px;
  display: flex; flex-direction: column; justify-content: space-between;
  background: var(--surface-2);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.week-day:hover { border-color: var(--border-strong); }
.week-day.clickable { cursor: pointer; }
.week-day.clickable:hover { background: var(--surface-hover); }
.week-day.today {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-soft) 0%, var(--surface-2) 70%);
  box-shadow: 0 0 0 1px rgba(0, 210, 106, 0.25);
}
.week-day .dow { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.week-day .dom { font-size: 15px; font-weight: 700; color: var(--ink); font-family: var(--font-mono); letter-spacing: -0.02em; }
.week-day .pill {
  font-size: 10.5px; padding: 3px 7px; border-radius: 999px; margin-top: 4px;
  color: #fff; font-weight: 600;
}
.week-day .pill.planned {
  background: transparent !important;
  color: var(--ink-soft);
  border: 1px dashed currentColor;
  opacity: 0.75;
  cursor: pointer;
}
.week-day .pill.planned:hover { opacity: 1; }
.week-day .pill.planned.intensity-easy { color: var(--easy); }
.week-day .pill.planned.intensity-tempo { color: var(--tempo); }
.week-day .pill.planned.intensity-long { color: var(--long); }
.week-day .pill.planned.intensity-workout { color: var(--workout); }
.week-day .rest { font-size: 18px; color: var(--muted-2); }

/* ── Plan table ─────────────────────────────────────────── */
.plan-table th, .plan-table td { padding: 10px 8px; font-size: 12.5px; }
.plan-table .plan-wk-num { font-family: var(--font-mono); font-weight: 700; color: var(--ink); white-space: nowrap; }
.plan-table .plan-wk-date { color: var(--muted); white-space: nowrap; }
.plan-table .plan-wk-total { font-family: var(--font-mono); font-weight: 600; color: var(--ink); }
.plan-table tr.plan-row-current { background: var(--accent-soft); }
.plan-table tr.plan-row-current td { color: var(--ink); }
.plan-table tr.plan-row-past td { opacity: 0.55; }
.plan-table tr.plan-row-deload .plan-wk-num { color: var(--muted); }
.plan-table .plan-cell {
  display: flex; flex-direction: column; gap: 2px;
  padding: 6px 8px; border-radius: 6px; background: var(--surface-2);
  border-left: 3px solid currentColor;
  cursor: pointer;
  transition: background 0.12s ease;
}
.plan-table .plan-cell:hover { background: var(--surface-hover); }
.plan-table .plan-cell.intensity-easy { color: var(--easy); }
.plan-table .plan-cell.intensity-tempo { color: var(--tempo); }
.plan-table .plan-cell.intensity-long { color: var(--long); }
.plan-table .plan-cell.intensity-workout { color: var(--workout); }
.plan-table .plan-cell-miles { font-family: var(--font-mono); font-weight: 600; color: var(--ink); font-size: 12px; }
.plan-table .plan-cell-type { font-size: 10.5px; color: var(--muted); text-transform: capitalize; }
.plan-table .plan-rest { color: var(--muted-2); }

.recent-runs { display: flex; flex-direction: column; gap: 8px; }
.recent-run {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 14px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
  background: var(--surface-2);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
.recent-run:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.recent-run:active { transform: translateY(1px); }
.recent-run .rr-meta { display: flex; flex-direction: column; gap: 3px; }
.recent-run .rr-name { font-weight: 600; color: var(--ink); }
.recent-run .rr-date { font-size: 12px; color: var(--muted); }
.recent-run .rr-stats { display: flex; gap: 18px; font-size: 13px; font-family: var(--font-mono); font-weight: 500; }
.recent-run .rr-stats div { text-align: right; color: var(--ink-soft); }
.recent-run .rr-stats .label { font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-family: var(--font-sans); font-weight: 600; }

/* ── Calendar view ──────────────────────────────────────── */
.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.cal-head h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.cal-head .nav-btns { display: flex; gap: 6px; }

.cal-legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 18px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px; color: var(--ink-soft);
}
.cal-legend .leg {
  position: relative;
  display: inline-flex; align-items: center; gap: 8px;
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 22 22'><circle cx='11' cy='11' r='9' fill='white' stroke='%231a1a1a' stroke-width='1.5'/><text x='11' y='15.5' font-family='Georgia,serif' font-size='13' font-style='italic' font-weight='700' text-anchor='middle' fill='%231a1a1a'>i</text></svg>") 11 11, pointer;
  font-weight: 500;
  padding: 2px 0;
}
.cal-legend .leg-dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
}
.cal-legend .leg-dot.planned {
  background: transparent;
  border: 1.5px dashed var(--ink-soft);
  box-shadow: none;
}
.cal-legend .leg[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px); left: 50%;
  transform: translateX(-50%) translateY(-4px);
  background: #0a0b0d;
  color: var(--ink);
  border: 1px solid var(--border-strong);
  padding: 8px 11px;
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.45;
  white-space: normal;
  width: max-content;
  max-width: 240px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease;
  z-index: 70;
}
.cal-legend .leg[data-tip]::before {
  content: '';
  position: absolute;
  top: calc(100% + 2px); left: 50%;
  transform: translateX(-50%) translateY(-4px);
  border: 6px solid transparent;
  border-bottom-color: var(--border-strong);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease;
  z-index: 71;
}
.cal-legend .leg[data-tip]:hover::after,
.cal-legend .leg[data-tip]:hover::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.cal-grid {
  /* Google Calendar-style month view: 5 rows, fills viewport — no scrolling.
     ~310px overhead = top bar (60) + view padding (68) + cal-head (~40) +
     legend (~60) + grid padding/border (~34) + dow row (~22) + 5 gaps (30). */
  --cal-row-h: max(64px, calc((100vh - 310px) / 5));
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: auto repeat(5, var(--cal-row-h));
  gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 16px; border-radius: var(--radius); box-shadow: var(--shadow);
}
.cal-grid .dow-label {
  font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em;
  text-align: center; padding: 4px; font-weight: 600;
}
.cal-cell {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px;
  display: flex; flex-direction: column; gap: 3px;
  min-height: 0;
  overflow: hidden;
  background: var(--surface-2);
  cursor: default;
  transition: border-color 0.12s ease;
}
.cal-cell:hover { border-color: var(--border-strong); }
.cal-cell.other-month { background: transparent; }
.cal-cell.other-month .dom { color: var(--muted-2); }
.cal-cell.other-month .act { opacity: 0.55; }
.cal-cell.today {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-soft) 0%, var(--surface-2) 70%);
  box-shadow: 0 0 0 1px rgba(0, 210, 106, 0.25);
}
.cal-cell .dom { font-size: 12px; font-weight: 600; color: var(--ink-soft); font-family: var(--font-mono); }
.cal-cell .act {
  font-size: 10px; padding: 3px 6px; border-radius: 4px;
  color: #fff; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 500;
}
.cal-cell .act:hover { opacity: 0.85; }
.act.planned {
  background: transparent !important;
  border: 1px dashed currentColor;
  font-weight: 500;
  cursor: pointer;
  opacity: 0.85;
}
.act.planned.intensity-easy { color: var(--easy); }
.act.planned.intensity-tempo { color: var(--tempo); }
.act.planned.intensity-long { color: var(--long); }
.act.planned.intensity-workout { color: var(--workout); }
.act.planned:hover { opacity: 1; }
.intensity-easy { background: var(--easy); }
.intensity-tempo { background: var(--tempo); }
.intensity-long { background: var(--long); }
.intensity-workout { background: var(--workout); }
.intensity-other { background: var(--muted); }

/* ── Activity list ──────────────────────────────────────── */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.page-head h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.sparkline { width: 80px; height: 24px; }

/* ── Activity detail ────────────────────────────────────── */
#chart-wrap { position: relative; height: 320px; }

/* ── Sign out + Login view ─────────────────────────────── */
.signout-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.signout-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--ink);
}

.login-card {
  max-width: 420px;
  margin: 64px auto 0;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
}
.login-card h1 { font-size: 24px; margin: 0 0 6px; }
.login-sub { color: var(--muted); margin: 0 0 24px; font-size: 13px; }
.login-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.login-form label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.login-form input {
  padding: 10px 12px; border-radius: 8px;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border); font-size: 14px;
}
.login-form input:focus { outline: none; border-color: var(--accent); }
.login-primary {
  margin-top: 8px;
  background: var(--accent); color: #001b0e;
  border: 0; padding: 11px 14px; border-radius: 8px;
  font-weight: 600; font-size: 14px; cursor: pointer;
}
.login-primary:hover { filter: brightness(1.05); }
.login-divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 11px;
  margin: 16px 0 12px;
}
.login-divider::before,
.login-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.login-oauth {
  width: 100%;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border);
  padding: 11px 14px; border-radius: 8px;
  font-size: 14px; cursor: pointer;
  margin-bottom: 8px;
}
.login-oauth:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.login-status { margin-top: 12px; font-size: 12px; color: var(--muted); min-height: 18px; }

.waitlist-card {
  max-width: 420px;
  margin: 96px auto 0;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.waitlist-card h1 { font-size: 22px; margin: 0 0 12px; }
.waitlist-sub { color: var(--ink-soft); font-size: 14px; margin: 0 0 24px; line-height: 1.5; }

/* ── Chat panel (drawer) ────────────────────────────────── */
#chat-panel {
  position: fixed; top: var(--top-h); right: 0; bottom: 0;
  width: var(--chat-w);
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 40;
  transition: transform 0.25s ease;
}
#chat-panel.collapsed { transform: translateX(100%); }

/* Drag handle — thin strip on the left edge of the chat panel. */
#chat-resize-handle {
  position: absolute;
  top: 0; left: -3px; bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 50;
  background: transparent;
  transition: background 0.12s ease;
}
#chat-resize-handle:hover,
body.chat-resizing #chat-resize-handle {
  background: var(--accent);
  box-shadow: 0 0 14px rgba(0, 210, 106, 0.45);
}

/* While dragging: freeze transitions and suppress iframe/text selection. */
body.chat-resizing { cursor: col-resize; user-select: none; }
body.chat-resizing #chat-panel,
body.chat-resizing #view { transition: none !important; }

#chat-panel header {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
#chat-panel header .title { font-weight: 700; font-size: 14px; letter-spacing: -0.01em; }
#chat-panel header .subtitle { font-size: 11px; color: var(--muted); margin-top: 1px; }
#chat-panel header .hdr-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

#chat-panel .session-row {
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  display: flex; gap: 6px; align-items: center;
  background: var(--surface);
}
#chat-panel select {
  flex: 1; font-size: 12px; padding: 6px 10px;
  border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--ink);
  font-family: inherit; cursor: pointer;
}
#chat-panel select:focus { outline: none; border-color: var(--accent); box-shadow: var(--accent-glow); }

#chat-messages {
  flex: 1; overflow-y: auto; padding: 18px 16px;
  display: flex; flex-direction: column; gap: 12px;
  min-height: 0;
}
.msg { max-width: 88%; display: flex; flex-direction: column; gap: 4px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.coach { align-self: flex-start; align-items: flex-start; }
.msg-bubble {
  padding: 10px 14px; border-radius: 16px;
  font-size: 13.5px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
}
.msg.user .msg-bubble {
  background: linear-gradient(135deg, #00d26a 0%, #00b85d 100%);
  color: #001b0e;
  border-bottom-right-radius: 5px;
  font-weight: 500;
}
.msg.coach .msg-bubble {
  background: var(--surface-2);
  color: var(--ink);
  border-bottom-left-radius: 5px;
  border: 1px solid var(--border);
}
.msg.coach .msg-bubble > *:first-child { margin-top: 0; }
.msg.coach .msg-bubble > *:last-child { margin-bottom: 0; }
.msg.coach .msg-bubble p { margin: 0 0 8px; }
.msg.coach .msg-bubble h1,
.msg.coach .msg-bubble h2,
.msg.coach .msg-bubble h3,
.msg.coach .msg-bubble h4 { margin: 10px 0 6px; font-size: 14px; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; }
.msg.coach .msg-bubble ul,
.msg.coach .msg-bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.msg.coach .msg-bubble li { margin: 2px 0; }
.msg.coach .msg-bubble code {
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 6px; border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #8dc3ff;
}
.msg.coach .msg-bubble pre {
  background: #0a0b0d; color: var(--ink-soft);
  padding: 11px 13px; border-radius: 8px;
  overflow-x: auto; margin: 8px 0; font-size: 12px;
  border: 1px solid var(--border);
}
.msg.coach .msg-bubble pre code { background: transparent; padding: 0; color: inherit; }
.msg.coach .msg-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px; margin: 6px 0; color: var(--ink-soft);
}
.msg.coach .msg-bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.msg.coach .msg-bubble a:hover { color: var(--accent-hover); }
.msg.coach .msg-bubble strong { font-weight: 700; color: var(--ink); }
.msg.coach .msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.msg.coach .msg-bubble table { font-size: 12px; margin: 6px 0; }
.msg.coach .msg-bubble th, .msg.coach .msg-bubble td { padding: 5px 8px; }
.msg-meta { font-size: 10px; color: var(--muted); padding: 0 4px; }
.node-badge {
  display: inline-block;
  background: var(--accent-2-soft);
  color: #b9a8ff;
  font-size: 9px; padding: 2px 7px; border-radius: 999px;
  margin-left: 6px; font-family: var(--font-mono); font-weight: 500;
  letter-spacing: 0.02em;
}

.typing-indicator {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 14px; background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px; border-bottom-left-radius: 5px;
  width: fit-content; max-width: 300px;
}
.typing-dots { display: flex; gap: 4px; }
.typing-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
.typing-status { font-size: 11px; color: var(--muted); font-style: italic; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

#chat-input-row {
  display: flex; gap: 8px; padding: 12px 14px;
  border-top: 1px solid var(--border); flex-shrink: 0;
  background: var(--surface);
}
#chat-input {
  flex: 1; border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 13px; font-size: 13.5px; font-family: inherit;
  resize: none; line-height: 1.45; max-height: 120px; outline: none;
  background: var(--surface-2); color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#chat-input::placeholder { color: var(--muted); }
#chat-input:focus { border-color: var(--accent); box-shadow: var(--accent-glow); }
#chat-send { flex-shrink: 0; }

/* Toggle button (floating) */
#chat-toggle {
  position: fixed; bottom: 22px; right: 22px;
  width: 54px; height: 54px; border-radius: 50%;
  background: linear-gradient(135deg, #00e87a 0%, #00b85d 100%);
  color: #001b0e; border: none;
  font-size: 22px; cursor: pointer;
  box-shadow: 0 6px 22px rgba(0, 210, 106, 0.45), inset 0 0 0 1px rgba(255,255,255,0.1);
  display: none;
  z-index: 45;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}
body.chat-collapsed #chat-toggle { display: block; }
#chat-toggle:hover { transform: translateY(-1px); box-shadow: 0 8px 26px rgba(0, 210, 106, 0.55), inset 0 0 0 1px rgba(255,255,255,0.15); }
#chat-toggle:active { transform: translateY(1px); }

/* Calendar connect button inside chat header */
.cal-btn {
  font-size: 11px; padding: 5px 11px; border-radius: 6px;
  border: 1px solid rgba(0, 210, 106, 0.35);
  background: var(--accent-soft); color: #4ae59c; cursor: pointer;
  font-weight: 600;
  transition: background 0.12s ease;
}
.cal-btn:hover { background: rgba(0, 210, 106, 0.22); }
.cal-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#cal-status { font-size: 10px; color: #4ae59c; }

/* ── Planned workout modal ──────────────────────────────── */
.planned-modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  padding: 24px;
}
.planned-modal {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}
.planned-modal-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
}
.planned-modal-head h3 {
  flex: 1; font-size: 16px; font-weight: 700; color: var(--ink);
  text-transform: capitalize; letter-spacing: -0.01em;
}
.planned-modal-dot {
  width: 10px; height: 10px; border-radius: 999px; flex-shrink: 0;
}
.planned-modal-close {
  background: none; border: none; color: var(--muted);
  font-size: 22px; line-height: 1; cursor: pointer; padding: 0 2px;
}
.planned-modal-close:hover { color: var(--ink); }
.planned-modal-meta {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  font-size: 12.5px; color: var(--muted); font-weight: 600;
  margin-bottom: 12px;
}
.planned-modal-meta div {
  font-family: var(--font-mono);
}
.planned-notes {
  font-size: 13.5px; line-height: 1.5; color: var(--ink-soft);
  border-top: 1px solid var(--border); padding-top: 12px;
  white-space: pre-wrap;
}
.planned-notes.muted { color: var(--muted); font-style: italic; }
.planned-modal-foot {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  border-top: 1px solid var(--border); margin-top: 14px; padding-top: 14px;
}
.btn-push-garmin {
  background: var(--accent); color: #001b0e; border: none;
  border-radius: 7px; padding: 7px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.btn-push-garmin:hover:not(:disabled) { background: var(--accent-hover); }
.btn-push-garmin:disabled { background: var(--surface-hover); color: var(--muted-2); cursor: not-allowed; }
.push-status { font-size: 12px; color: var(--muted); line-height: 1.4; }
.push-status.error { color: var(--danger, #e5534b); }

/* ── Narrow screens ─────────────────────────────────────── */
@media (max-width: 900px) {
  #view { right: 0; padding: 18px; }
  #chat-panel { width: 100%; }
  #top-bar { padding: 0 14px; }
  .brand { margin-right: 12px; }
  .brand-name { font-size: 14px; }
  #nav a { padding: 6px 10px; font-size: 13px; }
  .home-hero { flex-direction: column; align-items: flex-start; }
  .home-hero .hero-stats { gap: 20px; }
}
