/* wrist — mobile first, because Brooke will read this on a phone.
 *
 * Palette is the validated dataviz default. Only three hues carry meaning:
 * moving, stopped, off-wrist. An earlier five-hue version (one per gap cause)
 * FAILED validation — yellow outside the lightness band, yellow/orange ΔE 13.6
 * against a 15 floor — and was over-encoding anyway. The distinction that
 * matters is "was it on your wrist", not whether a hole was LTE or battery.
 *
 * Dark-mode red↔aqua sits in the 6–8 CVD band, legal only with secondary
 * encoding, so every segment ships an icon, a direct label and a 2px gap.
 */

:root {
  color-scheme: light;
  --surface:   #fcfcfb;
  --plane:     #f4f4f1;
  --sunken:    #eeeeea;
  --ink:       #0b0b0b;
  --ink-2:     #52514e;
  --ink-muted: #898781;
  --grid:      #e1e0d9;
  --rule:      #c3c2b7;
  --hairline:  rgba(11, 11, 11, .09);
  --shadow:    0 1px 2px rgba(11,11,11,.04), 0 4px 16px rgba(11,11,11,.05);

  --moving:   #2a78d6;
  --stopped:  #1baf7a;
  --offwrist: #d03b3b;
  --benign:   #b9b7ae;

  --r:   14px;
  --r-s: 9px;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface: #1a1a19; --plane: #101010; --sunken: #232322;
    --ink: #fff; --ink-2: #c3c2b7; --ink-muted: #898781;
    --grid: #2c2c2a; --rule: #383835; --hairline: rgba(255,255,255,.09);
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    --moving: #3987e5; --stopped: #199e70; --offwrist: #d03b3b; --benign: #55534d;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #1a1a19; --plane: #101010; --sunken: #232322;
  --ink: #fff; --ink-2: #c3c2b7; --ink-muted: #898781;
  --grid: #2c2c2a; --rule: #383835; --hairline: rgba(255,255,255,.09);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  --moving: #3987e5; --stopped: #199e70; --offwrist: #d03b3b; --benign: #55534d;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--plane); color: var(--ink);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.screen { min-height: 100%; display: flex; flex-direction: column; }
:focus-visible { outline: 2px solid var(--moving); outline-offset: 2px; border-radius: 4px; }

/* ---------- login ---------- */
#login { align-items: center; justify-content: center; padding: 1.5rem; }
#login-form {
  width: min(21rem, 100%); display: grid; gap: .9rem;
  background: var(--surface); padding: 1.6rem; border-radius: var(--r);
  border: 1px solid var(--hairline); box-shadow: var(--shadow);
}
#login-form h1 {
  margin: 0 0 .2rem; font-size: 1.35rem; letter-spacing: -.02em; font-weight: 640;
}
label { display: grid; gap: .3rem; font-size: .76rem; color: var(--ink-2); font-weight: 500; }
input, button, select {
  font: inherit; padding: .62rem .7rem; border-radius: var(--r-s);
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink);
}
input:focus { border-color: var(--moving); }
button { cursor: pointer; min-height: var(--tap); }
button.primary, #login-form button {
  background: var(--moving); color: #fff; border-color: transparent; font-weight: 620;
}
.error { color: var(--offwrist); margin: 0; font-size: .84rem; }

/* ---------- header ---------- */
header {
  display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: center;
  justify-content: space-between;
  padding: max(.65rem, env(safe-area-inset-top)) .9rem .65rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--hairline);
  position: sticky; top: 0; z-index: 600;
}
.brand { display: flex; align-items: center; gap: .45rem; min-width: 0; flex-wrap: wrap; }
.brand strong {
  font-size: .98rem; letter-spacing: -.01em; font-weight: 640;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 12rem;
}
.ctrl { display: flex; gap: .3rem; align-items: center; }
.ctrl button { padding: .4rem .58rem; min-height: 36px; border-radius: var(--r-s); }
.ctrl button:hover { background: var(--sunken); }
.ctrl input[type=date] { padding: .32rem .5rem; min-height: 36px; border-radius: var(--r-s); }

.pill {
  font-size: .72rem; padding: .22rem .5rem; border-radius: 999px;
  background: var(--sunken); color: var(--ink-2); white-space: nowrap;
  display: inline-flex; align-items: center; gap: .3rem; font-weight: 550;
  border: 1px solid transparent;
}
.pill.ok   { background: color-mix(in srgb, var(--stopped) 14%, transparent); color: var(--stopped); }
.pill.warn { background: color-mix(in srgb, var(--offwrist) 12%, transparent); color: var(--offwrist); }
.pill.bad  { background: var(--offwrist); color: #fff; font-weight: 650; }

/* ---------- layout ---------- */
main {
  padding: .9rem; display: grid; gap: .9rem;
  max-width: 74rem; width: 100%; margin: 0 auto;
}
.card {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r); padding: 1rem; box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 .75rem; font-size: .7rem; font-weight: 640;
  text-transform: uppercase; letter-spacing: .09em; color: var(--ink-muted);
}

/* ---------- stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r); padding: .8rem .9rem; box-shadow: var(--shadow);
}
.stat .k {
  font-size: .67rem; color: var(--ink-muted); text-transform: uppercase;
  letter-spacing: .08em; font-weight: 620;
}
.stat .v {
  font-size: 1.75rem; line-height: 1.1; margin-top: .25rem;
  letter-spacing: -.03em; font-weight: 560;
}
.stat .s { font-size: .73rem; color: var(--ink-2); margin-top: .15rem; }
.stat.alert { border-color: color-mix(in srgb, var(--offwrist) 40%, transparent); }
.stat.alert .v { color: var(--offwrist); }

/* ---------- coverage band ---------- */
.band-wrap { position: relative; }
.band {
  display: flex; height: 52px; width: 100%; gap: 2px;
  border-radius: var(--r-s); overflow: hidden; background: var(--grid);
}
.seg {
  position: relative; min-width: 2px; border: 0; padding: 0;
  cursor: pointer; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  transition: filter .12s ease;
}
.seg:hover { filter: brightness(1.08); }
.seg:first-child { border-radius: var(--r-s) 0 0 var(--r-s); }
.seg:last-child  { border-radius: 0 var(--r-s) var(--r-s) 0; }
.seg.moving   { background: var(--moving); }
.seg.stopped  { background: var(--stopped); }
.seg.offwrist { background: var(--offwrist); }
.seg.benign   { background: var(--benign); }
/* Texture on gaps: the accessibility channel, and it reads as "absence"
   rather than "a different activity" without relying on hue. */
.seg.gap::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(135deg,
    rgba(255,255,255,.26) 0 2px, transparent 2px 6px);
}
.seg .lbl {
  font-size: .67rem; font-weight: 650; color: #fff; z-index: 1;
  white-space: nowrap; padding: 0 .35rem; letter-spacing: .01em;
  text-shadow: 0 1px 2px rgba(0,0,0,.4);
}
/* "now" marker, only on today */
.now-line {
  position: absolute; top: -3px; bottom: 18px; width: 2px;
  background: var(--ink); z-index: 5; pointer-events: none; border-radius: 2px;
}
.now-line::before {
  content: ""; position: absolute; top: -3px; left: -3px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--ink);
}
.axis {
  display: flex; justify-content: space-between; margin-top: .4rem;
  font-size: .67rem; color: var(--ink-muted); font-variant-numeric: tabular-nums;
}
.legend { display: flex; flex-wrap: wrap; gap: .3rem .95rem; margin-top: .75rem; }
.legend span { display: inline-flex; align-items: center; gap: .38rem;
               font-size: .73rem; color: var(--ink-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- map ---------- */
#map {
  height: 44vh; min-height: 250px; border-radius: var(--r-s);
  background: var(--sunken); border: 1px solid var(--hairline);
}
.leaflet-container { border-radius: var(--r-s); font: inherit; }

/* ---------- timeline ---------- */
#segments { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
#segments li {
  display: grid; grid-template-columns: 3.9rem 1.2rem 1fr auto;
  gap: .5rem; align-items: baseline;
  padding: .55rem .6rem; border-radius: var(--r-s);
  background: var(--plane); border-left: 3px solid var(--rule);
  cursor: pointer; min-height: 40px;
  transition: background .12s ease;
}
#segments li:hover { background: var(--sunken); }
#segments li.stopped  { border-left-color: var(--stopped); }
#segments li.moving   { border-left-color: var(--moving); }
#segments li.benign   { border-left-color: var(--benign); }
#segments li.offwrist {
  border-left-color: var(--offwrist);
  background: color-mix(in srgb, var(--offwrist) 7%, var(--plane));
}
.t { font-size: .76rem; color: var(--ink-2); font-variant-numeric: tabular-nums;
     font-weight: 540; }
.ico { font-size: .9rem; line-height: 1; color: var(--ink-2); }
.w { min-width: 0; }
.w b { font-weight: 600; font-size: .92rem; }
.w small { display: block; color: var(--ink-muted); font-size: .71rem; margin-top: .1rem; }
.d { font-size: .78rem; color: var(--ink-2); white-space: nowrap;
     font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-muted); font-size: .84rem; padding: .5rem 0; }

/* ---------- tooltip ---------- */
#tip {
  position: fixed; z-index: 900; pointer-events: none;
  background: var(--ink); color: var(--surface);
  padding: .45rem .6rem; border-radius: 8px; font-size: .75rem; line-height: 1.4;
  box-shadow: 0 6px 20px rgba(0,0,0,.28); max-width: 16rem;
}
#tip b { display: block; font-size: .79rem; margin-bottom: .1rem; }

/* ---------- skeleton, so a slow load does not look like no data ---------- */
.skel { background: linear-gradient(90deg, var(--sunken) 25%, var(--grid) 37%, var(--sunken) 63%);
        background-size: 400% 100%; animation: sh 1.4s ease infinite; border-radius: var(--r-s); }
@keyframes sh { 0% { background-position: 100% 0 } 100% { background-position: 0 0 } }

@media (min-width: 940px) {
  .split { display: grid; grid-template-columns: minmax(0,1fr) 23rem; gap: .9rem; align-items: start; }
  #map { height: 58vh; }
  #segments { max-height: 58vh; overflow-y: auto; }
}

/* ---------- sign-in alternatives ---------- */
/* Google's brand guidelines require their mark on a white or dark surface with
   the wordmark legible, so this button keeps its own colours in both themes
   rather than inheriting the palette. */
.gbtn {
  display: flex; align-items: center; justify-content: center; gap: .6rem;
  min-height: var(--tap); padding: .62rem .9rem;
  border: 1px solid var(--rule); border-radius: var(--r-s);
  background: #fff; color: #1f1f1f; font-weight: 600; font-size: .92rem;
  text-decoration: none; cursor: pointer;
}
.gbtn:hover { background: #f7f7f7; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .gbtn { background: #131314; color: #e3e3e3; border-color: #5f6368; }
  :root:where(:not([data-theme="light"])) .gbtn:hover { background: #1e1f20; }
}
:root[data-theme="dark"] .gbtn { background: #131314; color: #e3e3e3; border-color: #5f6368; }

.sep { display: flex; align-items: center; gap: .7rem; color: var(--ink-muted); font-size: .74rem; }
.sep::before, .sep::after { content: ""; flex: 1; height: 1px; background: var(--hairline); }

.quiet { color: var(--ink-muted); font-size: .78rem; text-align: center; text-decoration: none; }
.quiet:hover { color: var(--ink-2); text-decoration: underline; }

.notice { font-size: .84rem; color: var(--ink-2); margin: 0; line-height: 1.5; }
.ok-note { color: var(--stopped); }

/* ---------- provenance ---------- */
/* A phone can show where it is but never who is carrying it. These stretches
   are real observations and belong in the record, but they are a weaker claim
   than the watch's, and the timeline must not present them as equivalent. */
#segments li.unverified { border-left-style: dashed; }
#segments li.unverified .ico { opacity: .5; }

.tag {
  font-size: .58rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; vertical-align: middle;
  padding: .1rem .3rem; margin-left: .35rem; border-radius: 4px;
  background: var(--sunken); color: var(--ink-muted);
}

/* Mode of transport. A glyph, not a new hue: the palette validated at three
   colours and adding five more would fail contrast the way an earlier version
   did. Colour reinforces the icon here; it never carries meaning alone. */
.mode { font-size: .8rem; margin-left: .25rem; vertical-align: baseline; }
