:root {
  --bg: #0f1216;
  --panel: rgba(20, 24, 30, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf1;
  --muted: #9aa3ad;
  --accent: #5fb878;
  --accent-strong: #3ea05a;
  --warn: #d97757;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

#header {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  align-items: stretch;
  gap: 16px;
  flex-wrap: wrap;
  pointer-events: none;
}

.title {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 14px 18px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  backdrop-filter: blur(8px);
  max-width: 540px;
  flex: 1 1 380px;
}

.title h1 {
  margin: 0 0 4px 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.title .sub {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  backdrop-filter: blur(8px);
  flex: 1 1 320px;
  min-width: 280px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 4px 8px;
}

.stat .num {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.stat .lbl {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.status.error {
  color: var(--warn);
  border-color: rgba(217, 119, 87, 0.4);
}

.about {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 1000;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--muted);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.about summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 500;
  padding: 4px 0;
  list-style: none;
}
.about summary::-webkit-details-marker { display: none; }
.about summary::before {
  content: "ⓘ ";
  color: var(--accent);
  margin-right: 4px;
}

.about-body { padding: 6px 0 10px 0; line-height: 1.5; }
.about-body ul { padding-left: 18px; margin: 6px 0 10px 0; }
.about-body a { color: var(--accent); text-decoration: none; border-bottom: 1px dotted var(--accent-strong); }
.about-body a:hover { color: #8edc9f; }

/* Detail blocks (used in both popups and sidebar) */
.detail-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; color: #1a1f24; }
.detail-addr { font-size: 12.5px; color: #4a5260; margin-bottom: 8px; }
.detail-meta { font-size: 11px; color: #7a8290; margin-top: 8px; }
.detail-aka { font-size: 11.5px; color: #5a6270; margin-top: 4px; font-style: italic; }
.detail-aka strong { font-style: normal; color: #4a5260; }

.detail-photo {
  display: block;
  margin: 6px 0 8px 0;
  border-radius: 8px;
  overflow: hidden;
  background: #1a1f24;
  text-decoration: none;
  color: inherit;
}
.detail-photo img {
  display: block;
  width: 100%;
  height: auto;
  background: #2a2f36;
}
.detail-photo.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 18px 14px;
  background: linear-gradient(135deg, #1a1f24 0%, #232a32 100%);
  border: 1px dashed rgba(95, 184, 120, 0.35);
  color: var(--accent);
  font-weight: 600;
  font-size: 12.5px;
  min-height: 80px;
  text-align: center;
}
.detail-photo.placeholder small {
  color: var(--muted);
  font-weight: 400;
  font-size: 10.5px;
  line-height: 1.4;
}
.detail-photo.placeholder small code {
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 10px;
}

.detail-links {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 6px 0 4px 0;
}
.detail-links .link {
  display: inline-flex;
  align-items: center;
  font-size: 11.5px;
  font-weight: 600;
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #f5f7fa;
  color: #1a1f24;
  transition: background-color 0.12s, border-color 0.12s;
}
.detail-links .link:hover { background: #e6eaf0; }
.detail-links .link-yelp { color: #d22323; border-color: rgba(210, 35, 35, 0.25); }
.detail-links .link-gmaps { color: #1a73e8; border-color: rgba(26, 115, 232, 0.25); }
.detail-links .link-sv { color: #2c8a4e; border-color: rgba(44, 138, 78, 0.3); }

/* Sidebar */
.sidebar {
  position: absolute;
  top: 110px;
  right: 16px;
  bottom: 16px;
  width: 320px;
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  transition: width 0.18s ease, opacity 0.18s ease;
}
.sidebar.collapsed {
  width: 38px;
}
.sidebar.collapsed .sidebar-header,
.sidebar.collapsed .sidebar-body {
  display: none;
}

.sidebar-toggle {
  position: absolute;
  top: 8px;
  left: 6px;
  z-index: 2;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(15, 18, 22, 0.85);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background-color 0.15s;
}
.sidebar-toggle:hover { background: rgba(95, 184, 120, 0.18); border-color: var(--accent); }
.sidebar.collapsed .sidebar-toggle { left: 6px; }

.sidebar-header {
  padding: 10px 14px 6px 38px;
  border-bottom: 1px solid var(--panel-border);
}
.sidebar-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 18px 16px;
  /* Sidebar always uses the dark theme — override the popup-style inheritance */
  color: var(--text);
}
.sidebar-body .detail-name { color: var(--text); font-size: 16px; margin-bottom: 6px; }
.sidebar-body .detail-addr { color: var(--muted); font-size: 13px; }
.sidebar-body .detail-meta { color: var(--muted); }
.sidebar-body .detail-aka { color: var(--muted); }
.sidebar-body .detail-aka strong { color: var(--text); }
.sidebar-body .detail-links .link {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--text);
}
.sidebar-body .detail-links .link:hover { background: rgba(255, 255, 255, 0.12); }
.sidebar-body .detail-links .link-yelp { color: #ff6b6b; }
.sidebar-body .detail-links .link-gmaps { color: #6ea8fc; }
.sidebar-body .detail-links .link-sv { color: var(--accent); }

.sidebar-empty p { margin: 0 0 8px 0; font-size: 13px; line-height: 1.5; color: var(--text); }
.sidebar-empty p.muted { color: var(--muted); font-size: 12px; }

.about {
  /* shift away from the sidebar when both are visible */
  right: 360px;
}

/* ----- Toolbar ----- */
.toolbar {
  position: absolute;
  top: 124px;
  left: 16px;
  z-index: 1000;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 7px 14px 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
.tb-btn:hover { background: rgba(95, 184, 120, 0.1); border-color: var(--accent); }
.tb-btn.on {
  background: rgba(255, 210, 58, 0.18);
  border-color: rgba(255, 210, 58, 0.5);
  color: #ffd23a;
}
.tb-icon { font-size: 14px; line-height: 1; }
.tb-label { line-height: 1; }

.tb-yelp {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 5px 14px 5px 12px;
  font-size: 12.5px;
  color: var(--text);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  cursor: default;
}
.tb-yelp.disabled { opacity: 0.55; }
.tb-yelp .tb-icon { color: #ffd23a; }
.tb-yelp input[type="range"] {
  width: 120px;
  accent-color: #ffd23a;
  margin: 0 2px;
}
.tb-yelp input[type="number"] {
  width: 56px;
  text-align: right;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  padding: 2px 6px;
}
.tb-yelp input[type="number"]:focus { outline: none; border-color: #ffd23a; }
.tb-yelp input[type="number"]:disabled { opacity: 0.5; cursor: not-allowed; }
.tb-select {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  color: var(--text);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  cursor: pointer;
}
.tb-select:disabled { opacity: 0.5; cursor: not-allowed; }
.tb-select:hover:not(:disabled) { border-color: var(--accent); }
.tb-sort .tb-icon { color: var(--accent); }
.tb-yelp input[type="range"]:disabled { cursor: not-allowed; }
.tb-yelp #yelp-value { font-weight: 700; min-width: 22px; text-align: right; font-variant-numeric: tabular-nums; }
.tb-yelp-coverage { color: var(--muted); font-size: 11px; margin-left: 4px; }

.detail-rating {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 6px 0;
  font-size: 12.5px;
  color: #1a1f24;
}
.detail-rating .rating-stars { color: #f4a300; letter-spacing: 1px; font-size: 13px; line-height: 1; }
.detail-rating .rating-num { font-weight: 700; font-variant-numeric: tabular-nums; }
.detail-rating .rating-count { color: #7a8290; font-size: 11px; }
.detail-rating .rating-link {
  margin-left: auto;
  color: #d22323;
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
  border-bottom: 1px dotted rgba(210, 35, 35, 0.5);
}
.detail-rating .rating-link:hover { border-bottom-style: solid; }

.sidebar-body .detail-rating { color: var(--text); }
.sidebar-body .detail-rating .rating-count { color: var(--muted); }
.sidebar-body .detail-rating .rating-link { color: #ff6b6b; border-color: rgba(255, 107, 107, 0.4); }

.route-active-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(244, 196, 48, 0.12);
  border: 1px solid rgba(244, 196, 48, 0.4);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  color: #f4c430;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.route-active-info input[type="range"] {
  width: 110px;
  vertical-align: middle;
  accent-color: #f4c430;
}
.route-active-info strong { color: #ffe082; font-weight: 700; }

/* ----- Routes panel ----- */
.routes-panel {
  position: absolute;
  top: 170px;
  left: 16px;
  z-index: 1000;
  width: 320px;
  max-height: calc(100vh - 200px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.routes-panel[hidden] { display: none; }
.rp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--panel-border);
}
.rp-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.rp-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
}
.rp-close:hover { color: var(--text); }

.rp-list {
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.route-item {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.02);
}
.route-item.active { border-color: rgba(244, 196, 48, 0.5); background: rgba(244, 196, 48, 0.08); }
.ri-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.ri-name { font-weight: 600; font-size: 13px; flex: 1; }
.ri-tag { font-size: 9.5px; padding: 1px 6px; border-radius: 999px; background: rgba(95, 184, 120, 0.2); color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; }
.ri-meta { font-size: 11.5px; color: var(--muted); margin-bottom: 8px; }
.ri-actions { display: flex; gap: 6px; }

.rp-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.rp-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); border-color: var(--accent); }
.rp-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.rp-btn.primary { background: var(--accent); color: #0d2113; border-color: var(--accent-strong); }
.rp-btn.primary:hover:not(:disabled) { background: #6dca87; }
.rp-btn.small { padding: 4px 10px; font-size: 11px; }
.rp-btn.ghost { background: transparent; color: var(--muted); }
.rp-btn.ghost:hover:not(:disabled) { color: var(--warn); border-color: var(--warn); background: rgba(217, 119, 87, 0.08); }

.rp-new {
  border-top: 1px solid var(--panel-border);
  padding: 10px 12px;
}
.rp-new summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  font-size: 12.5px;
  padding: 4px 0;
  list-style: none;
}
.rp-new summary::-webkit-details-marker { display: none; }
.rp-form { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; }
.rp-form label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.rp-form input, .rp-form textarea {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}
.rp-form input:focus, .rp-form textarea:focus { border-color: var(--accent); outline: none; }
.rp-msg { margin: 0; font-size: 11.5px; color: var(--muted); min-height: 16px; }
.rp-msg.error { color: var(--warn); }
.rp-foot { padding: 6px 12px 10px 12px; margin: 0; font-size: 10.5px; color: var(--muted); border-top: 1px solid var(--panel-border); }

/* ----- Detail block: actions row (favorite button) ----- */
.detail-actions {
  display: flex;
  gap: 6px;
  margin: 4px 0 6px 0;
}
.fav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f5f7fa;
  border: 1px solid rgba(0, 0, 0, 0.08);
  color: #5a6270;
  border-radius: 999px;
  padding: 4px 12px 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
}
.fav-btn:hover { background: #ffeaa7; border-color: #ffd23a; color: #7a5b00; }
.fav-btn.on { background: #fff3c4; border-color: #ffd23a; color: #7a5b00; }
.fav-btn .fav-glyph { font-size: 14px; line-height: 1; color: #ffb800; }
.fav-btn.on .fav-glyph { color: #f4a300; }

/* Sidebar dark-theme override of fav button */
.sidebar-body .fav-btn {
  background: rgba(255, 210, 58, 0.1);
  border-color: rgba(255, 210, 58, 0.25);
  color: var(--text);
}
.sidebar-body .fav-btn:hover { background: rgba(255, 210, 58, 0.2); border-color: rgba(255, 210, 58, 0.5); }
.sidebar-body .fav-btn.on { background: rgba(255, 210, 58, 0.25); border-color: rgba(255, 210, 58, 0.6); }
.sidebar-body .fav-btn .fav-glyph { color: #ffd23a; }

@media (max-width: 720px) {
  #header { flex-direction: column; gap: 8px; }
  .title, .stats { max-width: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .about { max-width: none; left: 16px; right: 16px; bottom: 80px; }
  .sidebar {
    top: auto;
    left: 16px;
    right: 16px;
    bottom: 16px;
    width: auto;
    max-height: 50vh;
  }
  .sidebar.collapsed { max-height: 36px; width: auto; }
  .sidebar.collapsed .sidebar-toggle { transform: rotate(90deg); }
}
