:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #646b75;
  --border: #d9dde3;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --start: #16a34a;
  --end: #dc2626;
  --pending: #8a9099;
  --error: #b42318;
  --route: #2563eb;
  --hover: #eef2ff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --panel: #161a20;
    --card: #1c2129;
    --text: #e6e8eb;
    --muted: #9aa3ae;
    --border: #2d343e;
    --accent: #4f8bff;
    --hover: #222a38;
    --error: #ff8a80;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --panel: #161a20; --card: #1c2129; --text: #e6e8eb; --muted: #9aa3ae;
  --border: #2d343e; --accent: #4f8bff; --hover: #222a38; --error: #ff8a80;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 14px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.hidden { display: none !important; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.error { color: var(--error); }
.spacer { flex: 1; }

.layout { display: grid; grid-template-columns: 420px 1fr; height: 100vh; }
.panel { background: var(--panel); border-right: 1px solid var(--border); overflow-y: auto; padding: 12px; }
#map { height: 100%; min-height: 320px; }
.panel-head { display: flex; align-items: center; gap: 8px; margin: 2px 2px 12px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.card > .row:first-child { margin-top: 0; }
label { display: block; font-size: 12px; color: var(--muted); margin: 8px 0 4px; }
textarea, select, input[type=text], input[type=password] {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; padding: 7px 8px;
}
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

button, .button {
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.ghost { background: transparent; }
button.small { padding: 2px 8px; font-size: 12px; }
button.wide { width: 100%; margin-top: 12px; padding: 9px; font-weight: 600; }

.pill { font-size: 11px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); }
.pill.ok { color: var(--start); border-color: var(--start); }
.pill.bad { color: var(--error); border-color: var(--error); }

.progress { margin-top: 10px; }
.bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; border: 1px solid var(--border); }
#progressBar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

#retryAllBtn { margin-top: 8px; }
.failed { list-style: none; padding: 0; margin: 8px 0 0; }
.failed li { display: flex; gap: 6px; margin-bottom: 6px; }
.failed input { flex: 1; min-width: 0; }

.summary { font-size: 15px; font-weight: 600; margin: 4px 0 8px; }
.chunks { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chunks a { font-size: 12px; }

.route { list-style: none; padding: 0; margin: 0; }
.route li { display: grid; grid-template-columns: 30px 1fr; gap: 8px; padding: 8px 4px; border-top: 1px solid var(--border); cursor: pointer; }
.route li:hover { background: var(--hover); }
.route .num { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; font-size: 12px;
  display: flex; align-items: center; justify-content: center; }
.route .num.start { background: var(--start); }
.route .num.end { background: var(--end); }
.route .label { font-weight: 600; overflow-wrap: anywhere; }
.tag { font-size: 10px; font-weight: 600; color: var(--error); border: 1px solid var(--error); border-radius: 4px; padding: 0 4px; margin-left: 4px; }
.route .addr { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.route .leg { font-size: 12px; margin-top: 2px; }
a { color: var(--accent); }

.marker { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center;
  font: 700 11px/1 system-ui, sans-serif; }
.marker.pending { background: var(--pending); width: 14px; height: 14px; }
.marker.start { background: var(--start); }
.marker.end { background: var(--end); }
.marker.wide { width: 32px; border-radius: 13px; }
/* Category-coloured markers keep start/finish visible as a ring. */
.marker.cat.start, .route .num.cat.start { box-shadow: 0 0 0 3px var(--start), 0 1px 4px rgba(0,0,0,.45); }
.marker.cat.end, .route .num.cat.end { box-shadow: 0 0 0 3px var(--end), 0 1px 4px rgba(0,0,0,.45); }
.marker.cat.pending { width: 16px; height: 16px; }

.legend { background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; line-height: 1.5; max-height: 40vh; max-width: 220px; overflow-y: auto;
  box-shadow: 0 1px 6px rgba(0,0,0,.25); }
.legend ul { list-style: none; margin: 4px 0 0; padding: 0; }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend .count { margin-left: auto; padding-left: 8px; color: var(--muted); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; margin-right: 4px; vertical-align: -1px; border: 1px solid rgba(0,0,0,.2); }
.route .cat-name { font-size: 12px; color: var(--muted); }

.login { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 2000; padding: 16px; }
.login-card { width: 100%; max-width: 320px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.login-card button { width: 100%; margin-top: 12px; }
.login-card button.ghost { margin-top: 6px; }
.support { display: inline-block; margin: -4px 2px 10px; font-size: 13px; font-weight: 600; text-decoration: none; }
.support:hover { text-decoration: underline; }
.privacy { margin: 4px 4px 16px; line-height: 1.4; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 45vh auto; height: auto; }
  #map { grid-row: 1; height: 45vh; position: sticky; top: 0; z-index: 1; }
  .panel { grid-row: 2; border-right: 0; padding: 12px 16px; }
}
