:root {
  --bg: #F0F4F8;
  --card: #FFFFFF;
  --navy: #1B2D45;
  --teal: #2A7C76;
  --teal-light: #E6F4F3;
  --coral: #D95F3B;
  --coral-light: #FDF0EC;
  --gold: #C9963A;
  --gold-light: #FDF5E6;
  --muted: #6B7A8D;
  --border: #E2E8F0;
  --green: #2D7A4F;
  --green-light: #E8F5EE;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', system-ui, sans-serif;
  color: var(--navy);
  overscroll-behavior-y: none;
}
#app { padding-bottom: env(safe-area-inset-bottom); min-height: 100vh; }

/* Header */
header {
  background: var(--navy);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 16px) 20px 14px;
  position: sticky;
  top: 0;
  z-index: 10;
}
header .topline { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
header .eyebrow { font-size: 11px; color: #7B9CC4; letter-spacing: 2px; text-transform: uppercase; margin-bottom: 4px; }
header h1 { font-size: 21px; font-weight: 800; margin: 0; letter-spacing: -0.5px; }
header p { color: #A8BFDB; font-size: 12.5px; margin: 8px 0 0; }

.userbox { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

main { max-width: 760px; margin: 0 auto; padding: 18px 14px 60px; }

/* Avatars */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: var(--teal); color: #fff; font-weight: 800; font-size: 12px;
}
.avatar.sm { width: 24px; height: 24px; font-size: 10px; }

/* Sub-navigation (tabs inside coach/client) */
.subnav { display: flex; gap: 6px; margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.subnav::-webkit-scrollbar { display: none; }
.subnav-btn {
  padding: 8px 16px; border-radius: 20px; border: 1px solid var(--border); cursor: pointer;
  font-weight: 600; font-size: 13px; white-space: nowrap; background: var(--card); color: var(--muted);
  font-family: inherit;
}
.subnav-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* Section / card */
.section, .tracker {
  background: var(--card); border-radius: 16px; padding: 18px;
  box-shadow: 0 2px 12px rgba(27,45,69,0.07); margin-bottom: 16px;
}
.tracker h3 { font-size: 15px; margin: 0 0 12px; }
.tracker-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }

/* Form rows */
.tracker-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.tracker-row label { font-size: 12.5px; color: var(--muted); width: 96px; flex-shrink: 0; }
.tracker-row input, .tracker-row select, .tracker-row textarea {
  flex: 1; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 14px; font-family: inherit; min-width: 0; background: #fff; color: var(--navy);
}
.tracker-row textarea { resize: vertical; }
.tracker-row input:focus, .tracker-row select:focus, .tracker-row textarea:focus {
  outline: 2px solid var(--teal); border-color: var(--teal);
}

.save-msg { font-size: 11.5px; color: var(--green); margin-top: 6px; min-height: 14px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 4px 2px 16px; }
.muted { color: var(--muted); }

/* Buttons */
.primary-btn {
  width: 100%; padding: 11px; border: none; border-radius: 8px; background: var(--teal);
  color: #fff; font-weight: 700; font-size: 14px; font-family: inherit; margin-top: 6px; cursor: pointer;
}
.primary-btn:disabled { opacity: 0.6; cursor: default; }
.clear-btn {
  background: none; border: 1px solid var(--border); color: var(--muted);
  font-size: 12px; padding: 8px 14px; border-radius: 8px; font-family: inherit; cursor: pointer; width: 100%;
}
.link-btn { background: none; border: none; color: var(--teal); font-size: 12.5px; font-weight: 600; font-family: inherit; cursor: pointer; padding: 0; }
.back-btn { background: none; border: none; color: var(--muted); font-size: 13px; font-weight: 600; font-family: inherit; cursor: pointer; padding: 4px 0; margin-bottom: 8px; }
.del-btn { background: none; border: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 4px; flex-shrink: 0; }
.del-btn:hover { color: var(--coral); }
.copy-btn { background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3); color: #fff; font-size: 12px; font-weight: 700; padding: 8px 16px; border-radius: 8px; font-family: inherit; cursor: pointer; }

/* Coach code banner */
.code-banner {
  background: var(--navy); color: #fff; border-radius: 14px; padding: 16px 18px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.code-label { font-size: 10.5px; color: #A8BFDB; text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 4px; }
.code-value { font-size: 26px; font-weight: 800; letter-spacing: 4px; }

/* Card lists (clients, plans) */
.card-list { display: flex; flex-direction: column; gap: 8px; }
.client-row, .plan-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; font-family: inherit; cursor: pointer;
}
.client-row:hover, .plan-row:hover { border-color: var(--teal); }
.client-name { font-weight: 700; font-size: 14.5px; color: var(--navy); flex: 1; }
.plan-row-main { flex: 1; }
.plan-row-title { font-weight: 700; font-size: 14.5px; color: var(--navy); margin-bottom: 4px; }
.plan-row-sub { font-size: 12px; display: flex; align-items: center; gap: 6px; }
.chev { color: var(--muted); font-size: 20px; flex-shrink: 0; }

/* Role picker */
.role-grid { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.role-card {
  flex: 1; min-width: 150px; background: var(--card); border: 1.5px solid var(--border);
  border-radius: 14px; padding: 18px 14px; text-align: center; cursor: pointer; font-family: inherit;
}
.role-card:hover { border-color: var(--teal); }
.role-card:disabled { opacity: 0.5; cursor: default; }
.role-emoji { font-size: 30px; margin-bottom: 8px; }
.role-title { font-weight: 800; font-size: 15px; color: var(--navy); margin-bottom: 4px; }
.role-desc { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* Plan content (read-only) */
.plan-section { padding: 8px 0; border-top: 1px solid var(--border); }
.plan-section:first-child { border-top: none; }
.plan-section-title { font-weight: 800; font-size: 13.5px; color: var(--navy); margin-bottom: 6px; }
.plan-items { margin: 0; padding-left: 20px; }
.plan-items li { color: var(--muted); font-size: 13.5px; line-height: 1.7; }

/* Tags */
.tag { display: inline-block; border-radius: 6px; padding: 3px 9px; font-size: 11px; font-weight: 700; }

/* Section editor */
.sec-edit { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.sec-edit-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.sec-title { flex: 1; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 13.5px; font-weight: 700; font-family: inherit; }
.sec-items { width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 13.5px; font-family: inherit; resize: vertical; }
.sec-del { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; padding: 0 4px; }
.sec-del:hover { color: var(--coral); }

/* Assignment checkboxes */
.assign-list { display: flex; flex-direction: column; gap: 4px; }
.assign-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; font-size: 14px; cursor: pointer; }
.assign-row input { width: 18px; height: 18px; accent-color: var(--teal); }

/* History */
.history { margin-top: 6px; max-height: 360px; overflow-y: auto; }
.history-row {
  display: flex; justify-content: space-between; align-items: center; padding: 7px 0;
  border-bottom: 1px solid var(--border); font-size: 12.5px; gap: 8px;
}
.history-row:last-child { border-bottom: none; }
.history-row .date { color: var(--muted); flex-shrink: 0; }
.history-row .vals { color: var(--navy); font-weight: 600; flex: 1; text-align: right; }
.log-note { font-size: 12px; color: var(--muted); font-style: italic; padding: 2px 0 8px; border-bottom: 1px solid var(--border); }
.empty-hist { color: var(--muted); font-size: 12.5px; font-style: italic; padding: 10px 0; text-align: center; }

/* Sync pill */
.sync-pill { font-size: 11px; font-weight: 600; color: var(--muted); }

/* Sign-in / errors */
.signin-card { text-align: center; }
.auth-error {
  background: var(--coral-light); color: var(--coral); border: 1px solid var(--coral);
  border-radius: 8px; padding: 10px 12px; font-size: 12.5px; line-height: 1.5;
  margin-bottom: 14px; text-align: left; word-break: break-word;
}
.google-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--navy); font-weight: 700; font-size: 14px; font-family: inherit; cursor: pointer;
}
.google-btn:disabled { opacity: 0.6; cursor: default; }
.google-btn .g-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%; background: #4285F4; color: #fff; font-weight: 800; font-size: 13px;
}

/* ===== Weekly plan: viewer ===== */
.goals-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.goal-chip {
  background: var(--navy); color: #fff; border-radius: 12px; padding: 8px 14px;
  display: flex; flex-direction: column; min-width: 90px;
}
.goal-chip .goal-name { font-size: 10px; color: #A8BFDB; text-transform: uppercase; letter-spacing: 1px; }
.goal-chip .goal-val { font-size: 16px; font-weight: 800; }

.week-card {
  background: var(--card); border-radius: 14px; margin-bottom: 10px;
  box-shadow: 0 2px 12px rgba(27,45,69,0.07); overflow: hidden; border: 1px solid var(--border);
}
.week-card.current { border-color: var(--teal); box-shadow: 0 2px 14px rgba(42,124,118,0.18); }
.week-sum {
  list-style: none; cursor: pointer; padding: 14px 16px; display: flex;
  justify-content: space-between; align-items: center; gap: 10px;
}
.week-sum::-webkit-details-marker { display: none; }
.week-sum::after { content: "▸"; color: var(--muted); font-size: 13px; transition: transform 0.15s; }
details[open] > .week-sum::after { transform: rotate(90deg); }
.week-no { font-weight: 800; font-size: 14.5px; color: var(--navy); }
.cur-pill { background: var(--teal); color: #fff; font-size: 9.5px; font-weight: 700; padding: 2px 7px; border-radius: 10px; text-transform: uppercase; letter-spacing: 0.5px; margin-left: 6px; vertical-align: middle; }
.week-meta { font-size: 11.5px; color: var(--muted); text-align: right; }

.wgrid { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.wday { display: flex; gap: 10px; padding: 8px; border-radius: 8px; background: var(--bg); align-items: flex-start; }
.wday.is-today { background: var(--teal-light); outline: 1.5px solid var(--teal); }
.wday-head { display: flex; flex-direction: column; min-width: 46px; flex-shrink: 0; }
.wday-head .day-name { font-weight: 800; font-size: 12px; color: var(--navy); }
.wday-head .day-date { font-size: 10px; color: var(--muted); }
.wday-body { font-size: 12.5px; color: var(--navy); line-height: 1.5; flex: 1; min-width: 0; }
.wday-body .day-rest { color: var(--muted); }
.wday-titlerow { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.day-type-tag { font-size: 9.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; padding: 2px 8px; border-radius: 20px; }
.wday-title { font-weight: 800; font-size: 12.5px; color: var(--navy); }
.wday-body .ex-list { list-style: none; margin: 0; padding: 0; }
.wday-body .ex-list li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px solid rgba(27,45,69,0.06); }
.wday-body .ex-list li:last-child { border-bottom: none; }
.ex-name { font-weight: 600; color: var(--navy); }
.ex-detail { font-size: 11.5px; color: var(--muted); font-weight: 600; flex-shrink: 0; }
.ex-opt { font-size: 9.5px; color: var(--gold); font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.ex-equip { display: block; font-size: 10.5px; color: var(--teal); font-weight: 500; margin-top: 1px; }
.day-text { white-space: normal; }
.wday-body .day-note { font-size: 11.5px; color: var(--muted); font-style: italic; margin-top: 6px; line-height: 1.5; }

.pace-table, .ref-body { padding: 4px 16px 14px; }
.pace-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.pace-row:last-child { border-bottom: none; }
.pace-label { color: var(--muted); font-weight: 600; }
.pace-val { color: var(--teal); font-weight: 700; }
.ref-body p { font-size: 12.5px; color: var(--muted); line-height: 1.6; margin: 0 0 8px; }

/* ===== Weekly plan: editor ===== */
.wk-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.wk-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.wk-no { font-weight: 800; font-size: 13.5px; color: var(--navy); }
.wk-del { background: none; border: 1px solid var(--border); color: var(--muted); font-size: 11px; padding: 4px 10px; border-radius: 6px; cursor: pointer; font-family: inherit; }
.wk-del:hover { color: var(--coral); border-color: var(--coral); }
.wk-meta { display: flex; gap: 8px; margin-bottom: 10px; }
.wk-phase { flex: 2; }
.wk-total { flex: 1; min-width: 0; }
.wk-meta input { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px; font-family: inherit; }
.wk-days { display: flex; flex-direction: column; gap: 10px; }
.wk-day-edit { border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.wk-day-top { display: flex; align-items: center; gap: 8px; }
.wk-day-name { width: 34px; flex-shrink: 0; font-size: 12px; font-weight: 800; color: var(--navy); }
.wk-dtype { flex: 1; min-width: 0; padding: 7px 9px; border-radius: 8px; border: 1px solid var(--border); font-size: 12.5px; font-family: inherit; }
.wk-dmode { flex-shrink: 0; background: var(--bg); border: 1px solid var(--border); color: var(--muted); font-size: 11px; font-weight: 700; padding: 6px 10px; border-radius: 8px; cursor: pointer; font-family: inherit; }
.wk-dtitle, .wk-dnote { padding: 7px 9px; border-radius: 8px; border: 1px solid var(--border); font-size: 12.5px; font-family: inherit; }
.wk-dnote { font-style: italic; }
.wk-dtext { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px; font-family: inherit; resize: vertical; min-width: 0; }
.wk-ex-list { display: flex; flex-direction: column; gap: 5px; }
.wk-ex-row { display: flex; gap: 5px; align-items: center; }
.wk-ex-name { flex: 2; min-width: 0; }
.wk-ex-presc { flex: 1; min-width: 0; width: 60px; }
.wk-ex-equip { flex: 1; min-width: 0; }
.wk-ex-row input[type="text"] { padding: 7px 8px; border-radius: 7px; border: 1px solid var(--border); font-size: 12px; font-family: inherit; }
.wk-ex-opt { display: flex; align-items: center; gap: 3px; font-size: 10px; color: var(--muted); flex-shrink: 0; }
.wk-ex-opt input { width: 14px; height: 14px; accent-color: var(--gold); }
.wk-ex-del { background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; flex-shrink: 0; padding: 0 2px; }
.wk-ex-del:hover { color: var(--coral); }
.wk-ex-add { background: none; border: 1px dashed var(--border); color: var(--teal); font-size: 12px; font-weight: 600; padding: 6px; border-radius: 8px; cursor: pointer; font-family: inherit; width: 100%; margin-top: 2px; }

.kv-row { display: flex; gap: 8px; margin-bottom: 6px; align-items: center; }
.kv-a, .kv-b { flex: 1; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px; font-family: inherit; min-width: 0; }

.assign-start { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); font-size: 12px; font-family: inherit; flex-shrink: 0; }

/* ===== Workout logging ===== */
.planned-box { background: var(--bg); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 12.5px; }
.status-btns { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.status-btn { flex: 1; min-width: 64px; padding: 8px 6px; border: 1.5px solid var(--border); border-radius: 8px; background: var(--card); color: var(--muted); font-weight: 700; font-size: 12px; font-family: inherit; cursor: pointer; }
.status-btn.active { border-color: var(--sc); color: var(--sc); background: color-mix(in srgb, var(--sc) 10%, white); }
#w-actual, #w-notes, #pf-lim, #pf-goals { width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 13.5px; font-family: inherit; margin-bottom: 8px; resize: vertical; }

.wlog-row { padding: 8px 0; border-bottom: 1px solid var(--border); }
.wlog-row:last-child { border-bottom: none; }
.wlog-top { display: flex; align-items: center; gap: 8px; }
.wlog-top .date { color: var(--muted); font-size: 12px; flex: 1; }
.wlog-status { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; padding: 2px 8px; border-radius: 20px; }
.wlog-planned, .wlog-actual { font-size: 12px; color: var(--navy); margin-top: 3px; line-height: 1.4; }
.wlog-lbl { color: var(--muted); font-weight: 700; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ===== Profile ===== */
.pf-label { display: block; font-size: 12px; font-weight: 700; color: var(--navy); margin: 12px 0 6px; }
.equip-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.equip-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--navy); background: var(--bg); border: 1px solid var(--border); border-radius: 20px; padding: 5px 10px; cursor: pointer; }
.equip-chip input { accent-color: var(--teal); }

/* ===== AI workout adaptation ===== */
.adapt-banner { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--gold-light); border: 1px solid var(--gold); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 12.5px; color: var(--navy); line-height: 1.5; }
.adapt-tag { display: inline-block; background: var(--gold); color: #fff; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; padding: 2px 8px; border-radius: 10px; margin-right: 6px; }
.adapt-toggle { color: var(--teal) !important; border-color: var(--teal) !important; font-weight: 700; }
.adapt-panel { display: none; margin-top: 8px; padding: 12px; border: 1px dashed var(--teal); border-radius: 10px; background: var(--teal-light); }
.adapt-panel.open { display: block; }
.adapt-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.adapt-chip { background: #fff; border: 1px solid var(--border); border-radius: 20px; padding: 6px 12px; font-size: 12px; font-weight: 600; color: var(--navy); cursor: pointer; font-family: inherit; }
.adapt-chip:hover { border-color: var(--teal); }
#adapt-req { width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 13.5px; font-family: inherit; margin-bottom: 8px; resize: vertical; }
.adapt-preview { margin-top: 12px; background: #fff; border: 1px solid var(--teal); border-radius: 10px; padding: 12px; }
.adapt-preview-head { font-weight: 800; font-size: 12.5px; color: var(--teal); margin-bottom: 8px; }
.adapt-rationale { font-size: 12px; color: var(--muted); font-style: italic; margin-top: 8px; line-height: 1.5; }

/* Chat */
.chat-thread { max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px 0 10px; }
.bubble-row { display: flex; }
.bubble-row.mine { justify-content: flex-end; }
.bubble-row.theirs { justify-content: flex-start; }
.bubble {
  max-width: 78%; padding: 9px 12px; border-radius: 14px; font-size: 13.5px; line-height: 1.45; word-wrap: break-word;
}
.bubble-row.mine .bubble { background: var(--teal); color: #fff; border-bottom-right-radius: 4px; }
.bubble-row.theirs .bubble { background: var(--bg); color: var(--navy); border-bottom-left-radius: 4px; }
.bubble-time { font-size: 9.5px; opacity: 0.7; margin-top: 4px; }
.chat-compose { display: flex; gap: 8px; align-items: center; }
.chat-compose input {
  flex: 1; padding: 10px 12px; border-radius: 20px; border: 1px solid var(--border);
  font-size: 14px; font-family: inherit; min-width: 0;
}
.chat-compose input:focus { outline: 2px solid var(--teal); border-color: var(--teal); }
