:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1f2630;
  --line: #2c353f;
  --text: #e6edf3;
  --muted: #93a1b0;
  --accent: #2f81f7;
  --ok: #2ea043;
  --warn: #d29922;
  --danger: #f85149;
  --radius: 12px;
  --tap: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body { padding-bottom: env(safe-area-inset-bottom); }

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 .75rem; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.row { display: flex; gap: .5rem; align-items: center; }
.row-between { display: flex; gap: .5rem; align-items: center; justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: .75rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- chrome -- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: max(.6rem, env(safe-area-inset-top)) .9rem .6rem;
  background: rgba(13, 17, 23, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar .brand { font-weight: 650; letter-spacing: -.01em; }

.wrap { max-width: 760px; margin: 0 auto; padding: 1rem .9rem 5.5rem; }

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  background: rgba(22, 27, 34, .97);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabbar button {
  flex: 1;
  min-height: var(--tap);
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: .78rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: .4rem 0;
  cursor: pointer;
}
.tabbar button .ico { font-size: 1.25rem; line-height: 1; }
.tabbar button[aria-selected="true"] { color: var(--accent); }
.tabbar .badge {
  position: absolute;
  transform: translate(1.1rem, -1.2rem);
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 700;
  min-width: 1.15rem;
  padding: 0 .3rem;
  line-height: 1.15rem;
  text-align: center;
}

/* ----------------------------------------------------------------- cards -- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}
.card + .card { margin-top: .8rem; }

/* --------------------------------------------------------------- controls -- */

button, .btn {
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  min-height: var(--tap);
  padding: 0 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  text-decoration: none;
}
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ok      { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-danger  { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-ghost   { background: transparent; }
.btn-block   { width: 100%; }
.btn-sm      { min-height: 38px; padding: 0 .7rem; font-size: .85rem; }

.btn-capture {
  width: 100%;
  min-height: 108px;
  font-size: 1.15rem;
  flex-direction: column;
  gap: .3rem;
  background: linear-gradient(180deg, #2f81f7, #1f6feb);
  border-color: #1f6feb;
  color: #fff;
}
.btn-capture .ico { font-size: 2rem; }

label { display: block; font-size: .84rem; color: var(--muted); margin-bottom: .3rem; }

input[type="text"], input[type="password"], input[type="tel"], input[type="search"],
input[type="datetime-local"], textarea, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .7rem .8rem;
  min-height: var(--tap);
}
textarea { min-height: 76px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.field + .field { margin-top: .7rem; }

/* ---------------------------------------------------------------- status -- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  border-radius: 999px;
  padding: .22rem .6rem;
  font-size: .76rem;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface-2);
  white-space: nowrap;
}
.pill-ok     { color: #7ee2a8; border-color: #1d572f; background: #10281a; }
.pill-warn   { color: #e3b341; border-color: #5a4614; background: #2a2110; }
.pill-danger { color: #ff8a80; border-color: #5f2320; background: #2b1413; }
.pill-info   { color: #79c0ff; border-color: #1b4a7a; background: #0f2437; }

.dot { width: .55rem; height: .55rem; border-radius: 50%; background: currentColor; flex: none; }

.banner {
  border-radius: 10px;
  padding: .7rem .85rem;
  font-size: .88rem;
  border: 1px solid;
}
.banner-error { color: #ff8a80; border-color: #5f2320; background: #2b1413; }
.banner-ok    { color: #7ee2a8; border-color: #1d572f; background: #10281a; }
.banner-warn  { color: #e3b341; border-color: #5a4614; background: #2a2110; }
.banner-info  { color: #79c0ff; border-color: #1b4a7a; background: #0f2437; }

.offline-bar {
  background: #5a4614;
  color: #ffdf8a;
  text-align: center;
  font-size: .82rem;
  font-weight: 600;
  padding: .35rem;
}

/* ------------------------------------------------------------------ list -- */

.item {
  display: flex;
  gap: .75rem;
  padding: .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  align-items: flex-start;
}
.item + .item { margin-top: .6rem; }

.thumb {
  width: 66px;
  height: 66px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-2);
  flex: none;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem 1rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty .ico { font-size: 2.2rem; display: block; margin-bottom: .5rem; opacity: .7; }

.meta-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .3rem .8rem;
  font-size: .85rem;
}
.meta-grid dt { color: var(--muted); }
.meta-grid dd { margin: 0; }

/* ------------------------------------------------------------------- map -- */

#map { width: 100%; height: 100%; background: var(--surface-2); }
.map-shell { position: absolute; inset: 0; top: 0; }

.leaflet-popup-content-wrapper { background: var(--surface); color: var(--text); border-radius: 10px; }
.leaflet-popup-tip { background: var(--surface); }
/* Kept deliberately small: this floats over the map, and a card that covers the
   street it is pointing at hides the thing being looked at. Enough to identify
   the point and get to the photo or the case; the detail lives behind those. */
.leaflet-popup-content { margin: .5rem .55rem; font: inherit; font-size: .78rem; line-height: 1.35; }
.leaflet-popup-content .pill { font-size: .68rem; padding: .1rem .4rem; }
.leaflet-popup-content .btn-sm { min-height: 30px; padding: .25rem .5rem; font-size: .72rem; }
.leaflet-popup-content .row { gap: .35rem; }
.leaflet-container { background: #0b1017; font: inherit; }
.leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--line); }
.leaflet-bar a:hover { background: var(--surface-2); color: var(--text); }

/* A thumbnail beside the facts rather than a photograph above them: the same
   information in roughly a third of the height. */
.popup-head { display: flex; gap: .45rem; align-items: flex-start; }
.popup-facts { min-width: 0; flex: 1; }
.popup-what { font-weight: 600; font-size: .78rem; line-height: 1.25; }
.popup-note { margin-top: .35rem; opacity: .9; }
.popup-actions { margin-top: .45rem; }

.popup-img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  flex: 0 0 auto;
  border-radius: 5px;
  display: block;
  cursor: zoom-in;
}

/* Every pin is the same teardrop carrying its category's glyph. The tip is the
   recorded coordinate, which on an evidence map has to stay exact. */
.marker-pin {
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  width: 30px;
  height: 30px;
  transform: rotate(-45deg);
  box-shadow: 0 2px 7px rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
}
.marker-pin svg {
  transform: rotate(45deg);
  width: 19px;
  height: 19px;
  fill: #fff;
}

/* Anything identified by a licence plate — a car parked overnight, a vehicle
   incident. Red and car-shaped so a vehicle can be picked out of a street of
   ordinary patrol points at a glance. It keeps the teardrop of every other
   marker: the tip is the coordinate, and on an evidence map that has to stay
   exact. */
.marker-pin-car {
  background: var(--danger);
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  width: 30px;
  height: 30px;
  transform: rotate(-45deg);
  box-shadow: 0 2px 7px rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
}
.marker-pin-car svg {
  transform: rotate(45deg);
  width: 19px;
  height: 19px;
  fill: #fff;
}

/* Evidence belonging to the case currently being focused. */
.marker-pin-case {
  background: var(--warn);
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  width: 28px;
  height: 28px;
  transform: rotate(-45deg);
  box-shadow: 0 3px 10px rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
}
.marker-pin-case span {
  transform: rotate(45deg);
  color: #1a1300;
  font-size: .72rem;
  font-weight: 800;
}

/* ----------------------------------------------------------------- modal -- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 2500;
  background: rgba(0, 0, 0, .72);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
  padding: 1.2rem;
  padding-top: max(1.2rem, env(safe-area-inset-top));
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  width: 100%;
  max-width: 460px;
  margin: auto;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
}

/* -------------------------------------------------------------- lightbox -- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(0, 0, 0, .93);
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.lightbox img { flex: 1; min-height: 0; object-fit: contain; width: 100%; }
.lightbox .lb-bar { display: flex; justify-content: space-between; align-items: center; padding: .6rem .9rem; gap: .6rem; }
.lightbox .lb-meta { padding: .3rem .9rem 1rem; font-size: .84rem; color: var(--muted); }

/* --------------------------------------------------------------- desktop -- */

@media (min-width: 900px) {
  .wrap { padding-bottom: 2rem; }
  .tabbar {
    position: sticky;
    top: 0;
    bottom: auto;
    border-top: 0;
    border-bottom: 1px solid var(--line);
    max-width: 760px;
    margin: 0 auto;
  }
}

/* ------------------------------------------------------------ dashboard -- */

/* Headline numbers are stat tiles, not one-bar charts: a single current value
   reads faster as a number than as a mark on an axis. */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; }
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .8rem .9rem;
}
.tile-label { font-size: .76rem; color: var(--muted); }
.tile-value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; margin-top: .15rem; }
.tile-note { font-size: .74rem; color: var(--muted); margin-top: .2rem; }
.tile-hero .tile-value { font-size: 2.6rem; }

/* A status tile always carries a word, never colour alone. */
.tile-ok    .tile-value { color: var(--ok); }
.tile-warn  .tile-value { color: var(--warn); }
.tile-alert .tile-value { color: var(--danger); }

/* Comparing people is a magnitude question, so one hue, more-is-longer, and the
   name and the number stay in text ink beside it. A table rather than a chart
   because a village can have any number of guards and every name carries
   meaning. */
.rank { width: 100%; border-collapse: collapse; }
.rank th {
  text-align: left;
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0 .5rem .35rem 0;
  border-bottom: 1px solid var(--line);
}
.rank th.num, .rank td.num { text-align: right; font-variant-numeric: tabular-nums; }
.rank td { padding: .45rem .5rem .45rem 0; border-bottom: 1px solid var(--line); font-size: .84rem; }
.rank tr:last-child td { border-bottom: 0; }
.rank .who { font-weight: 600; }
.rank .sub { display: block; font-size: .72rem; color: var(--muted); font-weight: 400; }
.rank-bar { width: 34%; }
.bar-track { background: var(--surface-2); border-radius: 4px; height: 8px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 4px; }

/* ------------------------------------------------------------- pagination -- */

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  margin-top: .8rem;
  padding-top: .8rem;
  border-top: 1px solid var(--line);
}
.pager .count { font-size: .78rem; color: var(--muted); text-align: center; }
.pager button { min-height: 36px; padding: 0 .8rem; font-size: .85rem; }

/* ------------------------------------------------------- branding icon -- */

/* A wrapping grid rather than fixed columns: the panel is the same component
   on a laptop and on a tablet held sideways, and a fixed count would either
   waste the width or overflow it. */
.icon-presets {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}
.icon-presets button {
  width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 1.35rem;
  line-height: 1;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.icon-presets button:hover { border-color: var(--accent); }
/* aria-pressed carries the selection, so the ring follows the state a screen
   reader announces rather than a second class that could drift out of step. */
.icon-presets button[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(47, 129, 247, .35);
}

.logo-preview {
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }

/* The badge stands in for an emoji in a line of text, so it has to sit on the
   text baseline and match the height around it rather than impose its own. */
.brand-logo { height: 1.4em; width: auto; vertical-align: -.3em; }
#authIcon .brand-logo { height: 2.6rem; vertical-align: middle; }
