:root {
  --bg: #111317;
  --card: #1a1d23;
  --card2: #22262e;
  --line: #2e333d;
  --text: #e7e9ee;
  --muted: #8d95a3;
  --accent: #e2b341;
  --ok: #4ec07a;
  --bad: #e0614f;
  --tap: 46px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: env(safe-area-inset-bottom); }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--bad); min-height: 1.2em; margin: 6px 0 0; font-size: 14px; }
.ok { color: var(--ok); min-height: 1.2em; margin: 6px 0 0; font-size: 14px; }

header {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg); border-bottom: 1px solid var(--line);
  padding: 10px 14px calc(10px); padding-top: calc(10px + env(safe-area-inset-top));
}

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.badge {
  background: var(--card2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 10px; font-size: 12px;
}

.sync { margin-left: auto; font-size: 12px; color: var(--accent); }

main { padding: 12px 14px 86px; max-width: 760px; margin: 0 auto; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; margin-bottom: 12px;
}

h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 16px; margin: 0 0 8px; }
h3 { font-size: 15px; margin: 0 0 4px; }

label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }

input, button, select, textarea {
  font: inherit; color: var(--text);
  background: var(--card2); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 12px; min-height: var(--tap);
}

input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  cursor: pointer; background: var(--card2); font-weight: 600;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: #17191d; border-color: var(--accent); }
button.ghost { background: transparent; color: var(--muted); }
button.danger { background: transparent; color: var(--bad); border-color: transparent; min-height: 34px; padding: 4px 8px; }

form.inline { display: flex; gap: 8px; }
form.inline input { flex: 1; min-width: 0; }

#login { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
#login .card { width: 100%; max-width: 340px; }
#login button { width: 100%; }

/* --- session checklist --- */

.exercise { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; overflow: hidden; }
.exercise > .head { padding: 12px 14px; }
.exercise .num { color: var(--muted); font-variant-numeric: tabular-nums; }
.exercise .meta { color: var(--muted); font-size: 13px; margin-top: 3px; }
.exercise.done .head { border-left: 3px solid var(--ok); }

.setrow {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-top: 1px solid var(--line);
}
.setrow .tag { width: 42px; color: var(--muted); font-size: 13px; }
.setrow input { min-height: 42px; padding: 8px 10px; width: 100%; min-width: 0; }
.setrow .fields { display: flex; gap: 8px; flex: 1; min-width: 0; }
.setrow .logged { flex: 1; font-variant-numeric: tabular-nums; }
.setrow.is-done { background: #171a1f; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { color: var(--muted); font-weight: 600; }

#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar button {
  flex: 1; border: 0; border-radius: 0; background: transparent;
  color: var(--muted); min-height: 56px; font-size: 13px;
}
#tabbar button.active { color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }

.tabs-sub { margin-bottom: 10px; }
.chip { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.chip.active { background: var(--accent); color: #17191d; border-color: var(--accent); }

/* --- markdown, anywhere it is rendered -------------------------------------
   Everything here is defensive about width: a coach reply can contain a long
   unbroken path, a wide table or a code block, and none of them may stretch
   the page. The container stays put; the content wraps or scrolls inside it. */

.md { min-width: 0; max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; }
.md h1 { font-size: 19px; margin: 14px 0 6px; }
.md h2 { font-size: 17px; margin: 16px 0 6px; }
.md h3, .md h4, .md h5, .md h6 { font-size: 15px; margin: 12px 0 4px; color: var(--accent); }
.md ul, .md ol { padding-left: 20px; margin: 0 0 8px; }
.md li { margin-bottom: 4px; }
.md li > p { margin: 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.md blockquote {
  border-left: 3px solid var(--line); margin: 8px 0; padding: 2px 0 2px 12px;
  color: var(--muted);
}
.md blockquote p:last-child { margin-bottom: 0; }

.md code {
  background: var(--card2); padding: 1px 5px; border-radius: 5px;
  font-size: 13px; overflow-wrap: anywhere;
}
.md pre {
  background: var(--card2); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; margin: 0 0 8px;
  max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain;
}
.md pre code { background: none; padding: 0; white-space: pre; }

/* A table scrolls sideways in its own box instead of breaking the layout. */
.md .tablewrap, .md > table {
  max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch; margin: 0 0 10px;
}
.md table { width: auto; min-width: 100%; border-collapse: collapse; }
.md th, .md td {
  border-bottom: 1px solid var(--line); padding: 6px 8px;
  font-size: 14px; text-align: left; vertical-align: top;
  white-space: normal; overflow-wrap: anywhere; min-width: 86px;
}
.md th { color: var(--accent); font-weight: 600; white-space: nowrap; }

/* --- charts --------------------------------------------------------------- */

.chartbox { position: relative; height: 240px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.stat { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.stat .n { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { color: var(--muted); font-size: 12px; }
#lift-pick { width: 100%; margin-bottom: 8px; }

/* --- chat ------------------------------------------------------------------
   The log scrolls inside itself so the composer and the tab bar stay put. */

#chat-log {
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 10px; min-width: 0;
  max-height: calc(100dvh - 300px); min-height: 180px;
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding-right: 2px;
}

.msg {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  min-width: 0; max-width: 100%;
}
.msg.marc { background: var(--card2); align-self: flex-end; max-width: min(85%, 52ch); }
.msg.coach { background: var(--card); align-self: stretch; }
.msg .who {
  color: var(--muted); font-size: 11px; text-transform: uppercase;
  letter-spacing: .04em; margin-bottom: 4px;
}
.msg.pending { border-style: dashed; color: var(--muted); }
.msg.failed { border-color: var(--bad); }

#chat-form { background: var(--bg); padding: 4px 0 0; }
.spin { display: inline-block; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .35 } 50% { opacity: 1 } }

/* The Plan tab renders the same markdown, just without a height cap. */
#doc-body.md { max-height: none; }

button.big { width: 100%; margin: 10px 0 4px; min-height: 52px; font-size: 16px; }
