:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #16a34a;
  --danger: #dc2626;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.topbar {
  position: relative;
  z-index: 1001; /* above Leaflet controls */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 16px;
  background: var(--panel);
  box-shadow: 0 1px 3px rgb(15 23 42 / 0.06);
}
.topbar::after { /* thin green-yellow stripe, like a crossing guard's vest */
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent) 0 70%, #facc15 70% 100%);
}
.topbar a { text-decoration: none; color: inherit; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { width: 40px; height: 40px; flex-shrink: 0; display: block; }
.brand-text { display: flex; align-items: baseline; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-name { font-size: 17px; font-weight: 800; letter-spacing: -0.01em; }
.brand-sep { font-size: 17px; color: var(--muted); }
.brand-town { font-size: 17px; font-weight: 700; color: var(--accent); }
.topnav { flex-shrink: 0; display: flex; gap: 4px; padding: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; }
.topnav a {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
  color: var(--muted);
}
.topnav a:hover { color: var(--text); background: #fff; }
.topnav a.active { background: var(--accent); color: #fff; }
@media (max-width: 560px) {
  .brand-logo { width: 34px; height: 34px; }
  .brand-name, .brand-sep, .brand-town { font-size: 15px; }
  .brand-text { gap: 5px; }
  .topnav a { padding: 6px 10px; }
  .topnav-label { display: none; }
}

.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 340px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 12px 16px;
  background: var(--panel);
  border-right: 1px solid var(--border);
}
.map { flex: 1; min-height: 300px; }

h2 { margin: 4px 0 12px; font-size: 18px; }
h3 { margin: 14px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.palette-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  font: inherit;
}
.palette-btn:hover { border-color: var(--muted); }
.palette-btn.active { border-color: var(--accent); background: #dcfce7; }
.swatch {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px;
  border-radius: 4px;
  border-left: 5px solid var(--c);
  font-size: 14px;
}

.network-status { margin: 16px 0 8px; padding: 8px; border-radius: 6px; background: #f1f5f9; }
.network-status.ok { background: #dcfce7; }
.network-status.bad { background: #fee2e2; }
.bad { color: var(--danger); }

.help ul { padding-left: 18px; margin: 6px 0; color: var(--muted); }
.help summary { cursor: pointer; color: var(--muted); }

.panel { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; }
.panel[hidden] { display: none; }
.panel label { display: flex; flex-direction: column; gap: 3px; font-weight: 600; }
.panel input, .panel select, .panel textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-weight: 400; }
.closure-fields { display: flex; flex-direction: column; gap: 8px; }
.closure-fields[hidden] { display: none; }
.date-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.panel label.check { flex-direction: row; align-items: center; gap: 6px; }
.step-closure b { color: var(--danger); }
.panel .actions { display: flex; gap: 6px; flex-wrap: wrap; }
button { font: inherit; padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: var(--danger); }

.hint { color: var(--muted); margin: 0; font-size: 13px; }

.pick-start { align-self: flex-start; font-size: 13px; }
.pick-start.active { border-color: var(--accent); background: #dcfce7; }
.pick-start[hidden] { display: none; }
.map-start { display: flex; align-items: center; gap: 6px; padding: 6px 8px; background: #f1f5f9; border-radius: 6px; font-size: 13px; }
.map-start[hidden] { display: none; }
.map-start small { color: var(--muted); }
.map-start button { margin-left: auto; padding: 0 8px; border: 0; background: transparent; color: var(--muted); font-size: 15px; }
.sw-picking, .sw-picking .leaflet-interactive { cursor: crosshair !important; }
.error { color: var(--danger); }
.warn { background: #fef3c7; padding: 8px; border-radius: 6px; }

.summary { margin: 16px 0 8px; padding: 10px; background: #f0fdf4; border-radius: 8px; }
.steps { list-style: none; padding: 0; margin: 8px 0; }
.step { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.step-at { color: var(--muted); white-space: nowrap; }
.step-icon {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border: 2px solid #94a3b8;
  border-radius: 50%;
  background: #fff;
  font-size: 16px;
}
.hazard { cursor: pointer; border-radius: 6px; }
.hazard:hover, .hazard:focus { background: #f8fafc; outline: none; }
.route-step { cursor: default; border-radius: 6px; }
.route-step:hover, .route-step:focus { background: #eff6ff; outline: none; }
.hazard .badge { font-size: 11px; vertical-align: 1px; white-space: nowrap; }
.step-danger b { color: var(--danger); }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 12px; }
.legend i { display: inline-block; width: 22px; height: 4px; margin-right: 5px; vertical-align: middle; }
.legend i.dashed { background: repeating-linear-gradient(90deg, #6b7280 0 6px, transparent 6px 10px); }

.sw-drawing .sw-icon, .sw-drawing .sw-icon span { pointer-events: none; }

.sw-icon span {
  position: absolute;
  left: 0; top: 0;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center;
  width: var(--sw-size, 32px); height: var(--sw-size, 32px);
  border-radius: 50%;
  background: #fff;
  border: 2px solid #333;
  font-size: calc(var(--sw-size, 32px) * 0.55);
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}

/* Planner: features that aren't part of the shown route. */
.sw-faded span { filter: grayscale(1); opacity: 0.7; }
.sw-faded { z-index: 0 !important; }

/* Planner: the route step under the mouse, marked on the map. */
.sw-pulse { pointer-events: none; }
.sw-pulse span {
  position: absolute; left: 0; top: 0;
  width: calc(var(--sw-size, 32px) * 1.7); height: calc(var(--sw-size, 32px) * 1.7);
  transform: translate(-50%, -50%);
  border: 4px solid #2563eb; border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255,255,255,.8);
  animation: sw-pulse 1.2s ease-in-out infinite;
}
@keyframes sw-pulse { 50% { transform: translate(-50%, -50%) scale(1.25); opacity: .6; } }
.sw-marked { z-index: 1000 !important; }
.sw-marked span { transform: translate(-50%, -50%) scale(1.3); transition: transform .15s; }

.sw-dim { background: #fff; }
.sw-dim .leaflet-tile-pane { filter: grayscale(1) opacity(0.45); }
.sw-dim-control {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 9px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.sw-icon-small span {
  width: calc(var(--sw-size, 32px) * 0.75); height: calc(var(--sw-size, 32px) * 0.75);
  font-size: calc(var(--sw-size, 32px) * 0.42);
}

/* Tooltip cards */
.leaflet-tooltip.sw-tip {
  padding: 10px 12px;
  width: max-content; /* tooltips are absolutely positioned and would otherwise shrink to the narrowest width */
  min-width: 180px;
  max-width: 300px;
  white-space: normal;
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #fff;
  border: 0;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .18), 0 1px 3px rgba(15, 23, 42, .12);
}
.sw-tip.leaflet-tooltip-top::before { border-top-color: #fff; }
.sw-tip.leaflet-tooltip-bottom::before { border-bottom-color: #fff; }
.sw-tip.leaflet-tooltip-left::before { border-left-color: #fff; }
.sw-tip.leaflet-tooltip-right::before { border-right-color: #fff; }
/* keep marker cards clear of the (zoom-dependent) icon */
.sw-tip-marker.leaflet-tooltip-top { margin-top: calc(var(--sw-size, 32px) / -2 - 8px); }

.tip-head { display: flex; align-items: center; gap: 10px; }
.tip-icon {
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c) 14%, #fff);
  font-size: 18px;
}
.tip-swatch { flex-shrink: 0; width: 6px; height: 30px; border-radius: 3px; background: var(--c); }
.tip-title { font-size: 15px; font-weight: 650; }
.tip-cat { font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--c); }
.tip-desc { margin-top: 8px; color: #334155; }
.tip-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.tip-foot { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.badge { padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-gray { background: #f1f5f9; color: #475569; }

@media (max-width: 760px) {
  .layout { flex-direction: column-reverse; }
  .sidebar { width: 100%; max-height: 50vh; border-right: 0; border-top: 1px solid var(--border); }
}

/* ---------- Printing a route (also "save as PDF") ----------
   body.printing is set by planner.js before the print dialog opens, so the
   map already has its print size; @media print covers a plain Ctrl+P. */
.print-route { margin-top: 14px; width: 100%; }

.printing .topnav, .printing #route-form, .printing .legal-links, .printing .print-route,
.printing .leaflet-control-zoom, .printing .sw-dim-control { display: none !important; }
html:has(body.printing), body.printing { height: auto; }
body.printing { display: block; }
.printing .layout { display: block; max-width: 680px; margin: 0 auto; }
.printing .sidebar { width: auto; border: 0; overflow: visible; padding: 12px 0; }
.printing .map { width: 680px; height: 520px; flex: none; border: 1px solid var(--border); }
.printing .step, .printing .map { break-inside: avoid; }

@media print {
  .topnav, #route-form, .legal-links, .print-route, .leaflet-control-zoom, .sw-dim-control { display: none !important; }
  html, body { height: auto; }
  body { display: block; background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .topbar { box-shadow: none; padding-left: 0; }
  .layout { display: block; max-width: 680px; }
  .sidebar { width: auto; border: 0; overflow: visible; padding: 12px 0; }
  .map { width: 680px; height: 520px; flex: none; border: 1px solid var(--border); }
  .step, .map { break-inside: avoid; }
  @page { margin: 14mm; }
}
