/* GPS Tracker dashboard.
   Tokens and the sign-in block are shared with the Hannale dashboard on
   purpose: same operators, same phones, same reverse proxy. Only the two
   panels below - the message log and the map - are new. */

:root {
  color-scheme: light;

  /* surfaces & ink */
  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --surface-2:    #f2f1ec;
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --muted:        #898781;
  --border:       rgba(11, 11, 11, 0.10);

  /* data */
  --series-1:     #2a78d6;

  /* status - fixed in both modes, never used for a track colour */
  --good:         #0ca30c;
  --warning:      #fab219;
  --critical:     #d03b3b;

  --shadow:       0 1px 2px rgba(11, 11, 11, .05), 0 8px 24px rgba(11, 11, 11, .04);

  --radius:       14px;
  --radius-sm:    9px;

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* One line of the message log. Five of these is the box. */
  --msg-line: 26px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:        #0d0d0d;
  --surface:      #1a1a19;
  --surface-2:    #232322;
  --ink:          #ffffff;
  --ink-2:        #c3c2b7;
  --muted:        #898781;
  --border:       rgba(255, 255, 255, 0.10);
  --series-1:     #3987e5;
  --shadow:       0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
}

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

body {
  margin: 0;
  font-family: var(--font);
  background: var(--plane);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--series-1); }

.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;
}

[hidden] { display: none !important; }

/* ------------------------------------------------------------------ */
/* Brand                                                               */
/* ------------------------------------------------------------------ */

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 30px; height: 30px; flex: none; border-radius: 8px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 650; letter-spacing: -.01em; }
.brand-sub {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
}

/* ------------------------------------------------------------------ */
/* Login                                                               */
/* ------------------------------------------------------------------ */

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.auth-card .brand { justify-content: center; margin-bottom: 4px; }
.auth-title { font-size: 20px; font-weight: 650; margin: 20px 0 4px; text-align: center; }
.auth-hint { color: var(--ink-2); font-size: 13.5px; margin: 0 0 24px; text-align: center; }

.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--ink-2); margin-bottom: 6px;
}

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 11px 12px;
  font: inherit;
  font-size: 14.5px;
  color: var(--ink);
  background: var(--plane);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus-visible {
  border-color: var(--series-1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--series-1) 22%, transparent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
.btn[disabled] { opacity: .55; cursor: default; }

.btn-primary {
  width: 100%;
  background: var(--series-1);
  border-color: transparent;
  color: #fff;
  padding: 12px 16px;
  margin-top: 6px;
}
.btn-primary:hover { filter: brightness(1.06); border-color: transparent; }

.btn-icon { padding: 8px 10px; }
.btn-small { font-size: 12px; padding: 6px 10px; }

/* A pressed toggle has to read as pressed without relying on colour alone. */
.btn[aria-pressed="true"] {
  background: var(--series-1); border-color: transparent; color: #fff;
}

.select {
  font: inherit; font-size: 12px; font-weight: 600;
  padding: 6px 8px;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.alert {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  font-size: 13.5px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  border: 1px solid color-mix(in srgb, var(--critical) 40%, transparent);
  background: color-mix(in srgb, var(--critical) 10%, transparent);
  color: var(--ink);
}
.alert svg { flex: none; margin-top: 2px; }

/* ------------------------------------------------------------------ */
/* Shell                                                               */
/* ------------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.user-chip {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--ink-2);
  padding-left: 12px; margin-left: 4px;
  border-left: 1px solid var(--border);
}

main {
  padding: 20px;
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Icon plus label, never colour alone. */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 11px 6px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.pill[data-state="good"]     .dot { background: var(--good); }
.pill[data-state="warning"]  .dot { background: var(--warning); }
.pill[data-state="critical"] .dot { background: var(--critical); }
.pill[data-state="good"] .dot { animation: pulse 2.4s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 55%, transparent); }
  70%      { box-shadow: 0 0 0 5px transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .pill[data-state="good"] .dot { animation: none; }
}

.timestamp { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ------------------------------------------------------------------ */
/* Cards                                                               */
/* ------------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-title { font-size: 14px; font-weight: 650; margin: 0; }
.card-sub { font-size: 12px; color: var(--muted); margin: 2px 0 0; }
.card-head .spacer { flex: 1; }
.card-foot { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

.count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

/* ------------------------------------------------------------------ */
/* Message log - exactly five lines tall                               */
/* ------------------------------------------------------------------ */
/* Five lines is the brief and it is also the right size: on a phone held
   one-handed in a field, more than five lines of scrollback is not read,
   it is scrolled past. Everything older is still here, one flick away. */

.msg-box {
  /* box-sizing is border-box, so the padding has to be added back or the
     fifth line is clipped in half - which looks like a rendering bug rather
     than a deliberate five. */
  height: calc(5 * var(--msg-line) + 12px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 10px;
  background: var(--plane);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 13px;
  /* overscroll-contain so flicking to the end of the log does not carry on
     and scroll the page - the map below is a big drop. */
  overscroll-behavior: contain;
}
.msg-box:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

.msg-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  height: var(--msg-line);
  line-height: var(--msg-line);
  white-space: nowrap;
}
.msg-time { color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }
.msg-text { color: var(--ink); overflow: hidden; text-overflow: ellipsis; }

/* Two seconds of highlight on the newest arrival, so a line that lands while
   you are looking elsewhere is still findable when you look back. */
.msg-row.fresh { animation: freshfade 2s ease-out 1; }
@keyframes freshfade {
  from { background: color-mix(in srgb, var(--good) 22%, transparent); }
  to   { background: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .msg-row.fresh { animation: none; }
}

.msg-empty { color: var(--muted); margin: 0; line-height: var(--msg-line); }

/* ------------------------------------------------------------------ */
/* Map                                                                 */
/* ------------------------------------------------------------------ */

.map-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.map-wrap {
  position: relative;
  height: min(62vh, 640px);
  min-height: 320px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

#map { position: absolute; inset: 0; }

.map-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  font-size: 13.5px;
  color: var(--ink-2);
  background: var(--surface-2);
}
.map-placeholder code {
  font-family: var(--mono); font-size: 12.5px;
  background: var(--plane); padding: 1px 5px; border-radius: 4px;
}

.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  color: var(--ink);
}
.legend-item .swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.legend-item[aria-pressed="false"] { opacity: .45; text-decoration: line-through; }
.legend-count { color: var(--muted); font-variant-numeric: tabular-nums; }

/* The Maps info window inherits the page font but not its colours, and its
   own white background is fixed. Keep its text dark in both themes rather
   than letting --ink turn it white-on-white. */
.gm-style .infowindow { color: #0b0b0b; font-family: var(--font); font-size: 13px; }
.gm-style .infowindow strong { display: block; margin-bottom: 2px; }
.gm-style .infowindow .mono { font-family: var(--mono); font-size: 12px; color: #52514e; }

/* ------------------------------------------------------------------ */
/* Errors                                                              */
/* ------------------------------------------------------------------ */

.error-page { display: grid; place-items: center; min-height: 100vh; text-align: center; padding: 24px; }
.error-code { font-size: 56px; font-weight: 650; letter-spacing: -.03em; }

@media (max-width: 720px) {
  main { padding: 14px; }
  .topbar { padding: 10px 14px; }
  .card { padding: 14px; }
  .map-wrap { height: min(55vh, 460px); }
}
