#map {
  width: 800px;
  height: 500px;
}

.info {
  padding: 6px 8px;
  font: var(--info-font-size, 14px)/1.143 Arial, Helvetica, sans-serif;
  background: white;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
  border-radius: 5px;
}

/* Clickable column names, with the sort indicator hanging to the left of the active one. The
   indicator needs no track space of its own: it sits in the column gap and any slack to the left
   of the name, so the column widths below are sized to their widest label or value. */
.info-col-text { position: relative; }
.info-col-sortable { cursor: pointer; user-select: none; }
.info-col-sortable:hover,
.info-col-label.info-col-sorted { color: #333; }
.info-col-sortable:focus-visible { outline: 1px solid #777; outline-offset: 1px; border-radius: 2px; }
.info-sort-ind {
  position: absolute;
  right: 100%;
  margin-right: 0.25em;
  font-size: 0.85em;
  white-space: nowrap;
  color: #333;
}

.info h4 {
  margin: 0 0 5px;
  color: #777;
  text-align: center;
}

.info-area-name {
  text-align: center;
  margin-bottom: 4px;
}

/* The title and area name wrap to the width the rows need, instead of setting it.
   width:0 removes them from the box's size-to-content calculation; min-width:100% then
   stretches them back to the box's full width. */
.info:not(.legend) h4,
.info-area-name {
  width: 0;
  min-width: 100%;
  overflow-wrap: break-word;
}
/* Floor for when there are no rows to size the box (e.g. "Hover over an area"). */
.info:not(.legend) {
  min-width: 16em;
}

.info-uni-list {
  text-align: left;
}

.info-section-heading {
  font-weight: bold;
  margin: 8px 0 2px;
  text-align: left;
}

.info-row {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 1.5em;
  align-items: baseline;
  text-align: left;
  padding-left: 6px;   /* indent content; flush-left headers now stand out */
}

.info-row-years {
  display: grid;
  grid-template-columns: 1fr 3.3em 3.3em 5.4em;
  column-gap: 0.6em;
  align-items: baseline;
}

/* Share views in comparison: wider year and change columns for "12.34%" and "0.12 pp" values */
.info-share-change .info-row-years {
  grid-template-columns: 1fr 3.5em 3.5em 6.6em;
}

.info-row-year {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.info-col-label {
  text-align: right;
  font-weight: normal;
  font-size: 0.857em;
  color: #777;
}
.info-years .info-row-label { max-width: 11em; }
.info-years .info-section-heading > span:first-child { white-space: nowrap; }

.info-row-shares {
  display: grid;
  grid-template-columns: 1fr 4.8em 4.4em 5.9em;
  column-gap: 0.6em;
  align-items: baseline;
}
.info-row-span {
  display: grid;
  grid-template-columns: 1fr 4.8em 4.4em 5.9em;   /* same tracks as .info-row-shares */
  column-gap: 0.6em;
  align-items: baseline;
}
.info-row-span .info-row-label { grid-column: 1 / span 3; }
.info-row-span .info-row-value { grid-column: 4; }
.info-shares .info-row-span .info-row-label { max-width: none; }   /* no need to wrap now */

.info-row-value {
  text-align: right;
  font-variant-numeric: tabular-nums;   /* keeps digit columns vertically aligned */
  white-space: nowrap;
}

.info-row-selected {
  font-weight: bold;
}
/* Row highlight on hover, so the eye can follow a name across to its numbers.
   Only on devices with a real hover, so touch screens don't leave a row stuck highlighted. */
@media (hover: hover) {
  .info-row:hover {
    background: rgba(0, 0, 0, 0.08);
    border-radius: 3px;
    /* Extend the highlight into the scroll area's 4px right padding without moving the
       numbers, so they stay lined up with their column headings. */
    margin-right: -4px;
    padding-right: 4px;
  }
}

/* Grouping icons (state / institutional network) before the name in the hover box list.
   Drawn as a mask, so the icon takes the text colour whatever fill the svg file has. */
.info-row-icon {
  display: inline-block;
  width: 1.15em;
  height: 1.15em;
  margin-right: 0.3em;
  vertical-align: -0.22em;
  background-color: currentColor;
  opacity: 0.7;
  -webkit-mask-repeat: no-repeat;  mask-repeat: no-repeat;
  -webkit-mask-position: center;   mask-position: center;
  -webkit-mask-size: contain;      mask-size: contain;
}
.info-row-icon-state {
  -webkit-mask-image: url('../icons/state_icon.svg');
  mask-image: url('../icons/state_icon.svg');
}
.info-row-icon-network {
  -webkit-mask-image: url('../icons/grouping_icon.svg');
  mask-image: url('../icons/grouping_icon.svg');
}

.info-bottom-row {
  margin-top: 6px;
}

/* Footer below the scrolling list, so "Show all" / "Show groupings" / "Show years" / "Show shares" are always
   visible and the list never scrolls underneath them. */
.info-toggle {
  text-align: center;
  flex: none;
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid rgba(0, 0, 0, 0.12);
}

.info-toggle a {
  font-size: 0.857em;
  color: #555;
  text-decoration: underline;
  cursor: pointer;
}

.info-toggle a:hover {
  color: #000;
}

.legend {
  text-align: left;
  line-height: 1.286;
  line-height: 18px;
  color: #555;
  width: max-content;
  min-width: 0;
  max-width: min(220px);
  box-sizing: border-box;
}

/* Title: allow wrapping so it doesn't force the box wider */
.legend h4 {
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
  margin: 0 0 6px;
  font-size: 0.93em; 
}

/* Each swatch + value row: flex layout, no wrapping */
.legend .legend-row {
  display: flex;
  align-items: center;
  white-space: nowrap;
  margin-top: 2px;
}

.legend i {
  width: 1.286em;    
  height: 1.286em;
  flex-shrink: 0;
  float: none; 
  margin-right: 8px;
  opacity: 0.7;
}

/* Hatched "empty region" swatch: same grey + pattern the map uses */
.legend i.legend-hatched {
  background-color: #969696a4;
  background-image: url('../icons/hatching.png');
}


/* leaflet marker fade in */
.leaflet-marker-icon,
.leaflet-marker-shadow {
  --fade-in-time: 0.5s;
  -webkit-animation: fadein var(--fade-in-time);
  /* Safari, Chrome and Opera > 12.1 */
  -moz-animation: fadein var(--fade-in-time);
  /* Firefox < 16 */
  -ms-animation: fadein var(--fade-in-time);
  /* Internet Explorer */
  -o-animation: fadein var(--fade-in-time);
  /* Opera < 12.1 */
  animation: fadein var(--fade-in-time);
}

@keyframes fadein {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* Firefox < 16 */
@-moz-keyframes fadein {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* Safari, Chrome and Opera > 12.1 */
@-webkit-keyframes fadein {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* Internet Explorer */
@-ms-keyframes fadein {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* Opera < 12.1 */
@-o-keyframes fadein {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}



/* Hover box: cap its height and scroll internally so a long list doesn't spill past
   the map and behind the attribution. auto = a scrollbar only when content exceeds.
   Kept ABOVE the mobile media query so the mobile max-height can override it. */
.info:not(.legend) {
  max-height: 75vh;      /* standalone desktop: the map is roughly viewport height */
  display: flex;         /* column: scrolling body on top, fixed toggle footer below */
  flex-direction: column;
  overflow: hidden;
}
.info-scroll {
  overflow-y: auto;      /* only the body scrolls... */
  overflow-x: hidden;    /* ...never sideways, even with long university names */
  min-height: 0;         /* lets it shrink below its content so the footer stays visible */
  padding-right: 4px;    /* small gap between the numbers and the scrollbar */

  /* Slim, subtle scrollbar so it doesn't compete with the page's own. */
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.28) transparent;
  /* Always reserve the scrollbar's space, so the box is sized to include it and it can
     never overlap the right-hand number column. */
  scrollbar-gutter: stable;
}
/* Older Safari doesn't know scrollbar-width; style the WebKit scrollbar instead. */
@supports not (scrollbar-width: thin) {
  .info-scroll::-webkit-scrollbar { width: 6px; }
  .info-scroll::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.28); border-radius: 3px; }
}

/* Embedded desktop: vh would be the iframe's (content-driven) height, so use pixels.
   Tracks the map height (--embedded-map-height in containers.css), minus room for the attribution. */
@media not all and (max-width: 800px) {
  html.embedded .info:not(.legend) {
    max-height: calc(var(--embedded-map-height, 700px) - 60px);
  }
}

/* ---- Mobile map scaling ---- */
@media (max-width: 800px) {
  /* --- existing overlay scaling --- */
  .info {
    transform: scale(0.6);
    transform-origin: top right;
    padding: 3px 5px;                 
  }
  .info.legend {
    transform: scale(0.6);
    transform-origin: bottom left;
    width: max-content;    
    min-width: 0;
    max-width: none;       
  }

  /* The hover box is drawn at scale(0.6), so its LAYOUT size is 1/0.6 of what is seen.
     - Height: the mobile map is a fixed 480px (see #map in containers.css); allow ~440px
       of it to be visible, i.e. 440 / 0.6 in layout px. (The old 420px cap was only ~250px
       on screen, which cut off the Show all / Show years links.)
     - Width: size to content instead of being squeezed to the map's width, otherwise the
       profile labels wrap onto two lines and eat vertical space. Capped to the viewport
       (also drawn at 0.6) so it can never overflow the screen. */
  .info:not(.legend) {
    max-height: calc((480px - 40px) / 0.6);
    width: max-content;
    max-width: calc((100vw - 20px) / 0.6);
  }
  .info-years .info-row-label { max-width: none; }   /* desktop wraps at 11em; no need on mobile */

  /* 1. Attribution: 50% smaller, pinned to its own corner */
  .leaflet-control-attribution {
    transform: scale(0.75);
    transform-origin: bottom right;
  }

  /* 2. Tuck every corner control tight to the map edge (Leaflet default is 10px) */
  .leaflet-top    .leaflet-control { margin-top: 2px; }
  .leaflet-bottom .leaflet-control { margin-bottom: 2px; }
  .leaflet-left   .leaflet-control { margin-left: 2px; }
  .leaflet-right  .leaflet-control { margin-right: 2px; }
}


/* ---- Map display control (layers button + options panel; see display_options.ts) ---- */

/* Above the hover box, which is a later control in the DOM and would otherwise paint over the panel */
.leaflet-control.acses-display-control {
  z-index: 1100;
}

.acses-display-button {
  display: flex !important;   /* centre the icon (Leaflet's .leaflet-bar a is display:block) */
  align-items: center;
  justify-content: center;
}
.acses-display-button svg {
  display: block;
}

.acses-display-panel {
  display: none;
  position: absolute;
  top: 0;
  left: calc(100% + 8px);
  width: max-content;
  min-width: 170px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 5px;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
  font: 13px/1.4 Arial, Helvetica, sans-serif;
  color: #333;
  text-align: left;
}
.acses-display-control.open .acses-display-panel {
  display: block;
}
.acses-display-title {
  font-weight: bold;
  margin-bottom: 4px;
}
.acses-display-heading {
  font-weight: bold;
  margin: 8px 0 2px;
}
.acses-display-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  cursor: pointer;
}

/* ---- Borders off ----
   Regions are painted opaque (see region_style in index.ts); the see-through look is applied
   to the whole polygon layer here, so neighbouring shapes can't stack and show darker edges.
   Keep this in step with FILL_OPACITY in index.ts. */
.leaflet-container.borders-off .leaflet-overlay-pane {
  opacity: 0.7;
}

/* ---- Basemap options ---- */
/* Muted: greyed and faded so the choropleth stands out. Only the tile pane is filtered; the
   regions, markers and controls are untouched. */
.leaflet-container.basemap-muted .leaflet-tile-pane {
  filter: grayscale(1) opacity(0.6);
}
/* None: the tile layer is removed in JS; give the empty map a plain light background */
.leaflet-container.basemap-none {
  background: #f7f7f7;
}

/* ---- Text size option (hover box + legend; see apply_font_size in display_options.ts) ----
   Desktop: Large = the original 14px, Default, Small and Smallest step down from it.
   Mobile:  Default = the original 14px (drawn at scale 0.6), Small and Smallest step down, Large up. */
.leaflet-container                              { --info-font-size: 13px; }   /* Default */
.leaflet-container[data-font-size="large"]      { --info-font-size: 14px; }
.leaflet-container[data-font-size="small"]      { --info-font-size: 12px; }
.leaflet-container[data-font-size="smallest"]   { --info-font-size: 11px; }

@media (max-width: 800px) {
  .leaflet-container                              { --info-font-size: 14px; }   /* Default */
  .leaflet-container[data-font-size="large"]      { --info-font-size: 16px; }
  .leaflet-container[data-font-size="small"]      { --info-font-size: 12px; }
  .leaflet-container[data-font-size="smallest"]   { --info-font-size: 10px; }
}

/* ---- Hover box and legend: tighter to the map edge ----
   Leaflet's default is 10px (.leaflet-top .leaflet-control etc. in leaflet.css). Only the hover box
   (top right) and legend (bottom left) are pulled in; the zoom and layers buttons, and the attribution,
   keep their positions. Desktop only: the mobile block above already uses 2px for every corner. */
@media not all and (max-width: 800px) {
  :root { --map-edge-gap: 3px; }   /* THE number to tune */

  .leaflet-top.leaflet-right .info:not(.legend) {
    margin-top: var(--map-edge-gap);
    margin-right: var(--map-edge-gap);
  }
  .leaflet-bottom.leaflet-left .info.legend {
    margin-bottom: var(--map-edge-gap);
    margin-left: var(--map-edge-gap);
  }
}