:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --sec-bg: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: #ff8a3d;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--hint); }
.center { display: flex; align-items: center; justify-content: center; min-height: 100vh; text-align: center; padding: 24px; }

#main { padding: 0 14px calc(72px + env(safe-area-inset-bottom)); }
#hdr {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 2px; font-size: 20px; font-weight: 700;
  background: var(--bg);
}
.streak { font-size: 14px; font-weight: 600; color: var(--accent); }
.hdr-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  border: 0; border-radius: 10px; padding: 7px 9px; background: var(--sec-bg);
  color: var(--text); font-size: 17px; cursor: pointer;
}

.tab { padding-top: 4px; }
.card {
  background: var(--sec-bg); border-radius: 14px; padding: 14px;
  margin: 10px 0; white-space: pre-wrap; word-wrap: break-word;
}
.dashboard { white-space: normal; }
.dash-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.small { font-size: 12px; }
.readiness {
  min-width: 74px; height: 74px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; background: #8a8a8e;
}
.readiness span { font-size: 25px; font-weight: 750; line-height: 1; }
.readiness small { font-size: 9px; margin-top: 4px; }
.readiness.good { background: #29a66a; }
.readiness.medium { background: #e6a526; }
.readiness.low { background: #dc5656; }
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.metric {
  display: grid; grid-template-columns: auto 1fr; column-gap: 8px;
  align-items: center; padding: 10px; border-radius: 11px; background: var(--bg);
}
.metric > span { grid-row: 1 / 3; font-size: 20px; }
.metric > b { font-size: 16px; line-height: 1.1; }
.metric > small { color: var(--hint); font-size: 10px; }
.status-line { margin-bottom: 8px; }
.sync-status { margin-top: 8px; color: var(--link); font-size: 11px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mini-btn {
  border: 0; border-radius: 10px; padding: 8px 10px; background: var(--btn);
  color: var(--btn-text); font: inherit; font-size: 12px; font-weight: 650; cursor: pointer;
}
.mini-btn:disabled { opacity: .5; }
.training-calendar { margin-top: 12px; }
.calendar-day {
  display: grid; grid-template-columns: 44px 1fr; gap: 10px;
  padding: 10px 0; border-top: 1px solid rgba(128, 128, 128, .18);
}
.calendar-day:first-child { border-top: 0; }
.calendar-date { text-align: center; color: var(--hint); font-size: 10px; text-transform: uppercase; }
.calendar-date b { display: block; color: var(--text); font-size: 18px; line-height: 1.05; }
.calendar-day.today .calendar-date b { color: var(--btn); }
.calendar-workout { display: grid; grid-template-columns: 30px 1fr; column-gap: 8px; margin-bottom: 8px; }
.calendar-workout:last-child { margin-bottom: 0; }
.workout-icon {
  width: 30px; height: 30px; border-radius: 9px; display: flex;
  align-items: center; justify-content: center; background: var(--bg); font-size: 16px;
}
.workout-title { font-weight: 650; line-height: 1.2; }
.workout-meta, .workout-details { color: var(--hint); font-size: 11px; margin-top: 2px; }
.calendar-workout.completed { opacity: .58; }
.calendar-workout.completed .workout-title { text-decoration: line-through; }
.original-duration { text-decoration: line-through; opacity: .7; }
.adapted-mark { color: var(--accent); font-weight: 650; }
.recommendation { border-left: 4px solid var(--hint); }
.calendar-card, .recommendation { white-space: normal; }
.calendar-details { margin: 10px 0; }
.calendar-details > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px; border-radius: 14px; background: var(--sec-bg); cursor: pointer;
  list-style: none;
}
.calendar-details > summary::-webkit-details-marker { display: none; }
.calendar-details > summary span:first-child { display: flex; flex-direction: column; }
.calendar-details > summary small { color: var(--hint); font-size: 10px; margin-top: 2px; }
.details-chevron { color: var(--hint); font-size: 20px; transition: transform .18s ease; }
.calendar-details[open] > summary .details-chevron { transform: rotate(180deg); }
.calendar-details > .calendar-card { margin: 6px 0 0; }
.calendar-card.calendar-empty {
  padding: 18px;
  border: 1px solid rgba(36, 129, 204, .22);
  background:
    linear-gradient(145deg, rgba(36, 129, 204, .14), rgba(255, 138, 61, .09)),
    var(--sec-bg);
}
.calendar-empty > .section-head { margin-bottom: 4px; }
.calendar-welcome h2 { margin: 12px 0 6px; font-size: 24px; line-height: 1.15; }
.calendar-welcome p { margin: 0; color: var(--hint); }
.calendar-kicker { color: var(--link); font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.calendar-benefits { display: flex; flex-wrap: wrap; gap: 7px; margin: 15px 0 4px; }
.calendar-benefits span {
  padding: 6px 9px; border-radius: 999px; background: var(--bg);
  color: var(--text); font-size: 10px; font-weight: 650;
}
.calendar-cta { box-shadow: 0 8px 20px rgba(36, 129, 204, .22); }
.calendar-trust { color: var(--hint); font-size: 10px; text-align: center; }
.recommendation.good { border-left-color: #29a66a; }
.recommendation.medium { border-left-color: #e6a526; }
.recommendation.low { border-left-color: #dc5656; }
.recommendation-score { font-size: 26px; font-weight: 750; line-height: 1; }
.factor-list { margin: 8px 0 0; padding-left: 18px; color: var(--hint); font-size: 11px; }
.today-card { white-space: normal; border-top: 4px solid var(--hint); }
.today-card.good { border-top-color: #29a66a; }
.today-card.medium { border-top-color: #e6a526; }
.today-card.low { border-top-color: #dc5656; }
.today-kicker, .feedback-kicker {
  color: var(--link); font-size: 10px; font-weight: 800; letter-spacing: .08em;
}
.today-card h2 { margin: 5px 0 6px; font-size: 21px; line-height: 1.16; }
.today-card > p { margin: 0; }
.today-why {
  margin-top: 8px; color: var(--hint); font-size: 11px; line-height: 1.35;
}
.today-workout {
  display: grid; grid-template-columns: 38px 1fr; gap: 10px; align-items: center;
  margin-top: 14px; padding: 11px; border-radius: 12px; background: var(--bg);
}
.today-workout > span {
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  border-radius: 11px; background: var(--sec-bg); font-size: 20px;
}
.today-workout div { display: flex; flex-direction: column; min-width: 0; }
.today-workout small { color: var(--hint); font-size: 9px; text-transform: uppercase; }
.today-workout b { line-height: 1.25; }
.today-workout em { color: var(--hint); font-size: 11px; font-style: normal; margin-top: 2px; }
.today-workout.completed { opacity: .68; }
.today-workout.empty b { font-weight: 600; }
.today-workout.next-workout {
  margin-top: 9px; border: 1px solid rgba(36, 129, 204, .2);
  background: rgba(36, 129, 204, .06);
}
.today-workout.next-workout small { font-size: 10px; text-transform: none; font-weight: 700; }
.today-rest {
  display: grid; grid-template-columns: 38px 1fr; gap: 10px; align-items: center;
  margin-top: 14px; padding: 11px; border-radius: 12px;
  background: rgba(41, 166, 106, .09);
}
.today-rest > span {
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  border-radius: 11px; background: rgba(41, 166, 106, .12); font-size: 20px;
}
.today-rest div { display: flex; flex-direction: column; min-width: 0; }
.today-rest small { color: var(--hint); font-size: 10px; }
.today-rest b { line-height: 1.25; }
.today-rest em { color: var(--hint); font-size: 11px; font-style: normal; margin-top: 2px; }
.today-rest.empty { background: var(--bg); }
.today-rest.empty > span { background: var(--sec-bg); }
.today-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.restore-adjustment { margin-top: 10px; width: 100%; }
.apply-adjustment { margin-top: 10px; width: 100%; background: var(--sec-bg); color: var(--link); border: 1px solid var(--link); }
.feedback-adapt-btn { margin-top: 9px; width: 100%; }
.calendar-day-restore { border: 0; background: transparent; color: var(--accent); padding: 7px 0 0; font-size: 12px; font-weight: 600; }
.today-action, .feeling-btn {
  border: 1px solid transparent; border-radius: 11px; padding: 10px 8px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 12px;
  font-weight: 650; cursor: pointer;
}
.today-action.on { border-color: var(--btn); color: var(--btn); }
.today-action:disabled, .feeling-btn:disabled { opacity: .5; }
.decision-status {
  margin-top: 10px; padding: 9px 10px; border-radius: 10px;
  background: rgba(36, 129, 204, .1); color: var(--link); font-size: 11px;
}
.workout-feedback-card { white-space: normal; }
.workout-feedback-card > b { display: block; margin-top: 4px; font-size: 17px; }
.workout-feedback-inline {
  margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(128, 128, 128, .18);
  white-space: normal;
}
.workout-feedback-inline > b { display: block; margin-top: 4px; }
.feeling-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 10px; }
.feeling-btn { background: var(--bg); border-color: rgba(128, 128, 128, .16); }
.workout-feedback-inline .feeling-btn { background: var(--sec-bg); }
.feeling-btn.pain { color: #c64646; }
.feeling-result { margin-top: 10px; font-size: 12px; }
.pain-warning {
  padding: 10px; border-radius: 10px; background: rgba(220, 86, 86, .12); color: #c64646;
}
.toggle-row {
  display: flex; align-items: flex-start; gap: 10px; padding-top: 12px; margin-top: 10px;
  border-top: 1px solid rgba(128, 128, 128, .18); cursor: pointer;
}
.toggle-row input { width: 20px; height: 20px; accent-color: var(--btn); flex: 0 0 auto; }
.toggle-row span { display: flex; flex-direction: column; }
.toggle-row small { color: var(--hint); font-size: 10px; margin-top: 2px; }
.legacy-plan { margin: 12px 0; }
.legacy-plan > summary { color: var(--link); cursor: pointer; font-weight: 600; padding: 8px 2px; }
.row { display: flex; gap: 8px; margin: 10px 0; }

.btn {
  appearance: none; border: 0; border-radius: 12px;
  background: var(--btn); color: var(--btn-text);
  padding: 12px 14px; font-size: 15px; font-weight: 600;
  cursor: pointer; flex: 1;
}
.btn.secondary { background: var(--sec-bg); color: var(--text); }
.btn.full { width: 100%; margin: 12px 0; }
.btn:active { opacity: .7; }
.btn:disabled { opacity: .5; }

.field { margin: 12px 0; }
.field label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--hint); }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--sec-bg);
  background: var(--sec-bg); color: var(--text); font: inherit; font-size: 16px;
}
.field textarea { resize: vertical; min-height: 110px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 10px 14px; border-radius: 12px; background: var(--sec-bg);
  color: var(--text); border: 1.5px solid transparent; cursor: pointer; font-size: 14px;
}
.chip.on { border-color: var(--btn); color: var(--btn); font-weight: 600; }
.chips.rpe .chip { flex: 1; min-width: 36px; text-align: center; padding: 10px 0; }

/* nav */
#nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--bg);
  border-top: 1px solid var(--sec-bg);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; border: 0; background: none; color: var(--hint);
  font-size: 20px; padding: 8px 0 10px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.nav-btn span { font-size: 11px; }
.nav-btn.active { color: var(--btn); }

/* progress */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.stat { background: var(--sec-bg); border-radius: 12px; padding: 12px; }
.stat .num { font-size: 22px; font-weight: 700; }
.stat .lbl { font-size: 12px; color: var(--hint); }
.cal { display: flex; gap: 6px; margin: 10px 0; }
.cal .day { flex: 1; text-align: center; }
.cal .dot { height: 26px; border-radius: 8px; background: var(--sec-bg); display: flex; align-items: center; justify-content: center; font-size: 13px; }
.cal .dot.done { background: var(--accent); color: #fff; }
.cal .dl { font-size: 10px; color: var(--hint); margin-top: 3px; }
svg.chart { width: 100%; height: 120px; display: block; }
.plan-fact-card { white-space: normal; }
.plan-fact-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.plan-fact-score { font-size: 25px; font-weight: 800; color: var(--link); }
.plan-fact-stats { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 10px; }
.plan-fact-stats span {
  padding: 5px 8px; border-radius: 999px; background: var(--bg);
  color: var(--hint); font-size: 10px;
}
.plan-fact-list { margin-top: 10px; }
.plan-fact-row {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 8px; align-items: start;
  padding: 8px 0; border-top: 1px solid rgba(128, 128, 128, .16);
}
.plan-fact-row:first-child { border-top: 0; }
.plan-fact-date { color: var(--hint); font-size: 10px; }
.plan-fact-row b { display: block; font-size: 12px; line-height: 1.25; }
.plan-fact-row small { display: block; color: var(--hint); font-size: 10px; margin-top: 2px; }
.fact-state { font-size: 10px; font-weight: 750; white-space: nowrap; }
.fact-state.completed { color: #29a66a; }
.fact-state.missed { color: #c64646; }
.fact-state.rest { color: var(--hint); }
.data-details { margin: 10px 0; }
.data-details > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px; border-radius: 14px; background: var(--sec-bg); cursor: pointer;
  list-style: none;
}
.data-details > summary::-webkit-details-marker { display: none; }
.data-details > summary span:first-child { display: flex; flex-direction: column; }
.data-details > summary small { color: var(--hint); font-size: 10px; margin-top: 2px; }
.data-details[open] > summary .details-chevron { transform: rotate(180deg); }
.activity-data-card { margin-top: 6px; white-space: normal; }
.activity-list { margin-top: 9px; }
.activity-row {
  padding: 11px 0; border-top: 1px solid rgba(128, 128, 128, .16);
}
.activity-row:first-child { border-top: 0; }
.activity-row.ignored { opacity: .55; }
.activity-head { display: flex; justify-content: space-between; gap: 10px; }
.activity-head b { line-height: 1.25; }
.activity-badges { display: flex; flex-wrap: wrap; gap: 5px; margin: 5px 0; }
.activity-badge {
  padding: 3px 6px; border-radius: 999px; background: var(--bg);
  color: var(--hint); font-size: 9px; font-weight: 700;
}
.activity-badge.garmin { color: #287e66; }
.activity-badge.duplicate { color: #b67700; }
.activity-match { color: var(--hint); font-size: 10px; }
.activity-match.matched { color: #24815f; }
.activity-actions { display: flex; gap: 6px; margin-top: 8px; }
.activity-action {
  border: 0; border-radius: 9px; padding: 7px 9px; background: var(--bg);
  color: var(--text); font: inherit; font-size: 10px; font-weight: 650; cursor: pointer;
}
.activity-action.danger { color: #c64646; }
.activity-action:disabled { opacity: .5; }

/* chat */
#tab-chat { display: flex; flex-direction: column; height: calc(100vh - 120px); }
#chat-log { flex: 1; overflow-y: auto; padding: 8px 0; }
.msg { max-width: 82%; padding: 9px 12px; border-radius: 14px; margin: 6px 0; white-space: pre-wrap; }
.msg.me { background: var(--btn); color: var(--btn-text); margin-left: auto; border-bottom-right-radius: 4px; }
.msg.coach { background: var(--sec-bg); border-bottom-left-radius: 4px; }
.chat-input { display: flex; gap: 8px; padding: 8px 0 12px; }
.chat-input input { flex: 1; padding: 12px; border-radius: 20px; border: 1px solid var(--sec-bg); background: var(--sec-bg); color: var(--text); font-size: 16px; }
.chat-input .btn { flex: 0 0 48px; border-radius: 50%; }

#screen-onboard { min-height: 100vh; padding: 18px 14px 28px; }
.onboard-shell {
  width: min(100%, 520px); margin: 0 auto; padding: 18px;
  border-radius: 20px; background: var(--bg); box-shadow: 0 8px 30px rgba(0, 0, 0, .06);
}
.onboard-shell .big { font-size: 42px; text-align: center; }
.onboard-shell h2 { margin: 6px 0; text-align: center; }
.onboard-shell h3 { margin: 18px 0 4px; }
.onboard-head > p, #onboard-garmin > p, .center-card > p { text-align: center; }
.onboard-progress { display: flex; justify-content: center; gap: 7px; margin: 16px 0; }
.onboard-progress i {
  display: block; width: 24px; height: 5px; border-radius: 99px; background: var(--sec-bg);
}
.onboard-progress i.on { background: var(--btn); }
.onboard-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.onboard-grid .field { min-width: 0; }
.onboard-step .field textarea { min-height: 72px; }
.onboard-actions { display: flex; gap: 8px; margin-top: 18px; }
.onboard-error {
  margin-top: 10px; padding: 9px 11px; border-radius: 10px;
  background: rgba(220, 86, 86, .12); color: #c64646; font-size: 12px;
}
.privacy-note {
  margin: 14px 0; padding: 11px; border-radius: 12px;
  background: var(--sec-bg); color: var(--hint); font-size: 11px; line-height: 1.4;
}
.text-btn {
  display: block; width: 100%; border: 0; background: transparent; color: var(--link);
  padding: 10px; font: inherit; font-weight: 600; cursor: pointer;
}
.text-btn.compact { width: auto; padding: 7px 0; text-align: left; font-size: 12px; }
#ob-garmin-status { min-height: 20px; margin-top: 8px; text-align: center; }
.center-card { margin-top: 18vh; text-align: center; }
.spinner { color: var(--hint); font-style: italic; }

.modal {
  position: fixed; inset: 0; z-index: 20; padding: 18px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .45);
}
.modal-card {
  width: min(100%, 480px); max-height: calc(100vh - 36px); overflow-y: auto;
  padding: 18px; border-radius: 18px; background: var(--bg); color: var(--text);
}
.modal-card h3 { margin: 0 0 6px; }
.settings-modal-card h4 { margin: 14px 0 4px; }
.settings-time-grid { grid-template-columns: 1fr 1fr; }
.settings-divider { border: 0; border-top: 1px solid var(--sec-bg); margin: 18px 0; }
.btn.danger { background: rgba(220, 86, 86, .12); color: #c64646; }
