:root {
  --bg: #f3f6f9;
  --panel: #ffffff;
  --ink: #1d2a36;
  --muted: #6b7a89;
  --line: #e2e8ef;
  --brand: #2e86ab;
  --brand-ink: #ffffff;
  --accent-bg: #e8f3f8;
  --warn-bg: #fff6e5;
  --warn-ink: #8a5a00;
  --radius: 10px;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); display: flex; flex-direction: column; }

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 18px; background: var(--brand); color: var(--brand-ink);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  background: rgba(255,255,255,.18); font-size: 20px; font-weight: 700;
}
.topbar h1 { margin: 0; font-size: 18px; }
.topbar .sub { margin: 2px 0 0; font-size: 12px; opacity: .85; }
.top-actions { display: flex; gap: 8px; }
.topbar .ghost { border-color: rgba(255,255,255,.5); color: #fff; }
.topbar .ghost:hover { background: rgba(255,255,255,.15); }

.ghost {
  background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px;
}
.ghost:hover { background: var(--accent-bg); }
.ghost.small { padding: 6px 10px; font-size: 13px; white-space: nowrap; }
.ghost.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.layout { flex: 1; display: flex; min-height: 0; position: relative; }

.sidebar {
  width: 360px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--panel); border-inline-end: 1px solid var(--line); min-height: 0;
}
.filters { padding: 14px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.filters label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.filters select, .filters input {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  font-size: 14px; color: var(--ink); font-weight: 400; width: 100%;
}
.row { display: flex; gap: 8px; align-items: end; }
.grow { flex: 1; }

.summary { padding: 8px 14px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); }
.list { overflow-y: auto; flex: 1; }

.group-head {
  position: sticky; top: 0; z-index: 1; padding: 8px 14px; font-size: 12px; font-weight: 700;
  background: var(--accent-bg); color: var(--brand); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
}
.item {
  display: flex; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.item:hover { background: #f7fafc; }
.item.selected { background: var(--accent-bg); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; margin-top: 4px; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.2); }
.item .name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.item .meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.item .badge { margin-inline-start: auto; align-self: center; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--accent-bg); color: var(--brand); white-space: nowrap;
}
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge.muted { background: #eef1f4; color: var(--muted); }

.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

.legend {
  position: absolute; bottom: 18px; inset-inline-start: 12px; z-index: 500; max-width: 340px; max-height: 45%;
  overflow-y: auto; background: rgba(255,255,255,.95); border-radius: var(--radius); padding: 10px 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.15); font-size: 12px;
}
.legend:empty { display: none; }
.legend h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.legend .lg { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.legend .lg .dot { margin-top: 0; }

.details {
  width: 420px; flex-shrink: 0; overflow-y: auto; background: var(--panel);
  border-inline-start: 1px solid var(--line); position: relative; padding: 18px;
}
.details.hidden { display: none; }
.close {
  position: absolute; top: 10px; inset-inline-end: 12px; border: 0; background: none;
  font-size: 24px; line-height: 1; color: var(--muted);
}
.details h2 { margin: 0 28px 2px 0; font-size: 18px; line-height: 1.3; }
[dir="rtl"] .details h2 { margin: 0 0 2px 28px; }
.details .alt-name { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.details h3 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--brand);
  margin: 20px 0 8px; padding-bottom: 4px; border-bottom: 2px solid var(--accent-bg);
}
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.note {
  background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px; padding: 10px 12px;
  font-size: 13px; white-space: pre-line; line-height: 1.5;
}
.links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.links a {
  font-size: 13px; text-decoration: none; color: var(--brand); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px;
}
.links a:hover { background: var(--accent-bg); }

.ref {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: 13px;
}
.ref.hl { border-color: var(--brand); box-shadow: 0 0 0 2px var(--accent-bg); }
.ref .spec { font-weight: 700; }
.ref .arrow { color: var(--muted); }
.ref .target { margin-top: 2px; }
.ref .cond { color: var(--muted); font-size: 12px; margin-top: 4px; }

.svc { border-bottom: 1px solid var(--line); padding: 7px 0; font-size: 13px; }
.svc.hl { background: var(--accent-bg); margin: 0 -8px; padding: 7px 8px; border-radius: 6px; }
.svc .svc-head { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.svc .shifts { color: var(--muted); font-size: 12px; margin-top: 3px; }

.empty { padding: 30px 14px; text-align: center; color: var(--muted); font-size: 14px; }

.loading {
  position: fixed; inset: 0; z-index: 2000; display: flex; gap: 12px; align-items: center; justify-content: center;
  background: rgba(243,246,249,.85); font-size: 15px;
}
.loading.hidden { display: none; }
.loading.error { color: #b00020; flex-direction: column; text-align: center; padding: 20px; }
.spinner {
  width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--brand);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.leaflet-popup-content { font-size: 13px; }
.leaflet-popup-content b { display: block; margin-bottom: 2px; }

@media (max-width: 1100px) {
  .details { position: absolute; inset-block: 0; inset-inline-end: 0; z-index: 1000; box-shadow: -4px 0 16px rgba(0,0,0,.15); }
}
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; max-height: 50%; border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .map-wrap { min-height: 320px; }
  .details { width: 100%; }
  .topbar .sub { display: none; }
}

/* In-map directions */
.link-btn {
  font-size: 13px; color: var(--brand); background: none; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px;
}
.link-btn:hover { background: var(--accent-bg); }
.link-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.route { font-size: 13px; }
.route-msg { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.route-sum { font-size: 15px; }
.route-sum strong { font-size: 20px; color: var(--brand); }
.steps { margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.steps summary { cursor: pointer; font-weight: 600; color: var(--brand); }
.steps ol { margin: 8px 0 2px; padding-inline-start: 20px; }
.steps li { padding: 5px 0; border-bottom: 1px solid var(--line); }
.steps li:last-child { border-bottom: 0; }
.steps li em { display: block; font-style: normal; color: var(--muted); font-size: 12px; }
.map-wrap.picking .leaflet-container { cursor: crosshair; }
