/* B7 Tracker — field.css
 *
 * Styles ONLY the inside of #field (the field browser / checkpoint detail sheet
 * built by js/field.js). base.css owns the #field box itself: on phones it is a
 * fixed bottom sheet (flex column, max-height min(88dvh, 820px), safe-area
 * padding, translateY transition, `.open` toggled by field.js); from 900px up it
 * becomes a centred dialog. Nothing here touches that box or redefines a token.
 *
 * Primitives reused from base.css: .btn .btn.sm .btn.icon .btn.ghost .chip
 * .chip.on .inp .skel .sr-only .num.
 *
 * Layout inside the sheet (top to bottom):
 *   .b7f-grip   drag handle        (phones only)
 *   .b7f-head   title + actions    (fixed)
 *   .b7f-tools  search + filters   (fixed)
 *   .b7f-body   list / states      (flex: 1, the only scrolling area)
 *   .b7f-foot   meta + close       (fixed)
 */

#field [hidden] { display: none !important; }

#field .b7f-ico {
  display: block;
  width: 20px;
  height: 20px;
  flex: none;
}


/* ================================================================== *
 * Drag handle
 * ================================================================== */

.b7f-grip {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.b7f-grip__bar {
  display: block;
  width: 42px;
  height: 4px;
  border-radius: var(--r-full);
  background: var(--line-strong);
  transition: background-color var(--dur) ease;
}

.b7f-grip:active { cursor: grabbing; }
.b7f-grip:active .b7f-grip__bar { background: var(--fg-3); }


/* ================================================================== *
 * Header
 * ================================================================== */

.b7f-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-1) var(--s-4) var(--s-3);
  touch-action: none;
}

.b7f-titles {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.b7f-title {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-4);
  font-weight: 700;
  line-height: 1.2;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.b7f-subtitle {
  margin: 0;
  font-size: var(--fs-1);
  font-weight: 600;
  line-height: 1.35;
  color: var(--fg-3);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.b7f-subtitle.is-stale { color: var(--warn); }

.b7f-subtitle:empty { display: none; }

/* The header is a drag surface; its controls must still be tappable. */
.b7f-head .btn { touch-action: manipulation; }


/* ================================================================== *
 * Tools — search box, filter chips, gap legend
 * ================================================================== */

.b7f-tools {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: 0 var(--s-4) var(--s-3);
}

.b7f-search {
  position: relative;
  display: block;
}

.b7f-search__ico {
  position: absolute;
  top: 50%;
  left: var(--s-3);
  transform: translateY(-50%);
  color: var(--fg-3);
  pointer-events: none;
}

.b7f-input {
  min-height: 48px;
  padding-left: calc(var(--s-3) + 20px + var(--s-2));
  padding-right: 48px;
  font-size: var(--fs-3);   /* never below 16px: iOS zooms smaller inputs */
}

/* Our own clear button replaces the native one, which is unstyleable. */
.b7f-input::-webkit-search-cancel-button,
.b7f-input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }

.b7f-clear {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: var(--r-2);
  background: transparent;
  color: var(--fg-3);
  cursor: pointer;
}

@media (hover: hover) {
  .b7f-clear:hover { color: var(--fg); }
}

.b7f-chips {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  /* Let focus rings on the chips breathe instead of being clipped. */
  margin: 0 calc(var(--s-1) * -1);
  padding: 0 var(--s-1) 2px;
}

.b7f-chips::-webkit-scrollbar { display: none; }

.b7f-chip { flex: none; }

.b7f-chip[disabled] {
  opacity: .4;
  pointer-events: none;
}

.b7f-jump { gap: var(--s-1); }

#field .b7f-jump .b7f-ico { width: 16px; height: 16px; }

.b7f-jump__txt {
  max-width: 14ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.b7f-legend {
  margin: 0;
  font-size: var(--fs-1);
  line-height: 1.3;
  color: var(--fg-3);
}


/* ================================================================== *
 * Body — the only scrolling area in the sheet
 * ================================================================== */

.b7f-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border-top: 1px solid var(--line);
}

.b7f-scroll {
  /* Source of truth for the virtualised row height: field.js reads this
     custom property and computes the window from it. Keep them in sync. */
  --b7f-row-h: 64px;

  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  outline: none;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.b7f-scroll::-webkit-scrollbar { width: 10px; }
.b7f-scroll::-webkit-scrollbar-track { background: transparent; }
.b7f-scroll::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: var(--r-full);
  background: var(--line-strong);
  background-clip: content-box;
}

/* Spacer that gives the scrollbar the full list height. */
.b7f-runner {
  position: relative;
  width: 100%;
}

/* The rendered window; translated into place on every scroll frame. */
.b7f-win {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  will-change: transform;
}


/* ================================================================== *
 * Row
 * ================================================================== */

.b7f-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  height: var(--b7f-row-h, 64px);
  margin: 0;
  padding: 0 var(--s-4);
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: var(--fs-3);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur) ease;
}

@media (hover: hover) {
  .b7f-row:hover { background: var(--surface); }
}

.b7f-row:active { background: var(--surface-2); }

.b7f-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
}

.b7f-pos {
  min-width: 3.8ch;
  font-size: var(--fs-2);
  font-weight: 600;
  line-height: 1.1;
  text-align: right;
  color: var(--fg-3);
}

.b7f-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.b7f-name {
  font-size: var(--fs-3);
  font-weight: 600;
  line-height: 1.2;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.b7f-sub {
  font-size: var(--fs-1);
  font-weight: 500;
  line-height: 1.2;
  color: var(--fg-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.b7f-sub:empty { display: none; }

.b7f-end {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
  white-space: nowrap;
}

.b7f-val {
  font-size: var(--fs-2);
  font-weight: 600;
  line-height: 1.2;
  color: var(--fg);
}

.b7f-val.is-ok { color: var(--ok); }

.b7f-note {
  font-family: var(--font-mono);
  font-size: var(--fs-1);
  font-weight: 500;
  line-height: 1.2;
  color: var(--fg-3);
  font-variant-numeric: tabular-nums;
}

.b7f-note:empty { display: none; }
.b7f-note.is-ahead { color: var(--info); }
.b7f-note.is-behind { color: var(--fg-3); }
.b7f-note.is-hero { color: var(--accent-2); font-family: var(--font-sans); }

/* --- row states --------------------------------------------------- */

.b7f-row.is-lost .b7f-name { color: var(--fg-2); }
.b7f-row.is-lost .b7f-sub { color: var(--warn); }

.b7f-row.is-current {
  box-shadow: inset 3px 0 0 0 var(--info);
  background: rgba(92, 180, 255, .07);
}

/* The pinned racer. Loud on purpose: it must be findable at a glance. */
.b7f-row.is-hero {
  box-shadow: inset 3px 0 0 0 var(--accent);
  background: var(--accent-dim);
}

.b7f-row.is-hero .b7f-name { color: var(--accent-2); font-weight: 700; }
.b7f-row.is-hero .b7f-pos { color: var(--accent-2); }

@media (hover: hover) {
  .b7f-row.is-hero:hover { background: rgba(255, 122, 31, .24); }
}

.b7f-row.is-flash { animation: b7f-flash 1.4s ease-out 1; }

@keyframes b7f-flash {
  0%   { background: rgba(255, 122, 31, .46); }
  100% { background: var(--accent-dim); }
}


/* ================================================================== *
 * Loading / empty / error states
 * ================================================================== */

.b7f-state {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* --- "not ready yet" bar, shown above the skeleton ----------------- */

.b7f-notebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line);
  background: var(--bg-3);
}

.b7f-notebar__txt {
  min-width: 0;
  font-size: var(--fs-2);
  line-height: 1.4;
  color: var(--fg-2);
}

.b7f-notebar .btn { flex: none; }

@media (min-width: 900px) {
  .b7f-notebar { padding-inline: var(--s-5); }
}

/* --- skeleton ----------------------------------------------------- */

.b7f-skel { padding: 0; }

.b7f-skelrow {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s-3);
  height: var(--b7f-row-h, 64px);
  padding: 0 var(--s-4);
  border-bottom: 1px solid var(--line);
}

.b7f-skel-pos { width: 26px; height: 12px; }

.b7f-skel-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.b7f-skel-name { width: 62%; max-width: 190px; height: 13px; }
.b7f-skel-sub { width: 38%; max-width: 120px; height: 10px; }
.b7f-skel-val { width: 58px; height: 13px; }

/* Stagger the shimmer so the list reads as one loading surface. */
.b7f-skelrow:nth-child(2n) .skel::after { animation-delay: .18s; }
.b7f-skelrow:nth-child(3n) .skel::after { animation-delay: .36s; }
.b7f-skelrow:nth-child(4n) { opacity: .86; }
.b7f-skelrow:nth-child(5n) { opacity: .72; }
.b7f-skelrow:nth-child(7n) { opacity: .58; }

/* --- message (empty / error) -------------------------------------- */

.b7f-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3);
  min-height: 100%;
  padding: var(--s-6) var(--s-5);
  text-align: center;
}

.b7f-msg__ico {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--bg-3);
  color: var(--fg-3);
}

#field .b7f-msg__svg { width: 24px; height: 24px; }

.b7f-state[data-kind="error"] .b7f-msg__ico {
  border-color: rgba(255, 93, 82, .38);
  color: var(--bad);
}

.b7f-msg__title {
  margin: 0;
  font-size: var(--fs-4);
  font-weight: 700;
  line-height: 1.25;
  color: var(--fg);
}

.b7f-msg__text {
  margin: 0;
  max-width: 38ch;
  font-size: var(--fs-2);
  line-height: 1.55;
  color: var(--fg-2);
  overflow-wrap: anywhere;
}

.b7f-msg__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s-2);
  margin-top: var(--s-1);
}


/* ================================================================== *
 * Footer
 * ================================================================== */

.b7f-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-4);
  border-top: 1px solid var(--line);
  background: var(--bg-3);
}

.b7f-metas {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.b7f-meta {
  margin: 0;
  font-size: var(--fs-2);
  font-weight: 600;
  line-height: 1.25;
  color: var(--fg-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.b7f-fresh {
  margin: 0;
  font-size: var(--fs-1);
  line-height: 1.25;
  color: var(--fg-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.b7f-meta:empty, .b7f-fresh:empty { display: none; }

.b7f-footclose { flex: none; }


/* ================================================================== *
 * Narrow phones
 * ================================================================== */

@media (max-width: 359px) {
  .b7f-head, .b7f-tools, .b7f-row, .b7f-skelrow, .b7f-foot { padding-inline: var(--s-3); }
  .b7f-row { gap: var(--s-2); }
  .b7f-pos { min-width: 3.2ch; }
  .b7f-jump__txt { max-width: 10ch; }
}


/* ================================================================== *
 * Desktop dialog (>= 900px): no drag handle, denser rows
 * ================================================================== */

@media (min-width: 900px) {
  .b7f-grip { display: none; }

  .b7f-head {
    padding-top: var(--s-4);
    touch-action: auto;
  }

  .b7f-scroll { --b7f-row-h: 56px; }

  .b7f-row { padding-inline: var(--s-5); }
  .b7f-skelrow { padding-inline: var(--s-5); }
  .b7f-head, .b7f-tools, .b7f-foot { padding-inline: var(--s-5); }

  .b7f-jump__txt { max-width: none; }
}


/* ================================================================== *
 * Reduced motion — base.css already zeroes --dur and neutralises
 * keyframes globally; kill the flash's colour jump as well.
 * ================================================================== */

@media (prefers-reduced-motion: reduce) {
  .b7f-row.is-flash {
    animation: none;
    background: rgba(255, 122, 31, .32);
  }
  .b7f-win { will-change: auto; }
}
