/* App styles. Builds on /site.css's five variables and adds four more
   (UX_SPEC.md §0.2). */
:root {
  --surface: #f2f1ed;
  --series-2: #b4561d;
  --warn: #8a5a00;
  --danger: #b3261e;
  --control: #85847e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface: #1f1f1d;
    --series-2: #f0a36b;
    --warn: #e8b24a;
    --danger: #ff8a80;
    --control: #77766f;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body.app {
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
/* Phase 3 fix: this safety net (no element overflows the viewport) was
   written as `body.app, body.app *`, whose specificity (0,1,1) beats any
   max-width set by a single class -- `.app-container{max-width:72rem}`,
   `.latest-posts-table-wrap{max-width:72rem}`, `.banner`, `.center-column`,
   `.max-w-48rem`, etc. all computed to 100% instead of their own value
   (confirmed live: §14.1.2's table rendered 1,368px wide at 1,400px, not
   ≤72rem/1,152px -- M1). `:where()` keeps the same matches but contributes
   zero specificity, so an intentional width class wins as authored while
   this still clamps anything with no such class. */
:where(body.app, body.app *) { max-width: 100%; }
.app-container { max-width: 72rem; margin: 0 auto; padding: 0 16px; }
.center-column { max-width: 24rem; margin: 0 auto; padding: 48px 16px 32px; }

a { color: var(--link); text-decoration: underline; }
button { font-family: inherit; }

/* ---------- App shell ---------- */
header.app-header { border-bottom: none; }
.shell-row1 {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--rule);
  padding: 0 16px;
}
/* S9: the icon itself stays 28x28 (N7's dark-mode outline is sized to it),
   but the link's own hit area is 44x44, centered in the 56/64px header row. */
.shell-row1 .app-icon-link { display: flex; align-items: center; justify-content: center; flex: 0 0 auto; min-width: 44px; min-height: 44px; }
.shell-row1 .app-icon-link img { width: 28px; height: 28px; display: block; border-radius: 6px; }
/* N7: the app icon is a dark tile, nearly invisible on the dark header. */
@media (prefers-color-scheme: dark) {
  .shell-row1 .app-icon-link img { outline: 1px solid var(--rule); outline-offset: -1px; }
}
.shell-app-name { font-size: 15px; color: var(--muted); white-space: nowrap; display: none; }
@media (min-width: 1000px) {
  .shell-app-name { display: inline; }
}
.shell-workspace {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 17px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shell-workspace button {
  background: none;
  border: none;
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  padding: 10px 4px;
  min-height: 44px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--rule);
  color: var(--fg);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.shell-row2 {
  height: 44px;
  display: flex;
  border-bottom: 1px solid var(--rule);
}
.shell-row2 nav { display: flex; width: 100%; }
.shell-row2 a {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--fg);
  font-size: 15px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  min-height: 44px;
}
.shell-row2 a[aria-current="page"] { border-bottom-color: var(--link); color: var(--link); }

@media (min-width: 1000px) {
  .shell-row1, .shell-row2 { border-bottom: none; }
  .shell-row1 {
    height: 64px;
    border-bottom: 1px solid var(--rule);
  }
  .shell-row2 { display: none; }
  .shell-row1 nav.desktop-nav { display: flex; gap: 4px; margin-left: 16px; }
  .shell-row1 nav.desktop-nav a {
    text-decoration: none;
    color: var(--fg);
    font-size: 15px;
    font-weight: 600;
    padding: 0 10px;
    height: 64px;
    display: flex;
    align-items: center;
    border-bottom: 2px solid transparent;
  }
  .shell-row1 nav.desktop-nav a[aria-current="page"] { border-bottom-color: var(--link); color: var(--link); }
}
@media (max-width: 999px) {
  nav.desktop-nav { display: none; }
}

/* popovers / sheets */
.menu-popover {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  min-width: 220px;
  z-index: 50;
  padding: 4px;
}
.menu-popover[hidden] { display: none; }
.menu-popover .menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--fg);
  font: inherit;
  padding: 10px 12px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  border-radius: 6px;
}
.menu-popover .menu-item:hover { background: var(--bg); }
.menu-popover .menu-header { padding: 10px 12px; }
.menu-popover .menu-rule { border-top: 1px solid var(--rule); margin: 4px 0; }
@media (max-width: 719px) {
  .menu-popover.sheet {
    position: fixed;
    left: 0; right: 0; top: 100px;
    width: 100%;
    border-radius: 0;
    border-left: none; border-right: none;
  }
}

/* ---------- Footer ---------- */
footer.app-footer {
  border-top: 1px solid var(--rule);
  margin-top: 2rem;
  padding: 16px;
  font-size: 13px;
  color: var(--muted);
}
footer.app-footer a { margin-right: 1rem; color: var(--muted); display: inline-flex; align-items: center; min-height: 44px; }

/* ---------- Blocks ---------- */
.block {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.block h2 { margin-top: 0; }
.big-number {
  font-size: 28px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.num-label { font-size: 13px; color: var(--muted); }
.caption { font-size: 13px; color: var(--muted); margin: 4px 0; }
tbody, td, th { font-variant-numeric: tabular-nums; }

/* ---------- Chips ---------- */
.chip {
  font-size: 13px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0 8px;
  display: inline-block;
  line-height: 20px;
}
.chip-muted { color: var(--muted); border-color: var(--rule); }
.chip-warn { color: var(--warn); border-color: var(--warn); }
.chip-danger { color: var(--danger); border-color: var(--danger); }

/* ---------- Buttons ---------- */
.btn {
  min-height: 44px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 600;
  padding: 0 16px;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary { background: var(--link); color: var(--bg); border-color: var(--link); }
.btn-secondary { background: transparent; border: 1px solid var(--control); color: var(--fg); }
.btn-danger { background: var(--danger); color: var(--bg); border-color: var(--danger); }
.btn-danger-outline { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-text { background: none; border: none; color: var(--link); min-height: 44px; cursor: pointer; font-weight: 600; font-size: 15px; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 15px; font-weight: 600; margin: 12px 0 4px; }
input[type=text], input[type=email], input[type=password], select, textarea {
  width: 100%;
  min-height: 44px;
  font-size: 16px;
  padding: 8px 10px;
  border: 1px solid var(--control);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
}
.help-text { font-size: 13px; color: var(--muted); margin: 4px 0 0; }
.field-error { font-size: 13px; color: var(--danger); margin: 4px 0 0; }
.password-field { position: relative; }
.password-field input { padding-right: 56px; }
.password-field .show-hide {
  position: absolute;
  right: 0; top: 0;
  height: 44px;
  min-width: 44px;
  background: none; border: none;
  color: var(--link); font-size: 13px; font-weight: 600;
  cursor: pointer;
}

/* ---------- Banners ---------- */
.banner {
  max-width: 72rem;
  margin: 0 auto 16px;
  border: 1px solid var(--link);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--fg);
}
.banner.banner-error { border-color: var(--danger); }
.banner .dismiss { min-height: 44px; background: none; border: none; color: var(--fg); cursor: pointer; font-weight: 600; }

/* ---------- Health strip rows ---------- */
.health-row {
  border: 1px solid var(--rule);
  background: var(--surface);
  padding: 12px;
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}
.health-row.warn { border-color: var(--warn); }
.health-row.error { border-color: var(--danger); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 8px 4px; }
.table-rule tr { border-bottom: 1px solid var(--rule); }
table caption { caption-side: top; text-align: left; margin-bottom: 8px; font-size: 13px; }
.num-col { text-align: right; }
.row-40 td, .row-40 th { height: 40px; }

/* ---------- Segmented control ---------- */
.segmented { display: inline-flex; border: 1px solid var(--control); border-radius: 6px; overflow: hidden; }
.segmented button {
  min-height: 44px;
  padding: 0 14px;
  background: var(--bg);
  border: none;
  border-right: 1px solid var(--control);
  color: var(--fg);
  cursor: pointer;
  font-size: 14px;
}
.segmented button:last-child { border-right: none; }
.segmented button[aria-pressed="true"] { background: var(--link); color: var(--bg); }
/* Phase 3 fix: `.segmented`'s `overflow: hidden` (needed to keep the group's
   own rounded corners while its buttons are square) clipped the default
   `outline-offset: 2px` ring to a 2px sliver. An inset box-shadow draws
   fully inside the button's own box, so it's never clipped by the group. */
.segmented button:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--link);
}

/* UX_SPEC.md §14.3/§14.8: the "Zoom to this {post}" toggle -- a single
   button, same boundary rule as .segmented (--control, M5), same pressed
   look as a segmented button. */
.zoom-toggle {
  min-height: 44px;
  padding: 0 14px;
  background: var(--bg);
  border: 1px solid var(--control);
  border-radius: 6px;
  color: var(--fg);
  cursor: pointer;
  font-size: 14px;
}
.zoom-toggle[aria-pressed="true"] { background: var(--link); color: var(--bg); border-color: var(--link); }
/* .segmented's explicit `display` would otherwise beat the UA [hidden]
   rule regardless of specificity (author stylesheets always outrank UA
   ones) -- the Instagram "Followers gained" metric control (§12.5.1) is
   the first segmented control that's conditionally hidden, which is how
   this surfaced. */
.segmented[hidden] { display: none; }

/* ---------- Dialogs ---------- */
dialog {
  border: none;
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  width: calc(100% - 32px);
  max-width: 32rem;
  padding: 20px;
}
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { margin-top: 0; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- Loading / error states ---------- */
.state-line { font-size: 13px; color: var(--muted); padding: 12px 0; }
.state-error { color: var(--danger); font-size: 15px; }
.state-box { padding: 16px 0; }

/* ---------- Charts ---------- */
.chart-wrap { position: relative; }
.chart-holder { height: 220px; }
@media (min-width: 1000px) { .chart-holder { height: 300px; } }
.chart-key { display: flex; gap: 16px; font-size: 13px; margin-bottom: 4px; flex-wrap: wrap; }
.chart-key .swatch { display: inline-block; width: 12px; height: 3px; margin-right: 6px; vertical-align: middle; }
.readout { font-size: 15px; margin-top: 4px; min-height: 20px; }
.uplot { font-size: 12px; }

/* ---------- Avatars / thumbnails ---------- */
.avatar, .thumb {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 600;
  overflow: hidden;
  flex: 0 0 auto;
}
.thumb { border-radius: 4px; }
.avatar img, .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- Post list / rows ---------- */
.post-row, .connection-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  text-decoration: none;
  color: var(--fg);
  border-bottom: 1px solid var(--rule);
  padding: 8px 0;
}
.post-row:last-child { border-bottom: none; }
.post-row .thumb { width: 64px; height: 36px; }
.post-row .lines { flex: 1 1 auto; min-width: 0; }
.post-row .title-line {
  font-size: 15px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
/* §14.1.1/M1: this used to be scoped to `.post-row .meta-line`, so Home's
   group rows (`.group-row-head .lines .meta-line`, not inside a `.post-row`)
   and the desktop table's post cell (`.latest-posts-table .meta-line`, inside
   a `<th>`) fell through to the 17px `--fg` body text instead -- confirmed
   live via computed style. Every meta-line wants the same 13px muted look. */
.meta-line { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ---------- Connection / account numbers ---------- */
.numbers-row { display: flex; gap: 24px; flex-wrap: wrap; }
.definitions summary { cursor: pointer; font-size: 13px; color: var(--link); margin-top: 8px; }
.definitions dl { margin: 8px 0; font-size: 13px; }
.definitions dt { font-weight: 600; margin-top: 8px; }
.definitions dd { margin: 2px 0 0; color: var(--muted); }

/* ---------- Layout grids desktop ---------- */
@media (min-width: 1000px) {
  .grid-40-60 { display: flex; gap: 24px; align-items: flex-start; }
  .grid-40-60 > .col-40 { flex: 0 0 40%; }
  .grid-40-60 > .col-60 { flex: 1 1 60%; min-width: 0; }
  .grid-50-50 { display: flex; gap: 24px; align-items: flex-start; }
  .grid-50-50 > div { flex: 1 1 50%; min-width: 0; }
}
@media (max-width: 999px) {
  .grid-40-60, .grid-50-50 { display: block; }
}

/* Home: the connection block's right-hand "Recent posts" column only
   exists at desktop width; phones get one combined section instead. */
@media (max-width: 999px) {
  .desktop-only-posts { display: none; }
}
@media (min-width: 1000px) {
  .mobile-only-posts { display: none; }
}
.posts-group { margin-bottom: 16px; }
.posts-group:last-child { margin-bottom: 0; }

@media (min-width: 720px) {
  .cards-to-table .card-only { display: none; }
}
@media (max-width: 719px) {
  .cards-to-table .table-only { display: none; }
}
/* UX_SPEC.md §12.5.3: Instagram's Posts list switches to a table at 1000px,
   not 720px, because there are eight number columns. */
@media (min-width: 1000px) {
  .cards-to-table-1000 .card-only { display: none; }
}
@media (max-width: 999px) {
  .cards-to-table-1000 .table-only { display: none; }
}

.sr-table { margin-top: 8px; }
.sr-table table { font-size: 13px; }

main.app-main { max-width: none; margin: 0; padding: 24px 0 48px; }
main.app-main .app-container { padding-left: 16px; padding-right: 16px; }

/* No-workspace / empty states */
.empty-state { text-align: center; padding: 48px 16px; }

/* ---------- Utility classes ----------
   The CSP (API_CONTRACT.md §1) is `default-src 'self'` with no
   'unsafe-inline', which blocks every `style="…"` attribute and inline
   event handler. These atoms replace the inline styles that used to be
   built into each page's markup strings; genuinely per-instance values
   (the handful that aren't from a small fixed set) are set via element.style
   property assignment in JS instead, which the CSP's style-src does allow
   (it isn't attribute parsing). */
.m-0 { margin: 0; }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: 2px; }
.mt-4 { margin-top: 4px; }
.mt-6 { margin-top: 6px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.my-8 { margin: 8px 0; }
.mt-2rem { margin-top: 2rem; }
.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.ml-8 { margin-left: 8px; }

.fw-600 { font-weight: 600; }
.fw-400 { font-weight: 400; }
.fs-12 { font-size: 12px; }
.fs-13 { font-size: 13px; }
.fs-15 { font-size: 15px; }
.fs-17 { font-size: 17px; }
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.text-link { color: var(--link); }
.uppercase { text-transform: uppercase; }
.monospace { font-family: monospace; }
.pre-wrap { white-space: pre-wrap; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; }
.valign-bottom { vertical-align: bottom; }
.d-block { display: block; }
.inline-block { display: inline-block; }

/* UX_SPEC.md §14.8: the standard visually-hidden clip pattern (never
   display:none, so it still reaches a screen reader / the a11y tree). */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-baseline { align-items: baseline; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-16-32 { gap: 16px 32px; }
.flex-1 { flex: 1 1 auto; }
.min-w-0 { min-width: 0; }

.w-100 { width: 100%; }
.max-w-16rem { max-width: 16rem; }
.max-w-22rem { max-width: 22rem; }
.max-w-48rem { max-width: 48rem; }

.border-link { border-color: var(--link); }
.border-danger { border-color: var(--danger); }

.row-divider {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
}
/* UX_SPEC.md §14.8/S9: a wrapped link used to leave 44px line-height gaps
   with an orphaned "›"; flex + a real min-height fixes that while still
   meeting the 44px tap target. */
.link-row { display: flex; align-items: center; min-height: 44px; line-height: 1.35; padding: 8px 0; }
.link-row-inline { display: inline-flex; align-items: center; min-height: 44px; }
.plain-link { text-decoration: none; color: inherit; }
.chart-loading { padding-top: 90px; text-align: center; }

/* UX_SPEC.md §14.8/S9: every summary (disclosure triangle) is a real 44px
   tap target, not just a line of 13px text.
   Phase 3 fix (Karen): `display: flex` makes Chromium stop drawing the
   native `::marker` triangle entirely (it's only drawn for `display:
   list-item`), which silently removed every "▸"/"▾" in the app. Restore a
   visible, rotating marker as a `::before` instead of reverting to
   `list-item` (which would bring back the 44px-tap-target problem S9 fixed). */
summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
  list-style: none;
}
summary::-webkit-details-marker { display: none; }
summary::before {
  content: "▸";
  display: inline-block;
  flex: 0 0 auto;
  margin-right: 6px;
  color: var(--link);
  transition: transform 0.15s ease;
}
details[open] > summary::before { transform: rotate(90deg); }
/* UX_SPEC.md §14.8/S9: "Same video on:" platform links get a real tap area. */
.samevideo-link { padding: 12px 4px; display: inline-flex; align-items: center; }

.avatar-40 { width: 40px; height: 40px; font-size: 16px; }
.avatar-56 { width: 56px; height: 56px; font-size: 22px; }
.thumb-64x36 { width: 64px; height: 36px; }
.thumb-96x54 { width: 96px; height: 54px; }

.swatch-link { background: var(--link); }
.swatch-link-thick { background: var(--link); height: 3px; }
.swatch-series2 { background: var(--series-2); }

.status-failed { color: var(--danger); }
.status-ok { color: var(--muted); }

.comment-reply { margin-left: 24px; border-left: 2px solid var(--rule); padding-left: 12px; }

.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
}

/* ---------- Accounts page grids ---------- */
@media (min-width: 1000px) {
  #connection-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  #connection-cards .block { margin-bottom: 0; }
  .platform-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
  .platform-grid .block { margin-bottom: 0; }
}

/* ---------- Phase 2: numbers grids (Instagram/TikTok post counts) ---------- */
.numbers-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 24px; }
@media (min-width: 720px) {
  .numbers-grid-3 { grid-template-columns: repeat(3, 1fr); }
  .numbers-grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Phase 2: coverage line under a column header (TikTok) ---------- */
.coverage-line { font-size: 13px; color: var(--muted); display: block; font-weight: 400; }

/* ---------- Phase 2: dashed suggested-match box ---------- */
.dashed-box {
  border: 1px dashed var(--rule);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

/* ---------- Phase 2: Audience list rows with bars ---------- */
.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 36px;
  padding: 4px 0;
}
.list-row .list-label { flex: 0 0 auto; width: 6rem; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .bar-track { flex: 1 1 auto; height: 8px; background: var(--rule); border-radius: 4px; overflow: hidden; }
.list-row .bar-fill { height: 8px; background: var(--link); border-radius: 4px; }
.list-row .list-value { flex: 0 0 auto; width: 3.5rem; text-align: right; font-size: 15px; font-variant-numeric: tabular-nums; }

/* ---------- Phase 2: online-followers hour bars ---------- */
.hours-grid {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  align-items: end;
  gap: 2px;
  height: 100px;
}
.hours-grid button {
  background: var(--link);
  border: none;
  min-width: 0;
  min-height: 4px;
  padding: 0;
  cursor: pointer;
}
.hours-grid button[aria-pressed="true"] { outline: 2px solid var(--fg); outline-offset: 1px; }
.hours-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- Phase 2: same-video cards ---------- */
.same-video-grid { display: block; }
.same-video-grid .block { margin-bottom: 16px; }
@media (min-width: 720px) {
  .same-video-grid { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 16px; align-items: start; }
  .same-video-grid .block { margin-bottom: 0; }
}
.same-video-numbers-row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--rule); font-size: 15px; }
.same-video-numbers-row:last-of-type { border-bottom: none; }
.same-video-numbers-row .val { font-variant-numeric: tabular-nums; }

/* ---------- Phase 2: 2x2 numbers grid on phone for post counts ---------- */
@media (max-width: 719px) {
  .numbers-grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Phase 2: "Link the same video" dialog rows ---------- */
.link-pick-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 6px 0;
  cursor: pointer;
  border-bottom: 1px solid var(--rule);
}
.link-pick-row:last-of-type { border-bottom: none; }
.link-pick-row input[disabled] + * { opacity: .6; }

/* ---------- Phase 2: Home "Recent posts" (recent_groups rows) ---------- */
.group-row { padding: 12px 0; border-bottom: 1px solid var(--rule); }
.group-row:last-child { border-bottom: none; }
.group-row-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 4px; }
.group-row-head .lines { flex: 1 1 auto; min-width: 0; }
.group-row-head .title-line {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 15px;
  color: var(--fg);
  text-decoration: none;
}
.group-platform-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  text-decoration: none;
  color: var(--fg);
}
.group-platform-line .chip-col { flex: 0 0 96px; }
.group-platform-line .nums { flex: 1 1 auto; font-size: 15px; }

/* ---------- Phase 2: Home connection blocks grid (replaces the Phase 1
   40/60 split-per-block desktop layout; UX_SPEC.md §12.4.3) ---------- */
@media (min-width: 1000px) {
  .home-blocks {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr));
    gap: 16px;
    align-items: start;
  }
  .home-blocks .block { margin-bottom: 0; }
}
.recent-posts-section { max-width: 56rem; }

/* =========================================================================
   §14 Phase 3 amendments
   ========================================================================= */

/* ---------- §14.1 Latest posts ---------- */
/* Phase 3 fix: this 56rem cap used to be silently void (the `body.app *`
   specificity bug fixed above), so it was never actually narrowing the
   phone card list it was meant for. Fixing that bug would otherwise have
   newly clamped the >=1000px desktop table (`.desktop-only-posts`, a
   sibling of `.mobile-only-posts` inside this same section) to 56rem too --
   narrower than §14.1.2's own 72rem on `.latest-posts-table-wrap` below.
   Scoping the 56rem cap to the phone rows only (it's a comfortable
   reading width for the card list; the desktop table already caps itself) */
.mobile-only-posts { max-width: 56rem; }
#latest-show-more { margin-top: 8px; }

/* §14.1.2 desktop table: one column per connected platform, right-aligned,
   tabular figures; "Post" (th scope=row) stays left-aligned. */
.latest-posts-table-wrap { max-width: 72rem; }
.latest-posts-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.latest-posts-table th, .latest-posts-table td { padding: 10px 8px; vertical-align: top; border-bottom: 1px solid var(--rule); }
.latest-posts-table th.post-col-head, .latest-posts-table td.post-cell { text-align: left; }
.latest-posts-table td.post-cell { font-weight: 400; }
.latest-posts-table .platform-col-head, .latest-posts-table td.platform-cell { text-align: right; font-variant-numeric: tabular-nums; }
.latest-posts-table .platform-cell a, .latest-posts-table .platform-cell .not-posted { display: block; min-height: 56px; text-decoration: none; color: var(--fg); }
.latest-posts-table .post-cell-inner { display: flex; gap: 12px; align-items: flex-start; }
.latest-posts-table .post-cell-inner .title-line {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 15px;
  color: var(--fg);
  text-decoration: none;
}

/* §14.8: row headers keep the look of a td, not a bold centered th. */
th[scope="row"] { font-weight: 400; text-align: left; }
th[scope="col"] { font-weight: 600; }

/* §14.1.1: the views figure leads each platform line, emphasised. */
.group-platform-line .views-emph { font-size: 15px; font-weight: 600; color: var(--fg); }
.group-platform-line .rest-muted { font-size: 15px; color: var(--muted); }

/* ---------- §14.8 headings ---------- */
.home-blocks h3 { font-size: 17px; font-weight: 600; margin: 0; }

/* ---------- §14.2 handles / titles ---------- */
/* (no new class needed; .d-block above carries the layout role .block used to) */

/* ---------- §14.3 element order: Views over time / Same video / Retention ----------
   §14.3's order is 7 Views over time, 8 Same video on other platforms, 9
   Retention, 10 Comments -- but §6.4 still wants Views-over-time paired
   with Retention in a 2-column row on YouTube desktop. Rather than fight
   those two rules against each other, the DOM order is the *mobile* order
   (vot-col, same-video, retention-col), which needs no CSS at all below
   1000px (plain block stacking already matches §14.3); at 1000px+, grid
   areas move retention-col up next to vot-col without touching the DOM.
   (Confirmed live before this fix: mobile showed Views over time, then
   Retention, then Same video -- Retention above Same video, the regression
   Karen flagged.) */
@media (min-width: 1000px) {
  .post-vot-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
    grid-template-areas: "vot retention" "samevideo samevideo";
  }
  .post-vot-grid > #vot-col { grid-area: vot; }
  .post-vot-grid > #retention-col { grid-area: retention; }
  .post-vot-grid > #same-video { grid-area: samevideo; }
}

/* ---------- §14.3 Views over time: zoom + one-reading ---------- */
.zoom-note { font-size: 13px; color: var(--muted); margin-top: 4px; }
.one-reading-line { font-size: 15px; margin: 8px 0; }

/* ---------- §14.4.1 dropped "Previous 28 days" column ---------- */
.no-previous-line { font-size: 13px; color: var(--muted); margin: 8px 0 4px; }

/* ---------- §14.5 Followers gained hidden row note ---------- */
.followers-gained-note { font-size: 13px; color: var(--muted); margin: 4px 0; }

/* ---------- §14.6 calculated-day notes / mixed time zone ---------- */
.tz-split-note { font-size: 13px; color: var(--muted); }

/* ---------- §14.7 Accounts: visible reconnect/disconnect hint (S7) ---------- */
.reconnect-hint { font-size: 13px; color: var(--muted); margin-top: 8px; }
.already-connected-note { font-size: 15px; margin: 8px 0; }

/* ---------- §14.7 / S4: video/post cards on phone ---------- */
@media (max-width: 719px) {
  /* §14.4.5/S4: phone post/video cards lose their card chrome and are
     separated by a rule line instead (these are only ever shown below
     720px -- .cards-to-table hides .card-only at 720px+).
     `.post-row` is itself `display:flex` (for `.connection-title-row`'s
     single-row use); these cards have a second top-level child (the
     counts) that needs to stack full-width below the thumb+title row, not
     compete with it as a second flex item -- which squeezed it into a
     narrow column and wrapped every label/value pair onto its own line
     (this *was* S4's "labels and values come apart"). */
  .card-only.post-row { display: block; border: none; border-bottom: 1px solid var(--rule); border-radius: 0; background: none; padding: 12px 0; margin-bottom: 0; }
  .card-only.post-row:last-child { border-bottom: none; }
  .nv-pair { white-space: nowrap; display: inline-block; margin-right: 12px; }
  .nv-pair .nv-label { font-size: 13px; color: var(--muted); }
  .nv-pair .nv-value { font-size: 15px; color: var(--fg); font-weight: 600; }
  .nv-group-label { display: block; font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; margin-top: 8px; }
  .nv-group-label:first-child { margin-top: 0; }
}

/* ---------- §14.4.5 / S6: desktop video tables group dividers ---------- */
.group-col-start { border-left: 1px solid var(--rule); }
.group-head-rule { border-bottom: 1px solid var(--rule); }
#sort-select, #ig-sort-select, #tt-sort-select { max-width: 20rem; }

/* ---------- N5: YouTube Analytics grid, 4 columns at >=1000px ---------- */
@media (min-width: 1000px) {
  .analytics-grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- S8: member rows stack below 720px ---------- */
.member-row .role-select { min-width: 9rem; }
@media (max-width: 719px) {
  .member-row { flex-wrap: wrap; }
  .member-row > div:first-child { flex: 1 1 100%; }
  .member-row .member-role-row { flex: 1 1 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
}

/* ---------- N2: "Last 28 d"/"Prev. 28 d" below 720px ---------- */
@media (max-width: 719px) {
  .full-range-label { display: none; }
  .short-range-label { display: inline; }
}
@media (min-width: 720px) {
  .full-range-label { display: inline; }
  .short-range-label { display: none; }
}

/* ---------- S14: same-video cards, 2-col numbers grid below 720px ----------
   Same markup as desktop (label span, then .val span); below 720px the
   rows become grid items with the value on top (column-reverse keeps DOM
   order, which screen readers read label-then-value, while flipping the
   visual order). */
@media (max-width: 719px) {
  .same-video-grid-numbers { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 16px; }
  .same-video-grid-numbers .same-video-numbers-row {
    display: flex; flex-direction: column-reverse; border-bottom: none; padding: 0; font-size: 13px; color: var(--muted);
  }
  .same-video-grid-numbers .same-video-numbers-row .val { font-size: 20px; font-weight: 600; color: var(--fg); font-variant-numeric: tabular-nums; }
  .same-video-asof { grid-column: 1 / -1; }
}
.not-same-video-btn {
  display: inline-flex; align-items: center; justify-content: flex-end; min-height: 44px;
  font-size: 13px; color: var(--muted); width: 100%; background: none; border: none; cursor: pointer; text-align: right;
}

/* ---------- N3: no-group state wrapped in a block ---------- */
.no-group-block { margin-bottom: 16px; }

/* ---------- S10: comparison lines / key swatches ---------- */
.swatch-compare { background: var(--muted); opacity: .7; }
.swatch-dashed {
  background-image: linear-gradient(to right, var(--series-2) 0 6px, transparent 6px 10px);
  background-repeat: repeat-x;
  background-size: 10px 3px;
  background-color: transparent !important;
}
.chart-figure { margin: 0; }
.chart-figure figcaption { font-size: 13px; color: var(--muted); }
