:root {
  --ink: #17212b;
  --muted: #637083;
  --line: #d8dee7;
  --surface: #f7f8fa;
  --panel: #ffffff;
  --blue: #1d5f91;
  --teal: #00806b;
  --green: #23814d;
  --yellow: #b8860b;
  --red: #b52b34;
  --focus: #154fbf;
  --shadow: 0 18px 45px rgba(23, 33, 43, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  background:
    linear-gradient(120deg, rgba(29, 95, 145, 0.08), transparent 28%),
    linear-gradient(300deg, rgba(0, 128, 107, 0.1), transparent 24%),
    var(--surface);
}

body[data-screen="pvtRun"] {
  overflow: hidden;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(21, 79, 191, 0.35);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 28px;
  padding: 28px;
  background: #eef2f5;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  fill: #dceee8;
  stroke: var(--teal);
  stroke-width: 2.5;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.step-list {
  display: grid;
  align-content: start;
  gap: 10px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.step-list li {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  min-height: 38px;
}

.step-list .dot {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  font-size: 13px;
}

.step-list li.is-active {
  color: var(--ink);
  font-weight: 700;
}

.step-list li.is-active .dot {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.step-list li.is-complete .dot {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.tablet-box {
  display: grid;
  gap: 6px;
  padding: 16px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
}

.tablet-box span {
  color: var(--muted);
  font-size: 13px;
}

.workbench {
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 24px;
}

.eyebrow {
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 6px 0 0;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
}

.clock {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.screen {
  display: none;
  align-content: center;
  min-height: 0;
}

.screen.is-active {
  display: grid;
}

.form-panel,
.measure-panel,
.state-panel,
.identity-band,
.pvt-setup,
.result-layout {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.form-panel {
  display: grid;
  gap: 18px;
  width: min(520px, 100%);
  padding: 26px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

input {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
}

.form-error {
  min-height: 22px;
  margin: 0;
  color: var(--red);
  font-weight: 700;
}

.primary-action,
.secondary-action {
  min-height: 48px;
  border-radius: 6px;
  padding: 0 18px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-action {
  background: var(--blue);
  color: #fff;
}

.secondary-action {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.identity-band {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
}

.identity-band div {
  display: grid;
  gap: 8px;
  padding: 24px;
  background: #fff;
}

.identity-band span,
.pvt-setup span,
.summary-grid span {
  color: var(--muted);
  font-size: 13px;
}

.identity-band strong,
.pvt-setup strong {
  font-size: 20px;
  line-height: 1.25;
}

.action-row {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 22px;
}

.measure-panel {
  display: grid;
  gap: 20px;
  width: min(620px, 100%);
  padding: 28px;
}

.measure-panel label {
  font-size: 22px;
}

.number-control {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) 76px;
  gap: 12px;
  align-items: center;
}

.number-control button {
  height: 72px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef5f4;
  color: var(--teal);
  font-size: 34px;
  font-weight: 700;
}

.number-control input {
  height: 72px;
  text-align: center;
  font-size: 32px;
  font-weight: 700;
}

.state-panel {
  display: grid;
  gap: 16px;
  width: min(760px, 100%);
  padding: 24px;
}

.card-eyebrow {
  display: block;
  margin-bottom: 8px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.medication-card {
  gap: 16px;
}

.medication-copy {
  display: grid;
  gap: 10px;
}

.switch-control {
  display: grid;
  grid-template-columns: auto 72px;
  align-items: center;
  justify-self: start;
  gap: 12px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
}

.switch-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  width: 72px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #dfe6ee;
  transition: background 160ms ease, border-color 160ms ease;
}

.switch-track::after {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 7px rgba(23, 33, 43, 0.24);
  content: "";
  transition: transform 160ms ease;
}

.switch-control input:checked + .switch-track {
  border-color: #b7c2cf;
  background: #cbd3df;
}

.switch-control input:checked + .switch-track::after {
  transform: translateX(32px);
}

.switch-control input:focus-visible + .switch-track {
  outline: 3px solid rgba(21, 79, 191, 0.35);
  outline-offset: 2px;
}

.slider-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.slider-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: baseline;
}

.slider-head label {
  display: block;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
}

.slider-head strong {
  color: var(--ink);
  font-size: 20px;
  line-height: 1.2;
  text-align: right;
  min-width: 130px;
}

.slider-help {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.risk-range {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  gap: 12px;
  align-items: center;
}

.risk-range-good-left {
  --range-gradient: linear-gradient(90deg, #1f8a52 0%, #d49c22 56%, #b42318 100%);
}

.risk-range-good-right {
  --range-gradient: linear-gradient(90deg, #b42318 0%, #d49c22 42%, #1f8a52 100%);
}

.range-face {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: #fff;
  font-size: 0;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(23, 33, 43, 0.16);
}

.range-face::before,
.range-face::after {
  position: absolute;
  content: "";
}

.range-face::before {
  top: 12px;
  left: 11px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 12px 0 0 #fff;
}

.range-face::after {
  left: 10px;
  width: 18px;
  height: 9px;
  border: 3px solid #fff;
}

.range-face-good {
  background: #1f8a52;
}

.range-face-good::after {
  top: 18px;
  border-top: 0;
  border-radius: 0 0 999px 999px;
}

.range-face-risk {
  background: #b42318;
}

.range-face-risk::after {
  top: 23px;
  border-bottom: 0;
  border-radius: 999px 999px 0 0;
}

.slider-card input[type="range"] {
  width: 100%;
  height: 30px;
  margin: 0;
  appearance: none;
  background: transparent;
}

.slider-card input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue) 0 var(--percent, 50%), #cbd3df var(--percent, 50%) 100%);
}

.risk-range input[type="range"]::-webkit-slider-runnable-track {
  background: var(--range-gradient);
}

.slider-card input[type="range"]::-webkit-slider-thumb {
  width: 22px;
  height: 22px;
  margin-top: -7px;
  appearance: none;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 2px 8px rgba(23, 33, 43, 0.28);
}

.slider-card input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: #cbd3df;
}

.risk-range input[type="range"]::-moz-range-track {
  background: var(--range-gradient);
}

.slider-card input[type="range"]::-moz-range-progress {
  height: 8px;
  border-radius: 999px;
  background: transparent;
}

.slider-card input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 2px 8px rgba(23, 33, 43, 0.28);
}

.range-scale {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.kss-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  width: min(720px, 100%);
}

.kss-option {
  display: grid;
  align-content: center;
  gap: 8px;
  min-height: 118px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.kss-option strong {
  font-size: 28px;
}

.kss-option span {
  color: var(--muted);
  line-height: 1.3;
}

.kss-option.is-selected {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 3px rgba(29, 95, 145, 0.16);
}

.pvt-setup {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  width: min(780px, 100%);
}

.pvt-setup div {
  display: grid;
  gap: 8px;
  padding: 22px;
  background: #fff;
}

.mode-row {
  width: min(780px, 100%);
  margin-top: 16px;
}

.pvt-help {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}

.toggle {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 700;
}

.toggle input {
  width: 22px;
  height: 22px;
  min-height: 22px;
}

.pvt-stage {
  align-content: stretch;
  gap: 18px;
}

body[data-screen="pvtRun"] .app-shell {
  grid-template-columns: 1fr;
  min-height: 100dvh;
}

body[data-screen="pvtRun"] .rail,
body[data-screen="pvtRun"] .topbar {
  display: none;
}

body[data-screen="pvtRun"] .workbench {
  grid-template-rows: 1fr;
  min-height: 100dvh;
  padding: clamp(12px, 2.5vw, 24px);
}

body[data-screen="pvtRun"] .pvt-stage.is-active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: calc(100dvh - clamp(24px, 5vw, 48px));
}

.pvt-topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  min-height: 54px;
}

.pvt-topline strong {
  color: var(--ink);
  font-size: 42px;
}

.stimulus-pad {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 320px;
  height: 100%;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #f3f6f8;
  color: var(--muted);
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.stimulus-pad span {
  font-size: clamp(44px, 7vw, 82px);
  font-weight: 800;
  letter-spacing: 0;
  text-align: center;
}

.stimulus-pad.is-hot {
  background: #0c8a50;
  color: #fff;
  border-color: #075f38;
}

.stimulus-pad.is-hot span {
  font-size: clamp(50px, 8vw, 92px);
  text-transform: uppercase;
}

.pvt-feedback {
  min-height: 28px;
  color: var(--muted);
  font-weight: 700;
}

.result-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  overflow: hidden;
}

.result-signal {
  display: grid;
  align-content: center;
  gap: 12px;
  min-height: 260px;
  padding: 26px;
  color: #fff;
}

.result-signal.verde {
  background: var(--green);
}

.result-signal.amarillo {
  background: var(--yellow);
}

.result-signal.rojo {
  background: var(--red);
}

.result-signal span {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
}

.result-signal strong {
  font-size: 32px;
  line-height: 1.08;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.summary-item {
  display: grid;
  gap: 7px;
  padding: 18px;
  background: #fff;
}

.summary-item strong {
  font-size: 22px;
}

.evidence-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: min(900px, 100%);
  margin-top: 18px;
}

.evidence-strip span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .rail {
    grid-template-rows: auto auto;
    padding: 18px;
  }

  .step-list,
  .tablet-box {
    display: none;
  }

  .workbench {
    padding: 18px;
  }

  .topbar {
    display: grid;
  }

  .identity-band,
  .pvt-setup,
  .result-layout,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .kss-grid {
    grid-template-columns: 1fr;
  }

  .number-control {
    grid-template-columns: 60px minmax(0, 1fr) 60px;
  }

  .action-row {
    justify-content: stretch;
  }

  .action-row button {
    flex: 1;
  }

  .switch-control {
    justify-self: start;
  }

  body[data-screen="pvtRun"] .workbench {
    padding: 12px;
  }

  body[data-screen="pvtRun"] .pvt-stage.is-active {
    height: calc(100dvh - 24px);
  }

  .stimulus-pad span {
    font-size: clamp(40px, 12vw, 76px);
  }

  .stimulus-pad.is-hot span {
    font-size: clamp(42px, 12vw, 82px);
  }
}
