/* ---- Font import: Roboto (clean sans-serif) ---- */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

/* ================================================================
   THEME VARIABLES  —  change these to restyle the whole app
   ================================================================ */
:root {
  --emphasis:        #1b4965;   /* primary navy: headers, active states, titles */
  --emphasis-text:   #ffffff;   /* text on top of --emphasis backgrounds */
  --accent-light:    #cae9ff;   /* light blue accent (header underline, subtitle) */
  --label-grey:      #6b6b6b;   /* all-caps section labels */
  --hairline:        #d6d0c4;   /* thin dividers / borders */
  --input-border:    #c4bdae;   /* input & button borders */
  --box-bg:          rgba(255, 255, 255, 0.92);  /* control box / legend bg */
}

/* ---- Base ---- */

html, body {
  height: auto;          /* not 100% or 100vh — let content grow */
  min-height: 100%;
  overflow-y: auto;      /* allow vertical scroll */
}

body {
  margin: 0;
  font-family: 'Roboto', Arial, Helvetica, sans-serif;
  color: #2b2b2b;
  background: #f7f5f0;
  line-height: 1.55;
  font-size: 1.5rem;            /* larger base for legibility */
  padding-bottom: 48px;
}

/* shared label style: grey, all-caps, spaced, easy to read */
.control-label,
.side-subtitle,
.about-card .credit,
.site-header .subtitle {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--label-grey);
  font-style: normal;        /* no italics anywhere */
  font-weight: 500;
}

/* ---- Header ---- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 26px 32px 18px;
  background: var(--emphasis);
  color: var(--emphasis-text);
  border-bottom: 4px solid var(--accent-light);
}

.site-header-text {
  min-width: 0;   /* let the text block shrink before the logo does */
}

.site-logo {
  height: 64px;         /* controls logo size; adjust to taste */
  width: auto;
  flex: 0 0 auto;       /* never squash the logo */
  object-fit: contain;
}

/* institution + funder logos row at the bottom of the About page */
.about-logos {
  display: flex;
  align-items: center;    /* vertically centre logos of differing heights */
  gap: 28px;              /* space between the two logos */
  margin: 32px 0 8px;
  flex-wrap: wrap;        /* stack on very narrow screens instead of overflowing */
}

.about-logos .about-logo {
  height: 64px;           /* same height for both, matches header logo */
  width: auto;
  display: block;
}

.site-header h1 {
  margin: 0;
  font-size: 4rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.site-header .subtitle {
  margin: 8px 0 0;
  font-size: 1.5rem;
  color: var(--accent-light);
}

/* ---- Tabs ---- */
.tabbable > .nav-tabs {
  padding: 0 32px;
  margin-top: 14px;
  border-bottom: 1px solid var(--hairline);
}

.nav-tabs > li > a {
  color: var(--emphasis);
  border-radius: 8px 8px 0 0;
  font-size: 1.5rem;
  font-weight: 500;
}

.nav-tabs > li.active > a,
.nav-tabs > li.active > a:hover,
.nav-tabs > li.active > a:focus {
  background: #ffffff;
  border-color: var(--hairline) var(--hairline) #ffffff;
  color: var(--emphasis);
}

/* ---- Map rounding / shadow ---- */
.map-wrap .mapboxgl-map,
.map-wrap .leaflet-container,
.map-wrap .html-widget {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.15);
}

/* ================================================================
   CONTROL BOX  (overlaid on the map)
   ================================================================ */
.map-controls {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 500;
  width: 280px;
  padding: 22px 24px;
  background: var(--box-bg);
  border: 1px solid rgba(27, 73, 101, 0.18);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

/* box title */
.map-controls h2 {
  margin: 0 0 18px;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--emphasis);
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 12px;
}

/* every section label: consistent size, spacing, grey caps */
.map-controls .control-label {
  font-size: 1.15rem;
  margin: 20px 0 8px;
}
.map-controls .control-label:first-of-type { margin-top: 4px; }

/* picker input (the "Colour towns by" dropdown trigger) */
.map-controls .btn,
.map-controls .selectpicker,
.map-controls .dropdown-toggle {
  border: 1px solid var(--input-border) !important;
  font-family: 'Roboto', Arial, sans-serif;
  font-size: 1.5rem !important;
  color: #2b2b2b !important;
  background: #ffffff !important;
}

/* ---- picker dropdown MENU items ---- */
.dropdown-menu > li > a {
  font-size: 1.5rem;
  padding: 8px 16px;
}

/* selected / hovered item in the dropdown menu */
.dropdown-menu > .active > a,
.dropdown-menu > .active > a:focus,
.dropdown-menu > .active > a:hover,
.dropdown-menu > li > a:hover {
  background-color: var(--emphasis) !important;
  color: var(--emphasis-text) !important;
}

/* optgroup headers inside the metric picker */
.dropdown-header {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 1.05rem !important;
  font-weight: 700;
  color: var(--emphasis) !important;
}

/* ---- fuel-type toggle (radioGroupButtons) ---- */
/* keep the natural shinyWidgets button-group look; only recolour
   the selected button to match the app's emphasis colour */
.map-controls .btn-group-container-sw {
  width: 100%;
  margin-bottom: 4px;
}

/* selected fuel button */
.map-controls .btn-group-container-sw .btn.active,
.map-controls .btn-group-container-sw .btn:active,
.map-controls .btn-group-container-sw input:checked + .btn {
  background: var(--emphasis) !important;
  color: var(--emphasis-text) !important;
  border-color: var(--emphasis) !important;
}

/* material switch (town names) — tint the "on" state to --emphasis */
.map-controls .material-switch input:checked + label::before {
  background-color: var(--emphasis) !important;
}

/* ---- About card ---- */
.about-card {
  max-width: 760px;
  margin: 28px auto;
  padding: 34px 38px;
  background: #ffffff;
  border: 1px solid #e2ddd2;
  border-radius: 12px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.08);
  font-size: 1.5rem;
}

.about-card h2 {
  margin-top: 0;
  font-weight: 700;
  font-size: 2rem;
  color: var(--emphasis);
}

.about-card h3 {
  font-weight: 500;
  font-size: 1.5rem;
  color: var(--emphasis);
  margin-bottom: 6px;
}

.about-card ul { padding-left: 22px; }
.about-card li { margin-bottom: 10px; }

.about-card code {
  background: #f0ede5;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.95em;
  font-family: 'Roboto Mono', monospace;
}

.about-card .credit {
  margin-top: 46px;      /* space above the credit block */
  margin-bottom: 0;
  font-size: 1.5rem;
}

/* a credit line that follows another credit line sits tight */
.about-card .credit + .credit {
  margin-top: 4px;       /* small gap between the two lines */
}

/* ---- Footer ---- */
.site-footer {
  text-align: center;
  padding: 18px;
  margin-top: 22px;
  font-size: 1.5rem;
  color: #888;
  border-top: 1px solid #e2ddd2;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ---- Ranking bar-plot panel ---- */
.rank-panel {
  background: #ffffff;
  border: 1px solid #e2ddd2;
  border-radius: 12px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  padding: 18px 24px 14px;

}

.side-header {
  border-bottom: 1px solid #ece7dc;
  flex: 0 0 auto;            /* header stays fixed height */
  margin-bottom: 14px;
}

.side-header h2 {
  margin: 0;
  font-weight: 700;
  font-size: 2rem;
  color: var(--emphasis);
}

.side-subtitle {
  margin-top: 5px;
  font-size: 1.5rem;
}

/* scrollable list area */
.rank-scroll {
  overflow-y: auto;
}

.rank-scroll::-webkit-scrollbar { width: 9px; }
.rank-scroll::-webkit-scrollbar-thumb {
  background: #cdc7b8;
  border-radius: 8px;
}

.rank-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 8px;
  margin: 0 -8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.rank-row:hover {
  background: #f4f1ea;
}

.rank-town {
  flex: 0 0 118px;          /* tighter → more room for the bar */
  font-size: 1.5rem;
  font-weight: 500;
  color: #2b2b2b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank-track {
  flex: 1 1 auto;
  min-width: 150px;         /* guarantee a readable bar length */
  height: 16px;
  background: #f0ede5;
  border-radius: 8px;
  overflow: hidden;
}

.rank-fill {
  height: 100%;
  min-width: 4px;           /* tiny values still show a sliver */
  border-radius: 8px 0 0 8px;
  transition: width 0.35s ease;
}

.rank-value {
  flex: 0 0 74px;
  text-align: right;
  font-size: 1.5rem;
  font-weight: 500;
  color: #555;
  font-variant-numeric: tabular-nums;
}

/* empty-state message when a measure has no data */
.rank-empty {
  padding: 24px 4px;
  color: var(--label-grey);
  font-size: 1.5rem;
}

/* ---- Side-by-side map + ranking layout ---- */
.map-layout {
  display: flex;
  gap: 20px;
  margin: 22px 32px;
  align-items: stretch;      /* both columns share the row's height */
  height: 74vh;              /* fixed row height: panel matches map */
}

.map-layout .rank-panel {
  flex: 0 0 460px;           /* wider sidebar → longer bars */
  margin: 0;
  display: flex;
  flex-direction: column;    /* header fixed, list scrolls to fill */
  min-height: 0;             /* allow inner scroll area to shrink */
}

/* list fills remaining panel height and scrolls internally */
.map-layout .rank-scroll {
  flex: 1 1 auto;
  min-height: 0;             /* critical: lets overflow-y actually scroll */
}

.map-layout .map-wrap {
  position: relative;
  flex: 1 1 auto;
  margin: 0;
  min-width: 0;
  display: flex;
}

.map-layout .map-wrap .mapboxgl-map,
.map-layout .map-wrap .html-widget,
.map-layout .map-wrap .leaflet-container {
  width: 100%;
  height: 100%;
  flex: 1 1 auto;
}

/* ---- Map legend (mapgl add_legend) ---- */
.mapboxgl-legend,
.maplibregl-legend {
  width: 300px !important;
  font-family: 'Roboto', Arial, sans-serif !important;
  background: var(--box-bg) !important;
  border: 1px solid rgba(27, 73, 101, 0.18) !important;
  border-radius: 12px !important;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18) !important;
  padding: 14px 16px !important;
}

.mapboxgl-legend .legend-title,
.maplibregl-legend .legend-title {
  font-weight: 700 !important;
  font-size: 1.3rem !important;
  color: var(--emphasis) !important;
  margin-bottom: 8px !important;
}

.mapboxgl-legend .legend-labels span,
.maplibregl-legend .legend-labels span,
.mapboxgl-legend span,
.maplibregl-legend span {
  font-size: 1.1rem !important;
  color: #444 !important;
}

/* ================================================================
   ABOUT TAB  —  reference documentation elements
   ================================================================ */

/* metadata block (Authors, Institution, Date, ...) */
.about-meta {
  margin: 4px 0;
  font-size: 1.35rem;
  line-height: 1.5;
}
.about-meta-label {
  font-weight: 700;
  color: var(--emphasis);
}

/* big section dividers (BRIEF METHODS, HOUSEHOLD COLUMNS, ...) */
.about-section {
  margin: 34px 0 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--emphasis);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--emphasis);
}

/* sub-headers: either a question or a column name */
.about-subheader {
  margin: 20px 0 6px;
  font-size: 1.4rem;
  font-weight: 500;
  color: #2b2b2b;
}

/* definition lists under each sub-header */
.about-defs {
  margin: 4px 0 8px;
  padding-left: 22px;
}
.about-defs li {
  margin-bottom: 6px;
  font-size: 1.35rem;
  line-height: 1.5;
}

/* indented note / caveat callouts */
.about-note {
  margin: 8px 0 8px 22px;
  padding: 10px 14px;
  background: #f4f1ea;
  border-left: 3px solid var(--input-border);
  border-radius: 0 8px 8px 0;
  font-size: 1.25rem;
  line-height: 1.5;
  color: #555;
}
.about-note-label {
  font-weight: 700;
  color: var(--emphasis);
}

/* town-names material switch: colour the "on" state to --emphasis */
.map-controls .material-switch > input[type="checkbox"]:checked + label::before {
  background: var(--emphasis) !important;   /* the track */
}
.map-controls .material-switch > input[type="checkbox"]:checked + label::after {
  background: var(--emphasis) !important;   /* the knob */
  border-color: var(--emphasis) !important;
}


/* ---- within-town comparison panel ---- */
.left-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 0;
  height: 100%;
}

.town-panel {
  background: #ffffff;
  border: 1px solid #e2ddd2;
  border-radius: 12px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.08);
  padding: 18px 24px;
  flex: 0 0 auto;
}

.town-empty {
  color: var(--label-grey);
  font-size: 1.2rem;
}

.town-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
}
.town-fuel {
  flex: 0 0 56px;
  font-weight: 500;
  font-size: 1.1rem;
}
.town-track {
  flex: 1 1 auto;
  height: 16px;
  background: #f0ede5;
  border-radius: 8px;
  overflow: hidden;
}
.town-fill {
  height: 100%;
  min-width: 4px;
  border-radius: 8px 0 0 8px;
  transition: width 0.35s ease;
}
.town-val {
  flex: 0 0 90px;
  text-align: right;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  color: #555;
}
.town-single {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--emphasis);
}


/* ================================================================
   MOBILE  —  stack everything vertically below tablet width
   ================================================================ */
@media (max-width: 768px) {

  /* ---- header: title/subtitle stack, logo drops below ---- */
  .site-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 18px 20px 14px;
  }
  .site-header h1 {
    font-size: 2.2rem;          /* 4rem is too big on a phone */
  }
  .site-header .subtitle {
    font-size: 1.05rem;
  }
  .site-logo {
    height: 44px;               /* smaller header logo on mobile */
  }

  /* ---- stack the ranking panel + map vertically ---- */
  .map-layout {
    flex-direction: column;
    height: auto;               /* was 74vh — grow with content */
    overflow: visible;          /* no inner scroll on the layout */
    margin: 14px 14px;
    gap: 14px;
  }

  /* ---- map-wrap: stack controls above the map, both in normal flow ---- */
  .map-layout .map-wrap {
    flex: none;
    flex-direction: column;     /* controls stack above the map */
    width: 100%;
    height: auto;               /* wrapper sizes to its children */
    position: static;           /* not a positioning context on mobile */
  }

  /* the map element itself gets an explicit height (0 otherwise) */
  .map-layout .map-wrap .mapboxgl-map,
  .map-layout .map-wrap .html-widget,
  .map-layout .map-wrap .maplibregl-map {
    height: 60vh !important;
    min-height: 320px;
    width: 100% !important;
  }

  /* ---- control box: out of the overlay, its own block above the map ---- */
  .map-controls {
    position: static !important;   /* was absolute — now flows normally */
    top: auto;
    right: auto;
    left: auto;
    width: 100% !important;
    max-width: 100%;
    margin: 14px auto;            /* gap below controls, before the map */
    box-sizing: border-box;
  }

/* ---- ranking panel: full width, fixed height, scrolls internally ---- */
  .map-layout .rank-panel {
    flex: none;
    width: 100%;
    max-height: 45vh;             /* fixed height so it doesn't run forever */
  }
  .map-layout .rank-scroll {
    overflow-y: auto;             /* scroll the town list inside the panel */
    max-height: none;
    overscroll-behavior: contain; /* stop scroll from chaining to the page */
    -webkit-overflow-scrolling: touch;  /* smooth momentum scroll on iOS */
  }

  .side-header h2 {
    font-size: 1.5rem;
  }
  .side-subtitle,  {
    font-size: 1.05rem;
  }

  /* ---- make sure the tab pane isn't its own scroll container ---- */
  .tab-content,
  .tab-pane {
    overflow: visible;
    height: auto;
  }

  /* ---- legend ---- */
  .mapboxgl-legend,
  .maplibregl-legend {
    margin: 10px auto !important;
  }

  /* ---- about card ---- */
  .about-card {
    margin: 16px 14px;
    padding: 22px 20px;
    font-size: 1.15rem;
  }
  .about-logos { gap: 18px; }
  .about-logos .about-logo { height: 48px; }
}