/* Relentless Coach Web_Client — dependency-free styling.
 *
 * Design language: "training notebook, calm confidence". Dark-first
 * black/blue palette (gyms and evenings are where this app lives),
 * light theme derived from the same palette for users who prefer it.
 * No hype, no gamification chrome — the UI speaks like the coach does.
 */

:root {
  /* Dark theme (primary) */
  --bg: #0e1116;
  --bg-raised: #161b22;
  --bg-inset: #10151c;
  --fg: #e8edf2;
  --muted: #93a1b0;
  --accent: #4d9fff;      /* actions, coach accent */
  --accent-soft: #163050; /* accent-tinted fills */
  --done: #3ecf8e;        /* completed state */
  --error: #ff7b72;
  --border: #2a3441;
  --focus: #7fbcff;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f9fb;
    --bg-raised: #ffffff;
    --bg-inset: #eef2f6;
    --fg: #16202b;
    --muted: #5b6b7b;
    --accent: #1268c3;
    --accent-soft: #ddebfa;
    --done: #0f8a5f;
    --error: #b42318;
    --border: #d4dde6;
    --focus: #1268c3;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  color: var(--fg);
  background: var(--bg);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

main#root {
  max-width: 44rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

h1 {
  font-size: 1.35rem;
  letter-spacing: 0.01em;
  margin: 0.5rem 0 0.75rem;
}

h2 { font-size: 1.1rem; margin: 1rem 0 0.5rem; }

.muted { color: var(--muted); font-size: 0.9rem; }

.error {
  color: var(--error);
  border: 1px solid var(--error);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  background: color-mix(in srgb, var(--error) 8%, transparent);
}

label { display: block; margin-bottom: 0.3rem; font-weight: 600; }

input,
textarea,
select {
  display: block;
  width: 100%;
  padding: 0.65rem 0.7rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--fg);
  background: var(--bg-inset);
}

select { width: auto; min-width: 12rem; }

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--accent);
}

button {
  min-height: 44px;
  padding: 0.55rem 1.2rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #08121f;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 120ms ease, background-color 120ms ease;
}

button:hover { filter: brightness(1.08); }
button:active { filter: brightness(0.94); }

button.secondary {
  background: transparent;
  color: var(--accent);
}

button:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.actions { display: flex; gap: 0.75rem; margin-top: 1rem; flex-wrap: wrap; }

.terms-document {
  max-height: 24rem;
  overflow-y: auto;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-raised);
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
}

/* ---------------------------------------------------------------- *
 * App header + navigation (bottom tab bar on phones — one-thumb use
 * between sets is the primary context)
 * ---------------------------------------------------------------- */

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.app-header h1 { color: var(--accent); }

.app-nav { display: flex; gap: 0.5rem; margin: 0.75rem 0; }

.app-nav button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  flex: 1;
}

.app-nav button.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

@media (max-width: 640px) {
  main#root { padding-bottom: 6rem; }
  .app-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 0.5rem 0.75rem calc(0.5rem + env(safe-area-inset-bottom));
    background: var(--bg-raised);
    border-top: 1px solid var(--border);
    z-index: 10;
  }
  .app-nav button { min-height: 48px; }
}

/* ---------------------------------------------------------------- *
 * Rendered markdown content (plan viewer; chat has matching rules)
 * ---------------------------------------------------------------- */

.md-content { line-height: 1.6; }
.md-content p { margin: 0.5rem 0; }
.md-content h3, .md-content h4, .md-content h5 {
  margin: 1rem 0 0.35rem;
  color: var(--accent);
}
.md-content ul, .md-content ol { margin: 0.4rem 0; padding-left: 1.4rem; }
.md-content li { margin: 0.2rem 0; }

/* Teaching sub-entries (What/Why/Benefit/Cue under an exercise):
   indented, no bullet marker — supporting detail, not more bullets. */
li:has(> .md-sub) { list-style: none; }
.md-sub {
  display: block;
  padding-left: 1rem;
  font-size: 0.95em;
  color: var(--muted);
}
.md-sub strong { color: var(--fg); }
.md-content hr { border: none; border-top: 1px solid var(--border); margin: 0.8rem 0; }
.md-content code {
  background: var(--bg-inset);
  padding: 0 0.3rem;
  border-radius: 4px;
  font-size: 0.92em;
}
.md-content table {
  border-collapse: collapse;
  margin: 0.6rem 0;
  font-size: 0.92rem;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}
.md-content th, .md-content td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  text-align: left;
  white-space: nowrap;
}
.md-content th { background: var(--bg-inset); color: var(--muted); }

/* My plan viewer: rendered document card. */
.plan-document {
  max-height: none;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-raised);
  margin-top: 0.75rem;
}

#plan-picker { margin-bottom: 0.25rem; }

/* ---------------------------------------------------------------- *
 * Tick-box logging (task 16.2)
 * ---------------------------------------------------------------- */

.checklist {
  list-style: none;
  margin: 1rem 0;
  padding: 0;
}

.checklist-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  margin-bottom: 0.75rem;
  background: var(--bg-raised);
}

.checklist-item.next { border-color: var(--accent); }

.resume-note {
  margin: 0 0 0.25rem;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
}

.item-status { margin: 0.25rem 0 0.5rem; font-size: 0.9rem; color: var(--muted); }
.item-status.done { color: var(--done); }

.item-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.item-actions button { font-size: 0.92rem; padding: 0.45rem 0.8rem; }

.entry-form {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
}

.entry-form label { font-size: 0.9rem; }
.entry-form input { margin-bottom: 0.5rem; }

.stepper { display: flex; gap: 0.5rem; align-items: center; }
.stepper input { width: 6rem; margin-bottom: 0; text-align: center; }
.stepper button { padding: 0.45rem 0.9rem; }

.manual-row { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.manual-row .field input { width: 5rem; margin-bottom: 0; }

button.linklike {
  background: none;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  padding: 0.25rem 0;
  font-size: 0.9rem;
  margin: 0.5rem 0;
  display: block;
  min-height: 0;
}

.entry-rest { margin-top: 0.5rem; }

/* ---------------------------------------------------------------- *
 * Phase 2: recovery check-in card, tick animation, onboarding,      *
 * direct profile edits                                              *
 * ---------------------------------------------------------------- */

/* Recovery check-in card — a quiet raised card below the checklist. */
#recovery-card {
  margin-top: 1.5rem;
  padding: 0.9rem 1rem 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
}

#recovery-card h3 { margin: 0 0 0.25rem; font-size: 1rem; }

.rating-row {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 0.15rem 0.75rem;
  align-items: center;
  margin: 0.6rem 0;
}

.rating-label { font-weight: 600; font-size: 0.92rem; }

.rating-group { display: flex; gap: 0.4rem; }

/* 1–5 tap dots: 44px+ targets, accent fill when selected. */
button.rating-dot {
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-inset);
  color: var(--muted);
  font-weight: 600;
}

button.rating-dot.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--fg);
}

.rating-hints { grid-column: 2; font-size: 0.78rem; }

.recovery-extras {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0.75rem 0 0.25rem;
}

.recovery-extras .field { flex: 1 1 12rem; }
.recovery-extras label { font-size: 0.85rem; }

/* Tick confirmation: one gentle pop + fade-in on the done state —
 * visual acknowledgment, not celebration (no gamification, Req 19.8). */
@keyframes tick-pop {
  0% { transform: scale(0.92); opacity: 0.4; }
  60% { transform: scale(1.04); }
  100% { transform: scale(1); opacity: 1; }
}

.item-status.done.just-done {
  animation: tick-pop 0.35s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .item-status.done.just-done { animation: none; }
}

/* First-run onboarding — the four honest steps, calmly presented. */
#onboarding {
  margin: 0.75rem 0 1.25rem;
  padding: 0.9rem 1rem 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--accent);
  border-radius: 12px;
}

#onboarding h3 { margin: 0 0 0.5rem; font-size: 1.05rem; }

.onboarding-steps { margin: 0 0 0.5rem; padding-left: 1.25rem; }
.onboarding-steps li { margin: 0.35rem 0; }

/* Direct profile edits — collapsed by default beneath the document. */
#profile-edit {
  margin-top: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
}

#profile-edit summary { cursor: pointer; font-weight: 600; }

#profile-edit form { margin-top: 0.75rem; }

#profile-edit input { margin-bottom: 0.75rem; }

/* Fresh-conversation escape hatch — present but quiet. */
.chat-reset { margin-top: 0.5rem; }
.chat-reset button { font-size: 0.85rem; }

/* Adaptation history — collapsed journal, grouped by date, newest first. */
#profile-history {
  margin-top: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
}

#profile-history summary { cursor: pointer; font-weight: 600; }

.history-group { margin: 0.75rem 0; }

.history-date {
  margin: 0 0 0.25rem;
  font-size: 0.85rem;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.history-items {
  margin: 0;
  padding-left: 1.1rem;
}

.history-items li { margin: 0.25rem 0; font-size: 0.92rem; }

#profile-history-more { margin-top: 0.5rem; font-size: 0.85rem; }

/* Nutrition targets card + word-shaped tap dots (Hit / Missed). */
#nutrition-card {
  margin-top: 1.5rem;
  padding: 0.9rem 1rem 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
}

#nutrition-card h3 { margin: 0 0 0.25rem; font-size: 1rem; }

#nutrition-content { font-size: 0.95rem; }

button.rating-dot.rating-word {
  border-radius: 999px;
  padding: 0 0.9rem;
  min-width: 0;
}
