/* ======================================================================
   MobileTracking — base layer
   Reset, document defaults, typography, and the utilities that are used
   often enough to earn a class name.

   Load order matters and is fixed:  tokens.css → base.css → kit.css
   ====================================================================== */

/* ---------------------------------------------------------------- reset */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

body {
  min-height: 100dvh;
  background: var(--c-background);
  color: var(--c-on-surface);
  font-family: var(--font-sans);
  font-size: var(--t-body-md-size);
  line-height: var(--t-body-md-line);
  letter-spacing: var(--t-body-md-track);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

img,
svg,
video,
canvas {
  display: block;
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button { background: none; border: none; cursor: pointer; }

a { color: var(--c-primary-text); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

/* Tables collapse by default so a component does not have to remember to. */
table { border-collapse: collapse; width: 100%; }

/* ------------------------------------------------------------ focus ring
   One ring, everywhere, and it is never removed — only moved.

   `:focus-visible` rather than `:focus` so a mouse click on a button does not
   leave a ring behind, while a Tab press does. The 2px offset keeps the ring
   outside rounded corners, where a 0-offset ring gets visually clipped and
   looks like a rendering fault.                                              */

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* Windows high-contrast mode replaces every colour in this file. Forcing the
   ring to `Highlight` keeps it visible there rather than silently vanishing. */
@media (forced-colors: active) {
  :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline-color: Highlight;
  }
}

/* --------------------------------------------------------------- headings
   Sizes come from the token scale rather than from h1–h6, because heading
   LEVEL is a document-structure decision and heading SIZE is a visual one.
   Tying them together is what forces someone to pick an h4 for a card title
   purely because h2 looked too big, and that is how a page ends up with an
   outline no screen reader can navigate.                                     */

h1, h2, h3, h4, h5, h6 { font-weight: 600; letter-spacing: -0.01em; }

.t-display-lg,
.t-display-md,
.t-display-sm,
.t-headline-lg,
.t-headline-md,
.t-headline-sm,
.t-title-lg,
.t-title-md,
.t-title-sm,
.t-body-lg,
.t-body-md,
.t-body-sm,
.t-label-lg,
.t-label-md,
.t-label-sm { margin: 0; }

.t-display-lg  { font-size: var(--t-display-lg-size);  line-height: var(--t-display-lg-line);  font-weight: var(--t-display-lg-weight);  letter-spacing: var(--t-display-lg-track); }
.t-display-md  { font-size: var(--t-display-md-size);  line-height: var(--t-display-md-line);  font-weight: var(--t-display-md-weight);  letter-spacing: var(--t-display-md-track); }
.t-display-sm  { font-size: var(--t-display-sm-size);  line-height: var(--t-display-sm-line);  font-weight: var(--t-display-sm-weight);  letter-spacing: var(--t-display-sm-track); }
.t-headline-lg { font-size: var(--t-headline-lg-size); line-height: var(--t-headline-lg-line); font-weight: var(--t-headline-lg-weight); letter-spacing: var(--t-headline-lg-track); }
.t-headline-md { font-size: var(--t-headline-md-size); line-height: var(--t-headline-md-line); font-weight: var(--t-headline-md-weight); letter-spacing: var(--t-headline-md-track); }
.t-headline-sm { font-size: var(--t-headline-sm-size); line-height: var(--t-headline-sm-line); font-weight: var(--t-headline-sm-weight); letter-spacing: var(--t-headline-sm-track); }
.t-title-lg    { font-size: var(--t-title-lg-size);    line-height: var(--t-title-lg-line);    font-weight: var(--t-title-lg-weight);    letter-spacing: var(--t-title-lg-track); }
.t-title-md    { font-size: var(--t-title-md-size);    line-height: var(--t-title-md-line);    font-weight: var(--t-title-md-weight);    letter-spacing: var(--t-title-md-track); }
.t-title-sm    { font-size: var(--t-title-sm-size);    line-height: var(--t-title-sm-line);    font-weight: var(--t-title-sm-weight);    letter-spacing: var(--t-title-sm-track); }
.t-body-lg     { font-size: var(--t-body-lg-size);     line-height: var(--t-body-lg-line);     font-weight: var(--t-body-lg-weight);     letter-spacing: var(--t-body-lg-track); }
.t-body-md     { font-size: var(--t-body-md-size);     line-height: var(--t-body-md-line);     font-weight: var(--t-body-md-weight);     letter-spacing: var(--t-body-md-track); }
.t-body-sm     { font-size: var(--t-body-sm-size);     line-height: var(--t-body-sm-line);     font-weight: var(--t-body-sm-weight);     letter-spacing: var(--t-body-sm-track); }
.t-label-lg    { font-size: var(--t-label-lg-size);    line-height: var(--t-label-lg-line);    font-weight: var(--t-label-lg-weight);    letter-spacing: var(--t-label-lg-track); }
.t-label-md    { font-size: var(--t-label-md-size);    line-height: var(--t-label-md-line);    font-weight: var(--t-label-md-weight);    letter-spacing: var(--t-label-md-track); }
.t-label-sm    { font-size: var(--t-label-sm-size);    line-height: var(--t-label-sm-line);    font-weight: var(--t-label-sm-weight);    letter-spacing: var(--t-label-sm-track); }

/* Numbers that sit in a column, or that tick upward in place. `tabular-nums`
   stops a counter from jittering as its digits change width. */
.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.92em;
  letter-spacing: 0;
}

/* A small uppercase label above a heading. Tracked out generously, because
   uppercase at 11px without extra tracking is genuinely hard to read. */
.eyebrow {
  font-size: var(--t-label-sm-size);
  line-height: var(--t-label-sm-line);
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--c-on-surface-variant);
}

/* ------------------------------------------------------------ text colour */

.dim   { color: var(--c-on-surface-variant); }
.faint { color: var(--c-outline); }

.c-safe     { color: var(--c-safe); }
.c-caution  { color: var(--c-caution); }
.c-risk     { color: var(--c-risk); }
.c-critical { color: var(--c-critical); }
.c-primary  { color: var(--c-primary-text); }

/* --------------------------------------------------------------- layout */

.stack   { display: flex; flex-direction: column; }
.row     { display: flex; align-items: center; }
.row-top { display: flex; align-items: flex-start; }
.wrap    { flex-wrap: wrap; }
.between { justify-content: space-between; }
.center  { justify-content: center; }
.grow    { flex: 1 1 auto; min-width: 0; }
/* "Do not stretch, do not shrink" — but still never wider than the space there
   is. Without the cap, a `.none` box takes its max-content width and any
   `.wrap` inside it can never engage, because a row that is already as wide as
   it wants to be has nothing to wrap. That is how the two "tell me when they
   arrive / leave" toggles on Places ended up 130px off the edge of a phone,
   inside a card that clips. */
.none    { flex: 0 0 auto; max-width: 100%; }

.g-hair { gap: var(--s-hair); }
.g-xs   { gap: var(--s-xs); }
.g-sm   { gap: var(--s-sm); }
.g-md   { gap: var(--s-md); }
.g-lg   { gap: var(--s-lg); }
.g-xl   { gap: var(--s-xl); }

/* Auto-fitting grid. `--min` is the narrowest a column may get before the grid
   drops one; set it per instance rather than adding a class per breakpoint.

   `min(--min, 100%)` rather than `--min` alone, because `minmax(260px, 1fr)`
   has a floor of 260px even when the container is 200px wide — the track keeps
   its minimum and the grid overflows. That is not theoretical: the dashboard
   asks for 380px columns and a phone gives it 358, so every child card on the
   busiest screen in the product hung 22px off the right edge and took the page
   with it. The `min()` lets the track collapse to the container on the screens
   where the number cannot be honoured. */
.grid {
  display: grid;
  gap: var(--s-lg);
  grid-template-columns: repeat(auto-fit, minmax(min(var(--min, 260px), 100%), 1fr));
}

.grid-2 { display: grid; gap: var(--s-lg); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: var(--s-lg); grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: var(--s-lg); grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* One breakpoint, not five. Below 900px this product is a single column, and
   pretending otherwise produces two 180px-wide charts side by side. */
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
}

/* `align-items: start` so a card sizes to its own content instead of
   stretching to match the tallest sibling. Without it, a card holding one line
   of empty-state text beside a full one renders as a mostly-blank box the
   height of its neighbour, which reads as a loading failure rather than as an
   empty state. */
.grid-main-side { display: grid; gap: var(--s-lg); align-items: start; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-side-main { display: grid; gap: var(--s-lg); align-items: start; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }

@media (max-width: 1100px) {
  .grid-main-side, .grid-side-main { grid-template-columns: minmax(0, 1fr); }
}

/* ------------------------------------------------------------- utilities */

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Clamp to N lines. Set --lines per instance. */
.clamp {
  display: -webkit-box;
  -webkit-line-clamp: var(--lines, 2);
  line-clamp: var(--lines, 2);
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.hidden { display: none !important; }

/**
 * Visible to screen readers, invisible on screen.
 *
 * Used for the words that make an icon-only control comprehensible, and for
 * headings that structure a page which does not visually need them. The
 * clip-path/1px combination rather than `display:none` because the latter
 * removes the element from the accessibility tree entirely, which defeats the
 * purpose.
 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/** Same, but becomes visible on focus. For the skip link. */
.sr-only-focusable:focus-visible {
  position: fixed;
  top: var(--s-md);
  left: var(--s-md);
  z-index: 200;
  width: auto;
  height: auto;
  margin: 0;
  padding: var(--s-md) var(--s-lg);
  clip: auto;
  clip-path: none;
  background: var(--c-primary);
  color: var(--c-on-primary);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-3);
}

/* Icons inherit their colour and their weight from the text around them, so a
   row does not need to restate either. */
.i {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.i-sm { width: 1em; height: 1em; }
.i-lg { width: 1.4em; height: 1.4em; }

hr, .rule {
  border: 0;
  border-top: 1px solid var(--c-outline-variant);
  margin: 0;
}

/* ---------------------------------------------------------------- print
   Panels get printed and emailed more than anyone expects — usually as
   evidence in a conversation with a school or an ex-partner. Making that
   legible costs almost nothing.                                             */

@media print {
  body { background: #fff; color: #000; }
  .rail, .topbar, .bottom-nav, .btn, .no-print { display: none !important; }
  .card { border: 1px solid #999; box-shadow: none; break-inside: avoid; }
  .main { padding: 0; }
  a::after { content: ' (' attr(href) ')'; font-size: 0.85em; color: #555; }
}
