/* Child Vulnerability Index — CfYL brand overrides
   Injected by the Cloudflare Worker. Matches centreforyounglives.org.uk */

:root {
  --cfyl-charcoal: #333333;
  --cfyl-watermelon: #ff4c5e;
  --cfyl-watermelon-hover: #8b121e;
  --cfyl-barley: #fff6d2;
  --cfyl-barley-hover: #e6dbb1;
  --cfyl-serif: "Roboto Serif", Georgia, serif;
  --cfyl-display: "Big Shoulders Display", "Arial Narrow", sans-serif;
}

/* ---------- Dash's own colours ---------- */
/* Dash draws focus rings, selected tabs, tick boxes and dropdown highlights from these
   settings. Out of the box they're purple with navy-tinted greys, so point them at CfYL colours. */
html:root {
  --Dash-Fill-Interactive-Strong: #ff4c5e !important;
  --Dash-Fill-Interactive-Weak: #fff6d2 !important;
  --Dash-Fill-Primary-Hover: #fff6d2 !important;
  --Dash-Fill-Primary-Active: #ffe4e7 !important;
  --Dash-Fill-Disabled: rgba(51, 51, 51, 0.08) !important;
  --Dash-Stroke-Strong: rgba(51, 51, 51, 0.4) !important;
  --Dash-Stroke-Weak: rgba(51, 51, 51, 0.12) !important;
  --Dash-Text-Primary: #333333 !important;
  --Dash-Text-Strong: #222222 !important;
  --Dash-Text-Weak: #616161 !important;
  --Dash-Text-Disabled: #8a8a8a !important;
}

/* Keyboard focus and text selection in brand colours (some browsers default to blue) */
#react-entry-point a:focus-visible,
#react-entry-point button:focus-visible,
#react-entry-point input:focus-visible,
#react-entry-point .tab:focus-visible,
.cvi-swipe-hint:focus-visible {
  outline: 2px solid var(--cfyl-watermelon) !important;
  outline-offset: 2px;
}
::selection {
  background: #ffd1d6;
  color: var(--cfyl-charcoal);
}

/* ---------- Base type ---------- */
body,
#react-entry-point,
#react-entry-point * {
  font-family: var(--cfyl-serif) !important;
}
html,
body {
  margin: 0 !important;
}
body {
  color: var(--cfyl-charcoal) !important;
  background: #fff !important;
  line-height: 1.5;
}

/* ---------- Headings ---------- */
#react-entry-point h1 {
  font-family: var(--cfyl-display) !important;
  font-weight: 700 !important;
  text-transform: uppercase;
  color: var(--cfyl-watermelon) !important;
  font-size: clamp(36px, 5vw, 50px) !important;
  line-height: 1 !important;
  letter-spacing: 0.01em;
}
#react-entry-point h2 {
  font-weight: 700 !important;
  color: var(--cfyl-charcoal) !important;
  line-height: 1.25 !important;
}
#react-entry-point h3 {
  font-weight: 700 !important;
  color: var(--cfyl-charcoal) !important;
}

/* ---------- Tabs ---------- */
#dashboard-tabs .tab {
  display: flex !important;
  align-items: center;
  justify-content: center;
  font-family: var(--cfyl-display) !important;
  font-weight: 700 !important;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--cfyl-charcoal) !important;
  background: var(--cfyl-barley) !important;
  border-color: var(--cfyl-barley) !important;
  transition: background 0.2s, color 0.2s;
}
#dashboard-tabs .tab * {
  font-family: var(--cfyl-display) !important;
  font-weight: 700 !important;
  font-size: 20px !important;
  color: inherit !important;
  background: transparent !important;
}
#dashboard-tabs .tab:hover {
  background: var(--cfyl-barley-hover) !important;
}
#dashboard-tabs .tab--selected {
  background: #fff !important;
  color: var(--cfyl-watermelon) !important;
  border-top: 4px solid var(--cfyl-watermelon) !important;
}

/* ---------- Inputs & dropdowns ---------- */
.dash-input-element,
.dash-dropdown,
.dash-dropdown-trigger {
  border-radius: 8px !important;
}
.dash-input,
.dash-dropdown {
  border-color: #c9c9c9 !important;
}
.dash-input:focus-within,
.dash-dropdown:focus-within {
  border-color: var(--cfyl-watermelon) !important;
  box-shadow: 0 0 0 2px rgba(255, 76, 94, 0.2) !important;
  outline: none !important;
}
.dash-dropdown-content {
  border-radius: 8px !important;
  border-color: #c9c9c9 !important;
}
.dash-dropdown-search-container {
  border-color: #c9c9c9 !important;
  border-radius: 6px !important;
}
.dash-dropdown-option:hover,
.dash-options-list-option:hover {
  background: var(--cfyl-barley) !important;
}
#react-entry-point label {
  font-weight: 700 !important;
}
.dash-options-list label,
.dash-options-list * {
  font-weight: 400 !important;
}

/* ---------- Download buttons ---------- */
/* Targeted by id: the dropdowns are also <button> elements */
#react-entry-point button[id*="download"] {
  font-family: var(--cfyl-display) !important;
  font-weight: 700 !important;
  text-transform: uppercase;
  font-size: 16px !important;
  letter-spacing: 0.02em;
  color: #fff !important;
  background: var(--cfyl-watermelon) !important;
  border: 0 !important;
  border-radius: 40px !important;
  padding: 10px 22px !important;
  transition: background 0.2s;
}
#react-entry-point button[id*="download"]:hover {
  background: var(--cfyl-watermelon-hover) !important;
}

/* ---------- Other buttons (Compare tab) ---------- */
#react-entry-point button[id$="-button"] {
  font-family: var(--cfyl-display) !important;
  font-weight: 700 !important;
  text-transform: uppercase;
  font-size: 16px !important;
  letter-spacing: 0.02em;
  color: #fff !important;
  background: var(--cfyl-watermelon) !important;
  border: 2px solid var(--cfyl-watermelon) !important;
  border-radius: 40px !important;
  padding: 8px 20px !important;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
#react-entry-point button[id$="-button"]:hover {
  background: var(--cfyl-watermelon-hover) !important;
  border-color: var(--cfyl-watermelon-hover) !important;
}
/* "Cancel" and "Refresh" are secondary actions, so they're outlined */
#react-entry-point button[id$="-cancel-button"],
#react-entry-point button[id$="-refresh-button"] {
  color: var(--cfyl-charcoal) !important;
  background: #fff !important;
  border-color: var(--cfyl-charcoal) !important;
}
#react-entry-point button[id$="-cancel-button"]:hover,
#react-entry-point button[id$="-refresh-button"]:hover {
  color: #fff !important;
  background: var(--cfyl-charcoal) !important;
}
#react-entry-point button[id$="-button"]:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Tick boxes and radio buttons in brand colour */
#react-entry-point input[type="checkbox"],
#react-entry-point input[type="radio"],
.dash-options-list input[type="checkbox"] {
  accent-color: var(--cfyl-watermelon) !important;
}

/* ---------- Links ---------- */
._dash-undo-redo-link {
  color: var(--cfyl-watermelon) !important;
}
#react-entry-point a {
  color: var(--cfyl-charcoal) !important;
  text-decoration: underline;
  text-decoration-color: var(--cfyl-watermelon);
  text-underline-offset: 3px;
}
#react-entry-point a:hover {
  color: var(--cfyl-watermelon) !important;
}

/* ---------- Info notice & stat cards ---------- */
#react-entry-point div[style*="border-left: 4px solid"] {
  color: var(--cfyl-charcoal) !important;
  border-left-color: var(--cfyl-watermelon) !important;
  border-radius: 0 8px 8px 0;
}
#react-entry-point div[style*="font-size: 34px"] {
  font-family: var(--cfyl-display) !important;
  font-size: 44px !important;
  line-height: 1 !important;
}

/* ---------- Charts (type only; line and bar colours are set in the app) ---------- */
.js-plotly-plot .main-svg text {
  font-family: var(--cfyl-serif) !important;
}
.js-plotly-plot .main-svg .xtick text,
.js-plotly-plot .main-svg .ytick text,
.js-plotly-plot .main-svg .g-xtitle text,
.js-plotly-plot .main-svg .g-ytitle text,
/* Plotly's default blue-grey text, wherever it appears (colour scales, legends, titles) */
.js-plotly-plot .main-svg text[style*="fill: rgb(42, 63, 95)"] {
  fill: var(--cfyl-charcoal) !important;
}

/* ---------- Logo ---------- */
/* The page around the dashboard already shows the CfYL logo in its nav */
#react-entry-point img[style*="height: 110px"] {
  display: none !important;
}

/* ---------- Loading states ---------- */
/* Dash's "Loading..." placeholder, shown before the dashboard appears */
._dash-loading {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  padding: 14vh 24px;
  font-size: 0 !important;
  color: transparent !important;
}
._dash-loading::before {
  content: "";
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 5px solid var(--cfyl-barley);
  border-top-color: var(--cfyl-watermelon);
  animation: cvi-spin 0.9s linear infinite;
}
._dash-loading::after {
  content: "Loading the Child Vulnerability Index";
  margin-top: 20px;
  font-family: var(--cfyl-display) !important;
  font-weight: 700;
  font-size: 24px;
  text-transform: uppercase;
  color: var(--cfyl-watermelon);
  text-align: center;
}
@keyframes cvi-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  ._dash-loading::before { animation-duration: 3s; }
}

/* ---------- Desktop tabs: a segmented control ---------- */
/* A soft barley track with rounded tabs inside; the selected tab is a solid watermelon pill */
@media (min-width: 801px) {
  .tab-parent > .tab-container {
    display: flex !important;
    gap: 6px;
    padding: 6px;
    background: var(--cfyl-barley);
    border: 0 !important;
    border-radius: 18px;
  }
  #dashboard-tabs .tab {
    flex: 1 1 auto !important;
    width: auto !important;
    min-height: 52px;
    padding: 10px 14px !important;
    border: 0 !important;
    border-radius: 13px !important;
    background: transparent !important;
    color: var(--cfyl-charcoal) !important;
    text-align: center;
    line-height: 1.1;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.2s;
  }
  #dashboard-tabs .tab * {
    font-size: 18px !important;
    letter-spacing: 0.03em;
  }
  #dashboard-tabs .tab:hover {
    background: rgba(255, 255, 255, 0.7) !important;
  }
  #dashboard-tabs .tab--selected,
  #dashboard-tabs .tab--selected:hover {
    background: var(--cfyl-watermelon) !important;
    color: #fff !important;
    border-top: 0 !important;
    box-shadow: 0 6px 16px rgba(255, 76, 94, 0.28);
  }
  #dashboard-tabs .tab:active {
    transform: scale(0.98);
  }
}

/* Swipe hint for the tab row only appears on small screens */
.cvi-swipe-hint {
  display: none;
}

/* ---------- Mobile (phones and small tablets) ---------- */
@media (max-width: 800px) {

  /* Headings sized for small screens */
  #react-entry-point h1 {
    font-size: 38px !important;
    margin: 8px 0 18px !important;
  }
  #react-entry-point h2 {
    font-size: 21px !important;
  }
  #react-entry-point h3 {
    font-size: 17px !important;
  }

  /* Tabs: one swipeable row of pills instead of a tall stack */
  .tab-parent {
    overflow: visible !important;
  }
  #dashboard-tabs.tab-container,
  .tab-parent > .tab-container {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 32px 12px 0;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    -webkit-mask-image: linear-gradient(to right, #000 88%, transparent);
    mask-image: linear-gradient(to right, #000 88%, transparent);
  }
  .tab-parent > .tab-container::-webkit-scrollbar {
    display: none;
  }
  #dashboard-tabs .tab {
    flex: 0 0 auto !important;
    width: auto !important;
    padding: 10px 18px !important;
    border: 0 !important;
    border-radius: 40px !important;
    scroll-snap-align: start;
  }
  #dashboard-tabs .tab * {
    font-size: 17px !important;
    white-space: nowrap;
  }
  #dashboard-tabs .tab--selected {
    background: var(--cfyl-watermelon) !important;
    color: #fff !important;
    border-top: 0 !important;
  }

  /* Swipe hint: a small arrow at the end of the tab row (added by the mobile script) */
  .tab-parent {
    position: relative !important;
  }
  .cvi-swipe-hint {
    position: absolute;
    top: 2px;
    right: -4px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 46px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    transition: opacity 0.25s;
    -webkit-tap-highlight-color: transparent;
  }
  .cvi-swipe-hint span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--cfyl-watermelon);
    color: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
    animation: cvi-nudge 1.4s ease-in-out 0.6s 3;
  }
  .cvi-swipe-hint svg {
    width: 16px;
    height: 16px;
  }
  .cvi-swipe-hint.is-hidden {
    opacity: 0;
    pointer-events: none;
  }
  /* Once the last tab is reached, stop fading the end of the row */
  .tab-parent > .tab-container.cvi-at-end {
    -webkit-mask-image: none;
    mask-image: none;
  }
  @keyframes cvi-nudge {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(5px); }
  }
  @media (prefers-reduced-motion: reduce) {
    .cvi-swipe-hint span { animation: none; }
  }

  /* National tab: stats and chart stacked, so the chart gets the full width */
  #react-entry-point div[style*="grid-template-columns: 260px"] {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 16px !important;
  }

  /* Compare tab: show comparison A, then comparison B, instead of two narrow columns */
  #react-entry-point div[style*="grid-template-columns: minmax(0px, 1fr) minmax(0px, 1fr)"] {
    grid-template-columns: minmax(0, 1fr) !important;
    row-gap: 8px;
  }
  #react-entry-point div[style*="grid-template-columns: minmax(0px, 1fr) minmax(0px, 1fr)"] > [style*="grid-area: 1 / 1"] { grid-area: auto !important; order: 1; }
  #react-entry-point div[style*="grid-template-columns: minmax(0px, 1fr) minmax(0px, 1fr)"] > [style*="grid-area: 2 / 1"] { grid-area: auto !important; order: 2; margin-bottom: 24px; }
  #react-entry-point div[style*="grid-template-columns: minmax(0px, 1fr) minmax(0px, 1fr)"] > [style*="grid-area: 1 / 2"] { grid-area: auto !important; order: 3; }
  #react-entry-point div[style*="grid-template-columns: minmax(0px, 1fr) minmax(0px, 1fr)"] > [style*="grid-area: 2 / 2"] { grid-area: auto !important; order: 4; }

  /* Source line and download buttons are indented to line up with the chart on desktop */
  #react-entry-point [style*="padding-left"] {
    padding-left: 0 !important;
  }

  /* Bigger, easier buttons */
  #react-entry-point button[id*="download"],
  #react-entry-point button[id$="-button"] {
    min-height: 44px;
    margin: 0 8px 8px 0 !important;
  }

  /* Form fields: 16px text stops iPhones zooming in, and taller fields are easier to tap */
  #react-entry-point input,
  .dash-input-element,
  .dash-dropdown-search {
    font-size: 16px !important;
  }
  .dash-input-element,
  .dash-dropdown-trigger {
    min-height: 44px;
  }
  /* Long indicator names wrap in the dropdown list instead of being cut off */
  .dash-options-list-option,
  .dash-options-list-option-text {
    white-space: normal !important;
    line-height: 1.35 !important;
  }
  .dash-options-list-option {
    padding-top: 8px !important;
    padding-bottom: 8px !important;
  }

  /* Big stat figure */
  #react-entry-point div[style*="font-size: 34px"] {
    font-size: 40px !important;
  }

  /* Tables become a stack of cards: one card per row, with each value labelled */
  #react-entry-point table,
  #react-entry-point tbody,
  #react-entry-point tr,
  #react-entry-point td {
    display: block !important;
    width: 100% !important;
    box-sizing: border-box;
  }
  #react-entry-point thead {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  #react-entry-point tbody tr {
    margin-bottom: 12px;
    padding: 12px 14px !important;
    border: 1px solid var(--cfyl-barley-hover) !important;
    border-radius: 8px;
    background: #fff;
  }
  #react-entry-point tbody td {
    padding: 4px 0 !important;
    border: 0 !important;
  }
  #react-entry-point tbody td:first-child {
    font-weight: 700 !important;
    font-size: 16px !important;
  }
  #react-entry-point tbody td[data-label]:not(:first-child)::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--cfyl-charcoal-hover, #616161);
  }

  /* Chart toolbar isn't useful on touch screens */
  .js-plotly-plot .modebar-container {
    display: none !important;
  }
}
