:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #0369a1;
  --accent-soft: #e0f2fe;
  --accent-strong: #0c4a6e;
  --warn: #b45309;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --nav-h: 64px;
  --footer-h: 36px;
  --font: "Source Sans 3", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-display: "IBM Plex Sans", "Source Sans 3", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body.viewer-page {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

#viewer-app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.viewer-nav {
  height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}
.brand-mark {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid #bae6fd;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
}
.brand strong {
  display: block;
  font-family: var(--font-display);
  font-size: 0.98rem;
  line-height: 1.2;
}
.brand .sub {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.viewer-links {
  display: flex;
  gap: 0.35rem;
  margin-left: 0.5rem;
}
.viewer-links a {
  text-decoration: none;
  color: var(--muted);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
}
.viewer-links a.is-active,
.viewer-links a:hover {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.viewer-meta {
  margin-left: auto;
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: #ecfeff;
  color: #155e75;
  border: 1px solid #a5f3fc;
}
.muted-pill {
  background: #f8fafc;
  color: var(--muted);
  border-color: var(--line);
}

.viewer-body {
  flex: 1;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 320px;
  min-height: calc(100vh - var(--nav-h) - var(--footer-h));
}

.viewer-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 1rem;
  overflow: auto;
}
.right-pane {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.viewer-stage {
  position: relative;
  overflow: hidden;
  min-height: 420px;
  height: 100%;
  background:
    radial-gradient(circle at 20% 0%, #eff6ff 0%, transparent 40%),
    linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
  cursor: grab;
  touch-action: none;
}
.viewer-stage.is-panning { cursor: grabbing; }

.map-svg {
  width: 100%;
  height: 100%;
  min-height: 420px;
  display: block;
  background: transparent;
}

.map-entity.is-selected {
  outline: none;
  filter: drop-shadow(0 0 6px rgba(3, 105, 161, 0.85));
}
.map-entity {
  cursor: pointer;
}

.zoom-controls {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  z-index: 5;
}
.zoom-controls button,
.btn,
.tour-controls button,
.tour-stop-list button {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.zoom-controls button {
  width: 2.4rem;
  height: 2.4rem;
  font-size: 1.1rem;
  font-weight: 700;
}
.btn-primary,
.tour-controls button[data-tour="play"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn:hover,
.zoom-controls button:hover,
.tour-controls button:hover {
  border-color: #94a3b8;
}

.search-box { position: relative; margin-bottom: 1rem; }
.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  background: #fff;
}
.search-box input:focus {
  outline: 2px solid #7dd3fc;
  border-color: var(--accent);
}
.search-results {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  max-height: 240px;
  overflow: auto;
  box-shadow: var(--shadow);
}
.search-hit {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
}
.search-hit:hover { background: var(--accent-soft); }
.search-hit span { color: var(--muted); font-size: 0.78rem; }
.search-empty { padding: 0.75rem; color: var(--muted); }

.panel-title {
  margin: 0 0 0.6rem;
  font-family: var(--font-display);
  font-size: 0.95rem;
}
.layer-list,
.tour-stop-list {
  list-style: none;
  margin: 0 0 1.25rem;
  padding: 0;
}
.layer-item {
  padding: 0.35rem 0;
  border-bottom: 1px solid #f1f5f9;
}
.layer-item label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.field {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.field select {
  font: inherit;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--ink);
}
.route-result { font-size: 0.85rem; color: var(--accent-strong); }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

.details-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.details-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
}
.details-header button {
  border: 0;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}
.details-dl {
  margin: 0;
  display: grid;
  gap: 0.65rem;
}
.details-dl div {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 0.5rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid #f1f5f9;
}
.details-dl dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}
.details-dl dd {
  margin: 0;
  font-size: 0.9rem;
}

.tour-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}
.tour-status {
  flex: 1 1 100%;
  font-size: 0.82rem;
  color: var(--accent-strong);
  font-weight: 600;
}
.tour-stop-list li {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem;
  margin-bottom: 0.5rem;
  background: #fff;
}
.tour-stop-list li.is-active {
  border-color: #7dd3fc;
  background: var(--accent-soft);
}
.tour-stop-list p {
  margin: 0.35rem 0;
  color: var(--muted);
  font-size: 0.8rem;
}
.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--warn);
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 999px;
  padding: 0.15rem 0.45rem;
}
.is-collapsed { display: none; }

.map-entity { cursor: pointer; }
.map-entity.is-selected {
  filter: drop-shadow(0 0 12px rgba(3, 105, 161, 0.55));
}
.map-entity.is-proposed {
  stroke-opacity: 0.95;
}
.focus-pulse {
  animation: pulse 1.4s ease-out 1;
}
@keyframes pulse {
  from { opacity: 1; r: 500; }
  to { opacity: 0; }
}

.viewer-footer {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

@media (max-width: 960px) {
  .viewer-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(55vh, 1fr) auto;
  }
  .left-pane,
  .right-pane {
    border: 0;
    border-top: 1px solid var(--line);
    max-height: 38vh;
  }
  .right-pane {
    position: sticky;
    bottom: 0;
    z-index: 10;
    max-height: 42vh;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 30px rgba(15, 23, 42, 0.08);
    transform: translateY(70%);
    transition: transform 0.25s ease;
  }
  .right-pane.is-open {
    transform: translateY(0);
  }
  .viewer-nav {
    height: auto;
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
    gap: 0.75rem;
  }
  .viewer-meta { width: 100%; margin-left: 0; }
}

/* Print / handout from interactive viewer */
@media print {
  .viewer-nav,
  .viewer-sidebar,
  .zoom-controls,
  .viewer-footer,
  .right-pane {
    display: none !important;
  }
  body.viewer-page,
  #viewer-app,
  .viewer-body,
  .viewer-stage {
    background: #fff !important;
    height: auto !important;
    min-height: 0 !important;
    display: block !important;
  }
  .viewer-stage {
    width: 100% !important;
  }
  .label-hidden {
    display: none !important;
  }
}

