/* SPDX-FileCopyrightText: 2026 The Royal College of Paediatrics and Child Health
   SPDX-License-Identifier: LGPL-3.0-or-later */

/* ============================================================
   Demo harness chrome - demo.css
   Styles ONLY for the demonstration shell (left sidebar + scenario picker).
   The chart itself is styled entirely by styles.css; nothing here changes the
   chart's appearance. Everything is scoped under body.demo so it can never leak
   into a real embedding of the chart component.
   ============================================================ */

body.demo {
  --demo-sidebar-w: 320px;
  --demo-controls-w: 268px;
  --demo-controls-w-collapsed: 46px;
  --demo-playback-h: 0px;
}

.demo-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

/* --- Sidebar -------------------------------------------------- */
.demo-sidebar {
  flex: 0 0 var(--demo-sidebar-w);
  width: var(--demo-sidebar-w);
  background: var(--section-label-bg); /* follows the active chart theme */
  color: #ffffff;
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.demo-sidebar__brand {
  padding: 1.25rem 1.25rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

/* White card so the full-colour RCPCH logo reads on any theme background. */
.demo-logo {
  background: #ffffff;
  border-radius: 6px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.demo-logo img {
  display: block;
  width: 100%;
  max-width: 220px;
  height: auto;
}

.demo-sidebar__title {
  font-size: 1.25rem;
  font-weight: 900;
  line-height: 1.2;
  margin: 0;
}

.demo-sidebar__subtitle {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.8);
  margin: 0.35rem 0 0;
}

.demo-sidebar__heading {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.7);
  padding: 1rem 1.25rem 0.35rem;
  margin: 0;
}

.scenario-list {
  list-style: none;
  margin: 0;
  padding: 0 0.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.scenario {
  display: block;
  width: 100%;
  text-align: left;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-left: 4px solid transparent;
  border-radius: 4px;
  padding: 0.6rem 0.75rem;
  color: #ffffff;
  font-family: inherit;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.scenario:hover {
  background: rgba(255, 255, 255, 0.14);
}

.scenario:focus-visible {
  outline: 3px solid var(--focus-ring, #ffdd00);
  outline-offset: 2px;
}

.scenario--active {
  background: rgba(255, 255, 255, 0.18);
  border-left-color: var(--focus-ring, #ffdd00);
}

.scenario__title {
  display: block;
  font-weight: 700;
  font-size: 0.95rem;
}

.scenario__band {
  display: inline-block;
  margin-top: 0.3rem;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--param-label-bg); /* follows the active chart theme */
  color: #ffffff;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
}

.scenario__desc {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.78rem;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.85);
}

.demo-sidebar__foot {
  margin-top: auto;
  padding: 1rem 1.25rem;
  font-size: 0.72rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.7);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}

/* --- Main (chart) region ------------------------------------- */
.demo-main {
  flex: 1 1 auto;
  min-width: 0; /* allow canvases to shrink instead of forcing overflow */
}

.demo-triggers {
  border: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0.4rem 1rem 0.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 1.25rem;
}

.demo-triggers__legend {
  flex: 1 0 100%;
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.demo-trigger {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8125rem;
}

.demo-trigger__toggle,
.demo-trigger__level {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.demo-trigger input,
.demo-trigger select {
  font: inherit;
  accent-color: var(--param-label-bg);
}

.demo-trigger select {
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface);
  color: var(--text-primary);
  padding: 0.15rem 0.25rem;
}

.demo-trigger :focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

.demo-triggers__note {
  flex: 1 0 100%;
  color: var(--text-secondary);
  font-size: 0.7rem;
}

/* --- Right controls sidebar (foldable) ----------------------- */
.demo-controls {
  flex: 0 0 var(--demo-controls-w);
  width: var(--demo-controls-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
  transition: flex-basis 0.15s ease, width 0.15s ease;
}

.demo-controls--collapsed {
  flex-basis: var(--demo-controls-w-collapsed);
  width: var(--demo-controls-w-collapsed);
}

.demo-controls__toggle {
  width: 100%;
  height: 46px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--section-label-bg);
  color: #ffffff;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.9rem;
}

.demo-controls__toggle:focus-visible {
  outline: 3px solid var(--focus-ring, #ffdd00);
  outline-offset: -3px;
}

.demo-controls__toggle-icon {
  font-size: 1.3rem;
  line-height: 1;
  transition: transform 0.15s ease;
}

/* Chevron points right when expanded (to fold away), left when collapsed. */
.demo-controls--collapsed .demo-controls__toggle-icon {
  transform: rotate(180deg);
}

.demo-controls--collapsed .demo-controls__toggle {
  justify-content: center;
  padding: 0;
}

.demo-controls--collapsed .demo-controls__toggle-label,
.demo-controls--collapsed .demo-controls__body {
  display: none;
}

.demo-controls__body {
  padding: 0.95rem 0.9rem 1.2rem;
}

.demo-controls__heading {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-secondary);
  margin: 0 0 0.6rem;
}

.demo-controls__heading--spaced {
  margin-top: 1.25rem;
}

.demo-display-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
}

.demo-display-option input {
  accent-color: var(--param-label-bg);
  margin: 0;
}

.demo-display-option:focus-within {
  outline: 3px solid var(--focus-ring, #ffdd00);
  outline-offset: 3px;
}

.theme-options {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--page-bg);
  cursor: pointer;
  transition: border-color 0.12s ease;
}

.theme-option:hover {
  border-color: var(--param-label-bg);
}

.theme-option:focus-within {
  outline: 3px solid var(--focus-ring, #ffdd00);
  outline-offset: 1px;
}

.theme-option input {
  accent-color: var(--param-label-bg);
  margin: 0;
}

.theme-option__swatch {
  display: inline-flex;
  gap: 2px;
  flex: 0 0 auto;
}

.theme-option__swatch i {
  display: block;
  width: 12px;
  height: 18px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.theme-option__label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
}

.demo-controls__note {
  margin-top: 0.85rem;
  font-size: 0.7rem;
  line-height: 1.45;
  color: var(--text-secondary);
}

/* The chart's sticky footer is position:fixed across the viewport; shift it so
   it aligns with the chart region rather than sitting under either sidebar. */
body.demo .sticky-footer {
  bottom: var(--demo-playback-h);
  left: var(--demo-sidebar-w);
  right: var(--demo-controls-w);
}

body.demo.demo--controls-collapsed .sticky-footer {
  right: var(--demo-controls-w-collapsed);
}

body.demo .main-content {
  padding-bottom: calc(5rem + var(--demo-playback-h));
}

/* --- Narrow screens: stack sidebar above the chart ----------- */
@media (max-width: 900px) {
  .demo-shell {
    flex-direction: column;
  }
  .demo-sidebar,
  .demo-controls {
    flex-basis: auto;
    width: 100%;
    height: auto;
    position: static;
  }
  .demo-controls {
    border-left: none;
    border-top: 1px solid var(--border);
    order: 3;
  }
  body.demo .sticky-footer,
  body.demo.demo--controls-collapsed .sticky-footer {
    left: 0;
    right: 0;
  }
  body.demo .playback,
  body.demo.demo--controls-collapsed .playback {
    left: 0;
    right: 0;
  }
  .demo-triggers { align-items: flex-start; }
}

/* --- Observation playback (demo only) ------------------------- */
body.demo {
  --demo-scrub: #00a3e0;
}

.playback[hidden] { display: none; }

.playback {
  box-sizing: border-box;
  position: fixed;
  bottom: 0;
  left: var(--demo-sidebar-w);
  right: var(--demo-controls-w);
  z-index: 201;
  background: var(--surface);
  border-top: 3px solid var(--demo-scrub);
  padding: 0.55rem 1rem 0.65rem;
  display: grid;
  grid-template-columns: minmax(15rem, auto) minmax(16rem, 1fr);
  gap: 0.5rem 1.25rem;
  align-items: center;
}

.demo--controls-collapsed .playback {
  right: var(--demo-controls-w-collapsed);
}

.playback__summary,
.playback__control {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.playback__label {
  color: var(--text-primary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.playback__readout {
  color: var(--text-secondary);
  font-size: 0.8125rem;
  line-height: 1.3;
}

.playback__readout strong {
  color: var(--text-primary);
}

.playback__readout .esc-badge {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-left: 0.35rem;
}

.playback__control {
  justify-content: center;
}

.playback__slider {
  width: 100%;
  margin: 0;
  cursor: pointer;
  accent-color: var(--demo-scrub);
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
}

.playback__slider:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

.playback__slider:disabled {
  cursor: default;
  opacity: 0.6;
}

.playback__slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--demo-scrub);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.2);
  cursor: pointer;
}

.playback__slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--demo-scrub);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.2);
  cursor: pointer;
}

.playback__hint {
  color: var(--text-secondary);
  font-size: 0.7rem;
  text-align: right;
}

@media (max-width: 600px) {
  .playback {
    grid-template-columns: 1fr;
    gap: 0.4rem;
  }

  .playback__hint {
    text-align: left;
  }
}
