:root {
  /* Compact visible controls; 34px exceeds the WCAG 2.2 24px minimum and
     controls are separated by at least 6px. Do not turn every pill into a
     44px-high block on phones. */
  --cgd-control-min: 34px;
  --cgd-icon-target: 44px;
  --cgd-body-size: 14px;
  --cgd-secondary-size: 12px;
}

html,
body {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  background: transparent;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

img,
svg,
canvas {
  max-width: 100%;
}

.viz-wrapper,
.remit-viz,
#flowExplorer,
#coverageExplorer {
  width: 100%;
  min-width: 0;
  margin-inline: auto;
  padding-inline: clamp(12px, 2.2vw, 20px);
}

.controls,
.remit-viz__controls {
  min-width: 0;
}

.control-label,
.control-group > label,
.remit-viz__control-label,
.remit-viz__control > label,
.combo__label,
.country-picker > label {
  font-size: 12px !important;
  line-height: 1.3 !important;
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;
}

button,
input,
select,
textarea,
.country-trigger,
.combo__button,
.select-trigger {
  font-size: var(--cgd-body-size);
}

input,
select,
textarea,
.country-trigger,
.combo__button,
.select-trigger {
  font-size: var(--cgd-body-size) !important;
}

select,
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
.country-trigger,
.combo__button,
.select-trigger,
.segmented button,
.remit-viz__toggle button,
.toggle button,
.pager-btn,
.zoom-btn {
  min-height: var(--cgd-control-min) !important;
  height: auto !important;
}

.segmented,
.remit-viz__toggle,
.toggle {
  min-height: var(--cgd-control-min);
}

.segmented button,
.remit-viz__toggle button,
.toggle button {
  padding: 6px 9px;
  font-size: 13px !important;
  line-height: 1.2;
}

.fullscreen-btn,
.popup-close,
.metric-info-close,
.info-btn,
.pager-btn,
.zoom-btn {
  min-width: var(--cgd-icon-target);
  min-height: var(--cgd-icon-target);
  width: var(--cgd-icon-target);
  height: var(--cgd-icon-target);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.zoom-btn.reset {
  width: auto;
  min-width: var(--cgd-control-min);
}

.notes,
.source,
.remit-viz__source,
.tooltip,
.popup-sub,
.descriptor-context {
  font-size: max(var(--cgd-secondary-size), 0.75rem);
  line-height: 1.4;
}

.descriptor-title {
  font-size: 12px !important;
}

.legend,
.legend-item,
.region-legend-item,
.remit-viz__legend,
.remit-viz__legend-item {
  font-size: 12px !important;
}

.country-menu,
.combo__list,
.country-options {
  max-width: calc(100vw - 24px);
}

.popup-card,
.modal-card {
  max-width: min(680px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
}

@media (max-width: 760px) {
  .controls,
  .remit-viz__controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
    gap: 10px;
  }

  .controls > *,
  .remit-viz__controls > * {
    min-width: 0;
    width: 100%;
    max-width: none;
    flex: none;
  }

  .country-picker {
    grid-column: auto;
  }
}

@media (max-width: 520px) {
  .viz-wrapper h1,
  .remit-viz h1,
  #flowExplorer h1,
  #coverageExplorer h1 {
    font-size: clamp(20px, 5.8vw, 22px) !important;
    line-height: 1.14 !important;
  }

  .viz-wrapper,
  .remit-viz,
  #flowExplorer,
  #coverageExplorer {
    padding-inline: 12px;
  }

  .controls,
  .remit-viz__controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 8px;
  }

  .country-picker {
    grid-column: 1 / -1;
  }

  .metric-control {
    grid-column: 1 / -1;
  }

  .segmented,
  .remit-viz__toggle,
  .toggle {
    width: 100%;
  }

  .segmented button,
  .remit-viz__toggle button,
  .toggle button {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap !important;
    overflow-wrap: normal !important;
    word-break: normal !important;
    hyphens: none !important;
    padding: 5px 7px !important;
    font-size: 12px !important;
  }

  /* Keep menus attached to their trigger. Fixed menus can appear far away after
     an iframe or mobile browser changes the visual viewport. */
  .country-menu,
  .combo__menu,
  .select-menu {
    position: absolute !important;
    inset-inline: 0 !important;
    top: calc(100% + 4px) !important;
    width: auto !important;
    max-height: min(48dvh, 360px) !important;
    overflow: auto !important;
    border-radius: 10px !important;
    padding: 4px !important;
  }

  .combo__list,
  .country-options {
    position: static !important;
    width: 100% !important;
    max-width: none !important;
    max-height: min(38dvh, 300px) !important;
    overflow: auto !important;
  }

  .combo__option,
  .country-option,
  .select-option {
    width: 100% !important;
    min-height: 36px !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 6px !important;
    background: transparent !important;
    box-shadow: none !important;
    text-align: left !important;
    font-size: 14px !important;
  }

  .combo__option[aria-selected="true"],
  .country-option.selected,
  .select-option.active {
    background: #eef4f5 !important;
  }

  /* iOS Safari zooms the page when an editable control below 16px receives
     focus. Do not suppress user zoom in the viewport meta tag. */
  input,
  select,
  textarea,
  .combo__search,
  .country-search,
  .search-select input {
    font-size: 16px !important;
  }

  .descriptor-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  .descriptor-tab {
    min-height: 0;
  }

  .descriptor-title {
    font-size: 12px !important;
  }

  .descriptor-value {
    font-size: 16px !important;
  }

  .descriptor-context {
    font-size: 12px !important;
  }

  .popup-backdrop,
  .modal-backdrop {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  .popup-card,
  .modal-card {
    width: 100% !important;
    max-width: none !important;
    max-height: min(82dvh, 680px) !important;
    border-radius: 16px 16px 0 0 !important;
    padding: 14px !important;
    overscroll-behavior: contain;
  }

  .popup-top,
  .modal-top {
    position: sticky;
    top: -14px;
    z-index: 2;
    background: #fff;
    padding-top: 14px;
  }

  .map-shell,
  .chart-wrap,
  .scatter-wrap,
  .plot-wrap {
    min-width: 0;
  }

  #coverageExplorer .controls {
    display: grid !important;
    grid-template-columns: minmax(112px, 0.85fr) minmax(146px, 1.15fr) !important;
    align-items: end !important;
    gap: 10px 8px !important;
    padding: 10px !important;
  }

  #coverageExplorer .controls > .control-group {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    flex: none !important;
  }

  #coverageExplorer .segmented {
    width: 100% !important;
  }

  #coverageExplorer .control-label,
  #coverageExplorer .segmented button {
    overflow-wrap: normal !important;
    word-break: normal !important;
    hyphens: none !important;
  }

  #coverageExplorer .segmented button {
    overflow: visible !important;
    text-overflow: clip !important;
  }
}

/*
  Some iOS iframe contexts retain a desktop-like layout viewport and visually
  scale it down. cgd-embed.js therefore adds this class from visualViewport,
  which follows the width the reader actually sees.
*/
.cgd-mobile-embed .viz-wrapper h1,
.cgd-mobile-embed .remit-viz h1,
.cgd-mobile-embed #flowExplorer h1,
.cgd-mobile-embed #coverageExplorer h1 {
  font-size: clamp(20px, 5.8vw, 22px) !important;
  line-height: 1.14 !important;
}

.cgd-mobile-embed .viz-wrapper,
.cgd-mobile-embed .remit-viz,
.cgd-mobile-embed #flowExplorer,
.cgd-mobile-embed #coverageExplorer {
  padding-inline: 12px;
}

.cgd-mobile-embed .controls,
.cgd-mobile-embed .remit-viz__controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
  gap: 6px;
  padding: 7px;
}

.cgd-mobile-embed .controls > *,
.cgd-mobile-embed .remit-viz__controls > * {
  min-width: 0;
  width: 100%;
  max-width: none;
  flex: none;
}

.cgd-mobile-embed .control-spacer {
  display: none !important;
}

.cgd-mobile-embed .country-picker,
.cgd-mobile-embed .metric-control {
  grid-column: 1 / -1;
}

.cgd-mobile-embed .segmented,
.cgd-mobile-embed .remit-viz__toggle,
.cgd-mobile-embed .toggle {
  width: 100%;
  min-height: var(--cgd-control-min) !important;
}

.cgd-mobile-embed .segmented button,
.cgd-mobile-embed .remit-viz__toggle button,
.cgd-mobile-embed .toggle button {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--cgd-control-min) !important;
  white-space: nowrap !important;
  overflow-wrap: normal !important;
  word-break: normal !important;
  hyphens: none !important;
  padding: 4px 6px !important;
  font-size: 12px !important;
  line-height: 1.15 !important;
}

.cgd-mobile-embed .country-menu,
.cgd-mobile-embed .combo__menu,
.cgd-mobile-embed .select-menu {
  position: absolute !important;
  inset-inline: 0 !important;
  top: calc(100% + 4px) !important;
  width: auto !important;
  max-height: min(48dvh, 360px) !important;
  overflow: auto !important;
  border-radius: 10px !important;
  padding: 4px !important;
  background: #fff !important;
  z-index: 1000 !important;
}

.cgd-mobile-embed .combo__list,
.cgd-mobile-embed .country-options {
  position: static !important;
  width: 100% !important;
  max-width: none !important;
  max-height: min(38dvh, 300px) !important;
  overflow: auto !important;
}

.cgd-mobile-embed .combo__option,
.cgd-mobile-embed .country-option,
.cgd-mobile-embed .select-option {
  display: block !important;
  width: 100% !important;
  min-height: 36px !important;
  margin: 0 !important;
  padding: 7px 9px !important;
  border: 0 !important;
  border-radius: 5px !important;
  background: transparent !important;
  box-shadow: none !important;
  text-align: left !important;
  font-size: 14px !important;
}

.cgd-mobile-embed .combo__option + .combo__option,
.cgd-mobile-embed .country-option + .country-option,
.cgd-mobile-embed .select-option + .select-option {
  border-top: 1px solid #edf2f3 !important;
}

.cgd-mobile-embed .combo__option[aria-selected="true"],
.cgd-mobile-embed .country-option.selected,
.cgd-mobile-embed .select-option.active {
  background: #eef4f5 !important;
}

.cgd-mobile-embed input,
.cgd-mobile-embed select,
.cgd-mobile-embed textarea,
.cgd-mobile-embed .combo__search,
.cgd-mobile-embed .country-search,
.cgd-mobile-embed .search-select input {
  font-size: 16px !important;
}

.cgd-mobile-embed .axis text,
.cgd-mobile-embed .tick text,
.cgd-mobile-embed .axis-label,
.cgd-mobile-embed svg text.axis,
.cgd-mobile-embed svg text.tick {
  font-size: 9.5px !important;
}

.cgd-mobile-embed .fullscreen-btn {
  display: none !important;
}

.cgd-mobile-embed .popup-backdrop,
.cgd-mobile-embed .modal-backdrop {
  align-items: flex-end !important;
  padding: 0 !important;
}

.cgd-mobile-embed .popup-card,
.cgd-mobile-embed .modal-card {
  width: 100% !important;
  max-width: none !important;
  max-height: min(82dvh, 680px) !important;
  border-radius: 16px 16px 0 0 !important;
  padding: 14px !important;
  overscroll-behavior: contain;
}

.cgd-mobile-embed #coverageExplorer .controls {
  grid-template-columns: minmax(108px, 0.85fr) minmax(138px, 1.15fr) !important;
  gap: 6px !important;
  padding: 7px !important;
}

.cgd-mobile-embed #coverageExplorer .controls > .control-group {
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  flex: none !important;
}

.cgd-mobile-embed #coverageExplorer .segmented {
  width: 100% !important;
}

/* Chart-specific compact control maps. Every occupied mobile row must be
   complete: no singleton half-row and no unexplained blank cell. */
[data-cgd-interactive-name="bilateral-remittances-map"].cgd-mobile-embed .country-picker {
  grid-column: auto;
}

[data-cgd-interactive-name="bilateral-remittances-model-v-world-bank"].cgd-mobile-embed .remit-viz__controls {
  grid-template-columns: minmax(94px, .95fr) minmax(112px, 1.15fr) minmax(82px, .8fr);
}

[data-cgd-interactive-name="bilateral-remittances-regions-matrix"].cgd-mobile-embed .year-control,
[data-cgd-interactive-name="bilateral-remittances-income-matrix"].cgd-mobile-embed .year-control {
  grid-column: 1;
}

[data-cgd-interactive-name="bilateral-remittances-regions-matrix"].cgd-mobile-embed .metric-control,
[data-cgd-interactive-name="bilateral-remittances-income-matrix"].cgd-mobile-embed .metric-control {
  grid-column: 2;
}

[data-cgd-interactive-name="bilateral-remittances-regions-matrix"].cgd-mobile-embed .controls,
[data-cgd-interactive-name="bilateral-remittances-income-matrix"].cgd-mobile-embed .controls {
  grid-template-columns: minmax(0, 1.26fr) minmax(0, .74fr) !important;
}

[data-cgd-interactive-name="bilateral-remittances-regions-matrix"].cgd-mobile-embed .year-control,
[data-cgd-interactive-name="bilateral-remittances-regions-matrix"].cgd-mobile-embed .metric-control,
[data-cgd-interactive-name="bilateral-remittances-income-matrix"].cgd-mobile-embed .year-control,
[data-cgd-interactive-name="bilateral-remittances-income-matrix"].cgd-mobile-embed .metric-control {
  display: grid !important;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  gap: 6px !important;
}

[data-cgd-interactive-name="bilateral-remittances-regions-matrix"].cgd-mobile-embed .segmented,
[data-cgd-interactive-name="bilateral-remittances-income-matrix"].cgd-mobile-embed .segmented {
  width: 100% !important;
  min-width: 0 !important;
}

[data-cgd-interactive-name="bilateral-remittances-regions-matrix"].cgd-mobile-embed .segmented button,
[data-cgd-interactive-name="bilateral-remittances-income-matrix"].cgd-mobile-embed .segmented button {
  padding-inline: 2px !important;
}

[data-cgd-interactive-name="bilateral-remittances-migrant-stock-gni"].cgd-mobile-embed .metric-control {
  grid-column: 1 / -1;
}

[data-cgd-interactive-name="bilateral-remittances-migrant-stock-gni"].cgd-mobile-embed .region-control {
  grid-column: 1;
}

[data-cgd-interactive-name="bilateral-remittances-migrant-stock-gni"].cgd-mobile-embed .country-control {
  grid-column: 2;
}

[data-cgd-interactive-name="bilateral-remittances-oda-fdi"].cgd-mobile-embed .income-filter-group {
  grid-column: 1;
}

[data-cgd-interactive-name="bilateral-remittances-oda-fdi"].cgd-mobile-embed .country-picker {
  grid-column: 2;
}

[data-cgd-interactive-name="bilateral-remittances-total-gni"].cgd-mobile-embed .short-control {
  grid-column: 1;
}

[data-cgd-interactive-name="bilateral-remittances-total-gni"].cgd-mobile-embed .country-control {
  grid-column: 2;
}

[data-cgd-interactive-name="bilateral-remittances-corridors-gni"].cgd-mobile-embed .role-control {
  grid-column: 1;
  grid-row: 1;
}

[data-cgd-interactive-name="bilateral-remittances-corridors-gni"].cgd-mobile-embed .limit-control {
  grid-column: 2;
  grid-row: 1;
}

[data-cgd-interactive-name="bilateral-remittances-corridors-gni"].cgd-mobile-embed .country-control {
  grid-column: 1 / -1;
  grid-row: 2;
}

[hidden] {
  display: none !important;
}

/* Fullscreen inside an embedded visual is unreliable or redundant on phones.
   Hide the control for coarse pointers while leaving desktop support intact. */
@media (hover: none) and (pointer: coarse), (max-width: 520px) {
  .fullscreen-btn {
    display: none !important;
  }
}

@media (max-width: 360px) {
  .controls,
  .remit-viz__controls {
    padding-inline: 8px;
  }

  #coverageExplorer .controls {
    grid-template-columns: minmax(106px, 0.82fr) minmax(140px, 1.18fr) !important;
    gap: 8px 6px !important;
    padding-inline: 8px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
