:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2330; --muted: #667085; --line: #d9dee7;
  --accent: #1d6b3f; --danger: #b42318; --ok-bg: #ecfdf3; --ok: #067647; --err-bg: #fef3f2;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
code { background: #eef1f5; padding: 0 .25em; border-radius: 3px; }
.muted { color: var(--muted); }

.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topbar .brand { font-weight: 700; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; gap: .9rem; flex: 1; }
.topbar nav a { color: var(--accent); text-decoration: none; }
.topbar .role { font-size: .75rem; color: var(--muted); border: 1px solid var(--line); border-radius: 9px; padding: 0 .4rem; }

.page { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem; }
.login { min-height: 100vh; display: grid; place-content: center; padding: 1rem; }
.login .card { width: min(360px, 100%); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 1.1rem; margin: 1rem 0; }
label { display: grid; gap: .25rem; margin-bottom: .75rem; font-weight: 500; }
input, select { font: inherit; padding: .45rem .55rem; border: 1px solid var(--line); border-radius: 5px; background: #fff; }
button { font: inherit; padding: .45rem .9rem; border: 0; border-radius: 5px; background: var(--accent); color: #fff; cursor: pointer; }
button.danger { background: var(--danger); }
button.link { background: none; color: var(--accent); padding: 0; }
form.inline { display: inline-flex; gap: .35rem; align-items: center; margin: 0; }
form.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; align-items: end; }
form.grid label { margin: 0; }

.notice { padding: .6rem .8rem; border-radius: 6px; }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.err { background: var(--err-bg); color: var(--danger); }

table { border-collapse: collapse; width: 100%; background: var(--panel); }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.stats { width: auto; }
table.users { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; display: block; overflow-x: auto; }
tr.disabled td { color: var(--muted); }

/* ---- map page ---- */
.small { font-size: .85rem; }
body:has(.mapview) { height: 100vh; display: flex; flex-direction: column; }
.mapview { display: grid; grid-template-columns: 320px 1fr; flex: 1; min-height: 0; }
#sidebar { overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); }
.side-head { position: sticky; top: 0; background: var(--panel); padding: .75rem; border-bottom: 1px solid var(--line); z-index: 1; }
.side-head input[type=search] { width: 100%; }
.count { margin: .5rem 0 .25rem; }
#unplotted { margin: 0 0 .25rem; }
details.filter { border-bottom: 1px solid var(--line); }
details.filter summary { padding: .5rem .75rem; cursor: pointer; font-weight: 600; }
details.filter .active-count { color: var(--accent); font-weight: 500; }
.filter-body { padding: 0 .75rem .6rem; }
.opt { display: flex; align-items: center; gap: .45rem; margin: .1rem 0; font-weight: 400; grid-template-columns: none; }
.opt-name { flex: 1; }
.opt-count { color: var(--muted); font-size: .85rem; }
.opt.zero { color: #b0b6c2; }
.opt-tools { text-align: right; font-size: .85rem; }
.range { display: flex; gap: .4rem; align-items: center; }
.range input { width: 6.5rem; }
#map-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#map-area { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; }
.map-panel { position: absolute; z-index: 500; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .7rem; box-shadow: 0 1px 4px rgba(0,0,0,.12); font-size: .9rem; }
#layer-panel { top: 10px; left: 54px; display: flex; gap: .9rem; align-items: center; flex-wrap: wrap; max-width: calc(100% - 120px); }
#layer-panel label { margin: 0; display: flex; gap: .35rem; align-items: center; font-weight: 500; }
#legend { bottom: 24px; right: 10px; max-height: 45%; overflow-y: auto; }
#legend div { display: flex; align-items: center; gap: .4rem; }
.swatch { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.2); }
#load-error { position: absolute; z-index: 600; top: 60px; left: 54px; }
.dot-pin span { display: block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.logo-pin > div { width: 38px; height: 38px; box-sizing: border-box; background: #fff; border-radius: 50%; border: 3px solid #9ca3af; box-shadow: 0 1px 3px rgba(0,0,0,.35); display: grid; place-items: center; overflow: hidden; }
/* Leaflet sets marker images to width:auto and max-width:none !important; win back the size. */
.leaflet-container .leaflet-marker-pane .logo-pin img { width: 100% !important; height: 100% !important; max-width: none !important; max-height: none !important; object-fit: cover; display: block; }
.logo-pin .initials { font: 700 11px/1 system-ui, sans-serif; color: #374151; }
.popup h3 { margin: .2rem 0; font-size: 1rem; }
.popup p { margin: .25rem 0; }
.popup table { width: auto; background: none; font-size: .85rem; }
.popup th, .popup td { padding: .15rem .4rem .15rem 0; border: 0; vertical-align: top; }
.popup th { color: var(--muted); font-weight: 500; white-space: nowrap; }
.popup-logo { max-width: 120px; max-height: 60px; display: block; margin-bottom: .3rem; }
@media (max-width: 760px) {
  body:has(.mapview) { height: auto; display: block; }
  .mapview { display: flex; flex-direction: column; height: auto; }
  #map-wrap { order: 1; }
  #map-area { height: 60vh; flex: none; }
  #list-panel { height: auto !important; max-height: 60vh; }
  #list-resize { display: none; }
  #sidebar { order: 2; border-right: 0; overflow: visible; }
  .side-head { position: static; }
  #layer-panel { left: 10px; top: auto; bottom: 10px; max-width: calc(100% - 20px); }
  #legend { display: none; }
}

/* ---- organisation page ---- */
.org-head { display: flex; gap: 1rem; align-items: center; }
.org-logo { max-width: 140px; max-height: 80px; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: .3rem; }
.org-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 0 1rem; align-items: start; }
table.kv { width: auto; background: none; }
table.kv th { color: var(--muted); font-weight: 500; white-space: nowrap; vertical-align: top; }
table.timeline { border: 1px solid var(--line); }
.pre { white-space: pre-line; }
.pill { font-size: .8rem; padding: .05rem .5rem; border-radius: 9px; margin-left: .4rem; background: #e0e7ff; color: #3730a3; }
.pill.rel-customer { background: #dcfce7; color: #166534; }

/* ---- summary strip and list ---- */
.summary { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1.4rem; padding: .5rem .9rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.stat { display: flex; flex-direction: column; line-height: 1.15; }
.stat-n { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-l { font-size: .78rem; color: var(--muted); }
.stat-n.up { color: var(--ok); }
.spark { width: 160px; height: 40px; overflow: visible; }
.spark path.line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.spark path.area { fill: var(--accent); opacity: .12; }
.summary-actions { margin-left: auto; display: flex; gap: .5rem; align-items: center; }
.summary-actions form { margin: 0; }
button.secondary { background: #fff; color: var(--accent); border: 1px solid var(--accent); }
button.secondary.active { background: var(--accent); color: #fff; }
#list-panel { flex: none; height: 260px; display: flex; flex-direction: column; background: var(--panel); border-top: 1px solid var(--line); min-height: 0; }
#list-panel[hidden] { display: none; }
#list-resize { flex: none; height: 8px; cursor: ns-resize; background: #eef1f5; border-bottom: 1px solid var(--line); touch-action: none; }
#list-resize::after { content: ""; display: block; width: 40px; height: 3px; margin: 2px auto 0; border-radius: 2px; background: #b0b6c2; }
#list-resize:hover { background: #e2e8f0; }
#list-scroll { flex: 1; overflow: auto; min-height: 0; }
#list-table tbody tr { cursor: pointer; }
#list-table { font-size: .9rem; }
#list-table thead th { position: sticky; top: 0; background: #eef1f5; cursor: pointer; white-space: nowrap; user-select: none; }
#list-table thead th[data-sort]::after { content: " ↕"; color: #b0b6c2; }
#list-table thead th.asc::after { content: " ↑"; color: var(--accent); }
#list-table thead th.desc::after { content: " ↓"; color: var(--accent); }
#list-table td { padding: .35rem .6rem; }
#list-table tbody tr:hover { background: #f1f8f3; }

/* ---- brand ---- */
.topbar .brand { display: inline-flex; align-items: center; gap: .45rem; }
.topbar .brand img { height: 32px; width: auto; }
.topbar { padding-top: .4rem; padding-bottom: .4rem; }
.login-logo { display: block; width: 220px; max-width: 100%; height: auto; margin: 0 auto .75rem; }
