/* ── Reset & tokens ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f1f5f9;
  --bg2:         #f8fafc;
  --surface:     #ffffff;
  --surface2:    #f1f5f9;
  --border:      #e2e8f0;
  --border2:     #cbd5e1;
  --text:        #0f172a;
  --text2:       #475569;
  --text3:       #94a3b8;

  --green:       #16a34a;
  --green-dim:   rgba(22,163,74,.08);
  --yellow:      #b45309;
  --yellow-dim:  rgba(180,83,9,.08);
  --orange:      #c2410c;
  --orange-dim:  rgba(194,65,12,.08);
  --red:         #dc2626;
  --red-dim:     rgba(220,38,38,.08);
  --indigo:      #6366f1;
  --indigo-mid:  #4f46e5;
  --indigo-dim:  rgba(99,102,241,.1);

  --radius-sm:   6px;
  --radius:      10px;
  --radius-lg:   14px;
  --radius-xl:   18px;

  --sidebar-w:   230px;
  --topbar-h:    60px;
  --shadow-sm:   0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow:      0 4px 12px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.05);
}

body {
  font-family: Inter, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ────────────────────────────────────────────── */
.app-shell {
  display: flex;
  align-items: flex-start;   /* let children size to their content */
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0 0 16px;
  overflow-y: auto;
  /* stick to viewport while page scrolls */
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.logo-icon { font-size: 20px; }
.logo-text  { font-size: 17px; font-weight: 800; letter-spacing: -0.5px; color: var(--indigo); }

.sidebar-site-link {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text3);
  text-decoration: none;
  padding: 0 16px 14px;
  margin-top: -8px;
  transition: color 0.15s;
}
.sidebar-site-link:hover { color: var(--indigo); }
.sidebar-site-link svg { flex-shrink: 0; }

.sidebar-nav { flex: 1; padding: 0 10px; }
.nav-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--text3);
  padding: 0 6px;
  margin-bottom: 6px;
  display: block;
}

.team-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  margin-bottom: 2px;
}
.team-nav-item:hover  { background: var(--bg); color: var(--text); }
.team-nav-item.active { background: var(--indigo-dim); color: var(--indigo); font-weight: 600; }
.team-nav-item .tni-count {
  font-size: 11px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 7px;
  color: var(--text3);
}
.team-nav-item.active .tni-count { background: var(--indigo-dim); border-color: transparent; color: var(--indigo); }

.sidebar-new-team {
  padding: 14px 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
  margin-top: 10px;
}

/* ── Main content ─────────────────────────────────────────── */
.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.top-bar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  /* stick to top as user scrolls down */
  position: sticky;
  top: 0;
  z-index: 40;
}
.page-title { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.page-sub   { font-size: 12px; color: var(--text3); margin-top: 1px; }
.top-bar-actions { display: flex; gap: 8px; align-items: center; }

/* Natural flow — body scrolls, no overflow tricks needed */
.roster-view {
  padding: 24px 28px 100px; /* bottom padding clears the chat widget */
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.roster-view.hidden { display: none; }

/* ── Inputs & Buttons ─────────────────────────────────────── */
input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus { border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
input::placeholder { color: var(--text3); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 8px 14px;
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.12s;
  font-family: inherit;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary  { background: var(--indigo); color: #fff; box-shadow: 0 1px 3px rgba(99,102,241,.35); }
.btn-primary:hover  { background: var(--indigo-mid); }

.btn-accent   { background: var(--indigo-dim); color: var(--indigo); border-color: rgba(99,102,241,.2); }
.btn-accent:hover { background: rgba(99,102,241,.18); }

.btn-ghost    { background: transparent; border-color: var(--border); color: var(--text2); }
.btn-ghost:hover { border-color: var(--border2); color: var(--text); background: var(--bg); }

.btn-danger   { background: transparent; border-color: rgba(220,38,38,.25); color: var(--red); }
.btn-danger:hover { background: var(--red-dim); border-color: rgba(220,38,38,.4); }

.btn-sm  { padding: 7px 13px; font-size: 13px; }
.btn-xs  { padding: 5px 10px; font-size: 12px; }
.w-full  { width: 100%; }

/* ── Add-athlete form ─────────────────────────────────────── */
.add-athlete-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr auto;
  gap: 10px;
  align-items: end;
  box-shadow: var(--shadow-sm);
}
.add-athlete-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

/* ── Athlete Card ─────────────────────────────────────────── */
.athlete-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, border-color 0.2s;
}
.athlete-card:hover { box-shadow: var(--shadow); border-color: var(--border2); }

.ac-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.ac-avatar {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(99,102,241,.3);
}
.ac-initials { font-size: 16px; font-weight: 800; color: #fff; letter-spacing: -0.5px; }

.ac-info { flex: 1; min-width: 0; }
.ac-name { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-pos {
  display: inline-flex;
  align-items: center;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--indigo);
  background: var(--indigo-dim);
  border-radius: 20px;
  padding: 2px 9px;
  letter-spacing: 0.3px;
}

.ac-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* WHOOP pill */
.whoop-pill {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 3px 9px;
  border-radius: 20px;
  border: 1px solid;
}
.whoop-pill.connected    { color: var(--green); border-color: rgba(22,163,74,.3); background: var(--green-dim); }
.whoop-pill.disconnected { color: var(--text3); border-color: var(--border);     background: var(--surface2); }

/* ── Quick stats bar ──────────────────────────────────────── */
.ac-quick {
  display: flex;
  align-items: stretch;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.ac-quick.hidden { display: none; }

.qs-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 8px;
  gap: 3px;
  min-width: 0;
}
.qs-item--status { flex: 1.2; }
.qs-label { font-size: 10px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap; }
.qs-val   { font-size: 17px; font-weight: 800; color: var(--text); }
.qs-divider { width: 1px; background: var(--border); align-self: stretch; flex-shrink: 0; }

.readiness-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid;
}

/* ── Dashboard panel ──────────────────────────────────────── */
.ac-dashboard { padding: 20px; background: var(--bg2); }
.ac-dashboard:empty { display: none; }

.no-data-panel {
  text-align: center;
  padding: 32px 16px;
  color: var(--text3);
}
.no-data-panel strong { display: block; font-size: 14px; color: var(--text2); margin-bottom: 6px; }
.no-data-panel p { font-size: 13px; }

/* ── Hero card ────────────────────────────────────────────── */
.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.ring-wrap {
  position: relative;
  width: 96px;
  height: 96px;
  flex-shrink: 0;
}
.ring-wrap svg { width: 96px; height: 96px; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--border); stroke-width: 8; }
.ring-fill  { fill: none; stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset 0.7s ease; }
.ring-fill.green  { stroke: var(--green);  }
.ring-fill.yellow { stroke: var(--yellow); }
.ring-fill.orange { stroke: var(--orange); }
.ring-fill.red    { stroke: var(--red);    }
.ring-fill.gray   { stroke: var(--text3);  }
.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-score { font-size: 24px; font-weight: 800; line-height: 1; }
.ring-denom { font-size: 10px; color: var(--text3); margin-top: 1px; }

.hero-body { flex: 1; min-width: 180px; }
.hero-label-sm { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text3); margin-bottom: 4px; }
.hero-status { font-size: 26px; font-weight: 800; line-height: 1.1; margin-bottom: 12px; }
.hero-rec {
  font-size: 13px;
  color: var(--text2);
  background: var(--indigo-dim);
  border: 1px solid rgba(99,102,241,.15);
  border-radius: var(--radius);
  padding: 9px 13px;
  line-height: 1.5;
}

/* ── Metrics grid ─────────────────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.m-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.m-card:hover { box-shadow: var(--shadow); border-color: var(--border2); }

.m-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.m-card-title { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text3); }
.m-card-icon  { font-size: 18px; }

.m-main { display: flex; align-items: baseline; gap: 5px; margin-bottom: 8px; }
.m-val  { font-size: 30px; font-weight: 800; line-height: 1; color: var(--text); }
.m-unit { font-size: 12px; color: var(--text3); }

.m-rows { display: grid; gap: 6px; margin-top: 10px; }
.m-row  { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.m-row .l { color: var(--text3); }
.m-row .v { font-weight: 600; color: var(--text2); }

/* ── Status badge ─────────────────────────────────────────── */
.sbadge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  letter-spacing: 0.3px;
  border: 1px solid transparent;
}
.sbadge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.sbadge.green  { background: var(--green-dim);  color: var(--green);  border-color: rgba(22,163,74,.15); }
.sbadge.yellow { background: var(--yellow-dim); color: var(--yellow); border-color: rgba(180,83,9,.15); }
.sbadge.orange { background: var(--orange-dim); color: var(--orange); border-color: rgba(194,65,12,.15); }
.sbadge.red    { background: var(--red-dim);    color: var(--red);    border-color: rgba(220,38,38,.15); }
.sbadge.gray   { background: var(--surface2);   color: var(--text3);  border-color: var(--border); }

/* ── Injury pills ─────────────────────────────────────────── */
.factor-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.factor-pill {
  font-size: 11px;
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(220,38,38,.15);
  border-radius: 12px;
  padding: 2px 9px;
}

/* ── Sleep bar ────────────────────────────────────────────── */
.sleep-bar-wrap { margin-top: 10px; }
.sleep-bar-bg { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.sleep-bar-fill { height: 100%; border-radius: 3px; background: var(--indigo); transition: width 0.5s ease; }

/* ── Sync info ────────────────────────────────────────────── */
.sync-info { font-size: 11px; color: var(--text3); text-align: right; margin-top: 16px; }

/* ── Empty state ──────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 10px;
  color: var(--text3);
  padding: 60px;
  text-align: center;
}
.empty-state .big { font-size: 40px; margin-bottom: 8px; }
.empty-state h2   { font-size: 16px; color: var(--text2); font-weight: 600; }
.empty-state p    { font-size: 13px; }

/* ── WHOOP Link Modal ─────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  padding: 24px;
  box-shadow: 0 24px 64px rgba(0,0,0,.15);
}

.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-header h2 { font-size: 16px; font-weight: 700; }

.modal-steps { display: flex; flex-direction: column; gap: 16px; margin-bottom: 20px; }
.step { display: flex; gap: 14px; align-items: flex-start; }
.step-num {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--indigo-dim); color: var(--indigo);
  font-size: 12px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 2px;
}
.step-body { flex: 1; }
.step-body strong { font-size: 13px; display: block; margin-bottom: 4px; }
.step-body p { font-size: 12px; color: var(--text2); line-height: 1.5; }
.step-body code { font-family: monospace; background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 11px; color: var(--green); border: 1px solid var(--border); }

.code-hint {
  margin-top: 8px; font-size: 11px; font-family: monospace;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 10px;
  color: var(--text3); word-break: break-all; line-height: 1.5;
}
.code-hint strong { color: var(--green); }

.modal-footer { display: flex; flex-direction: column; gap: 8px; }
.modal-err { font-size: 12px; color: var(--red); padding: 8px 10px; background: var(--red-dim); border: 1px solid rgba(220,38,38,.15); border-radius: var(--radius-sm); }
.modal-err.hidden { display: none; }

/* ── AI Chat Widget ───────────────────────────────────────── */
.chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--indigo);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(99,102,241,.45);
  transition: transform 0.2s, box-shadow 0.2s;
}
.chat-bubble:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(99,102,241,.55); }

.chat-panel {
  position: fixed;
  bottom: 88px;
  right: 24px;
  z-index: 200;
  width: 360px;
  max-height: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 16px 48px rgba(0,0,0,.14);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: opacity 0.18s, transform 0.18s;
}
.chat-panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.92) translateY(8px);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--indigo);
  color: #fff;
}
.chat-header-left { display: flex; align-items: center; gap: 9px; }
.chat-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.chat-title   { font-size: 14px; font-weight: 700; }
.chat-sub     { font-size: 11px; opacity: 0.75; }
.chat-close   { background: transparent; border: none; color: #fff; cursor: pointer; font-size: 18px; opacity: 0.8; padding: 2px; }
.chat-close:hover { opacity: 1; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg2);
}

.chat-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 100%;
}
.chat-msg.user  { flex-direction: row-reverse; }
.chat-msg-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--indigo-dim); color: var(--indigo);
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.chat-msg.user .chat-msg-avatar { background: var(--indigo); color: #fff; }
.chat-bubble-text {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px 14px 14px 4px;
  padding: 9px 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  max-width: 260px;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-msg.user .chat-bubble-text {
  background: var(--indigo);
  color: #fff;
  border-color: transparent;
  border-radius: 14px 14px 4px 14px;
}

.chat-typing {
  display: flex; gap: 4px; align-items: center; padding: 4px 0;
}
.chat-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text3);
  animation: typing-bounce 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.chat-welcome {
  text-align: center;
  padding: 20px 12px;
  color: var(--text3);
  font-size: 12px;
  line-height: 1.6;
}
.chat-welcome strong { display: block; color: var(--text2); margin-bottom: 4px; font-size: 13px; }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  resize: none;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  line-height: 1.4;
  max-height: 80px;
  outline: none;
  transition: border-color 0.15s;
}
.chat-input:focus { border-color: var(--indigo); }
.chat-input::placeholder { color: var(--text3); }
.chat-send {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--indigo); color: #fff; border: none;
  cursor: pointer; font-size: 16px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  align-self: flex-end;
  transition: opacity 0.15s;
}
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-send:not(:disabled):hover { opacity: 0.85; }

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }
