/* ============================================================
   Chittenden County Accessibility & Household Travel
   Styled to match the project's companion app:
   teal (#005475) + green (#adc642), light gray panels with a
   green top bar, centered uppercase title, teal footer band.

   Every size is relative to --font-size-base, so changing that
   one number rescales the whole interface.
   ============================================================ */

/* Fonts load from Google Fonts when the network allows it; if the
   request is blocked, the fallback stacks below take over silently. */
@import url("https://fonts.googleapis.com/css2?family=Source+Sans+3:wght@400;500;600;700&display=swap");

/* ---- Design tokens ---------------------------------------- */
:root {
  /* brand, from the companion app */
  --teal:        #005475;
  --teal-dark:   #003f58;
  --green:       #adc642;
  --green-quiet: rgba(173, 198, 66, 0.18);

  /* surfaces */
  --bg:          #fcfcfb;   /* page                          */
  --panel:       #eff0ef;   /* side panels, row hover        */
  --surface:     #ffffff;   /* map frame, tables             */
  --border:      #dfe1df;
  --border-strong: #c6cac6;

  /* text */
  --text:        #222222;
  --text-muted:  #4b5153;
  --text-dim:    #6b7275;

  --radius:      0.5em;
  --shadow:      0px 0px 2px 0px rgba(29, 31, 33, 0.14), 0px 2px 4px 0px rgba(29, 31, 33, 0.16);

  /* headings use the same sans as the body, like the companion app */
  --font-heading: "Source Sans 3", "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-ui:      "Source Sans 3", "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, sans-serif;

  /* Master text size. 16px is a comfortable default; try 17px on large monitors. */
  --font-size-base: 16px;
}

/* ---- Global ----------------------------------------------- */
html { font-size: var(--font-size-base); }

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;   /* the full-width footer would otherwise add a sideways scrollbar */
}

.container-fluid {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  color: var(--text);
  font-weight: 700;
}

/* section titles above tables */
h4 {
  font-size: 1.25rem;
  color: var(--teal);
  margin: 0 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--green);
}

/* panel headings */
h5 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 0.85rem;
}

.control-panel * + h5 { margin-top: 1.5rem; }

p { margin: 0 0 0.75rem; }

/* links: green, with the companion app's green-chip hover */
a,
a:visited,
a:active { color: var(--teal); font-weight: 600; }

a:hover {
  background-color: var(--green);
  color: var(--teal);
  padding: 0.1em;
  border-radius: 0.1em;
  text-decoration: none;
}

::selection { background: var(--green-quiet); }

/* ---- Page header ------------------------------------------ */
.app-header {
  text-align: center;
  padding: 1.75rem 0.5rem 1.25rem;
}

.app-eyebrow {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
}

/* matches #title_panel in the companion app */
.app-title {
  color: var(--teal);
  font-size: 30px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  line-height: 1.2;
  margin: 0 0 0.5rem;
}

.app-lede {
  font-size: 1.05rem;
  color: var(--text-muted);
  max-width: 50rem;
  margin: 0 auto;
}

/* ---- Tabs -------------------------------------------------
   Same treatment as the companion app's tabs-within-tabs:
   teal bold labels, green top bar on the active tab.           */
.nav-tabs {
  background-color: var(--bg);
  border-bottom: 1px solid var(--border-strong);
  font-weight: 700;
  display: flex;
  justify-content: center;
}

.nav-tabs > li > a,
.nav-tabs .nav-link {
  color: var(--teal);
  font-weight: 700;
  font-size: 1.02rem;
  background-color: transparent;
  border: none;
  border-top: solid var(--bg) 0.6em;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0.55rem 1.25rem;
  margin-right: 0.25rem;
  transition: background-color 0.12s ease;
}

.nav-tabs > li > a:hover,
.nav-tabs .nav-link:hover {
  background-color: var(--green);
  color: var(--teal);
  border: none;
  border-top: solid var(--green) 0.6em;
  padding: 0.55rem 1.25rem;   /* override the global link-hover padding */
}

.nav-tabs > li.active > a,
.nav-tabs > li.active > a:hover,
.nav-tabs > li.active > a:focus,
.nav-tabs .nav-link.active {
  background-color: var(--surface);
  color: var(--teal);
  border: 1px solid var(--border-strong);
  border-bottom-color: var(--surface);
  border-top: solid var(--green) 0.6em;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0.55rem 1.25rem;
}

.tab-content { padding-top: 1.25rem; }

/* ---- Control panel ----------------------------------------
   Matches #side_panel: light gray, green top bar, soft shadow. */
.control-panel {
  background: var(--panel);
  color: var(--text);
  border-top: solid var(--green) 1em;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1em 1.25em 1.25em;
  margin: 0 0 1.25rem;
}

.help-text {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0.25rem 0 0;
}

/* summary statistics: label left, value right */
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(40, 70, 94, 0.1);
  font-size: 0.94rem;
}
.stat-row:last-child { border-bottom: none; }

.stat-label { color: var(--text-muted); }

/* caption under the "Distribution" heading (parcel / household counts) */
.dist-caption {
  font-size: 0.9rem;
  font-style: italic;
  color: var(--text-muted);
  margin: -0.5rem 0 0.5rem;   /* sit close under the heading */
}

.stat-value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--teal);
  text-align: right;
  overflow-wrap: anywhere;
}

/* ---- Form inputs ------------------------------------------ */
.form-group { margin-bottom: 25px; }

.shiny-input-container:not(.shiny-input-container-inline) {
  width: 100%;
  max-width: 100%;
}

.control-label,
.shiny-input-container > label {
  display: block;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.form-control,
.selectize-input,
.shiny-input-container input[type="text"] {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 0.3em;
  box-shadow: none;
  font-size: 0.95rem;
  height: auto;
}

.form-control:focus,
.selectize-input.focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 84, 117, 0.12);
}

/* pickerInput button */
.bootstrap-select > .btn.dropdown-toggle,
.bootstrap-select > .btn.dropdown-toggle.bs-placeholder {
  background-color: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: 0.3em;
  box-shadow: none !important;
  font-size: 0.95rem;
  font-weight: 500;
  text-align: left;
}

.bootstrap-select > .btn.dropdown-toggle:focus,
.bootstrap-select.open > .btn.dropdown-toggle,
.bootstrap-select.show > .btn.dropdown-toggle {
  border-color: var(--teal) !important;
  outline: none !important;
}

.bootstrap-select .dropdown-menu {
  border: 1px solid var(--border-strong);
  border-radius: 0.3em;
  box-shadow: var(--shadow);
  font-size: 0.95rem;
}

/* dropdown items: bold on hover, teal when selected (as in the companion app) */
.dropdown-menu > li > a:hover,
.bootstrap-select .dropdown-menu li a:hover {
  background-color: var(--panel);
  color: var(--text);
  padding: 3px 20px;   /* override the global link-hover padding */
  border-radius: 0;
}

.dropdown-menu > li.active > a,
.dropdown-menu > li.active > a:hover,
.bootstrap-select .dropdown-menu li.selected a,
.bootstrap-select .dropdown-menu li.active a {
  background-color: var(--teal);
  color: #ffffff;
  font-weight: 700;
  position: static;
}

/* group headings inside the picker (Travel, Built environment, ...) */
.bootstrap-select .dropdown-header {
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.7rem 1.25rem 0.25rem;
}

/* ---- Buttons ---------------------------------------------- */
/* shinyWidgets puts a <br> between a radioGroupButtons label and its
   buttons; hide it so the spacing matches the other inputs */
.form-group > .control-label + br,
.shiny-input-container > label + br {
  display: none;
}

/* Segmented controls (radioGroupButtons).
   One text color and one weight in every state, so labels never
   change color or width; the green fill alone marks the selection. */
.btn-group-container-sw .btn,
.btn-group-container-sw .btn:hover,
.btn-group-container-sw .btn:focus,
.btn-group-container-sw .btn.active,
.btn-group-container-sw .btn.active:hover,
.btn-group-container-sw .btn.active:focus {
  color: var(--text);
  font-weight: 600;
  box-shadow: none;
}

.btn-group-container-sw .btn {
  background-color: var(--surface);
  border: 1px solid var(--border-strong);
  font-size: 0.92rem;
  /* small side padding: four modes share a narrow sidebar */
  padding: 0.4rem 0.35rem;
  white-space: nowrap;
}

.btn-group-container-sw .btn:hover {
  background-color: var(--panel);
}

/* selected: green fill, as in the companion app */
.btn-group-container-sw .btn.active,
.btn-group-container-sw .btn.active:hover,
.btn-group-container-sw .btn.active:focus {
  background-color: var(--green);
  border-color: var(--green);
}

.btn:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}

/* ---- Sliders (same shapes as the companion app) ----------- */
.irs--shiny { height: 40px; }

/* slider tick labels in the app's font rather than the browser default */
.irs { font-family: var(--font-ui) !important; }

/* note directly under the household-minimum slider */
/* same caption style as .dist-caption */
.slider-note {
  font-size: 0.9rem;
  font-style: italic;
  color: var(--text-muted);
  margin: -0.6rem 0 1rem;   /* pull up close to the slider it describes */
}

.irs--shiny .irs-line {
  background: var(--surface);
  border: 1px solid var(--border-strong);
}

.irs--shiny .irs-bar {
  top: 25px;
  height: 8px;
  border-top: 1px solid var(--teal);
  border-bottom: 1px solid var(--teal);
  background: var(--teal);
  z-index: 2;
}

.irs--shiny .irs-handle {
  top: 18px;
  width: 8px;
  height: 20px;
  border: 1px solid var(--teal);
  background-color: var(--teal);
  box-shadow: 1px 1px 3px rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  z-index: 2;
}

.irs--shiny .irs-from,
.irs--shiny .irs-to,
.irs--shiny .irs-single {
  color: #ffffff;
  text-shadow: none;
  padding: 1px 3px;
  background-color: var(--teal);
  border-radius: 3px;
  font-size: 11px;
  line-height: 1.333;
}

.irs--shiny .irs-min,
.irs--shiny .irs-max { color: var(--text-dim); background: transparent; }

/* ---- Maps ------------------------------------------------- */
.map-frame {
  background-color: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.map-caption {
  font-size: 0.88rem;
  font-style: italic;
  color: var(--text-dim);
  margin: 0.5rem 0.15rem 0;
}

.mapboxgl-ctrl-group {
  border-radius: 0.3em;
  box-shadow: var(--shadow) !important;
}

.mapboxgl-ctrl-attrib a:hover { padding: 0; }

/* mapgl legend */
.mapboxgl-legend,
.mapgl-legend,
.legend {
  background-color: rgba(252, 252, 251, 0.96) !important;
  color: var(--text) !important;
  border: none !important;
  border-top: solid var(--green) 0.4em !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
  font-family: var(--font-ui) !important;
  font-size: 0.86rem !important;
  font-variant-numeric: tabular-nums;
  /* equal padding on all sides, so the bar and labels sit inside an even margin */
  padding: 0.75rem 1rem 0.7rem !important;
  /* !important beats the width mapgl sets inline */
  width: 340px !important;
  max-width: calc(100% - 20px) !important;   /* never wider than the map on small screens */
  box-sizing: border-box !important;
  /* sit above the Mapbox logo instead of on top of it */
  margin-bottom: 34px !important;
}

/* every child (title, bar, labels) spans the same inner width, flush left */
.mapboxgl-legend > *,
.mapgl-legend > *,
.legend > * {
  box-sizing: border-box !important;
  max-width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.mapboxgl-legend h2,
.mapgl-legend h2,
.legend h2,
.legend-title {
  font-family: var(--font-ui) !important;
  color: var(--teal) !important;
  font-size: 0.9rem !important;
  font-weight: 700 !important;
  line-height: 1.3 !important;
  margin: 0 0 0.5rem !important;
  padding: 0 !important;
}

/* color bar */
.mapboxgl-legend .legend-gradient,
.mapgl-legend .legend-gradient,
.legend .legend-gradient {
  width: 100% !important;
  height: 12px !important;
  margin: 0 !important;
  border-radius: 2px !important;
}

/* tick labels: mapgl centers each label on its stop, which pushes the first
   and last labels past the ends of the bar. Laying them out as a flex row
   pins the end labels to the bar's ends and spaces the rest evenly. */
.mapboxgl-legend .legend-labels,
.mapgl-legend .legend-labels,
.legend .legend-labels {
  position: static !important;
  display: flex !important;
  justify-content: space-between !important;
  width: 100% !important;
  height: auto !important;
  margin: 0.3rem 0 0 !important;
  padding: 0 !important;
  font-size: 0.8rem !important;
  color: var(--text-muted) !important;
}

.mapboxgl-legend .legend-labels > *,
.mapgl-legend .legend-labels > *,
.legend .legend-labels > * {
  position: static !important;
  left: auto !important;
  transform: none !important;
  white-space: nowrap;
}

.mapboxgl-legend .legend-labels > *:first-child,
.mapgl-legend .legend-labels > *:first-child,
.legend .legend-labels > *:first-child { text-align: left; }

.mapboxgl-legend .legend-labels > *:last-child,
.mapgl-legend .legend-labels > *:last-child,
.legend .legend-labels > *:last-child { text-align: right; }

/* hover tooltip */
.mapboxgl-popup-content {
  background-color: var(--surface);
  color: var(--text);
  border-top: solid var(--teal) 0.3em;
  border-radius: 0.3em;
  box-shadow: var(--shadow);
  font-family: var(--font-ui);
  font-size: 0.92rem;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  padding: 0.5rem 0.75rem;
}

.mapboxgl-popup-content strong { color: var(--teal); }

.tip-meta {
  color: var(--text-dim);
  font-size: 0.82rem;
}

/* ---- Tables (matches the companion app's table look) ------ */
.table-section { margin-top: 2rem; }

.table-scroll {
  max-height: 32rem;
  overflow: auto;
  background-color: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.table-scroll-tall { max-height: 40rem; }

.table,
.shiny-table {
  width: 100%;
  margin: 0;
  background-color: var(--bg);
  color: var(--text);
  border-collapse: collapse;
  font-size: 0.95rem;
}

thead,
.table > thead > tr > th,
.shiny-table thead th {
  background-color: var(--bg);
  color: var(--teal);
}

.table > thead > tr > th,
.shiny-table thead th {
  position: sticky;   /* header stays visible while scrolling */
  top: 0;
  z-index: 1;
  font-weight: 700;
  padding: 0.65rem 0.9rem;
  border: none;
  border-bottom: 2px solid var(--teal);
  white-space: nowrap;
}

.table > tbody > tr > td,
.shiny-table tbody td {
  padding: 0.5rem 0.9rem;
  border: none;
  border-bottom: 1px solid rgba(40, 70, 94, 0.1);
}

.table > tbody > tr:hover > td,
.shiny-table tbody tr:hover td {
  background-color: var(--panel);
  font-weight: 700;
}

/* numeric columns */
.table td[align="right"],
.table th[align="right"],
.shiny-table td[align="right"],
.shiny-table th[align="right"] {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ---- Footer: full-width teal band (matches #homepage-footer) */
.app-footer {
  background-color: var(--teal);
  color: #ffffff;
  text-align: center;
  font-size: 1rem;
  padding: 1em 1.5em 2em;
  margin-top: 3rem;
  /* stretch past the page container to the window edges */
  width: 100vw;
  margin-left: calc(50% - 50vw);
}

.app-footer p {
  max-width: 60rem;
  margin: 0 auto;
}

.app-footer strong { color: var(--green); }

/* ---- Shiny states ----------------------------------------- */
.recalculating {
  opacity: 0.5;
  transition: opacity 0.2s ease;
}

.shiny-output-error { color: #9b2c2c; }

.shiny-output-error-validation {
  color: var(--text-dim);
  font-style: italic;
}

.shiny-notification {
  border-left: 4px solid var(--teal);
  border-radius: 0.3em;
  box-shadow: var(--shadow);
  opacity: 1;
}

/* ---- Responsive ------------------------------------------- */
@media (max-width: 992px) {
  .container-fluid { padding: 0 1rem; }
  .app-title { font-size: 24px; }
  .nav-tabs { justify-content: flex-start; }
}

/* ---- Print ------------------------------------------------ */
@media print {
  .control-panel, .map-frame, .table-scroll { box-shadow: none; }
  .table-scroll { max-height: none; overflow: visible; }
  .nav-tabs { display: none; }
}

/* ---- Housing scenario tab ---------------------------------- */

/* numbered step labels in the inputs panel */
.scenario-step {
  font-weight: 700;
  color: var(--teal);
  margin: 1.1rem 0 0.4rem;
}
.control-panel > .scenario-step:first-child { margin-top: 0; }

/* the one filled button in the app */
#run_housing_scenario {
  background-color: var(--teal);
  border: 1px solid var(--teal);
  color: #ffffff;
  font-weight: 700;
  padding: 0.6em 1em;
  border-radius: var(--radius);
  margin-top: 0.5rem;
}
#run_housing_scenario:hover,
#run_housing_scenario:focus {
  background-color: var(--teal-dark);
  border-color: var(--teal-dark);
  color: #ffffff;
}

/* side panels that scroll on their own, level with the map, instead of the whole page */
.scroll-panel {
  max-height: 78vh;
  overflow-y: auto;
  scrollbar-width: thin;                               /* Firefox */
  scrollbar-color: var(--border-strong) transparent;
}
.scroll-panel::-webkit-scrollbar { width: 6px; }       /* Chrome, Edge, Safari */
.scroll-panel::-webkit-scrollbar-track { background: transparent; }
.scroll-panel::-webkit-scrollbar-thumb {
  background-color: var(--border-strong);
  border-radius: 3px;
}
.scroll-panel::-webkit-scrollbar-thumb:hover { background-color: var(--text-dim); }

/* one card per result */
.result-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.75rem;
}
.result-card-title {
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.25rem;
}
.result-warning { color: #a14a00; }

/* expandable "How does this work?" explanation */
.explainer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0 0 1.25rem;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text-muted);
}
.explainer > summary {
  cursor: pointer;
  list-style: none;            /* hide the default triangle; ours is below */
  padding: 0.55rem 0.85rem;
  font-weight: 700;
  color: var(--teal);
}
.explainer > summary::-webkit-details-marker { display: none; }
.explainer > summary::before {
  content: "\25B8";           /* small right-pointing triangle */
  display: inline-block;
  margin-right: 0.45rem;
  transition: transform 0.15s ease;
}
.explainer[open] > summary::before { transform: rotate(90deg); }
.explainer > summary:hover { color: var(--teal-dark); }
.explainer > p {
  margin: 0 0.85rem 0.6rem;
}
.explainer > p:last-child { margin-bottom: 0.8rem; }
.explainer-note {
  font-size: 0.85rem;
  font-style: italic;
  color: var(--text-dim);
}
.explainer-note em { font-style: normal; font-weight: 600; }

/* results header: title on the left, view switch on the right */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
}
.results-toggle,
.results-toggle:hover,
.results-toggle:focus {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  font-weight: 700;
  color: var(--teal);
}
.results-toggle:hover { color: var(--teal-dark); text-decoration: underline; }

/* which switch shows: "Edit scenario" in the results view,
   "Expand results" in the inputs view once there are results */
.housing-layout .edit-toggle,
.housing-layout .expand-toggle { display: none; }
.housing-layout.results-mode .edit-toggle { display: inline-block; }
.housing-layout.has-results:not(.results-mode) .expand-toggle { display: inline-block; }

/* results view: inputs hidden, map and results share the width (7 + 5 of 12) */
@media (min-width: 768px) {
  .housing-layout.results-mode .housing-inputs-col { display: none; }
  .housing-layout.results-mode .housing-map-col {
    width: 58.333%;
    flex: 0 0 58.333%;
    max-width: 58.333%;
  }
  .housing-layout.results-mode .housing-results-col {
    width: 41.667%;
    flex: 0 0 41.667%;
    max-width: 41.667%;
  }
}
/* result cards stack one per row */
.result-list { margin-bottom: 0.75rem; }
.results-note { margin-bottom: 0.5rem; }
.results-note + .result-list { margin-top: 0.75rem; }

/* keep each number on one line (labels wrap instead) */
.result-card .stat-value {
  white-space: nowrap;
  overflow-wrap: normal;
}

/* findings rows: shaded like a small table, set apart from the explanatory text */
.result-card .stat-row {
  background: rgba(0, 84, 117, 0.07);    /* light tint of the brand teal */
  border-bottom: none;
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  margin: 0 0 3px;
}
.result-card .stat-row + .help-text,
.result-card .help-text + .stat-row { margin-top: 0.6rem; }
.result-card .result-card-title { margin-bottom: 0.5rem; }

#download_housing_scenario {
  width: 100%;
  margin-top: 0.5rem;
}