/* GPS fleet panel — instrument-housing palette.
   Direction: the map is the document; every panel is a margin annotation on it.
   Colours are drawn from RF/satellite instrumentation, not from fashion. */

:root {
  --ink:        #10151c;   /* instrument housing */
  --panel:      #171e27;   /* raised face */
  --panel-2:    #1e2733;   /* recessed well */
  --edge:       #2b3644;   /* machined seam */
  --edge-bright:#3b4a5c;
  --mist:       #e8eef4;   /* primary text */
  --mist-dim:   #93a3b5;   /* metadata */
  --mist-faint: #5d6d80;

  --signal:     #3fb6e8;   /* live GPS fix */
  --signal-dim: #1d6b8d;
  --ember:      #e8823f;   /* standby / positioning stopped */
  --moss:       #5fa87a;   /* ack received, healthy */
  --alert:      #e0553f;   /* no fix, CRC failure */
  --violet:     #9b8ce0;   /* XTRA assistance traffic */

  --radius:   3px;
  --radius-lg: 5px;
  --rail:  318px;
  --strip: 148px;

  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  --sans: "Inter", ui-sans-serif, system-ui, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--ink);
  color: var(--mist);
  font-family: var(--sans);
  font-size: 13px;
  overflow: hidden;
}

/* Micro-labels: the panel's typographic signature. Wide-tracked, uppercase,
   deliberately smaller than the values they label so numbers dominate. */
.label {
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mist-faint);
  font-weight: 600;
}

.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- shell */

#shell {
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  grid-template-rows: 46px 1fr;
  height: 100vh;
}

/* ---------------------------------------------------------------- header */

header {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 22px;
  padding: 0 16px;
  background: linear-gradient(180deg, var(--panel) 0%, #131923 100%);
  border-bottom: 1px solid var(--edge);
}

.brand { display: flex; align-items: baseline; gap: 9px; }
.brand h1 {
  margin: 0; font-size: 14px; font-weight: 650; letter-spacing: 0.03em;
}
.brand .ver {
  font-family: var(--mono); font-size: 10px; color: var(--mist-faint);
}

/* A hairline sweep behind the title — the one ornamental gesture, and it
   reads as a radar sweep rather than decoration. */
.brand::before {
  content: ""; width: 13px; height: 13px; border-radius: 50%;
  border: 1.5px solid var(--signal-dim);
  border-top-color: var(--signal);
  align-self: center;
  animation: sweep 2.4s linear infinite;
}
@keyframes sweep { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .brand::before { animation: none; }
}

.hstat { display: flex; flex-direction: column; gap: 1px; line-height: 1.15; }
.hstat .v { font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.hstat .v.ok   { color: var(--moss); }
.hstat .v.bad  { color: var(--alert); }
.hstat .v.warn { color: var(--ember); }
.spacer { flex: 1; }

.pill {
  font-family: var(--mono); font-size: 10px;
  padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--edge-bright); color: var(--mist-dim);
}
.pill.danger { border-color: var(--alert); color: var(--alert); }

/* Signed-in identity + sign out, at the far right of the header. */
.signout { display: flex; align-items: center; gap: 8px; margin: 0; }
.whoami {
  font-family: var(--mono); font-size: 10.5px; color: var(--mist-dim);
  max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.signout button.t { border: 1px solid var(--edge-bright); }
.signout button.t:hover { color: var(--mist); border-color: var(--ember); }

/* ---------------------------------------------------------------- rail */

#rail {
  background: var(--panel);
  border-right: 1px solid var(--edge);
  display: flex; flex-direction: column;
  min-height: 0;
}

.rail-head {
  padding: 10px 13px 8px;
  border-bottom: 1px solid var(--edge);
  display: flex; align-items: center; justify-content: space-between;
}

#devices { overflow-y: auto; flex: 1; min-height: 0; }

.device {
  padding: 10px 13px;
  border-bottom: 1px solid var(--edge);
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-left-color 0.12s;
}
.device:hover { background: var(--panel-2); }
.device.sel { background: var(--panel-2); border-left-color: var(--signal); }
.device.state-tracking  { border-left-color: var(--signal); }
.device.state-standby   { border-left-color: var(--ember); }
.device.state-stale     { border-left-color: var(--mist-faint); }
.device.state-searching { border-left-color: var(--alert); }
.device.sel.state-standby   { border-left-color: var(--ember); }
.device.sel.state-stale     { border-left-color: var(--mist-faint); }
.device.sel.state-searching { border-left-color: var(--alert); }

.device-top {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px; margin-bottom: 5px;
}
.device-id {
  font-family: var(--mono); font-size: 12.5px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip {
  font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 2px 6px; border-radius: var(--radius); font-weight: 700;
  white-space: nowrap;
}
.chip.tracking  { background: rgba(63,182,232,0.16); color: var(--signal); }
.chip.standby   { background: rgba(232,130,63,0.16); color: var(--ember); }
.chip.stale     { background: rgba(147,163,181,0.14); color: var(--mist-dim); }
.chip.searching { background: rgba(224,85,63,0.16);  color: var(--alert); }

.device-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 5px 8px; margin-bottom: 7px;
}
.cell .k { font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase;
           color: var(--mist-faint); display: block; }
.cell .v { font-family: var(--mono); font-size: 11.5px;
           font-variant-numeric: tabular-nums; color: var(--mist); }

/* Battery: a real gauge, not a number. Reads at a glance across a fleet. */
.batt { display: flex; align-items: center; gap: 5px; }
.batt-shell {
  width: 30px; height: 9px; border: 1px solid var(--edge-bright);
  border-radius: 2px; padding: 1px; position: relative;
}
.batt-shell::after {
  content: ""; position: absolute; right: -3px; top: 2.5px;
  width: 2px; height: 3px; background: var(--edge-bright);
}
.batt-fill { height: 100%; background: var(--moss); border-radius: 1px; }
.batt-fill.low  { background: var(--ember); }
.batt-fill.crit { background: var(--alert); }

/* ---------------------------------------- SIGNATURE: duty-cycle ribbon */
/* Observed upload cadence against the configured data_time interval. A missed
   report is a gap you can see, which no numeric readout makes obvious. */

.ribbon-wrap { margin-top: 2px; }
.ribbon-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 3px;
}
.ribbon-head .drift { font-family: var(--mono); font-size: 9.5px; }
.drift.on   { color: var(--moss); }
.drift.late { color: var(--ember); }
.drift.none { color: var(--mist-faint); }

.ribbon {
  display: flex; gap: 1.5px; height: 16px; align-items: flex-end;
}
.ribbon i {
  flex: 1; min-width: 0; display: block; border-radius: 1px;
  background: var(--signal-dim);
}
.ribbon i.on   { background: var(--signal); }
.ribbon i.late { background: var(--ember); }
.ribbon i.gap  { background: var(--edge); }

/* ---------------------------------------------------------------- main */

#main {
  position: relative;
  display: grid;
  grid-template-rows: 1fr var(--strip);
  min-height: 0; min-width: 0;
}

#map { width: 100%; height: 100%; background: #0b0f14; }
.leaflet-container { background: #0b0f14; font-family: var(--sans); }
.leaflet-control-attribution {
  background: rgba(16,21,28,0.82) !important;
  color: var(--mist-faint) !important; font-size: 9px !important;
}
.leaflet-control-attribution a { color: var(--mist-dim) !important; }
.leaflet-bar a {
  background: var(--panel) !important; color: var(--mist) !important;
  border-color: var(--edge) !important;
}
.leaflet-bar a:hover { background: var(--panel-2) !important; }

/* Floating map controls, kept as a quiet strip so they never rival the map */
.map-tools {
  position: absolute; top: 11px; right: 11px; z-index: 500;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end;
}
.tool-row {
  display: flex; gap: 5px;
  background: rgba(23,30,39,0.93);
  border: 1px solid var(--edge); border-radius: var(--radius-lg);
  padding: 5px;
  backdrop-filter: blur(6px);
}

button.t {
  font-family: var(--sans); font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.04em;
  background: transparent; color: var(--mist-dim);
  border: 1px solid transparent; border-radius: var(--radius);
  padding: 4px 9px; cursor: pointer;
  transition: color 0.12s, background 0.12s;
}
button.t:hover { color: var(--mist); background: var(--panel-2); }
button.t.on { color: var(--ink); background: var(--signal); }
button.t:focus-visible { outline: 2px solid var(--signal); outline-offset: 1px; }

/* Fix-quality readout pinned to the map — the map's own caption */
.fix-card {
  position: absolute; left: 11px; top: 11px; z-index: 500;
  background: rgba(23,30,39,0.93);
  border: 1px solid var(--edge); border-left: 3px solid var(--signal);
  border-radius: var(--radius-lg); padding: 9px 12px;
  min-width: 214px;
  backdrop-filter: blur(6px);
}
.fix-card.nofix { border-left-color: var(--alert); }
.fix-card.standby { border-left-color: var(--ember); }
.fix-card h3 {
  margin: 0 0 6px; font-family: var(--mono); font-size: 12px; font-weight: 650;
}
.fix-rows { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; }
.fix-rows .k { font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase;
               color: var(--mist-faint); align-self: center; }
.fix-rows .v { font-family: var(--mono); font-size: 11.5px;
               font-variant-numeric: tabular-nums; text-align: right; }

/* ---------------------------------------------------------------- strip */

#strip {
  border-top: 1px solid var(--edge);
  background: var(--panel);
  /* Controls take the larger share so two columns of rows fit without
     squeezing the wire-byte labels. */
  display: grid; grid-template-columns: 1.1fr 0.9fr;
  min-height: 0;
}

/* Control rows flow into as many columns as fit, so the strip stays shallow
   and the map keeps its height. One column on narrow screens. */
.controls {
  padding: 9px 13px; border-right: 1px solid var(--edge);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  align-content: start;
  gap: 7px 20px;
  overflow-y: auto;
}
.ctl-row { display: flex; align-items: center; gap: 7px; min-width: 0; }
.ctl-row > .label { width: 64px; flex-shrink: 0; }
/* The XTRA row carries two buttons plus a filename, so it takes the full width
   instead of forcing every other row to size for its worst case. */
.ctl-row.wide { grid-column: 1 / -1; }

input[type="number"] {
  width: 58px; background: var(--ink); color: var(--mist);
  border: 1px solid var(--edge-bright); border-radius: var(--radius);
  padding: 3px 6px; font-family: var(--mono); font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
input[type="number"]:focus-visible { outline: 2px solid var(--signal); outline-offset: 0; }

button.act {
  font-family: var(--sans); font-size: 10.5px; font-weight: 650;
  letter-spacing: 0.04em;
  background: var(--panel-2); color: var(--mist);
  border: 1px solid var(--edge-bright); border-radius: var(--radius);
  padding: 4px 11px; cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
button.act:hover:not(:disabled) { background: var(--edge); border-color: var(--signal-dim); }
button.act:disabled { opacity: 0.4; cursor: not-allowed; }
button.act.primary { background: var(--signal); color: var(--ink); border-color: var(--signal); }
button.act.primary:hover:not(:disabled) { background: #55c4f2; }
button.act.warn { border-color: var(--ember); color: var(--ember); }
button.act.warn:hover:not(:disabled) { background: rgba(232,130,63,0.14); }
button.act:focus-visible { outline: 2px solid var(--signal); outline-offset: 1px; }

/* The exact outgoing byte, shown next to the control that sends it.
   Discrepancy D2 means an operator must be able to see the wire value. */
/* The wire byte must never be truncated -- it is how an operator verifies what
   actually went out, which matters because the two vendor documents disagree on
   the sleep_time unit. Let the softer hint text shrink instead. */
.wire {
  font-family: var(--mono); font-size: 10px; color: var(--violet);
  white-space: nowrap; flex-shrink: 0;
}
.hint {
  font-size: 10px; color: var(--mist-faint);
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------------------------------------------------------------- log */

.logpane { display: flex; flex-direction: column; min-height: 0; }
.logpane .rail-head { border-bottom: 1px solid var(--edge); }
#log { flex: 1; overflow-y: auto; padding: 3px 0; min-height: 0; }

.line {
  display: grid; grid-template-columns: 62px 26px 1fr;
  gap: 8px; padding: 1.5px 13px;
  font-family: var(--mono); font-size: 10.5px; line-height: 1.45;
  border-left: 2px solid transparent;
}
.line:hover { background: var(--panel-2); }
.line .t { color: var(--mist-faint); font-variant-numeric: tabular-nums; }
.line .d { font-weight: 700; }
.line.in  .d { color: var(--signal); }
.line.out .d { color: var(--violet); }
.line.system .d { color: var(--mist-faint); }
.line .m { color: var(--mist-dim); overflow-wrap: anywhere; }
.line.warn  { border-left-color: var(--ember); }
.line.warn .m { color: var(--ember); }
.line.error { border-left-color: var(--alert); background: rgba(224,85,63,0.07); }
.line.error .m { color: var(--alert); }
.line .hex { color: var(--mist-faint); opacity: 0.7; }

/* ---------------------------------------------------------------- empty */

.empty {
  padding: 26px 18px; text-align: center; color: var(--mist-faint);
  font-size: 11.5px; line-height: 1.6;
}
.empty code {
  font-family: var(--mono); font-size: 10.5px; color: var(--signal);
  background: var(--ink); padding: 1px 5px; border-radius: 2px;
  display: inline-block; margin-top: 6px;
}

.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  z-index: 2000; padding: 8px 16px; border-radius: var(--radius-lg);
  background: var(--panel); border: 1px solid var(--edge-bright);
  font-size: 11.5px; box-shadow: 0 6px 22px rgba(0,0,0,0.55);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-3px); }
.toast.err { border-color: var(--alert); color: var(--alert); }
.toast.ok  { border-color: var(--moss); color: var(--moss); }

/* Device marker: a heading wedge, because these devices report course. */
.marker-dot {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--signal); border: 2px solid var(--ink);
  box-shadow: 0 0 0 1.5px var(--signal), 0 0 11px rgba(63,182,232,0.75);
}
.marker-dot.standby   { background: var(--ember); box-shadow: 0 0 0 1.5px var(--ember); }
.marker-dot.stale     { background: var(--mist-faint); box-shadow: 0 0 0 1.5px var(--mist-faint); }
.marker-dot.searching { background: var(--alert); box-shadow: 0 0 0 1.5px var(--alert); }
.marker-wrap { position: relative; }
.marker-head {
  position: absolute; left: 50%; top: 50%;
  width: 0; height: 0; margin: -17px 0 0 -4.5px;
  border-left: 4.5px solid transparent; border-right: 4.5px solid transparent;
  border-bottom: 8px solid var(--signal);
  transform-origin: 50% 21px;
}

/* ---------------------------------------------------------------- narrow */

@media (max-width: 1080px) {
  :root { --rail: 268px; --strip: 168px; }
  #strip { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .controls { border-right: none; border-bottom: 1px solid var(--edge); }
}
@media (max-width: 760px) {
  #shell { grid-template-columns: 1fr; grid-template-rows: 46px 190px 1fr; }
  #rail { border-right: none; border-bottom: 1px solid var(--edge); }
  header { gap: 13px; overflow-x: auto; }
}
