:root {
  color-scheme: light;
  --page: #f9f9f7; --surface: #fcfcfb; --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7; --ring: rgba(11,11,11,0.10);
  --s1: #2a78d6; --s3: #1baf7a; --rest: #c3c2b7;
  --o1: #86b6ef; --o2: #2a78d6; --o3: #104281;         /* ordinal blue: easy → hard */
  --good: #0ca30c; --critical: #d03b3b; --accent: #2a78d6;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --ring: rgba(255,255,255,0.10);
    --s1: #3987e5; --s3: #199e70; --rest: #4a4a46;
    --o1: #184f95; --o2: #3987e5; --o3: #9ec5f4;        /* on dark, harder = brighter */
    --accent: #3987e5;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); font: 15px/1.45 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 2px; }
.sub { color: var(--ink-2); margin: 0 0 10px; font-size: .9rem; }

.top { display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: var(--surface);
       border-bottom: 1px solid var(--ring); position: sticky; top: 0; z-index: 2; }
.brand { font-weight: 600; color: var(--ink); }
.top nav { display: flex; gap: 16px; flex: 1; }
.top nav a { color: var(--ink-2); padding: 4px 0; }
.top nav a[aria-current="page"] { color: var(--ink); border-bottom: 2px solid var(--accent); }
.logout { margin: 0; }

main { max-width: 1040px; margin: 0 auto; padding: 20px 24px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.back { font-size: .9rem; }
.card { background: var(--surface); border: 1px solid var(--ring); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; }

button { font: inherit; padding: 7px 14px; border-radius: 7px; border: 1px solid transparent;
         background: var(--accent); color: #fff; cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
button.ghost { background: transparent; color: var(--ink-2); border-color: var(--ring); }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--ring); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.t-label { color: var(--ink-2); font-size: .85rem; }
.t-value { font-size: 1.7rem; font-weight: 600; }
.t-value small { font-size: .9rem; font-weight: 400; color: var(--ink-2); }
.t-sub { color: var(--muted); font-size: .8rem; }

.sync { display: flex; align-items: center; gap: 12px; }
.sync-text { display: flex; flex-direction: column; align-items: flex-end; font-size: .85rem; }
.sync-state::before { content: "●"; margin-right: 6px; color: var(--muted); }
.sync[data-state="ok"] .sync-state::before { content: "✓"; color: var(--good); }
.sync[data-state="error"] .sync-state::before { content: "!"; color: var(--critical); font-weight: 700; }
.sync[data-state="running"] .sync-state::before { content: "↻"; color: var(--accent); }
.sync-msg { color: var(--ink-2); max-width: 360px; text-align: right; }

table.data { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data th { text-align: left; color: var(--ink-2); font-weight: 500; border-bottom: 1px solid var(--axis); padding: 6px 8px; }
table.data td { border-bottom: 1px solid var(--grid); padding: 6px 8px; }
table.data .n { text-align: right; font-variant-numeric: tabular-nums; }
table.data th small { color: var(--muted); font-weight: 400; }
table.data tbody tr:hover { background: var(--grid); }
section.card { overflow-x: auto; }

/* charts */
svg.chart { width: 100%; height: auto; display: block; }
svg.chart .grid { stroke: var(--grid); stroke-width: 1; }
svg.chart .baseline { stroke: var(--axis); stroke-width: 1; }
svg.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
svg.chart .tick.unit, svg.chart .tick.zone { font-size: 10px; }
svg.chart .value { fill: var(--ink); font-size: 12px; font-weight: 600; }
svg.chart .s1 { fill: var(--s1); } svg.chart .s3 { fill: var(--s3); } svg.chart .rest { fill: var(--rest); }
svg.chart .o1 { fill: var(--o1); } svg.chart .o2 { fill: var(--o2); } svg.chart .o3 { fill: var(--o3); }
svg.chart .s1:not(.current):not(.line) { opacity: .85; }
svg.chart .line { fill: none; stroke: var(--s1); stroke-width: 2; stroke-linejoin: round; }
svg.chart .hit { fill: transparent; }
svg.chart .hit:hover { fill: var(--ink); fill-opacity: .05; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .85rem; color: var(--ink-2); margin: 4px 0 6px; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw.s1 { background: var(--s1); } .sw.s3 { background: var(--s3); } .sw.rest { background: var(--rest); }
.sw.o1 { background: var(--o1); } .sw.o2 { background: var(--o2); } .sw.o3 { background: var(--o3); }
#tip { position: fixed; z-index: 10; pointer-events: none; background: var(--ink); color: var(--surface);
       font-size: .8rem; padding: 6px 9px; border-radius: 6px; max-width: 320px; box-shadow: 0 2px 8px rgba(0,0,0,.2); }

/* login */
.login { max-width: 340px; margin: 12vh auto 0; }
.login h1 { font-size: 1.2rem; margin-bottom: 14px; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--ink-2); }
.login input { font: inherit; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--axis); background: var(--page); color: var(--ink); }
.error { color: var(--critical); margin: 0; font-size: .9rem; }

@media (max-width: 640px) {
  .top { gap: 12px; padding: 10px 14px; flex-wrap: wrap; }
  main { padding: 14px; }
  .sync-text { align-items: flex-start; } .sync-msg { text-align: left; }
}

/* Sync from a chosen date */
.sync-range { margin: -8px 0 18px; font-size: .85rem; text-align: right; }
.sync-range summary { cursor: pointer; color: var(--ink-2); }
.sync-range-form { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 8px; }
.sync-range-form .hint { color: var(--muted); }
.sync-range-form .check { display: inline-flex; align-items: center; gap: 6px; }

/* forms: profiles + settings */
form.stack { display: flex; flex-direction: column; gap: 12px; max-width: 460px; }
form.stack label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--ink-2); }
form.stack label.check { flex-direction: row; align-items: center; gap: 8px; }
form.stack input:not([type=checkbox]) { font: inherit; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--axis);
  background: var(--page); color: var(--ink); }
form.stack button { align-self: flex-start; }
.hint { color: var(--muted); font-size: .8rem; }
.notice { background: var(--surface); border: 1px solid var(--ring); border-left: 3px solid var(--good);
  border-radius: 8px; padding: 10px 14px; margin: 0 0 16px; }
.notice::before { content: "✓ "; color: var(--good); }
.error::before { content: "! "; font-weight: 700; }
.top .who { color: var(--ink-2); font-size: .9rem; }
.top .who[aria-current="page"] { color: var(--ink); }
/* date-range sync */
.sync-range-form { max-width: 620px; justify-content: flex-end; }
.range-note { flex-basis: 100%; margin: 2px 0 0; text-align: right; line-height: 1.4; }
.range-warn { flex-basis: 100%; margin: 0; padding: 8px 12px; border-radius: 7px; text-align: left;
  background: var(--surface); border: 1px solid var(--ring); border-left: 3px solid #fab219; color: var(--ink); }
.range-warn.bad { border-left-color: var(--critical); }
/* sync refused because of cooldown: clearly not "ok" */
.sync[data-state="wait"] .sync-state::before { content: "⏳"; color: #fab219; }
.sync[data-state="wait"] .sync-state, .sync[data-state="error"] .sync-state { font-weight: 600; }
.sync[data-state="wait"] .sync-msg, .sync[data-state="error"] .sync-msg { color: var(--ink); }
/* HTTPS certificate warning (admins only) */
.cert-banner { margin: 0 0 16px; padding: 10px 14px; border-radius: 8px; background: var(--surface);
  border: 1px solid var(--ring); border-left: 3px solid #fab219; color: var(--ink); font-size: .9rem; }
.cert-banner::before { content: "⚠ "; }
.cert-banner.expired { border-left-color: var(--critical); }
.cert-banner code, .card code { font-size: .85em; background: var(--grid); padding: 1px 5px; border-radius: 4px; }
/* Strength & Yoga: categorical slot 2 (orange) for yoga; slot 1 (blue) is strength */
:root { --s2: #eb6834; }
@media (prefers-color-scheme: dark) { :root { --s2: #d95926; } }
svg.chart .s2 { fill: var(--s2); }
.sw.s2 { background: var(--s2); }
.kind { display: inline-flex; align-items: center; gap: 6px; }
.kind::before { content: ""; width: 9px; height: 9px; border-radius: 2px; background: var(--s1); }
.kind-yoga::before { background: var(--s2); }
/* Coach Bennett: plan */
.coach-say { margin: 6px 0; line-height: 1.5; }
.card.coach { border-left: 3px solid var(--s1); }
.plan-actions { display: flex; gap: 14px; align-items: center; }
.plan-actions form { margin: 0; }
table.plan-week td { vertical-align: top; }
table.plan-week tr.st-today { background: var(--grid); }
table.plan-week tr.st-missed td { opacity: .65; }
.flag { color: var(--critical); font-size: .82rem; }
.kind-easy::before, .kind-shakeout::before { background: var(--o1); }
.kind-long::before { background: var(--s1); }
.kind-quality::before { background: var(--s2); }
.kind-race::before { background: var(--critical); }
tr.current td { font-weight: 600; }
tr.past td { opacity: .7; }
.archive-goal { margin-top: 8px; text-align: right; }
form.stack select { font: inherit; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--axis); background: var(--page); color: var(--ink); }
table.plan-week td:first-child, table.plan-week td.n { white-space: nowrap; }
/* Today card + pre-run notes */
.card.today { border-left: 3px solid var(--s1); }
.card.today.heat-humid { border-left-color: #fab219; }
.card.today.heat-hot, .card.today.heat-very-hot, .card.today.heat-extreme { border-left-color: var(--critical); }
.today-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.today-run h3 { font-size: 1rem; margin: 10px 0 4px; }
.today-details { margin: 2px 0; }
dl.prerun { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 10px 0 2px; font-size: .9rem; }
dl.prerun dt { color: var(--ink-2); font-weight: 600; }
dl.prerun dd { margin: 0; line-height: 1.45; }
.today-run.next { border-top: 1px solid var(--grid); margin-top: 10px; padding-top: 4px; }
@media (max-width: 640px) { dl.prerun { grid-template-columns: 1fr; } dl.prerun dt { margin-top: 6px; } }
/* ================= Phone layout (<= 640px) ================= */
@media (max-width: 640px) {
  body { font-size: 15px; }
  main { padding: 12px 12px 40px; }
  h1 { font-size: 1.3rem; }

  /* header: brand + name + logout on one line, menu as one swipeable row below */
  .top { display: grid; grid-template-columns: 1fr auto auto; gap: 6px 10px; padding: 8px 12px 0; align-items: center; }
  .top .brand { font-size: .95rem; }
  .top nav { grid-column: 1 / -1; order: 3; overflow-x: auto; white-space: nowrap; gap: 18px;
             -webkit-overflow-scrolling: touch; scrollbar-width: none; padding: 4px 0 8px; }
  .top nav::-webkit-scrollbar { display: none; }
  .top nav a { padding: 4px 0; }
  .top .who { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .logout button { padding: 5px 10px; font-size: .85rem; }

  .page-head { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 12px; }
  .sync { justify-content: space-between; }
  .sync-text { align-items: flex-start; } .sync-msg { text-align: left; max-width: none; }
  .sync-range { text-align: left; }
  .sync-range-form { justify-content: flex-start; }
  .range-note { text-align: left; }
  .plan-actions { justify-content: space-between; }

  .card { padding: 12px; border-radius: 8px; margin-bottom: 12px; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
  .tile { padding: 10px; }
  .t-value { font-size: 1.35rem; }
  .t-label { font-size: .78rem; } .t-sub { font-size: .72rem; }

  /* charts keep readable text: fixed minimum size, swipe sideways */
  section.card:has(svg.chart) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  svg.chart { min-width: 560px; }
  .legend { font-size: .8rem; gap: 10px; }

  /* tables -> one card per row, each cell labelled (labels added by app.js) */
  table.data.reflow thead { display: none; }
  table.data.reflow, table.data.reflow tbody, table.data.reflow tr, table.data.reflow td { display: block; width: 100%; }
  table.data.reflow tr { border: 1px solid var(--ring); border-radius: 8px; padding: 6px 10px; margin-bottom: 8px; background: var(--page); }
  table.data.reflow tbody tr:hover { background: var(--page); }
  table.data.reflow td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.data.reflow td.n { text-align: right; }
  table.data.reflow td[data-label]::before { content: attr(data-label); color: var(--ink-2); font-weight: 500; text-align: left; flex: 0 0 auto; }
  table.data.reflow td:not([data-label]) { display: block; text-align: left; }
  table.data.reflow td:first-child { font-weight: 600; }
  table.plan-week.reflow td { white-space: normal; }
  table.plan-week.reflow td:nth-child(3) { display: block; text-align: left; }
  table.plan-week.reflow td:nth-child(3)::before { display: block; margin-bottom: 2px; }

  /* forms: 16px text so iOS doesn't zoom, full-width controls */
  form.stack { max-width: none; }
  input, select, textarea, button { font-size: 16px; }
  .login { margin-top: 6vh; }
  .cert-banner { font-size: .85rem; }
  dl.prerun { font-size: .88rem; }
}
@media (max-width: 640px) {
  /* keep a cell's content together: label floats left, value flows right */
  table.data.reflow td { display: block; text-align: right; overflow: hidden; }
  table.data.reflow td[data-label]::before { float: left; margin-right: 12px; }
  table.plan-week.reflow td:nth-child(3) { text-align: left; }
  table.plan-week.reflow td:nth-child(3)::before { float: none; }
}
/* Post-run review */
.review { border-top: 1px solid var(--grid); padding: 10px 0 6px; }
.review:first-of-type { border-top: 0; }
.review h3 { font-size: .95rem; margin: 0 0 4px; }
.rv-line { margin: 2px 0; color: var(--ink-2); font-size: .9rem; }
.rv-good { margin: 4px 0; }
.rv-good::first-letter { color: var(--good); }
.rv-tip { margin: 6px 0; padding: 8px 10px; border-radius: 7px; background: var(--page); border-left: 3px solid #fab219; }
.verdict-pain .rv-tip { border-left-color: var(--critical); }
.rv-ask summary { cursor: pointer; color: var(--accent); margin: 6px 0; font-weight: 500; }
.rv-form { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 4px; }
.rv-form fieldset { border: 0; padding: 0; margin: 0; }
.rv-form legend { font-size: .85rem; color: var(--ink-2); margin-bottom: 4px; }
.rv-form fieldset label { display: inline-block; margin: 0 4px 6px 0; }
.rv-form fieldset input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.rv-form fieldset span { display: inline-block; min-width: 34px; padding: 6px 9px; text-align: center; border-radius: 7px;
  border: 1px solid var(--axis); cursor: pointer; font-size: .9rem; }
.rv-form fieldset input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.rv-form fieldset input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.rv-note { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--ink-2); }
.rv-note input { font: inherit; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--axis); background: var(--page); color: var(--ink); }
.rv-form button { align-self: flex-start; }
@media (max-width: 640px) { .rv-form fieldset span { min-width: 30px; padding: 7px 8px; } .rv-note input { font-size: 16px; } }
/* Data quality check banner */
.dq-banner { border-left: 3px solid var(--accent); }
.dq-list { margin: 8px 0 12px; padding-left: 18px; line-height: 1.6; }
.dq-old { color: var(--muted); text-decoration: line-through; }
.dq-new { font-weight: 600; }
.dq-actions { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.dq-actions form { margin: 0; }
.dq-actions .dq-dismiss { margin-left: auto; }
.dq-confirm summary { list-style: none; cursor: pointer; display: inline-block; padding: 7px 14px; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 500; }
.dq-confirm summary::-webkit-details-marker { display: none; }
.dq-confirm[open] summary { opacity: .6; }
.dq-confirm-body { margin-top: 10px; padding: 12px 14px; border: 1px solid var(--ring); border-radius: 8px; max-width: 560px; }
.dq-confirm-body p { margin: 0 0 10px; }
.dq-check-now { display: flex; gap: 10px; align-items: center; justify-content: flex-end; flex-wrap: wrap; margin: -6px 0 14px; }

/* Route map + minute charts */
.map-wrap { border-radius: 10px; overflow: hidden; border: 1px solid var(--ring); background: #e8e6df; }
svg.map { display: block; width: 100%; height: auto; }
svg.map .route-halo { fill: none; stroke: #fff; stroke-width: 7; stroke-linejoin: round; stroke-linecap: round; opacity: .85; }
svg.map .route { fill: none; stroke: #d03b3b; stroke-width: 4; stroke-linejoin: round; stroke-linecap: round; }
svg.map .route-start { fill: #0ca30c; stroke: #fff; stroke-width: 2.5; }
svg.map .route-finish { fill: #fff; stroke: #0b0b0b; stroke-width: 3; }
.map-credit { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.map-credit .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.map-credit .dot.start { background: #0ca30c; }
.map-credit .dot.finish { background: #fff; border: 2px solid #0b0b0b; }
.chart .warmup-band { fill: var(--ink); opacity: .05; }
.chart .pause-mark line { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 3 3; }
.chart .pause-mark rect:not(.hit) { fill: var(--surface); stroke: var(--muted); stroke-width: 1; }
.chart .pause-mark text { fill: var(--ink-2); font-size: 10.5px; }

/* Profile photos */
.av { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex: none; display: inline-flex;
  align-items: center; justify-content: center; position: relative; z-index: 1; }
.av-init { background: linear-gradient(#a5abb8, #858994); color: #fff; font-weight: 600; font-size: .85rem; user-select: none; }
.av-init.av-coach { background: linear-gradient(#5aa0f0, #2a78d6); }
.av-xs { width: 24px; height: 24px; font-size: .7rem; }
.av-md { width: 56px; height: 56px; font-size: 1.3rem; }
.av-lg { width: 96px; height: 96px; font-size: 2rem; }
.av-gap { visibility: hidden; }
.av-sm { width: 36px; height: 36px; font-size: .8rem; }
h2.coach-h { display: flex; align-items: center; gap: 10px; }
h2.coach-h > span { display: flex; flex-direction: column; line-height: 1.2; }
.coach-by { font-size: .72rem; font-weight: 500; color: var(--muted); }
.plan-week .kind-strength::before, .today .kind-strength::before { background: var(--s3); border-radius: 50%; }   /* plan only; the Strength tab keeps its own colour */
.done-tag { font-size: .8rem; color: var(--good); font-weight: 600; margin-left: 6px; }
fieldset.days { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
fieldset.days legend { font-size: .9rem; color: var(--ink-2); margin-bottom: 6px; padding: 0; }
.day-picks { display: flex; flex-wrap: wrap; gap: 6px; }
.day-picks label.check { display: inline-flex; flex-direction: row; align-items: center; gap: 5px; padding: 6px 10px;
  border: 1px solid var(--axis); border-radius: 999px; font-size: .85rem; color: var(--ink); cursor: pointer; }
.pick-label { align-self: center; margin-right: 2px; }
.move-form { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.move-form select { font: inherit; font-size: .8rem; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--axis);
  background: var(--page); color: var(--ink-2); }
button.small { padding: 3px 8px; font-size: .8rem; }
@media (max-width: 640px) { .move-form select { font-size: 16px; } }
.day-picks label.check:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.top .who { display: inline-flex; align-items: center; gap: 8px; }
.photo-row { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.photo-row form.stack { flex: 1; min-width: 220px; }
.inline-form { margin: 10px 0 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Coach chat, laid out like a phone messaging app */
:root { --im-bg: var(--surface); --im-me: #007aff; --im-them: #e9e9eb; --im-them-ink: #0b0b0b; }
@media (prefers-color-scheme: dark) { :root { --im-me: #0a84ff; --im-them: #2c2c2e; --im-them-ink: #f0efec; } }
.imsg { max-width: 760px; margin: 0 auto; background: var(--im-bg); border: 1px solid var(--ring);
  border-radius: 18px; overflow: hidden; display: flex; flex-direction: column; }
.imsg-head { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 14px 12px 10px;
  border-bottom: 1px solid var(--ring); background: color-mix(in srgb, var(--im-bg) 85%, var(--page)); }
.imsg-name { font-size: .8rem; font-weight: 600; color: var(--ink); }
.imsg-status { font-size: .7rem; color: var(--muted); }
.imsg-thread { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px 16px; overflow-y: auto;
  height: min(64vh, 680px); overscroll-behavior: contain; }
.imsg-stamp { align-self: center; margin: 14px 0 6px; font-size: .7rem; color: var(--muted); }
.imsg-stamp:first-child { margin-top: 2px; }
.imsg-row { display: flex; align-items: flex-end; gap: 10px; }
.imsg-row.me { flex-direction: row-reverse; }
.imsg-row.tail { margin-bottom: 8px; }
.bubble { position: relative; max-width: min(75%, 520px); padding: 8px 14px; border-radius: 18px; line-height: 1.38;
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: .95rem; }
.me .bubble { background: var(--im-me); color: #fff; }
.them .bubble { background: var(--im-them); color: var(--im-them-ink); }
.them .bubble a { color: var(--accent); }
/* bubble tails: a coloured corner, trimmed into a curve by a patch of the thread's background */
.tail .bubble::before, .tail .bubble::after { content: ""; position: absolute; bottom: 0; height: 20px; }
.me.tail .bubble::before { right: -8px; width: 20px; background: var(--im-me); border-bottom-left-radius: 16px 14px; }
.me.tail .bubble::after { right: -10px; width: 10px; background: var(--im-bg); border-bottom-left-radius: 10px; }
.them.tail .bubble::before { left: -7px; width: 20px; background: var(--im-them); border-bottom-right-radius: 16px 14px; }
.them.tail .bubble::after { left: -10px; width: 10px; background: var(--im-bg); border-bottom-right-radius: 10px; }
.imsg-typing .bubble { display: inline-flex; gap: 4px; padding: 12px 14px; }
.imsg-typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: imsg-dot 1.2s infinite; }
.imsg-typing i:nth-child(2) { animation-delay: .2s; }
.imsg-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes imsg-dot { 0%, 60%, 100% { opacity: .35; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .imsg-typing i { animation: none; } }
.imsg-bar { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--ring); }
.imsg-bar textarea { flex: 1; font: inherit; font-size: .95rem; line-height: 1.35; padding: 7px 14px; min-height: 36px;
  max-height: 140px; border-radius: 18px; border: 1px solid var(--axis); background: var(--im-bg); color: var(--ink);
  resize: none; overflow-y: auto; }
.imsg-bar textarea:focus { outline: none; border-color: var(--im-me); }
.imsg-send { width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 0; background: var(--im-me); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; flex: none; margin-bottom: 1px; }
.imsg-send:disabled { opacity: .35; }
.imsg-error { margin: 0; padding: 8px 14px; color: var(--critical); font-size: .85rem; border-top: 1px solid var(--ring); }
.imsg-foot { max-width: 760px; margin: 8px auto 0; display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; }
.imsg-foot .inline-form { margin: 0; }
@media (max-width: 640px) {
  .imsg { border-radius: 14px; margin: 0 -6px; }
  .imsg-head { padding: 8px 10px 6px; gap: 1px; }
  .imsg-head .av-md { width: 42px; height: 42px; font-size: 1rem; }
  .imsg-thread { height: calc(100dvh - 300px); min-height: 280px; padding: 10px 8px 14px; }
  .bubble { max-width: 78%; }
  .imsg-row { gap: 8px; }
  .imsg-row .av:not(.av-md) { width: 26px; height: 26px; }
  .imsg-bar textarea { font-size: 16px; }       /* no auto-zoom on iPhone */
  .top .who span { display: none; }              /* photo only in the menu bar */
}