:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #101828;
  --muted: #667085;
  --border: #e4e7ec;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff4ff;
  --error: #b42318;
  --error-bg: #fef3f2;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);

  /* Feature colours: used on the map, in the legend and in the table. */
  --area: #3b82f6;
  --length: #f97316;
  --point: #22c55e;
  --other: #9ca3af;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1017;
    --surface: #131a24;
    --text: #e7ecf3;
    --muted: #98a2b3;
    --border: #263041;
    --accent: #6ea8fe;
    --accent-hover: #8ebbff;
    --accent-soft: rgba(110, 168, 254, 0.12);
    --error: #fda29b;
    --error-bg: rgba(180, 35, 24, 0.2);
    --ok: #75e0a7;
    --ok-bg: rgba(6, 118, 71, 0.22);
    --shadow: none;
  }
  /* Darken the map tiles to match the page. */
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9); }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

h1, h2, p { margin: 0; }

/* ---------- Top bar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 1.05rem; font-weight: 650; line-height: 1.2; }
.brand p { font-size: 0.82rem; color: var(--muted); }
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
}
.text-link { color: var(--accent); text-decoration: none; font-weight: 600; font-size: 0.9rem; }
.text-link:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px 40px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

/* ---------- Upload area ---------- */
.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 16px;
  padding: 32px 16px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone input {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}
.dz-icon { color: var(--accent); display: grid; place-items: center; }
.dz-title { font-weight: 600; }
.dz-title u { color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.dz-hint { font-size: 0.85rem; color: var(--muted); }
.dz-busy, .spinner { display: none; }
.dropzone.busy { cursor: progress; border-color: var(--accent); }
.dropzone.busy .dz-idle, .dropzone.busy .dz-icon { display: none; }
.dropzone.busy .dz-busy { display: block; }
.dropzone.busy .spinner {
  display: block;
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .dropzone.busy .spinner { animation-duration: 2.4s; }
}

#message { margin: 0 16px 16px; padding: 10px 14px; border-radius: 8px; font-size: 0.92rem; }
#message:empty { display: none; }
#message.error { background: var(--error-bg); color: var(--error); }
#message.ok { background: var(--ok-bg); color: var(--ok); }

/* ---------- Summary cards ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 1.5rem; font-weight: 650; line-height: 1.3; word-break: break-word; }
.stat-sub { font-size: 0.8rem; color: var(--muted); }

/* ---------- Map + table ---------- */
.split { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 960px) { .split { grid-template-columns: 3fr 2fr; } }

.panel { overflow: hidden; margin-bottom: 0; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { font-size: 0.95rem; font-weight: 650; }

#map { height: 480px; }
.table-wrap { max-height: 480px; overflow: auto; }

.legend { display: flex; gap: 14px; margin: 0; padding: 0; list-style: none; font-size: 0.82rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--other); }
.dot[data-kind="area"] { background: var(--area); }
.dot[data-kind="length"] { background: var(--length); }
.dot[data-kind="point"] { background: var(--point); }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 9px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th {
  position: sticky; top: 0;
  background: var(--surface);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.num { text-align: right; white-space: nowrap; }
tbody tr { cursor: default; }
tbody tr[tabindex] { cursor: pointer; }
tbody tr[tabindex]:hover { background: var(--accent-soft); }
tbody tr.selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
tbody tr:last-child td { border-bottom: 0; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--other); }
.badge[data-kind="area"]::before { background: var(--area); }
.badge[data-kind="length"]::before { background: var(--length); }
.badge[data-kind="point"]::before { background: var(--point); }

.note { display: block; margin-top: 2px; font-size: 0.78rem; color: var(--muted); font-weight: 400; }
.sub { display: block; font-size: 0.78rem; color: var(--muted); }

/* ---------- Buttons ---------- */
.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-color-scheme: dark) { .button { color: #0b1017; } }