/* Shared colors for all context components */

.mapgl-context-panel,
.mapgl-context-search,
.mgc-tooltip {
  --mgc-accent: #1f6feb;
  --mgc-bg: rgba(255, 255, 255, 0.95);
  --mgc-text: #1f2328;
  --mgc-muted: #59636e;
  --mgc-bar: #d0d7de;
  box-sizing: border-box;
  color: var(--mgc-text);
  font: 12px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ------------------------------------------------------------------ */
/* Panels: view summary and ranking                                    */
/* ------------------------------------------------------------------ */

.mapgl-context-panel {
  max-width: calc(100vw - 20px);
  padding: 10px 12px 8px;
  border-radius: 8px;
  background: var(--mgc-bg);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
}

.mapgl-context-panel .mgc-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 18px;
}

.mapgl-context-panel .mgc-title {
  flex: 1;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mgc-muted);
}

.mapgl-context-panel .mgc-mini-value {
  display: none;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.mapgl-context-panel .mgc-toggle {
  flex: none;
  width: 20px;
  height: 20px;
  margin: -2px -4px -2px 0;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--mgc-muted);
  font: 16px/20px system-ui, sans-serif;
  cursor: pointer;
}

.mapgl-context-panel .mgc-toggle:hover,
.mapgl-context-panel .mgc-toggle:focus-visible {
  background: rgba(0, 0, 0, 0.06);
  color: var(--mgc-text);
}

/* Collapsed: only the header, sized to its content */

.mapgl-context-panel.mgc-collapsed {
  width: auto !important;
  padding: 6px 10px;
}

.mapgl-context-panel.mgc-collapsed .mgc-mini-value {
  display: inline;
}

.mapgl-context-panel.mgc-collapsed .mgc-body {
  display: none;
}

/* Text */

.mgc-muted {
  margin-top: 2px;
  color: var(--mgc-muted);
  font-variant-numeric: tabular-nums;
}

.mapgl-context-panel .mgc-label {
  margin-top: 8px;
}

.mapgl-context-panel .mgc-value {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.mapgl-context-panel .mgc-extremes {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--mgc-bar);
}

.mapgl-context-panel .mgc-empty {
  margin-top: 4px;
  color: var(--mgc-muted);
}

.mapgl-context-panel .mgc-footnote {
  margin-top: 4px;
  font-size: 10px;
  color: var(--mgc-muted);
}

.mgc-link {
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: var(--mgc-bar);
  text-underline-offset: 2px;
  cursor: pointer;
}

.mgc-link:hover,
.mgc-link:focus-visible {
  text-decoration-color: currentColor;
}

/* Histograms and strips */

.mgc-histogram {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 8px;
  overflow: visible;
}

.mgc-bar-all {
  fill: var(--mgc-bar);
}

.mgc-bar-view {
  fill: var(--mgc-accent);
}

/* A thin edge keeps light colors (the middle of a diverging scale)
   visible against the panel background. */
.mgc-bar-view,
.mgc-bar-colored {
  stroke: rgba(0, 0, 0, 0.25);
  stroke-width: 0.5;
}

.mgc-hit {
  fill: transparent;
  cursor: pointer;
}

.mgc-bin-active .mgc-hit {
  fill: rgba(0, 0, 0, 0.06);
}

.mgc-bin-active .mgc-bar-all,
.mgc-bin-active .mgc-bar-view {
  stroke: var(--mgc-text);
  stroke-width: 1;
}

.mgc-mean-all {
  stroke: var(--mgc-muted);
  stroke-width: 1;
  stroke-dasharray: 2 2;
  pointer-events: none;
}

.mgc-mean-view {
  stroke: var(--mgc-text);
  stroke-width: 2;
  pointer-events: none;
}

.mgc-axis {
  font-size: 9px;
  fill: var(--mgc-muted);
}

.mgc-legend {
  display: flex;
  gap: 12px;
  margin-top: 2px;
  font-size: 10px;
  color: var(--mgc-muted);
}

.mgc-legend-item i {
  display: inline-block;
  width: 14px;
  height: 8px;
  margin-right: 4px;
  border-radius: 2px;
}

.mgc-key-view {
  background: var(--mgc-accent);
}

.mgc-key-all {
  background: var(--mgc-bar);
}

/* Compact summary: count, value and comparison only */

.mapgl-context-panel.mgc-compact .mgc-value {
  font-size: 18px;
}

/* Mini summary: three figures side by side */

.mgc-mini-grid {
  display: flex;
  gap: 14px;
  margin-top: 4px;
}

.mgc-mini-cell {
  flex: 0 1 auto;
  min-width: 0;
}

/* The statistic's caption can be long ("Average · Population growth"):
   it takes the remaining space and up to two lines. */
.mgc-mini-cell:nth-child(2) {
  flex: 1 1 0;
}

.mgc-mini-num {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.mgc-mini-arrow {
  margin-left: 3px;
  font-size: 11px;
  color: var(--mgc-muted);
  vertical-align: 2px;
}

.mgc-mini-cap {
  display: -webkit-box;
  margin-top: 1px;
  overflow: hidden;
  font-size: 10px;
  line-height: 1.25;
  color: var(--mgc-muted);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

/* ------------------------------------------------------------------ */
/* Ranking                                                             */
/* ------------------------------------------------------------------ */

.mgc-rank-list {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.mgc-rank-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}

.mgc-rank-pos {
  flex: none;
  width: 14px;
  color: var(--mgc-muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.mgc-rank-main {
  flex: 1;
  min-width: 0;
}

.mgc-rank-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.mgc-rank-line .mgc-link {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mgc-rank-value {
  flex: none;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.mgc-rank-track {
  height: 4px;
  margin-top: 2px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.06);
}

.mgc-rank-bar {
  height: 100%;
  border-radius: 2px;
  background: var(--mgc-accent);
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.25);
}

.mgc-rank-overall {
  flex: none;
  min-width: 30px;
  color: var(--mgc-muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ------------------------------------------------------------------ */
/* Context tooltip                                                     */
/* ------------------------------------------------------------------ */

.mgc-tooltip {
  position: absolute;
  z-index: 3;
  display: none;
  width: 224px;
  padding: 8px 12px 6px;
  border-radius: 6px;
  background: var(--mgc-bg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.mgc-tooltip .mgc-tt-name {
  font-weight: 600;
}

.mgc-tooltip .mgc-tt-value {
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.mgc-tooltip .mgc-tt-strip {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 6px;
  overflow: visible;
}

.mgc-tooltip .mgc-tt-marker {
  stroke: var(--mgc-text);
  stroke-width: 1.5;
}

/* ------------------------------------------------------------------ */
/* Feature search                                                      */
/* ------------------------------------------------------------------ */

/* Above the other controls in the same corner, so its suggestions are not
   hidden behind a panel below it. */
.mapgl-context-search {
  position: relative;
  z-index: 5;
  pointer-events: auto;
}

.mapgl-context-search .mgc-search-input {
  box-sizing: border-box;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 6px;
  background: var(--mgc-bg);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  color: var(--mgc-text);
  font: inherit;
}

.mapgl-context-search .mgc-search-input:focus {
  outline: 2px solid var(--mgc-accent);
  outline-offset: -1px;
}

.mapgl-context-search .mgc-search-list {
  display: none;
  position: absolute;
  z-index: 4;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 260px;
  margin: 0;
  padding: 4px 0;
  overflow-y: auto;
  list-style: none;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.mapgl-context-search .mgc-search-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 10px;
  cursor: pointer;
}

.mapgl-context-search .mgc-search-item.mgc-active {
  background: rgba(0, 0, 0, 0.06);
}

.mapgl-context-search .mgc-search-detail {
  color: var(--mgc-muted);
  font-size: 11px;
  text-align: right;
}

.mapgl-context-search .mgc-search-none {
  padding: 5px 10px;
  color: var(--mgc-muted);
}
