[hidden] { display: none !important; }
:root {
  --bg: #f6f6f3;
  --panel: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6a65;
  --line: #e2e0d9;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --route: #1f6feb;
  --corridor: #12a088;
  --show: #e39b17;
  --maneuver: #d4512e;
  --warn: #9a5b00;
  --radius: 8px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1a; --panel: #242422; --ink: #ecebe6; --muted: #a3a29b; --line: #3a3936; --warn: #f0a43a;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); }
body { display: grid; grid-template-columns: 360px 1fr; }

#sidebar { display: flex; flex-direction: column; min-height: 0; height: 100vh; background: var(--panel); border-right: 1px solid var(--line); }
.bar { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
footer.bar { border-top: 1px solid var(--line); border-bottom: 0; margin-top: auto; }
.app-version {
  flex: none; margin: 0; padding: 0 16px 10px; font-size: 11px; line-height: 1.4; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-version a { color: inherit; text-decoration: none; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.app-version a:hover, .app-version a:focus-visible { text-decoration: underline; }
h1 { font-size: 16px; margin: 0; flex: 1; font-weight: 600; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.block { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.grow-block { flex: 1; overflow-y: auto; min-height: 120px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; margin-top: 8px; }
.grow { flex: 1; }
.spacer { flex: 1; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
label.check { display: flex; align-items: center; gap: 6px; color: var(--ink); font-size: 13px; margin: 0; white-space: nowrap; }
input, select, textarea {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 100%; margin-top: 3px;
}
input[type=checkbox] { width: auto; margin: 0; }
input[type=range] { padding: 0; }
textarea { resize: vertical; }
#routeSelect { flex: 1; margin: 0; }

/* ---- route colour: only for the route's name in the app */
.swatch {
  display: inline-block; flex: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--swatch, transparent); box-shadow: inset 0 0 0 1px rgba(0,0,0,.18);
}
/* No colour: an empty ring with a slash. */
.swatch.none, .palette button.none {
  background: linear-gradient(135deg, transparent 45%, var(--muted) 45% 55%, transparent 55%);
  box-shadow: inset 0 0 0 1.5px var(--muted);
}
.name-row { align-items: flex-end; }
.name-row label { margin-bottom: 8px; }
.color-label { flex: none; }
.color-btn { display: flex; align-items: center; gap: 6px; margin-top: 3px; padding: 5px 8px; background: var(--bg); }
.color-btn[aria-expanded="true"] { border-color: var(--accent); }
.color-hex { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); }
.color-panel { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 8px; background: var(--bg); }
.color-panel .help { margin: 0 0 8px; }
.palette { display: grid; grid-template-columns: repeat(11, minmax(0, 28px)); justify-content: space-between; gap: 5px; }
.palette button {
  aspect-ratio: 1; width: 100%; padding: 0; border-radius: 50%; border: 2px solid transparent;
  background: var(--swatch); box-shadow: inset 0 0 0 1px rgba(0,0,0,.18);
}
.palette button[aria-checked="true"] { border-color: var(--panel); outline: 2px solid var(--ink); }
.palette button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.custom-color { margin-top: 10px; align-items: flex-end; }
.custom-color label { margin: 0; }
.custom-color input[type=color] { width: 40px; height: 32px; padding: 2px; flex: none; cursor: pointer; }
.color-panel .form-err { margin: 6px 0 0; }
.color-warn { font-size: 12px; line-height: 1.45; color: var(--warn); margin: 0 0 8px; }

button {
  font: inherit; font-size: 14px; border-radius: 6px; padding: 7px 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
button:hover { border-color: var(--muted); }
button.small { font-size: 13px; padding: 5px 10px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button:disabled { opacity: .45; cursor: default; }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.modes .mode { border: 0; border-radius: 0; background: transparent; padding: 8px 4px; font-size: 13px; }
.modes .mode + .mode { border-left: 1px solid var(--line); }
.modes .mode.on { background: var(--accent); color: var(--accent-ink); }
.help { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.45; }
.stats { font-size: 12px; color: var(--muted); margin-top: 8px; }
.status { flex: 1; font-size: 12px; color: var(--muted); }
.status.err { color: var(--danger); }

#maneuverList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.mv { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; background: var(--bg); }
.mv.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.mv-head { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.mv-icon { width: 36px; height: 36px; flex: none; border-radius: 6px; background: #1d1d1b; color: #fff; display: grid; place-items: center; --icon-bg: #1d1d1b; }
.mv-title { flex: 1; min-width: 0; font-size: 13px; }
.mv-title b { display: block; font-weight: 600; }
.mv-title span { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.mv-body { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; margin-top: 8px; }
.mv-body .full { grid-column: 1 / -1; }
.mv-body label { margin-bottom: 6px; }
.mv-actions { grid-column: 1 / -1; display: flex; gap: 6px; justify-content: flex-end; }
.empty { font-size: 13px; color: var(--muted); }

#mapWrap { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }
#map.cursor-add { cursor: crosshair; }
/* Over the route line in Draw mode: drag it to insert a point. */
#map.on-line, #map.on-line .leaflet-interactive { cursor: move; }
#map.inserting, #map.inserting .leaflet-interactive { cursor: grabbing; }

.wp { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--route); box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.wp.first { border-color: #1a9c4a; }
.wp.last { border-color: #111; }
.route-arrows { pointer-events: none; }
.wp.ghost { width: 12px; height: 12px; border-width: 2px; opacity: .85; box-shadow: none; }
.show-pt { width: 16px; height: 16px; border-radius: 50%; background: var(--show); border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.mv-pin { width: 34px; height: 34px; border-radius: 8px; background: #1d1d1b; color: #fff; display: grid; place-items: center; border: 2px solid var(--maneuver); box-shadow: 0 1px 4px rgba(0,0,0,.5); --icon-bg: #1d1d1b; }
.mv-pin.sel { border-color: var(--accent); border-width: 3px; }
/* Start and Finish: the same tile, with a border that tells them apart from maneuvers. */
.mv-pin.end-pin.start { border-color: #1a9c4a; }
.mv-pin.end-pin.finish { border-color: #fff; outline: 2px solid #1d1d1b; }
.mv-pin.end-pin.sel { border-color: var(--accent); }
.mv.end { border-style: dashed; }
.mv.end.sel { border-style: solid; }
.dir-arrow { color: var(--corridor); filter: drop-shadow(0 0 1px #fff); }
.car { color: var(--accent); filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }

.banner {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 1000;
  background: #14301f; color: #fff; border-radius: 14px; padding: 14px 20px; min-width: 300px;
  box-shadow: 0 6px 20px rgba(0,0,0,.35); --icon-bg: #14301f;
}
/* Every state sets its own text colour, so no general rule can recolour it. */
.banner.banner-idle { background: #2b2b29; color: #fff; --icon-bg: #2b2b29; }
.banner.banner-off { background: #8a1f17; color: #fff; --icon-bg: #8a1f17; }
.banner.banner-start { background: #173a5e; color: #fff; --icon-bg: #173a5e; }
.b-title { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 700; margin-bottom: 10px; }
.b-progress { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.b-track { flex: 1; height: 4px; border-radius: 2px; background: rgba(255,255,255,.25); overflow: hidden; }
.b-fill { height: 100%; background: #fff; border-radius: 2px; }
.banner-main { display: flex; align-items: center; gap: 16px; }
.b-icon { color: #fff; }
.b-dist { font-size: 34px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.b-label { font-size: 16px; opacity: .85; margin-top: 4px; }
.b-then { display: flex; align-items: center; gap: 8px; margin-top: 10px; padding-top: 8px; border-top: 1px solid rgba(255,255,255,.2); font-size: 14px; }

.simbar {
  position: absolute; left: 16px; right: 16px; bottom: 24px; z-index: 1000;
  display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 14px; box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
.simbar input[type=range] { flex: 1; margin: 0; }
.simbar select { width: auto; margin: 0; }
.sim-info { font-size: 12px; color: var(--muted); min-width: 130px; text-align: right; font-variant-numeric: tabular-nums; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); width: 340px; }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { text-transform: none; letter-spacing: 0; font-size: 16px; color: var(--ink); }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 16px 0 0; }

@media (max-width: 800px) {
  body { grid-template-columns: 1fr; grid-template-rows: 55vh auto; }
  #sidebar { height: auto; order: 2; border-right: 0; }
  #mapWrap { order: 1; height: 55vh; }
}

/* ------------------------------------------------------------ accounts */
.user-menu { position: relative; }
#userBtn { display: flex; align-items: center; gap: 6px; max-width: 200px; }
#userBtn .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-badge { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 2000; min-width: 180px; padding: 4px;
  display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
.menu button { border: 0; background: transparent; text-align: left; padding: 7px 10px; font-size: 13px; }
.menu button:hover, .menu button:focus-visible { background: var(--bg); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }
/* On the map, at the clicked spot (positioned inline). */
.map-menu { right: auto; top: 0; z-index: 1100; min-width: 160px; }
.map-menu-title { font-size: 12px; color: var(--muted); padding: 5px 10px 3px; }

dialog.auth { width: 360px; }
.auth-brand { margin: 0 0 16px; font-size: 18px; font-weight: 700; }
/* Outside the sign-in box, at the bottom left of the screen, over the dark backdrop. */
dialog.auth .app-version { position: fixed; left: 16px; bottom: 12px; padding: 0; max-width: calc(100vw - 32px); color: rgba(255,255,255,.7); }
/* The sidebar's copy would show through the backdrop in the same spot. */
body:has(dialog.auth[open]) #sidebar .app-version { visibility: hidden; }
dialog.auth::backdrop { background: rgba(20,20,18,.72); backdrop-filter: blur(3px); }
dialog.wide { width: min(980px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
.dlg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.dlg-head h2 { flex: 1; margin: 0; }
.form-err { color: var(--danger); font-size: 13px; margin: 4px 0 8px; line-height: 1.4; }
.form-err:empty { display: none; }
dialog .help { margin: 0 0 12px; }

.add-user, .filters { display: grid; gap: 8px; align-items: end; margin-bottom: 8px; }
.add-user { grid-template-columns: 1.2fr 1fr 1fr .8fr auto; }
.filters { grid-template-columns: 1fr 1fr 1fr 1fr auto auto; }
.add-user label, .filters label { margin: 0; }
.add-user button, .filters button { margin-bottom: 1px; }

.table-wrap { overflow: auto; max-height: 58vh; border: 1px solid var(--line); border-radius: var(--radius); }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  position: sticky; top: 0; z-index: 1; background: var(--panel); text-align: left; font-weight: 600;
  color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.grid td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid select { width: auto; margin: 0; padding: 3px 6px; font-size: 13px; }
table.grid .empty { text-align: center; padding: 16px; }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
table.grid .user-disabled { color: var(--danger); }
.details { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-word; }
.pager { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.pager span { flex: 1; font-size: 12px; color: var(--muted); }

@media (max-width: 800px) {
  .add-user, .filters { grid-template-columns: 1fr 1fr; }
}
