.theme-toggle {
  position: absolute;
  top: 34px;
  right: 22px;
  width: 68px;
  height: 36px;
  padding: 0;
  border: 1px solid #ffffff2b;
  border-radius: 999px;
  background: #ffffff0d;
  color: #d3e3e5;
  box-shadow: inset 0 1px 0 #ffffff15;
  z-index: 5;
}
.theme-toggle-track {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
}
.theme-toggle svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  z-index: 1;
  transition:
    color 240ms ease,
    transform 350ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.theme-toggle-thumb {
  position: absolute;
  left: 3px;
  top: 3px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(145deg, #fff9df, #f7d96e);
  box-shadow:
    0 3px 12px #00000035,
    inset 0 1px 0 #fff;
  transition:
    transform 380ms cubic-bezier(0.2, 0.9, 0.25, 1.15),
    background 250ms ease,
    box-shadow 250ms ease;
}
.theme-sun {
  color: #7b6512;
}
.theme-moon {
  color: #9db3ba;
}
html[data-theme='dark'] .theme-toggle-thumb {
  transform: translateX(32px);
  background: linear-gradient(145deg, #d9e7ff, #8fa9d8);
  box-shadow:
    0 3px 14px #0008,
    inset 0 1px 0 #fff9;
}
html[data-theme='dark'] .theme-sun {
  color: #71828a;
  transform: rotate(-45deg) scale(0.9);
}
html[data-theme='dark'] .theme-moon {
  color: #26334d;
  transform: rotate(8deg) scale(1.05);
}
.theme-toggle:hover {
  border-color: #78bdb7;
  background: #ffffff16;
}
.theme-toggle:focus-visible {
  outline: 3px solid #65c9c2;
  outline-offset: 3px;
}

html[data-theme='dark'] {
  --teal: #5fc9c1;
  --ui-accent: #5fc9c1;
  --line: #334852;
  --muted: #a8bac3;
  --bg: #0e1921;
  --surface: #17252e;
  --ink: #e9f1f3;
  color-scheme: dark;
  color: var(--ink);
  background: var(--bg);
}
html[data-theme='dark'] body {
  color: var(--ink);
  background:
    radial-gradient(ellipse at 90% 0, #174c5038, transparent 47%),
    radial-gradient(ellipse at 10% 75%, #17464b24, transparent 43%), #0e1921;
}
html[data-theme='dark'] body::before {
  background: linear-gradient(115deg, transparent 34%, #c8fffa08 49%, transparent 64%);
}
html[data-theme='dark'] .sidebar {
  background:
    radial-gradient(ellipse at 0 0, #1d4b50 0, transparent 57%), linear-gradient(170deg, #101f2a, #09131c 85%);
  border-right-color: #79c9c229;
}
html[data-theme='dark'] .workspace,
html[data-theme='dark'] main,
html[data-theme='dark'] footer {
  color: var(--ink);
}
html[data-theme='dark'] main h1,
html[data-theme='dark'] main h2,
html[data-theme='dark'] main h3,
html[data-theme='dark'] main h4,
html[data-theme='dark'] legend,
html[data-theme='dark'] label,
html[data-theme='dark'] strong {
  color: #edf5f6;
}
html[data-theme='dark'] main:has(#overview-search) h1 {
  background: linear-gradient(100deg, #f1f7f8 15%, #83dbd4 68%, #48a9a4);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
html[data-theme='dark'] :is(p, small, .meta, .si-meta, .pv-hint, .atb-meta, .dm-caption, .ph-subtitle) {
  color: #a8bac3;
}
html[data-theme='dark'] a {
  color: #75d5cd;
}
html[data-theme='dark'] #overview-search,
html[data-theme='dark'] .search,
html[data-theme='dark'] .catalog-toolbar,
html[data-theme='dark'] .context-links {
  color: #c8d6dc;
  background: linear-gradient(125deg, #172832, #14232c);
  border-color: #344b55;
  box-shadow:
    inset 0 1px 0 #ffffff09,
    0 10px 28px #0003;
}
html[data-theme='dark'] #overview-search:hover {
  border-color: #5ba9a3;
  box-shadow: 0 12px 32px #0005;
}
html[data-theme='dark']
  #main
  :is(
    a.si-card,
    a.card,
    a.pv-entry,
    a.atb-card,
    a.ref-specialty,
    .ph-bi-list a,
    .panel,
    .si-box,
    .pv-box,
    .pv-screen,
    .ph-bi-card,
    .ref-section,
    .atb-inputs,
    .atb-output,
    .atb-regimen,
    .score-card,
    .wh-card,
    .wh-care-card,
    .wh-method-card,
    .wh-category,
    .wh-condition-fieldset,
    .si-age-disclosure,
    .si-table-wrap,
    .result-panel,
    .question,
    details
  ) {
  color: #e6eff1;
  background: linear-gradient(135deg, #192a33, #15232c);
  border-color: #334953;
  box-shadow:
    inset 0 1px 0 #ffffff08,
    0 7px 22px #0002;
}
html[data-theme='dark'] #main .home-access-grid > :first-child.si-card,
html[data-theme='dark'] #main .home-access-grid > :first-child a.si-card {
  background:
    radial-gradient(ellipse at 110% -20%, #5fc9c145, transparent 65%),
    linear-gradient(135deg, #16454a, #102e35 85%);
  border-color: #477d7b;
}
html[data-theme='dark'] #main .home-access-grid a.si-card :is(h2, h3) {
  color: #eef6f7;
}
html[data-theme='dark'] #main .home-access-grid a.si-card p {
  color: #aabdc5;
}
html[data-theme='dark'] #main .home-access-grid .si-icon {
  background: #234048;
  color: #77d4cd;
}
html[data-theme='dark'] #main :is(a.si-card, a.card, a.pv-entry, a.atb-card, a.ref-specialty):hover {
  color: #f2f8f9;
  background: #1d3039;
  border-color: #598982;
  box-shadow:
    0 14px 34px #0005,
    inset 0 1px 0 #ffffff0b;
}
html[data-theme='dark'] :is(input, select, textarea) {
  color: #edf5f6;
  background-color: #101d25;
  border-color: #3c525c;
}
html[data-theme='dark'] :is(input, select, textarea)::placeholder {
  color: #81959e;
}
html[data-theme='dark'] :is(input, select, textarea):focus {
  border-color: #68c9c1;
  box-shadow: 0 0 0 3px #4ebbb322;
}
html[data-theme='dark'] .btn.secondary,
html[data-theme='dark'] .history-navigation .btn,
html[data-theme='dark'] .history-back,
html[data-theme='dark'] .context-links > a,
html[data-theme='dark'] .chip {
  color: #d7e4e7;
  background: #1a2a33;
  border-color: #3a505a;
}
html[data-theme='dark'] .btn.secondary:hover,
html[data-theme='dark'] .history-navigation .btn:hover,
html[data-theme='dark'] .history-back:hover,
html[data-theme='dark'] .context-links > a:hover {
  background: #243943;
  border-color: #5b8883;
}
html[data-theme='dark'] table {
  color: #dce7ea;
  border-color: #3a4e57;
}
html[data-theme='dark'] :is(th, thead) {
  color: #eaf2f4;
  background: #21323b !important;
}
html[data-theme='dark'] :is(td, th) {
  border-color: #344a54;
}
html[data-theme='dark'] tbody tr:nth-child(even) {
  background: #ffffff03;
}
html[data-theme='dark'] dialog,
html[data-theme='dark'] .dm-context,
html[data-theme='dark'] .pv-dialog,
html[data-theme='dark'] .atb-dialog {
  color: #e8f1f3;
  background: #17252e;
  border-color: #415761;
  box-shadow: 0 28px 90px #000a;
}
html[data-theme='dark'] dialog::backdrop {
  background: #02070bb8;
}
html[data-theme='dark'] .dm-context header {
  background: #17252e;
}
html[data-theme='dark'] .dm-frame {
  background: #14222a;
  border-color: #344952;
}
html[data-theme='dark'] .dm-frame-controls {
  background: linear-gradient(115deg, #192a33, #14242c);
  border-color: #344952;
}
html[data-theme='dark'] .dm-frame .dm-viewport {
  background-color: #101c23;
  background-image: radial-gradient(#60868030 0.7px, transparent 0.7px);
}
html[data-theme='dark'] #main .dm-frame-controls .dm-rail .btn {
  color: #dce8ea;
  background: #1a2b34;
  border-color: #3b515b;
}
html[data-theme='dark'] #main .dm-frame-controls .dm-map-selector .btn[aria-pressed='true'] {
  color: #edfaf8;
  background: #25413f;
  border-color: #5b918c;
}
html[data-theme='dark'] .dm-node:not(.danger) {
  color: #e8f1f2 !important;
  background: #1d3438 !important;
  border-color: #4e7773 !important;
}
html[data-theme='dark'] .dm-node.goal {
  background: #173c3b !important;
}
html[data-theme='dark'] .dm-node.warm {
  background: #403624 !important;
  border-color: #8c7847 !important;
}
html[data-theme='dark'] .dm-node.decision {
  background: #233b44 !important;
}
html[data-theme='dark'] .dm-node.danger {
  color: #ffe7e8 !important;
  background: #42252a !important;
  border-color: #b65f68 !important;
}
html[data-theme='dark'] .dm-node :is(strong, span, dt, dd) {
  color: inherit;
}
html[data-theme='dark'] .dm-node-number,
html[data-theme='dark'] .dm-number-link {
  color: #e5f3f1;
  background: #2c5b57;
  border-color: #6aa09a;
}
html[data-theme='dark'] .ph-bi-card[data-tone='ok'] {
  background: #162e2a !important;
  border-color: #31594f !important;
}
html[data-theme='dark'] .ph-bi-card[data-tone='caution'] {
  background: #332d1d !important;
  border-color: #665631 !important;
}
html[data-theme='dark'] .ph-bi-card[data-tone='danger'] {
  background: #382327 !important;
  border-color: #704149 !important;
}
html[data-theme='dark'] #main .ph-bi-card .ph-bi-status {
  color: #eef5f6;
  background: #293c45;
}
html[data-theme='dark'] #main .ph-bi-card[data-tone='caution'] .ph-bi-status {
  color: #ffe2a1;
  background: #54451f;
}
html[data-theme='dark'] #main .ph-bi-card[data-tone='danger'] .ph-bi-status {
  color: #ffc3c6;
  background: #5a3036;
}
html[data-theme='dark'] :is(.warning, .notice, .pv-warning, .atb-notice, .si-alert) {
  color: #f5dfad;
  background: #382f1d;
  border-color: #6d5b31;
}
html[data-theme='dark'] :is(.danger, .urgent, .red, .atb-urgent) {
  --card-tint: #3c2227;
}
html[data-theme='dark'] hr {
  border-color: #344952;
}
html[data-theme='dark'] footer {
  border-color: #2c4049;
  background: transparent;
}
html[data-theme='dark'] ::selection {
  color: white;
  background: #287f78;
}
html[data-theme='dark'] ::-webkit-scrollbar-thumb {
  background: #49616b;
  border-radius: 99px;
}

@media (max-width: 700px) {
  .theme-toggle {
    position: absolute;
    top: 18px;
    right: 18px;
  }
  .sidebar {
    position: relative;
  }
}
@media (prefers-reduced-motion: reduce) {
  .theme-toggle *,
  .theme-toggle svg {
    transition: none !important;
  }
}

/* Explicit component tokens override legacy light-theme text and surfaces. */
html[data-theme='dark']
  :is(.card-end, .news-meta, .internal-breadcrumbs, .context-links > span, .wh-care-phase, .si-foot) {
  color: #b6c7ce;
}
html[data-theme='dark'] :is(.eyebrow, .si-eyebrow, .si-arrow, .news-meta > span:first-child, .wh-care-open) {
  color: #86d8ce;
}
html[data-theme='dark'] #main :is(summary, .pv-vaccine-name, .pv-vaccine-name span) {
  color: #dcebea;
}
html[data-theme='dark'] .dm-node :is(p, small, i) {
  color: #bcd3d3;
}
html[data-theme='dark']
  #main
  :is(
    .pv-table-wrap,
    .pv-table,
    .pv-calendar-scroll,
    .si-age-group a,
    .si-chips a,
    .si-nav a,
    .pv-reset,
    .pv-mode button,
    .pv-details
  ) {
  background: #17252e;
  color: #e0ebee;
  border-color: #405761;
}
html[data-theme='dark'] .pv-dose {
  background: #254c42;
  color: #e4f5eb;
  border-color: #619381;
}
html[data-theme='dark'] .pv-dose:hover {
  background: #336453;
  color: white;
}
html[data-theme='dark'] .dm-node.active {
  outline: 3px solid #89e3d8;
  outline-offset: 3px;
}

html[data-theme='dark'] #main .si-eyebrow {
  color: #86d8ce !important;
}
html[data-theme='dark'] #main .si-foot {
  color: #b6c7ce !important;
}

html[data-theme='dark'] :is(dialog, .dm-context) :is(dt, dd, label, legend) {
  color: #c6d9df;
}

html[data-theme='dark'] .atb-card-code {
  color: #b6c7ce;
}
html[data-theme='dark'] .atb-card-arrow {
  color: #86d8ce;
}

/* Catalogue cards: the wrapper owns motion, so the favourite stays attached. */
#main :is(.tool-card, .resource-favorite) {
  background: transparent;
  border-radius: 18px;
  box-shadow: none;
  transition: transform 200ms ease;
}
@media (hover: hover) and (pointer: fine) {
  #main :is(.tool-card, .resource-favorite):hover {
    transform: translateY(-4px);
  }
  #main
    :is(.tool-card, .resource-favorite):hover
    > :is(a.card, a.si-card, a.pv-entry, a.atb-card, a.ref-specialty),
  #main
    :is(.tool-card, .resource-favorite)
    > :is(a.card, a.si-card, a.pv-entry, a.atb-card, a.ref-specialty):hover {
    transform: none;
  }
}

/* Dark icon system and favourite states. */
html[data-theme='dark'] #main :is(.icon, .si-icon, .pv-entry-icon, .atb-icon, .ref-specialty-icon) {
  color: #8de0d7;
  background: #203b40;
  border-color: #41646a;
  box-shadow: inset 0 1px 0 #ffffff0b;
}
html[data-theme='dark'] #main :is(.icon.blue, .icon.purple) {
  color: #a8c9ee;
  background: #25394c;
}
html[data-theme='dark'] #main .pill {
  color: #bfd0d8;
  background: #243740;
  border-color: #40545e;
}
html[data-theme='dark'] #main .favorite-toggle {
  color: #b9ccd5;
  background: #1d3039;
  border-color: #49616c;
  box-shadow: inset 0 1px 0 #ffffff0a;
}
html[data-theme='dark'] #main .favorite-toggle:hover {
  color: #f2cf70;
  background: #293b40;
  border-color: #8f7b43;
}
html[data-theme='dark'] #main .favorite-toggle[aria-pressed='true'] {
  color: #f2cf70;
  background: #3b3522;
  border-color: #8f7b43;
}
html[data-theme='dark']
  #main
  :is(.tool-card, .resource-favorite):hover
  > :is(a.card, a.si-card, a.pv-entry, a.atb-card, a.ref-specialty),
html[data-theme='dark']
  #main
  :is(.tool-card, .resource-favorite):focus-within
  > :is(a.card, a.si-card, a.pv-entry, a.atb-card, a.ref-specialty) {
  color: #f2f8f9;
  background: #1d3039;
  border-color: #598982;
  box-shadow:
    0 14px 34px #0005,
    inset 0 1px 0 #ffffff0b;
}
