/* Layout and components. Colours and fonts come from tokens.css only. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body.alt { background: var(--page-alt); }
button { font: inherit; color: inherit; }
a { color: inherit; }
.icon { display: block; flex: 0 0 auto; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app {
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 100vh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
.pad { padding: 20px var(--gutter) calc(46px + env(safe-area-inset-bottom)); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 18px;
  border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
  font-family: var(--font-ui); font-weight: 700; font-size: 11.5px;
  letter-spacing: var(--tracking-label); text-transform: uppercase;
  text-decoration: none; cursor: pointer;
}
.btn-primary {
  min-height: 48px; padding: 0 28px; border: none;
  background: var(--ink); color: #FFFFFF; font-size: 13px; letter-spacing: var(--tracking-caps);
}
.btn-primary:disabled { background: var(--grey-light); cursor: not-allowed; }
.btn:focus-visible, .tab:focus-visible, .view-btn:focus-visible, .scale-row:focus-visible, .combo-input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------- Select screen ---------- */
.select { max-width: 600px; margin: 0 auto; padding: 40px var(--gutter) calc(40px + env(safe-area-inset-bottom)); }
.wordmark { display: block; height: 40px; width: auto; margin-bottom: 28px; } /* Dot logo, public/brand/logo-dot.svg */
.title { font-family: var(--font-display); font-weight: 800; font-size: clamp(24px, 6vw, 32px); line-height: 1.2; margin: 6px 0 8px; }
.intro { font-style: italic; font-size: 14px; margin: 0 0 28px; }
.hero { width: 100%; height: auto; aspect-ratio: 16 / 7; object-fit: cover; display: block; margin-bottom: 28px; background: var(--page-alt); }
.slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 32px; }
.slot-label {
  display: block; margin-bottom: 6px;
  font-family: var(--font-ui); font-weight: 900; font-size: 11px; letter-spacing: var(--tracking-caps);
  text-transform: uppercase; color: var(--ink);
}
.slot.optional .slot-label { color: var(--grey); }

/* Searchable person picker */
.combo { position: relative; }
.combo-input {
  width: 100%; min-height: var(--tap); padding: 0 40px 0 12px;
  border: 1px solid #C9D3E3; border-radius: 0; background: var(--card); color: var(--ink);
  font-family: var(--font-ui); font-weight: 700; font-size: 16px; /* 16px stops iOS zooming */
  -webkit-appearance: none; appearance: none;
}
.combo-input::placeholder { color: var(--ink); font-weight: 400; opacity: 0.85; }
.combo.filled .combo-input { border-color: var(--ink-muted); }
.combo-clear {
  position: absolute; right: 0; top: 0; width: var(--tap); height: 100%;
  display: flex; align-items: center; justify-content: center;
  border: none; background: none; color: var(--grey); cursor: pointer;
}
.combo-list {
  position: absolute; z-index: 20; left: 0; right: 0; top: 100%;
  max-height: 280px; overflow-y: auto; margin: 0; padding: 4px 0; list-style: none;
  background: var(--card); border: 1px solid var(--ink-muted); border-top: none;
  box-shadow: 0 8px 20px rgba(0, 32, 78, 0.12);
}
.combo-list[hidden] { display: none; }
.combo-option { display: flex; align-items: center; gap: 10px; min-height: var(--tap); padding: 0 12px; cursor: pointer; font-family: var(--font-ui); font-size: 15px; }
.combo-option[aria-selected="true"], .combo-option:hover { background: var(--page-alt); }
.combo-empty { padding: 12px; font-style: italic; font-size: 14px; color: var(--grey); }

/* ---------- Avatars ---------- */
.avatar {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-ui); font-weight: 900; font-size: 9.5px; letter-spacing: 0.02em;
}
.p1 { --p: var(--person-1); --p-on: var(--person-1-on); }
.p2 { --p: var(--person-2); --p-on: var(--person-2-on); }
.p3 { --p: var(--person-3); --p-on: var(--person-3-on); }
.p4 { --p: var(--person-4); --p-on: var(--person-4-on); }
/* Initials stay readable on any person colour: a set text colour per person,
   or, where the browser supports it, contrast-color() picks black or white. */
.avatar { background: var(--p); color: var(--p-on); }
@supports (color: contrast-color(red)) {
  .avatar { color: contrast-color(var(--p)); }
}

/* ---------- Top bar (sticky): the people, then the tabs ---------- */
.top-bar {
  position: sticky; top: var(--banner-h, 0px); z-index: 30;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.people-strip { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px var(--gutter) 6px; }
.chip { display: inline-flex; align-items: center; gap: 7px; min-width: 0; font-family: var(--font-ui); font-weight: 700; font-size: 13px; white-space: nowrap; }
.chip .avatar { width: 24px; height: 24px; font-size: 9px; }
.tabs { display: flex; scrollbar-width: none; }
.tab {
  flex: 1 1 0; min-width: 0; min-height: var(--tap); padding: 12px 4px 10px; margin-bottom: -1px;
  border: none; border-bottom: 3px solid transparent; background: none; cursor: pointer; white-space: nowrap; text-align: center;
  font-family: var(--font-ui); font-weight: 700; font-size: 14px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--grey);
}
.tab-wide { flex-grow: 1.8; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }

/* ---------- Bottom bar (fixed): Back, chart views, Change ---------- */
.with-bottom-bar { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.bottom-inner { max-width: var(--max-width); margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px var(--gutter); }
.bar-btn {
  flex: 0 0 auto; width: var(--tap); height: var(--tap); padding: 0;
  border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.views { display: flex; border: 1px solid var(--line-strong); background: var(--card); }
.view-btn {
  width: 42px; height: 42px; padding: 0; border: none; background: var(--card); color: var(--ink);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.view-btn + .view-btn { border-left: 1px solid var(--line-strong); }
.view-btn[aria-pressed="true"] { background: var(--ink); color: #FFFFFF; }
.bar-change { flex: 0 0 auto; padding: 0 12px; gap: 6px; }
.bar-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Page sections ---------- */
.card { background: var(--card); border: 1px solid var(--line); padding: 20px; margin-bottom: 32px; }
.card-title { font-family: var(--font-display); font-weight: 800; font-size: 19px; line-height: 1.3; margin: 0 0 2px; }
.card-text { font-size: 14px; line-height: 1.55; color: var(--ink-soft); margin: 8px 0 14px; max-width: 760px; }
.inv-hint { margin: 0 0 12px; font-size: 13px; font-style: italic; color: var(--ink-muted); }
.inv-hint strong { font-style: normal; color: var(--ink); }
.glance-block { margin-bottom: 28px; }
.legend-swatch { width: 14px; height: 14px; border-radius: 50%; background: var(--p); box-shadow: 0 0 0 1px #FFFFFF, 0 0 0 2px var(--p); }
.notice { padding: 40px 0; font-style: italic; font-size: 14px; color: var(--grey); }

/* ---------- Scale rows: name + poles, badge, arrow; the chart full width beneath ---------- */
.scale-list { border: 1px solid var(--line); background: var(--card); padding: 0 14px; }
.scale-row { display: block; padding: 12px 0; border-top: 1px solid var(--line-soft); text-decoration: none; color: inherit; cursor: pointer; }
.scale-row:first-child { border-top: none; }
.scale-row:hover .row-name { text-decoration: underline; text-underline-offset: 3px; }
.row-top { display: flex; align-items: center; gap: 8px; }
.row-label { flex: 1; min-width: 0; }
.row-name { font-family: var(--font-ui); font-weight: 700; font-size: 13px; letter-spacing: var(--tracking-label); text-transform: uppercase; }
.row-poles, .poles { font-style: italic; font-size: 11.5px; color: var(--grey); }
.row-poles { display: block; margin-top: 2px; line-height: 1.35; }
.poles-arrow { font-style: normal; color: var(--grey-light); }
.row-badge { flex: 0 0 auto; width: 24px; display: flex; justify-content: center; }
.row-go { flex: 0 0 auto; display: flex; color: #7F8FA6; margin-right: -4px; }
.row-track { margin-top: 8px; }
.badge {
  /* Never squeezed by neighbouring text in a flex row: always a circle. */
  flex: 0 0 auto; aspect-ratio: 1;
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%; color: #FFFFFF;
}
.badge.divergent { background: var(--watch); }
.badge.highAnchor { background: var(--ink); }
.badge.lowAnchor { background: var(--accent); }

/* ---------- Range track ---------- */
.track { position: relative; height: 36px; border: 1px solid var(--line); }
.track.compact { height: 32px; }
.inv-HPI .track, .track.inv-HPI { background: var(--hpi-track); }
.inv-HDS .track, .track.inv-HDS { background: var(--hds-track); }
.inv-MVPI .track, .track.inv-MVPI { background: var(--mvpi-track); }
.track-in { position: absolute; top: 0; bottom: 0; left: 12px; right: 12px; }
.zone-line { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(0, 32, 78, 0.22); }
.range-bar { position: absolute; top: 50%; height: 3px; transform: translateY(-50%); background: rgba(0, 32, 78, 0.35); }
/* Each person's dot: white, ringed and lettered in their fixed slot colour. */
.dot {
  --size: 26px;
  position: absolute; top: 50%; width: var(--size); height: var(--size); border-radius: 50%;
  transform: translate(-50%, -50%); box-sizing: border-box;
  background: #FFFFFF; border: 2px solid var(--p); box-shadow: 0 0 0 2px #FFFFFF;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-ui); font-weight: 900; font-size: 10px; color: var(--p);
}
.track.compact .dot { --size: 24px; font-size: 8.5px; }
.dot.avg { background: var(--ink); border-color: var(--ink); color: #FFFFFF; }
.zone-labels { position: relative; height: 24px; margin-bottom: 4px; }
.zone-label {
  position: absolute; bottom: 0; text-align: center; line-height: 1.05;
  font-family: var(--font-ui); font-weight: 700; font-size: 9.5px; letter-spacing: var(--tracking-caps); color: #5A5A5A;
}

/* ---------- Bars: a full-width bar per person ---------- */
.pbars { display: flex; flex-direction: column; gap: 5px; }
.pbar { display: flex; align-items: center; gap: 8px; }
.pbar-who { width: 20px; height: 20px; font-size: 7.5px; }
.pbar-track { position: relative; flex: 1; min-width: 0; height: 12px; background: #FFFFFF; border: 1px solid var(--line-strong); }
.pbar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--p); }
.pbar-line { position: absolute; top: 0; bottom: 0; width: 1px; background: #9AA3B2; }
.pbar-val { flex: 0 0 auto; width: 24px; text-align: right; font-family: var(--font-display); font-weight: 800; font-size: 12px; }

/* ---------- Scorecard: scales down, people across ---------- */
.scorecard { background: var(--card); border: 1px solid var(--line); padding: 10px 12px; }
.sc-head, .sc-row { display: grid; gap: 4px; align-items: center; }
.sc-head { padding-bottom: 6px; }
.sc-who { display: flex; justify-content: center; }
.sc-who .avatar { width: 24px; height: 24px; font-size: 9px; }
.sc-row { margin-bottom: 4px; text-decoration: none; color: inherit; cursor: pointer; }
.sc-row:hover .sc-name { text-decoration: underline; text-underline-offset: 3px; }
.sc-name { font-family: var(--font-ui); font-weight: 700; font-size: 12px; letter-spacing: 0.05em; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-cell {
  height: 36px; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: #FFFFFF; color: var(--ink);
  font-family: var(--font-display); font-weight: 800; font-size: 13px;
}
.sc-cell.high { background: var(--ink); border-color: var(--ink); color: #FFFFFF; }
.sc-cell.moderate { background: #3A5A87; border-color: #3A5A87; color: #FFFFFF; }
.sc-cell.low { background: #E2E7EF; color: #3F4B63; }
.sc-badge { display: flex; justify-content: flex-end; }
.sc-key { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--ink-muted); }
.sc-key span { display: inline-flex; align-items: center; gap: 6px; }
.sc-swatch { display: inline-block; width: 13px; height: 13px; border: 1px solid var(--line); }
.sc-swatch.high { background: var(--ink); }
.sc-swatch.none { background: #FFFFFF; }
.sc-swatch.low { background: #E2E7EF; }

/* ---------- Anchor key ---------- */
.key { margin-top: 16px; background: var(--card); border: 1px solid var(--line); padding: 16px 18px; }
.key-title { font-family: var(--font-display); font-weight: 800; font-size: 12px; letter-spacing: var(--tracking-caps); text-transform: uppercase; margin-bottom: 12px; }
.key-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px 22px; }
.key-item { display: flex; align-items: flex-start; gap: 10px; }
.key-name { font-family: var(--font-display); font-weight: 700; font-size: 11px; letter-spacing: var(--tracking-label); text-transform: uppercase; margin-bottom: 2px; }
.key-text { font-size: 12.5px; line-height: 1.45; color: var(--ink-muted); }

/* ---------- Radar ---------- */
/* One card per person: a full-width name bar in their colour, then their radar. */
.radar-card { background: var(--card); border: 1px solid var(--line); margin-bottom: 16px; }
.radar-card.group { --p: var(--ink-muted); } /* slate, so it never reads as the navy 'You' card below it */
.radar-name {
  margin: 0; display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--p); color: #FFFFFF;
  font-family: var(--font-ui); font-weight: 900; font-size: 14px; letter-spacing: 0.04em;
}
.radar-name .avatar { width: 26px; height: 26px; font-size: 9.5px; background: #FFFFFF; color: var(--p); }
.radar-card .radar { padding: 8px 8px 12px; }
.radar svg { display: block; width: 100%; max-width: 640px; height: auto; margin: 0 auto; overflow: visible; }
.radar text { font-family: var(--font-ui); font-weight: 700; font-size: 19px; letter-spacing: 0.04em; fill: var(--ink); text-transform: uppercase; }

/* ---------- Scale sheet (bottom sheet over the list) ---------- */
body.sheet-open { overflow: hidden; }
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 32, 78, 0.45); animation: sheet-fade 0.2s ease-out; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; top: calc(48px + env(safe-area-inset-top)); z-index: 41;
  max-width: var(--max-width); margin: 0 auto;
  background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -8px 24px rgba(0, 32, 78, 0.18);
  display: flex; flex-direction: column;
  animation: sheet-up 0.25s ease-out; transition: transform 0.2s ease-out;
}
.sheet.dragging { transition: none; }
.sheet-grab { display: flex; justify-content: center; padding: 8px 0 2px; cursor: grab; touch-action: none; }
.sheet-handle { width: 40px; height: 4px; background: #C9D1DD; }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; padding: 6px var(--gutter) 12px; border-bottom: 1px solid var(--line-soft); touch-action: none; }
.sheet-title-wrap { flex: 1; min-width: 0; }
.sheet-head .poles { display: block; font-size: 13px; margin-top: 3px; }
.sheet-head .badge { margin-top: 6px; }
.sheet-close { width: 40px; height: 40px; }
.sheet-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px var(--gutter) calc(24px + env(safe-area-inset-bottom)); }
.sheet-chart { margin-bottom: 12px; }
.sheet-who { list-style: none; margin: 0 0 14px; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 14px; }
.sheet-who li { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.sheet-who .avatar { width: 22px; height: 22px; font-size: 8px; }
.sheet-who li span:last-child { color: var(--ink-muted); }
.detail-title { font-family: var(--font-ui); font-weight: 900; font-size: 20px; letter-spacing: 0.04em; text-transform: uppercase; margin: 0; }
.panel { background: var(--page-alt); border: 1px solid var(--line); padding: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quad { background: var(--card); border: 1px solid var(--line); }
.quad.wide { grid-column: 1 / -1; }
.cell { padding: 12px 20px; }
.cell + .cell { border-top: 1px solid var(--line-soft); }
.cell-label { font-family: var(--font-display); font-weight: 800; font-size: 11px; letter-spacing: var(--tracking-caps); text-transform: uppercase; margin-bottom: 4px; }
.cell-label.avg { color: var(--ink-muted); }
.cell-text { font-size: 14px; line-height: 1.5; color: var(--ink-body); }
.cell.watch .cell-label { color: var(--watch); font-weight: 700; font-style: italic; }
.cell.watch .cell-text { font-style: italic; }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes sheet-fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { animation: none; transition: none; } }

/* A tab reached by swiping slides in from the side it came from. */
main.slide-from-right { animation: slide-from-right 0.22s ease-out; }
main.slide-from-left { animation: slide-from-left 0.22s ease-out; }
@keyframes slide-from-right { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slide-from-left { from { transform: translateX(-40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { main.slide-from-right, main.slide-from-left { animation: none; } }
body { overflow-x: clip; }

/* ---------- Sign-in ---------- */
.auth .hero { margin-bottom: 22px; }
.auth-card { background: var(--card); border: 1px solid var(--line); padding: 22px 20px 18px; }
.auth-card .intro { margin: 0 0 16px; }
.btn-wide { width: 100%; }
.auth-or { display: flex; align-items: center; gap: 12px; margin: 22px 0; color: var(--grey); font-family: var(--font-ui); font-size: 12px; letter-spacing: var(--tracking-caps); text-transform: uppercase; }
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.offline-status { margin: 10px 0 0; font-size: 12.5px; color: var(--ink-muted); }
.auth-block { margin-bottom: 36px; }
.auth-heading { font-family: var(--font-display); font-weight: 800; font-size: 19px; margin: 0 0 6px; }
.auth-text { font-size: 14px; margin: 0 0 14px; color: var(--ink-soft); }
.link-form { display: grid; gap: 10px; }
.link-form .btn { justify-self: stretch; width: 100%; }
.auth-msg { min-height: 1.5em; font-size: 14px; margin: 12px 0 0; color: var(--ink-soft); }
.auth-msg.error { color: var(--watch); }
.auth-msg:empty { display: none; }
.signout { margin: 40px 0 0; }
.link-btn { padding: 8px 0; border: none; background: none; cursor: pointer; font-family: var(--font-ui); font-size: 14px; color: var(--ink-muted); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Offline ---------- */
.offline-bar { position: sticky; top: 0; z-index: 50; padding: calc(8px + env(safe-area-inset-top)) var(--gutter) 8px; background: var(--ink); color: #FFFFFF; font-family: var(--font-ui); font-weight: 700; font-size: 12.5px; text-align: center; }
.offline-bar[hidden] { display: none; }

/* ---------- States ---------- */
.state { max-width: 600px; margin: 0 auto; padding: 80px var(--gutter); text-align: center; color: var(--ink-muted); }
.state.error { color: var(--watch); }

/* ---------- Phone ---------- */
@media (max-width: 640px) {
  .panel { grid-template-columns: 1fr; }
  .card { padding: 16px; margin-left: calc(-1 * var(--gutter) + 4px); margin-right: calc(-1 * var(--gutter) + 4px); }
  .scale-list { padding: 0 12px; }
  .chip { font-size: 12px; gap: 5px; }
  .tab { font-size: 13px; }
  .cell { padding: 12px 16px; }
  /* One person per line in the sheet, band and score on the right. */
  .sheet-who { grid-template-columns: 1fr; gap: 8px; }
  .sheet-who li span:last-child { margin-left: auto; }
}
