:root {
  --bg: #f4f4f1;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #6b7078;
  --border: #d9dad5;
  --accent: #2f6fd6;
  --ok: #2b8a3e;
  --warn: #b7791f;
  --error: #c92a2a;
  --row-hover: #eef3fb;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --panel: #1f2227;
    --text: #e6e7ea;
    --muted: #9aa0a8;
    --border: #33373e;
    --accent: #6ea2ff;
    --ok: #51cf66;
    --warn: #fcc419;
    --error: #ff6b6b;
    --row-hover: #262b33;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

/* display rules below must not override the hidden attribute */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

h1 {
  margin: 0;
  font-size: 16px;
}

h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.spacer {
  flex: 1;
}

.status::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--warn);
}

.status[data-state="ok"]::before {
  background: var(--ok);
}

.status[data-state="error"]::before {
  background: var(--error);
}

button {
  font: inherit;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.small {
  padding: 0 6px;
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
}

main {
  flex: 1;
  display: flex;
  min-height: 0;
}

.map-pane {
  position: relative;
  flex: 1;
  min-width: 0;
  background: #e7e6e1;
}

#map {
  position: absolute;
  inset: 0;
  background: #e7e6e1;
  font: inherit;
}

#map.picking {
  cursor: crosshair;
}

.map-hint {
  position: absolute;
  z-index: 1000;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 4px 10px;
  border-radius: 6px;
  background: rgb(31 35 40 / 0.85);
  color: #fff;
  font-size: 13px;
  pointer-events: none;
}

.map-hint[hidden] {
  display: none;
}

button.move-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.map-marker {
  width: 0;
  height: 0;
}

.map-vehicle {
  position: absolute;
  transform: translate(-50%, -50%);
  box-sizing: border-box;
  min-width: 18px;
  height: 16px;
  padding: 0 4px;
  border: 1.5px solid #fff;
  border-radius: 4px;
  color: #fff;
  font: bold 10px/13px system-ui, sans-serif;
  text-align: center;
  white-space: nowrap;
}

.map-character {
  position: absolute;
  top: -7px;
  left: -7px;
  display: flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}

.map-character-dot {
  width: 10px;
  height: 10px;
  border: 2px solid #fff;
  border-radius: 50%;
}

.map-character-label {
  color: #1f2328;
  font: 12px system-ui, sans-serif;
  text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff;
}

.leaflet-control.map-scale {
  margin-bottom: 26px;
  padding: 2px 4px 3px;
  background: rgb(255 255 255 / 0.8);
  color: #333;
  font-size: 11px;
}

.map-scale-bar {
  height: 4px;
  border: 2px solid #333;
  border-top: none;
}

.map-message {
  position: absolute;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  color: #444;
  text-align: center;
  pointer-events: none;
}

.map-toolbar {
  position: absolute;
  z-index: 1000;
  top: 8px;
  left: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgb(255 255 255 / 0.85);
  color: #1f2328;
}

.map-toolbar button {
  background: #fff;
  color: #1f2328;
  border-color: #c9cac5;
}

.map-cursor {
  position: absolute;
  z-index: 1000;
  bottom: 0;
  left: 0;
  padding: 2px 6px;
  background: rgb(255 255 255 / 0.8);
  color: #333;
  font-size: 11px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.map-cursor:empty {
  display: none;
}

aside {
  width: 400px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 12px 16px;
  background: var(--panel);
  border-left: 1px solid var(--border);
}

aside section {
  margin-bottom: 20px;
}

.count {
  color: var(--text);
}

table.list {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

table.list th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding: 2px 6px 2px 0;
}

table.list td {
  padding: 3px 6px 3px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  overflow-wrap: anywhere;
}

table.list:has(tbody:empty) {
  display: none;
}

table.clickable tbody tr {
  cursor: pointer;
}

table.clickable tbody tr:hover {
  background: var(--row-hover);
}

.empty,
.muted {
  margin: 0;
  color: var(--muted);
}

.tag {
  display: inline-block;
  padding: 0 5px;
  margin-right: 3px;
  border-radius: 4px;
  font-size: 11px;
  background: var(--row-hover);
  border: 1px solid var(--border);
}

.tag.on {
  border-color: var(--accent);
  color: var(--accent);
}

.events-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font: 12px/1.35 ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.events-list li {
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
}

.events-list time {
  color: var(--muted);
  margin-right: 6px;
}

.events-list .type {
  font-weight: 600;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  max-width: min(420px, calc(100vw - 32px));
}

dialog h2 {
  font-size: 15px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
}

dialog input {
  width: 100%;
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.95em;
}

@media (max-width: 800px) {
  main {
    flex-direction: column;
  }

  .map-pane {
    flex: none;
    height: 55vh;
  }

  aside {
    width: auto;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}
